akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    ll N, L;
    ll origin = 0;
    ll diff = 1e9;
    ll answer = 0;

    cin >> N >> L;

    rep(i, N) origin += L + i;
    rep(i, N) if (abs(L + i) < abs(diff)) diff = L + i;

    answer = origin - diff;

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     // freopen("error.txt","w",stderr);
     ll x,y;
     cin>>x>>y;
     for(ll i=0;i<=x;i++)
     {
        if(i*2 + (x-i)*4 == y)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
     }
     cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3688
import std.stdio;
import std.algorithm;
import std.array;
import std.string;
import std.conv;

void main(){
	auto buf = readln.chomp.split.to!(int[]);
	swap(buf[0], buf[1]);
	swap(buf[0], buf[2]);
	foreach(i; buf){
		write(i, " ");
	}
}

Measured memory_bytes: 256
def main():
    n = input()
    for _ in range(0,n):
        arr = map(int,raw_input().split())
        arr.sort()
        if arr[2] * arr[2] == arr[0] * arr[0] + arr[1] * arr[1]:
            print "YES"
        else:
            print "NO"

if __name__ == '__main__':
    main()

Measured memory_bytes: 6236
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  bool ok=0;
  int x;
  rep(i,0,n+1){
    if(i*108/100==n) {
      x=i;
      ok=true;
    }
  }
  if(ok)cout<<x<<endl;
  else{
   cout<<":("<<endl; 
  }
}

Measured memory_bytes: 3520
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#define md double
#define LL long long
using namespace std;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int f[4010][4010],g[4010][4010];
int fac[8010],inv[8010];
const int mod=1e9+7;
int main()
{
	int n=gi(),i,j,x,y,ans=0;
	for (i=fac[0]=1;i<=8000;i++) fac[i]=1LL*fac[i-1]*i%mod;
	for (i=2,inv[1]=1;i<=8000;i++) inv[i]=mod-1LL*inv[mod%i]*(mod/i)%mod;
	for (i=inv[0]=1;i<=8000;i++) inv[i]=1LL*inv[i-1]*inv[i]%mod;
	for (i=1;i<=n;i++) {
		x=gi(),y=gi();
		f[2000-x][2000-y]++;
		g[2000+x][2000+y]++;
		ans=(ans+1LL*fac[(x+y)<<1]*inv[x<<1]%mod*inv[y<<1])%mod;
	}
	ans=mod-ans;
	for (i=0;i<=4000;i++)
		for (j=0;j<=4000;j++) {
			(f[i][j]+=(i?f[i-1][ j ]:0)+(j?f[i][j-1]:0))%=mod;
			ans=(ans+1LL*g[i][j]*f[i][j])%mod;
		}
	printf("%d\n",int(ans*((mod+1LL)>>1)%mod));
	return 0;
}


Measured memory_bytes: 95104
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
      //System.out.println("Nの値が入力されました");
    int sum=0;
    int [][] A = new int [3][N];//配列の宣言

    for(int j=0;j<2;j++){//横の配列
      for(int i=0;i<N;i++){//縦の配列
      A[j][i] = scan.nextInt();
            }
    }
    for(int i=0;i<N-1;i++){
    A[2][i]=scan.nextInt();//Ciの入力
    }
    for(int i=0; i<N;i++){
      //System.out.print(A[1][i] );
      sum +=A[1][i];
      //if(A[0][i]==(A[0][i+1]+1)){
         //sum +=A[2][i];
      }
      for(int i=0;i<N-1;i++){
        if((A[0][i]+1)==A[0][i+1]){
        sum +=A[2][A[0][i]-1];
      }
    }

    System.out.println(sum);
  }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main(void){
	int n,k;
	cin >> n >> k;

	int ans = 1 << 20;
	rep(mask,1<<n){
		int cur = 1;
		rep(i,n){
			if(mask&(1<<i))
				cur *= 2;
			else
				cur +=k;
		}
		chmin(ans,cur);
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
    int n;
    vector<string> words;
    string temp;

    cin >> n; cin.ignore();

    for (int i = 0; i < n; i++)
    {
        getline(cin, temp);
        words.push_back(temp);
    }

    for (int i = 1; i < n; i++)
    {
        int s = words[i - 1].size();
        if (words[i][0] != words[i - 1][s - 1])
        {
            cout << "No" << endl;
            return 0;
        }

        for (int j = 0; j < n; j++)
        {
            if (words[j] == words[i] && i != j)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
dp = [[10**9] * (W+1) for _ in range(H+1)]

dp[0][1] = dp[1][0] = 0
  
for i in range(1, H+1):
  for j in range(1, W+1):
    if grid[i-1][j-1] == '.':
      dp[i][j] = min(dp[i-1][j], dp[i][j-1])
    else:
      dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + 1
      if i >= 2 and grid[i-2][j-1] == '#':
        dp[i][j] =  min(dp[i][j], dp[i-1][j])
      if j >= 2 and grid[i-1][j-2] == '#':
        dp[i][j] =  min(dp[i][j], dp[i][j-1])
print(dp[-1][-1])

Measured memory_bytes: 42480
#include<bits/stdc++.h>
using namespace std;
const int N=105;
char s[N];
int flag[N],ans=1e9;
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i='a';i<='z';i++){
		for (int j=1;j<=n;j++)
			if (s[j]==i)flag[j]=1;
			else flag[j]=0;
		flag[n+1]=1;
		int num=0;
		for (int j=n;j;j--)
			for (int k=j;k<=n+1;k++)
				if (flag[k]){
					num=max(num,k-j);
					break;
				}
		ans=min(ans,num);		
	}
	printf("%d\n",ans);
}

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

using namespace std;

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

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int q; cin >> q;
    while (q--) {
        int l, m, r;
        cin >> l >> m >> r;
        auto b = v.begin();
        rotate(b + l, b + m, b + r);
    }
    rep(i, n) {
        if (i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3144
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    ll a, b; cin >> a >> b;
    if(abs(a-b) > 1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    if (a == b) ans = 2;
    rip(i,a,0) {
        ans *= i+1;
        ans %= 1000000007;
    }
    rip(i,b,0) {
        ans *= i+1;
        ans %= 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include<cstdio>
//const int maxx 1e9 ;
#define ll long long
using namespace std ;

int main(){
    string s, t ;
    cin>>s>>t ;
    int i, j ,rmv=0, lens = s.length(), ans=999999, lent = t.length() ;
    //cout<<lens<<lent<<endl ;
    for(i=0 ; i<lens-lent+1 ; i++){
        int minrmv = 0 ;
        for(j=0 ; j<lent; j++){
            if(t[j]!=s[i+j]) minrmv++ ;
        }
            ans = min(minrmv,ans) ;
            //cout<<minrmv<<" "<<ans<<endl  ;
    }
    cout<<ans<<endl ;
}


Measured memory_bytes: 3548
//abc095_b.cpp
//Sat Apr 21 20:18:56 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

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

	int min = 1000;
	int a[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
		x = x-a[i];
		if (a[i] < min){
			min = a[i];
		}
	}

	int extra = x/min;
	int ans = n + extra;

	cout << ans << endl;
}

Measured memory_bytes: 256
(set! *unchecked-math* true)

(defn input []
  (let [[N K] (->> (clojure.string/split (read-line) #"\s")
                (map #(Integer/parseInt %)))]
    (letfn [(for-input [] (Integer/parseInt (read-line)))]
      (list N K (repeatedly N for-input)))))

(defn Christmas [[N K H]]
  (let [H2 (vec (sort H))
        K2 (dec K)]
   (loop [i 0 Min (Integer/MAX_VALUE)]
     (if (< N (+ i K))
       Min
       (let [Dif (int (- (nth H2 (+ i K2)) (nth H2 i)))]
         (if (zero? Dif)
           0
           (recur (inc i) (min Dif Min))))))))

(defn Christmas2 [[N K H]]
  (let [K2 (unchecked-dec-int K)]
    (loop [H2 (sort H) Min (Integer/MAX_VALUE)]
      (if (> K (count H2))
        Min
        (let [Dif (unchecked-subtract-int (nth H2 K2) (first H2))]
          (if (zero? Dif)
            0
            (recur (rest H2) (min Dif Min))))))))

(->> (input)
  Christmas
  println)

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

using namespace std;

int n, x, y;

int a[30], b[30], c[30];

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int sum = 0;
	for(int i = 1; i <= n; i++){
		cin >> b[i];
		sum += b[i];
	}
	for(int i = 1; i <= n - 1; i++){
		cin >> c[i];
	}
	for(int i = 2; i <= n; i++){
		if(a[i] == a[i-1] + 1) sum += c[a[i-1]];
	}
	cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> cnt(n+1);
   vector<int> a(n);
   f(i,0,n){
      cin >> a[i];
      cnt[a[i]]++;
   }
   int ans = 0;
   f(i,1,n+1){
      ans += (cnt[i]*(cnt[i]-1))/2;
   }
   f(i,0,n){
      int cur = ans;
      cur -= (cnt[a[i]]*(cnt[a[i]]-1))/2;
      cnt[a[i]]--;
      cur += (cnt[a[i]]*(cnt[a[i]]-1))/2;
      cnt[a[i]]++;
      cout << cur << '\n';
   }
   return 0;
}

Measured memory_bytes: 5760
import sys
input = sys.stdin.readline


class UnionFind:
    def __init__(self, num):
        self.rank = [0] * (num+1)
        self.par = [i for i in range(num+1)]
        self.size = [1] * (num+1)

    def find_root(self, node):
        if self.par[node] == node:
            return node
        else:
            self.par[node] = self.find_root(self.par[node])
            return self.par[node]

    def same_root(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def union(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
            self.size[x] += self.size[y]

        else:
            self.par[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def find_size(self, node):
        root = self.find_root(node)
        return self.size[root]


n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
ans = [0] * m
ans.append((n*(n-1))//2)

for i in range(m-1, -1, -1):
    a, b = ab[i][0], ab[i][1]
    if uf.same_root(a, b):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - uf.find_size(a) * uf.find_size(b)
        uf.union(a, b)

for i in range(1, m+1):
    print(ans[i])


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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  double med = a[0];
  for(int i = 1; i < N; ++i) {
    med = (med + double(a[i])) / 2.;
  }
  cout << med << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static long a = sc.nextLong();
    static long b = sc.nextLong();
    static long n = sc.nextLong();
    static long result = 0;
    public static void main(String[] args) { 
        long k = Math.min(n, b - 1);
        result = a * k / b - a * (k / b);
        System.out.println(result);
    }

}


Measured memory_bytes: 35608
N,M,Q = map(int,input().split())
src = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
src.sort(reverse=True)
qs = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(Q)]

q_arr = [[] for i in range(N)]
for i,(l,r) in enumerate(qs):
    q_arr[l].append((r,i))

bit = [0] * (N+2)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = [None] * Q

last_l = N-1
for l,r in src:
    while last_l > l:
        for qr,qi in q_arr[last_l]:
            ans[qi] = bit_sum(qr+1)
        last_l -= 1
    bit_add(r+1, 1)
while last_l >= 0:
    for qr,qi in q_arr[last_l]:
        ans[qi] = bit_sum(qr+1)
    last_l -= 1

print(*ans, sep='\n')


Measured memory_bytes: 50656
g,r=map(int,input().split());
num,table=list(),list()
for i in range(g):
    num=list(map(int,input().split()))
    num.append(0)
    table.append(num)
num=[0 for i in range(r+1)]
table.append(num)
for i in range(g):
    for j in range(r):
        table[i][r]+=table[i][j]
        table[g][j]+=table[i][j]
    table[g][r]+=table[i][r]
for i in range(g+1):
    for j in range(r):
        print(table[i][j],end=" ")
    print(table[i][r])


Measured memory_bytes: 6228
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=200010, T=55;

ll ans; // :))
int n, m, k, u, v, x, y, t, a, b;
pii A[MAXN];
int cnt[T][T];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++){
		ld shit;
		cin>>shit;
		ll x=round(shit*1000000000);
		while (x%2==0) A[i].first++, x/=2;
		while (x%5==0) A[i].second++, x/=5;
		cnt[A[i].first][A[i].second]++;
//		debugp(A[i])
		if (min(A[i].first, A[i].second)>=9) ans--;
	}
	for (int i=T-2; ~i; i--) for (int j=T-2; ~j; j--)
		cnt[i][j]+=cnt[i+1][j]+cnt[i][j+1]-cnt[i+1][j+1];
	
	for (int i=1; i<=n; i++) ans+=cnt[max(0, 18-A[i].first)][max(0, 18-A[i].second)];
	ans/=2;
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 5304
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int a, b, c, d; cin >> a >> b >> c >> d;
    int t = 0;
    while (1) {
        if (t % 2 == 0) {
            c -= b;
            if (c <= 0) {
                cout << "Yes\n";
                return 0;
            }
        } else {
            a -= d;
            if (a <= 0) {
                cout << "No\n";
                return 0;
            }
        }
        t++;
    }

}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int H,W;
int sx,sy;
int bcnt;
bool field[7][7];
bool res = false;
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};

void solve(int nowx,int nowy,int ncnt){
  if(res) return;
  if(bcnt-1 == ncnt){
    for(int i=0;i<4;i++){
      int gx=nowx+dx[i],gy=nowy+dy[i];
      if(sx == gx && sy == gy){
	res = true;
	return;
      }
    }
  }
  int neigh_cnt = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(field[i][j]) continue;
      neigh_cnt = 0;
      for(int k=0;k<4;k++){
	int nx=j+dx[k],ny=i+dy[k];
	if(sx == nx && sy == ny) {
	  neigh_cnt++;
	  continue;
	}
	if(nowx == nx && nowy == ny){
	  neigh_cnt++;
	  continue;
	}
	if(nx>=0 && nx<W && ny>=0 && ny<H && field[ny][nx] == false){
	  neigh_cnt++;
	}
      }
      if(neigh_cnt == 1) {
	return;
      }
    }
  }
  for(int i=0;i<4;i++){
    int nx=nowx+dx[i],ny=nowy+dy[i];
    if(nx>=0 && nx<W && ny>=0 && ny<H && field[ny][nx] == false){
      field[ny][nx] = true;
      solve(nx,ny,ncnt+1);
      field[ny][nx] = false;
    }
  }
  return;
}

int main(){
  while(cin >> W >> H, H){
    res = false;
    bcnt = 0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> field[i][j];
	if(!field[i][j]){
	  if(bcnt==0){
	    sx = j;
	    sy = i;
	  }
	  bcnt++;
	}
      }
    }
    if(bcnt % 2 == 1) cout << "No" << endl;
    else {
      bool flg = true;
      int neigh_cnt;
      for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	  if(field[i][j]) continue;
	  neigh_cnt = 0;
	  for(int k=0;k<4;k++){
	    int nx = j+dx[k],ny = i+dy[k];
	    if(nx>=0&&nx<W&&ny>=0&&ny<H&&field[ny][nx] == false) {
	      neigh_cnt++;
	    }
	  }
	  if(neigh_cnt == 1){
	    flg = false;
	    break;
	  }
	}
	if(!flg) break;
      }
      if(!flg){
	cout << "No" << endl;
      } else {
	field[sy][sx] = true;
	solve(sx,sy,0);
	if(res) cout << "Yes" << endl;
	else cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))

now = 0
start = 0
ans = 0

while now < N - 1:
    if H[now] >= H[now + 1]:
        now += 1
    else:
        ans = max(ans, now - start)
        now += 1
        start = now
ans = max(ans, now - start)
print(ans)

Measured memory_bytes: 14252
open Scanf
open Printf
open Array

let bit k =
  let r = init 40 (fun i -> let p = 1 lsl i in k land p / p)
  in mapi (fun i _ -> r.(39-i)) r
let print_iarr a = iter (printf "%d ") a; print_newline ()

let () = scanf " %d %d" @@ fun n k ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  let count = make_matrix 2 40 0 in
  iter (fun v ->
    let b = bit v in
    iteri (fun i w ->
      count.(w).(i) <- count.(w).(i) + 1
    ) b;
  ) a;
  (* print_iarr count.(0);
  print_iarr count.(1); *)
  let score i c = (1 lsl (39-i)) * c in
  let each =
    init 40 (fun i -> score i @@ max count.(0).(i) count.(1).(i))
  in
  (* print_iarr each; *)
  (* let cml = map (fun v -> v) each in
  for i=38 downto 0 do
    cml.(i) <- cml.(i) + cml.(i+1)
  done; *)
  (* print_iarr cml; *)
  let r = ref 0 in
  let sum = ref 0 in
  bit k |> iteri (fun i v ->
    if v=1 then (
      let c = !sum + score i count.(1).(i)
      + (init (39-(i-1)-1) (fun j -> each.(i+1+j)) |> fold_left (+) 0)
      in
      r := max !r c
    );
    sum := !sum + score i count.(1-v).(i);
  );
  print_int @@ max !r !sum




Measured memory_bytes: 5248
def zeroOne(start=0):
    """Infinite sequence of alternating zero and one."""
    assert start == 0 or start == 1
    x = start
    while True:
        yield x
        x = 1 - x

def cost(S, zeroOne):
    """The number of different tiles between S and zeroOne sequence."""
    return sum(1 for c, z in zip(S, zeroOne) if int(c) == z)

S = input()

v = min(cost(S, zeroOne(0)), cost(S, zeroOne(1)))
print(v)


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

int ans;
string s;
int main(){
    cin >> s;
    if (s[0] == '1') ans++;
    if (s[1] == '1') ans++;
    if (s[2] == '1') ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    ab = [list(map(int,input().split())) for _ in range(n)]
    res = 0
    for a,b in ab[::-1]:
        a += res
        if a%b != 0:
            res += b-a%b
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 60940
//????????????2???????????§??????????????????????????????????????????????¬??????¨NG. ???????????¨??¢?´¢????????????
//??????????????????????????????????????????????????£?????????????????????????????????O(2^n)????????????????????°??§?????????
//?????????????????????????????????????????£?????????)???????????°????????¶?????????????????????????????§???????????????????§???????????¢??????????????????§?????¨?????????????????????????????????????????§????????????
#include <iostream>
#include <algorithm>
using namespace std;

int n;
int x[24], y[24], r[24], c[24];
short int dp[1 << 24];

//rem???i??????????????????i????????£???????????°1, ??????????????????????????°0
//????????????????????????????????????????????°????????§???
int dfs(int rem) {
	bool isOut[24];	//isOut[i] = ???i??????????????????????????°true
	int i, j;
	
	//if (rem == 0) return 0;
	if (dp[rem] >= 0) return dp[rem];
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < i; j++) {
			if ((rem >> j) % 2 == 0) continue;	//??¢????????????????????????
			int dd = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
			int rr = (r[i] + r[j]) * (r[i] + r[j]);
			if (dd < rr) break;
		}
		isOut[i] = (j == i);
	}
	
	int ret = 0;
	for (i = 0; i < n; i++) {
		if ((rem >> i) % 2 == 0 || !isOut[i]) continue;
		for (j = i + 1; j < n; j++) {
			if ((rem >> j) % 2 == 0 || !isOut[j]) continue;
			if (c[i] != c[j]) continue;
			//???i, j????????????????????????
			ret = max(ret, dfs(rem - (1 << i) - (1 << j)) + 2);
		}
	}
	return (dp[rem] = ret);
}

int main() {
	while (cin >> n) {
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		for (int i = 0; i < (1<<n); i++) {
			dp[i] = -1;
		}
		cout << dfs((1 << n) - 1) << endl;
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int r;
  cin >> r;
  PRINT(r*r);
}



Measured memory_bytes: 3596
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[110][10];

int main() {
	clr(dp, 0);
	dp[0][0] = 1;
	ll h, w, K;
	cin >> h >> w >> K;
	K--;
	rep(i, 1, h + 1) {
		rep(j, 0, 1 << (w - 1)) {
			ll flag = 1;
			rep(k, 1, w - 1) {
				if (((j >> (k - 1)) & 1) == 1 && ((j >> k) & 1))flag = 0;
			}
			if (flag == 0)continue;
			rep(k, 0, w) {
				ll flag1 = 0;
				if (k > 0) {
					if (((j >> (k - 1)) & 1) == 1) {
						dp[i][k - 1] += dp[i - 1][k];
						dp[i][k - 1] %= MOD;
						flag1 = 1;
					}
				}
				if (k < w - 1) {
					if (((j >> k) & 1) == 1) {
						dp[i][k + 1] += dp[i - 1][k];
						dp[i][k + 1] %= MOD;
						flag1 = 1;
					}
				}
				if (flag1 == 0) {
					dp[i][k] += dp[i - 1][k];
					dp[i][k] %= MOD;
				}
			}
		}
	}
	cout << dp[h][K] << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> pyi;
    rep(i, m) {
        int p, y;
        cin >> p >> y;
        pyi.push_back(make_tuple(p, y, i));
    }
    sort(pyi.begin(), pyi.end());

    string ans[m];
    int index = 1;
    int old_p = 0;
    for (auto& t : pyi) {
        if (get<0>(t) == old_p)
            index++;
        else
            index = 1;
        // cout << index << endl;
        // cout << string(6 - to_string(get<0>(t)).length(), '0') +
        // to_string(get<0>(t))
        //  << endl;
        // cout << get<2>(t) << endl;
        ans[get<2>(t)] = string(6 - to_string(get<0>(t)).length(), '0') +
                         to_string(get<0>(t)) +
                         string(6 - to_string(index).length(), '0') +
                         to_string(index);
        // cout << ans[get<2>(t)] << endl;
        old_p = get<0>(t);
    }

    rep(i, m) cout << ans[i] << endl;

    return 0;
}

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

int main()
{
    int n, m, c;
    cin >> n >> m >> c;

    vector<int> b(m);
    rep(i, m)
        cin >> b.at(i);

    int cnt = 0;

    rep(i, n) {
        int a;
        int s = 0;

        rep(j, m) {
            cin >> a;

            s += a * b.at(j);
        }

        if (s + c > 0)
            cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3588
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll r, g, b;
    cin >> r >> g >> b;
    if ((10 * g + b) % 4 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3540
//////////////////////////
/*      _        ____   */
/*  U  /"\  u U /"___|  */
/*   \/ _ \/  \| | u    */
/*   / ___ \   | |/__   */
/*  /_/   \_\   \____|  */
/*   \\    >>  _// \\   */
/*  (__)  (__)(__)(__)  */
/*  Compro by NULL_CT©  */
//////////////////////////
/*STL Libs*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

/*Boost to boost compile time*/
#include <boost/multiprecision/cpp_int.hpp>

#define REP(I, LIM) for (long I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using bint = boost::multiprecision::cpp_int;

static constexpr int MOD = 10000007;
static constexpr long INF = LONG_MAX;

vector<long> divisor(long n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

template <typename T> T input(void) {
  T data;
  cin >> data;
  return data;
}

//--------------------------------

void execute() {
  int n = input<int>();
  string s = input<string>();

  int cnt = 0;
  for (auto i : s) {
    if (i == 'R')
      cnt++;
  }

  int ans = 0;

  REP(i, cnt) {
    if (s[i] == 'W')
      ans++;
  }
  cout << ans << endl;
}

//--------------------------------

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

  execute();

  return (0);
}


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

int main()
{
  int N;
  string S, X, Y;
  int res = 0;
  cin >> N >> S;

  rep(i,N-1){
    int cnt=0;
    vector<char> xvec, yvec;
    X = S.substr(0,i+1);
    Y = S.substr(i+1);
    #if 0
    cout << "-----" << i << "----" << endl;
    cout << X << endl;
    cout << Y << endl;
    #endif
    rep(j,i+1){
      if(find(xvec.begin(),xvec.end(),X[j])==xvec.end()){
        xvec.push_back(X[j]);
        #if 0
        cout << X[j] << endl;
        #endif
      }
    }
    rep(j,N-i-1){
      if(find(yvec.begin(),yvec.end(),Y[j])==yvec.end()){
        #if 0
        cout << Y[j] << endl;
        #endif
        yvec.push_back(Y[j]);
      }
    }
    for(auto it=xvec.begin();it<xvec.end();it++){
      #if 0
      cout << "*** " << *it << endl;
      #endif
      if(find(yvec.begin(),yvec.end(),*it)!=yvec.end())
	cnt++;
    }
    #if 0
    cout << cnt << endl;
    #endif
    res = max(cnt, res);
  }
  cout << res << endl;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << 2 * a << endl;
	}
	else {
		cout << max(a, b) * 2 - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
int t[maxn], x[maxn], y[maxn];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d%d%d", &t[i], &x[i], &y[i]);
		int dt = t[i] - t[i - 1], dis = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		if(dt < dis || dt % 2 != dis % 2)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");	
	return 0;
}

Measured memory_bytes: 4816
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  if(s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n;
	int a[100000];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int dp[100000];
	fill_n(dp, 100000, LLONG_MAX / 2);
	dp[0] = a[0];
	int len = 1;
	for (int i = 1; i < n; i++)
		if (dp[len-1] < a[i])
			dp[len++] = a[i];
		else {
			int j = len-1;
			for (; j >= 0; j--)
				if (dp[j] < a[i])
					break;
			dp[j+1] = a[i];
		}
	cout << len << endl;
	return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  string s;

  cin >> s;

  for(int i =0 ; i<SZ(s);i++){
    if(i ==0 && s.at(i) == 'B'){
s.erase(i,1);
i = -1;
    }
    if(i > 0&&s.at(i) == 'B'){
      s.erase(i - 1,2);
      i = -1;
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    # test()
    res = []
    n, m, l = map(int, input().split())
    a = []
    b = []

    for _ in range(n):
         a.append(list(map(int, input().split())))

    for _ in range(m):
         b.append(list(map(int, input().split())))

    for i in range(n):
        for j in range(l):
            s = 0
            for k in range(m):
                s += a[i][k] * b[k][j]
            res.append(s)

    for i in range(len(res)):
        if (i % l) == l-1:
            print(res[i])
        else: 
            print(res[i], end=" ")




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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll a, b, h, m;
	cin >> a >> b >> h >> m;
	
	complex<double> u = polar(double(a), double(60*h+m)/12/60 * 2 * M_PI);
	complex<double> v = polar(double(b), double(m)/60 * 2 * M_PI);
	
	cout << fixed << setprecision(20) << abs(u-v) << endl;
}



Measured memory_bytes: 4112
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

signed main(){
	int A,B,C;
	cin >> A >> B >> C;
	swap(A,B);
	swap(A,C);
	out(A,B,C);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  char a,b;
  cin >> a >> b;
  if(a==b) pr("H");
  else pr("D");
}

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1e9+7;

int N;
int a[21][21]; // [boy-index][girl-index]
int dp[21][2100000]; // [boy-index][paired girls bitmap] => # of possible pairs
bool done[21][2100000];

LL solve(int boyIndex, const int pairedGirls = 0)
{
    LL ret = dp[boyIndex][pairedGirls];
    if (!done[boyIndex][pairedGirls]) {
        for (int girlIndex = 0, girlBit = 1; girlIndex < N; ++girlIndex, girlBit *= 2) { 
            if ((pairedGirls & girlBit) == 0 && a[boyIndex][girlIndex]) {
                //! if the girl is not paired yet and the boy and the girl are in good match,
                if (boyIndex == N-1) {
                    ++ret;
                } else {
                    ret = (ret + solve(boyIndex+1, pairedGirls|girlBit)) % MOD;        
                }
            }
        }
        dp[boyIndex][pairedGirls] = ret;
        done[boyIndex][pairedGirls] = true;
    }
    return ret;
}

int main()
{
    cin >> N;
    rep(i, N) rep(j, N) cin >> a[i][j];

    cout << solve(0) << endl;

    return 0;
}


Measured memory_bytes: 203008
#include <stdio.h>
        #include <stdlib.h>
         
        int main() {
         
        	int num_a, num_b, num_c, num_d;
        	int max_s,min_e;
        	int res = 0;
         
        	scanf("%d %d %d %d", &num_a, &num_b, &num_c, &num_d);
         
        	max_s = (num_a > num_c) ? num_a : num_c;
         
        	min_e = (num_b < num_d) ? num_b : num_d;
         
        	res = min_e - max_s;
         
        	if (res < 0) {
        		printf("%d", 0);
        	} else {
        		printf("%d", res);
        	}
         
        	return 0;
         
        }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 100003;
const LL C = 2e17;
template<typename T>
inline void read(T &x){
    int ch = getchar(); x = 0; bool f = false;
    for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
    for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
    if(f) x = -x;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n;
LL x[N], y[N];
bool qry(LL a, LL b, LL c){return c >= a && (C - a - b & c - a) == c - a;}
bool qry(LL c){
    bool ans = false;
    for(Rint i = 0;i < n;++ i) ans ^= qry(x[i], y[i], c);
    return ans;
}
void calc(LL m, LL v, bool res[3]){
    bool dp[2][3][60] = {0}; dp[1][0][59] = true;
    for(Rint i = 58;~i;-- i){
        int w = 1 + (i & 1);
        for(Rint j = 0;j < 3;++ j){
            dp[0][j][i] ^= dp[0][j][i + 1];
            dp[!(v>>i&1)][j][i] ^= dp[1][j][i + 1];
            if(m>>i&1){
                dp[0][(j+w)%3][i] ^= dp[0][j][i + 1];
                if(v>>i&1) dp[1][(j+w)%3][i] ^= dp[1][j][i + 1];
            }
        }
    }
    for(Rint i = 0;i < 3;++ i) res[i] = dp[0][i][0] ^ dp[1][i][0];
}
void calc(LL m, LL l, LL r, bool res[3]){
    chmax(l, 0ll); chmin(r, m);
    if(l > r){res[0] = res[1] = res[2] = 0; return;}
    bool sr[3] = {0}, vr[3] = {0};
    if(l) calc(m, l-1, sr); calc(m, r, vr);
    for(Rint i = 0;i < 3;++ i) res[i] = vr[i] ^ sr[i];
}
LL solve(LL l, LL r){
    if(l == r) return l;
    LL mid = l + r >> 1; bool res[3] = {0}, tmp[3] = {0};
    for(Rint i = 0;i < n;++ i){
        calc(C - x[i] - y[i], l - x[i], mid - x[i], tmp);
        int tt = (x[i] % 3 + 3) % 3;
        for(Rint j = 0;j < 3;++ j) res[(j+tt)%3] ^= tmp[j];
    }
    if(res[0] || res[1] || res[2]) return solve(l, mid);
    return solve(mid + 1, r);
}
int main(){
    read(n);
    for(Rint i = 0;i < n;++ i){read(x[i]); read(y[i]);}
    LL lst = solve(-1e17, 3e17), rst = lst;
    for(Rint i = 58;~i;-- i) if(qry(lst-(1ll<<i))) lst -= 1ll<<i;
    for(Rint i = 58;~i;-- i) if(qry(rst+(1ll<<i))) rst += 1ll<<i;
    printf("%lld %lld\n", lst, C - rst);
}

Measured memory_bytes: 3944
use std::f64::consts::PI;
 
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
 
fn main() {
    input! {
        r: f64,
    }
 
    println!("{}", r * 2.0 * PI);
}

Measured memory_bytes: 2164
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, D, L, R,K;
ll A;
ll B[200001];
ll ans;
string S;
char s[52][52];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}


int main() {
	ll x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2;
	x3 = x2-(y2-y1);
	y3 = y2 + (x2 - x1);
	cout << x3 << " " << y3 << " ";
	x4 = x3 - (x2 - x1);
	y4 = y3 - (y2 - y1);
	cout << x4 << " " << y4 << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long n;
void solve()
{
    long x=n,u=0;
    while(x) {u+=x%10;x/=10;}
    if (n%u) cout<<"No";
    else cout<<"Yes";
    cout<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

const int maxn = 2e5 + 5;

vector<int> g[maxn];

int dp1[maxn], dp2[maxn], n;

void dfs(int u, int p){
	
	int mx = -1, smx = -1;
	for(auto &v : g[u]){
		if(v != p){
			dfs(v, u);
			dp1[u] = max(dp1[u], 1 + dp1[v]);
			
			if(dp1[v] >= mx){
				smx = mx;
				mx = dp1[v];
			}
			else if(dp1[v] >= smx)
				smx = dp1[v];
		}
	}
	
	if(mx != -1 && smx != -1)
		dp2[u] = 2 + mx + smx;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	for(int i = 1, a, b; i < n; i++){
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	dfs(1, 0);
	
	int diameter = 0;
	for(int i = 1; i <= n; i++){
		diameter = max(diameter, dp1[i]);
		diameter = max(diameter, dp2[i]);
	}
	
	int rem = diameter % 3;
	
	if(rem == 1)
		cout << "Second" << endl;
	else
		cout << "First" << endl;

	return 0;
}


Measured memory_bytes: 27008