akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    int n,m;
    cin >> n >> m;

    vector<vector<ll> > people(n, vector<ll>(4,1000000000));
    vector<vector<ll> > points(m, vector<ll>(2,0));

    for (int i = 0; i < n; i++) {
        cin >> people[i][0];
        cin >> people[i][1];
    }

    for (int i = 0; i < m; i++) {
        cin >> points[i][0];
        cin >> points[i][1];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ll dist = abs(people[i][0] - points[j][0]) + abs(people[i][1] - points[j][1]);
            // cout << dist << endl;
            if (dist < people[i][2]) {
                people[i][2] = dist;
                people[i][3] = j+1;
            }
        }
    }


    for (int i = 0; i < n; i++) {
        cout << people[i][3] << endl;
    }


    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        //dp[0] = num[0];
        dp[1] = Math.abs(num[0] - num[1]);

        for (int i = 2; i < n; i++) {
            dp[i] = Math.min(dp[i - 1] + Math.abs(num[i] - num[i - 1]),
                    dp[i - 2] + Math.abs(num[i] - num[i - 2]));
        }

        System.out.println(dp[n-1]);


    }
}
 

Measured memory_bytes: 59460
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

using T = ll;
const int MAX_V = 1<<18;
//演算の内容
T f(T a, T b){return max(a, b);}
//何で初期化するか
T other = 0;

struct segment_tree{
    int n;
    T seg[2*MAX_V];
    //要素数N(0〜N-1)の初期化されたセグメント木を構築
    segment_tree(int N){
        n = 1;
        while(n < N) n *= 2;
        fill_n(seg, 2*n-1, other);
    }
    //i番目の要素をxに変更(0番目から数える)
    void update(int i, T x){
        i += n-1;
        seg[i] = x;
        while(i > 0){
            i = (i-1)/2;
            seg[i] = f(seg[2*i+1], seg[2*i+2]);
        }
    }
    //i番目の要素を取得
    T at(int i){
        return seg[i+n-1]; 
    }
    //query(a, b)で[a, b)における演算の結果を取得
    T query(int a, int b, int i = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return other;
        elif(a <= l && r <= b) return seg[i];
        else{
            T vl = query(a, b, 2*i+1, l, (l+r)/2);
            T vr = query(a, b, 2*i+2, (l+r)/2, r);
            return f(vl, vr);
        }
    }
};

int main(){
    int N;
    cin >> N;
    pll p[N];
    rep(i, N){
        ll x, d;
        cin >> x >> d;
        p[i] = pll(x, x+d);
    }
    sort(p, p+N);
    ll L[N], R[N];
    rep(i, N){
        L[i] = p[i].first, R[i] = p[i].second;
    }
    segment_tree seg(N);
    rep(i, N){
        seg.update(i, i);
    }
    rep3(i, N-1, 0){
        int j = lower_bound(L, L+N, R[i])- L;
        seg.update(i, seg.query(i, j));
    }
    //a[i]:=i個目のロボットを起動したときにどこまで消滅するか
    int a[N];
    rep(i, N){
        a[i] = seg.at(i);
        //cout << a[i] << endl;
    }
    //dp[i]:=起動させるロボットがi番目以降のものだけであるときの組み合わせの数
    ll dp[N+1];
    dp[N] = 1;
    rep3(i, N-1, 0){
        dp[i] = dp[i+1] + dp[a[i]+1];
        dp[i] %= MOD;
    }
    cout << dp[0] << endl;
}

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

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

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;


int main(){
    int n;
    string s;
    cin >> n >> s;
    int left = 0;
    int right = 0;
    int l_kakko = 0;
    int r_kakko = 0;

    REP(i, n) {
        if(s[i] == '(') {
            left++;
        } else {
            right++;
        }
        if(left < right) {
            l_kakko++;
            left = right = 0;
        }
    }
    //cout << l_kakko << endl;

    left = right = 0;

    REP(i, n) {
        if(s[i] == '(') {
            left++;
        } else {
            right++;
        }
    }

    r_kakko = left + l_kakko - right;

    REP(i, l_kakko) cout << "(";
    REP(i, n) cout << s[i];
    REP(i, r_kakko) cout << ")";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#include <cstdint>
#include<iomanip>
#define ll long long int
#define rep(i,rept) for (int (i) = 0; (i) < rept; (i)++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define lolo 92233720368547757
#define susu 1000000007
typedef std::pair<int, int> pp;
typedef std::pair<ll, ll> llpp;
using namespace std;

int main() {
	ll n, m = 0, sum = 0,o;
	cin >> o;
	rep(i, o) {
		cin >> n;
		m = max(n, m);
		sum += n;
	}
	sum -= m;
	Yes(sum > m);
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <iomanip>
#include <iostream>
#include <vector>    
#include <cstdlib>
#include <set>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    
        string s;
        cin >> s ;
        if(s[2]==s[3]&&s[4]==s[5]&&s.length()==6)
            cout << "Yes";
        else
            cout << "No";

        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0;i<n;i++) scanf("%hu",&A[i+1]);

  for(i=0;i<=VMAX;i++) C[i] = 0;

  for(j=0;j<n;j++) C[A[j+1]]++;

  for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n-1;i++)
    printf("%d ",B[i]);

  printf("%d\n",B[n]);

  return 0;
}



Measured memory_bytes: 9640
#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

void solve() {
    int n, m;
    std::cin >> n >> m;

    auto ans = vec(1 << n, vec(1 << m, 0));
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < (1 << m); ++j) {
            ans[i][j] = __builtin_popcount(i & j) % 2;
        }
    }

    for (int i = 1; i < (1 << n); ++i) {
        for (int j = 1; j < (1 << m); ++j) {
            int b = (ans[i][j] + ans[i - 1][j] +
                     ans[i][j - 1] + ans[i - 1][j - 1]) %
                    2;
            std::cout << b;
        }
        std::cout << std::endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
#include <string.h>

int max(int x, int y)
{
	if (x > y){
		return (x);
	}	
	return (y);
}

void swap(int *i, int *j)
{
	*i += *j;
	*j = *i - *j;
	*i -= *j;
}

int main(void)
{
	int card[13];
	char str[7][16] = {
		"null", "one pair", "two pair", "three card", 
		"straight", "full house", "four card",
	};
	int ans;
	int tmp;
	int i, j;
	char c[5];
	int count;
	
	while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF){
		ans = 0;
		tmp = 0;
		memset(card, 0, sizeof(card));
		
		for (i = 0; i < 5; i++){
			card[c[i] - 1]++;
		}
		
		for (i = 0; i < 13; i++){
			if (card[i]){
				for (j = i, count = 0; count < 5; count++, j++){
					if (!card[j]){
						count = 0;
						break;
					}
					if (j == 12 && count == 3){
						j = -1;
					}
					else if (j == 12){
						count = 0;
						break;
					}
				}
			}
			
			if (count){
				tmp = 4;
				break;
			}
		}
		
		for (i = 0; i < 12; i++){
			for (j = 0; j < 12 - i; j++){
				if (card[j] < card[j + 1]){
					swap(&card[j], &card[j + 1]);
				}
			}
		}
		
		if (card[0] == 4){
			ans = 6;
		}
		else if (card[0] == 3 && card[1] == 2){
			ans = 5;
		}
		else if (card[0] == 3){
			ans = 3;
		}
		else if (card[0] == 2 && card[1] == 2){
			ans = 2;
		}
		else if (card[0] == 2){
			ans = 1;
		}
		
		printf("%s\n", str[max(ans, tmp)]);
	}
	
	return (0);
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}

double L;
double g(double x, double y) {
    return x * y * (L - x - y);
}
double f(double x) {
    double xl = 0.0, xr = 1000.0;
    double eps = 1e-9;
    while (abs(xl - xr) > eps) {
        // cout << xl << " " << xr << endl;
        double xl2 = (xl * 2 + xr) / 3;
        double xr2 = (xl + xr * 2) / 3;
        if (g(x, xl2) > g(x, xr2)) xr = xr2;
        else xl = xl2;
    }
    return g(x, xl);
}
void solve() {
    cin >> L;
    double xl = 0.0, xr = L;
    double eps = 1e-9;
    while (abs(xl - xr) > eps) {
        // cout << xl << " " << xr << endl;
        double xl2 = (xl * 2 + xr) / 3;
        double xr2 = (xl + xr * 2) / 3;
        if (f(xl2) > f(xr2)) xr = xr2;
        else xl = xl2;
    }
    cout << f(xl) << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

static int Seat[502][502];
static int IsVacant[502][502];
static int N;

void UpdateSeat(int x, int y, int givenValue = -1){
	int newDist = 10000;
	if(IsVacant[x][y]){
		givenValue -= 1;
	}
	if(givenValue == -1){
		IsVacant[x][y] = true;
		if(x-1 >= 0){
			newDist = min(newDist, Seat[x-1][y]);
		}
		if(x+1 <= N+1){
			newDist = min(newDist, Seat[x+1][y]);
		}
		if(y-1 >= 0){
			newDist = min(newDist, Seat[x][y-1]);
		}
		if(y+1 <= N+1){
		newDist = min(newDist, Seat[x][y+1]);
		}
	}else{
		if(Seat[x][y] > givenValue){
			newDist = givenValue;
		}
	}

	if(Seat[x][y] > newDist){
		Seat[x][y] = newDist;
		if(x-1 >= 0){
			UpdateSeat(x-1,y,newDist+1);
		}
		if(x+1 <= N+1){
			UpdateSeat(x+1,y,newDist+1);
		}
		if(y-1 >= 0){
			UpdateSeat(x,y-1,newDist+1);
		}
		if(y+1 <= N+1){
			UpdateSeat(x,y+1,newDist+1);
		}
	}
}

int GetMinDist(int x, int y){
	int newDist = 1000000;
	if(x-1 >= 0){
		newDist = min(newDist, Seat[x-1][y]);
	}
	if(x+1 <= N+1){
		newDist = min(newDist, Seat[x+1][y]);
	}
	if(y-1 >= 0){
		newDist = min(newDist, Seat[x][y-1]);
	}
	if(y+1 <= N+1){
		newDist = min(newDist, Seat[x][y+1]);
	}
	return newDist;
}

int main()
{
	for(int i = 0; i <= 501; i++){
		for(int j = 0; j <= 501; j++){
			Seat[i][j] = 0;
			IsVacant[i][j] = false;
		}
	}

	cin >> N;
	int P[500*500];
	for(int i = 0; i < N*N; i++){
		cin >> P[i];
	}
	
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++){
			int dx = min(i, N+1-i);
			int dy = min(j, N+1-j);
			int dist = min(dx, dy);
			Seat[i][j] = dist;
		}
	}
	
	ll ans = 0;
	for(int i = 0; i < N*N; i++){
		int p = P[i]-1;
		int x = p % N + 1;
		int y = p / N + 1;
		
		/*
		for(int j = 0; j <= N+1; j++){
			for(int i = 0; i <= N+1; i++){
				cout << Seat[i][j] << " ";
			}
			cout << endl;
		}
		cout << "(x, y) = " << "(" << x << " , " << y << ")" << " " << GetMinDist(x,y)<< endl;
		cout << endl;
		*/
		ans += GetMinDist(x, y);
		UpdateSeat(x, y, -1);
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

#define LL long long int
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

LL big_mod(LL val,LL pow,LL mod)
{
    LL res = 1;
    val = val % mod;
    while(pow > 0)
    {
        if(pow & 1)
        {
            res = (res*val) % mod;
        }
        pow = pow >> 1;
        val = (val*val) % mod;
    }
    return res;
}

LL fact[200005],mod=998244353;

LL Fun(LL n,LL x)
{
    return (fact[n]*big_mod((fact[x]*fact[n-x])%mod,mod-2,mod))%mod;
}

int main()
{
    FAST();
    LL i,k,m,n,ans=0;
    cin >> n >> m >> k;
    fact[0]=fact[1]=1;
    for(i=2;i<=n;i++)fact[i]=(fact[i-1]*i)%mod;
    for(i=0;i<=k;i++)ans=(ans+m*big_mod(m-1,n-i-1,mod)%mod*Fun(n-1,i)%mod)%mod;
    cout << ans;
    return 0;
}


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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;
typedef int64_t ll;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);
  int o = 0;
  string s;
    cin >> s;
  for(char c :s) o+= (c=='1');
  std::cout << o << std::endl;

  return 0;
}


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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N; cin >> N;
   vector<int> H(N);
   for (int i = 0; i < N; ++i) cin >> H[i];
   sort(H.begin(), H.end(), greater<int>());
   int cur = 0;
   while (cur+1 < N && H[cur+1] > cur+1) cur++;
   int up = H[cur] - cur - 1;
   int right = 0;
   for (int nxt = cur+1; nxt < N; ++nxt) right += (H[nxt] > cur);
   if ((up & 1) || (right & 1)) cout << "First\n";
   else cout << "Second\n";
   return 0;
}


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

ll n, m, k, s, p;
vector<ll> ps;
vector<vector<ll>> ss;

void print_vec(vector<ll> vec) {
    for (int a = 0; a < vec.size(); ++a){
        cout << vec[a] << " ";
    }
    cout << endl;
}

int vector_finder(ll number, std::vector<ll> vec) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance(vec.begin(), itr);
    if (index != vec.size()) {
        return 1;
    } else {
        return 0;
    }
}


bool is_tento(vector<ll> sws, ll x){
    ll accum = 0;
    //cout << "sws in is_tento = ";
    //print_vec(sws);
    for (int a = 0; a < ss[x].size(); ++a) {
        accum += sws[ss[x][a]];
    }
    if (accum % 2 == ps[x]) {
        return true;
    } else {
        return false;
    }
}

ll dfs(ll x, ll i, vector<ll> sws) {
    //cout << x << " " << i << endl;
    //for(int j = 0; j < m; ++j) {
    //    cout << sws[j] << " ";
    //}
    //cout << endl;
    //cout << "sws = ";
    //print_vec(sws);
    //cout << "(x, i) = " << x  << " " << i << endl;

    if (x == m) {
        for(int j=0; j<m; ++j){
            if (!is_tento(sws, j)) return 0;
        }
        ll res = 1;
        for(int j=0; j<n; ++j) {
            if (sws[j] == -1) {
                res *= 2;
            }
        }
        return res;
    }
    if (i == n) {
        return dfs(x+1, 0, sws);
    }
    if (!vector_finder(i, ss[x])) {
        return dfs(x, i+1, sws);
    }

    ll res = 0;
    if (sws[i] == -1) {
        sws[i] = 0;
        res += dfs(x, i+1, sws);
        sws[i] = 1;
        res += dfs(x, i+1, sws);
    } else {
        //cout << x << " " << i << "hoge" << endl;
        res += dfs(x, i+1, sws);
    }
    //cout << "res = " << res << endl;
    return res;
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < m; ++i) {
        cin >> k;
        ss.push_back(vector<ll>());
        for (int j = 0; j < k; ++j) {
            cin >> s;
            ss[i].push_back(s-1);
        }
    }
    for(int i = 0; i < m; ++i) {
        cin >> p;
        ps.push_back(p);
    }

    vector<ll> sws(n, -1);
    //print_vec(sws);
    cout << dfs(0, 0, sws) << endl;

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
path=[list(map(int,input().split())) for i in range(m)]
# print(path)

def ok(l1, now, next):
    # print([l1])
    # print([now, next])
    l=l1[:]
    count=0
    if [now,next] in path or [next, now] in path:
        l.remove(next)
        if len(l)==0:
            return 1
        for i in range(len(l)):
            count+=ok(l, next, l[i])
        return count
    else:
        return 0

li=[i+1 for i in range(1,n)]

now=1
tmp=li[:]
count=0
for i in range(len(tmp)):
    count+=ok(tmp, now, tmp[i])
print(count)

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

#define INF 1000000
#define MAX_N 50000

int main(){
	int n, m;
	cin >> n >> m;
	
	int c[20];
	for(int i=0;i<m;i++)
		cin >> c[i];
	
	int dp[MAX_N+1];   //dp[i] : i円を支払うための最小枚数

	for(int i=1;i<=MAX_N;i++)   
		dp[i] = INF;            //初期化(dp[0]=0)

	for(int i=0;i<=n;i++){ 		//i円を支払うとき
		for(int j=0;j<m;j++){   	//j番目のコインを使うとき
			if(i+c[j] <= n)
				dp[i+c[j]] = min(dp[i+c[j]], dp[i]+1);	
		}
	}

	cout << dp[n] << endl;

	return 0;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const char mp[] = "RYGB";
int n, m, d;

int main() {
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = (i + j + m) / d;
      int y = (i - j + m) / d;
      putchar(mp[(x & 1) << 1 | (y & 1)]);
    }
    putchar(10);
  }
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
using namespace std;

int main()
{
    int add = 0;
    char ord[8];
    scanf("%s", ord);
    for(int i = 0; i < 3; i++){
        if(ord[i] == 'o') add++;
    }
    printf("%d", 700 + add*100);
    return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  int sum = 0;
  for (int i = 0; i < N; i++) sum += a.at(i);
  double avg = sum / (double)N;
  double diff = 1000;
  for (int i = 0; i < N; i++) diff = min(diff, abs(avg - a.at(i)));
  for (int i = 0; i < N; i++) {
    if (abs(avg - a.at(i)) == diff) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n;
  long long k;
  cin>>n>>k;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  long long gf[n];//Aにおいてiより前にあってA[i]より大きいものの個数
  long long g[n];//AにおいてA[i]より大きい要素の個数
  long long temp;
  REP(i,n){
    temp = 0;
    REP(j,i){
      if(a[j]>a[i])temp++;
    }
    gf[i] = temp;
  }
  REP(i,n){
    temp = 0;
    REP(j,n){
      if(a[j]>a[i])temp++;
    }
    g[i] = temp;
  }
  
  long long ans = 0;
  REP(i,n){
    ans += k*gf[i];
    ans = mod(ans);
    ans += (mod(k*(k-1)/2))*g[i];
    ans = mod(ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_LEN 100000

using namespace std;

int N, Q;
char str[MAX_LEN + 1];

vector<int> ac_loc;
void find_ac() {
    for(int i = 0; i < N - 1; ++i)
        if(str[i] == 'A' && str[i + 1] == 'C')
            ac_loc.push_back(i);
}

int main(int argc, char **argv) {
    scanf("%d %d", &N, &Q);
    scanf("%s", str);

    find_ac();

    for(int i = 0; i < Q; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);

        vector<int>::iterator it1 = lower_bound(ac_loc.begin(), ac_loc.end(), l - 1);
        vector<int>::iterator it2 = lower_bound(ac_loc.begin(), ac_loc.end(), r - 1);
        printf("%d\n", distance(it1, it2));
    }
    
}

Measured memory_bytes: 1276
#!/usr/bin/env python3
n, m = map(int, input().split())
a = sorted(map(int, input().split()))
cb = [[None]] * m
for i in range(m):
    b, c = map(int, input().split())
    cb[i] = [c, b]
cb.sort(reverse=True)
p = 0
for i in range(m):
    c, b = cb[i]
    for _ in range(b):
        if p > n - 1 or a[p] >= c:
            print(sum(a))
            exit()
        a[p] = c
        p += 1
print(sum(a))


Measured memory_bytes: 23988
A = [[0 for i in range(3)] for j in range(3)]
c = [[False for i in range(3)] for j in range(3)]
for i in range(3):
    A[i] = list(map(int,input().split()))

N = int(input())

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if (A[j][k] == b):
                c[j][k] = True

f = False
for i in range(3):
    f |= c[0][i] & c[1][i] & c[2][i]
    f |= c[i][0] & c[i][1] & c[i][2]

f |= c[0][0] & c[1][1] & c[2][2]
f |= c[0][2] & c[1][1] & c[2][0]

if (f):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
using System;
class Program {
  static void Main(string[] args) {
    string[] _list = Console.ReadLine().Split();
    int N = int.Parse(_list[0]);
    string[] A = new string[N];

    for (int i = 0; i < N; ++i) {
      A[i] = Console.ReadLine();
    }

    Array.Sort(A);

    for (int i = 0; i < N; ++i) {
      Console.Write(A[i]);
    }
    Console.WriteLine();
  }
}


Measured memory_bytes: 13408
#include <stdio.h>
#include <string.h>

int main(void){
  char str[12],ans[12];
  int i,len,j=0;

  scanf("%s",str);
  len=strlen(str);
  for(i=0;i<len;i++){
    if(str[i]=='0'){
    	ans[j]='0';  j++;
    }
    else if(str[i]=='1'){
    	ans[j]='1';  j++;
    }
    else if(str[i]=='B'){
      if(j>0)  j--;
    }
  }
  for(i=0;i<j;i++)  printf("%c",ans[i]);
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	char str[128];
	char original[128];

	while (scanf("%s", str) != EOF){
		int i, j;
		int loop;
		char loop_char;

		for (i = j = 0; str[i] != 0; i++){
			if (str[i] == '@'){
				loop = str[++i] - '0';
				loop_char = str[++i];
				while (loop-- > 0){
					original[j++] = loop_char;
				}
			}
			else {
				original[j++] = str[i];
			}
		}
		original[j] = 0;
		puts(original);
	}

	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N), COUNT(N, 0);
	for (int i = 1; i < N; i++) cin >> A[i], A[i]--, COUNT[A[i]]++;
	for (int i = 0; i < N; i++) cout << COUNT[i] << endl;
}

Measured memory_bytes: 4716
import itertools
n = int(input())
lis = [x for x in range(1,n+1)]
permutations_lis = list(itertools.permutations(lis))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
print(abs(permutations_lis.index(Q)-permutations_lis.index(P)))


Measured memory_bytes: 8052
import copy


def countBlack(c, k):
    cnt = 0
    for i in range(len(c)):
        for j in range(len(c[i])):
            if c[i][j] == '#':
                cnt += 1
                if cnt == k + 1:
                    return cnt

    return cnt


def createPaintedC(c, rows, cols):
    c_copy = copy.deepcopy(c)
    for i in range(len(c_copy)):
        for j in range(len(c_copy[i])):
            if i in rows or j in cols:
                c_copy[i] = c_copy[i][:j] + '$' + (c_copy[i][j + 1:] if j < len(c_copy[i]) else '')

    return c_copy

if __name__ == '__main__':
    H, W, K = map(int, input().split())
    c = []
    for _ in range(H):
        c.append(input())

    cnt = 0
    painted_rows_list = [[]]
    for i in range(H):
        new_rows_list = []
        for rows in painted_rows_list:
            rows_copy = copy.copy(rows)
            rows_copy.append(i)
            new_rows_list.append(rows_copy)
        painted_rows_list += new_rows_list

    painted_cols_list = [[]]
    for i in range(W):
        new_cols_list = []
        for cols in painted_cols_list:
            cols_copy = copy.copy(cols)
            cols_copy.append(i)
            new_cols_list.append(cols_copy)
        painted_cols_list += new_cols_list

    for rows in painted_rows_list:
        for cols in painted_cols_list:
            new_c = createPaintedC(c, rows, cols)
            black_count = countBlack(new_c, K)
            if black_count == K:
                cnt += 1

    print(cnt)

Measured memory_bytes: 9308
N,M = map(int,input().split())
PY = []
for i in range(M):
    P,Y = map(int,input().split())
    PY.append([P,Y,i])

PY.sort()
ans = [0 for i in range(M)]
count = 0
old = 0
for j in range(M):
    p,y,inum = PY[j]
    if old == p:
        pnum = p
        cnum = count
    else:
        old = p
        count = 1
        pnum = p
        cnum = 1

    count += 1
    pnum = str(pnum)
    cnum = str(cnum)
    ans[inum] = '0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum

for i in range(M):
    print(ans[i])

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


int main() {
	string s;
	cin >> s;

	int K = 0;
	cin >> K;

	// K = K % (s.length() * 26);

	bool canChange = true;

	while(canChange) {
		canChange = false;
		for (int i = 0; i < s.length(); ++i) {
			if (s[i] != 'a' && 'z' - s[i] + 1 <= K) {
				K -= (int)('z' - s[i]) + 1;
				canChange = true;
				s[i] = 'a';
			}
		}
	}
	K = K % 26;
	s[s.length() - 1] = (char)(s[s.length() - 1] + K);
	
	cout << s;

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	char S[201];
	scanf("%s", S);
	
	int i;
	char T[101] = {};
	for (i = 0; S[i*2] != 0; i++) T[i] = S[i];
	for (T[--i] = 0, S[i*2] = 0; lex_smaller(T, &(S[i])) != 0; T[--i] = 0, S[i*2] = 0);
	
	printf("%d\n", i * 2);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool Match(char c1, char c2)
{
    if (c1 == c2 || c1 == '?' || c2 == '?')
    {
        return true;
    }
    return false;
}

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size() - t.size();
    vector<int> id;
    bool gok = false;
    for (int i = 0; i <= n; ++i)
    {
        string ssub = s.substr(i, t.size());
        bool ok = true;
        for (int j = 0; j < ssub.size(); ++j)
        {
            if (!Match(ssub[j], t[j]))
            {
                ok = false;
                break;
            }
        }
        if (ok)
        {
            gok = true;
            id.push_back(i);
        }
    }
    if (!gok)
    {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    int start = *(id.end() - 1);
    for (int i = start; i < start + t.size(); ++i)
    {
        if (s[i] == '?')
        {
            s[i] = t[i - start];
        }
    }
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == '?')
        {
            s[i] = 'a';
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict,deque

input = sys.stdin.readline
def inar():
    return [int(el) for el in input().split()]
def main():
    n=int(input())
    ans=0
    for i in range(1,n+1):
        if i%3==0 or i%5==0:
            continue
        else:
            ans+=i
    print(ans)

if __name__ == '__main__':
    main()





Measured memory_bytes: 73536
n,m = map(int,input().split())
x_li = [0]*m
y_li = [0]*m
for i in range(m):
    x_li[i],y_li[i]=map(int,input().split())

map_li = [1]*n
red = [False]*n
red[0]=True

for i in range(m):
    x,y = x_li[i],y_li[i]
    x,y = x-1,y-1
    if red[x]:
        red[y]=True
    map_li[x]-=1
    map_li[y]+=1
    if map_li[x]==0:
        red[x]=False
#print(map_li)
print(sum(red))

Measured memory_bytes: 12404
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
#define int ll
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
vector <int> g[105];
set <pii> s;
int n, m;
void solve () {
	cin >> n >> m;
	int sum = n - 1;
	sum = ((sum - 1) * sum) / 2;
	if (m > sum) {
		cout << -1;     
		return;
	}
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		if (i != 2) {        	
			g[2].pb (i);
			ans ++;
		}
	}
	for (int i = 1; i <= n; i ++) {
		if (i != 2) {
  			for (int j = max (3ll, i + 1); j <= n; j ++) {
  			    if (m == sum) break;
  			    sum --;
  			    g[i].pb (j);  
  			    ans ++;
  			}
		}
	}   	
	if (sum != m) {
		cout << -1;
		return;
	}
	cout << ans << endl;
	for (int i = 1; i <= n; i ++) {
		for (auto to : g[i]) {
			cout << i << " " << to << endl;
		}
	}
}                        
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//	cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		A();
	}
	
	// R+X = 2G
	public static void A() {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		System.out.println(2*g-r);
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??¨??°????????°?????????
		int n = sc.nextInt();
		//???????????£?¨?
		int [] num = new int [n];
		long  sum = 0; //????¨???? ????????????????????????
		//??????????????°??????????´?
		for(int  i = 0; i < n;i++){
			//??°??????????´?
			 num [i] = sc.nextInt();
		}
		//??£?¨?
		int min = num[0];
		int max = num[0];
		for(int i = 0; i<n; i++){
			//?????§???
			if(max < num[i]){
				max = num[i]; //
			}
			//????°????
			if(min > num[i]){
				min = num[i];
			}
				//????¨?
				sum += num[i];
		}
			//???????????¨???
			System.out.println(min + " " + max + " "+  sum);
	}
}

Measured memory_bytes: 41548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int> s
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004

int main() {
    char s[10];
    cin >> s;
    sort(s, s + 4);
    printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    string s;
    cin >> s;
    if(s.at(0) == s.at(1) && s.at(1) == s.at(2)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
  middle=b[i]
  h=n
  l=-1
  while h-l>1:
    m=(h+l)//2
    if a[m]<middle:
      l=m
    else:
      h=m
  ab=l+1
  h=n
  l=-1
  while h-l>1:
    m=(h+l)//2
    if c[m]>middle:
      h=m
    else:
      l=m
  bc=n-h
  ans+=ab*bc
print(ans)

Measured memory_bytes: 23372
<?php
fscanf(STDIN, "%d %d", $max, $length);

$textList = array();
for( $i=0; $i<$max; $i++ )
{
  $textList[] = trim(fgets(STDIN));
}
sort( $textList );

$result = implode( "", $textList );
echo $result;
?>

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

using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
vector<int> adj[N];
int n, k, a, b;

int solve(int idx, int d1, int d2, int p) {
    int res = max(0, k - d1 - d2);
    int cnt = 0;
    for (auto v:adj[idx]) {
        if (v == p) continue;
        res = (1ll * res * solve(v, 1, cnt + (p != 0), idx)) % mod;
        ++cnt;
    }
    return res;
}

int main() {
    //  freopen("in.txt", "rt", stdin);

    scanf("%d %d", &n, &k);
    for (int i = 1; i < n; ++i) {
        scanf("%d %d", &a, &b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for (int i = 1; i <= n; ++i) {
        if (adj[i].size() > 1) continue;
        printf("%d", solve(i, 0, 0, 0));
        break;
    }

}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n >> m;
    vi v(n);
    cnt = INF;
    REP(i, n) {
        cin >> v[i];
        chmin(cnt, v[i]);
        sum += v[i];
    }
    m -= sum;
    ans += (m / cnt);
    cout << ans + n << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

char dic(string &s) {
  for (char c = 'a'; c <= 'z'; c++) {
    for (size_t i = 0; i < s.size(); i++) {
      if (s[i] == c) {
        i = s.size();
      }
      if (i == s.size() - 1) {
        return c;
      }
    }
  }
  return 'N';
}

string s;
int main(int argc, char const *argv[]) {
  cin >> s;
  char ans = dic(s);
  if (ans == 'N') {
    cout << "None" << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


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

int main(){
  int W,H,N;
  cin>>W>>H>>N;
  vector<vector<bool>> white(W,vector<bool>(H,true));
  for(int i=0;i<N;i++){
    int x,y,a;
    cin>>x>>y>>a;
    switch(a){
      case 1:
        for(int j=0;j<x;j++){
          for(int k=0;k<H;k++){
            white.at(j).at(k)=false;
          }
        }
        break;
      case 2:
        for(int j=x;j<W;j++){
          for(int k=0;k<H;k++){
            white.at(j).at(k)=false;
          }
        }
        break;
      case 3:
        for(int j=0;j<W;j++){
          for(int k=0;k<y;k++){
            white.at(j).at(k)=false;
          }
        }
        break;
      case 4:
        for(int j=0;j<W;j++){
          for(int k=y;k<H;k++){
            white.at(j).at(k)=false;
          }
        }
        break;
    }
  }
  
  int sum=0;
  for(int i=0;i<W;i++){
    for(int j=0;j<H;j++){
      if(white.at(i).at(j)){
        sum++;
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
while True:
    m,f,r=map(int,input().split())
    if m==f==r==-1:break
    a=m+f
    if m==-1 or f==-1:print('F')
    elif a >= 80:print('A')
    elif a >= 65:print('B')
    elif a >= 50:print('C')
    elif a >= 30:
        if r >= 50:print('C')
        else:print('D')
    else:print('F')

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

lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        for j in tmplst:
            if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                lst_append((a + i, b + j))

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Measured memory_bytes: 128036
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, std::vector<long long> V, std::vector<long long> C) {
  int ans = 0;
  for (int i = 0; i < N; i++)
    if (V[i] - C[i] > 0) ans += V[i] - C[i];
  cout << ans << endl;
}

int main() {
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> V(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &V[i]);
  }
  std::vector<long long> C(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &C[i]);
  }
  solve(N, std::move(V), std::move(C));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long N;
 
void func(long long result, int bit, long long& count) {
   
    if (result > N) {
        return;
    }
 
    if (bit == 0b111) {
        ++count;
    }
   
    func(result * 10 + 3, bit | 0b001, count);
    func(result * 10 + 5, bit | 0b010, count);
    func(result * 10 + 7, bit | 0b100, count);
}
 
int main() {
    cin >> N;
    long long count = 0;
    func(0, 0, count);
    cout << count << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int> > a(2, vector<int>(n));
    for(int i=0; i<2; ++i){
        for(int j=0; j<n; ++j){
            cin >> a[i][j];
        }
    }

    int sum = accumulate(a[0].begin(), a[0].end(), 0);
    int ans = 0;
    for(int i=n-1; i>=0; --i){
        sum += a[1][i];
        ans = max(ans, sum);
        sum -= a[0][i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
a, b, h, m = map(int,input().split())
c = ((h%12) * 60 + m) / (60 * 12)
d = m / 60
t = abs(c-d) * 2 * math.pi
# print(t)
print((a**2 + b**2 - 2*a*b*math.cos(t)) ** 0.5)

Measured memory_bytes: 62416
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1

for y in range(3):
    f = True
    for x in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')

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

int main() {
  int a;
  cin>>a;
  if(0<a/100&&a/100<13){
    if(0<a%100&&a%100<13){
    cout<<"AMBIGUOUS"<<endl;
    return 0;
    }
    cout<<"MMYY"<<endl;
    return 0;
  }
  
  if(0<a%100&&a%100<13){
    cout<<"YYMM"<<endl;
    return 0;
    }
    cout<<"NA"<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
    h, w = map(int, raw_input().split())

    square = []
    for i in range(h):
        square.append(raw_input())

    for i in range(h):
        for j in range(w):
            if square[i][j] == '.':
                continue
            else:
                if check(square, i, j, h, w):
                    continue
                else:
                    print("No")
                    exit()

    print("Yes")

def check(square, i, j, h, w):
    if i-1 >= 0:
        if square[i-1][j] == '#':
            return True
    if i+1 < h:
        if square[i+1][j] == '#':
            return True
    if j-1 >= 0:
        if square[i][j-1] == '#':
            return True
    if j+1 < w:
        if square[i][j+1] == '#':
            return True

    return False

if __name__ == '__main__':
    main()


Measured memory_bytes: 2696
n, a, b = map(int, input().split())
law = 10 ** 9 + 7

def fermat(n, r, law):
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % law
        y = y * (i + 1) % law

    ans = x * pow(y, law - 2, law) % law
    return ans

print((pow(2,n,law)- fermat(n,a,law)-fermat(n,b,law)-1)%law)

Measured memory_bytes: 3064
s = gets.to_i
used = Hash.new(false)
used[s] = true
ans = 1
loop do
    if s.odd?
        s = 3*s+1
    else
        s /= 2
    end
    ans += 1
    if used[s]
        puts ans
        break
    end
    used[s] = true
end

Measured memory_bytes: 1788