akhauriyash/Code-Regression huggingface dataset:
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
static constexpr double PI = 3.1415926535897932;
 
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;
 
template<class T>bool bmaxi(T&a, const T&b) { if (b<a)return 0;a = b;return 1; }
template<class T>bool bmini(T&a, const T&b) { if (a<b)return 0;a = b;return 1; }
template<class T>bool nmaxi(T&a, const T&b) { if (a<b) { a = b;return 1; }return 0; }
template<class T>bool nmini(T&a, const T&b) { if (b<a) { a = b;return 1; }return 0; }
template<typename T>auto scan(T&d)->typename std::enable_if<std::is_same<T, std::string
>::value>::type {
	d.clear();int c = fgetc(stdin);while (c<'a' || 'z'<c)c = fgetc(stdin);
	while ('a' <= c&&c <= 'z') { d.push_back(c);c = fgetc(stdin); }
}
template <typename T>auto scan(T&d)->
typename std::enable_if<std::is_same<T, double>::value>::type {
	scanf("%lf", &d);
}
template <typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value
	== std::is_same<T, std::string>::value>::type {
	d = 0;int c = fgetc(stdin);
	while (c<'0' || '9'<c)c = fgetc(stdin);while ('0' <= c&&c <= '9') { d = d * 10 + c - '0';c = fgetc(stdin); }
}
template <typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value
	!= std::is_same<T, double>::value>::type {
	d = 0;int c = fgetc(stdin);bool f = 0;while (c<'0' || '9'<c)
	{
		if (c == '-')f = 1;c = fgetc(stdin);
	}while ('0' <= c&&c <= '9') { d = d * 10 + c - '0';c = fgetc(stdin); }if (f)d = -d;
}
template<typename F, typename...R>void scan(F&f, R&...r) { scan(f);scan(r...); }
 
 
 
int main(void) {
	int64 n, m;
	scan(n, m);
	printf("%ld\n", std::abs((n - 2)*(m - 2)));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int count =0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                int num = i*500 + j*100 + k*50;
                if(num==x){
                    count++;
                }
            }
        }
    }
    cout << count <<endl;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;





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

	cout << fixed << setprecision(15) << a / b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N;

  cin >> N;
    int a[N];
  for (int i = 0; i < N; i++) {cin >> a[i];}

  int t = 0;
  int find_num = 1;
  while (t != N) {
    for(int i=t; i< N; i++){
      if(a[i]==find_num){
        find_num++;
        t = i + 1;
        break;
      } else if (i == N-1){
        t = i + 1;
      }
    }
  }
  int answer;
  if (find_num > 1){
    answer = N - find_num + 1;
  }else{
    answer = -1;
  }
  cout << answer << "\n";
  return 0;
}

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

int main(){
  int n,t,ans,mo=0,me=0,co,ce;cin>>n;
  vector<int> ve(100001,0),vo(100001,0);
  REP(i,n){
    cin>>t;
    if(i%2){
      vo.at(t)++;
      if(vo.at(t)>mo) mo=vo.at(t),co=t;
    }else{
      ve.at(t)++;
      if(ve.at(t)>me) me=ve.at(t),ce=t;
    }
  }
  if(co!=ce) ans=n-mo-me;
  else{
    sort(ve.begin(),ve.end(),greater<int>());
    sort(vo.begin(),vo.end(),greater<int>());
    ans=n-max(mo+ve.at(1),me+vo.at(1));
  }  
  cout<<ans;
}

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

inline bool compare(int x, int y, int z) {
  return (x < y && y < z) || (x > y && y > z);
}

int main(int argc, char **argv) {
  int n, ans;

  cin >> n;

  vector<int> P = vector<int>(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> P[i];
  }

  ans = 0;
  for (int i = 1; i < n - 1; i++) {
    if (compare(P[i-1], P[i], P[i+1])) {
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

ll inv(ll x){
    // MOD=10e9+7
	ll n=MOD-2,a=1;
	while(n>0){
		if(n%2) a=a*x%MOD;
		x=x*x%MOD;
		n=n/2;
	}
	return a;
}

ll Comb(ll n,ll m){
    ll ans = 1; 
    for(int i=0;i < m; i++){
        ans *= ((n-i)*inv(i+1)) % MOD;
        ans %= MOD;
    }
    while(ans<0)ans+=MOD;
    return ans;
}

ll PowMod(ll N,ll P,ll M){
    ll ans = 1;
    while(P >= 1){
        if(P % 2)ans = ans * N % M;
        N = N*N %M;
        P /= 2;
    }
    ans %= M;
    return ans;
}

int main(){
    ll K;
    cin>>K;
    string S;
    cin>>S;
    ll M = S.size();

    v pre(K+1);
    ll now = 1;
    pre[0] = 1;

    rep(i,1,K+1){
        now *= (inv(i)*(i+M-1)) %MOD;
        now %= MOD;
        pre[i] = (now * PowMod(25,i,MOD) % MOD);
    }

    ll sum = 0;

    rep(i,0,K+1){
        sum += (pre[i] * PowMod(26,K-i,MOD)) %MOD;
        sum %= MOD;
    }

    cout<<sum;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n, m; cin >> n >> m;

    vector<pair<ll, ll>> p(n);
    for (ll i = 0; i < n; ++i) {
        ll a, b; cin >> a >> b;

        p[i] = make_pair(a, b);
    }

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

    ll sum = 0;

    ll ans = 0;

    for (ll i = 0; i < n; ++i) {
        sum += p[i].second;

        if (sum > m) {
            ans += (m - (sum - p[i].second)) * p[i].first;
            break;
        } else {
            ans += p[i].second * p[i].first;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#!python3

INF = 10 ** 15


# input
N = int(input())
a, b, c, d = [None] * N, [None] * N, [None] * N, [None] * N
for i in range(N):
    a[i], b[i] = list(map(int, input().split()))
for i in range(N):
    c[i], d[i] = list(map(int, input().split()))


class MaxFlow():

    def __init__(self, n):
        self.n = n
        self.c = [[0] * n for _ in range(n)]
        self.visit = [False] * n

    def add_link(self, x, y, capa):
        self.c[x][y] += capa
    
    def dfs(self, v, t, f):
        if v == t:
            return f
        self.visit[v] = True
        
        for i in range(self.n):
            if self.visit[i] or self.c[v][i] == 0:
                continue
            d = self.dfs(i, t, min(f, self.c[v][i]))
            if d > 0:
                self.c[v][i] -= d
                self.c[i][v] += d
                return d
                
        return 0

    
    def max_flow(self, s, t):
        ans = 0
        while True:
            f = self.dfs(s, t, INF)
            self.visit = [False] * self.n
            if f == 0:
                return ans
            else:
                ans += f
        

def main():
    w = MaxFlow(2 * N + 2)
    for i in range(N):
        w.add_link(0, i + 1, 1)
        w.add_link(N + i + 1, 2 * N + 1, 1)
        for j in range(N):
            if a[i] < c[j] and b[i] < d[j]:
                w.add_link(i + 1, N + j + 1, 1)
    
    ans = w.max_flow(0, 2 * N + 1)
    print(ans)


if __name__ == "__main__":
    main()


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void solve(){
    ll n;
    cin>>n;
    vec<ll> a(n);
    REP(i,n) cin>>a[i];

    ll ans=INF;
    REP(k,2){
        ll sum=0;
        ll cost=0;
        REP(i,n){
            sum+=a[i];
            if(i%2==k){
                if(sum<=0){
                    cost+=1-sum;
                    sum=1;
                }
            }else{
                if(sum>=0){
                    cost+=sum+1;
                    sum=-1;
                }
            }
        }
        chmin(ans,cost);
    }
    cout<<ans<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 100005;

int n,k;
int pos;
int ans=0;
int a[N];

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),k=read();
	rep(i,1,n) a[i]=read();
	printf("%d\n",(n-2)/(k-1)+1);

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define ll long long

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

int tgcd(int a, int b, int c)
{
  return gcd(gcd(a, b), c);
}

int main(void)
{
  int n, i, j, k;
  scanf("%d", &n);
  int *a, *b;
  int z;
  a = (int *)malloc(sizeof(int) * n);
  b = (int *)malloc(sizeof(int) * n);
  b[0] = 0;
  for (i = 0; i < n; i++)
  {
    a[i] = 0;
  }
  for (i = 1; i < n; i++)
  {
    scanf("%d", &z);
    b[i] = z;
  }
  for (i = n - 1; i > 0; i--)
  {
    z = b[i];
    a[z - 1]++;
  }

  for (i = 0; i < n; i++)
  {
    printf("%d\n", a[i]);
  }

  return 0;
}

Measured memory_bytes: 3280
#include<bits/stdc++.h>
#define mkp make_pair
#define all(a) a.begin(),a.end() 
using namespace std;
typedef long long ll;
typedef map<ll,ll>::iterator itll;
typedef pair<ll,ll> P; 
int main()
{
	ll n,k;
	cin>>n>>k;
	ll cnt = 1;
	while(n>=k)
	{
		n/=k;
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
} 

Measured memory_bytes: 256
import numpy

n, d = map(int, input().split())
x = [numpy.array(list(map(int, input().split()))) for i in range(n)]

c = 0
for i in range(n-1):
    for j in range(i+1, n):
        if numpy.linalg.norm(x[i]-x[j]).is_integer():
            c+=1
print(c)

Measured memory_bytes: 12500
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  ll n, p;
  string s;
  cin >> n >> p >> s;

  if (p == 2 || p == 5) {
    ll ans = 0;
    rep(i, n) {
      if ((s[i] - '0') % p == 0) ans += i + 1;
    }
    cout << ans << endl;
  }
  else {
    map<ll, ll> m;
    m[0]++;
    ll res = 0, keta = 1;
    repr(i, n - 1) {
      res = (res + keta * (s[i] - '0')) % p;
      m[res]++;
      keta = (keta * 10) % p;
    }
    ll ans = 0;
    rep(i, p) {
      ans += m[i] * (m[i] - 1) / 2;
    }
    cout << ans << endl;
  }


  
  return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <string.h>
int main(){
  int K,i,l;
  scanf("%d",&K);
  char S[101];
  scanf("%s",S);
  for(i=0;i<101;i++){
    if(S[i]=='\0'){
      l=i;
      break;
    }
  }
  if(K>=l) printf("%s",S);
  else{
    for(i=0;i<K;i++) printf("%c",S[i]);
    printf("...");
  }
  return 0;
}

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

a=list(map(int,input().split()))
if len(set(a))==1:
    if n>=2*a[0] or n-1==a[0]:print("Yes")
    else:print("No")
elif len(set(a))>=3:print("No")
else:
    s,S=sorted(list(set(a)))
    k=a.count(s)
    if S==s+1 and 2*S-n<=k and S>k:print("Yes")
    else:print("No")

Measured memory_bytes: 14208
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int x, a, b;
	cin >> x >> a >> b;
	cout << (abs(x - a) < abs(x - b) ? "A" : "B") << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	ll n;
	vector<ll>list;

	cin >> n;

	for (int i = 0; i < n; i++) {
		ll num;
		cin >> num;
		list.push_back(num);
	}

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

	while (true)
	{
		ll minn = list[0];
		bool flag = false;

		for (int i = 1; i < list.size(); i++) {
			if (list[i] % minn != 0) {
				list[i] = list[i] % minn;
				flag = true;
			}
		}

		sort(list.begin(), list.end());
		if (flag == false) break;
		
	}

	cout << list[0] << endl;

	return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>

int main(void){

int a,b; 

scanf("%d %d",&a,&b);

if(a<b){

printf("a < b\n");

}

else{

if(a>b){
printf("a > b\n");
} 

else{
printf("a == b\n");
}


}

return 0; 

}

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

ll N;

int main(void){
    
    cin >> N;
    
    string s = (N == 0) ? "0" : "";
    ll base = 1;
    while(N != 0){
        if(N % (base * 2) == 0){
            s = "0" + s;
        }
        else{
            s = "1" + s;
            N -= base;
        }
        base *= -2;
    }
    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFizzBuzzSum solver = new BFizzBuzzSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFizzBuzzSum {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            long total = 0;
            for (int x = 1; x <= n; x++) {
                if (x % 3 != 0 && x % 5 != 0) {
                    total += x;
                }
            }

            out.println(total);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
    long long R, G, B, N;
    cin >> R >> G >> B >> N;
    long long res = 0;
    for (long long r = 0; r <= N/R; ++r) {
        for (long long g = 0; g <= N/G; ++g) {
            if (r * R + g * G > N) continue;
            long long rem = N - r*R - g*G;
            if (rem % B != 0) continue;
            ++res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
void shuffle(int ,char *);

void shuffle(int n, char *c){
  int i,s,len=strlen(c);
  char dummy[402]={};
  //printf("%d %d\n",len,n);
  strcpy(dummy,c);
  if( n > len ) s = n % len;
  else s = n;
  strncat(dummy,c,s);
  for(i=0;i<len;i++){
    c[i] = dummy[s+i];
  }
  while(i!=202){
    c[i]=NULL;
    i++;
  }
}

int main(){
  int i,sh,h,hsum=0;
  char card[201]={};
  
  while( scanf("%s",card)!=EOF ){
    if( strcmp(card,"-")==0 ) break;
    scanf("%d",&sh);
    for(i=0;i<sh;i++){
      scanf("%d",&h);
      hsum+=h;
    }
    if( hsum!=strlen(card) || hsum%strlen(card)!=0 ) shuffle(hsum,card);
    puts(card);
    hsum=0;
  }
  return 0;
}

Measured memory_bytes: 604
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long LL;
typedef double db;
const int N = 1e5 + 5, M = 1e5 + 5;
struct Edge {
    int u, v;
    LL ans;
}e[M];
inline LL read() {
    LL x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-')f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int n, m;
int siz[N], fa[N];
LL cur;
inline int getf(int x) { return fa[x] == x ? x: fa[x] = getf(fa[x]);}
int main() {
    n = read(); m = read();
    for (int i = 1; i <= m; ++i) {
        e[i].u = read();
        e[i].v = read();
    }
    cur = 1LL * n * (n - 1) / 2;
    for (int i = 1; i <= n; ++i) {
        fa[i] = i;
        siz[i] = 1;
    }
    for (int i = m; i; --i) {
        e[i].ans = cur;
        int f1 = getf(e[i].u), f2 = getf(e[i].v);
        if (f1 != f2) {
            cur -= 1LL * siz[f1] * siz[f2];
            fa[f1] = f2;
            siz[f2] += siz[f1];
        }
    }
    for (int i = 1; i <= m; ++i) printf("%lld\n", e[i].ans);
    return 0;
}


Measured memory_bytes: 3712
# -*- coding: utf-8 -*-
import sys
lines = sys.stdin.readlines()
l = 0
while not ("-" in lines[l]):
 s = lines[l].replace('\n','')
 n = int(lines[l+1])
 l += 2
 t = sum([int(lines[i]) for i in xrange(l, l+n)]) % len(s)
 print s[t:]+s[:t]
 l += n

Measured memory_bytes: 6448
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

signed main() {
	string S; cin >> S;
	map<char, int>mp;
	for (char c : S)mp[c]++;
	int Min = INT_MAX;
	for (auto p : mp) {
		string s = S;
		int cnt = 0;
		while (1) {
			map<char, int>mp;
			for (char c : s) {
				mp[c]++;
			}
			if (mp.size() == 1)break;
			cnt++;
			string t;
			rep(i, s.size() - 1) {
				if (s[i] == p.first || s[i + 1] == p.first)t += p.first;
				else t += s[i];
			}
			s = t;
		}
		Min = min(Min, cnt);
	}
	cout << Min << endl;
}

Measured memory_bytes: 256
import itertools

n, a = list(map(int, input().split()))
xs = list(map(int, input().split()))

dp = [[[0 for _ in range(a * n + 1)] for _ in range(n + 1)]
      for _ in range(n + 1)]
dp[0][0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        for k in range(a * n + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j > 0 and k - xs[i-1] >= 0:
                dp[i][j][k] += dp[i-1][j-1][k-xs[i-1]]


c = 0
for j in range(1, n+1):
    c += dp[n][j][j * a]

print(c)

Measured memory_bytes: 96092
#include <iostream>
using namespace std;
static const int MAX = 1000;
static const int NIL = -1;

struct Node {int p; int l; int r; };

Node T[MAX];
int n;

void preParse(int u)
{
    if (u == NIL) return;
    cout << " " << u;
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u)
{
    if (u == NIL) return;
    inParse(T[u].l);
    cout << " " << u;
    inParse(T[u].r);
}

void postParse(int u)
{
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    cout << " " << u;
}

void print(int r)
{
    cout << "Preorder" << endl;
    preParse(r);
    cout << endl;
    cout << "Inorder" << endl;
    inParse(r);
    cout << endl;
    cout << "Postorder" << endl;
    postParse(r);
    cout << endl;
}

int main()
{
    int u, r, c1, c2;
    cin >> n;

    for (int i = 0; i != n; ++i)
    {
        T[i].p = T[i].l = T[i].r = NIL;
    }

    for (int i = 0; i != n; ++i)
    {
        cin >> u >> c1 >> c2;
        if (c1 != NIL)
        {
            T[u].l = c1;
            T[c1].p = u;
        }
        if (c2 != NIL)
        {
            T[u].r = c2;
            T[c2].p = u;
        }
    }

    for (int i = 0; i != n; ++i)
    {
        if (T[i].p == NIL) r = i;
    }

    print(r);

    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    for (int i=a;i<=b;i++){
        if (i%k==0){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
    return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>

using namespace std;

int st[200010], dr[200010], v[200010], eg[200010];

int main ()
{
    int n;
    scanf ("%d", &n);

    int lst = 0, ldr = 0;
    for (int i = 1; i <= n; ++i)
    {
        scanf ("%d", &v[i]);

        for (; lst > 0 && v[i] < v[st[lst]]; --lst);
        st[++lst] = i;

        eg[i] = st[lst - 1];
    }

    dr[0] = n + 1;
    long long rez = 0LL;

    for (int i = n; i; --i)
    {
        for (; ldr > 0 && v[i] < v[dr[ldr]]; --ldr);
        dr[++ldr] = i;

        int g = dr[ldr - 1];

        eg[i] = i - eg[i];
        g = g - i;

        rez += 1LL * eg[i] * g * v[i];
    }

    printf ("%lld\n", rez);

    return 0;
}


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

using namespace std;


void solve() {
    int n,A,B,C,D;
    cin >> n >> A >> B >> C >> D;
    A--;B--;C--;D--;
    string s; cin >> s;
    auto ck = [&](int x, int y){
        for (int i = x; i < y; i++) {
            if (s[i]=='#' && s[i+1]=='#') return false;
        }
        return true;
    };
    if (ck(A,C) && ck(B,D)) {
        if (C < D) {
            cout << "Yes";
        } else {
            bool across = false;
            for (int i = B; i <= D; i++) {
                if (s[i]=='.' && s[i-1]=='.' && s[i+1]=='.') {
                    across = true; break;
                }
            }
            cout << (across?"Yes":"No");
        }
    } else {
        cout << "No";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
#define ll          long long
#define dl          double
#define pb          push_back
#define eb          emplace_back
#define mp          make_pair
#define F           first
#define S           second
#define rep(i,a,b)  for(i=a;i<b;i++)
#define all(v)      v.begin(),v.end()
#define allr(v)     v.rbegin(),v.rend()
#define mod         1e9+7
#define CIN(V,s,n)  for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) for(int i=s;i<n;i++){cout <<  V[i] << " ";}
#define SbS         sortbysec
#define fast        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);   for(ll i=0;i<V.size();i++) V[i] = 0;

using namespace std;

int main()
{
ll t=1;
//cin >> t;
while(t--)
{
    ll n,m,i,j,k,h,l,w,q,u,v,c0=0;
    cin >> n ;
    multiset<ll> P;
    for(i=0;i<n;i++)
    {
        cin >> u ;
        P.insert(u);
    }

    vector<pair<ll,ll> > OP;
    while(P.size()>2 and *++P.begin()<0)
    {
        ll x = *P.begin();
        ll y = *P.rbegin();
        P.erase(P.begin());
        P.erase(--P.end());
        OP.pb(mp(y,x));
        P.insert(y-x);
    }
    while(P.size()>2)
    {
        ll x = *P.begin();
        ll y = *P.rbegin();
        P.erase(P.begin());
        P.erase(--P.end());
        OP.pb(mp(x,y));
        P.insert(x-y);
    }
    ll x = *P.begin();
    ll y = *P.rbegin();
    OP.pb(mp(y,x));
    cout << y-x << endl;
    for(i=0;i<OP.size();i++)
    {
        cout << OP[i].F << " " << OP[i].S << endl;
    }

}
    return 0;
}


Measured memory_bytes: 8188
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <map>

using namespace std;

int main()
{
  int64_t N, K;
  cin >> N >> K;

  vector<int> A(N+1,0);

  for (int n=1; n<=N; ++n) {
    cin >> A[n];
  }

  map<int,int> X;

  int a=1;
  int n;
  
  X[1] = 0;
  for (n=1; n<=N; ++n) {
    a = A[a];
    auto itr = X.find(a);
    if (itr!=X.end())
      break;
    X[a] = n;
  }

  // for (auto x : X) {
  //   cerr << x.first << ":" << x.second << "  ";
  // }
  // cerr << endl;

  int loop = n - X[a];

  //  cerr << "loop:" << loop << " a:" << a << " n:" << n  << " X[a]:" << X[a]<< endl;

  if (K < X[a]) {
    a = 1;
    while (K--) {
      a = A[a];
    }
  } else if (K==X[a]) {
    ;
  } else {
    K -= X[a];
    K %= loop;
    while(K--) {
      a = A[a];
    }
  }

  cout << a << endl;

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  //毎回、操作AとBを行い値を比較する
  int minInt = 1;
  for(int i = 0; i < n; i++){
    minInt = min(minInt * 2, minInt + k); 
  }
  cout << minInt << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n,r;
  string s;

  cin >> r;

  cout << 3*pow(r,2)<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,A,B = LI()
    G = LIR(n)
    ma = sum([a for (a,_,_) in G])
    mb = sum([b for (_,b,_) in G])
    dp = [float("inf")]*((ma+1)*mb+1)
    dp[0] = 0
    for a,b,c in G:
        for sa in range(ma)[::-1]:
            na = sa+a
            if na > ma:
                continue
            for sb in range(mb)[::-1]:
                nb = sb+b
                if nb > mb:
                    continue
                nd = dp[sa*mb+sb]+c
                i = na*mb+nb
                if nd < dp[i]:
                    dp[i] = nd
    ans = float("inf")
    for i in range(1,ma+1):
        s = B*i
        if s%A:
            continue
        j = B*i//A
        if j > mb:
            continue
        k = i*mb+j
        if dp[k] < ans:
            ans = dp[k]
    if ans == float("inf"):
        print(-1)
        return
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 43248
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    
    auto calc= [&](long long n) {
        long long res = 0;
        while (n != 0) {
            res += n % 10;
            n /= 10;
        }
        return res;
    };

    if (n % calc(n) == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int num, i;
    long long int a, ans = 1;
    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%lld", &a);
        if (a == 0) {
            puts("0");
            return 0;
        } else if (a <= 1000000000000000000 / ans && ans != -1) {
            ans *= a;
        } else {
            ans = -1;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N),B(N),C(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N) cin >> C[i];
    // Bのパーツで探索する
    sort(A.begin(),A.end());
    sort(C.begin(),C.end());
    ll ans = 0;
    rep(i,N){
        ll ixA = lower_bound(A.begin(),A.end(),B[i]) - A.begin();
        ll ixB = upper_bound(C.begin(),C.end(),B[i]) - C.begin();
        ans += ixA * (N-ixB);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

#define N 20

int main() {
	static int aa[N];
	int n, i, j, cnt, yes;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	cnt = 1;
	for (i = 1; i < n; i++) {
		yes = 1;
		for (j = 0; j < i; j++)
			if (aa[j] > aa[i]) {
				yes = 0;
				break;
			}
		if (yes)
			cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
ll k;
int n,m,t;
int gt[MAXN];
ll a[MAXN],pre[MAXN],ans[MAXN];
vector<int> num;
bool vis[MAXN];
void got(int x){
	vis[x]=1;
	if(num.size()>=1&&x==num[0])
		return ;
	num.push_back(x);
	got(gt[x]);
}
int main(){
	SF("%d",&n);	
	for(int i=1;i<=n;i++)
		SF("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		pre[i]=a[i]-a[i-1];
	SF("%d%lld",&m,&k);
	for(int i=1;i<=n;i++)
		gt[i]=i;
	for(int i=1;i<=m;i++){
		SF("%d",&t);	
		swap(gt[t],gt[t+1]);
	}
	for(int i=1;i<=n;i++){
		if(vis[i]!=0)
			continue;
		got(i);
		int len=num.size();
		ll k1=k%len;
		for(int j=0;j<len;j++)
			ans[num[j]]=pre[num[(j+k1)%len]];
		num.clear();
	}
	ll sum=0;
	for(int i=1;i<=n;i++){
		sum+=ans[i];
		PF("%lld.0\n",sum);
	}
}

Measured memory_bytes: 7928
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		sc.close();

		int l = 0;
		int r = 2 * n - 1;
		while (l < r - 1) {
			if (s[l] == 'W') {
				System.out.println(0);
				return;
			} else if (s[l] == 'B' && s[l + 1] == 'B') {
				l += 2;
			} else {
				break;
			}
		}
		while (l < r - 1) {
			if (s[r] == 'W') {
				System.out.println(0);
				return;
			} else if (s[r] == 'B' && s[r - 1] == 'B') {
				r -= 2;
			} else {
				break;
			}
		}

		int cnt = 0;
		int[] a = new int[2 * n];
		for (int i = l; i <= r; i++) {
			if (cnt % 2 == 0) {
				if (s[i] == 'B') {
					a[i] = 1;
					cnt++;
				} else {
					a[i] = -1;
					cnt--;
				}
			} else {
				if (s[i] == 'B') {
					a[i] = -1;
					cnt--;
				} else {
					a[i] = 1;
					cnt++;
				}
			}
		}
		if (cnt != 0) {
			System.out.println(0);
			return;
		}

		int mod = 1000000007;
		long ans = 1;
		for (int i = l; i <= r; i++) {
			if (a[i] == 1) {
				cnt++;
			} else if (a[i] == -1) {
				ans *= cnt;
				ans %= mod;
				cnt--;
			}
		}
		long p = 1;
		for (int i = 1; i <= n; i++) {
			p *= i;
			p %= mod;
		}
		System.out.println(ans * p % mod);
	}
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  string A, B, C;
  cin >> A >> B >> C;
  A[0] -= 32;B[0] -= 32;C[0] -= 32;
  cout << A[0] << B[0] << C[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int a = 1;
    int z = s.size();
    for (a = 1; a < s.size(); a++)
    {
        if (s[a - 1] == 'A')
        {
            break;
        }
    }
    for (z = s.size(); z > 0; z--)
    {
        if (s[z - 1] == 'Z')
        {
            break;
        }
    }
    cout << z - a + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 150;
const LL INF = 9E18;
int n;
vector<int> G[N];
int d[N], vis[N], p[N];
void bfs(int s, int ban = -1) {
    queue<int> q;
    memset(vis, 0, sizeof vis);
    q.push(s); d[s] = 0; p[s] = 0; vis[s] = 1;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v: G[u]) {
            if (v == ban || vis[v]) continue;
            q.push(v); d[v] = d[u] + 1; p[v] = u; vis[v] = 1;
        }
    }
}

vector<int> go() {
    bfs(1);
    int s = max_element(d, d + n + 1) - d;
    bfs(s);
    int t = max_element(d, d + n + 1) - d;
    vector<int> ans;
    while (t) {
        ans.push_back(t);
        t = p[t];
    }
    return ans;
}

int main() {
    cin >> n;
    FOR (i, 0, n - 1) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> D = go();
    dbg(D);
    int dsz = D.size();
    LL ans1 = (dsz + 1) / 2, ans2 = INF;
    if (dsz % 2) {
        ans1 = (dsz + 1) / 2;
        bfs(D[dsz / 2]);
        vector<int> deg(ans1);
        FOR (i, 1, n + 1) deg[d[i]] = max(deg[d[i]], (int) G[i].size());
        ans2 = deg[0];
        FOR (i, 1, ans1 - 1) ans2 *= deg[i] - 1;
    }
    
    FOR (c1, 1, n + 1) for (int c2: G[c1]) {
        bfs(c2, c1); bfs(c1, c2);
        int maxd = *max_element(d + 1, d + n + 1);
        if (maxd >= ans1) continue;
        vector<int> deg(ans1);
        FOR (i, 1, n + 1) deg[d[i]] = max(deg[d[i]], (int) G[i].size());
        dbg(c1, c2); dbg(deg);
        LL t = 2; FOR (i, 0, ans1 - 1) t *= deg[i] - 1;
        ans2 = min(ans2, t);
    }

    printf("%lld %lld\n", ans1, ans2);
}


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

//https://qiita.com/tubo28/items/e6076e9040da57368845
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 dfs(n:usize,select:&mut Vec<Vec<bool>>,select_list:&mut Vec<bool>){

    if select_list.len() == n {
        select.push(select_list.to_vec());
        return;
    }

    for i in 0..2{
        if i == 0{
            select_list.push(true);
        }else{
            select_list.push(false);
        }
        dfs(n,select,select_list);
        select_list.pop();
    }
}

fn main() {
    let h:usize = read();
    let w:usize = read();
    let k:usize = read();
    let mut board:Vec<Vec<char>> = vec![vec![' '; w];h]; //列、行

    for i in 0..h{
        board[i] = read::<String>().chars().collect();
    }

    let mut h_select: Vec<Vec<bool>> = Vec::new();
    let mut select_list:Vec<bool> = Vec::new();
    dfs(h,&mut h_select,&mut select_list);
    let mut w_select: Vec<Vec<bool>> = Vec::new();
    let mut select_list:Vec<bool> = Vec::new();
    dfs(w,&mut w_select,&mut select_list);

    let mut ans = 0;

    for i in 0..h_select.len(){
        for j in 0..w_select.len(){
            let mut chk_board:Vec<Vec<char>> = board.clone(); //列、行
            for l in 0..h_select[i].len(){
                if h_select[i][l] == true {
                    for x in 0..w{
                        chk_board[l][x] = 'x';
                    }
                }
            }
            for m in 0..w_select[j].len(){
                if w_select[j][m] == true {
                    for x in 0..h{
                        chk_board[x][m] = 'x';
                    }
                }
            }
            //println!("h:{:?} j:{:?}", h_select[i], w_select[j]);
            //#の数を数える
            let mut black = 0;
            for x in 0..h{
                for y in 0..w{
                    if chk_board[x][y] == '#'{
                        black += 1;
                    }
                }
            }
            if black == k {
                ans += 1;
            }
            
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C,D=0;
  str N;
  cin>>A>>B>>C;
  if(A*B>C)cout<<C<<endl;
  else cout<<A*B<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define ll long long
const int N = 505;
map<int,int>mp;
int main()
{
    int n,x;
    cin >> n;
    int flag=1;
    for(int i=1;i<=n;i++)
    {
        cin >> x;
        if(mp[x]==1)
            flag=0;
        mp[x]=1;
    }
    if(flag)
        puts("YES");
    else
        puts("NO");
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=300010;

ll gcd(ll a,ll b){
    if(a>b){
        swap(a,b);
    }
    if(a==0)return b;
    return gcd(a,b%a);
}

signed main(){
    vector<ll>p(1000010);
    p[1]=1;
    REP(i,2,1000010){
        if(p[i]>0)continue;
        ll k=1;
        while(k*i<=1000010){
            if(p[k*i]==0)p[i*k]=i;
            k++;
        }
    }
    ll n;cin>>n;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll g=a[0];
    rep(i,n){
        g=gcd(g,a[i]);
    }
    if(g>1){
        cout<<"not coprime"<<endl;
        return 0;
    }
    vector<ll> cnt(1000010);
    bool f=0;
    rep(i,n){
        while(a[i]>1){
            ll s=p[a[i]];
            if(cnt[s]>0)f=1;
            cnt[s]++;
            while(a[i]%s==0){
                a[i]/=s;
            }
        }
    }
    if(f){
        cout<<"setwise coprime"<<endl;
    }else{
        cout<<"pairwise coprime"<<endl;
    }
}

Measured memory_bytes: 26752
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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



int main(){
    int X;
    cin>>X;
    if(X>=30){
        out("Yes");
    } else {
        out("No");
    }
    
    
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a; i < b; ++i)

int main()
{
    int N;
    scanf("%d", &N);
    int T[N];
    int sm = 0;
    REP(i, 0, N) { scanf("%d", &T[i]); sm += T[i]; }
    int M;
    scanf("%d", &M);
    int P[M], X[M];
    REP(i, 0, M) { scanf("%d %d", &P[i], &X[i]); --P[i]; }

    REP(i, 0, M) printf("%d\n", sm + X[i] - T[P[i]] );
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    vvl f(n, vl(10));
    rep(i,n){
        rep(j,10) cin >> f[i][j];
    }
    vvl p(n,vl(11));
    rep(i,n){
        rep(j,11) cin >> p[i][j];
    }
    ll ans = -INF;
    for(ll bit=1; bit<1<<10; bit++){
        vl cnt(n,0);
        ll sum = 0;
        rep(i,n){
            rep(j,10){
                if(bit & (1<<j)){
                    if(f[i][j]==1) cnt[i]++;
                }
            }
        }
        rep(i,n) sum += p[i][cnt[i]];
        ans = max(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    
    int m;
    cin >> m;
    vector<int> p(m), x(m);
    rep(i, m) cin >> p[i] >> x[i];

    int sum = accumulate(all(t), 0);
    rep(i, m) {
        put(sum - (t[p[i] - 1] - x[i]))
    }

    
    return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
int main(void){
int i,n,h,w;
while(1){
scanf("%d %d",&h,&w);
if(h==0&&w==0){break;}
else{
for(i=0;i<h;i++){
for(n=0;n<w;n++){
printf("#");
}
printf("\n");
}
printf("\n");
}
}
return 0;
}

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

using PP = pair<int, int>;
int n;
long a[18];
map<PP, long> memo[18][18];
long rec(int l, int r, int p, int q) {
  if (l + 1 == r) return p * a[l] + q * a[r];
  const auto it = memo[l][r].find(PP(p, q));
  if (it != memo[l][r].end()) return it->second;
  
  long mn = 1e18;
  for (int m = l + 1; m < r; ++m) {
    long nv = rec(l, m, p, p + q) + rec(m, r, p + q, q) - a[m] * (p + q);
    mn = min(mn, nv);
  }
  return mn;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cout << rec(0, n - 1, 1, 1) << endl;
}

Measured memory_bytes: 256