akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

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

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

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


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

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

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class CPrison {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        int left = 1, right = n;
        FOR(i, 0, m) {
            int l, r;
            in >> l >> r;
            ckmax(left, l);
            ckmin(right, r);
        }
        int res = max(right - left + 1, 0);
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    CPrison solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int a[N], b[N];

signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n;  cin >> n;
    for(int i = 1; i <= n+1; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        cin >> b[i];   
    int ans = 0;
    for(int i = n; i >= 1; i--){
        int x = min(a[i+1], b[i]);
        ans += x;
        a[i+1] -= x;    b[i] -= x;
        x = min(a[i], b[i]);
        ans += x;
        a[i] -= x;  b[i] -= x;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[5];
	for(int i=0;i<5;i++)cin>>a[i];
	sort(a,a+5);
	int k;
	cin>>k;
	puts(k>=a[4]-a[0]?"Yay!":":(");
	return 0;
}

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

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = a; i <= b; i++)
    {
        if (i - a < k || b - i < k)
        {
            cout << i << endl;
        }
        /* code */
    }

    return 0;
}

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

using namespace std;


typedef long long ll;
ll mod=1e9+0LL;
ll MOD=1e18+0LL;
double pi=acos(-1);


int main()
{
    int cs=1;
    //scanf("%d",&cs);
    while(cs--)
    {
        double A,B,M,H,m,h,ans,PI=acos(-1),theta;
        cin>>A>>B>>H>>M;
        m=6.0*M;
       // m/=180.00;
        h=.5*((60*H)+M);
       // h/=180.00;
        //h+=(6.0/360.0)*m;
        theta=min(abs(h-m),abs(m-h));
        theta=(PI*theta)/180.00;
        ans=(A*A)+(B*B)-(2*A*B*cos(theta));
        ans=sqrt(ans);
        printf("%.10lf",ans);
    }
}


Measured memory_bytes: 4200
object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  val tasks = Array.fill(n){
    readLine.trim.split(' ').map(_.toInt) match {
      case Array(a, b) => Task(a, b)
    }
  }
  println(
    if (tasks.sortBy(_.limit).foldLeft(Some(0): Option[Int]){(o, t) => o.map(_ + t.time).filter(_ <= t.limit)}.isDefined) "Yes" else "No"
  )
  case class Task(time: Int, limit: Int)
}


Measured memory_bytes: 121256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9

int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ll n,i,k,j;
    cin>>n>>k;
    ll h[n];
    rep(i,n)
    cin>>h[i];
    ll f[n];
    f[0]=0;
    // cout<<"e"<<endl;
    REP(i,1,n)
    {   f[i]=INT_MAX;
       
        REV(j,i,max((ll)0,i-k))
        {
             // cout<<h[j]-h[i]<<endl;
                f[i]=min(f[j]+abs(h[j]-h[i]),f[i]);
        }
        // cout<<i<<" "<<f[i]<<endl;
    }
    cout<<f[n-1]<<endl;
    
    
    return 0;
}

Measured memory_bytes: 5176
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=50000+10;
int a[34]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
	int n;
	cin>>n;
	cout<<a[n-1];
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  string S;

  cin >> N;
  cin >> S;

  int ans = 0;
  int list[N];

  for (int i = 0; i < N; ++i) {
    list[i] = S[i] - '0';
  }

  for (int a = 0; a <= 9; ++a) {
    for (int b = 0; b <= 9; ++b) {
      for (int c = 0; c <= 9; ++c) {
        int target[3] = {a, b, c};
        int idx = 0;

        for (int i = 0; i < N && idx < 3; ++i) {
          if (list[i] == target[idx]) {
            ++idx;
          }
        }

        if (idx == 3) {
          ++ans;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
x,n = map(int,input().split())
if n==0:
  print(x)
  exit(0)
  
lis = list(map(int,input().split()))
i=0

def judge(X):
  if (X not in lis) and (X >= 0):
    print(X)
    exit(0)
    
for j in range(100):
  judge(x-i)
  judge(x+i)
  i+=1

Measured memory_bytes: 9116
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			if (a == 0)
				break;
			int[] map = new int[5];
			boolean[] b = new boolean[4];
			map[0] = a;
			for (int i = 1; i < 5; i++) {
				map[i] = scanner.nextInt();
			}
			for (int aa : map) {
				b[aa] = true;
			}
			int sum = 0;
			for (int i = 1; i < 4; i++) {
				if (b[i])
					sum++;
			}
			if (sum == 3 || sum == 1)
				for (int i = 0; i < 5; i++)
					System.out.println(3);
			else if (!b[1]) {
				for (int i = 0; i < 5; i++) {
					if (map[i] == 2)
						System.out.println(1);
					else
						System.out.println(2);
				}
			} else if (!b[2]) {
				for (int i = 0; i < 5; i++) {
					if (map[i] == 3)
						System.out.println(1);
					else
						System.out.println(2);
				}
			} else {
				for (int i = 0; i < 5; i++) {
					if (map[i] == 1)
						System.out.println(1);
					else
						System.out.println(2);
				}
			}
		}
	}
}

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

const int MAX_N = (int)1e5 + 5;

int n, t[MAX_N], x[MAX_N], y[MAX_N];

int main(void){
  // Here your code !
  scanf("%d", &n);
  t[0] = 0; x[0] = 0; y[0] = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d %d", &t[i], &x[i], &y[i]);
  }

  for (int i = 1; i <= n; ++i) {
    int difft = t[i] - t[i - 1];
    int diffmh = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
    if (difft < diffmh) {
      printf("No\n");
      return 0;
    }
    else {
      if ((difft - diffmh) % 2 == 1) {
        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	long long Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;

	long long m1 = min({ 4 * Q, 2 * H, S });
	long long m2 = min({ 8 * Q, 4 * H, 2 * S, D });

	long long ans = (N / 2) * m2 + (N % 2) * m1;
	cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int x = tx-sx, y = ty-sy;

  rep(i, x) cout << "R";
  rep(i, y) cout << "U";
  rep(i, x) cout << "L";
  rep(i, y+1) cout << "D";
  rep(i, x+1) cout << "R";
  rep(i, y+1) cout << "U";
  cout << "L";
  cout << "U";
  rep(i, x+1) cout << "L";
  rep(i, y+1) cout << "D";
  cout << "R" << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

class Union_Find {
public:
  vector<int> par;

  Union_Find(int n) : par(n, -1) {}
  void init(int n) {
    par.assign(n, -1);
  }

  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  Union_Find uf(n);

  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i] -= 1; b[i] -= 1;
  }
  ll con = (n * (n-1)) / 2;
  vector<ll> comf;
  // comf.push_back(con);

  for (int i = m - 1; i >= 0; --i) {
    comf.push_back(con);
    if (uf.issame(a[i], b[i])) {
      continue;
    }
    ll ta = uf.size(a[i]), tb = uf.size(b[i]);
    con -= ta * tb;
    uf.merge(a[i], b[i]);
  }

  for (int i = m - 1; i >= 0; --i) {
    cout << comf[i] << endl;
  }
}


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

int main(){
  long long A,B,C,sum;
  int key=0;
  cin>>A>>B>>C;
  for(int i=1;i<=B;i++){
    sum =A*i%B;
    if(sum==C)key=1;
  }
  if(key==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

#define ll long long
#define f(i,a,n) for (int i=a;i<n;i++)
typedef pair<ll, ll> pa;
const ll mod=1000000007;
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin >> n;
    
    ll a[n + 1];
    double ans = 1;
    f(i, 1, n + 1) {
        cin >> a[i];
        ans *= a[i];
    }

    double b = ans;
    double deno = 0;

    f(i, 1, n + 1) {
        deno += b/a[i];
    }

    cout << setprecision(11) << ans/deno;

    return 0;
}

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

Measured memory_bytes: 1024
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
A = Counter(a)
count = 0
ans = 0
for number in A:
    if  A[number]%2 == 0:
        count += 1
    ans += 1

if count%2 == 0:
    print(ans)
else:
    print(ans-1)

Measured memory_bytes: 62124
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int N;
  cin >> N;
  int sum;
  for (int i=0; i<N; i++){
    int P, Q;
    cin >> P >> Q;
    sum += Q-P+1;
  }
  cout << sum << endl;
}


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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FDivisionOrSubstraction {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n; cin >> n;
      ll ans = 0;
      ll medk = 0;
      for(ll k=2; k*k<=n; k++) {
        ll tmp = n;
        while(tmp%k==0) {
          tmp/=k;
        }
        if (tmp%k == 1) {
          ans++;
        }
        medk = k;
      }

      for(ll p=1; p*p<n; p++) {
        if (p==1 || n%p == 1) {
          ll k = (n-1)/p;
          if (2 <= k && medk < k) {
            ans++;
          }
        }
      }
      // K=N
      ans += 1;
      cout << ans << endl;
    }
};

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

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

using namespace std;

int main(){
	char a,b;
	cin >> a >> b;
	if(a< b)
		cout << '<' << endl;
	else if(a == b)
		cout << '=' << endl;
	else
		cout << '>' << endl;
	
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int a = (s[0] == 'A') + (s[1] == 'A') + (s[2] == 'A');
  if(a > 0 and a < 3)
           cout << "Yes\n";
   else
           cout << "No\n";

  return 0;
}

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; cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];
  
  sort(d.begin(), d.end());
  
  cout << d[N/2]-d[N/2-1] << endl;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=4001000,mod=998244353;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
inline int ksm(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) res=1ll*res*a%mod;
	return res;
}
int fac[maxn],invfac[maxn];
inline int C(int n,int m){return 1ll*fac[n]*invfac[m]%mod*invfac[n-m]%mod;}
int n,m;
inline int cal(int n,int m,int lim)
{
	int ans=0;
	for(int i=0;i<=min(n,lim);i++) if(!((m-i)&1))
		Add(ans,1ll*C(n,i)*C((m-i)/2+n-1,n-1)%mod);
	return ans;
}
int main()
{
	for(int i=fac[0]=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[maxn-1]=ksm(fac[maxn-1],mod-2);
	for(int i=maxn-2;i>=0;i--) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	cin>>n>>m;printf("%lld\n",(cal(n,3*m,m)-1ll*n*cal(n,m,m)%mod+1ll*n*cal(n-1,m,m)%mod+mod)%mod);
	return 0;
}

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

int main() {
	int n,ans = 0;
	string s[310];
	cin >> n;
	for (int i = 0;i < n;++i) {
		string a;
		cin >> a;
		s[i] = a+a;
	}
	for (int i = 0;i < n;++i) {
		bool good = true;
		for (int j = 0;j < n;++j) {
			for (int k = 0;k < n;++k) {
				if (s[j][k+i] != s[k][j+i]) {
					good = false;
					break;
				}
			}
			if (!good) break;
		}
		if (good) ans++;
	}

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

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

#define int long long
#define MOD 1000000007

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

    string s;
    cin >> s;
    n *= 2;

    int ans = 1;

    int tmp = 0;

    for(int i = n-1;i >= 0;i--){
        int tt = (s[i] == 'B' ? 1 : 0) + tmp % 2;
        if(tt % 2 ==  0){
            if(tmp == 0 && s[i] == 'W'){
                cout << 0 << endl;
                return 0;
            }else{
                ans *= tmp;
                ans %= MOD;
                tmp--;
            }
        }else{
            tmp++;
        }
    }

    if(tmp != 0){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1;i <= n/2;i++){
        ans = (ans * i) % MOD;
    }

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









Measured memory_bytes: 640
N,M=list(map(int,input().split()))
S=[[0,0]]*N
for i in range(N):
  S[i]=list(map(int,input().split()))
C=[[0,0]]*M
for j in range(M):
  C[j]=list(map(int,input().split()))

INF=float('inf')
ans=[[0,INF]]*N
for i in range(N):
  for j in range(M):
    x=abs(S[i][0]-C[j][0])
    y=abs(S[i][1]-C[j][1])
    if x+y<ans[i][1]:
      ans[i]=[j+1,x+y]
for i in range(N):
  print(ans[i][0])

Measured memory_bytes: 68820
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr
 
def cmb(n,r,mod):
  a=1
  b=1
  r = min(r,n-r)
  for i in range(r):
    a = a*(n-i)%mod
    b = b*(i+1)%mod
  return a*pow(b,mod-2,mod)%mod

N,M = map(int,input().split())
MOD = 10**9+7
f = factorization(M)
ans = 1

for i,j in f:
  ans *= cmb(j+N-1,j,MOD)
  ans %= MOD
if M == 1:
  ans = 1
print(ans)

Measured memory_bytes: 9512
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

char ch[10];

int main()
{
	scanf("%s",ch+1);
	(ch[3]==ch[4]&&ch[5]==ch[6])?printf("Yes\n"):printf("No\n");
}

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

#define MAX_V 100000
#define MAX_E 500000
#define INF 1e9
int V, E,r;
int d[MAX_V];
struct edge {
	int from, to, cost;
};
edge es[MAX_E];

bool find_negative_loop(int s) {
	d[s] = 0;
	int count = 0;
	while (true) {
		count++;
		bool update = false;
		for (int i = 0; i < E; i++) {
		
			if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost) {
				update = true;
				if (count == V) {
					return true;
				}
				d[es[i].to] = d[es[i].from] + es[i].cost;
			}
		}
		if (update == false) {
			return false;
		}
	}
}

int main() {
	cin >> V >> E>>r;
	for (int i = 0; i < E; i++) {
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	for (int i = 0; i < V; i++) {
		d[i] = INF;
	}

	if (find_negative_loop(r)){
		cout << "NEGATIVE CYCLE" << endl;

     }
	else {
		for (int i = 0; i < V; i++) {
			if (d[i] == INF) {
				cout << "INF" << endl;
			}
			else {
				cout << d[i] << endl;
			}
		}
	}
	return 0;
}












Measured memory_bytes: 9208
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod


const ll MAXN=1000010;

ll bit[MAXN];
void add(ll a, ll w) {
for (ll x = a; x <= MAXN; x += (x & -x)) bit[x] += w;
}
ll sum(ll a) {
 ll ret = 0;
for (ll x = a; x > 0; x -= (x & -x)) ret += bit[x];
 return ret;
}

struct Qu{
    ll l; ll num;
    Qu(ll L, ll NUM){l=L; num=NUM;}
};

vec C[MAXN];
vector<Qu> d[MAXN];

int main(){
    ll N,Q; cin>>N>>Q;
    vec c(N+1,0);
    REP(i,1,N+1) cin>>c[i];
    REP(i,1,N+1) C[c[i]].pb(i);
    rep(i,Q){
        ll l,r; cin>>l>>r;
        Qu x(l,i);
        d[r].pb(x);
    }
    vec ans(Q,0);
    REP(i,1,N+1){
        add(i,1);
        ll f=lower_bound(ALL(C[c[i]]),i)-C[c[i]].begin();
        
        if(f) {
            //cout<<c[i]<<' '<<i<<' '<<C[c[i]][f-1]<<endl;
            add(C[c[i]][f-1],-1);
        }
        rep(j,d[i].size()) {
            ans[d[i][j].num]=sum(i)-sum(d[i][j].l-1);
        }
    }
    rep(i,Q) cout<<ans[i]<<endl;
    

    
}

Measured memory_bytes: 91200
#include<bits/stdc++.h>
using namespace std;
#define MAXN	105
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char mp[MAXN][MAXN];
int sum[MAXN][MAXN];
int ans[2][MAXN][MAXN][MAXN];
int n, m, x, y;
int getsum(int x, int y, int n, int m) {
	if (x > n || y > m) return 0;
	else return sum[n][m] - sum[n][y - 1] - sum[x - 1][m] + sum[x - 1][y - 1];
}
void update(int &x, int y) {
	x = max(x, y);
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++) {
		scanf("\n%s", mp[i] + 1);
		for (int j = 1; j <= m; j++) {
			if (mp[i][j] == 'E') x = i, y = j;
			if (mp[i][j] == 'o') sum[i][j] = 1;
			sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	}
	int finalans = 0;
	for (int i = 1, now = 1, last = 0; i <= n; i++, now ^= 1, last ^= 1) {
		for (int j = n; j >= i - 1; j--)
		for (int k = 1; k <= m; k++)
		for (int l = m; l >= k - 1; l--) {
			int ti = x - (n - j), tj = x + (i - 1);
			int tk = y - (m - l), tl = y + (k - 1);
			update(ans[now][j][k][l], ans[last][j][k][l] + getsum(max(tj, i), max(tk, k), min(tj, j), min(tl, l)));
			update(ans[now][j][k][l], ans[now][j + 1][k][l] + getsum(max(ti, i), max(tk, k), min(ti, j), min(tl, l)));
			update(ans[now][j][k][l], ans[now][j][k - 1][l] + getsum(max(ti, i), max(tl, k), min(tj, j), min(tl, l)));
			update(ans[now][j][k][l], ans[now][j][k][l + 1] + getsum(max(ti, i), max(tk, k), min(tj, j), min(tk, l)));
			update(finalans, ans[now][j][k][l]);
		}
		for (int j = n; j >= x; j--)
		for (int k = 1; k <= y; k++)
		for (int l = m; l >= y; l--)
			ans[last][j][k][l] = 0;
	}
	cout << finalans << endl;
	return 0;
}

Measured memory_bytes: 9088
import sys

# import numpy as np
import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(1000000)


def factorial(n):
    w = 10**9 + 7
    table = [1]*(n+1)
    for i in range(1, n+1):
        table[i] = table[i-1]*i % w
    return table


def modinv(a, m):
    b = m
    u = 1
    v = 0

    while b > 0:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u


def moddiv(x, y, m=10**9+7):
    y_inv = modinv(y, m)
    return x * y_inv % m


def perm(N1, N2):
    table = factorial(N1+N2)
    s = table[N1+N2]
    a = table[N1]
    b = table[N2]
    return moddiv(moddiv(s, a), b)


def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))

    x, y = map(int, input().split())
    diff = abs(x-y)

    if diff == 0:
        if x % 3 != 0:
            print(0)
            return
        cnt = x // 3
        ret = perm(cnt, cnt)
    else:
        if (min(x, y)-diff) % 3 != 0 or min(x, y) - diff < 0:
            print(0)
            return
        cnt = (min(x, y) - diff) // 3
        ret = perm(cnt, cnt+diff)

    print(ret)


if __name__ == "__main__":
    main()


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

using ll = long long;

constexpr ll MOD = 998244353;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()


vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n){ //x^n(mod 
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbmod
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

void init()
{
	fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // 
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; 
    }
}


int main(int argc, char **argv)
{
	init();
	
	ll N, M, K; cin >> N >> M >> K;

	vector<ll> sum(N+1, 0);
	sum[0] = 1;
	for (ll i = 0; i < N; ++i)
		(sum[i+1] = sum[i] * (M-1)) %= MOD;
	
	ll res{0};
	for (ll c = 0; c <= K; ++c)
	{
		ll tmp{(M * sum[N-c-1])%MOD};
		(res += (comb(N-1, c) * tmp) % MOD) %= MOD;
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll m,n,t=0,c,d;
    cin>>n>>m;
    ll a[n+10],b[n+10];
    for(int i = 0;i < n;i++)
    {
        cin>>c>>d;
        if(d <= m)
        {
            b[t] = c;
            t++;
        }
    }
    sort(b,b+t);
    if(t==0)
    {
        cout<<"TLE\n";
    }
    else
    {
        cout<<b[0]<<endl;
    }


}


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

int main() {
  vector<int> A(5);

  for (int i = 0; i < 5; i++) {
    cin >> A.at(i);
  }

  int max = 0;
  for (int i = 1; i < 5; i++) {
    if ((A.at(i) % 10) == 0) continue;
    if ((10 - A.at(i) % 10) > (10 - A.at(max) % 10)) {
      max = i;
    }
  }

  int sum = 0;
  for (int i = 0; i < 5; i++) {
    if (i != max) {
      sum += A.at(i);
      if (A.at(i) % 10 != 0) sum += 10 - A.at(i) % 10;
    }
  }
  sum += A.at(max);

  cout << sum << endl;
}



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

int const N = 100000;
char s1[N + 1], s2[N + 1];

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(){
	int n, m;
	scanf("%d%d%s%s", &n, &m, s1, s2);
	int g = gcd(n, m);
	int ln1 = n / g, ln2 = m / g;
	int st1 = 0, st2 = 0;
	f(i, 0, g){
		if (s1[st1] != s2[st2]) { printf("-1\n"); return 0; }
		st1 += ln1;
		st2 += ln2;
	}
	printf("%lld\n", (ll)n / g * m);
}

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

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

using namespace std;

int main(int argc, const char* argv[]) {
	char s[4];
	scanf("%s", &s);
	sort(&s[0], &s[3]);
	printf((s[0] == 'a' && s[1] == 'b' && s[2] == 'c') ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    g[u - 1].append(v - 1)
s, t = map(int, input().split())
s -= 1
t -= 1
done = [[-1] * n for _ in range(3)]
done[2][s] = 0
que = deque([s])
while que:
    d = que.popleft()
    for node1 in g[d]:
        if done[0][node1] != -1:
            continue
        done[0][node1] = 1
        for node2 in g[node1]:
            if done[1][node2] != -1:
                continue
            done[1][node2] = 1
            for node3 in g[node2]:
                if done[2][node3] != -1:
                    continue
                que.append(node3)
                done[2][node3] = done[2][d] + 1
print(done[2][t])

Measured memory_bytes: 62768
class SegmentTree:
    def __init__(self, n):
        n_ = 1
        while n_ <= n: n_ *= 2
        self.n = n_
        self.data = [(0, -n_-1)] * (2*n_)

    def add(self, k, a):
        idx = k + (self.n-1)
        data = self.data
        data[idx] = (data[idx][0] + a, -k)
        while idx:
            idx = (idx - 1) / 2
            data[idx] = max(data[2*idx+1], data[2*idx+2])

    def get(self):
        return self.data[0]

inputs = lambda: map(int, raw_input().split())
n, q = inputs()
st = SegmentTree(n)
for t in xrange(q):
    a, v = inputs()
    st.add(a, v)

    p, q = st.get()
    print -q, p

Measured memory_bytes: 31584
N, M = map(int, input().split())
C = tuple(map(int, input().split()))

inf = 10**18
dp = [inf] * (N + 10)
dp[0] = 0

for c in C:
    for i in range(c, N + 1):
        dp[i] = min(dp[i], dp[i - c] + 1)
ans = dp[N]
print(ans)


Measured memory_bytes: 7512
#include <bits/stdc++.h>
using namespace std;
 
//Made with <3 by MinumCoklatPanas
typedef long long ll;
const ll INF = 1e9;
const ll INFF = 1e18;
const ll MAXN = 510;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;
#define R 0
#define G 1
#define B 2


ll pref[3][4010];
ll n;

ll add(ll ix,ll color1,ll color2)
{
	ll kiri = pref[color1][ix - 1];
	ll kanan = pref[color2][n - 1] - pref[color2][ix];
	return (kiri * kanan);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	string s;
	cin >> s;
	pref[0][0] = (s[0] == 'R');
	pref[1][0] = (s[0] == 'G');
	pref[2][0] = (s[0] == 'B');
	for (ll i = 1 ; i < n ; i++)
	{
		pref[0][i] = pref[0][i - 1] + (s[i] == 'R');
		pref[1][i] = pref[1][i - 1] + (s[i] == 'G');
		pref[2][i] = pref[2][i - 1] + (s[i] == 'B');
	}
	ll ans = 0;
	for (ll j = 1 ; j < n - 1 ; j++)
	{
		if (s[j] == 'R')
		{
			ans += add(j,G,B);
			ans += add(j,B,G);
		}
		else
		if (s[j] == 'G')
		{
			ans += add(j,R,B);
			ans += add(j,B,R);
		}
		else
		if (s[j] == 'B')
		{
			ans += add(j,R,G);
			ans += add(j,G,R);
		}
		for (ll i = 0 ; i < j ; i++)
			{
				ll k = 2 * j - i;
				// cout << i << " " << j << " " << k << endl;
				if (k < n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
					--ans;
			}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=100005;
const ll p=998244353ll;
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}

int main(){
	string s;
	cin>>s;
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])puts("Bad");
	else puts("Good");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

#ifndef INT_MAX
#  define INT_MAX std::numeric_limits<int>().max()
#endif
#ifndef INT_MIN
#  define INT_MIN std::numeric_limits<int>().min()
#endif
#define LL_MAX std::numeric_limits<ll>().max()
#define LL_MIN std::numeric_limits<ll>().min()
#define INF LL_MAX

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
// 配列の初期化
#define ZERO(p) memset(p, 0, sizeof(p))
// 配列の初期化(-1)
#define MINUS(p) memset(p, 1, sizeof(p))

// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    REP(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge
{
  int a, b, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  int n;  // 頂点数
  vector<Edge> es;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  int kruskal() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;

    REP(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.a, e.b)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

ll V;
vector< pair<ll, ll> > sx, sy; // 値、インデックス

int main()
{
    cin >> V;
    REP(i, V) {
        ll x, y;
        cin >> x >> y;
        sx.push_back(make_pair(x, i));
        sy.push_back(make_pair(y, i));
    }

    SORT(sx);
    SORT(sy);

    Graph g;
    g.n = V;
    REP(i, V-1) {
        Edge e;
        e.a = sx[i].second;
        e.b = sx[i+1].second;
        e.cost = abs(sx[i].first - sx[i+1].first);
        g.es.push_back(e);

        e.a = sy[i].second;
        e.b = sy[i+1].second;
        e.cost = abs(sy[i].first - sy[i+1].first);
        g.es.push_back(e);
    }

    printf("%d\n", g.kruskal());

    return 0;
}


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

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int sum = 0;
    if(A<B) sum+=A;
    else sum+=B;
    if(C<D) sum+=C;
    else sum+=D;
    cout << sum <<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5010;
char a[N],b[N];
int n,c[N],c1,d[N],d1;
int ty[N],ty2[N],ans;
int abs(int x){
	return x<0?-x:x;
}
int ac(int x){
	return max(1,min(c1,x));
}
int ad(int x){
	return max(1,min(d1,x));
}
int main(){
	cin>>n;
	ans=n*n;
	scanf("%s",a+1);
	scanf("%s",b+1);
	ty[0]=(a[1]-'0')^1;
	c[++c1]=0;
	for (int i=1;i<=n;i++){
		if (a[i]==a[i+1])ty[i]=2;
		else ty[i]=a[i]-'0',c[++c1]=i;
	}
	ty2[0]=(b[1]-'0')^1;
	d[++d1]=0;
	for (int i=1;i<=n;i++){
		if (b[i]==b[i+1])ty2[i]=2;
		else ty2[i]=b[i]-'0',d[++d1]=i;
	}
	for (int i=1;i<=d1;i++){
		int x=d[ad(i)];
		if (ty2[x]==ty[0]){
			int sum=0;
			for (int j=-5002;j<=5002;j++)
				sum+=abs(c[ac(j)]-d[ad(i+j-1)]);
			ans=min(ans,sum);
		}
		if (ty2[x]==ty[n]){
			int sum=0;
			for (int j=5002;j>=-5002;j--)
				sum+=abs(c[ac(j)]-d[ad(i+j-c1)]);
			ans=min(ans,sum);
		}
	}
	for (int i=1;i<=c1;i++){
		int x=c[i];
		if (ty[x]==ty2[0]){
			int sum=0;
			for (int j=-5002;j<=5002;j++)
				sum+=abs(d[ad(j)]-c[ac(i+j-1)]);
			ans=min(ans,sum);
		}
		if (ty[x]==ty2[n]){
			int sum=0;
			for (int j=5002;j>=-5002;j--)
				sum+=abs(d[ad(j)]-c[ac(i+j-d1)]);
			ans=min(ans,sum);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>



int main(){
  int number;
  int array[1000000];

  scanf("%d",&number);



  int i;
  for(i=1;i<=number;i++){
    scanf("%d",&array[i]);
  }


  int kazu; 
  kazu=partition(array,1,number); 


  for(i=1;i<=number;i++){
    if(i==number){printf("%d\n",array[i]);}  



    else{
      if(i==kazu){printf("[%d] ",array[i]);}
      else{printf("%d ",array[i]);}
    }
  }
 
  
  return 0;
}


int partition(int A[],int p,int r){

  int x;
  
  x=A[r];

  int i;
  i=p-1;

  
  int j;
  int tmp;
 

  
  for(j=p;j<r;j++){
    if(A[j]<=x){

      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;

    }
  }


  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  
  
  return i+1;
}



Measured memory_bytes: 2164
#pragma GCC optimize("O3")

#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;

typedef long long ll;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin >> n;
    ll k;
    cin >> k;
    n-=k*(n/k);
    cout << min(n,abs(n-k));
    
    return 0;
}


Measured memory_bytes: 256
import math
for i in range(input()):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split(" "))
    if y2==y1 or y3==y1:
        if y2==y1:
            a2=-(x3-x1)/(y3-y1)
            b2=((y3+y1)-a2*(x1+x3))/2.0
            a,b,c,d,e,f=1.0,0.0,(x1+x2)/2.0,-a2,1.0,b2
        else:
            a1=-(x2-x1)/(y2-y1)
            b1=((y2+y1)-a1*(x1+x2))/2.0
            a,b,c,d,e,f=-a1,1.0,b1,1.0,0.0,(x1+x3)/2.0
    else:
        a1=-(x2-x1)/(y2-y1)
        a2=-(x3-x1)/(y3-y1)
        b1=((y2+y1)-a1*(x1+x2))/2.0
        b2=((y3+y1)-a2*(x1+x3))/2.0
        a,b,c,d,e,f=-a1,1.0,b1,-a2,1.0,b2
    py=(a*f-c*d)/(a*e-b*d)
    px=(c*e-f*b)/(a*e-b*d)
    r=math.sqrt((px-x1)**2 + (py-y1)**2)
    print "{0:.3f} {1:.3f} {2:.3f}".format(px,py,r)

Measured memory_bytes: 6488
n = int(input())
a = [int(x) for x in input().split()]
dp = [[0,0] for i in range(n)]

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)


d1 = [0 for i in range(n)]
d2 = [0 for i in range(n)]
d1[0] = a[0]
d2[-1] = a[-1]

for i in range(1,n):
    d1[i] = gcd(d1[i - 1], a[i])
for i in range(n - 2, -1, -1):
    d2[i] = gcd(d2[i + 1], a[i])

otv = 1

for i in range(n):
    if i == 0:
        otv = max(otv,d2[i + 1])
    elif i == n - 1:
        otv = max(otv,d1[i - 1])
    else:
        otv = max(otv, gcd(d2[i + 1],d1[i - 1]))
print(otv)

Measured memory_bytes: 74340
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	string a = "", b = ""; cin >> a >> b;

	bool res = false;
	rep (i, a.length() ){
		bool match = (i <= a.length() - b.length() );
		for (int j = i; j < i+b.length() && j < a.length(); j++ ){
			if (a[j] != b[j-i] && b[j-i] != '_' ){
				match = false;
				break;
			} // end if
		} // end for
		res |= match;
	} // end rep
	cout << (res ? "Yes" : "No" ) << endl;

	return 0;
}


Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define hahahahahahahahahahahah ios_base::sync_with_stdio(0);
using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;
ld ex[N];
ld pre[N];
int main()
{

	hahahahahahahahahahahah;
	cin.tie(0);
	ll n,k;
	cin>>n>>k;
	ll p[n+1];
	for(int i =1;i<=n;i++)cin>>p[i];
		
	for(int i =1;i<=n;i++){
		ld lol = 1.0;
		lol/=(ld)p[i];
		for(int j = 1;j<=p[i];j++){
			ex[i] += ((ld)j * lol);
		}
	}

	for(int i =1;i<=n;i++){
		pre[i] = (pre[i-1] + ex[i]); 
	}

	ld ans = 0;
	for(int i =1;i<=n;i++){
		if((i+k-1)>n)break;
		ans = max(ans,pre[i+k-1]-pre[i-1]);
	}
	cout<<fixed<<setprecision(20)<<ans<<endl;

	
	return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	long long h[n];
	for (long long i=0;i<n;i++) cin>>h[i];
	for (long long i=n-1;i>0;i--){
		if (h[i]<h[i-1]-1){
			cout<<"No";
			return 0;
		}  
		else if (h[i]==h[i-1]-1) h[i-1]=h[i-1]-1;
	}
	cout<<"Yes";
}
	


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

using namespace std;

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

  if (A >= 13) {
    cout << B << endl;
  }
  else if ( (A >= 6) && (12 >= A) ){
    cout << B/2 << endl;
  }
  else {
    cout << 0 << endl;
  }
 
 return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define in std::cin
#define out std::cout
#define rep(i,N)for(int i=0;i<N;i++)
typedef long long int LL;

LL N,ans;

int main()
{
    in>>N;
    ans=N;
    for(LL i=0; i<=N;++i)
    {
        LL n=i,res=0;
        while(n>0)
        {
            res+=n%6;
            n/=6;
        }
        n=N-i;
        while(n>0)
        {
            res+=n%9;
            n/=9;
        }
        ans=std::min(ans,res);
    }
    out <<ans<<std::endl;
    return 0;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  int ans=0;
  for(int i=0;i<N;i++){
    cin >> h.at(i);
    if(h.at(i)>=K){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

const ll MOD = 1000000007;

ll modpow(ll n, ll t) {
  ll ret = 1;
  while (0 < t) {
    if (t % 2 == 0) {
      n *= n;
      n %= MOD;
      t >>= 1;
    } else {
      ret *= n;
      ret %= MOD;
      --t;
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll zero = 0;
  map<pair<ll, ll>, ll> mp;
  ll ans = 1;
  REP(i, N) {
    ll A, B;
    cin >> A >> B;
    if (A == 0 && B == 0) {
      zero++;
      continue;
    } else if (A == 0 || B == 0) {
      A = (B == 0) ? 1 : 0;
      B = (A == 0) ? 1 : 0;
    } else if (B > 0) {
      ll G = gcd(A, B);
      A = A / G;
      B = B / G;
    } else if (B < 0) {
      ll G = gcd(A, B);
      A = -1 * (A / G);
      B = -1 * (B / G);
    }
    if (mp.count({A, B}))
      mp.at({A, B})++;
    else
      mp[{A, B}] = 1;
  }

  ll adhoc = 0;
  for (auto a : mp) {
    ll A = a.first.first;
    ll B = a.first.second;
    ll X, Y;
    X = a.second;  //{A,B}の個数
    if (A < 0) {
      if (mp.count({B, -A}))
        Y = mp.at({B, -A}), mp.erase({B, -A});
      else {
        Y = 0;
      }
    } else if (B == 0) {
      if (mp.count({0, 1}))
        Y = mp.at({0, 1}), mp.erase({0, 1});
      else {
        Y = 0;
      }
    } else if (A == 0) {
      if (mp.count({1, 0}))
        Y = mp.at({1, 0}), mp.erase({1, 0});
      else {
        Y = 0;
      }
    } else {
      if (mp.count({-B, A}))
        Y = mp.at({-B, A}), mp.erase({-B, A});
      else {
        Y = 0;
      }
    }

    ans = (ans * (modpow(2, X) + modpow(2, Y) - 1)) % MOD;
    // cout << A << " " << B << " " << X << " " << Y << " " << ans << endl;
    //    debugB
  }
  ans = (ans + zero - 1 + MOD) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 16072