akhauriyash/Code-Regression huggingface dataset:
// compilation flags
// normal
//      g++ -std=c++17 -O2 -Wall a.cpp -o a
// fast running time
//      g++ -O2 -std=c++17 -Wno-unused-result -Wshadow -Wall -o a a.cpp
// check for mistakes
//      g++ -std=c++17 -Wshadow -Wall -o a a.cpp -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g
#include<bits/stdc++.h>
using namespace std;
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define f0(a,b) for(lli i=a;i<b;i++)
#define fn(b,a) for(lli i=b;i>a;i--)
#define dbg(x); cout<<"\n"<<#x<<": "<<x;
#define ret return
#define pb push_back
#define pf push_front
#define mp make_pair
#define E9 1000000007
#define E5 100007
#define INF 1e18+7
#define PI 3.14159265358979323846264338327950L
#define sq(a) (a)*(a)
#define fs first
#define sc second
#define el "\n"
#define all(a) a.begin(),a.end()
typedef long long int lli;  //  e-18 to e18
typedef vector<long long int> vll;
typedef vector<vector<long long int>> vvll;
void solve(){
    lli a,b,h,m;
    double c,C;
    cin>>a>>b>>h>>m;
    a=double(a);
    b=double(b);
    h=double(h);
    m=double(m);
    C=abs((0.5*(h*60+m))-(m*6));
    C=(M_PI/180.0L)*min(360-C,C);
    c=sqrt(sq(a)+sq(b)-(2*a*b*cos(C)));
    cout<<fixed<<setprecision(20)<<c<<el;
}
int main(){
    fastIO();
    lli t(1);
    // cin>>t;
    while(t--) solve();
    ret 0; 
}                                                             

Measured memory_bytes: 4172
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<=b)cout<<a<<endl;
    else cout<<a-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    int N; cin>>N; int cnt = 0;
    std::vector<int> v;
    for(int i=0; i<N ;i++){
      int h; cin>>h;
      v.push_back(h);
    }
    bool flag=true;
    for(int i=1; i<N ;i++){
      for(int j=0; j<i ;j++){
        if(v[j] > v[i]) flag = false;
      }
      if(flag) cnt++;
      flag = true;
    }

    cout<<cnt+1<<endl;
    return 0;
}


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

using namespace std;

using lli = long long int;

const int MAXN = 80; 
const int MOD = 1e9 + 7;

template<typename T>
class matrix {
private:
	int n, m;
	T xss[MAXN][MAXN];

public:
	matrix(int _n, int _m): n(_n), m(_m) {
		memset(xss, 0, sizeof(xss));
	}

	matrix operator* (matrix &b){
		matrix ans = matrix(n, b.m);
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				for (int k = 1; k <= n; ++k) {
					ans.xss[i][j] += xss[i][k]*b(k, j);
					ans.xss[i][j] %= MOD;
				}

		return ans;
	}

	matrix operator^ (lli k) {
		matrix ans = matrix(n, m);
		
		for (int i = 1; i <= n; ++i)
			ans.xss[i][i] = 1;

		for (int i = 62; i >= 0; --i) {
			ans *= ans;
			if (k & (1LL << i)) 
				ans *= (*this);
		}
		return ans;
	}

	void operator*= (matrix &b) {
		*this = (*this)*b;
	}

	void operator^= (lli k) {
		*this = (*this)^k;
	}

	T& operator() (int i, int j) {
		return xss[i][j];
	}

	T sum() {
		T ans = 0;
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j) {
				ans += xss[i][j];
				ans %= MOD;
			}
		return ans;
	}
};

int main() {
	int n; lli k;
	scanf("%d%lld", &n, &k);

	matrix<lli> adj(n, n);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			scanf("%lld", &adj(i, j));

	adj ^= k;
	printf("%lld\n", adj.sum());
}

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

using namespace std;

int main() {
    string s;
    cin >> s;

    string t = "CODEFESTIVAL2016";
    int ans = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

Measured memory_bytes: 23764
#include <stdio.h>

int main(void){
  int i;
  int N;
  scanf("%d", &N);
  int H[N];
  for(i=0; i<N; i++)
    scanf("%d", &H[i]);

  for(i=N-2; i>=0; i--){
    if(H[i] > H[i+1]+1)
      break;
    else if(H[i] > H[i+1])
      H[i]--;
    }
  if(i == -1)
    printf("Yes\n");
  else
    printf("No\n");
    
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 5;
int n;
int head[MAXN] , to[MAXN << 1] , nxt[MAXN << 1] , cnt , ans , du[MAXN << 1];
LL f[MAXN] , a[MAXN];
void add(int u , int v) {nxt[++cnt] = head[u];head[u] = cnt;to[cnt] = v;}
void dfs(int x , int fa) {
	LL _sum = 0 , mx = 0;
	for (int i = head[x]; i; i = nxt[i]) {
		if(to[i] == fa) continue;
		dfs(to[i] , x);
		if(ans) return;
		mx = max(mx , f[to[i]]);
		_sum += f[to[i]];
	}
	if(!_sum) {
		f[x] = a[x];
		return;
	}
	f[x] = 2ll * a[x] - _sum;
	if(f[x] < 0 || f[x] > a[x] || a[x] < mx) {
		printf("NO");
		exit(0);
	}
}
signed main() {
	scanf("%lld" , &n);
	for (int i = 1; i <= n; ++i) scanf("%lld" , &a[i]);
	if (n == 2) return puts(a[1] == a[2] ? "YES" : "NO"), 0;
	int root = 0;
	for (int i = 1; i < n; ++i) {
		int u , v;
		scanf("%lld %lld" , &u , &v);
		du[u] ++;du[v] ++;
		add(u , v);add(v , u);
		if(du[u] > 1) root = u;
		if(du[v] > 1) root = v;
	}
	dfs(root , 0);
	if(f[root]) printf("NO");
	else printf("YES");
	return 0;
}

Measured memory_bytes: 15760
a,p,b,q=map(int,input().split())

n=2*(10**6)+3
mod=10**9+7
kaidan=[1]*(n+1)
gyaku=[1]*(n+1)
for i in range(1,n+1):
    kaidan[i]=i*kaidan[i-1]%mod
    gyaku[i]=pow(kaidan[i],mod-2,mod)
def comb(n,r):
    if n-r>=0 and n>=0 and r>=0:
        return (kaidan[n]*gyaku[n-r]*gyaku[r])%mod
    else:
        return 0

def ans(a,b):
    return comb(a+b+2,a+1) -(a+b+2) 

print((ans(b,q)-ans(b,p-1)-ans(a-1,q)+ans(a-1,p-1))%mod)

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

#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
// typedef long long ll;
using ll = long long;

const int N_MAX = 200000;
int A[N_MAX];
int B[N_MAX];

int editorial(int N) {
  int ans = 0;
  const int n_bit = 29;

  rep(i, 0, n_bit) {
    int t = 1 << i;
    int t2 = t << 1;

    vector<int> mod;
    rep(i, 0, N) {
      int b = B[i];
      mod.push_back(b & (t2 - 1));
    }
    sort(all(mod));

    auto count = 0;
    rep(i, 0, N) {
      int da = A[i] % t2;
      // iterator を返す
      int t1_count = lower_bound(all(mod), t - da) - mod.begin();
      int t2_count = lower_bound(all(mod), t2 - da) - mod.begin();
      int t3_count = lower_bound(all(mod), t * 3 - da) - mod.begin();

      count += N - t3_count + t2_count - t1_count;
    }

    if (count & 1 == 1) {
      ans += 1 << i;
    }
  }
  return ans;
}

int main() {
  int N, ans;
  cin >> N;

  rep(i, 0, N) cin >> A[i];
  rep(i, 0, N) cin >> B[i];

  ans = editorial(N);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
long long n,k;
long long ans;
int main()
{
	cin>>n>>k;
	if(k==0) {cout<<n*n;return 0;}
	if(n<=10000)
	{
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		if(i%j>=k) ans++;
		cout<<ans;
		return 0;
	}
	for(int i=k+1;i<=n;i++)
	{
		int t=(n+1)/i;
		ans+=(i-k)*t;
		int s=n-t*i-k+1;
		if(s>0) ans+=s;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;
const int MOD(998244353);
const int Max_N(18);

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

constexpr int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

constexpr int squ(int x)
{
	return Mult(x, x);
}

void exgcd(int a, int b, int &x, int &y)
{
	if (b == 0)
		x = 1, y = 0;
	else
		exgcd(b, a % b, y, x), y -= x * (a / b);
}

inline int inverse(int a)
{
	int invx, invy;
	exgcd(a, MOD, invx, invy);
	return (invx % MOD + MOD) % MOD;
}

int N, A[1 << Max_N], E[1 << Max_N], SumA;

void FWT(int F[1 << Max_N], bool inv = false)
{
	for (int i = 0;i <= N - 1;++i)
		for (int S = 0, x, y;S < (1 << N);++S)
			if ((S & (1 << i)) == 0)
			{
				x = F[S], y = F[S + (1 << i)];
				F[S] = Add(x, y), F[S + (1 << i)] = Sub(x, y);
			}
	if (inv)
		for (int S = 0, invL = inverse(1 << N);S < (1 << N);++S)
			F[S] = Mult(F[S], invL);
}

int main()
{
	gi(N);
	for (int S = 0;S < (1 << N);++S)
		gi(A[S]), SumA += A[S];
	for (int S = 0, inv = inverse(SumA);S < (1 << N);++S)
		A[S] = Mult(A[S], inv);
	FWT(A);
	E[0] = 0;
	for (int S = 1;S < (1 << N);++S)
		E[S] = inverse(Sub(A[S], 1));
	FWT(E, true);
	for (int S = 0, G1, _G1, H1, _H1, inv = inverse(1 << N);S < (1 << N);++S)
	{
		G1 = inv, _G1 = E[S], H1 = inv, _H1 = E[0];
		print(Mult(Sub(Mult(_G1, H1), Mult(G1, _H1)), inverse(squ(H1)))), putc('\n');
	}
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
     
int main(){
  int H,W;
  string s;
  cin>>H>>W;
  for(int i=0;i<H;i++){
      cin>>s;
      cout<<s<<endl;
      cout<<s<<endl;
    
  }
  
  return 0;
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&a!=c){
    cout<<"Yes";
  }
  else if (c==a&&c!=b)
    cout<<"Yes";
  else if(b==c&&b!=a)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3544
function myout(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = parseInt(input.trim());
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var list = ["Sunny","Cloudy","Rainy"];
  var ind = list.indexOf(input) + 1;
  if(ind == 3){
     ind = 0;
  }
  myout(list[ind]);
}

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


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

using namespace std;

const int N = 1e5 + 10;
const unsigned X = 1234567;
const unsigned R = 7531;

int n;
unsigned h[N];
vector <int> g[N];
map <unsigned, int> f;

void dfs (int u, int p) {
	unsigned now = 0;
	for (int v : g[u]) if (v != p) {
		dfs(v, u); 
		now += h[v];
	}
	h[u] = now * X + R;
	++f[h[u]];  
}

int main (int argc, char const *argv[]) {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(1, 0);

	long long ans = 0;
	for (auto it : f) {
		long long cnt = (long long) it.second;
		ans += (cnt * (cnt - 1LL))/2LL;
	}

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

Measured memory_bytes: 21612
r, c = map(int, input().split())

A = []
for _ in range(r):
    a = [int(x) for x in input().split()]
    a.append(sum(a))
    A.append(a)

B = []
for i in range(c + 1):
    b = 0
    for j in range(r):
        b += A[j][i]
    B.append(b)
A.append(B)

for a in A:
    print(*a)


Measured memory_bytes: 6244
#include <algorithm>
#include <iostream>
#include "stdio.h"
#include <iterator>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;
 
vector<int> rankSort(vector<int> v_temp, const int size) {
    vector<pair<int, int> > v_sort(size);

    for (int i = 0U; i < size; ++i) {
        v_sort[i] = make_pair(v_temp[i], i);
    }

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

    pair<double, int> rank;
    vector<int> result(size);

    for (int i = 0U; i < size; ++i) {
        if (v_sort[i].first != rank.first) {
            rank = make_pair(v_sort[i].first, i);
        }
        result[v_sort[i].second] = rank.second;
    }
    return result;
}
 
int main() {
	//const int v_temp[] = { 10.0F, 332.0F, 42.0F, 0.9F, 0.0F, 42.0F };
	//const vector<int> v_sort = rankSort(v_temp, sizeof(v_temp) / sizeof(*v_temp));
    int n, m;
    int idxs[100001];
    int p[100001], y[100001];
    vector<int> prefs[100001];
    vector<int> ranks[100001];
    std::cin >> n >> m;
    REP(i, m){
        std::cin >> p[i] >> y[i];
        prefs[p[i] - 1].push_back(y[i]);
    }
    REP(i, n){
        ranks[i] = rankSort(prefs[i], prefs[i].size());
    }

    REP(i, m){
        int pref = p[i] - 1;
        int rank = ranks[pref][idxs[pref]];

        idxs[pref] = idxs[pref] + 1;
        printf("%06d%06d\n", 1 + pref, rank + 1);
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  sort(l.rbegin(),l.rend());
  int a = 0;
  int b = 0;
  rep(i,n){
    if(i == 0) a += l[i];
    else{
      b += l[i];
    }
  }
  if(a < b) puts("Yes");
  else puts("No"); 
  return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,z,w = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	if n == 1
		println(abs(a[n]-w))
	else
		println(max(abs(a[n]-w),abs(a[n]-a[n-1])))
	end
end

main()


Measured memory_bytes: 111328
#include <iostream>

#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 srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    int n,d;
    cin>>n>>d;
    int ans = 1;
    int p = d+1;
    while(p+d<n){
        p += 2*d+1;
        ans ++;
    }
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

long long int f0(const long long int x)
{
    switch (x % 4)
    {
    case 0:
        return x;
    case 1:
        return 1;
    case 2:
        return x + 1;
    case 3:
        return 0;
    }
}

int main()
{
    long long int a, b;
    scanf("%lld %lld", &a, &b);

    printf("%lld\n", a == 0 ? f0(b) : f0(a - 1) ^ f0(b));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;

int main(){
    string s;
    cin >> s;

    int n = s.length();
    
    vector<vector<long long int>> dp(n+1, vector<long long int>(4));
    dp[0][0] = 1;
    for(int i=1; i<=n; i++){
        for(int j=0; j<4; j++){
            dp[i][j] = dp[i-1][j];
            if(s[i-1] == '?') dp[i][j] *= 3;
        }

        if(s[i-1] == 'A') dp[i][1] += dp[i-1][0];
        if(s[i-1] == 'B') dp[i][2] += dp[i-1][1];
        if(s[i-1] == 'C') dp[i][3] += dp[i-1][2];
        if(s[i-1] == '?'){
            for(int j=0; j<3; j++){
                dp[i][j+1] += dp[i-1][j];
            }
        }

        for(int j=0; j<4; j++){
            dp[i][j] %= MOD;
            //cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
        }
    }
    cout << dp[n][3] << endl;
    return 0;
}

Measured memory_bytes: 7424
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n,C;
    cin >> n >> C;
    vector<int> s(n);
    vector<int> t(n);
    vector<int> c(n);
    REP(i,n){
        cin >> s[i] >> t[i] >> c[i];
        c[i]--;
    }
    vector<vector<bool>> channel(C,vector<bool>(1e5+10,false));
    REP(i,n){
        FOR(j,s[i]-1,t[i]){
            channel[c[i]][j]=true;
        }
    }
    int res = 0;
    REP(j,1e5+10){
        int temp = 0;
        REP(i,C){
            if(channel[i][j]){
                temp++;
            }
        }
        chmax(res,temp);
    }
    put(res);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
    int A, B;
    int max = 0;
    int result = 0;

    cin >> A >> B;

    A += A-1;
    B += B-1;

    if(A > B) {
        cout << A << endl;
    } else if(A < B) {
        cout << B << endl;
    } else {
        cout << (A+1) << endl;
    }

    
}

Measured memory_bytes: 636
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <stdlib.h>
const int MAX = 3;
int main(){
    string a;
    cin >> a;
    int min = 10000;
    for(int i = 0;i < a.length() - 2;i++){
        int num = ((int)(a[i] - '0')) * 100;
        num += ((int)(a[i + 1] - '0')) * 10;
        num += ((int)(a[i + 2] - '0')) * 1;
        if(abs(num - 753) < min){
            min = abs(num - 753);
        }



    }
    cout << min << endl;

    return 0;
}

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

vector <int> G[100006];
vector <int> B[100006];
int v[100006];
int ans[100006];

int bfs(int lab,int i){
  int u,j,t;
  int cnt = 1;
  int a[100006];
  int head = 0;
  int tail = 0;

  a[tail++] = i;

  while(head != tail){
    u = a[head++];
    v[u] = lab;
    for(j = 0;j < G[u].size();j++){
      t = G[u][j];

      if(v[t] == -1){
        a[tail++] = t;
        cnt++;
        v[t] = lab;
      }
    }
  }

  return cnt;
}

int main(){
  int n,m,k;
  int i,j,u;
  int s,t;
  int lab = 1;

  scanf("%d %d %d", &n, &m, &k);

  for(i = 1;i <= n;i++) v[i] = -1;

  for(i = 1;i <= m;i++){
    scanf("%d %d", &s, &t);
    G[s].push_back(t);
    G[t].push_back(s);
  }

  for(i = 1;i <= k;i++){
    scanf("%d %d", &s, &t);
    B[s].push_back(t);
    B[t].push_back(s);
  }

  int cnt[100006];

  for(i = 1;i <= n;i++){
    if(v[i] == -1){
      cnt[lab] = bfs(lab,i);
      lab++;
    }
  }

  for(i = 1;i <= n;i++){
    ans[i] = cnt[v[i]] - G[i].size() - 1;

    for(j = 0;j < B[i].size();j++){
      if(v[B[i][j]] == v[i]) ans[i]--;
    }
  }


  for(i = 1;i < n;i++){
    printf("%d ", ans[i]);
  }

  printf("%d\n", ans[n]);

  return 0;
}

Measured memory_bytes: 13048
#include <stdio.h>

int main(void)
{
	int map[16][16];
	int n;
	int a, b;
	int x, y;
	int i, j;
	
	while (1){
		scanf("%d%d", &a, &b);
		
		if (a == 0 && b == 0){
			break;
		}
		
		scanf("%d", &n);
		
		for (i = 0; i < b; i++){
			for (j = 0; j < a; j++){
				map[i][j] = 0;
			}
		}
		
		for (i = 0; i < n; i++){
			scanf("%d%d", &x,&y);
			map[b - y][x - 1] = -1;
		}
		
		for (i = 0; i < a; i++){
			if (map[b - 1][i] != -1){
				map[b - 1][i] = 1;
			}
			else if(map[b -1][i] == -1){
				break;
			}
		}
		for (i = b - 1; i >= 0; i--){
			if (map[i][0] != -1){
				map[i][0] = 1;
			}
			else if(map[i][0] == -1){
				break;
			}
		}
		
		for (i = b - 2; i >= 0; i--){
			for (j = 1; j < a; j++){
				if (map[i][j] != -1){
					if (map[i][j - 1] != -1){
						map[i][j] += map[i][j - 1];
					}
					
					if (map[i + 1][j] != -1){
						map[i][j] += map[i + 1][j];
					}
				}
			}
		}
		
		printf("%d\n", map[0][a - 1]);
	}
	
	return (0);
}

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

int main(void){
    string s,t;
    char tmp;
    bool flag=false;
    

    cin>>s>>t;

    for(int i=0;i<s.length();i++){
        if(s==t){
            flag=true;
            break;
        }
        tmp=s[s.length()-1];
        s.pop_back();
        s=tmp+s;

    }

    if(flag==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
main(){int e;while(std::cin>>e&&e){int m=1<<30;for(int z=0,c=0;c<=e;++z,c=z*z*z)for(int y=0,b=0;c+b<=e;++y,b=y*y)m=std::min(m,e-c-b+y+z);std::cout<<m<<'\n';}}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		int n = s.length;

		out:
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (s[(i + j) % n] != t[j]) {
					continue out;
				}
			}
			
			pr.println("Yes");
			return;
		}

		pr.println("No");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

vector<int> z_algorithm(const string &s) 
{
  vector<int> prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i-j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i+k < s.size() && s[k] == s[i+k])
        k++;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = int(s.size());
  return prefix;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  REP(i,n-1){
    string t = s.substr(i);
    auto zv = z_algorithm(t);
    REP(k,zv.size()) ans = max(ans, min(zv[k], k));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
typedef long long ss;
int main()
{
    start;
    ss a,b,c=0,i,d;
   string s,t;
   cin>>s>>t;
   a=s.size();
   f(i,0,a)
   {
       if(s[i]!=t[i])
        c++;
   }
   cout<<c<<endl;
   return 0;
}


Measured memory_bytes: 3784
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	ll a,b,k;
	cin>>a>>b>>k;

	for(ll i=a; i<b; ++i){
		if(i<=a+(k-1)){
			cout<<i<<endl;
		}else{
			if(i>=b-(k-1)){
				cout<<i<<endl;
			}
		}
	}
	cout<<b<<endl;



	return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer, Integer> a = new HashMap<>();
        for (Integer i=1; i<=n; i++) {            
            a.put(i, sc.nextInt());
        }
        
        Integer next = 1;
        Integer count = 0;
        while (true) {
            next = a.get(next);
            count++;
            if (next == 1) {
                System.out.println("-1");
                return;
            }
            if (next == 2) {
                System.out.println(count);
                return;
            }
            if (count > n) {
                System.out.println("-1");
                return;
            } 
        }
    }
}


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

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

const double EPS = 1e-10;

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


int main(){
    int a; cin >> a;
    if(a >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define vbi vector<bool> 
#define mod 1000000007
#define INF 1000000000
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
ll i,j,k;
void solve()
{
  ll n; cin>>n;
  string t; cin>>t;
 
  if(n%2!=0){
    cout<<"No";
    return;
  }
   n=n/2;
  vector<char>v;

  for(i=0;i<n;i++){
     v.pb(t[i]);
  }
  j=0;
  for(i=n;i<2*n;i++){
    if(v[j]!=t[i]){
      cout<<"No";
      return;
    }
    j++;
  }
  cout<<"Yes";
}
signed main(){
   
    solve();
    return 0;
}

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

using namespace std;
typedef long long LL;
const int maxn=1e5+10;
int a[maxn];
int main() {
    int n,k,ans=1e9,ans1;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=100;i++){
        int tmp=0;
        for(int j=0;j<n;j++){
            tmp+=(i-a[j])*(i-a[j]);
        }
        if(tmp<ans){
            ans=tmp;ans1=i;
        }
    }
    cout<<ans;
}




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

using namespace std;

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

int main(){

  int n, ans = 0;
  
  cin >> n;
  
  rep(i, n){
   	int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N, Z, W;
    cin >> N >> Z >> W;

    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    ll ans = abs(a[N - 1] - W);
    if (N >= 2) chmax(ans, abs(a[N - 1] - a[N - 2]));

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# ABC136D - Gathering Children
def main():
    """
    RR..LLの部分列に分解
    それぞれの部分列のRL境界に子どもが集まる
    奇数マスの子は奇数マスに、偶数マスの子は偶数マスの境界に (10^100 % 2 == 0)
    境界以外は全て0
    """
    S = input().rstrip() + "R"
    n = len(S)
    cur, P = S[0], []  # p: partial strings
    for i in S[1:] :
        if cur[-1] == "L" and i == "R":
            P += [cur]
            cur = ""
        cur += i
    ans = []
    for p in P:
        e, o = len(p) // 2, len(p) // 2 + len(p) % 2
        r_cnt, l_cnt = p.count("R"), p.count("L")
        l, r = (e, o) if p.index("L") % 2 == 0 else (o, e)
        ans += [0] * (r_cnt - 1) + [l] + [r] + [0] * (l_cnt - 1)
    print(*ans, sep=" ")


if __name__ == "__main__":
    main()

Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int a[n], b[n], c[n - 1];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  
  for (int i = 0; i < n - 1; i++) {
    cin >> c[i];
  }
  
  for (int i = 0; i < n; i++) {
    ans += b[a[i] - 1];
    if (a[i] == a[i + 1] - 1) {
      ans += c[a[i] - 1];
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	int n, k, p=0;
	cin >> n >> k;
	int arr[n];
	for (int i = 0;i < n;i++)
	{
		cin >> arr[i];
	}
	sort(arr, arr + n);
	for (int i = 0;i < k;i++)
	{
		p += arr[i];
	}
	cout << p;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <queue>
#include <set>
using namespace std;
typedef pair<int,int> pa;
typedef pair<int,pa> pp;

int ary[1010][1010];
int dy[8]={0,1,1,1,0,-1,-1,-1},dx[8]={1,1,0,-1,-1,-1,0,1};
int H,W;

int main(){
	cin>>H>>W;
	char ch;
	queue<pa> quf;
	set<pa> se[2];
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			cin>>ch;
			if(ch=='.') ary[i][j]=0;
			else ary[i][j]=ch-'0';
			se[1].insert(pa(i,j));
		}
	}
	
	int tmx,tmy,now=0,cnt=0,res=0;
	quf.push(pa(0,0));
	for(int i=1;;i++){
		if(quf.empty()){
			res=i-2;
			break;
		}
		while(!quf.empty()){
			ary[quf.front().first][quf.front().second]=0;
			quf.pop();
		}
		se[1-(i&1)].clear();
		for(auto it=se[i&1].begin();it!=se[i&1].end();it++){
			if(ary[it->first][it->second]==0) continue;
			cnt=0;
			for(int j=0;j<8;j++){
				if(ary[it->first+dx[j]][it->second+dy[j]]==0){
					cnt++;
				}
			}
			if(ary[it->first][it->second]<=cnt){
				quf.push(pa(it->first,it->second));
				for(int j=0;j<8;j++){
					if((1<=it->first+dx[j])&&(it->first+dx[j]<=H)&&(1<=it->second+dy[j])&&(it->second+dy[j]<=W)) se[1-(i&1)].insert(pa(it->first+dx[j],it->second+dy[j]));
				}
			}
		}
		cout<<"";
	}
	cout<<res<<endl;
	return 0;
}

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

int main(){
int N,D,X;
  cin>>N>>D>>X;
  
  vector<int>A(N);
  for(int i=0; i<N; i++){
  cin>>A[i];  
  }
  
  int S=0;
  for(int i=0; i<N; i++){
  S+=((D-1)/A[i])+1;
  }
  cout<<S+X<<endl;
}


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

int main() {
int N,K,S;
cin >>N>>K;
  S=0;
rep(i,N){
  int x;
  cin>>x;
if(x>abs(K-x)){
S+=2*abs(K-x);
}
else{
S+=2*x;
}

}
cout<< S <<endl;

}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
res = 0
high = [1 for i in range(N)]
for u in range(N):
    for v in G[u]:
        if H[u] < H[v]:
            high[u] = 0
        elif H[u] > H[v]:
            high[v] = 0
        else:
            high[u] = 0
            high[v] = 0
    if high[u]:
        res += 1
print(res)

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

int main(){
    long long A, B;
    cin >> A >> B;

    for(long long i = 0; i <= 1000000001; i++){
        if(abs(A-i) == abs(B-i)){
            cout  << i << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

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

    if(n >= 10){
        cout << r << "\n";
    }else{
        cout << r+100*(10-n) << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int calc(int x) {
	int ret = 0;
	while(x % 100 == 0) {
		x /= 100;
		++ret;
	}
	return ret;
}
int main() {
	int D, N;
	cin >> D >> N;
	int cnt = 0, val = 0;
	while(cnt < N) {
		++val;
		if(calc(val) == D) ++cnt;
	}
	cout << val << '\n';
	return 0;
}

Measured memory_bytes: 888
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  def solve(sc: Scanner): String = {
    val (p, q, r) = (sc.nextInt(), sc.nextInt(),sc.nextInt())

    Seq(p, q, r).sorted.take(2).sum.toString
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


Measured memory_bytes: 25920
// Problem : 
// 			B - Making Triangle
// 			
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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 db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n;
	cin >> n;
	vector<int> v;
	map<int,int> mp;
	for(int i=0;i<n;i++)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	for(auto [a,b]:mp)
		v.pb(a);
	sort(all(v));
	n = v.size();
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(v[i]+v[j] >v[k])
				{
					int tmp = mp[v[i]]*mp[v[j]]*mp[v[k]];
					ans+=tmp;
				}
			}
		}
	}
	cout << ans ;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
const int INF = INT_MAX/3;
const double EPS = 1e-14;

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;

int N, P;

const int PRIMEMAX = 150000;
int FACTOR[PRIMEMAX];
vector<int> Primes;
void sieve(lli upb) {
  FACTOR[0] = FACTOR[1] = -1;
  for(lli n = 0; n < upb; ++n) {
    if (FACTOR[n] != 0) continue;
    Primes.push_back(n);
    lli kn = n * n;
    while (kn < PRIMEMAX) { FACTOR[kn] = n; kn += n; }
  }
}

bool is_prime(int n) {
  return FACTOR[n] == 0;
}

int main() {
  cout << fixed << setprecision(12);
  sieve(PRIMEMAX);
  while (cin >> N >> P and N != -1) {
    auto iter = upper_bound(ALL(Primes), N);
    vector<int> v;
    REP(i, 100) FOR(j, i, 100 + i) {
      v.push_back(*(iter + i) + *(iter + j));
    }
    sort(ALL(v));
    cout << v[P-1] << endl;
  }
  return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = INT_MAX;
    for (int ab = 0; ab <= int(2e5); ab += 2) {
        ans = min(ans, ab * C + max(0, X - ab/2) * A + max(0, Y - ab/2) * B);
    }
    cout << ans << endl;

    return 0;
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);
            int q = int.Parse(str[2]);

            int[,] tb = new int[q, 4];
            for (int i = 0; i < q; ++i)
            {
                str = Console.ReadLine().Split();
                for (int j = 0; j < 4; ++j)
                    tb[i, j] = int.Parse(str[j]);
            }

            if (m == 1)
            {
                int s = 0;
                for (int i = 0; i < q; ++i)
                    if (tb[i, 2] == 0) s += tb[i, 3];
                Console.WriteLine(s);
                return;
            }

            int[] a = new int[n];
            for (int i = 0; i < n; ++i)
                a[i] = 1;

            int max = 0;
            while (a[0] == 1)
            {
                int s = 0;
                for (int i = 0; i < q; ++i)
                {
                    int aa = tb[i, 0] - 1;
                    int bb = tb[i, 1] - 1;
                    if (a[bb] - a[aa] == tb[i, 2]) s += tb[i, 3];
                }
                if (max < s) max = s;

                for (int i = n - 1; i >= 0; --i)
                {
                    if (a[i] < m)
                    {
                        ++a[i];
                        for (int j = i; j < n; ++j)
                        {
                            a[j] = a[i];
                        }
                        break;
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 27400
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int Prime[1000000];   //Prime[i] = 1のときiは素数。0のときiは素数でない

void Eratosthenes(int n) {  //n未満の素数を求める

    rep(i, n) {
        Prime[i] = 1;
    }

    Prime[0] = 0;  Prime[1] = 0;
    for(int i = 2; i*i < n; i++) {
        if(Prime[i]) {
            for(int j = 2; i*j < n; j++) {
                Prime[i*j] = 0;
            }
        }
    }
}

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    else {
        return gcd(y, x%y);
    }
}

int main() {
    ll a, b;
    cin >> a >> b;

    ll G = gcd(a, b);

    Eratosthenes(1000000);

    ll ans = 1LL;
    for(ll i = 2; i*i <= G; i++) {
        if(Prime[i] && G%i == 0) {
            ans++;
            while(G%i == 0) {
                G /= i;
            }
        }
    }
    if(G != 1) {
        ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

int n, m, a[30];
char s[105];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read();
	for (int i = 1; i <= n; i ++)
	{
		scanf("%s", s + 1);
		for (int j = 1; j <= m; j ++)
			a[s[j] - 'a'] ++;
	}
	if (!(n & 1) && !(m & 1))
	{
		for (int i = 0; i < 26; i ++)
			if (a[i] & 3)
				return puts("No"), 0;
		return puts("Yes"), 0;
	}
	if ((n & 1) && (m & 1))
	{
		int cnt1 = 0, cnt2 = 0;
		for (int i = 0; i < 26; i ++)
			if ((a[i] & 3) == 2)
				cnt1 ++;
			else if (a[i] & 1)
				cnt2 ++;
		if (cnt2 == 1 && cnt1 <= (n + m - 2 >> 1))
			return puts("Yes"), 0;
		return puts("No"), 0;
	}
	int cnt = 0;
	for (int i = 0; i < 26; i ++)
		if ((a[i] & 3) == 2)
			cnt ++;
		else if (a[i] & 1)
			return puts("No"), 0;
	if (n & 1)
	{
		if (cnt <= (m >> 1))
			return puts("Yes"), 0;
		return puts("No"), 0;
	}
	if (m & 1)
	{
		if (cnt <= (n >> 1))
			return puts("Yes"), 0;
		return puts("No"), 0;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 100000
#define SENTINEL 2000000000
constexpr int inf = 100000000;

struct card{
    char suit;
    int value;
};

struct card l[MAX/2+2],r[MAX/2+2];

void merge(struct card a[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++){
        l[i]=a[left+i];
    }
     for(int i=0;i<n2;i++){
        r[i]=a[mid+i];
    }
    l[n1].value=SENTINEL;
    r[n2].value=SENTINEL;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(l[i].value<=r[j].value){
            a[k]=l[i++];
        }else{
            a[k]=r[j++];
        }
    }
}

void mergesort(struct card a[],int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergesort(a,left,mid);
        mergesort(a,mid,right);
        merge(a,left,mid,right);
    }
}

int partition(struct card a[],int p,int r){
    int i=p-1;
    for(int j=p;j<r;j++){
        if(a[j].value<=a[r].value){
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[i+1],a[r]);
    return i+1;
}

void quicksort(struct card a[],int p,int r){
    int q;
    if(p<r){
        q=partition(a,p,r);
        quicksort(a,p,q-1);
        quicksort(a,q+1,r);
    }
}

int main(){
    int n;
    cin>>n;
    struct card a[n],b[n];
    bool stable=true;
    rep(i,n){
        cin>>a[i].suit>>a[i].value;
        b[i]=a[i];
    }
    quicksort(a,0,n-1);
    mergesort(b,0,n);
    rep(i,n){
       if(a[i].suit!=b[i].suit){
           stable=false;
       }
    }
    if(stable){
        cout<<"Stable"<<endl;
    }else{
        cout<<"Not stable"<<endl;
    }
    rep(i,n){
        cout<<a[i].suit<<" "<<a[i].value<<endl;
    }
   return 0;
}












Measured memory_bytes: 5428
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

int main(){
    ll a,b;cin >>a >> b;
    string s,t;cin >>s >> t;
    ll m=a*b/__gcd(a,b);
    ll x=__gcd(a,b);
    bool flag=true;
    rep(i,x){
        if(s[i*(a/x)]!=t[i*(b/x)])flag=false;
    }
    if(flag)cout << m <<endl;
    else cout << -1 <<endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<cstdlib>
int main(void){
	int c;
	int n;
	char d[100001];
	char e[100001];
	c = 0;
	scanf("%s", e);
	n = strlen(e);
	for (int i = 0; i < n; i++){
		d[i] = e[n - i - 1];
		if (d[i] == 98)d[i] = 100;
		else if (d[i] == 100)d[i] = 98;
		else if (d[i] == 112)d[i] = 113;
		else if (d[i] == 113)d[i] = 112;
		if (d[i] == e[i])c++;
	}
	if (n == c)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

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

  int a, b;
  cin >> a >> b;
  a += 13 * (a == 1);
  b += 13 * (b == 1);
  if (a == b)
    cout << "Draw\n";
  else if (a < b)
    cout << "Bob\n";
  else
    cout << "Alice\n";

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int A, B, M;
    cin >> A >> B >> M;

    vector<int> a(A), b(B);
    vector<int> x(M), y(M), c(M);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    rep(i,M) {
        cin >> x[i] >> y[i] >> c[i];
        x[i]--; y[i]--;
    }

    int minimum = INF;
    rep(i,M) minimum = min(minimum, a[x[i]] + b[y[i]] - c[i]);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    minimum = min(minimum, a[0] + b[0]);

    cout << minimum << endl;
    
    return 0;
}

Measured memory_bytes: 2176