akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
#include <set>

typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll R;
	cin >> R;
	
		cout << 2 * 3.14159265358979323846 * R << endl;

	

	return 0;

}


Measured memory_bytes: 3796
#include <iostream>
using namespace std;
int main(void){
  int i, n, k=0;
  cin >> n;
  int a[100]={}, c[100] = {};
  for(i=0;i<n;i++) {
    cin >> a[i];
  }
  for(i=0;i<9;i++){
    c[i] = 0;
  }

  for(i=0;i<n;i++){
    if(a[i] >=    1 && a[i] <=  399) c[0]++;
    if(a[i] >=  400 && a[i] <=  799) c[1]++;
    if(a[i] >=  800 && a[i] <= 1199) c[2]++;
    if(a[i] >= 1200 && a[i] <= 1599) c[3]++;
    if(a[i] >= 1600 && a[i] <= 1999) c[4]++;
    if(a[i] >= 2000 && a[i] <= 2399) c[5]++;
    if(a[i] >= 2400 && a[i] <= 2799) c[6]++;
    if(a[i] >= 2800 && a[i] <= 3199) c[7]++;
    if(a[i] >= 3200                ) c[8]++;
  }

  for(i=0;i<9;i++){
    if(c[i]!=0) k++;
  }

  if(c[8]!=0){
    k--;
  }
  if(k==0){
    k=1;
    c[8]--;
  }

  cout << k << " " << k+c[8] << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> dp((1 << n), INF);
	vector<int> a(m), b(m);
	vector<vector<int>> c(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		c[i].resize(b[i]);
		rep(j,b[i]){
			cin >> c[i][j];
			c[i][j]--;
		}
	}
	dp[0] = 0;
	rep(i,(1 << n)){
		rep(j,m){
			int nextS = i;
			rep(k,b[j]){
				if(!(nextS >> c[j][k] & 1)) nextS += (1 << c[j][k]);
			}
			chmin(dp[nextS] , dp[i] + a[j]);
		}
	}
	int ans = dp[(1 << n)-1];
	if(ans == INF) ans = -1;
	cout << ans << endl;
	return 0;
}

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

int main(){
ll D, T, S, A = 0;cin >> D >> T >> S;

if(T*S >= D)cout << "Yes";
  
else cout << "No";



}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  char c;
  cin >> c;
  if(islower(c)) cout << "a" << endl;
  else cout << "A" << endl;
  return 0;
}

Measured memory_bytes: 3592
#define NDEBUG
#include <cassert>
#include <deque>
#include <functional>
#include <utility>

template <typename Key, typename T, class Compare = std::greater<Key>>
class _01Heap {
public:
	using key_type = Key;
	using mapped_type = T;
	using value_type = std::pair<key_type, mapped_type>;
	using reference = value_type &;
	using const_reference = const value_type &;
	using key_compare = Compare;
	using container_type = std::deque<value_type>;
	using size_type = typename container_type::size_type;
	class value_compare {
		friend class _01Heap;
		const key_compare comp;
		value_compare() : comp() {}

	public:
		constexpr bool operator()(const_reference x, const_reference y) const {
			return comp(x.first, y.first);
		}
	};

private:
	const value_compare comp;
	container_type dq;
	size_type size_;

public:
	_01Heap() : comp(), dq(), size_(0) {}
	const_reference top() const {
		assert(size_);
		return dq.front();
	}
	void pop() {
		assert(size_);
		--size_;
		dq.pop_front();
	}
	void push(const_reference x) {
		assert(!size_||!comp(dq.front(), x));
		if (!size_)
			dq.push_front(x);
		else if (comp(x, dq.front())) {
			assert(!comp(dq.back(), x));
			dq.push_back(x);
		}
		else
			dq.push_front(x);
		++size_;
	}
	size_type size() const noexcept { return size_; }
	bool empty() const noexcept { return !size_; }
};


struct edge {
	int to;
	int cost;
};
#include<iostream>
#include<vector>
#include<limits>
#include<tuple>
int main(void) {
	int k;
	std::cin >> k;
	std::vector<std::vector<edge>> G(k);
	for (int i = 0;i < k;++i) {
		G[i].push_back({ i * 10 % k,0 });
		G[i].push_back({ (i + 1) % k,1 });
	}
	_01Heap<int, int> Q;
	static constexpr int INF = std::numeric_limits<int>::max();
	std::vector<int> d(k, INF);
	Q.push({ 1,1 });
	d[1] = 1;
	int v, c;
	while (!Q.empty()) {
		std::tie(c, v) = Q.top();Q.pop();
		if (d[v] < c) continue;
		for (const auto &e : G[v]) {
			if (c + e.cost < d[e.to]) {
				d[e.to] = c + e.cost;
				Q.push({ d[e.to],e.to });
			}
		}
	}
	std::cout << d[0] << std::endl;
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    string T;
    int ans = 0;
    rep(i, S.size()){
        T = "";
        if(S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G'){
            T += S[i];
        }else{
            continue;
        }
        for(int j = i+1; j <= S.size(); j++){
            if(j != S.size()){
                if(S[j] == 'A' || S[j] == 'T' || S[j] == 'C' || S[j] == 'G'){
                    T += S[j];
                }else{
                    break;
                }
            }
        }
        int Tsize = T.size();
        ans = max(ans, Tsize);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  
  for (int i = n - 1; i >= 0; i -= 2) {
    cout << v[i] << " ";
  }
  for (int i = n % 2; i < n; i += 2) {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main() {
  solve();
  return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;

int main() {
  int N,X; cin >> N >> X;
  vector <int> M(N); rep(i, N) cin >> M[i];
  
  int sum=0;
  rep(i, M.size()) {
    sum += M[i];
  }
  X -= sum;
  int min = *min_element(M.begin(), M.end());
  
  int min_cnt = X/min;
  dump(N + min_cnt);
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = 1001001001001

// Data :
type Data struct {
	x, num int
}

// Datas :
type Datas []Data

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	return p[i].num > p[j].num
}
func main() {
	sc.Split(bufio.ScanWords)
	n := getInt()
	a0 := make(map[int]int)
	a1 := make(map[int]int)
	c0 := 0
	c1 := 0
	for i := 0; i < n; i++ {
		v := getInt()
		if i%2 == 0 {
			a0[v]++
			c0++
		} else {
			a1[v]++
			c1++
		}
	}

	b0 := make(Datas, 0)
	b1 := make(Datas, 0)
	for i, v := range a0 {
		b0 = append(b0, Data{i, v})
	}
	b0 = append(b0, Data{inf, 0})
	for i, v := range a1 {
		b1 = append(b1, Data{i, v})
	}
	b1 = append(b1, Data{inf, 0})

	sort.Sort(b0)
	sort.Sort(b1)

	ans := 0
	if b0[0].x == b1[0].x {
		ans = min(
			c0-b0[0].num+c1-b1[1].num,
			c0-b0[1].num+c1-b1[0].num)
	} else {
		ans = c0 - b0[0].num + c1 - b1[0].num
	}

	out(ans)
}


Measured memory_bytes: 9728
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k: usize = read();
    let s: usize = read();
    let mut cnt = 0;
    let mut memo: Vec<i64> = vec![0; 2500 * 2 + 2];

    for i in 0..k + 1 {
        for j in 0..k + 1 {
            memo[i + j] += 1;
        }
    }

    for i in 0..k + 1 {
        if s >= i && s - i <= 5000 {
            cnt += memo[s - i];
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
	 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, cnt, p[N][3], sum[3], res[N];
string s;

void f (int m, int i) {
	if (m <= 0)
		return;

	p[0][i] = 1 % m;
	for (int j = 1; j < N; ++j)
		p[j][i] = p[j - 1][i] * 2 % m;
}

int F (int x) {
	if (!x)
		return 0;
	return F(x % __builtin_popcount(x)) + 1;
}


main () {
	cin >> n >> s;
	reverse(all(s));
	for (auto c : s)
		if (c == '1')
			++cnt;

	f(cnt, 0);
	f(cnt - 1, 1);
	f(cnt + 1, 2);

	for (int i = 0; i < n; ++i)
		if (s[i] == '1') 
			for (int j = 0; j < 3; ++j)
				sum[j] += p[i][j];
			
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == '1') {
			if (cnt == 1) {
				cout << 0 << endl;
				continue;	
			}

			int Sum = sum[1] - p[i][1];
			Sum = (Sum + cnt - 1) % (cnt - 1);
			cout << F(Sum) + 1 << endl;
		} else {
			int Sum = (sum[2] + p[i][2]) % (cnt + 1);
			cout << F(Sum) + 1 << endl;
		}
	}
}
	
        	
//check for the constants

                                                                                   	

                     	             

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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
	
		var s = Input();
		
		var set = new HashSet<string>();
		for(int i = 0; i < n; i++)
		{
			if(!set.Contains(s[i]))
				set.Add(s[i]);
		}
		Console.WriteLine(set.Count == 3 ? "Three" : "Four");
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13280
n = int(input())
p= list(map(int, input().split()))

ans = 0
for i in range(n-2):
    b = [p[i],p[i+1],p[i+2]]
    if p[i+1]!=max(b) and p[i+1]!=min(b):
        ans+=1
print(ans)


Measured memory_bytes: 3060
n = int(input())

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


N = A[:]
ncount = 0
if N[0] >= 0:
    ncount += abs(N[0]) + 1
    N[0] = -1
for i in range(1, n):
    N[i] +=  N[i-1]
    if i % 2 == 1:
        if N[i] <= 0:
            ncount += abs(N[i]) + 1
            N[i] = 1
    else:
        if N[i] >= 0:
            ncount += abs(N[i]) + 1
            N[i] = -1

P = A[:]
pcount = 0
if P[0] <= 0:
    pcount += abs(P[0]) + 1
    P[0] = 1
for i in range(1, n):
    P[i] +=  P[i-1]
    if i % 2 == 0:
        if P[i] <= 0:
            pcount += abs(P[i]) + 1
            P[i] = 1
    else:
        if P[i] >= 0:
            pcount += abs(P[i]) + 1
            P[i] = -1



print(min(ncount, pcount))

Measured memory_bytes: 14332
n = int(input())

if n==1:
    print("a")
    exit()

alp = "abcdefghijklmnopqrstuvwxyz"

def next(s,n):
    if n==0:
        print(s)
        return
    val = len(set(s)) # 1 => only a, 2=> a and b
    for i in range(val+1):
        next(s + alp[i],n-1)

s="a"
next(s,n-1)

Measured memory_bytes: 52184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<ll, ll>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

    int n, m;
    cin >> n >> m;

    vector<P> p;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        p.emplace_back(a, b);
    }

    sort(all(p));

    ll ans = 0;
    int k = 0;
    rep(i, n){
        if(k + p[i].second < m){
            ans += p[i].first * p[i].second;
            k += p[i].second;
        }
        else{
            ans += p[i].first * (m - k);
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    int n,d,left,ans=0;
    cin>>n>>d>>left;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        for(int i=1;i<=d;i+=x)
        {
            ++ans;
        }
    }
    cout<<ans+left;
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int n, s[105];
int main(){
//freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> s[i];
        sum+=s[i];
    }
    sort(s+1,s+1+n);
    if(sum%10!=0) cout << sum << endl;
    else{
        for(int i = 1; i <= n; i++){
            if(s[i] % 10 != 0){
                sum-=s[i];
                cout << sum << endl;
                return 0;
            }
        }
        cout << "0" << endl;
    }
    return 0;
}

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

#define INF 1e9;
//#define mod 1e9+7

//#define max(x,y) (x>y)?x:y
//#define min(x,y) (x<y)?x:y
#define rep(i,j,k) for(int i=j;i<k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define mi(n) (int*)malloc(sizeof(int)*n);
#define mc(n) (char*)malloc(sizeof(char)*n);

using namespace std;
int mod=1000000007;

int main(){
    string s,ss;
   getline(cin,s);
   getline(cin,ss);
   
   int maxx=max(s.length(),ss.length());
   
   rep(i,0,maxx){
       if(i<s.length()) cout<<s[i];
       if(i<ss.length())cout<<ss[i];
   }

   
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef    long long          ll;
typedef    vector<long long>    vi; 
typedef    vector<vi>         vvi; 
typedef    pair<long,long>      ii; 
#define    sz(a)              long((a).size()) 
#define    pb                 push_back 
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end() 
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define    present(c,x)       ((c).find(x) != (c).end()) 
#define    cpresent(c,x)      (find(all(c),x) != (c).end())  
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "


ll inf = 1e18;

ll n;
ll a[403],s[403];
ll dp[403][403];


ll fnd( ll i, ll j)
{
  if(dp[i][j])return dp[i][j];
  if(j-i==1){
    return a[i]+a[j];
  }
  if(i == j) return 0;

  ll ret = inf;
  for(ll l=i;l<j;l++)
  {
    ret = min(fnd(i,l)+fnd(l+1,j)+s[j]-((i>0)?s[i-1]:0),ret);
  }
  dp[i][j]=ret;
  return dp[i][j];
}

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


  ll i;
  cin>>n;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
    s[i]=a[i];
    if(i)
    {
      s[i]+=s[i-1];
    }
  }
  cout<<fnd(0,n-1)<<"\n";


  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a,b;
	cin >> a >> b;
	const int N = 100;
	int g[N][N];
	--a;--b;
	for(int i = 0;i < 50;++i){
		for(int j = 0;j < 100; ++j){
			g[i][j] = 0;
		}
	}
	for(int i = 50;i < 100;++i){
		for(int j = 0;j < 100; ++j){
			g[i][j] = 1;
		}
	}
	for(int i = 0;i < 50; i += 2){
		for(int j = 0;j < 100; j+=2){
			if(a){
				--a;
				g[i][j]^=1;
			}
		}
	}
	for(int i = 51;i < 100; i += 2){
		for(int j = 0;j < 100; j+=2){
			if(b){
				--b;
				g[i][j]^=1;
			}
		}
	}
	cout << N << ' ' << N << '\n';
	for(int i = 0;i < N; ++i){
		for(int j = 0;j < N; ++j)
			cout << (g[i][j]?'.':'#');
		cout << '\n';
	}
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	while (true) {
		int N, M;
		cin >> N >> M;
		if(N==0)break;
		vector<pair<int, int>> mm(N);
		REP(i, M) {
			int s, k, tmp;
			cin >> s >> k;
			// maximum
			REP(j, k) {
				cin >> tmp;
				tmp--;
				mm[tmp].first += s;
			}
			// minimum
			if (k == 1)mm[tmp].second += s;
		}
		vector<pair<int, int>> mini, maxi;
		REP(i, N) {
			maxi.push_back({ mm[i].first,i });
			mini.push_back({ mm[i].second,i });
		}
		sort(maxi.begin(), maxi.end(), greater<pair<int,int>>());
		sort(mini.begin(), mini.end());
		if (maxi.front().second != mini.front().second) {
			cout << maxi.front().first - mini.front().first + 1 << endl;
		}
		else {
			cout << max(
				maxi.front().first - mini[1].first,
				maxi[1].first - mini.front().first
			) + 1 << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3312
#include<stdio.h>
int main(){
  int n,h[100001],i,j;
  int cnt=0,max=0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&h[i]);
  }
  for(i=0; i<n-1; i++){
    int j=i+1;
    if(h[i]>=h[j]){
      cnt++;
    }
    else{
      if(cnt>max){
        max=cnt;
      }
      else{
        max=max;
      }
      cnt=0;
    }
    if(cnt>max){
      max=cnt;
    }
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>
#include <bitset>

#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Pair = pair<ll, ll>;

ll n, x;
vector<ll> as;

ll solve() {
    sort(as.begin(), as.end());
    
    ll haveX = x;
    for (int i = 0; i < n; i++) {
        if (haveX == as[i])
            return i + 1;
        if (haveX < as[i])
            return i;
        haveX -= as[i];
    }
    return n - 1;
}

int main() {
    cin >> n >> x;
    as.resize(n);
    for (auto& v : as)
        cin >> v;
    
    cout << solve() << endl;
    
    return 0;
}



Measured memory_bytes: 256
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val +=  (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

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

using namespace std;

int field[50][50];
int N,M;
void dfs(int x,int y){
    field[x][y]=0;
    for(int dx=-1;dx<=1;dx++){
        for(int dy=-1;dy<=1;dy++){
            int nx=x+dx,ny=y+dy;
            if(0<=nx&&nx<N&&0<=ny&&ny<M&&field[nx][ny]==1)dfs(nx,ny);
        }
    }
}
int main(){
    for(;;) {
        cin>>M>>N;
        if(N==0)break;
        rep(i,N){
            rep(j,M){
                cin>>field[i][j];
            }
        }
        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if (field[i][j] == 1) {
                    dfs(i, j);
                    res++;
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3260
#include <iostream>
#include <queue>

struct P {
	int x, y;
	P() {}
	P(int x, int y) : x(x), y(y) {}
};

using namespace std;

typedef long long ll;

int main() {
	int W, H;
	while ( cin >> W >> H, W || H ) {
		int N; cin >> N;
		ll dp[16][16] = {0};
		bool X[16][16] = {0};
		for (int i = 0; i < N; ++i) {
			int x, y; cin >> x >> y;
			--x, --y;
			X[y][x] = true;
		}

		dp[0][0] = 1;
		bool gone[16][16] = {0};
		queue<P> Q; Q.push( P(0, 0) );
		while ( !Q.empty() ) {
			P p = Q.front(); Q.pop();
			if ( gone[p.y][p.x] ) continue;
			gone[p.y][p.x] = true;

			if ( p.y+1 < H && !X[p.y+1][p.x] ) dp[p.y+1][p.x] += dp[p.y][p.x], Q.push( P(p.x, p.y+1) );
			if ( p.x+1 < W && !X[p.y][p.x+1] ) dp[p.y][p.x+1] += dp[p.y][p.x], Q.push( P(p.x+1, p.y) );
		}
		cout << dp[H-1][W-1] << endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a[55];
signed main(){
	int n,k;
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++)ans+=a[i];
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

int main(void){
  int x,y,z;
  std::cin >> x >> y >> z;
  std::cout << z << " " << x << " "  << y;
  return 0;
}


Measured memory_bytes: 3588
import java.security.SecureRandom;
import java.sql.Array;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int count = 0;
//       if (s.charAt(0)=='R')count++;
//       else count=0;
//       if (s.charAt(1)=='R')count++;
//       else count=0;
//        if (s.charAt(2)=='R')count++;
//        else count=0;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'R') count++;
            else count = 0;
            if (count > max) max = count;
        }

            System.out.println(max);

    }
    }






Measured memory_bytes: 35516
// AOJ 	0340: Pancake
// 2018.1.26 bal4u

#include <stdio.h>
#include <string.h>

char p[5002];
char f[5002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, n1, i, j, t, ans;
 
    n = in(), n1 = n-1;
	for (i = 0 ;i < n; i++) p[i] = in();
	ans = 6*n;
	for (i = 0; i <= p[0]; i++) {
		memcpy(f, p, n);
		t = i, f[0] -= i;
		for (j = 0; j < n1 ; j++) {
			t += f[j] << 1;
			f[j+1] -= f[j];
			if (f[j+1] < 0) f[j+1] = 0;
		}
		t += f[n1];
		if (t < ans) ans = t;
	}
	printf("%d\n", ans);
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i = 0; i < n; ++i){
    cin >> d[i];
  }
  sort(d,d+n);
  int res = 1;
  for(int i = n-2; i >= 0; --i){
    if(d[i] < d[i+1]){
      ++res;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
   double a,b,c,d,e,f;
   double x,y;
   while(cin >> a >> b >> c >> d >> e >> f)
   {
        x=(c*e-f*b)/(a*e-d*b);
        y=(c*d-f*a)/(b*d-e*a);
        if(x>-0.001 && x<0.001)x=0;
        if(y>-0.001 && y<0.001)y=0;
      printf("%1.3f %1.3f\n" ,x,y);
   }
    return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, a;
    cin >> n >> m;
    long long sum = 0;
    while (m--) {
        cin >> a;
        sum += a;
    }

    cout << (sum > n ? -1 : n - sum) << '\n';
    return 0;
}



Measured memory_bytes: 3652
# coding: utf-8


def solve(*args: str) -> str:
    n, m, k = map(int, args[0].split())
    mod = 998244353

    if m == 1 and n-1 == k:
        return str(1)

    iR = [1]
    C = [1]
    for i in range(1, k+1):
        iR.append(max(1, (-(mod//i) * iR[mod % i]) % mod))
        C.append((n-i)*C[i-1]*iR[i] % mod)

    ret = 0
    p = m*pow(m-1, n-1-k, mod) % mod
    for i in range(1, k+1):
        ret += p*C[-i] % mod
        p = p*(m-1) % mod
    ret += p

    return str(ret % mod)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 24976
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    while(b<=a&&k>0){
        b*=2;
        k--;
    }
    while(c<=b&&k>0){
        c*=2;
        k--;
    }
    if(a<b&&b<c){
        puts("Yes");
    }else{
        puts("No");
    }

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define int long long int
#define ld long double
#define pb push_back
#define pf push_front
#define ft first
#define sc second
#define all(v) v.begin(), v.end()
using namespace std;
const int maxn = 201001;
bool is_p(string s) {
    for (int d = 0; d < s.size(); d++) {
        if (s[d] != s[s.size() - 1 - d]) return false;
    }
    return true;
}
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    if (!is_p(s)) {
        cout << "No\n";
        return 0;
    }
    string s1 = "";
    for (int d = 0; d < s.size() / 2; d++) {
        s1.pb(s[d]);
    }
    //cout << s1 << "\n";
    if (!is_p(s1)) {
        cout << "No\n";
        return 0;
    }
    s1 = "";
    for (int d = (s.size() + 1) / 2; d < s.size(); d++) {
        s1.pb(s[d]);
    }
    //cout << s1 << "\n";
    if (!is_p(s1)) {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
 
const int vmax=10001;
const int inf=1<<29;
struct edge{int to,cap,cost,rev;};
vector<edge> graph[vmax];
 
int h[vmax],dist[vmax];
int pv[vmax],pe[vmax];
typedef tuple<int,int> state;
 
void add_edge(int from,int to,int cap,int cost){
    graph[from].push_back({to,cap,cost,(int)graph[to].size()});
    graph[to].push_back({from,0,-cost,(int)graph[from].size()-1});
}
 
int min_cost_flow(int s,int t,int f,int n){
    int res=0;
    fill(h,h+n,0);
    while(f>0){
        priority_queue <state,vector<state>,greater<state> > q;
        fill(dist,dist+n,inf);
        dist[s]=0;
        q.push(state(0,s));
        while(!q.empty()){
            int cost,v;
            tie(cost,v)=q.top();q.pop();
            if(dist[v] < cost) continue;
            rep(i,graph[v].size()){
                edge &e=graph[v][i];
                if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                    dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
                    pv[e.to]=v,pe[e.to]=i;
                    q.push(state(dist[e.to],e.to));
                }
            }
        }
        if(dist[t]==inf) return -1;
        rep(v,n) h[v]+=dist[v];
 
        int d=f;
        for(int v=t;v!=s;v=pv[v]) d=min(d,graph[pv[v]][pe[v]].cap);
        f-=d;res+=d*h[t];
        for(int v=t;v!=s;v=pv[v]){
            edge &e=graph[pv[v]][pe[v]];
            e.cap-=d;
            graph[v][e.rev].cap+=d;
        }
    }
    return res;
}
 
signed main(void){
    int n; cin >> n;
    vector<pair<int, int>> rects(n);
    int idx = n;
    map<int, int> l2i;
    for(auto & e : rects){
        int a, b; cin >> a >> b;
        e = make_pair(a, b);

        if(l2i.find(a) == end(l2i)) l2i[a] = idx++;
        if(l2i.find(b) == end(l2i)) l2i[b] = idx++;
    }

    int dummy = idx++, s = idx++, t = idx++;

    rep(i, n){
        add_edge(s, i, 1, 0);
    }
    range(i, n, dummy){
        add_edge(i, t, 1, 0);
    }
    add_edge(dummy, t, inf, 0);

    rep(i, n){
        add_edge(i, l2i[rects[i].first] , 1, -rects[i].second);
        add_edge(i, l2i[rects[i].second], 1, -rects[i].first );
        add_edge(i, dummy, 1, 0);
    }

    cout << -min_cost_flow(s, t, n, idx) << endl;

    return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v) cout << i << ' ' << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vin2(v, w) for (ll i = 0; i < v.size(); ++i) cin >> v[i] >> w[i];
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 (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }

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

	int N; cin >> N;
	string str;
	int cnt_R = 0;
	int cnt_ok = 0;
	rep(i, N){
		char chr; cin >> chr;
		if(chr == 'R')cnt_R++;
		str.push_back(chr);
	}
	rep(i, cnt_R){
		if(str.at(i) ==	'R')cnt_ok++;
	}
	//cout << str;
	//cout << cnt_R;
	//cout << cnt_ok;
	cout << cnt_R - cnt_ok;
}


Measured memory_bytes: 3788
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
ans = 0
for i in range(n):
  tmp=0
  for j in range(n):
    if s[i] == s[j]:
      tmp+=1
  for j in range(m):
    if s[i] == t[j]:
      tmp-=1
  ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 3064
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (x, a, b) = readListOfInt()

    val eatDay = b - a
    println(when {
        (eatDay <= 0) -> "delicious"
        (eatDay <= x) -> "safe"
        else -> "dangerous"
    })
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }


// Extensions
fun<T> List<T>.toBuckets(bucketKeys: List<T>): Map<T, Int> {
    val buckets = bucketKeys.associate { t -> Pair(t, 0) }.toMutableMap()
    this.forEach { t ->
        buckets[t] = buckets[t]!! + 1
    }
    return buckets
}

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> = HashMap(this)

// Util Functions
fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37876
n, k = map(int,input().split())
d = list(map(int,input().split()))

for i in range(n,100001):
    x = 0
    for j in str(i):
       
        if int(j) in d:
            x = 1
            break
   
    if x == 1:
        pass
    else:
        break
print(i)

Measured memory_bytes: 2940
#include <cstdio>
#include <complex>
#include <algorithm>
using namespace std;
// ------ FFT ------ //
const double pi = 3.14159265358979323;
const int sz = 4096; // more than 2 * n
double va[4105], vb[4105], v[4105]; complex<double> fa[4105], fb[4105];
void dft(complex<double> *x, bool rev) {
	for (int i = 0, j = 1; j + 1 < sz; j++) {
		for (int k = sz >> 1; k > (i ^= k); k >>= 1);
		if (i > j) swap(x[i], x[j]);
	}
	for (int i = 1; i < sz; i <<= 1) {
		complex<double> b = polar(1.0, (rev ? -1.0 : 1.0) * pi / i);
		for (int j = 0; j < sz; j += i << 1) {
			complex<double> mul(1.0, 0.0);
			for (int k = 0; k < i; k++) {
				complex<double> xa = x[j + k], xb = mul * x[j + k + i];
				x[j + k] = xa + xb;
				x[j + k + i] = xa - xb;
				mul *= b;
			}
		}
	}
	if (rev) for (int i = 0; i < sz; i++) x[i] /= sz;
}
void fft() {
	for (int i = 0; i < sz; i++) fa[i] = va[i]; dft(fa, false);
	for (int i = 0; i < sz; i++) fb[i] = vb[i]; dft(fb, false);
	for (int i = 0; i < sz; i++) fa[i] *= fb[i]; dft(fa, true);
	for (int i = 0; i < sz; i++) v[i] = fa[i].real();
}
// ------ Main Part ------ //
int n, pre[4009], nxt[4009], val[2009], v1[2009], v2[2009], c[2009]; char a[2009], b[2009];
int main() {
	scanf("%s%s", a, b);
	int bit = 0;
	while (b[n]) {
		if (b[n] == '1') bit |= 2;
		if (a[n] != b[n]) bit |= 1;
		n++;
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			va[j] = (a[n - j - 1] == i + 48 ? 1.0 : 0.0);
			vb[j] = (b[j] == (i ^ 1) + 48 ? 1.0 : 0.0);
		}
		fft();
		for (int j = 1; j < 2 * n; j++) c[j < n ? j : j - n] += (int)(v[j - 1] + 0.5);
	}
	int ret = 1 << 30;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			if (b[j] == '1') {
				nxt[n + j] = 0;
				for (int k = j; k < n + j; k++) pre[k] = (b[k < n ? k : k - n] == '1' ? 0 : pre[k - 1] + 1);
				for (int k = n + j - 1; k >= j; k--) nxt[k] = (b[k < n ? k : k - n] == '1' ? 0 : nxt[k + 1] + 1);
				for (int k = 0; k < j; k++) pre[k] = pre[k + n], nxt[k] = nxt[k + n];
				break;
			}
		}
		fill(val, val + n, 0);
		for (int j = 0; j < n; j++) {
			if (a[j] == '0') pre[j] = nxt[j] = 0;
			val[pre[j]] = max(val[pre[j]], nxt[j]);
		}
		for (int j = n - 1; j >= 0; j--) val[j] = max(val[j], val[j + 1]);
		fill(v1, v1 + n, 1 << 30);
		fill(v2, v2 + n, 1 << 30);
		for (int j = 1; j <= n; j++) {
			v1[val[j]] = min(v1[val[j]], (j - 1) * 2 + val[j] * 2);
			v2[val[j]] = min(v2[val[j]], (j - 1) * 2);
		}
		for (int j = n - 2; j >= 0; j--) v1[j] = min(v1[j], v1[j + 1]);
		int cl = 1 << 30;
		for (int j = 0; j < n; j++) {
			cl = min(cl, v2[j]);
			ret = min(ret, c[j] + min(cl + j, v1[j] - j));
		}
		for (int j = 0; j < n - j; j++) swap(a[j], a[n - j - 1]), swap(b[j], b[n - j - 1]);
		for (int j = 1; j < n - j; j++) swap(c[j], c[n - j]);
	}
	printf("%d\n", bit <= 1 ? -bit : ret);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

struct FordFulkerson {
  struct Edge{
    int from,to,capacity,flow;
    int calcRest(bool isRev) {
      return isRev ? flow : capacity-flow;
    }
    int getNext(bool isRev) {
      return isRev ? from : to;
    }
  };
  static const int MAX_E=40000;
  static const int MAX_V=300;
  static const int INF=1000000;
  bool visited[MAX_V];
  Edge edgeInstances[MAX_E];
  std::vector<Edge*> edges[MAX_V][2]; // 1 => reverse edge
  FordFulkerson() {E=0;}
  int E;

  void addEdge(Edge edge) {
    edgeInstances[E] = edge;
    edges[edge.from][0].push_back(&edgeInstances[E]);
    edges[edge.to][1].push_back(&edgeInstances[E]);
    E++;
  }

  int calcMaxFlow(int s, int t) {
    int max_flow=0;
    while(true) {
      std::memset(visited,0,sizeof(visited));
      int flow=findFlow(s,t,INF);
      max_flow += flow;
      if(flow==0) {
        break;
      }
    }
    return max_flow;
  }

  int findFlow(int current, int destination, int flow) {
    visited[current] = true;
    if(current == destination) return flow;

    for(int j=0;j<2;++j) {
      bool revEdge = j == 1;
      std::vector<Edge*>& edgeList=edges[current][j];
      for(int i=0;i<edgeList.size();++i) {
        Edge& edge = *edgeList[i];
        int rest = edge.calcRest(revEdge), next = edge.getNext(revEdge);
        if(visited[next]) continue;
        if(rest > 0){
          int max_flow = findFlow(next, destination, std::min(rest,flow));
          edge.flow += revEdge ? -max_flow: max_flow;
          if(max_flow>0) {
            return max_flow;
          }
        }
      }
    }
    return 0;
  }
};
int H,W;
char S[110];
FordFulkerson fordFulkerson;
int main() {
  scanf("%d%d", &H, &W);
  for(int i=0;i<H;++i){
    memset(S,0,sizeof(S));
    scanf("%s", S);
    for(int j=0;j<W;++j) {
      int idh=i+1,idw=j+101;
      if (S[j]=='o') {
        fordFulkerson.addEdge({idh,idw,1,0});
        fordFulkerson.addEdge({idw,idh,1,0});
      } else if(S[j]=='S') {
        fordFulkerson.addEdge({0,idw,FordFulkerson::INF,0});
        fordFulkerson.addEdge({0,idh,FordFulkerson::INF,0});
      } else if(S[j]=='T') {
        fordFulkerson.addEdge({idw,201,FordFulkerson::INF,0});
        fordFulkerson.addEdge({idh,201,FordFulkerson::INF,0});
      }
    }
  }
  int answer = fordFulkerson.calcMaxFlow(0,201);
  if (answer>=FordFulkerson::INF) {
    answer=-1;
  }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n)
    {
        cin >> a[i];
    }
    vector<vector<ll>> num(n);
    rep(i,n)
    {
        if(i-a[i] >= 0) num[i-a[i]].push_back(-i);
        if(i+a[i] < n) num[i+a[i]].push_back(i);
    }
    ll ans =0;
    rep(i,n){
        int sum=0;
        rep(j,num[i].size()){
            if(num[i][j]>=0) ++sum;

        }
        ans += sum*(num[i].size()-sum);
    }
    cout << ans <<endl;
    
    
   

    return 0;
}


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

ll d[200000][2];
int x[200000], y[200000];
vector<int>X[100000], Y[100000];
struct st {
	int p; bool b; ll c;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int main() {
	int m, n, k; scanf("%d%d%d", &m, &n, &k);
	priority_queue<st>que;
	memset(d, 0x3f, sizeof(d));
	rep(i, k) {
		scanf("%d%d", &x[i], &y[i]); x[i]--; y[i]--;
		X[x[i]].push_back(i); Y[y[i]].push_back(i);
		if (x[i] == 0) {
			d[i][1] = y[i];
			que.push({ i,1,d[i][1] });
		}
	}
	while (!que.empty()) {
		st p = que.top(); que.pop();
		if (d[p.p][p.b] != p.c)continue;
		if (p.b) {
			for (int u : Y[y[p.p]]) {
				if (d[u][0] > p.c + abs(x[p.p] - x[u]) + 1) {
					d[u][0] = p.c + abs(x[p.p] - x[u]) + 1;
					que.push({ u,0,d[u][0] });
				}
			}
		}
		else {
			for (int u : X[x[p.p]]) {
				if (d[u][1] > p.c + abs(y[p.p] - y[u]) + 1) {
					d[u][1] = p.c + abs(y[p.p] - y[u]) + 1;
					que.push({ u,1,d[u][1] });
				}
			}
		}
	}
	ll Min = INF;
	for (int u : X[m - 1])Min = min(Min, d[u][1] + abs(y[u] - n + 1));
	for (int u : Y[n - 1])Min = min(Min, d[u][0] + abs(x[u] - m + 1));
	if (Min == INF)puts("-1");
	else printf("%lld\n", Min);
}

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

int main()
{
	string a, b;
	cin>>a>>b;
	int A = a.length(), B = b.length();
	int arr[A + 1][B + 1];
	for(int i = 0; i <= A; i++)
	{
		arr[i][0] = 0;
	}
	for(int i = 0; i <= B; i++)
	{
		arr[0][i] = 0;
	}
	for(int i = 1; i <= A; i++)
	{
		for(int j = 1; j <= B; j++)
		{
			if(a[i - 1] == b[j - 1])
			{
				arr[i][j] = arr[i - 1][j - 1] + 1;
			}
			else
			{
				if(arr[i][j - 1] >= arr[i - 1][j])
				arr[i][j] = arr[i][j - 1];
				else
				arr[i][j] = arr[i - 1][j];
			}
		}
	}
	stack <char> s;
	int i = A, j = B;
	while(i != 0 && j != 0)
	{
		if(a[i - 1] == b[j - 1])
		{
			s.push(a[i - 1]);
			i--;
			j--;
		}
		else
		{
			if(arr[i][j - 1] >= arr[i - 1][j])
			{
				j--;
			}
			else
			{
				i--;
			}
		}
	}
	while(!s.empty())
	{
		cout<<s.top();
		s.pop();
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 35456
#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 a,b, c;
    cin >> a >> b >> c;
    if((a==b and a!=c) or (a!=b and a==c) or (b==c and b!=a)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
zero = 0
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        zero += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if (a, b) in [(1, 0), (0, 1)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) % MOD
print((ans + MOD - 1) % MOD)


Measured memory_bytes: 110324