akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<cstdio>
#include<stdlib.h> 
using namespace std;
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int i=0,j=0;
        vector<int> ans;
        int k=0;
        for(i=0;i<nums.size();i++){
            for(j=i;j<nums.size();j++){ 
                if(i!=j && (nums[i]+nums[j] == target ) ){
                    ans.push_back(i);
                    ans.push_back(j);
                    k=0;
                    break;
                }
                k++;
            }
            if(k==0) break;
        }
        return ans;
    }
};
int main (){
	int n,i;
	int a[100005];
	bool zero=true,three=true;
	cin >> n;
	for(i=0;i<n;i++) {
		cin >> a[i];
		if(a[i]!=0) zero=false;
	}
	if(zero){
		cout << "Yes" << endl;
		return 0;
	}
	if(n%3!=0){
		cout << "No" << endl;
		return 0;
	}
	sort(a,a+n);
	for(i=1;i<n;i++){
		if(i!=n/3&&i!=n*2/3){
			if(a[i-1]!=a[i]) three=false;
		}
	}
	int b=(a[0]^a[n/3]);
	if(three&&(b==a[n*2/3])) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
int mka() {
	// your code goes here
	long long n,i=0;
	cin>>n;
	long long arr[n];
	for(i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	if(arr[0]==1&&arr[1]==2&&arr[2]==3&&n==3)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

int maMAA(){
     int i,j,n,c=0,k;
      cin>>n;int a[n+1];
      for(i=0;i<n;i++)
       cin>>a[i];
      for(i=0;i<n;i++){
        for(j=0;j<n&&j!=i;j++){
        for(k=0;k<n&&k!=i&&k!=j;k++){
        	if((a[j]^a[k])!=a[i])
         {c=1;break;}
      }if(c==1) break;}if(c==1) break;}
      if(c==1) cout<<"No";
      else cout<<"Yes";
    return 0;
}
int mA(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    vector<int> nums={2,7,11,15,-100,19,9,101,87,199,100101,-1818,29,-1,101};
    int target=98;
    Solution o;
    vector<int> ans={o.twoSum(nums,target)};
    for(auto i:ans){
        cout<<i<<" ";
    }
    return 0;
}

Measured memory_bytes: 640
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll a[Max];
ll n,A,B,ans,f=1;
void solve(){
	string s;
	cin>>s;
	n = sz(s);
	rep(i,0,n){
		if(i&1){
			if(s[i]=='R')f=0;
		}else{
			if(s[i]=='L')f=0;
		}
	}
	cout<<(f?"Yes":"No");
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int i;
    long long lucas[85]={0};
    lucas[0]=2;
    lucas[1]=1;
    for(i=2; i<=86; i++){
        lucas[i]=lucas[i-1]+lucas[i-2];
    }
    cin >> i;
    cout << lucas[i] << endl;
    return 0;
}

Measured memory_bytes: 256
dic = {'A': 0, 'B': 0, 'AB': 0, 'O': 0}

while True:
    try:
        s = raw_input()
        sp = s.split(',')
        dic[ sp[1] ] += 1;
        
    except EOFError:
        print "%d\n%d\n%d\n%d" % (dic['A'], dic['B'], dic['AB'], dic['O'])
        break

Measured memory_bytes: 5036
#include <stdio.h>
#define N 100

main()
{
  int n,i,j;
  int temp,count=0;
  int A[N];
  
  scanf("%d",&n);
  
  for( i = 0 ; i < n ; i++ ){

    scanf("%d",&A[i]);

  }

  for(i = 0 ; i < n - 1 ; i++){
    for(j = n - 1 ; j >= i + 1 ; j--){
      
      if( A[j] < A[j-1] ){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	count++;
      }
    }
  }

  for( i = 0 ; i < n ; i++ ){
    if(i != 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
using namespace std;
typedef long long ll;
ll N,a[10000],s,memory[3003][3003];
ll dp(ll left,ll right)
{
    if (memory[left][right]!=0){
        return memory[left][right];
    }
    if (left>right) return 0;
    ll x1=a[left]+min(dp(left+2,right),dp(left+1,right-1));
    ll x2=a[right]+min(dp(left+1,right-1),dp(left,right-2));
    memory[left][right]=max(x1,x2);
    return max(x1,x2);
}
int main()
{
   cin>>N;
   s=0;
   for (int i=1;i<=N;++i){
        cin>>a[i];
        s+=a[i];
}
    cout<<2*dp(1,N)-s;

}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    int a = 0; int b = 0; int c=0;
    REP(i,3){
        if(s[i]=='a') a++;
        else if(s[i]=='b') b++;
        else c++;
    }
    if(a==1 &&b==1&&c==1) print("Yes");
    else print("No");
    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4)


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	int n;
	cin >> n;
	int arr[n];
	int start = 101, end = 1;
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		start = min(arr[i], start);
		end = max(arr[i], end);
	}
	int mn = 2e9;
	for(int i = start; i <= end; i++) {
		int sum = 0;
		for(int j = 0; j < n; j++) {
			sum += pow(i - arr[j], 2);
		}
		mn = min(mn, sum);
	}
	cout << mn << "\n";
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int ans = 0;
  string s;
  cin >> s;
  if(s[0] == '1') ans++;
  if(s[1] == '1') ans++;
  if(s[2] == '1') ans++;
  cout << ans << endl;
  
} 


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 200000 + 100;
int N, A, B; ll sum = 0ll, minn = 1e10;

void Solve()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i)
	{
		scanf("%d%d", &A, &B), sum += (ll)A;
		if(A > B) minn = min(minn, (ll)B);
	}
	if(minn != 1e10) printf("%lld\n", sum-minn);
	else printf("0\n");
}

int main()
{
	Solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    ll k; cin >> k;
    vi perm(n+1); F0R(i,1,n) cin >> perm[i];
    vector<ll> cost(n+1); F0R(i,1,n) cin >> cost[i];
    ll ans = cost[1];
    F0R(i,1,n){
        int sz = 0;
        int cur = i;
        vector<ll> pre,best; pre.push_back(0); best.push_back(0);
        while(1){
            sz++;
            pre.push_back(pre[sz-1]+cost[cur]);
            if(sz == 1) best.push_back(pre[sz]);
            else best.push_back(max(best[sz-1],pre[sz]));
            cur = perm[cur];
            if(cur == i) break;
        }
        ll nk = k%sz;
        if(pre[sz] > 0 && k >= sz){
            ll times = k/sz;
            ans = max(ans,times*pre[sz] + max(0LL,best[nk]));
            ans = max(ans,(times-1LL)*pre[sz] + best[sz]);
        }else{
            if(k >= sz) ans = max(ans,best[sz]);
            else ans = max(ans,best[k]);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;
const int MOD=1000000007;
int n;
vector <int> a,b;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    a.resize(n);
    b.resize(n);
    for (int i=0;i<n;++i)
        cin >> a[i] >> b[i];

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    if (n&1)
    {
        int meda,medb;
        meda = a[n/2];
        medb = b[n/2];
        cout << medb-meda+1;
    }
    else
    {
        int meda,medb;
        meda = (a[n/2 - 1] + a[n/2]);
        medb = (b[n/2 - 1] + b[n/2]);
        cout << (medb-meda) + 1;
    }
    return 0;
}


Measured memory_bytes: 6364
#include <iostream>
#include <string.h>
#include<algorithm>
#include<math.h>

using namespace std;

int main()
{
	int N, M, A[101],SUM=0,count=0;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		SUM += A[i];
	}
	for (int j = 0; j < N; j++) {
		if (4 * M * A[j] >= SUM)count++;
	}
	if (count >= M)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    ll k = a + b;
    ll cou = n / k;
    ll ans = cou * a;

    if(n % k != 0){
        n -= k * cou;
        if(n >= a){
            ans += a;
        }else{
            ans += n;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N;
    cin >> N;
    vector<vector<ll>> nodes(N, vector<ll>{});
    for (auto &&i: boost::irange(0LL, N - 1)) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        nodes.at(a).emplace_back(b);
        swap(a, b);
        nodes.at(a).emplace_back(b);
    }
    vector<ll> distance_from_0(N, numeric_limits<ll>::max());
    deque<ll> q{};
    q.emplace_back(0LL);
    distance_from_0.at(0) = 0;
    while (!q.empty()) {
        ll now = q.front();
        q.pop_front();
        for (auto &&next: nodes.at(now)) {
            if (distance_from_0.at(next) == numeric_limits<ll>::max()) {
                distance_from_0.at(next) = distance_from_0.at(now) + 1;
                q.emplace_back(next);
            }
        }
    }
    vector<ll> distance_from_last(N, numeric_limits<ll>::max());
    q.emplace_back(N - 1);
    distance_from_last.back() = 0;
    while (!q.empty()) {
        ll now = q.front();
        q.pop_front();
        for (auto &&next: nodes.at(now)) {
            if (distance_from_last.at(next) == numeric_limits<ll>::max()) {
                distance_from_last.at(next) = distance_from_last.at(now) + 1;
                q.emplace_back(next);
            }
        }
    }
    ll count_f{0};
    ll count_s{0};
//    for (auto &&i: boost::irange(0LL, N)){
//        cout << i << " " << distance_from_0.at(i) << " " << distance_from_last.at(i) << endl;
//    }
    for (auto &&i: boost::irange(0LL, N)) {
        if (distance_from_0.at(i) <= distance_from_last.at(i)) {
            count_f++;
        } else {
            count_s++;
        }
    }
    if (count_f > count_s) {
        cout << "Fennec";
    } else {
        cout << "Snuke";
    }
    return 0;
}

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

#define int long long
#define REP(i, l, r) REPEAT(i,l,r,true) // [l, r)
#define rep(i, n) REP(i,0,n)           // [0, n)
#define REPEAT(i, l, r, condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n, l, r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...) true
#define showlr(n,l,r) true
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int, int>;

struct io {
    io() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.tie(0);
        cout << fixed << setprecision(20);
    }
} io;

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &e:v)is >> e;
    return is;
}

template<class T>
ostream &operator<<(ostream &os, vector<T> v) {
    os << "{";
    for (T &e:v)os << e << (v.size() - (int) (&e - &v[0]) > 1 ? ", " : "");
    os << "}";
    return os;
}

void _DEBUG() {}

template<typename H, typename... T>
void _DEBUG(H a, T...b) {
    cerr << a << (sizeof...(b) ? "," : "\n");
    _DEBUG(b...);
}

inline void in() {}

template<typename H, typename... T>
void in(H &a, T &... b) {
    cin >> a;
    in(b...);
}

inline void out() {}

template<typename H, typename... T>
void out(H a, T... b) {
    cout << a << (sizeof...(b) ? " " : "\n");
    out(b...);
}

template<class T>
void resz(int n, T &v) { v.resize(n); }

template<class H, class... T>
void resz(int n, H &a, T &... b) {
    a.resize(n);
    resz(n, b...);
}

template<typename V, typename H>
void resize(vector<V> &v, const H a) { v.resize(a); }

template<typename V, typename H, typename... T>
void resize(vector<V> &v, const H &a, const T... b) {
    v.resize(a);
    for (auto &v:v) resize(v, b...);
}

const int INF = 1LL << 55;
const int MOD = 1000000007;
const double EPS = 1e-8;

/*------------end of definitions------------*/

int N;
vector<string> V;
int ans;

signed main() {

    in(N);
    V.resize(N);
    rep(i, N) {
        string S;
        in(S);
        sort(all(S));
        V[i] = S;
    }
    sort(all(V));
    int left = 0, right = 0;
    while (left < N) {
        while (right < N && V[left] == V[right]) {
            right++;
        }
        show(left, right);
        ans += (right - left) * (right - left - 1) / 2;
        left = right;
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 5760
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define MAXN 1000006
using namespace std;
int n;
long long A,B,C,D;
long long gcd(long long a,long long b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
		if(A<B) printf("No\n");
		else if(D<B) printf("No\n");
		else if(C>=B) printf("Yes\n");
		else
		{
			long long g=gcd(B,D);
			//printf("\n%lld  !!!",g);
			//long long X=((A-C-1)%B+B)%B;
			//long long Y=((A-B)%B+B)%B;
			long long X=A-C-1;
			long long Y=A-B;
			if(X/g>Y/g) printf("No\n");
			else printf("Yes\n");
		}
	}
}

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

#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) x.find( y ) != x.end()
#define pb push_back

signed main(){
	int L, R, d, c = 0 ;
	cin >> L >> R >> d ;
	cout << R / d - (L-1) / d ;
	return 0 ;
}

Measured memory_bytes: 3568
from itertools import product
ABCD = list(input())
ops = ['+', '-']

for op in list(product(ops, ops, ops)) :
    if eval(ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3]) == 7 :
        print(str(ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3])+'=7')
        break


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

#include <atcoder/fenwicktree>
using namespace atcoder;

using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  fenwick_tree<ll> fw(n);
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    fw.add(i, ai);
  }
  while (q--) {
    int op;
    cin >> op;
    if (op == 0) {
      int p, x;
      cin >> p >> x;
      fw.add(p, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << fw.sum(l, r) << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 8244
n = int(input())
actions = []
for _ in range(n):
    actions.append(list(map(int, input().split())))

dp = []
for i in range(n + 1):
    dp.append([0] * 3)

for i in range(0, n):
    for j in range(3):
        for k in range(3):
            if j == k: continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + actions[i][k])

print(max(dp[n]))


Measured memory_bytes: 47332
s = int(input())
h = s//100
l = s%100
# print(h,l)

def check_month(i):
    if i <= 12 and i >= 1:
        return True
    else:
        return False

def check_year(i):
    return True
    # if i != 0:
    #     return True
    # else:
    #     return False

ym = check_year(h) and check_month(l)
my = check_month(h) and check_year(l)

if ym and my:
    print("AMBIGUOUS")
elif ym and not my:
    print("YYMM")
elif not ym and my:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
	int N;
	int d[100] = { 0 };
	long long count[100][21];
	int i, j;
	for (i = 0; i < 100; i++){
		for (j = 0; j < 21; j++){
			count[i][j] = 0;
		}
	}
	scanf("%d", &N);
	for (i = 0; i < N; i++){
		scanf("%d", &d[i]);
	}
	count[0][d[0]] = 1;
	for (i = 1; i < N-1; i++){
		for (j = 0; j < 21; j++){
			if (count[i - 1][j] != 0){
				if (j + d[i] <= 20){//20??\????????´???
					count[i][j + d[i]] += count[i - 1][j];//????????´???
				}
				if (j - d[i]>= 0){//0??\????????´???
					count[i][j - d[i]] += count[i - 1][j];//?¶??????´???
				}
			}
		}
	}
	printf("%lld\n", count[N - 2][d[N - 1]]);//???????????????
	return 0;
}

Measured memory_bytes: 2752
N = int(input())
h = list(map(int,input().split()))

dp = [0,abs(h[0]-h[1])]
for i in range(2,N):
  dp.append(min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i])))
print(dp[N-1])

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

const int maxn=10000000+7;
const int mod=998244353;
int inv[maxn];
int finv[maxn];
int fpow[maxn];
int fthe[maxn];
int ftwo[maxn];
int n;

int comb(int a,int b){
    return (1ll*fpow[a]*finv[a-b]%mod*finv[b]%mod)%mod;
}

int main(){
    fpow[0]=fpow[1]=1;
    inv[1]=finv[1]=1;
    inv[0]=finv[0]=1;
    fthe[0]=1;fthe[1]=3;
    ftwo[0]=1,ftwo[1]=2;
    for(int i=2;i<maxn;i++){
        inv[i]=(1ll*(mod-mod/i)*inv[mod%i])%mod;
        finv[i]=(1ll*finv[i-1]*inv[i])%mod;
        fpow[i]=(1ll*fpow[i-1]*i)%mod;
        fthe[i]=(1ll*fthe[i-1]*3)%mod;
        ftwo[i]=(1ll*ftwo[i-1]*2)%mod;
    }
    scanf("%d",&n);
    int p=n>>1;
    int ans=0;
    for(int i=p+1;i<=n;i++){
        ans=(1ll*ans+1ll*2*comb(n,i)*ftwo[n-i]%mod)%mod;
        //cout<<comb(n,i)<<" "<<ftwo[n-i]<<endl;
    }
    ans=(1ll*fthe[n]-1ll*ans+1ll*mod)%mod;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 195584
#include <iostream>
#include <vector>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <climits>

using namespace std;

int main(){
    
    long long N, M, X;
    cin >> N >> M >> X;
    vector<long long> C(N);
    vector<vector<long long>> A (N, vector<long long>(M));
    for(int i = 0; i < N; i++){
        cin >> C[i];
        for(int j = 0; j < M; j++){
            cin >> A[i][j];
        }
    }
    
    bool count = false;
    long long ans = LONG_MAX;

    for(int tmp = 0; tmp < (1 << 12); tmp++){
        vector<long long> K(M,X);
        bool b = true;
        long long sum = 0;
        bitset<12> s(tmp);
        
        for(int i = 0; i < N; i++){
            if(s.test(i)){
                sum += C[i];
                for(int j = 0; j < M; j++){
                    K[j] -= A[i][j];

                }
            }
        }
        
        for(int j = 0; j < M; j++){
            if(K[j] > 0) b = false;
        }
        
        if(b){
            count = true;
            ans = min(sum,ans);
        }
    }
    if(count){
        cout << ans << endl;
    }
    else{
        cout << -1 << endl;
    }

}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

vi v[16];
int p[16];

int main(){
	int n, m; scanf("%d%d", &n, &m);
	REP(i, m){
		int k; scanf("%d", &k);
		REP(j, k){
			int a; scanf("%d", &a);
			v[i].EB(a-1);
		}
	}
	REP(i, m) scanf("%d", p+i);

	int ans = 0;
	REP(i, 1<<n){
		bool ok = true;
		REP(j, m){
			int q = 0;
			for(int &k:v[j]) if(i&(1<<k)) q++;
			if(q%2!=p[j]) ok=false;
		}
		if(ok) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
# A - Grouping 2
# ある学校に N 人の生徒がいる
# なるべく多く 3人 以上のグループにしたい！
# 3人以上のグループを 最大で x 個 作れるときの x の値を出力する

# 生徒数 N （整数） を入力
N = int(input())
# print(N)

# # N を 3 で割った余りで 計算する
# if 及び % を使わずに再現
answer = int(N / 3)


# 結果の表示
print(answer)


Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N=3005,inf=0x3f3f3f3f;
const ld PI=3.1415926535897932384626;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,L,a[N];
ld b[N],ansx,ansy;
int main(){
//	freopen("balance.in","r",stdin);
//	freopen("balance.out","w",stdout);
	n=read();L=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++){
		ansx+=(n+i*2-j*2)*cos(PI*(a[i]+a[j])/L);
		ansy+=(n+i*2-j*2)*sin(PI*(a[i]+a[j])/L);
	}
	ll s=(ll)n*(n-1)*(n-2)/6;
	ansx/=s;ansy/=s;
	printf("%.16Lf %.16Lf\n",ansx,ansy);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){
	int n, m, i, c;
	int pnum;
	int player[1001];/*1..exist  0...none*/
	while(1){
		scanf("%d%d",&n, &m);
		if(n == 0 && m == 0){
			break;
		}
		for(i = 0; i < 1001; i++){
			player[i] = 1;
		}
		c = n;
		for(pnum = n; pnum >= 1; pnum--){
			for(i = 0; i < m; i++){
				while(1){
					c++;
					c %= n;
					if(c == 0){c = n;}
					if(player[c]){
						break;
					}
				}
			}
			player[c] = 0;
		}
		printf("%d\n",c);
	}

	return 0;
}

Measured memory_bytes: 408
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
#include <atcoder/all>


using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


#define REP(i, n) for(ll i = 0; i < n; i++)





















int main(){
    ll n, Q;
    cin >> n >> Q;
    vector<ll> a(n);
    fenwick_tree<ll> tw(n);
    REP(i, n){
        cin >> a[i];
        tw.add(i, a[i]);
    }
    REP(i, Q){
        ll q;
        cin >> q;
        if(q == 0){
            ll p, x;
            cin >> p >> x;
            tw.add(p, x);
        }
        else{
            ll l, r;
            cin >> l >> r;
            cout << tw.sum(l, r) << endl;
        }
    }
}

Measured memory_bytes: 12120
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pp pair<ll,ll>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define mod 1000000007

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<double> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    vector<vector<double>> dp(n+1,vector<double>(n+1,0));  //j heads in i tosses
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j==0) dp[i][j]=(1.0-arr[i-1])*dp[i-1][j];
            else dp[i][j]=(arr[i-1]*dp[i-1][j-1])+((1.0-arr[i-1])*dp[i-1][j]);
        }
    }
    double ans=0;
    for(int i=ceil(n/2.0);i<=n;i++){
        ans+=dp[n][i];
    }
    cout<< fixed << setprecision(9)<<ans;
}

Measured memory_bytes: 70656
from sys import stdin

n,q = map(int,input().split(" "))

list2 = [[] for _ in range(n)]

for i in range(q):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		list2[int(cmd[1])].append(cmd[2])
	elif cmd[0] == "1":
		print(*list2[int(cmd[1])])
	else:
		list2[int(cmd[1])].clear()
		



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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
const int inf = 5000;
void solve() {	
	int l, r;
	cin >> l >> r;
	if (r - l >= 2025) {
		cout << 0;
		return;
	}
	int mn = inf;
	for (int i = l; i <= r; ++i) {
		for (int j = i + 1; j <= r; ++j) {
			mn = min(mn, (i * j) % 2019);
		}
	}
	cout << mn;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

int both;
int atail, bhead;
int poe;

int main(void) {
    int n;
    scanf("%d",&n);
    char s[20];
    for(int i=0; i<n; i++) {
        scanf("%s", s);
        if(s[0] == 'B') bhead++;
        if(s[strlen(s)-1] == 'A') atail++;
        if(s[0] == 'B' && s[strlen(s)-1] == 'A') both++;

        for(int i=0; s[i+1]; i++)
            if(s[i]=='A' && s[i+1]=='B') poe++;
    }
    if(both == atail && both == bhead && both > 0) poe += both-1;
    else {
        if(bhead < atail) poe += bhead;
        else poe += atail;
    }
    printf("%d\n", poe);
}

Measured memory_bytes: 128
p=[1]
b=[1]
for i in range(50):
    p.append(p[i]*2+1)
    b.append(b[i]*2+3)
def main(n,x):
    if n==0:
        if x==1:
            return 1
        return 0
    if b[n]==x:
        return p[n]
    if b[n-1]+1>=x:
        return main(n-1,x-1)
    else:
        return main(n-1,x-b[n-1]-2)+1+p[n-1]
n,x=map(int,input().split())
print(main(n,x))

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
using namespace std;
const int maxn = 100100;
int n;
int a[maxn], sa[maxn], b[maxn];
int bit[maxn * 2];
void add(int x, int d){
	for(x += maxn; x < maxn * 2; x += x & -x) bit[x] += d;
}
int rec(int x){
	int r = 0;
	for(x += maxn; x; x -= x & - x) r += bit[x];
	return r;
}
long long count(int x){
	memset(bit, 0, sizeof(bit));
	for(int e = 0; e < n; e++){
		if(a[e] <= x) b[e] = -1;
		else b[e] = 1;
	}
	int sa = 0;
	add(0, 1);
	long long res = 0;
	int sar = 0;
	for(int e = 0; e < n; e++){
		sar += b[e];
		int tr = rec(n + 1) - rec(sar);
		res += tr;
		add(sar, 1);
	}
	return res;
}
int main(){
	cin >> n;
	for(int e = 0; e < n; e++) cin >> a[e];
	for(int e = 0; e < n; e++) sa[e] = a[e];
	sort(sa, sa + n);
	int lo = 0, hi = n - 1, ans = -1;
	long long need = (1ll * n * (n + 1)) / 2;
	while(lo <= hi){
		int mid = (lo + hi)/2;
		long long val = count(sa[mid]);
		// cout << sa[mid] << " " << val << endl;
		if( - val + (need - val) < 0) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	cout << sa[ans] << endl;
	return 0;
}


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

int main()
{
  int N, Na, t = 0;
  cin >> N;
  Na = N;
  while (Na > 0)
  {
    t += Na % 10;
    Na /= 10;
  }
  if (N % t == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<math.h>
using namespace std;
int main(){
  /*
  int a,b;
  cin>>a>>b;
  if(a>8||b>8){
    cout<<":("<<endl;
  }
  else{
    cout<<"Yay!"<<endl;
  }
  */
  //int a,b,tmp1,tmp2=0;
  //cin>>a>>b;
  /*
  int i=0,check=0;
  while(1){
    i++;
    if((i%100)%100==0&&(i/100)/100!=0){
      check++;
    }
    if(check==b){
      cout<<i<<endl;
      break;
    }
  }
  */
  /*
  if(b==100&&a==0){
    tmp2=101;
  }
  else if(b==100&&a==1){
    tmp2=10100;
  }
  else if(b==100&&a==2){
    tmp2=1010000;
  }
  else{
    tmp1=pow(100,a);
    for(int i=1;i<=b;i++){
        tmp1=pow(100,a);
        tmp2=i*tmp1;
        //cout<<tmp2<<endl;
    }
  }
  cout<<tmp2<<endl;
  */
  /*
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]%2==0){
    }
  }
  int kisuu[n];
  for(int i=0;i<n;i++){
    if(a[i]%2==0){
      kisuu[i]=0;
    }
    else{
      kisuu[i]=1;
    }
    //cout<<kisuu[i]<<endl;
  }
  for(int i=n;i>0;i--){
    if(kisuu[i]==0){
      a[i]=a[i]/2;
    }
  }
  */
  int n;
  cin>>n;
  long long a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int c=0;
  for(int i=0;i<n;i++){
    while(1){
      if(a[i]%2==0){
        a[i]=a[i]/2;
        c++;
      }
      else{
        break;
      }
    }
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 384
from sys import stdin

def main():
    S = input()

    l = len(S)
    ans = 'NO'
    for i in range(7, -1, -1):
        j = l - (7 - i)
        if S[:i] + S[j:] == 'keyence':
            ans = 'YES'
    print(ans)

input = lambda: stdin.readline().rstrip()
main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<long long> A(3);
    cin >> A.at(0) >> A.at(1) >> A.at(2);
    if(A.at(0)%2==0||A.at(1)%2==0||A.at(2)%2==0)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    long long chk=A.at(0)/2;
    cout << abs(A.at(1)*A.at(2)*chk-A.at(1)*A.at(2)*(A.at(0)-chk));
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
int mod = 1e9 + 7;

signed main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N), F(N);
    cin >> A >> F;
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    int left = -1, right = 1e12 + 100;
    while (left + 1 < right) {
        int c = (left + right) / 2;
        bool check = [&] {
            int temp = 0;
            rep(i, N) {
                temp += max(0LL, A[i] - c / F[i]);
            }
            return temp <= K;
        }();
        if (check) right = c;
        else left = c;
    }
    cout << right << endl;
    return 0;
}





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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

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

    cin>>n;
    cout<<!n<<'\n';
    
    return 0;
}

Measured memory_bytes: 3604
import fractions
a, b, c, d = map(int, input().split())

def lcm(x: int, y: int) -> int:
    return (x*y)//fractions.gcd(x, y)

def calc(n: int, a: int, b: int) -> int:
    return n - (n//a + n//b - n//(lcm(a, b)))

print(calc(b, c, d) - calc(a-1, c, d))


Measured memory_bytes: 5052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        int m = ni();

        int[] x = new int[m];
        int[] y = new int[m];
        for (int i = 0; i < m; i++) {
            x[i] = ni() - 1;
            y[i] = ni() - 1;
        }

        int[] cnt = new int[n];
        Arrays.fill(cnt, 1);
        boolean[] can = new boolean[n];
        can[0] = true;

        for (int i = 0; i < m; i++) {
            if (can[x[i]]) can[y[i]] = true;
            cnt[x[i]]--;
            if (cnt[x[i]] == 0) can[x[i]] = false;
            cnt[y[i]]++;
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (can[i]) ans++;
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 28240
x,y = map(int, input().split())
a = {4,6,9,11}
b = {1,3,5,7,8,10,12}
if x==y==2:
    print('Yes')
elif x in a and y in a:
    print('Yes')
elif x in b and y in b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
	int N,right=0,left=0;
	cin >> N;
	char a[N+10];
	for(int i=0; i<N; i++){
		cin >> a[i];
	}for(int i=0; i<N; i++){
		if(a[i]=='('){
			left+=1;
		}else{
			if(left==0){
				right+=1;
			}else{
				left-=1;
			}
		}
	}
	for(int i=0; i<right; i++){
		cout << "(";
	}
	for(int i=0; i<N; i++){
		cout << a[i];
	}
	for(int i=0; i<left; i++){
		cout << ')';
	}
	cout << endl;
}

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

#define REP(i, n) for (int i = 0; i < (int)n; i++)

using namespace std;
using ll = long long;

void InsertionSort(int *A, int n, int *cnt, int h = 1) {
  for (int i = h; i < n; i++) {
    int v = A[i];
    int j = i - h;
    while (j >= 0 && A[j] > v) {
      A[j + h] = A[j];
      j = j - h;
      *cnt += 1;
    }
    A[j + h] = v;
  }
}

void ShellSort(int *A, int n) {
  int h[n / 3 + 1], i = 0;
  h[0] = 1;
  REP(_, n) {
    int v = 3 * h[i] + 1;
    if (v < n) {
      h[++i] = v;
    }
  }

  cout << i + 1 << endl;
  for (int j = i; j >= 0; j--) {
    cout << h[j];
    if (j != 0) cout << " ";
  }
  cout << endl;

  int cnt = 0;
  for (i; i >= 0; i--) {
    InsertionSort(A, n, &cnt, h[i]);
  }
  cout << cnt << endl;
}

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

  int A[n];
  REP(i, n) cin >> A[i];

  ShellSort(A, n);

  REP(i, n) cout << A[i] << endl;

  return 0;
}



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

int main(void){
    int n;
    while(cin>>n,n!=0){
        map<int, valarray<int>> lg;
        map<int,int> ans;
        int mm,dd,h,m,id,yesterday=0;
        rep(ln,n+1){
            char c;
            if(ln!=n)scanf("%d/%d %d:%d %c %d",&mm,&dd,&h,&m,&c,&id);
            if((yesterday!=0 && yesterday!=mm*100+dd) || ln==n){
                if(lg.find(0)!=lg.end()){
                    for(auto p:lg){
                        if(p.first==0) continue;
                        valarray<int> q=p.second+lg[0];
                        partial_sum(begin(q),end(q),begin(q));
                        ans[p.first]+=q.apply([](int x){return x==2?1:0;}).sum();
                    }
                }
                lg.clear();
                yesterday=0;
            }
            yesterday=mm*100+dd;
            if(lg.find(id)==lg.end()){
                lg[id]=valarray<int>(0,1441);
            }
            lg[id][h*60+m]+=(c=='I'?1:-1);
        }
        int avl=0;
        for(auto i:ans){
            avl=max(avl,i.second);
        }
        cout<<avl<<endl;
    }
}

Measured memory_bytes: 5812
#include <stdio.h>
int main(){
  char a[6];
  scanf("%s",a);
  for(int i=0;i<5;i++){
    if(a[i]=='A'&&a[i+1]=='C'){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
int Mod;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b){ return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
void Add(int &a, int b){ a = add(a,b); }
void Mul(int &a, int b){ a = mul(a,b); }
void Dec(int &a, int b){ a = dec(a,b); }
cs int N = 205;
int n, K, C[N][N], fc[N];
void fc_init(int n){
	fc[0]=fc[1]=1;
	for(int i=2; i<=n; i++)fc[i]=mul(fc[i-1],i);
	for(int i=0; i<=n; i++)C[i][0]=1;
	for(int i=1; i<=n; i++)
	for(int j=1; j<=i; j++)
	C[i][j]=add(C[i-1][j-1],C[i-1][j]);
}
int cope(int k, int l, int lm){
	static int dp[N][N];
	for(int i=0; i<=l; i++)
	for(int j=0; j<=k; j++)dp[i][j]=0;
	dp[1][0]=1;
	for(int i=1; i<=l; i++){
		for(int j=0; j<=k; j++){
			if(j)Add(dp[i][j],dp[i][j-1]);
			Add(dp[i][j],dp[i-1][j]);
			if(j&&l-i+j-1>lm)dp[i][j]=0;
		} for(int j=0; j<=k; j++)
		if(k-j+i-1>lm)dp[i][j]=0;
	} int ans = 0;
	for(int i=1; i<=k; i++)
	Add(ans,dp[l][i]); 
	return ans;
}
int work(int n, int k){
	if(n==0) return 1;
	if(n==1) return 0; 
	if(k<=0) return 0;
	int ans = 0;
	for(int i=0,coe; i<=k&&i<n; i++){
		coe=mul(C[n-1][i],mul(fc[i],fc[n-i-1]));
		Add(ans, mul(coe,cope(i,n-i-1,k-1)));
	} return ans;
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d%d%d",&n,&K,&Mod);
	fc_init(n); int ans = 0;
	for(int i=0; i<=K+1; i++){
		Add(ans, mul(mul(C[n][i],fc[i]),work(n-i,K-i)));
	} cout << ans; return 0;
} 

Measured memory_bytes: 4092
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

#define MAX 1000
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

int w,h;
int  b[64][64];

void clustering(int x, int y, char num){
  if(b[y][x] == 0) return;

  b[y][x] = 0;

  REP(i,3) REP(j,3){
    int xx = x + j - 1;
    int yy = y + i - 1;
    if(xx >= 0 && xx <= w-1 && yy >= 0 && yy <= h-1)
      clustering(xx, yy, num);
  }
}

int main(){
  while(scanf("%d%d",&w,&h), w+h){
    int cl = 0;
    REP(i,h) REP(j,w) scanf("%d", &b[i][j]);
    REP(i,h) REP(j,w){
      if(b[i][j] == 1){
        clustering(j,i,b[i][j]);
        cl++;
      }
    }
    printf("%d\n",cl);
  }
  return 0;
}

Measured memory_bytes: 0
class Unionfindtree:
    def __init__(self,number):
        self.par = [i for i in range(number)]
        self.rank = [0]*(number)

    def find(self,x):#親を探す xの親を示す
        if self.par[x] ==x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self,x,y):#x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return 
        if self.rank[px]<self.rank[py]:
            self.par[px]=py
        else:
            self.par[py]=px
        if self.rank[px]==self.rank[py]:
            self.rank[px] +=1
    
    def connect(self,x,y):#親が同じかみる
        return self.find(x)==self.find(y)

N,M=map(int,input().split())
table=[]
for i in range(M):
    a,b=map(int,input().split())
    table.append([a-1,b-1])
ans =0
for i in range(M):
    K=Unionfindtree(N)
    for j in range(M):
        if i==j:
            continue
        a,b=table[j]
        K.union(a,b)
    flag=False
    for k in range(1,N):
        if not K.connect(0,k):
            flag=True
    if flag:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n, h, i, k, count = 0, max = 0;
  scanf("%d", &n);
  scanf("%d", &k);
  for(i = 1; i < n; ++i){
    scanf("%d", &h);
    if(k >= h) count++;
    else {
      if(max < count) max = count;
      count = 0;
    }
    k = h;
  }
  if(max < count) max = count;
  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 128
N = int(input())
S = [input() for i in range(N)]
c0, c1, c2, c3 = 0, 0, 0, 0
for i in S:
    if i == 'AC':
        c0 += 1 
    if i == 'WA':
        c1 += 1
    if i == 'TLE':
        c2 += 1
    if i == 'RE':
        c3 += 1
print('AC','x',c0)
print('WA','x',c1)
print('TLE','x',c2)
print('RE','x',c3)

Measured memory_bytes: 16164
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
	static double EPS = 0.0000000001;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int g = scan.nextInt();
		Polygon pol = new Polygon();
		for (int i=0;i<g;i++) {
			pol.add(new Point(scan.nextInt(),scan.nextInt()));
		}
		int q = scan.nextInt();
		for (int i=0;i<q;i++) {
			System.out.println(contains(pol, new Point(scan.nextInt(),scan.nextInt())));
		}
	}
	static int contains(Polygon poly, Point p) {
		int nCross=0;
		for (int i=0;i<poly.size();i++) {
			Vector a = poly.get(i).diff(p); 
			Vector b = poly.get((i+1)%poly.size()).diff(p); 
			if (Math.abs(a.crossProduct(b))<EPS && a.dotProduct(b)<EPS) return 1;// 1:on
			if (a.y>b.y){Vector tmp=a;a=b;b=tmp;}
			if (a.y<EPS && b.y>EPS && a.crossProduct(b)>EPS) nCross++;
		}
		return nCross%2==1 ? 2 : 0;// 2:in, 0:out
	}


}
class Point {
	static double EPS = 0.0000000001;
	double x; double y;
	public Point(double ax, double ay){x=ax;y=ay;}
	public Vector sum(Point p) { return new Vector(x+p.x,y+p.y); }
	public Vector diff(Point p) { return new Vector(x-p.x,y-p.y); }
	public Vector mult(double k) { return new Vector(x*k,y*k); }
	public Vector div(double k) { return new Vector(x*(1.0/k),y*(1.0/k)); }
	public boolean equals(Point p){return Math.abs(x-p.x)<EPS && Math.abs(y-p.y)<EPS;}
	public String toString(){return "("+x+","+y+")";}
}
class Vector extends Point {
	public Vector(double ax, double ay) {super(ax,ay);}
	public Vector(Point p1, Point p2) {super(p1.x-p2.x,p2.x-p2.y);}
	public double norm() {return x*x+y*y;}
	public double abs() {return Math.sqrt(norm());}
	// TODO:
	public boolean isSmallerThan(Vector v) {return x!=v.x?x<v.x:y<v.y;}
	public double dotProduct(Vector v) {return x*v.x+y*v.y;}
	public double crossProduct(Vector v) {return x*v.y - y*v.x;}
}

class Segment {
	Point p1; Point p2;
	public Segment(Point ap1, Point ap2){p1=ap1;p2=ap2;}
	public double dotProduct(Segment s) {return (p1.x-p2.x)*(s.p1.x-s.p2.x)+(p1.y-p2.y)*(s.p1.y-s.p2.y);}
	public double crossProduct(Segment s) {return (p1.x-p2.x)*(s.p1.y-s.p2.y) - (p1.y-p2.y)*(s.p1.x-s.p2.x);}
	public String toString(){return p1.toString()+"->"+p2.toString();}
	public Line toLine() {return new Line(p1,p2);}
}
class Line extends Segment{public Line(Point ap1, Point ap2){super(ap1,ap2);}}

class Circle {Point c;double r;Circle(Point ac, double ar){c=ac;r=ar;}public String toString(){return "c:"+c.toString()+",r:"+r;}}
class Polygon extends ArrayList<Point>{}

Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

signed main()
{
  string S;
  bool izryt = false, flag = true;
  stack < char > st;
  
  while(getline(cin, S), izryt || S != ".") {
    izryt = true;
    Rep(i, S.size()) {
      if(S[i] == '.' && i == (int)S.size() - 1) {
	izryt = false;
      } else if(S[i] == '(' || S[i] == '[') {
	st.push(S[i]);
      } else if(S[i] == ')' || S[i] == ']') {
	if(!st.empty() && (S[i] == ')' && st.top() == '(' || S[i] == ']' && st.top() == '[')) {
	  st.pop();
	} else {
	  flag = false;
	}
      }
    }
    if(!izryt) {
      if(flag && st.empty()) cout << "yes" << endl;
      else cout << "no" << endl;

      while(!st.empty()) {
	st.pop();
      }
      flag = true;
    }
  }

  return 0;
}

Measured memory_bytes: 3160
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    M,K=map(int,input().split())
    if K>2**M-1:
        print(-1)
    elif M==1:
        if K==0:
            print(0,0,1,1)
        else:
            print(-1)
    else:
        ans=[i for i in range(2**M) if i!=K]+[K]+[i for i in range(2**M-1,-1,-1) if i!=K]+[K]
        print(*ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 68608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int s_size = s.size();
    rep(i, s_size){
        if(s[i] + n > 'Z'){
            s[i] = s[i] + n - 'Z' + 'A' - 1;
        }else{
            s[i] = s[i] + n;
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
import sys
arr_3d=[[[0 for r in range(10)] for f in range(3)  ] for b in range (4)]
x=int(sys.stdin.readline())
for i in range(x):
    a,b,c,d=map(int,sys.stdin.readline().split())
    arr_3d[a-1][b-1][c-1]+=d


for b in range(4):
    for f in range(3):
        print (' ', ' '.join(map(str, arr_3d[b][f])), sep='')
    if b < 3:
        print ('#' *20)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256