akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <double> x(n);
  vector <double> y(n);
  rep(i, n) cin >> x.at(i) >> y.at(i);
  double ans = 0;
  rep(i, n) {
    for (ll j = i+1; j < n; j++) {
      double tmp = pow(x.at(i)-x.at(j), 2) + pow(y.at(i)-y.at(j), 2);
      ans += pow(tmp, 0.5);
    }
  }
  cout << fixed << setprecision(10);
  cout << ans*2*(double)factorial(n-1)/(double)factorial(n) << endl;
}

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

int main() {
  int n;
  cin >> n;
  int max_height = 0;
  ll ans = 0;
  int a;
  rep(i, n) {
    cin >> a;
    if (a < max_height) {
      ans += max_height - a;
    }
    max_height = max(a, max_height);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(void)
{
	int h, w;
	int ans_h, ans_w, l;

	while(cin >> h >> w, h && w){
		ans_h = ans_w = l = 999999;
		for(int y = 1;y < 200; y++){
			for(int x = 1;x < 200; x++){
				if(y >= x) continue;
				if(y*y + x*x > h*h + w*w || y*y + x*x == h*h + w*w && y > h){
					if(y*y + x*x < l || y*y + x*x == l && ans_h > y)
						ans_h = y, ans_w = x, l = y*y + x*x;
				}
			}	
		}
		cout << ans_h << ' ' << ans_w << endl;
	}
}


Measured memory_bytes: 1160
n, m = map(int, input().split())

ss = []
for i in range(m):
    s = list(map(int, input().split()))[1:]
    te = 0
    for sm in s:
        te += 2**(sm-1)
    ss.append(te)

pp = list(map(int, input().split()))
res = 0
for i in range(2**n):
    tm = True
    for j in range(len(ss)):
        st = 0
        su = i & ss[j]
        for u in range(n):
            st += (su >> u) & 1
        if st % 2 != pp[j]:
            tm = False
            break
    if tm:
        res += 1
print(res)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
    if(a==b || b==c || c==d) printf("Bad");
    else printf("Good");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <iomanip>
using namespace std;

int bubbleSort(int *a,int n)
{
  int flag=1;
  int b;
  int ans=0;
  while(flag){
    flag=0;
    for(int j=n-1;j>0;j--){
      if(a[j]<a[j-1]){
	b=a[j];
	a[j]=a[j-1];
	a[j-1]=b;
	flag=1;
	ans++;
      }
    }
  }
  return ans;
}

int main()
{
  int n;
  int a[100];
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  int ans=bubbleSort(a,n);
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, y;
    cin >> n >> y;
    rep(i, n + 1){
        rep(j, n - i + 1){
            if(i * 1000 + j * 5000 + (n - i - j) * 10000 == y){
                cout << n - i - j << " " << j << " " << i << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VL a(n), b(n);
    ll sa = 0, sb = 0;
    REP(i,n){
        scanf("%lld", &a[i]);
        sa += a[i];
    }
    REP(i,n){
        scanf("%lld", &b[i]);
        sb += b[i];
    }

    ll d = sb - sa;
    if (d < 0){
        cout << "No" << endl;
        return 0;
    }

    sa = sb = 0;
    REP(i,n){
        ll p = b[i] - a[i];
        if (p > 0){
            sa += (p + 1) / 2;
            if (p % 2) sb++;
        }
        if (p < 0){
            sb -= p;
        }
    }

    // cout << sa << " " << sb << endl;

    if (sa <= d && sb <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll median(const vector<ll>& v) {
    if (v.size() % 2 == 0) {
        return round((v[v.size() / 2] + v[v.size() / 2 - 1]) / 2.);
    } else {
        return v[v.size() / 2];
    }
}

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

    ll N;
    cin >> N;
    vector<ll> A;
    for (ll i = 1; i <= N; ++i) {
        ll a;
        cin >> a;
        A.push_back(a - i);
    }
    sort(A.begin(), A.end());
    ll med = median(A);
    ll ans = 0;
    for (ll i = 0; i < N; ++i) {
        ans += abs(A[i] - med);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;

int n;

int res = 0;

int convert(string s){
	int tmp = 1;
	int res = 0;
	for(int i=s.size()-1;i>=0;--i){
		res += tmp * (s[i] - '0');
		tmp *= 10;
	}
	return res;
}

bool check(string s){
	set<int> se;
	bool a=false,b=false,c=false;
	for(int i=0;i<s.size();++i){
		if(s[i] == '7') a = true;
		if(s[i] == '5') b = true;
		if(s[i] == '3') c = true;
	}
	
	if(a && b && c){
		if(convert(s) <= n)
			return true;
	}
	return false;
}

void dfs(string s){
	//cout << s <<endl;
	if(s.size() >= 10) return ;
	if(s.size() >= 3){
		if(check(s)) res++;
	}
	
	string adds = "753";
	for(int i=0;i<3;++i){
		string ss = s;
		ss += adds[i];
		dfs(ss);
	}
	
}

int main(){
	cin >> n;
	
	dfs("");
	cout << res <<endl;
	
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static boolean[] prime = new boolean[10001];
	static int n;
	public static void main(String[] args) {
		make_prime();
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		if(!sc.hasNext())return false;
		n = sc.nextInt();
		return true;
	}
	
	static void solve(){
		int res = 0;
		for(int i = 2; i <= n; i++){
			if(prime[i] && prime[n - i + 1])res++;
		}
		System.out.println(res);
	}
	
	static void make_prime(){
		Arrays.fill(prime, true);
		prime[0] = false;
		prime[1] = false;
		for(int i = 2; i < prime.length; i++){
			if(prime[i]){
				for(int j = 2*i; j < prime.length; j += i){
					prime[j] = false;
				}
			}
		}
	}

}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPS(i,n) for(int i=0; i<(n); i++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

int main(int argc, char const *argv[])
{
  int N;
  cin >> N;
  
  map<char,bool> hinaarare = {
    {'P',false},
    {'W',false},
    {'G',false},
    {'Y',false}
  };

  char s;
  REP(N) {
    cin >> s;
    hinaarare[s] = true;
  }

  int ans = 0;
  for(auto kv : hinaarare) {
    ans += (kv.second?1:0);
  }

  if(ans == 3) cout << "Three";
  else cout << "Four";


  return 0;
}


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

using namespace std;

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


#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define mod 1000000007
 
ll dp[10000];

int main() {
    ios::sync_with_stdio(false);
 	int N;
 	cin>>N;
 	dp[1] = 1;
 	for(int i = 2; i <=N; i++) {
 		int fac= i;
 		while(fac%2 == 0) {
 			dp[2]++;
 			fac /=2;
 		}
 		for(int j = 3; j*j <= fac; j++) {
 			while(fac%j==0) {
 				dp[j]++;
 				fac/=j;
 			}
 		}
 		dp[fac]++;
 	}
 	ll ans = 1;
 	for(int i = 2; i<=N; i++) {
 		ans *= (dp[i]+1);
 		ans %= mod;
 	}
 	cout<<ans<<endl;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - H and V
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 6;
const int MAX_W = 6;
const int HBITS = 1 << MAX_H;
const int WBITS = 1 << MAX_W;

/* typedef */

/* global variables */

char fs[MAX_H][MAX_W + 4];

/* subroutines */

/* main */

int main() {
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);
  for (int y = 0; y < h; y++) scanf("%s", fs[y]);

  int hbits = 1 << h, wbits = 1 << w, cnt = 0;
  for (int ybits = 0; ybits < hbits; ybits++)
    for (int xbits = 0; xbits < wbits; xbits++) {
      int c = 0;
      for (int y = 0, by = 1; y < h; y++, by <<= 1)
	if (ybits & by)
	  for (int x = 0, bx = 1; x < w; x++, bx <<= 1)
	    if ((xbits & bx) && fs[y][x] == '#') c++;
      if (c == k) cnt++;
    }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

struct Combination {
	vector<int64_t> _fact, _rfact, _inv;
	int64_t MOD;

	Combination(size_t sz, int64_t mod) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1), MOD(mod) {
		_fact[0] = _rfact[sz] = _inv[0] = 1;
		for (int i = 1; i <= sz; ++i) {
			_fact[i] = _fact[i - 1] * i % MOD;
		}
		_rfact[sz] = inverse(_fact[sz]);
		for (int i = sz - 1; i >= 0; --i) {
			_rfact[i] = _rfact[i + 1] * (i + 1) % MOD;
		}
		for (int i = 1; i <= sz; ++i) {
			_inv[i] = _rfact[i] * _fact[i - 1] % MOD;
		}
	}

	inline int64_t fact(int k) const { return _fact[k]; }
	inline int64_t rfact(int k) const { return _rfact[k]; }
	inline int64_t inv(int k) const { return _inv[k]; }

	int64_t inverse(int64_t x) const { return pow(x, MOD - 2); }
	int64_t pow(int64_t x, int64_t n) const {
		int64_t ret = 1;
		while (n > 0) {
			if (n & 1) { (ret *= x) %= MOD; }
			(x *= x) %= MOD;
			n >>= 1;
		}
		return ret;
	}

	int64_t P(int n, int r) const {
		if (r < 0 || n < r) { return 0; }
		return fact(n) * rfact(n - r) % MOD;
	}
	int64_t C(int n, int r) const {
		if (r < 0 || n < r) { return 0; }
		return fact(n) * rfact(r) % MOD * rfact(n - r) % MOD;
	}
	int64_t H(int n, int r) const {
		if (n < 0 || r < 0) { return 0; }
		return r == 0 ? 1 : C(n + r - 1, r);
	}
};

int main() {
	constexpr Int MOD = 1e9 + 7;
	Int S;
	cin >> S;

	Combination cb(S + 10, MOD);
	Int ans = 0;
	for (int n = 1; n <= S / 3; ++n) {
		(ans += cb.C(S - 2*n - 1, S - 3 *n)) %= MOD;
	}
	cout << ans % MOD << "\n";

	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

int main(){
  long long n,xnum,ynum,i,s,t;
  cin >> n >> xnum >> ynum;
  long long a[n];
  for(i=0; i<n; i++){
    cin >> a[i];
  }

  if(n==1){
  	s = abs(a[0]-ynum);
  	cout << s << endl;
  }else{
  	s = abs(a[n-1] - ynum);
  	t = abs(a[n-1] - a[n-2]);
  	t = max(s,t);
  	cout << t << endl; 
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] aa = new int[2];
        int i = 1;
        while (sc.hasNext()){
            if (i % 2 != 0) {
                aa[0] = sc.nextInt();
                i++;
            }else {
                aa[1] = sc.nextInt();
                int c = aa[0] + aa[1];
                int digit = 0;
                while (c >= 10){
                    c = c / 10;
                    digit++;
                }
                System.out.println(digit + 1);
                i++;
            }
        }
    }
}



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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;


int main(){
    SCIN(s);
    flag=true;
    rep(i,s.size()){
        Rep(j,i+1,s.size()){
            if(s[i]==s[j])flag=false;
            if(!flag)break;
        }
        
    }
    printf(flag?"yes":"no");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static int rmax = 3;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int r = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());
        int k = Integer.parseInt(scan.next());
        int[][] item = new int[r][c];
        for (int i = 0; i < k; i++) {
            int rk = Integer.parseInt(scan.next());
            int ck = Integer.parseInt(scan.next());
            int vk = Integer.parseInt(scan.next());
            rk--;
            ck--;
            item[rk][ck] = vk;
        }
        scan.close();

        long[][][] dp = new long[r][c][rmax + 1];
        if (item[0][0] != 0) {
            dp[0][0][1] = item[0][0];
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                for (int l = 0; l <= rmax; l++) {
                    // 下方向への移動
                    if (i + 1 < r) {
                        dp[i + 1][j][1] = Math.max(dp[i + 1][j][1], dp[i][j][l] + item[i + 1][j]);
                        dp[i + 1][j][0] = Math.max(dp[i + 1][j][0], dp[i][j][l]);
                    }
                    // 右方向への移動
                    if (j + 1 < c) {
                        if (l < rmax) {
                            dp[i][j + 1][l + 1] = Math.max(dp[i][j + 1][l + 1], dp[i][j][l] + item[i][j + 1]);
                        }
                        dp[i][j + 1][l] = Math.max(dp[i][j + 1][l], dp[i][j][l]);
                    }
                }
            }
        }

        long ans = 0;
        for (int l = 0; l <= rmax; l++) {
            ans = Math.max(ans, dp[r - 1][c - 1][l]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 686916
# E - Crested Ibis vs Monster
def main():
    INF = 1 << 30

    H, N, *AB = map(int, open(0).read().split())
    dp = [INF] * (H + 10001)  # dp[i] := min magic points to decrease monster's health by i
    dp[0] = 0
    for i in range(H):
        if dp[i] == INF:
            continue
        for a, b in zip(*[iter(AB)] * 2):
            if dp[i] + b < dp[i + a]:
                dp[i + a] = dp[i] + b
    print(min(dp[H:]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 39792
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
def ans1(x):
    return s.count(x)-t.count(x)
ans2=0
ans_1=0
for S in s:
    if ans1(S)>0 and ans1(S)>ans2:
            ans2=ans1(S)
if ans2>=0:
    print(ans2)
else:
    print("0")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll h,w,k,ans=INF;
char ch[12][1010];
bool cut[12];
void cal(){
	ll cnt=0;
	ll now=0;
	while(now!=w){
		ll sum[12]={0};
		ll next=0;
		for(ll i=0;i<h;i++){
			if(ch[i][now]=='1'){
			 sum[next]++;
			 if(sum[next]>k){
			 	return ;
			 }
			}
			if(cut[i]){
			 	next++;
			}			
		}
		now++;
		next=0;
		bool b=true;
		for(;now<w;now++){
			for(ll i=0;i<h;i++){
				if(ch[i][now]=='1'){
					sum[next]++;
					if(sum[next]>k){
						cnt++ ;
						b=false;
						break;
					}
				}
				if(cut[i]){
					next++;
				}
			}
			if(b==false){
				break;
			}
			next=0;
		}
	}
	for(ll i=0;i<h-1;i++){
		if(cut[i]){
			cnt++;
		}
	}
	ans=min(ans,cnt);
}
void dep(ll now){
	if(now==h-1){
		cal();
		return ;
	}
	cut[now]=false;dep(now+1);
	cut[now]=true;dep(now+1);
}
int main() {
	cin>>h>>w>>k;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>ch[i][j];
		}
	}
	dep(0);
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int n;
int a[200010];
int main(){
  scan(n);
  rep(i,n){
    scan(a[i]);
  }
  ll res=0,num=0,loc=n-1;
  for(ll i=n-1;i>=0;i--){
    if(a[i]>i){
      res=-1;
      break;
    }
    ll now=max(num+i-loc,(ll)0);
    if(now>a[i]){
      res=-1;
      break;
    }
    else if(now<a[i]){
      res+=a[i];
      num=a[i];
      loc=i;
    }
  }
  prin(res);
      

  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;


int main() {
  ll n;
  cin >> n;
  vector<ll> a(n); rep(i,n) cin >> a[i];

  ll sum = 0;
  rep(i,n) sum += a[i];
  ll even_sum = 0;
  for(ll i = 1; i < n; i += 2 ) {
    even_sum += a[i];
  }

  ll x_1 = sum - 2*even_sum;
  cout << x_1;
  ll x_i = x_1;
  rep(i,n) {
    if( i == n-1 ) continue;
    x_i = 2*a[i] - x_i;
    cout << ' ' << x_i;
  } 
  cout << endl;
  return 0;
}


Measured memory_bytes: 4056
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	string s;
	string t = "abcdefghijklmnopqrstuvwxyz";
	ll k;
	cin>>s;
	cin>>k;
	rep(i,s.size()-1){
		if(s[i]=='a')continue;
		rep(j,26){
			if(t[j]==s[i]){
				if(26-j<=k){
					s[i]='a';
					k=k-26+j;
				}
				break;
			}
		}
	}
	rep(j,26){
		if(t[j]==s[s.size()-1]){
			if(26-j<=k){
				k=k-26+j;
				k%=26;
				s[s.size()-1]=t[k];
			}else s[s.size()-1]=t[j+k];
			cout<<s<<endl;
			return 0;
		}
	}

	return 0;

}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>

int main(){
	long long N;
	long long T;
	long long t[200000];
	long long ans = 0;

	scanf("%lld %lld",&N,&T);
	for(long long i=0;i<N;i++){
		scanf("%lld",&t[i]);
	}

	ans += T;
	for(long long i=1;i<N;i++){
		if(t[i-1]+T<t[i]){
			ans += T;
		}else{
			ans += t[i]-t[i-1];
		}
	}

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

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  int n,q;
  while(true){
    cin >> n >>q;
    if(n==0) break;
    int day[110]={0};
    for(int i=0;i<n;i++){
      int m;cin >> m;
      for(int j=0;j<m;j++){
        int d;cin >> d;
        day[d]++;
        }
      }
    int max=0,ans=0;
    for(int i=0;i<105;i++){
      if(day[i]>=q){
        if(max<day[i]){
          max=day[i];
          ans=i;
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2976
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
D,T,S = LI()
print('Yes' if D/S<=T else 'No')


Measured memory_bytes: 27000
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }   
    int dp[n]={0};
    dp[0]=0;
    for(int i=1;i<n;i++)dp[i]=INF;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=0){
                dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
 return 0;   
}

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

int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if(s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll a,b,k;
	ll c=0,d=0;
	ll f=0;

	cin>>a>>b>>k;

	c=a;
	d=b;
	rep(i,k){
	if(c%2==1){
		c=c-1;
	}
	c=c/2;
	d+=c;
	f++;
	if(f==k){
		break;
	}
	if(d%2==1){
		d=d-1;
	}
	d=d/2;
	c+=d;
	f++;
	if(f==k){
		break;
	}

	}
	cout<<c<<" "<<d<<endl;
	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int x,y,a;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0)break;
    else{
        if(x>y){
            a=x;
            x=y;
            y=a;
        }
    printf("%d %d\n",x,y);}}
    return 0;
}



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

int main()
{
	string A, B, C;
	cin >> A >> B >> C;

	if(A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int ans=0;
    int seki=0;
    for(int i=1;i<5;i++){
        for(int j=i+1;j<6;j++){
            for(int k=j+1;k<7;k++){
                seki=(2*i+1)*(2*j+1)*(2*k+1);
                if(seki<=n){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())

e = [0] * (N + 1)

for i in range(2, N + 1):
  cur = i
  for j in range(2, N + 1):
    while cur % j == 0:
      e[j] += 1
      cur //= j

def num(m):
  return len(list(filter(lambda x: x >= m-1, e)))

print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) +
  num(5) * (num(5) - 1) * (num(3) - 2) // 2)

Measured memory_bytes: 3064
def constructXOR(A, n): 
      
    # calculate xor of array 
    XOR = 0
    for i in range(0, n): 
        XOR ^= A[i] 
  
    # update array 
    for i in range(0, n): 
        A[i] = XOR ^ A[i] 

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

for i in range(0,n): 
    print(A[i], end =" ")

Measured memory_bytes: 105676
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
d = {}
for i in range(N):
    s = ST()
    d[s] = d.get(s,0)+1
    max_i = 0
for k,i in d.items():

    if i>max_i:
        ans = [k]
        max_i = i
    elif i == max_i:
        ans.append(k)
ans.sort()
for i in ans:
    print(i)


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{

    optimize();


    int n;
    cin>> n;

    cout<< (((n+ 1000-1)/ 1000)* 1000) -n;
    nl;


    return 0;
}




Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define int long long

#define check(c)       cout<<#c<<" : "<<c<<endl;
#define check2(a, b)    cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<endl;
#define check3(a, b, c)  cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<" | "<<#c<<" : "<<c<<endl;

int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

void testCase(){
    int n; cin >> n;
    vector<int> a(n);

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

    map<int, int> mp;
    int pair = 1;
    for(int i = 0; i < n; i++){
        // check(a[i])
        for(int j = 1; j * j <= a[i]; j++){
            if(a[i] % j == 0){
                // if(i == 1 && j != 1){
                //     check2(j, a[i] / j)
                // }
                // if(i == 2)

                if(mp[j] == 1){
                    // check("YES")
                    // check2(i, j)
                    pair = 0;
                    break;
                }
                if(j != 1 && mp[j] == 0){
                    mp[j] = 1;
                    // check2(i, j)
                }
                if(j * j != a[i] && mp[a[i] / j] == 1){
                    // check("NO")
                    // check2(i, j)
                    // check(a[i] / j)
                    pair = 0;
                    break;
                }
                if(j * j != a[i])mp[a[i] / j] = 1;
                // check2(i, a[i] / j)

            }
        }
        // for(auto x : mp){
        //     check2(i, x.second)
        // } cout << '\n';
        if(pair == 0){
            break;
        }
    }

    if(pair){
        cout << "pairwise coprime" << endl;
    } else{
        int gd = a[0];
        for(int i = 0; i < n; i++){
            gd = gcd(gd, a[i]);
        }
        if(gd == 1){
            cout << "setwise coprime" << endl;
        } else{
            cout << "not coprime" << endl;
        }
    }
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int t = 1;
    // int t; cin >> t;
    while(t--)
        testCase();
    
    return 0;
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (d == 1 ? 1 : 0) << endl;
}


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

typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define all(obj) (obj).begin(), (obj).end()
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

ll aN[100000];
// dp[この子までの範囲で][飴を配る総数] = 場合の数
ll dp[110][20010];

int main() {
	int N, K;
	cin >> N >> K;
	rep(i, 0, N) cin >> aN[i];
	dp[0][0] = 1;

	rep(i, 0, N) {
		ll sm[K+2];
		// 今回送るi行について累積和を取る
		rep(j, 1, K+2) {
			sm[j] = (sm[j-1] + dp[i][j-1]) % MOD;
		}
		rep(j, 0, K+1) {
			// iが送る予定の長さに応じた区間和を取る
			dp[i+1][j] = (sm[j+1] - sm[max(j-aN[i], ll(0))] + MOD) % MOD;
		}
	}
	cout << dp[N][K] << endl;
	return 0;
}


Measured memory_bytes: 17280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

long long solve(const vector<int>& low, const vector<int>& high){
    long long res = 0;
    int pos = 0;
    long long sum = 0;
    for(int i=0;i<low.size();i++){
        if(low[i] >= pos) break;
        sum += pos - low[i];
        pos = low[i];
        res = max(res, sum + abs(pos));
        if(high[i] <= pos) break;
        sum += high[i] - pos;
        pos = high[i];
        res = max(res, sum + abs(pos));
    }
    sum = 0;
    pos = 0;
    for(int i=0;i<low.size();i++){
        if(high[i] <= pos) break;
        sum += high[i] - pos;
        pos = high[i];
        res = max(res, sum + abs(pos));
        if(low[i] >= pos) break;
        sum += pos - low[i];
        pos = low[i];
        res = max(res, sum + abs(pos));
    }
    return res;
}

int main(){
    int N; cin >> N;
    vector<int> L(N), R(N);
    for(int i=0;i<N;i++) cin >> L[i] >> R[i];
    sort(L.rbegin(), L.rend());
    sort(R.begin(), R.end());
    cout << solve(R, L) << endl;
}

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

int map[14][14];

void put(int x,int y,int size){
	int i,j;
	int d1[2] = {-1,1},d2[2] = {-2,2};

	switch(size){
		case 1:
			for(i = 0;i < 2;i++){
				map[y][x+d1[i]]++;
				map[y+d1[i]][x]++;
			}
			map[y][x]++;
			break;
		case 2:
			for(i = -1;i < 2;i++){
				for(j = -1;j < 2;j++){
					map[y+i][x+j]++;
				}
			}
			break;
		case 3:
			for(i = -1;i < 2;i++){
				for(j = -1;j < 2;j++){
					map[y+i][x+j]++;
				}
			}
			for(i = 0;i < 2;i++){
				map[y][x+d2[i]]++;
				map[y+d2[i]][x]++;
			}
			break;
		default:
			break;
	}
}

int main(){
	int x,y,size,i,j,cnt,max;

	memset(map,0,sizeof(map));

	while(scanf("%d,%d,%d",&x,&y,&size) != EOF){
		put(x+2,y+2,size);

		cnt = 0;
		max = 0;
		for(i = 2;i < 12;i++){
			for(j = 2;j < 12;j++){
				if(map[i][j] == 0){
					cnt++;
				}else if(max < map[i][j]){
					max = map[i][j];
				}
			}
		}
	}

	printf("%d\n%d\n",cnt,max);

	return 0;
}

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

int main ()
{
string s;
int a;
cin>>a>>s;
if(a<=5000&&a>=2800&&s.length()>=1&&s.length()<=10){
if(a>=3200){
    cout<<s;
}
else{
    cout<<"red";
}
}
return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mask(int a) { return (1ull << a) - 1; }
const int bases[64] = {257,262,266,275,276,281,285,290,296,302,306,310,311,313,323,333,344,345,350,357,367,370,373,402,423,425,431,440,442,443,454,457,458,462,471,478,481,487,489,492,499,501,502,503,506,514,524,532,535,541,550,552,557,559,562,563,567,570,571,580,592,597,604,612};
const ull mod = 0x1fffffffffffffff, base = bases[chrono::duration_cast<chrono::microseconds>(chrono::system_clock::now().time_since_epoch()).count() & 63];
struct RollingHash {
    vector<ull> hashed, power;
    inline ull mul(ull a, ull b) const {
        __uint128_t ans = __uint128_t(a) * b;
        ans = (ans >> 61) + (ans & mask(61));
        if(ans >= mod) ans -= mod;
        return ans;
    }
    RollingHash(const string &s) {
        ll n = s.size();
        hashed.assign(n + 1, 0);
        power.assign(n + 1, 0);
        power[0] = 1;
        for(ll i = 0; i < n; i++){
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i];
            if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
        }
    }
    ull get(ll l, ll r) const {
        ull ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
        if(ret >= mod) ret -= mod;
        return ret;
    }
};
struct HashSet{
    vector<pair<ll, ll>> data[1 << 14];
    ll get(ll at, ll val){
        for(auto& i : data[at & mask(14)]) if(i.first == at) return val - i.second;
        data[at & mask(14)].emplace_back(at, val);
        return 0;
    }
};
int main(){
    int n;
    string s;
    cin >> n >> s;
    RollingHash rh(s);
    int ok = 0, ng = n / 2 + 1;
    while(ng - ok > 1){
        int cen = (ok + ng) / 2;
        bool flag = 0;
        HashSet cnt;
        for(int i = cen; i <= n; i++) if(cnt.get(rh.get(i - cen, i), i) >= cen){
            flag = 1;
            break;
        }
        if(flag) ok = cen;
        else ng = cen;
    }
    cout << ok << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#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 repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;
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;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  ll n, sum = 0;
  cin >> n;
  vector<ll> a(n);
  vector<pair<ll, ll>> cnt;
  rep(i, n) { cin >> a[i]; }
  sort(ALL(a), greater<>());
  rep(i, n - 1) {
    int f = (i + 1) / 2;
    sum += a[f];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4772
import sys

def answer():
    input = sys.stdin.readline
    M = int(input())

    Ds = [0] * M
    Cs = [0] * M
    total = 0

    for i in range(M):
        c, d = map(int, input().split())
        Cs[i] = c
        Ds[i] = d
        total += d * c

    digits = sum(Ds)

    ans = (digits-1) + (total-1) // 9

    print(ans)


if __name__ == '__main__':
    answer()


Measured memory_bytes: 12520
n,l,t=map(int,input().split())
a,cs=[0]*n,0
for i in range(n):
	x,y=map(int,input().split())
	x+=(t if y==1 else -t)
	cs=(cs+x//l)%n
	x%=l
	if x<0:
		x+=l
		cs-=1
	a[i]=x
a.sort()
print('\n'.join([str(a[(i+cs+n)%n]) for i in range(n)]))

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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 A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int N, M;
struct Edge {
    int to, id;
    Edge(int to, int id): to(to), id(id) {}
};
vector<Edge> g[55];
vector<int> es;

bool dfs(int v, int tv, int p = -1) {
    if (v == tv) {
        return true;
    }
    for (Edge e : g[v]) {
        if (e.to == p) continue;
        if (dfs(e.to, tv, v)) {
            es.pb(e.id);
            return true;
        }
    }
    return false;
}

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

    cin >> N;
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    cin >> M;
    vector<ll> eset(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        es = vector<int>();
        dfs(a, b);
        for (int e : es) {
            eset[i] |= 1ll << e;
        }
    }
    ll ans = 0;
    rep(i, 1 << M) {
        ll mask = 0;
        rep(j, M) {
            if (i >> j & 1) {
                mask |= eset[j];
            }
        }
        int white = __builtin_popcountll(mask);
        ll now = 1ll << (N - 1 - white);
        if (__builtin_popcountll(i) % 2 == 0) ans += now;
        else ans -= now;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m1 = in.nextInt();
        int d1 = in.nextInt();
        int m2 = in.nextInt();
        int d2 = in.nextInt();
        System.out.println(m1==m2?0:1);
    }
}


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

int main()
{
	int n,m; cin>>n>>m;
	int a[5000001]={0};

	for(int i=0;i<m;i++)
	{
		int l,r;
		cin>>l>>r;
		a[l]++;
		a[r+1]--;
	}
	int c=0;
	for(int i=1;i<=n;i++)
	{
		a[i] = a[i] + a[i-1];
		if(a[i]==m) c++;
	}

	cout<<c<<endl;
}

Measured memory_bytes: 19840
N, K  = list(map(int,input().split()))
A = list(map(int,input().split()))

dp = [0 for _ in range(K+1)]
dp[0] = 0
for k in range(1,K+1):
	for a in A:
		if k-a>=0:
			if dp[k-a]==0:
				dp[k]=1


if dp[K]==1:
	print('First')
else:
	print('Second')

Measured memory_bytes: 9920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
	ll n,a[214514],b[214514];
int main() {
	cin>>n;
	for(int i=0;i<=n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	ll ans=0;
	for(int i=n-1;i>=0;i--){
		if(a[i+1]<=b[i]){
			b[i]-=a[i+1];
			ans+=a[i+1]+min(b[i],a[i]);
			a[i]-=min(b[i],a[i]);
		}else{
			ans+=b[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main() {
	string A, B, C;
	int a, b, c;
	int na = 0, nb = 0, nc = 0;
	int player = 1;
	//1->A,2->B,3->C;

	cin >> A >> B >> C;

	a = A.size();
	b = B.size();
	c = C.size();

	for (;;) {
		//cout << player << endl;
		if (player == 1) {
			if (a == na ) {
				break;
			}
			else {
				player = A[na++] - 'a' + 1;
				continue;
			}
		}
		else if (player == 2) {
			if (b == nb ) {
				break;
			}
			else {
				player = B[nb++] - 'a' + 1;
				continue;
			}
		}
		else if (player == 3) {
			if (c == nc ) {
				break;
			}
			else {
				player = C[nc++] - 'a' + 1;
				continue;
			}
		}
	}

	if (player == 1) {
		cout << 'A' << endl;
	}
	else if (player == 2) {
		cout << 'B' << endl;
	}
	else
	{
		cout << 'C' << endl;
	}

	return 0;
}

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

void swap(int*, int*);
int main(){
  int n; cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];

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

  cout << ans << endl;

  return 0;
}

void swap(int* a, int*b){
  int temp=*a;
  *a = *b;
  *b = temp;
}


Measured memory_bytes: 640
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
def do():
    A,B = INTM()
    if A==B:
        print('Draw')
    elif A==1:
        print('Alice')
    elif B==1:
        print('Bob')
    elif A>B:
        print('Alice')
    else:
        print('Bob')
if __name__ == '__main__':
    do()

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

using namespace std;

const int MX = 100005;

int main() {
	int n;
	cin >> n;
	vector<long long> cnt(MX);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	long long tot = 0;
	for (int i = 0; i < MX; i++) {
		tot += i * cnt[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int b, c;
		cin >> b >> c;
		tot -= b * cnt[b];
		tot -= c * cnt[c];
		cnt[c] += cnt[b];
		cnt[b] = 0;
		tot += b * cnt[b];
		tot += c * cnt[c];
		cout << tot << endl;
	}
	return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
long long mod(int n){
  long long p=1000000000+7;
  if(n==1) return 2;
  if(n%2==0) return mod(n/2)*mod(n/2)%p; 
  if(n%2==1) return 2*mod(n-1)%p; 
}
long long from_up(int n,int r){
  long long p=1000000000+7;
  if(r==1) return n;
  if(r>1) return from_up(n,r-1)*(n-r+1)%p;
}
long long bunbo_1(int r,int P){
   long long p=1000000000+7;
  if(P==1) return from_up(r,r);
  if(P%2==0) return bunbo_1(r,P/2)*bunbo_1(r,P/2)%p; 
  if(P%2==1) return from_up(r,r)*bunbo_1(r,P-1)%p; 
}
long long nCr_mod(int n,int r){
  long long p=1000000000+7;
  return from_up(n,r)*bunbo_1(r,p-2)%p;
}
int main() {
 int n,a,b;
  cin>>n>>a>>b;
  int p=1000000000+7;
  long long ans=mod(n)-1-nCr_mod(n,a)-nCr_mod(n,b);
  if(ans>0) ans%=p;
  if(ans<0){
    while(ans<0) ans+=p;
  }
  cout<<ans<<endl;
}
 
  

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ss, ee) for (int i = (ss); i < (ee); ++i)
using Vi = vector<int>;
using VVi = vector<Vi>;

void solve() {
  int N, D;
  cin >> N >> D;
  VVi v(N, Vi(D));
  for (auto &e1 : v)
    for (auto &e2 : e1) cin >> e2;

  int ans = 0;
  rep(i, 0, N - 1) {
    rep(j, i + 1, N) {
      int sum = 0;
      rep(k, 0, D) {
        int x = (v[i][k] - v[j][k]);
        sum += x * x;
      }
      double chk = sqrt(sum);
      if (floor(chk) == chk) ans++;
    }
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int H, W, A, B;
const int K = 1E9 + 7 + 1E-5;
ll pow_mod(ll n, ll k, ll m) {
  assert(k >= 0);
  assert(m > 0);
  ll ret = 1;
  ll base = n % m;
  while (k) {
    if (k & 1) {
      ret = (ret * base) % m;
    }
    base = (base * base) % m;
    k /= 2;
  }
  return ret;
}

ll choose(ll n, ll k) {
  ll ret = 1;
  for(ll i = 1; i <= k; ++i) {
    ret *= n--;
    ret /= i;
  }
  return ret;
}

ll perm(ll n, ll k) {
  ll ret = 1;
  while(k--) {
    ret *= n--;
  }
  return ret;
}

ll perm_mod(ll n, ll k, const ll m) {
  assert(m > 0);
  ll ret = 1;
  while(k--) {
    ret = (ret * ((n--) % m)) % m;
  }
  return ret;
}

ll choose_mod(ll n, ll k) {
  const ll up = perm_mod(n, n, K);
  const ll dm = (perm_mod(k, k, K) * perm_mod(n - k, n - k, K)) % K;

  const ll idm = pow_mod(dm, K - 2, K);

  return (up * idm) % K;
}
int ct(int h, int w) {
  if (h == 0 || w == 0) return 0;
  return choose_mod(h + w - 2, min(h, w) - 1);
}

int main() {
  cin >> H >> W >> A >> B;
  if (A == H || B == W) {
    cout << 0 << endl;
    return 0;
  }
  long long ret = ct(H, W);

  int n1 = H - 1 + B - 1;
  const int k1 = B - 1;
  int n2 = W - 1 - B + 1 - 1;
  const int k2 = W - 1 - B;

  long long d1 = choose_mod(n1, k1);
  long long d2 = choose_mod(n2, k2);

  for (int i = 0; i < A; ++i) {
    ret -= (d1 * d2) % K;
    ret += K;
    ret %= K;
    ll nd1 = (d1 * (n1 - k1)) % K;

    nd1 = (nd1 * pow_mod(n1, K - 2, K)) % K;
    n1--;
    n2++;

    ll nd2 = (d2 * n2) % K;

    nd2 = (nd2 * pow_mod(n2 - k2, K - 2, K)) % K;
    d1 = nd1;
    d2 = nd2;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define For(i , j , k) for (int i = (j) ; i <= (k) ; ++ i)
using namespace std;

int n , a , sum1 , sum4;

int main()
{
	scanf("%d" , &n);
	For(i , 1 , n)
	{
		scanf("%d" , &a);
		if (a % 4 == 0)
			++ sum4;
		else
		if (a % 2)
			++ sum1;
	}
	if (sum4 >= sum1 || (sum1 == sum4 + 1 && sum1 + sum4 == n))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 256