akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define INFLL (1LL << 60)
#define INF (1 << 30)
using namespace std;
typedef long long ll;

template<class T> inline void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }

namespace Dijkstra
{
	struct Edge {
		int to, weight;
		Edge(int t, int w) {
			to = t; weight = w;
		}
	};
	using Graph = vector<vector<Edge>>;
	using Vtx = pair<int, int>;
	vector<ll> dijkstra(int s, const Graph& graph) {
		const int N = graph.size();
		priority_queue<Vtx, vector<Vtx>, greater<Vtx>> pq;	//コスト、頂点
		pq.push(make_pair(0, s));
		vector<ll> cost(N, INFLL);
		cost[s] = 0;
		while (!pq.empty()) {
			auto t = pq.top(); pq.pop();
			int c = t.first;
			int v = t.second;
			if (c > cost[v]) continue;	//より低いコストがすでにあるとき、探索省略
			for (auto e : graph[v]) {
				ll nc = cost[v] + e.weight;
				if (nc >= cost[e.to]) continue;	//探索済みよりコストが大きいなら、探索省略
				pq.push(make_pair(nc, e.to));
				cost[e.to] = nc;
			}
		}
		return cost;
	}
	void exec()
	{
		const ll have = 1000000000000000;
		int N, M, S, T; cin >> N >> M >> S >> T; --S; --T;
		Graph yen(N), snk(N);
		for (int i = 0; i < M; ++i) {
			int u, v, a, b; cin >> u >> v >> a >> b; --u, --v;
			yen[u].push_back(Edge(v, a));
			yen[v].push_back(Edge(u, a));
			snk[u].push_back(Edge(v, b));
			snk[v].push_back(Edge(u, b));
		}
		auto c1 = dijkstra(S, yen);
		auto c2 = dijkstra(T, snk);
		vector<ll> used(N);
		ll mu = INFLL;
		for (int year = N - 1; year >= 0; --year) {
			chmin(mu, c1[year] + c2[year]);
			used[year] = mu;
		}
		for (int year = 0; year < N; ++year) {
			cout << have - used[year] << endl;
		}

	}
}

int main()
{
	Dijkstra::exec();
	return 0;
}


Measured memory_bytes: 17112
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int N, M;
vector<int> A(200000), B(200000), ans(100000),visited(100000, 0);
bool judge = true;
queue<int> q;
vector<vector<int>> graph(200001, vector<int>(0));

void DFS(int now){

  visited[0] = 1;
  rep(i,graph[now].size()){
    if(visited[graph[now][i]-1] == 0){
      ans[graph[now][i]-1] = now;
      visited[graph[now][i]-1] = 1;
      q.push(graph[now][i]);
      //DFS(B[i]);
    }
  }
  return;
  //cout << q.size() <<endl;

}

int main() {

  cin >> N >> M;
  rep(i, M) {
    cin >> A[i] >> B[i];
    graph[A[i]].push_back(B[i]);
    graph[B[i]].push_back(A[i]);
  }
  DFS(1);

  while(1){
    rep(i,q.size()){
      //cout << q.front() <<endl;
      DFS(q.front());
      q.pop();
    }
    if(q.size() == 0) break;
  }

  rep(i, N){
    if(visited[i] == 0){
      judge = 0;
      break;
    }
  }




  if(judge){
    cout << "Yes" << endl;
    for(int i = 1; i < N; i++) cout << ans[i] << endl;
  }
  else cout << "No" << endl;

}


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

using namespace std;

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

    long long ans;
    int n, m;
    cin >> n >> m;

    if (n == 1 && m == 1)
        ans = 1;
    else if (n == 1 || m == 1)
        ans = 1ll * n * m - 2;
    else if (n == 2 || m == 2)
        ans = 0;
    else
        ans = 1ll * n * m - (1ll * n * 2 + 1ll * (m - 2) * 2);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


template<class T> struct Dinic {
  struct Edge { int to, rev; T cap; };
  const int n;
  const T inf = numeric_limits<T>::max();
  VV<Edge> g;
  V<> dist, i;
  Dinic(int n) : n(n), g(n), dist(n), i(n) {}
  void add_edge(int from, int to, T cap) {
    assert(from != to);
    assert(cap >= 0);
    g[from].emplace_back(Edge{to, (int) g[to].size(), cap});
    g[to].emplace_back(Edge{from, (int) g[from].size() - 1, 0});
  }
  void bfs(int s) {
    fill(begin(dist), end(dist), -1);
    queue<int> que;
    dist[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (const auto& e : g[v]) {
        if (dist[e.to] != -1 or e.cap <= 0) continue;
        dist[e.to] = dist[v] + 1;
        que.push(e.to);
      }
    }
  }
  T dfs(int v, int s, T f) {
    if (v == s) return f;
    for (; i[v] < g[v].size(); ++i[v]) {
      Edge& e = g[v][i[v]];
      if (dist[e.to] >= dist[v] or g[e.to][e.rev].cap <= 0) continue;
      T d = dfs(e.to, s, min(f, g[e.to][e.rev].cap));
      if (d > 0) {
        g[e.to][e.rev].cap -= d;
        e.cap += d;
        return d;
      }
    }
    return 0;
  }
  T max_flow(int s, int t) {
    assert(s != t);
    T res = 0;
    while (true) {
      bfs(s);
      if (dist[t] == -1) return res;
      fill(begin(i), end(i), 0);
      while (true) {
        T f = dfs(t, s, inf);
        if (f == 0) break;
        res += f;
      }
    }
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w, c; cin >> h >> w >> c;
  VV<> b(h, V<>(w));
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
    cin >> b[i][j];
  }
  auto idx = [&](int i, int j) -> int {
    return i * (w - 1) + j >> 1;
  };
  int S = (h - 1) * (w - 1) + 1 >> 1, T = S + 1;
  Dinic<lint> g(T + 1);
  for (int i = 0; i < h - 1; i += 2) {
    for (int j = 0; j < w - 1; j += 2) {
      g.add_edge(S, idx(i, j), c);
      lint sum = 0;
      if (i == 0 or j == 0) sum += b[i][j];
      else g.add_edge(idx(i, j), idx(i - 1, j - 1), b[i][j]);
      if (i == 0 or j + 1 == w - 1) sum += b[i][j + 1];
      else g.add_edge(idx(i, j), idx(i - 1, j + 1), b[i][j + 1]);
      if (i + 1 == h - 1 or j == 0) sum += b[i + 1][j];
      else g.add_edge(idx(i, j), idx(i + 1, j - 1), b[i + 1][j]);
      if (i + 1 == h - 1 or j + 1 == w - 1) sum += b[i + 1][j + 1];
      else g.add_edge(idx(i, j), idx(i + 1, j + 1), b[i + 1][j + 1]);
      if (sum) g.add_edge(idx(i, j), T, sum);
    }
  }
  for (int i = 1; i < h - 1; i += 2) {
    for (int j = 1; j < w - 1; j += 2) {
      g.add_edge(idx(i, j), T, c);
    }
  }
  lint res = 0;
  for (int i = 0; i < h; ++i) {
    res += accumulate(begin(b[i]), end(b[i]), 0LL);
  }
  res -= g.max_flow(S, T);
  cout << res << '\n';
}


Measured memory_bytes: 3360
S = input()
ac = True
if S[0] != 'A':
  ac = False
if S[2:-1].count('C') != 1:
  ac = False
UC = ''
for s in S:
  if ord(s) < 97:
    UC += s
if UC != 'AC':
  ac = False
print('AC' if ac else 'WA')


Measured memory_bytes: 2940
mod=10**9+7
ferumaC=300000
fac=[0 for i in range(ferumaC)]
fac[0]=1
ifac=[0 for i in range(ferumaC)]
ifac[0]=1
def mpow(x,n):
    num=1
    while n > 0:
        if n&1:
            num=num*x%mod
        x=x*x%mod
        n=n>>1
    return(num)

for i in range(0,ferumaC-1):
    fac[i+1]=(fac[i]*(i+1))%mod
    ifac[i+1]=ifac[i]*mpow(i+1,mod-2)%mod
def comb(a,b):
    if a==0 and b==0:return(1)
    if a<b or a<0:return(0)
    tmp=ifac[a-b]*ifac[b]%mod
    return(tmp*fac[a]%mod)


from fractions import gcd
def lcm(a,b):
    return(a*b//gcd(a,b))

N=int(input())
A=list(map(int,input().split()))

value=A[0]
for i in range(1,N):
    value=lcm(value,A[i])
value%=mod
count=0
for a in A:
    count+=value*(mpow(a,mod-2))%mod
    count%=mod
print(count)


Measured memory_bytes: 73096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    int n;
    cin >> n;
    vector<double> last(1,1.0);
    rep(i,1,n+1) {
        vector<double> dp(i+1);
        double p;
        cin >> p;
        rep(j,0,i+1) {
            if(j>0) dp[j]=p*last[j-1];
            if(j<i) dp[j]+=(1-p)*last[j];
        }
        swap(dp,last);
    }
    double ans=0;
    rep(i,(n+1)/2,n+1) {
        ans+=last[i];
    }
    cout<<setprecision(12);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Refreshment Area
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0632

"""
import sys


def solve(area, n, m, d):
    ans = 0
    for y in range(n):
        for x in range(m):
            horizontal = area[y][x:x+d]
            ans += '.' * d in horizontal
            vertical = ''.join([area[yy][x] for yy in range(y, n)])[:d]
            ans += '.' * d in vertical
    return ans


def main(args):
    n, m, d = map(int, input().split())
    area = [input() for _ in range(n)]
    ans = solve(area, n, m, d)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



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

int main() {
    int N, X, T, ans = 0;
    cin >> N >> X >> T;
    if (X > N) {
        cout << T;
    } else if ((N % X) == 0) {
        ans = N / X * T;
        cout << ans;
    } else {
        ans = (N / X + 1) * T;
        cout << ans;
    }
}

Measured memory_bytes: 3528
#include<stdio.h>
#include<math.h>
int main()
{
	int i, n;
	double x[101], y[101], D1 = 0, D2 = 0, D3 = 0, Dmax = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%lf", &x[i]);	/*入力 %lf*/
	for (i = 0; i < n; i++)
		scanf("%lf", &y[i]);

	/* When p = 1*/
	for (i = 0; i < n; i++){
		double hako = 0.0;
		hako = x[i] - y[i];
		if (hako < 0)
			hako = -1 * hako;
		D1 += hako;
	}

	/* When p = 2*/
	for (i = 0; i < n; i++){
		double hako = 0;
		hako = (x[i] - y[i]) * (x[i] - y[i]);
		D2 += hako;
	} D2 = sqrt(D2);

	/* When p = 3*/
	for (i = 0; i < n; i++){
		double hako = 0;
		hako = (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
		if (hako < 0)
			hako *= -1;
		D3 += hako;
	} D3 = cbrt(D3);

	double hako = 0, hako2 = 0;
	/* When p = ∞*/
	for (i = 0; i < n; i++){
		hako = x[i] - y[i];
		if (hako < 0)
			hako *= -1;
		if (hako2 < hako)
			hako2 = hako;
	} Dmax = hako2;

	printf("%f\n", D1);
	printf("%f\n", D2);
	printf("%f\n", D3);
	printf("%f\n", Dmax);

	return(0);
}


Measured memory_bytes: 2108
#include <stdio.h>

#define MAX_NUM 1000000007

int main(void) {
	long long int a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	if ((c < a) || (c < b)) {
		printf("No\n");
	}
	else if ((4 * a * b) < (c - (a + b)) * (c - (a + b))) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
while 1:
    H,W = map(int,input().split())
    if H ==0:break
    for i in range(H):
        if i%2==0:
        
            for j in range(W):
                if j%2 == 0:print("#",end="")
                else:print(".",end="")

            else:print("")
            
        else:
            for j in range(W):
                if j%2 == 1:print("#",end="")
                else:print(".",end="")

            else:print("")
            
    else:print("")



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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using i32 = int;
using i64 = long long;

using namespace std;

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

    i64 n;cin >> n;
    vector<i64> s(n);
    REP(i,n)cin >> s[i];

    i64 ans = 0;
    for(i64 C = 1;C < n - 1;C++){
        map<i64,i32> used;
        i64 tmp = 0;
        for(i64 k = 0;(k+1) * C < n-1;k++){
           if(used[(n-1)-k*C]++ || used[k*C]++)break;
           tmp += s[(n-1) - k*C] + s[k*C];
           ans = max(ans , tmp);
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 10328
S = input()

ans = 0
if len(S) == 1:
    ans = int(S)
else:
    for i in range(2**(len(S)-1)):
        tmp = S[0]
        for j, b in enumerate(format(i, 'b').zfill(len(S)-1)):
            if b == '1':
                tmp += '+'
            tmp += S[j+1]
        ans += eval(tmp)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e21 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl


/*--------------------template--------------------*/

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

    for (int i = n; i > 0; i--) {
        if (s.substr(n - i) == t.substr(0, i)) {
            cout << n + t.substr(i).size() << endl;
            return 0;
        }
    }
    cout << 2 * n << endl;
}

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for _ in range(N)]
L = set([0])
i = 0
cnt = 0
while True:
    if a[i]-1 == 1:
        cnt += 1
        break
    elif a[i]-1 in L:
        cnt = -1
        break
    else:
        L.add(a[i]-1)
        cnt += 1
        i = a[i]-1
print(cnt)

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

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

    if((b-a) != (c-b)){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int H, W;
char C[101][101];
int main() {
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> C[i][j];
        }
    }
    for (int i = 1; i <= 2*H; i++) {
        for (int j = 1; j <= W; j++) {
            cout << C[(i+1)/2][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#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

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int ans[N];
int a[N], added[N];
#define pii pair<int, int>
vector<pii> v[N];
int BIT[N];
void upd(int idx, int val){
    //trace(idx, val);
    while(idx<N){
        BIT[idx] += val;
        idx += idx & (-idx);
    }
}
int query(int idx){
    if (idx<1) return 0;
    int ret = 0;
    int idx1 = idx;
    while(idx){
        ret += BIT[idx];
        idx -= idx & (-idx);
    }
    return ret;
}
int main(){
    int n, q;
    sc(n);sc(q);
    fr(i, 1, n) sc(a[i]);
    fr(i, 1, q){
        int l, r;sc(l);sc(r);
        v[r].pb({l, i});
    }
    fr(i, 1, n){
        //trace(i);
        if (added[a[i]]){
            upd(added[a[i]], -1);
        }
        added[a[i]] = i;
        upd(added[a[i]], 1);
        for(auto pp: v[i]){
            int l = pp.fi;
            int idx = pp.se;
            ans[idx] = query(i) - query(l-1);
        }
    }
    fr(i, 1, q){
        pr(ans[i]);
    }n_l;
    return 0;
}



Measured memory_bytes: 44996
/* Bismillahirrahmanirrahim
   Semoga Dapet AC ya Allah
   Amin.................. :)
*/
#include<bits/stdc++.h>
#define forA for(int i=0; i<a; i++)
#define ll long long
#define F first
#define S second
using namespace std;

int main(){
	int a, b, c, d, e;
	cin >> a >> b;
	cin >> c >> d;
	if((a==c)&&(b==d)) cout << 0;
	else{
		a-=c;
		e=a;
		a*=b;
		a-=e*d;
		cout << a;
	}
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum_a = 0
r = 0
for l in range(n):
    while r < n:
        x = a[r]
        if sum_a & x != 0:
            break
        sum_a += x
        r += 1
    ans += r - l
    sum_a -= a[l]
print(ans)

Measured memory_bytes: 24840
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define ls rt<<1
#define rs rt<<1|1
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const double PI = acos(-1.0);
const long double eps = 1e-14;
const int MAXN = 5e5+5;
const ll MOD = 1e9+7;

int main()
{
    long double a, b, c;
    cin >> a >> b >> c;
    if (sqrt(a) + sqrt(b) - sqrt(c) < -eps) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        n: usize,
        a: [i64; n]
    }

    for i in &a {
        if *i == 0 {
            println!("0");
            return;
        }
    }

    let mut ans: i64 = 1;
    for i in &a {
        if 1000000000000000000 / i < ans {
            println!("-1");
            return;
        }
        ans *= i;
    }
    println!("{}", ans);
}


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

int N;
struct Robot {
  ll X, L;
};

int main() {
  cin >> N;
  vector<Robot> R(N);
  rep(i, N) cin >> R[i].X >> R[i].L;

  sort(all(R),
       [&](const Robot& a, const Robot& b) { return a.X + a.L < b.X + b.L; });

  ll ans = 0, x = -1e10;
  rep(i, N) {
    if (x <= R[i].X - R[i].L) {
      ++ans;
      x = R[i].X + R[i].L;
    }
  }

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


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

int cnt[2005][2005], s[2005][2005];
char in[5];

inline int sum(int u, int d, int l, int r)
{
    return s[d][r] - s[d][l-1] - s[u-1][r] + s[u-1][l-1];
}
int main()
{
    int n,k,ws=0;
    scanf("%d%d",&n,&k);
    int m = k*2;
    for(int i=0;i<n;i++)
    {
        int x,y;
        scanf("%d%d%s",&x,&y,in);
        x = x%m+1;
        y = y%m+1;
        if(in[0] == 'B') cnt[y][x]++;
        else
        {
            ws++;
            cnt[y][x]--;
        }
    }
    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + cnt[i][j];
    int ans = -1e9;
    for(int y=1;y<=k;y++)
        for(int x=1;x<=k;x++)
        {
            int yy = y+k, xx = x+k;
            int tmp = sum(yy,m,x,xx-1) + sum(y,yy-1,xx,m) + sum(y,yy-1,1,x-1) + sum(1,y-1,x,xx-1);
            if(tmp > ans) ans = tmp;
            tmp = sum(yy,m,xx,m) + sum(yy,m,1,x-1) + sum(y,yy-1,x,xx-1) + sum(1,y-1,xx,m) + sum(1,y-1,1,x-1);
            if(tmp > ans) ans = tmp;
        }
    ans += ws;
    printf("%d\n",ans);
}


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

typedef long long ll;

#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
 
int main()
{
    int k, a, b;
 
    cin >> k;
    cin >> a >> b;
 
    FOR(i, a, b) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
 
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0

#二乗和だけは1項ずつ求めてmodをとる
#for x in A:
#  sum += x
#  sum %= (10**9+7)
sum = A.sum() % (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)
#sum2 = (A**2).sum() % (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))


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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

char maze[410][410];
bool isReached[410][410];
int H, W;
int dh [] = {1, -1, 0, 0};
int dw [] = {0, 0, 1, -1};
ll B_cnt = 0;
ll W_cnt = 0;
ll ans = 0;

vector<pair<int, int>> start;
vector<pair<int, int>> nums;

void dfs(int h, int w) {
    isReached[h][w] = true;

    if (maze[h][w] == '#') {
        B_cnt += 1;
    } else {
        W_cnt += 1;
    }

    rep(i, 4) {
        int nh = h + dh[i];
        int nw = w + dw[i];
        if (0 > nh or nh >= H or 0 > nw or nw >= W) continue;
        if (maze[h][w] == maze[nh][nw]) continue;
        if (isReached[nh][nw]) continue;
        dfs(nh, nw);
    }
}

int main() {
    cin >> H >> W;
    rep(i, H) rep(j, W) {
        cin >> maze[i][j];
    }

    rep(i, H) rep(j, W) {
        if (maze[i][j] == '.') continue;
        if (isReached[i][j]) continue;
        B_cnt = 0;
        W_cnt = 0;
        dfs(i, j);
        ans += B_cnt * W_cnt;
    }


    cout << ans << endl;
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		int[][] a = new int[n][m];
		int[] b = new int[m];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				a[i][j] = scan.nextInt();
			}
		}

		for(int i = 0; i < m; i++) {
			b[i] = scan.nextInt();
		}

		for(int i = 0; i < n; i++) {
			int result = 0;
			for(int j = 0; j < m; j++) {
				result += a[i][j] * b[j];
			}
			System.out.println(result);
		}

		scan.close();
	}
}



Measured memory_bytes: 40580
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
    int num = 0;
    int temp = 0;
    while (s) {
        temp = s % 10;
        num += temp;
        s = s / 10;
    }
    return num;
}

int countDivisorNum(int n) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            count++;
        }
    }
    return count;
}


int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans = 0;

    ll temp1 = 0;
    ll temp2 = 0;
//    ll temp3 = 0;
//    ll temp = 0;
    if (n >= b) {
        temp1 = (a * (b - 1)) / b;
        temp2 = (a * ((b - 1) / b));
        ans = temp1 - temp2;
//        for (n; n >= b - 1; n--) {
//            temp1 = (a * n) / b;
//            temp2 = (a * (n / b));
//            temp3 = temp1 - temp2;
//            if (temp3 >= ans) {
//                ans = temp3;
//            }
//        }
    } else {
        temp1 = (a * n) / b;
        temp2 = (a * (n / b));
        ans = temp1 - temp2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
int main(void){
    int i;
    char c[1300];
    while(1){
        scanf("%c",&c[i]);
        if(c[i]>=97)printf("%c",toupper(c[i]));
        else printf("%c",tolower(c[i]));
        if(c[i]=='\n')break;
    }
    return 0;
 }

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


int main() {
    long long N;
    cin>>N;
    long long ans=0;

    for(long long i=1;i*i<=N;i++){
        int count=0;
        if(N%i==0){
            long gc = N/i;
            while(gc!=0){
                gc = gc/10;
                count++;
            }
            if(ans==0){
                ans = count;
            }else{
                if(ans>count){
                    ans = count;
                }
            }

        }


    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Random;

//The Closest Circle
public class Main{

	class Scanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-') return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
	
	class R implements Comparable<R>{
		double x, y, r;
		public R(double x, double y, double r) {
			this.x = x;
			this.y = y;
			this.r = r;
		}
		public int compareTo(R o) {
			if(Math.abs(x-o.x)<EPS)return (int)Math.signum(y-o.y);
			return (int)Math.signum(x-o.x);
		}
	}
	
	double EPS = 1e-8;
	
	void run(){
		Scanner sc = new Scanner();
		Random rand = new Random(System.currentTimeMillis());
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int rot = rand.nextInt(44)+1;
			double sin = Math.sin(rot*Math.PI/180), cos = Math.cos(rot*Math.PI/180);
			R[] rs = new R[n];
			for(int i=0;i<n;i++){
				double r = sc.nextDouble(), x = sc.nextDouble(), y = sc.nextDouble();
				rs[i] = new R(cos*x-sin*y, sin*x+cos*y, r);
			}
			Arrays.sort(rs);
			double res = 1L<<60;
			for(int i=0;i<n;i++){
				int t = Math.min(n, i+20);
				for(int j=i+1;j<t;j++){
					res = Math.min(res, Math.sqrt((rs[i].x-rs[j].x)*(rs[i].x-rs[j].x) + (rs[i].y-rs[j].y)*(rs[i].y-rs[j].y))-rs[i].r-rs[j].r);
				}
			}
			System.out.printf("%.9f\n", res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 19000
c1 = list(map(int, input().strip().split()))
c2 = list(map(int, input().strip().split()))
c3 = list(map(int, input().strip().split()))

if c1[1]-c1[0] != c2[1]-c2[0] or c3[1]-c3[0] != c1[1]-c1[0] or c2[1]-c2[0] != c3[1]-c3[0]:
    print("No")
elif  c1[2]-c1[1] != c2[2]-c2[1] or c3[2]-c3[1] != c1[2]-c1[1] or c2[2]-c2[1] != c3[2]-c3[1]:
    print("No")
elif  c2[1]-c1[0] != c2[1]-c1[0] or c3[1]-c2[0] != c3[1]-c2[0] or c1[1]-c3[0] != c1[1]-c3[0]:
    print("No")
elif  c2[2]-c1[1] != c2[2]-c1[1] or c3[2]-c2[1] != c3[2]-c2[1] or c1[2]-c3[1] != c1[2]-c3[1]:
    print("No")
else:
    print("Yes")
    

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

int main(){
    int N;
    cin >> N;
    int t[N+1]={0},v[N+1]={300};
    for(int i=0;i<N;i++){
        cin >> t[i+1];
        t[i+1]+=t[i];
    }
    int vm=0;
    for(int i=0;i<N;i++){
        cin >> v[i+1];
        vm=max(vm,v[i+1]);
    }
    v[N+1]=0;
    double dp[2*t[N]+2][2*vm+2];
    for(int i=0;i<2*t[N]+2;i++){
        for(int j=0;j<2*vm+2;j++){
            dp[i][j]=0;
        }
    }
    int c=1;
    for(int i=1;i<=2*t[N];i++){
        if(i==2*t[c]&&v[c]>v[c+1]) c++;
        for(int j=0;j<=2*v[c];j++){
            double a=0,b=0,c=0;
            if((dp[i-1][j-1]!=0&&j!=0)||j==1)a=dp[i-1][j-1]+(double)(2*j-1)/8;
            if(dp[i-1][j]!=0)b=dp[i-1][j]+(double)j/4;
            if(dp[i-1][j+1]!=0)c=dp[i-1][j+1]+(double)(2*j+1)/8;
            dp[i][j]=max({a,b,c});
        }
        if(i==2*t[c]&&v[c]<=v[c+1]) c++;
    }
    printf("%f\n",dp[2*t[N]][0]);
    return 0;
}

Measured memory_bytes: 33920
#include <iostream>
#include <cstring>
using namespace std;
int N, G;
int V[105], W[105];
int w;
int DP[105][105][405];
void Read()
{
    cin >> N >> G;
    for(int i = 1; i <= N; i++)
        cin >> W[i] >> V[i];
    w = W[1];
    for(int i = 1; i <= N; i++)
        W[i] -= w - 1;
}

void Solve()
{
    memset(DP, -1, sizeof(DP));
    DP[0][0][0] = 0;
    int g = 4 * N;
    for(int i = 1; i <= N; i++)
    {
        DP[i][0][0] = 0;
        for(int j = 1; j <= N; j++)
        {
            for(int k = 1; k <= g; k++)
                DP[i][j][k] = DP[i - 1][j][k];
            for(int k = W[i]; k <= g; k++)
            {
                int val = DP[i - 1][j - 1][k - W[i]];
                if(val == -1)
                    continue;
                DP[i][j][k] = max(DP[i][j][k], val + V[i]);
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= N; i++)
        for(int j = 1; j + 1LL * (w - 1) * i <= G && j <= g; j++)
        {
            ans = max(ans, DP[N][i][j]);
        }
    cout << ans << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int n,cnt=0;
int x[N],y[N],m,X,Y,cmp;
char step[35]; 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&x[i],&y[i]);
		if((x[i]+y[i])&1)cnt++;
		else cnt--;
	}
	if(abs(cnt)!=n){cout<<-1<<endl;return 0;}
	m=31+(cnt<0);
	printf("%d\n",m);
	for(int i=0;i<=30;i++)printf("%d ",1<<i);
	if(cnt<0)cout<<1;
	cout<<endl;
	for(int i=1;i<=n;i++){
		X=x[i];Y=y[i];cmp=0;
		if(cnt<0)step[31]='R',X--;
		for(int j=30;j>=0;j--){
			if(abs(X)<abs(Y))swap(X,Y),cmp^=1;
			if(X>0)X-=1<<j,step[j]=cmp?'U':'R';
			else X+=1<<j,step[j]=cmp?'D':'L';
		}
		printf("%s\n",step);
	}
	return 0;
}

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

int main(void)
{
	char str[21] = {};
	char str2[21] = {};
	int len;
	int i = 0;
	fgets(str,21,stdin);
	len = strlen(str);
	
	for(i = 0; i < len; i++){
	    str2[i] = str[len - i - 1];
	}
	
	printf("%s\n",str2);
	
	

	return 0;
}


Measured memory_bytes: 2052
#include<stdio.h>
int main(void){
	double a,b,c,d,e,f;
	double x,y;
	while(scanf("%lf",&a)!=EOF){
		scanf("%lf %lf %lf %lf %lf",&b,&c,&d,&e,&f);
		x=(c*e-b*f)/(a*e-b*d);
		if(x==-0){
			x=0;
		}
		y=(c*d-a*f)/(b*d-a*e);
		if(y==-0){
			y=0;
		}
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> d(N);
  for(int i=0; i<N; i++){
    cin>>d.at(i);
  }
  int ans = 0;
  for(int i=0; i<N;i++){
    for(int j=0; j<N; j++){
      if(i != j){
      ans += d.at(i)*d.at(j);
      }
    }
  }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 256
NK=list(map(int,input().split()))
d=[0]*NK[1]
A_list=[]

for j in range(NK[1]):
    d[j-1]=int(input())
    A_in=list(map(int,input().split()))
    A_list.append(A_in)

N_list=list(range(1,NK[0]+1))
A_sort=[]
for A in A_list:
    for a in A:
        A_sort.append(a)
print(NK[0]-len(set(A_sort)))

Measured memory_bytes: 9236
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
    arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
    for (auto& i : arr) {
        fill_all(i, v);
    }
}

int32_t N;

std::pair<int64_t, int64_t> A[3000];
int64_t dp[3000][3000];
int64_t func(int i, int l, int r)
{
    if (i == N) {
        return 0;
    }
    auto& memo = dp[i][l];
    if (memo >= 0) {
        return memo;
    }

    memo = 0;
    //l
    memo = std::max(memo, A[i].first* (A[i].second - l) + func(i + 1, l + 1, r));
    //r
    memo = std::max(memo, A[i].first * (N-r-1 - A[i].second) + func(i + 1, l, r + 1));

    return memo;
}


int main()
{
    fill_all(dp, -1);

    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    in >> N;
    for (size_t i = 0; i < N; i++)
    {
        in >> A[i].first;
        A[i].second = i;
    }
    std::sort(A, A + N, std::greater<>{});

    out << func(0, 0, 0) << endl;

    return 0;
}
#endif


Measured memory_bytes: 73628
#include<bits/stdc++.h>
#define N 10010
#define rep(i, l, r) for(register int i = l; i <= r; ++i)
using namespace std;
int main()
{
	string a;
	cin>>a;
	int b;
	if(a=="SAT") printf("1\n");
	else if(a=="SUN") printf("7\n");
	else if(a=="MON") printf("6\n");
	else if(a=="TUE") printf("5\n");
	else if(a=="WED") printf("4\n");
	else if(a=="THU") printf("3\n");
	else if(a=="FRI") printf("2\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
int a[3], b;
scanf("%d %d %d", a, a + 1, a + 2);
if (a[1] > a[2])
{
b = a[1];
a[1] = a[2];
a[2] = b;
}
if (a[0] > a[1])
{
b = a[0];
a[0] = a[1];
a[1] = b;
}
if (a[1] > a[2])
{
b = a[1];
a[1] = a[2];
a[2] = b;
}
printf("%d %d %d\n", a[0], a[1], a[2]);
 
return 0;
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
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(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ASubscribers {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n, a, b;
	    in >> n >> a >> b;
	    out << min(a, b) sp max(0, a+b-n) << endl;
	}
};


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


Measured memory_bytes: 256
N,M = map(int,input().split())
ABC = []
for i in range(M):
  a,b,c=map(int,input().split())
  c=-c
  ABC.append([a,b,c])

def BellmanFord():
  inf=float("Inf")
  dist=[inf for i in range(N)]
  dist[0]=0
  
  for i in range(N):
    for edge in ABC:
      if dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
        dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
        if i==N-1 and edge[1]-1==N-1: return inf
    
  return -dist[N-1]
  
print(BellmanFord())

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

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> P2;
const ll inf=100000000000000001;
vector<int> v[100001];

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n-1;++i){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	queue<P> que;
	int dp[100001]={};
	que.push(P(1,1));
	while(!que.empty()){
		P p1=que.front();que.pop();
		int to=p1.first;
		int cost=p1.second;
		if(dp[to]>0)continue;
		dp[to]=cost;
		for(auto it:v[to])que.push(P(it,cost+1));
	}
	int f=(dp[n]-1)/2+1;
	int s=n;
	for(int i=dp[n];i>f;--i){
		for(auto it:v[s]){
			if(dp[it]==i-1&&dp[it]>=f+1){
				s=it;
				break;
			}
		}
	}
	int t=0;
	que.push(P(s,1));
	while(!que.empty()){
		P p1=que.front();que.pop();
		int to=p1.first;
		int cost=p1.second;
		t++;
		for(auto it:v[to]){
			if(dp[it]>dp[to])que.push(P(it,cost+1));
		}
	}
//	cout<<t;
	if(t<n-t){
		cout<<"Fennec"<<endl;
	}else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}


Measured memory_bytes: 6528
import fractions
N,M=map(int,input().split())
S=input()
T=input()

n=N//fractions.gcd(N,M)
m=M//fractions.gcd(N,M)
g=fractions.gcd(N,M)
judge=True

for i in range(g):
    if S[i*n]!=T[i*m]:
        judge=False

if judge==True:
    print(N*M//g)
else:
    print(-1)

Measured memory_bytes: 5436
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main(){
	while(true){
		string num;
		cin >> num;
		if(num.at(0) == '0') break;
		
		int total = 0;
		for(int i = 0; i < num.size(); i++){
			total += num.at(i) - '0';
		}
		
		cout << total << endl;
		
	}
}





Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

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

void Integer_factorization(ll factor[],ll n){
    ll a = 2;
    bool flag = false;
    for(int p = 2;p*p <= n;p++){
        while(n%p == 0){
            n/=p;
            factor[p]++;
        }
    }
    if(n!=1)  factor[n]++; //prime num
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
   int n; cin >> n;
   int a;cin >> a;
   if(n%500 <= a) ys();
   else ns();
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = do
    [a, b, x] <- map read . words <$> getLine
    putStrLn $ solve a b x
    
solve :: Int -> Int -> Int -> String
solve a b x = if (length [y | y <- [0..b], y + a == x]) > 0 then "YES" else "NO"

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define debug(x) cout << (x) << "\n";
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max();
constexpr auto llinf = numeric_limits<ll>().max();

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << *it << " ";
	}
	cout << "\n";
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << (*it).first << ":" << (*it).second << " ";
	}
	cout << "\n";
}

void solve() {
  int n, x;
  cin >> x >> n;
  set<int> p;
  rep(i, n) {
    int g;
    cin >> g;
    p.insert(g);
  }
  auto diff = 0;
  while (true) {
    auto num1 = x - diff;
    auto num2 = x + diff;
    if (p.find(num1) == p.end()) {
      printf("%d\n", num1);
      return;
    }
    if (p.find(num2) == p.end()) {
      printf("%d\n", num2);
      return;
    }
    ++diff;
  }
	cout << "\n";
}

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

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 987654321
#define PI 3.1415926535

vector<int> adj[100001];
int tvisit[100001], avisit[100001];
int parent[100001];

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

    int n, u, v;
    cin >> n >> u >> v;

    int a, b;
    for(int i=0; i<n-1; i++) {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    queue<int> qt, qa;
    qt.push(u);
    qa.push(v);
    int mx=-1;
    while(!qt.empty() || !qa.empty()) {
        int s=qt.size();
        for(int i=0; i<s; i++) {
            int cur=qt.front();
            qt.pop();
            if(cur==v || avisit[cur]) continue;
            for(int next : adj[cur]) {
                if(tvisit[next] || next==u) continue;
                tvisit[next]=tvisit[cur]+1;
                if(next==v || avisit[next]) {
                    mx=max(mx, avisit[next]);
                    continue;
                }
                qt.push(next);
            }
        }
        
        int s2=qa.size();
        for(int i=0; i<s2; i++) {
            int cur=qa.front();
            qa.pop();
            for(int next : adj[cur]) {
                if(avisit[next] || next==v) continue;
                avisit[next]=avisit[cur]+1;
                if(tvisit[next]==avisit[next]) {
                    mx=max(mx, avisit[next]);
                }
                else if(tvisit[next] || next==u) {
                    mx=max(mx, avisit[next]-1);
                }
                qa.push(next);
            }
        }
    }

    cout << mx;
}

Measured memory_bytes: 6656
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

constexpr ll inf=1e9;
int main()
{
    ll h=in(),n=in();
    map<ll,ll>waza;
    for(ll i=0;i<n;++i){
        ll a=in(),b=in();
        if(waza.count(a)==0||waza[a]>b)waza[a]=b;
    }

    auto ans=vec2<ll>(waza.size()+1,h+1,inf);
    ans[0][0]=0;
    auto itr=waza.begin();
    for(ll i=1;i<=waza.size();++i,++itr){
        ll d=itr->first,m=itr->second;
        for(ll j=0;j<=h;++j){
            for(ll k=0;;++k){
                ans[i][j]=min(ans[i][j],ans[i-1][max(0ll,j-k*d)]+k*m);
                if(j-k*d<=0)break;
            }
        }
    }
    cout<<ans.back().back()<<endl;
}


Measured memory_bytes: 78592
s = input() + 'R'

x = []
y = 'R'
a = b = 0
for i in range(len(s)):
    if y == 'R':
        if s[i] == 'R':
            a += 1
        else:
            y = 'L'
            b = 1
    else:
        if s[i] == 'L':
            b += 1
        else:
            y = 'R'

            # print(a, b)
            p = [0] * (a-1)
            q = [0] * (b-1)

            if (a + b) % 2 == 0:
                c = (a+b) // 2
                a = c
                b = c
            elif a % 2 == 1 and b % 2 == 0:
                a, b = (a+1)//2 + b//2, (a-1)//2 + b//2
            else:
                a, b = a//2 + (b-1)//2, a//2 + (b+1)//2
            # elif a % 2 == 0 and b % 2 == 1:
            #     a, b = b, a
            x += p + [a] + [b] + q

            a = 1
            b = 0


print(' '.join([str(xi) for xi in x]))


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

using namespace std;

int
main(void){
	int n; cin >> n;
	vector<int> vec(n);
	vector<int> mp1(100001, 0);
	for(int i = 0; i < n; i++) cin >> vec[i];
	for(int i = 0; i < n; i++){
		mp1[vec[i]]++;
	}
	
	int ans = 0;
	for(int i = 1; i < 100000; i++){
		ans = max(ans, mp1[i] + mp1[i - 1] + mp1[i + 1]);
	}

	ans = max(ans, max(mp1[100000] + mp1[100000 - 1], mp1[0] + mp1[1]));
	cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    CINVEC(S);

    SORT(S);
    REP(i, N) {
        cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (n, m) = readLine()!!.split(" ").map { it.toInt() }
  val connected = Array(m, { BooleanArray(n) })
  repeat(m) {
    val ss = readLine()!!.split(" ").map { it.toInt() }
    for (i in 1 until ss.size) {
      connected[it][ss[i] - 1] = true
    }
  }
  val ps = readLine()!!.split(" ").map { it.toInt() }

  val ans = (0 until (1 shl n)).count { pattern ->
    val ons = BooleanArray(n, { (pattern and (1 shl it)) != 0 })
    (0 until m).all { lightId ->
      (0 until n).count { switchId -> connected[lightId][switchId] && ons[switchId] } % 2 == ps[lightId]
    }
  }
  println(ans)
}

Measured memory_bytes: 38124