akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using ull = unsigned long long;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, d, count = 0;
    cin >> n >> d;
    vvl a(n, vl (d));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < d; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            double sum = 0;
            for(int k = 0; k < d; k++) {
                sum += abs(a[i][k] - a[j][k])*abs(a[i][k] - a[j][k]);
            }
            sum = sqrt(sum);
            if(ceil(sum) == floor(sum)) {
                count++;
            }
        }
    }
    cout << count << "\n";
    return 0; 
}

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

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


k = [1 for _ in range(N+1)]
for i in range(2, N+1):
    k[i] = (i) * k[i-1]
# print(k)

def C(n, r):
    return k[n] // (k[r] * k[n-r])

red = N-K
blue = K
for i in range(1, K+1):
    # print(red+1, blue-1, i)
    # print(C(red+1, i), C(blue-1, i-1))
    ans = C(red+1, i) * C(blue-1, i-1)

    print(ans % (10**9+7))


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

#define int long long

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> b(50);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		for (int j = 0;  j < 50; j++) {
			if ((1LL << j) & x) b[j]++;
		}
	}
	int mx = 0;
	for (int i = 0; i < 50; i++) {
		if ((1LL << i) > k) {
			mx = i;
			break;
		}
	}
	mx--;

	long long ans = 0;
	long long num = 0;
	for (int i = mx; i >= 0; i--) {
		if (n - b[i] > b[i] && num + (1LL << i) <= k) {
			ans += (n - b[i]) * (1LL << i);
			num += (1LL << i);
		} else {
			ans += b[i] * (1LL << i);
		}
	}
	for (int i = mx + 1; i < 50; i++) {
		ans += b[i] * (1LL << i);
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld n, k;
      cin >> n;
      cin >> k;
      dbl A[n];
      lld i;
      foi(i, n)
      {
      	cin >> A[i];
      	A[i] = (A[i]+1)/2;
      }
      dbl s, m;
      s = 0;
      m = 0;
      foi(i, k)
      {
      	s += A[i];
      }
      m = s;
      for(i = k;i<n;i++)
      {
      	s-=A[i-k];
      	s+=A[i];
      	if (s>m)
      		m=s;
      }
      cout << fixed << setprecision(12) << m;
      return 0;
}

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

int main(){
    string a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]) ans+=1;
    }
    cout<<ans;
    
}

Measured memory_bytes: 3916
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n,t;
int c[505],s[505],f[505];
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
	   scanf("%d%d%d",&c[i],&s[i],&f[i]);
    }
    for(int i=1;i<=n;i++){
        t=0;
		for(int j=i;j<n;j++){
            if(t<s[j])t=s[j];//那么它就得等到能离开这个站时才能离开 
            else if(t%f[j])t+=f[j]-t%f[j];//那么它就得等到能离开这个站时才能离开 
            t+=c[j];//从当前站到下一个站需要的时间 
        }
        printf("%d\n",t);
    }
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1232>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MAX_PRIME = 200000;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}
int m,a,b;
vector<int> solve(){
    vector<int> res{0,0};
    for(int i(0); primes[i]*primes[i] <= m;i++){
        for(int j(i); primes[i]*primes[j] <= m;j++){
            if(a*primes[j] <= b*primes[i] && primes[j]*primes[i] >= *res.begin()**res.rbegin()){
                *res.begin() = primes[i]; *res.rbegin() = primes[j];
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    init_primes();
    while(cin >> m >> a >> b,m){
        cout << solve() << endl;
    }
    return 0;
}



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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

vector<lln> logg;int n,k;

int ok(lln i){
    int val = 0;
    for(int j=0;j<n;j++){
        val += ((logg[j] / i) * (logg[j] != i)); 
        if(val > k) return 0;
    }
    return 1;
}

int main(){
    //IOS;
    
    cin >> n >> k;
    lln mi = INT64_MIN;lln val;
    for(int i=0;i<n;i++){
        cin >> val;
        mi = max(val,mi);
        logg.push_back(val);
    }
    lln low = 1,high = mi;
    while(true){
        if(low == high){
            cout << low << endl;
            break;
        }
        lln i = (low + high) / 2;
        if(ok(i)) high = i;
        else{
            if(low+1 == high){
                cout << high << endl;
                break;
            }
            low = i;
        }
    }
    return 0;
}

Measured memory_bytes: 5332
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define inf (1<<28)
#define ll long long
#define db double
#define c233 cout<<"233"<<endl
#define mem(s) memset(s,0,sizeof(s))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
const int N=205;
const int M=1050;
using namespace std;

int l[N][N],s[N][N],dp[M][N],way[M];
int n,m,r,ans;

void fre(){
  freopen("in","r",stdin);
  freopen("out","w",stdout);
}

inline int gi(){
  int x=0,res=1;char ch=getchar();
  while(ch>'9'||ch<'0'){if(ch=='-')res*=-1;ch=getchar();}
  while(ch<='9'&&ch>='0')x=(x<<1)+(x<<3)+ch-48,ch=getchar();
  return x*res;
}

void init(){
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      l[i][j]=s[i][j]=inf;
  for(int i=1;i<=n;i++)
    l[i][i]=s[i][i]=0;
  for(int i=1;i<=m;i++){
    int a,b,c;
    char d;
    scanf("%d%d%d %c",&a,&b,&c,&d);
    if(d=='L')l[a][b]=l[b][a]=min(l[a][b],c);
    if(d=='S')s[a][b]=s[b][a]=min(s[a][b],c);
  }
  r=gi();
  for(int i=1;i<=r;i++)
    way[i]=gi();
}

void pre(){
  for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++){
	l[i][j]=min(l[i][j],l[i][k]+l[k][j]);
	s[i][j]=min(s[i][j],s[i][k]+s[k][j]);
      }
  for(int i=1;i<=r;i++)
    for(int j=1;j<=n;j++)
      dp[i][j]=inf;
  ans=inf;
}

void work(){
  dp[1][way[1]]=0;
  for(int i=2;i<=r;i++)
    for(int j=1;j<=n;j++){
      dp[i][j]=min(dp[i][j],dp[i-1][j]+l[way[i-1]][way[i]]);
      for(int k=1;k<=n;k++)
	dp[i][k]=min(dp[i][k],dp[i-1][j]+l[way[i-1]][j]+s[j][k]+l[k][way[i]]);
    }
  for(int i=1;i<=n;i++)
    ans=min(ans,dp[r][i]);
  printf("%d\n",ans);
}

int main(){
  //fre();
  while(1){
    n=gi();m=gi();
    if(n==0&&m==0)break;
    init();
    pre();
    work();
  }
  return 0;
}

Measured memory_bytes: 4276
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
 
int main()
{
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     
	int a,b,c,d;
	cin>>a>>b>>c>>d;
    
	while(a>0&&c>0)
	{
	
		  c=c-b;
		  a=a-d;
		  
		  
		  if(c<=0)
		  {
		 
		  	cout<<"Yes"<<endl;
		  	
		  	
		  }
		  
		  
		  else if(a<=0)
		  {
		  
		  	cout<<"No"<<endl;
		    
		  	
		  	
		  }
		  
	
	}	
	
	


     return 0;
     
     
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

int main(void)
{
    int n;
    cin >> n;
    vector<int> d(n);
    int i;
    rep(i,n)
    {
        cin >> d[i];
    }

    sort(d.begin(),d.end());
    int ans = 0;
    for(i=d[n/2-1];i<d[n/2];i++)
    {
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define rep(i,n) for(int (i)=0;(i) < (n);(i)++)
#define MAX 35
using namespace std;

void reset(int a[],int from){
    for(int i= from;i<MAX;i++){
        a[i]=0;
    }
}
void show(int array[]){
    int temp=0;
    while(array[temp+1]!=0&&temp<MAX){
        printf("%d ",array[temp]);
        temp++;
    }
    printf("%d\n",array[temp]);
}

void dfs(int *a){
    show(a);
    if(a[0]==1)
        return;
    int last = 0;
    for(last = 0;a[last+1]!=0&&last<MAX;last++);
    if(a[last]!=1){
        a[last]--;
        a[++last]++;
        dfs(a);
    }else{
        int sum = 0;
        for(int temp = last;temp >= 0;temp--){
            sum+=a[temp];
            if(a[temp]==2){
                a[temp]=1;
                a[++last]++;
                dfs(a);
                break;
            }else if(a[temp]>=3){
                int mow=a[temp]-1;
                reset(a,temp);
                while(sum>mow){
                    a[temp++]=mow;
                    sum-=mow;
                }
                a[temp]=sum;
                dfs(a);
                break;
            }
        }
    }
    return;
}

int main() {
    int n;
    int array[MAX];
    while(scanf("%d",&n),n!=0){
        reset(array,0);
        array[0]=n;
        dfs(array);
    }
    return 0;
}

Measured memory_bytes: 1188
n = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

count = 0
before = 0
for i in range(n+1):
    if As[i] >= before:
        count += before
        As[i] -= before
    else:
        count += As[i]
        As[i] = 0

    if i >= n:
        break

    if As[i] > 0:
        if As[i] < Bs[i]:
            count += As[i]
            before = Bs[i] - As[i]
        else:
            before = 0
            count += Bs[i]
    else:
        before = Bs[i]

print(count)

Measured memory_bytes: 19156
// a program which finds the number of prime numbers in the given list

import java.util.*;
import java.lang.*;

class Main{

  public static void main(String[] args){
    final int N;
    int A, num = 0;           // num : the number of prime numbers in the given list

    Scanner scanner = new Scanner(System.in);
    N = scanner.nextInt();

    for( int i = 0; i<N; i++ ){
      A = scanner.nextInt();
      num += isPrime(A);
    }

    scanner.close();
    System.out.println(num);
  }

  // a function for judging whether the given number is a prime number or not
  // Returned Value 0: not prime number 1: prime number
  static int isPrime(int n){

    for( int i = 2; i<=Math.sqrt(n); i++ ){
      if( n % i == 0 )
        return 0;
    }

    return 1;
  }// the end of the method: "isPrime"

}// the end of the class: "Main"



Measured memory_bytes: 41292
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
//#define ls rt<<1
//#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int maxn=3e5+100;
const int N=2e5+100;
const int M=500+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;//cout.tie(0);
    ll k;cin>>k;
    ll ans=0;int cnt=-1;
    for(int i=1;i<=20000000;++i)
    {
        ans=(ans*10+7)%k;
        if(ans==0) {cnt=i;break;}
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <iterator>
#include <bitset>
#include <random>
#include <assert.h>
#include <unordered_map>
#include <array>
#include <ctime>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define umap unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef unsigned int uint;

int c[20], v[20];
int visit[1 << 20];
int ans;
int n, U;

void dfs(int cnt, int bits, int sum){
	if (visit[bits]) return;
	visit[bits] = 1;
	if (ans <= cnt) return;
	if (sum >= U){
		ans = cnt;
		return;
	}

	for (int i = 0; i < n; ++i){
		if (bits&(1 << i))continue;
		if ((bits&v[i]) != v[i]) continue;
		dfs(cnt + 1, bits | (1 << i), sum + c[i]);
	}
}

int main(){
	while (cin >> n >> U, n|U){
        rep(i, n){
            cin >> c[i];
            int k;
            cin >> k;
			v[i] = 0;
            rep(j, k){
                int x;
                cin >> x;
                v[i] |= 1<<x;
            }
        }
        ans = n;
		MEMSET(visit, 0);
		dfs(0, 0, 0);
        cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 5264
def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return list(map(int, ss_raw()))


n = int_raw()
a = int_raw()
b = int_raw()
c = int_raw()
d = int_raw()
e = int_raw()

minimum = min([a, b, c, d, e])
ans = 5 + n // minimum
if n % minimum == 0:
    ans -= 1
print(ans)


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N; cin >> N;
    ll a0 = 0, a2 = 0, a4 = 0;
    rep(_,N){
        ll a;
        cin >> a;
        if(a % 4 == 0) a4++;
        else if(a % 2 == 0) a2++;
        else a0++;
    }

    if(a0 + a2 % 2 > a4 + 1) print("No");
    else print("Yes");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s1,s2;
    cin>>s1>>s2;
    if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0])
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;
 
    if (A > B) {
      cout << A+A-1 << endl;
    } else if (A==B) {
      cout << A+B << endl;
    } else {
      cout << B+B-1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int p,q,r,maxx;
    scanf("%d%d%d",&p,&q,&r);
    maxx=max(p,q);
    maxx=max(maxx,r);
    printf("%d\n",p+q+r-maxx);
    return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll nax=3005,mod=1e9+7;



int main(){

    sync
   // file();
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<ll> realp(n+2),reals(n+2);
    realp[1] = 1;
    reals[1] = 1;
    fore(i,2,n){
        vector<ll> temp(n+2);
        fore(j,1,i){
            if(s[i-2]=='<'){
                temp[j]=realp[j-1];
                temp[j]%=mod;
            }
            else{
                temp[j]=reals[j];
                temp[j]%=mod;
            }
        }
        realp = temp;
        reals = temp;
        fore(j,1,i) realp[j]+=realp[j-1], realp[j]%=mod; 
        for(int j = i;j>=1;j--) reals[j]+=reals[j+1], reals[j]%=mod;
    }
    cout<<realp[n];

  return 0;
}

Measured memory_bytes: 384
// abc047_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    int ans = 0;
    REP(i, S.size()-1){
        if (S[i] != S[i+1]){
            ans++;
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,a,b,c,q,d[100005]={};
    long long ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        d[a]++;
        ans+=a;
    }
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>b>>c;
        ans+=(c-b)*d[b];
        d[c]+=d[b];
        d[b]=0;
        cout<<ans<<endl;
    }
    return(0);
}

Measured memory_bytes: 4412
#include<iostream>
using namespace std;
int mp[200];
int main()
{
	int x,n;	cin>>x>>n;
	for(int i=1;i<=n;i++){
		int k;	cin>>k;
		mp[k]=1;
	}
	for(int i=0;i<=100;i++)
	{
		if(mp[x-i]==0){
			cout<<x-i<<endl;
			break;
		}
		else if(mp[x+i]==0){
			cout<<x+i<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3172
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	string S;
	cin>>S;
	int T[10];
	ll ans=0;
	for(int i=0;i<S.size();i++)T[i]=S[i]-'0';
	int N=S.size()-1;
	for(int i=0;i<(1<<N);i++){
		ll tmp=0;
		REP(j,N){
			tmp=10*tmp+T[j];
			if(i&(1<<j)){
				ans+=tmp;
				tmp=0;
			}
		}
		ans+=tmp*10+T[N];
	}
	cout<<ans<<endl;
	
	return 0;
}






















Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AExpired {
public:
    void solve(istream &in, ostream &out) {
        ll x, a, b;
        in >> x >> a >> b;
        if (a - b >= 0)out << "delicious" << endl;
        else if (b - a <= x) out << "safe" << endl;
        else out << "dangerous" << endl;
    }
};

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define $ template <tyepename T>

int main(){    
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(c>min(a, b) && c<max(a, b))
        cout << "Yes\n";
    else 
        cout << "No\n";
}


Measured memory_bytes: 256
S=input()
even=0
odds=0
for i in range(len(S)):
    if i%2==0:
        if S[i]=="1":
            even+=1  
        else:
            odds+=1
    
    else:
        if S[i]=="0":
            even+=1
        else:
            odds+=1
print(min(odds,even))

Measured memory_bytes: 39536
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (1 << 23);

struct pt
{
	int x, y;
	pt() { }
};

int H[maxn], F[maxn], used[maxn];

struct hash_table
{
	hash_table() { }

	int getpos(int h) const
	{
		int i = h % maxn;
		for (; used[i] && H[i] != h; ++i) if (i + 1 == maxn) i = -1;
		return i;
	}

	int& operator[](int h)
	{
		int i = getpos(h);
		H[i] = h;
		used[i] = 1;
		return F[i];
	}
};

struct fenwick
{
	int n;
	hash_table F;

	fenwick() { n = inf; }

	void upd(int i, int x)
	{
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	}

	int get(int i)
	{
		int res = 0;

		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);

		return res;
	}
};

int n;
pt s, f;
pt p[maxn];

bool read()
{
	if (scanf("%d %d %d %d %d", &s.x, &s.y, &f.x, &f.y, &n) != 5)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].x, &p[i].y);

	return true;
}

bool cmp(pt a, pt b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); }

void solve()
{
	if (s.x > f.x)
		swap(s, f);

	if (s.y > f.y)
	{
		f.y = 2 * s.y - f.y;

		forn (i, n)
			p[i].y = 2 * s.y - p[i].y;
	}

	vector<pt> pp;

	forn (i, n)
		if (s.x <= p[i].x && p[i].x <= f.x && s.y <= p[i].y && p[i].y <= f.y)
			pp.push_back(p[i]);

	sort(pp.begin(), pp.end(), cmp);
	fenwick dp;

	forn (i, size(pp))
		dp.upd(pp[i].y, dp.get(pp[i].y) + 1);

	int lis = dp.get(inf);
	long double ans = 0;

	if (lis != min(f.y - s.y, f.x - s.x) + 1)
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * lis;
	else
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * (lis - 1) + 10 * M_PI;

	printf("%.15f\n", (double) ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 101872
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb puah_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n; cin >> n;
    vector<string> lis(n);
    vector<ll> name(5, 0);
    REP(i, 0, n){
        string s; cin >> s;
        if(s[0] == 'M'){
            name[0]++;
        }else if(s[0] == 'A'){
            name[1]++;
        }else if(s[0] == 'R'){
            name[2]++;
        }else if(s[0] == 'C'){
            name[3]++;
        }else if(s[0] == 'H'){
            name[4]++;
        }
    }
    ll ans = 0;
    REP(i, 0, 5){
        if(name[i] == 0){
            continue;
        }
        REP(l, i+1, 5){
            if(name[l] == 0){
                continue;
            }
            REP(k, l+1, 5){
                if(name[k] == 0){
                    continue;
                }
                ans += name[i] * name[l] * name[k];
            } 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;

int maxelem(vector<int> src) {
	int dst = IMIN;
	rep(i, src.size()) {
		dst = (dst > src[i]) ? dst : src[i];
	}
	return dst;
}

int secondelem(vector<int> src) {
	int dst = IMIN;
	int dst2 = IMIN;
	rep(i, src.size()) {
		if (dst < src[i]) {
			dst2 = dst;
			dst = src[i];
		}
		else if (dst2 < src[i]) {
			dst2 = src[i];
		}
	}
	return dst2;
}

vector<int> count(vector<int> a) {
	int ma = maxelem(a);
	vector<int> count(ma+1, 0);
	rep(i, a.size()) {
		count[a[i]]++;
	}
	return count;
}

int find(vector<int> a, int b) {
	rep(i, a.size()) {
		if (a[i] == b) return i;
	}
	return -1;
}

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	int cnt = 0;
	int mini = IMAX;
	rep(i, N) cin >> h[i];
	sort(h.begin(), h.end());
	rep(i, N-K+1) {
		cnt = h[i+K-1] - h[i];
		mini = (mini <= cnt)? mini : cnt;
	}
	cout << mini << endl;


	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    long long a[100];
    for(int i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
    long long nums = 0;
    long long nSum = 1000;
    long long nMin;
    for(long long i=0; i<n;) {
        nMin = a[i];
        bool res = 1;
        for(long long j=i+1; j<n; j++) {
            if(nMin >= a[j]) {
                nMin = a[j];
            }
            else {
                nums = nSum / nMin;
                nSum = nSum % nMin;
                nSum += nums * a[j];
                i = j;
                res = 0;
                // printf("%d %d\n", nMin, a[j]);
                break;
            }
        }
        if(res) i++;
    }
    printf("%lld\n", nSum);
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

struct edge{
    int to;
    int index;
};

vector<bool> used;
vector<int> col;

void dfs(vector<vector<edge>> &G, int v, int p){
    used[v] = true;
    int color = 0;
    for (auto nv : G[v]){
        if(used[nv.to]) continue;
        color++;
        if(color == p) color++;
        col[nv.index] = color;
        dfs(G, nv.to, color);
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<edge>> G(n);
    used.assign(n, false);
    col.assign(n, -1);

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

    int res = 0;
    for (int i = 0; i < n; ++i) {
        res = max(res, (int)G[i].size());
    }

    dfs(G, 0, 0);

    cout << res << endl;
    for (int i = 0; i < n - 1; ++i) {
        cout << col[i] << endl;
    }
}

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

int main(){
    int k,n;
    
    cin >> k >> n;
    vector<int> a(n, 0);
    rep(i, n) cin>>a.at(i);

    int dist = (k-a.at(n-1)) + a.at(0);
    rep(i, n-1){
        int adiff = a.at(i+1)-a.at(i);
        if(adiff > dist) dist = adiff;
    }
    cout << k-dist << endl; 
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

class S{
public:
  int g, d, s, e;
  S(){}
  S(int g, int d, int s, int e) : g(g), d(d), s(s), e(e) {}
};

class State{
public:
  int y, x, used, t, sum;
  State(){}
  State(int y, int x, int used, int t, int sum) : y(y), x(x), used(used), t(t), sum(sum) {}
};

int w, h, n;
char mapData[20][20];
map<int, int> conv;
S data[10];
int sy, sx;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

int bfs(){
  bool vis[20][20][1<<10];
  for(int i=0;i<20;i++){
    for(int j=0;j<20;j++){
      for(int k=0;k<(1<<10);k++){
        vis[i][j][k] = false;
      }
    }
  }
  State u, v;
  u = State(sy, sx, 0, 0, 0);
  queue<State> q;
  q.push(u);
  vis[u.y][u.x][u.used] = true;
  int res = 0;
  while(!q.empty()){
    u = q.front(); q.pop();
    //cout << u.y << ' ' << u.x << ' ' << u.used << ' ' << u.t << endl;
    for(int i=0;i<4;i++){
      int ny = u.y + dy[i];
      int nx = u.x + dx[i];
      if(ny<0 || ny>=h) continue;
      if(nx<0 || nx>=w) continue;
      if(mapData[ny][nx] != '.'){
        int num = conv[mapData[ny][nx] - '0'];
        if(u.t < data[num].e && !((1 << num) & u.used)){
          if(u.t >= data[num].s){
            v.y = u.y;
            v.x = u.x;
            v.used = u.used | (1<<num);
            //v.t = max(u.t, data[num].s);
            v.t = u.t;
            v.sum = u.sum + data[num].d;
            res = max(res, v.sum);
            if(!vis[v.y][v.x][v.used]){
              vis[v.y][v.x][v.used] = true;
              q.push(v);
            }
          }else{
            q.push(State(u.y, u.x, u.used, data[num].s, u.sum));
          }
        }
      }else{
        if(!vis[ny][nx][u.used]){
          vis[ny][nx][u.used] = true;
          q.push(State(ny, nx, u.used, u.t+1, u.sum));
        }
      }
    }
  }
  return res;
}

main(){
  while(cin >> w >> h && (w|h)){
    conv.clear();
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> mapData[i][j];
        if(mapData[i][j] == 'P'){
          mapData[i][j] = '.';
          sy = i;
          sx = j;
        }
      }
    }
    cin >> n;
    for(int i=0;i<n;i++){
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      data[i] = S(a, b, c, d);
      conv[a] = i;
    }
    cout << bfs() << endl;
  }
}

Measured memory_bytes: 1432
#include<math.h>
using namespace std;
#define MAX 100
#define INFTY (1 << 21)

struct Building{ int x, y; };

int n;
Building B[MAX+1];
double D[MAX+1];
int P[MAX+1];

double getDistance( Building b1, Building b2 ){
    return sqrt(1.0*(b1.x-b2.x)*(b1.x-b2.x) + (b1.y - b2.y)*(b1.y - b2.y));
}

void dijkstra( int s ){
    bool visited[MAX+1];
    for ( int i = 1; i <= n; i++ ){
	D[i] = INFTY;
	P[i] = -1;
	visited[i] = false;
    }

    D[s] = 0.0;

    while(1){
	double minv = INFTY;
	int u = 0;
	for ( int i = 1; i <= n; i++ ){
	    if ( visited[i] ) continue;
	    if ( minv > D[i] ){
		minv = D[i];
		u = i;
	    }
	}
	if ( minv == INFTY ) break;
	visited[u] = true;

	for ( int v = 1; v <= n; v++ ){
	    if ( visited[v] ) continue;
	    double d = getDistance( B[u], B[v] );
	    if ( d <= 50.0 && D[u] + d < D[v] ){
		D[v] = D[u] + d;
		P[v] = u;
	    }
	}
    }
}

void print( int i, bool f){
    if ( i == -1 ) return;
    print(P[i], true);
    cout << i;
    if ( f ) cout << " ";
}

void printPath( int s, int g ){
    if ( D[g] == INFTY ) {
	cout << "NA" << endl;
	return;
    }
    print(g, false);
    cout << endl; 
}

main(){
    while( cin >> n && n ){
	int x;
	for ( int i = 1; i <= n; i++ ){
	    cin >> x;
	    cin >> B[x].x >> B[x].y;
	}
	int query; cin >> query;
	int s, g;
	for ( int i = 0; i < query; i++ ){
	    cin >> s >> g;
	    dijkstra(s);
	    printPath(s, g);
	}
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking 
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1ll<<60)
using namespace std;

int n;
int main(){
	scanf("%d",&n);
	int la=0,lav=0,ans=0;
	for (int i=1;i<=n;i++){
		int x; scanf("%d",&x);
		if (x!=lav){
			int lalen=i-la;
			ans+=lalen/2;
			la=i;
		}
		lav=x;
	}
	int lalen=n-la+1;
	ans+=lalen/2;
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    int max = a[0];
    for(i=1;i<n;i++){
        if(max>a[i]+1){
            printf("No");
            return 0;
        }
        if(max<a[i]) max = a[i];
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

const int MAXN = 3005;

vpll P;

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int N, T;
    cin >> N >> T; T--;
    
    P.resize(N);

    for(int i = 0; i < N; ++i)
        cin >> P[i].st >> P[i].nd;

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

    vvll DP(N+1, vll(T+1, 0));

    for(ll i = 0; i < N; ++i){
        for(ll j = 0; j < T+1; ++j){
            ll a = P[i].st, b = P[i].nd;
            if(j - a >= 0){ DP[i+1][j] = max(DP[i][j], DP[i][j-a]+b); }
            else DP[i+1][j] = DP[i][j];
        }
    }
    ll res = 0;
    for(int i = 0; i < N; ++i) res = max(res, DP[i][T] + P[i].nd);
    cout << res << endl;

    return 0;
}

//cikisir



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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

N = N % 500;
if(A >= N) yes;
else no;
}

Measured memory_bytes: 384
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

solve :: Int -> Int -> [[Int]] -> (Int, [[Int]])
solve h w ass = (length coms, coms)
  where
    coms = reverse $ rowop Nothing 1 [] ass

rowop _ _ res [] = res
rowop pos y res (as:ass)
  = rowop thisPos (y+1) (thisRes ++ vert pos ++ res) ass
  where
    (thisPos, thisRes) = colop Nothing 1 [] as

    vert Nothing = []
    vert (Just x) = [[y-1, x, y, x]]

    colop start x res [] = (start, res)
    colop start x res (a:as)
      | a' `mod` 2 == 0 = colop start (x+1) res as
      | otherwise = case start of
          Nothing -> colop (Just x) (x+1) res as
          Just x' -> colop Nothing (x+1) (coms x' x ++ res) as
      where a' | pos == Just x = a + 1
               | otherwise     = a
            coms x1 x2 = [[y,t,y,t+1] | t <- [x2-1,x2-2..x1]]

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

main = do
  cont <- B.getContents
  let [h, w] : ass = map bsReadInts (B.lines cont)
      (n, yss) = solve h w ass
  B.putStr $ B.unlines $ map (B.unwords . map (B.pack . show)) ([n] : yss)


Measured memory_bytes: 73852
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool gg = 0;
int c[N], cnt[3];
vector<int> G[N];
void dfs(int x, int col = 1) {
	if (c[x]) {
		gg |= col != c[x];
		return;
	}
	c[x] = col;
	cnt[col] ++;
	for (int u : G[x]) dfs(u, 3 - col);
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1);
	if (gg) printf("%lld\n", 1LL * n * (n - 1) / 2 - m); else printf("%lld\n", 1LL * cnt[1] * cnt[2] - m);
}

Measured memory_bytes: 6528
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();

    let mut init_i = 0usize;
    let mut init_j = 0usize;
    let mut init_k = 0usize;
    for num in a {
        if num == 3 {
            init_i += 1;
        } else if num == 2 {
            init_j += 1;
        } else {
            init_k += 1;
        }
    }
    let max_i = init_i;
    let max_j = init_i + init_j;
    let max_k = init_i + init_j + init_k;
    let mut dp = vec![vec![vec![0.0f64; max_k + 1]; max_j + 1]; max_i + 1];
    let denominator = (init_i + init_j + init_k) as f64;

    for i in 0..max_i + 1 {
        for j in 0..max_j + 1 {
            for k in 0..max_k + 1 {
                let ii = i as f64;
                let jj = j as f64;
                let kk = k as f64;
                if i == 0 && j == 0 && k == 0 {
                    continue;
                }
                dp[i][j][k] += denominator / (ii + jj + kk);
                if i > 0 && j + 1 <= max_j {
                    dp[i][j][k] += ii / (ii + jj + kk) * dp[i - 1][j + 1][k];
                }
                if j > 0 && k + 1 <= max_k {
                    dp[i][j][k] += jj / (ii + jj + kk) * dp[i][j - 1][k + 1];
                }
                if k > 0 {
                    dp[i][j][k] += kk / (ii + jj + kk) * dp[i][j][k - 1];
                }
            }
        }
    }
    println!("{:?}", dp[init_i][init_j][init_k]);
}


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

using namespace std;

long long inf=1000000007;
vector<bool> seen(10000,false);

void dfs(long long &cnt,long long now,vector<long long> &d,vector<long long> &f,vector<vector<long long>> kankei){
	seen.at(now)=true;
	cnt++;
	d.at(now)=cnt;

	for(auto a:kankei.at(now)){
		if(seen.at(a)) continue;

		dfs(cnt,a,d,f,kankei);
	}

	cnt++;
	f.at(now)=cnt;

	return;
}

int main(){
	long long n;
	cin>>n;
	vector<vector<long long>> kankei(n+1);

	for(long long i=1;i<=n;i++){
		long long k,u;
		cin>>k>>u;
		vector<long long> vec(u);
		for(long long j=0;j<u;j++){
			cin>>vec.at(j);
		}
		sort(vec.begin(),vec.end());

		kankei.at(k)=vec;
	}

	vector<long long> d(n+1,0);
	vector<long long> f(n+1,0);
	long long cnt=0;

	for(long long i=1;i<=n;i++){
		if(seen.at(i)) continue;

		dfs(cnt,i,d,f,kankei);
	}

	for(long long i=1;i<=n;i++){
		cout<<i<<" "<<d.at(i)<<" "<<f.at(i)<<endl;
	}

	return 0;
}



Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int N, D;

bool validate(int x[], int y[]) {
    int tmp = 0;
    rep(i, 0, D) {
        tmp += pow(x[i] - y[i], 2);
    }
    int tmp_s = sqrt(tmp);
    return tmp == tmp_s * tmp_s;
}

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

  cin >> N >> D;
  int X[N][D];
  rep(i, 0, N) rep(j, 0, D) cin >> X[i][j];

  int rsl = 0;
  rep(i, 0, N) {
      rep(j, i + 1, N) {
          if(validate(X[i], X[j])) rsl++;
      }
  }
  cout << rsl << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <chrono>
#include <numeric>

using namespace std;
using namespace std::chrono;

typedef long long int lo;
#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9
#define N (lo)1e5 * 5
#define all(x) (x).begin(), (x).end()
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
#define vi vector <lo> 
#define vii vector <ii> 

int main() {
	fast
	lo n, k, ans = 0;
	cin >> n >> k;
	while(0 < n){
		n /= k;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define xrep(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()
string dumpd(vector<double> vs) { string out = "[";for (int i = 0; i < vs.size(); ++i) {if (i == vs.size() - 1) {out += to_string(vs[i]);} else {out += to_string(vs[i]) + ", ";}}out += "]";return out;}
string dumpi(vector<int> vs) {string out = "[";for (int i = 0; i < vs.size(); ++i) {if (i == vs.size() - 1) {out += to_string(vs[i]);} else {out += to_string(vs[i]) + ", ";}}out += "]";return out;}
typedef long long ll;

double A, B, H, M;
const double PI = acos(-1);
int main() {
  cin >> A >> B >> H >> M;
  double thetaH  = 2.0*PI * ((H  + (M / 60.0)) / 12.0);
  double thetaM = 2.0 * PI * (M / 60.0);
  double theta = abs(thetaH - thetaM);
  double len = sqrt(pow((double)A, 2) + pow((double)B, 2) - 2 * A * B * cos(theta));
  printf("%.20lf\n", len);
  return 0;
}

Measured memory_bytes: 4168
import itertools

n, c = [ int(v) for v in input().split() ]
d_list = [ [ int(v) for v in input().split() ] for i in range(c) ]
c_list = [ [ int(v)-1 for v in input().split() ] for i in range(n) ]
change_list = [ [0,0,0] for i in range(c) ]

for k in range(c):
    x, y, z = 0, 0, 0
    for i in range(n):
        for j in range(n):
            if (i + j) % 3 == 0:
                x += d_list[c_list[i][j]][k]
            elif (i + j) % 3 == 1:
                y += d_list[c_list[i][j]][k]
            elif (i + j) % 3 == 2:
                z += d_list[c_list[i][j]][k]
    change_list[k] = [x, y, z]

ans = 10**9
for i in itertools.permutations(range(c),3):
    x, y, z = i
    ans = min(ans, change_list[x][0] + change_list[y][1] + change_list[z][2])
print(ans)


Measured memory_bytes: 45404