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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vstr s(h);
    rep(i, h) cin >> s[i];

    vvint ans(h, vint(w));
    int tmp = 0;
    bool first_row_ok = false;
    rep(i, h)
    {
        bool row_ok = false;
        rep(j, w)
        {
            char c = s[i][j];
            if (c == '#')
            {
                ++tmp;
                ans[i][j] = tmp;
                if (!row_ok)
                {
                    for (int k = j - 1; k >= 0; --k)
                    {
                        ans[i][k] = tmp;
                    }
                }
                row_ok = true;
            }
            else
            {
                if (row_ok)
                {
                    ans[i][j] = tmp;
                }
            }
        }
        if (!row_ok)
        {
            if (first_row_ok)
            {
                rep(j, w)
                {
                    ans[i][j] = ans[i - 1][j];
                }
            }
        }
        else
        {
            if (!first_row_ok)
            {
                for (int k = i - 1; k >= 0; --k)
                {
                    rep(j, w)
                    {
                        ans[k][j] = ans[k + 1][j];
                    }
                }
                first_row_ok = true;
            }
        }
    }
    rep(i, h) rep(j, w)
    {
        cout << ans[i][j] << (j == w - 1 ? "\n" : " ");
    }
}

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


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define pi 3.14159
using namespace std;

struct ca
{
  int idx,st,et,aidx;
};

int prime[1000001]={};

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
         
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
  
bool cmp1(ca c1,ca c2)
{
  if(c1.st<c2.st)
   return true;

  if(c1.st==c2.st && c1.idx<c2.idx)
   return true;

  return false;
}

bool cmp2(ca c1,ca c2)
{
  
  if(c1.idx<c2.idx)
  return true;
  return false;
}








int main()
{

  ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   //pr();
  int t;
  // cin>>t;
   t=1;
  int id=1;

  while(t--)
{
  double n;

   cin>>n;
   double ans= (2*pi*n);

    cout<<ans;
   
}



return 0;
}


Measured memory_bytes: 3804
/* -----------------------------------------------
 * Calculate nCr
 * Last update : 2019-11-20
 ------------------------------------------------- */

#include <cstdio>
#include <iostream>
#include <iomanip>

#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;

// 階乗の計算
ll factorial_mod(ll n, ll m) {

  ll num = 1 % m;
  for(int i = n; i >= 1; i--){
    num = (num * i) % m;
  }
  
  return num;
}

// フェルマーの小定理を使って除算を乗算に変換
ll conv_div_mul_mod(ll a, ll m){
  
  ll num = 1 % m;
  // 方法(1) 単純なループ → mが大きいときに時間がかかる
  for (int i = 0; i < m-2; i++) {
    num = (num % m)  * (a % m);
    num = num % m;
  }
  
  return num;
}


// 二分累乗法によって高速にa^n mod mを求める
ll pow_mod(ll a, ll n, ll m) {

  ll res = 1;

  while (n > 0) {
    if (n & 1) res = res * a % m;
    a = a * a % m;
    n = n >> 1;
  }

  return res;

}


int main() {

  // -----------------------------
  // input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  // input
  ll n, a, b;
  cin >> n >> a >> b;

  // mod m
  ll m = 1000000000 + 7;
  //ll m = 13;

  
  //ll com[n];
  //fill(com, com+n, 0);
  
  // -----------------------------

  // nCa, nCb
  
  ll nca = 1;

  for (int i = 0; i < a; i++) {
    nca = (nca * (n-i)) % m;
  }
  
  for (int i = 0; i < a; i++) {
    nca = (nca * pow_mod(i+1, m-2, m) ) %m;
  }
  
  ll ncb = 1;

  for (int i = 0; i < b; i++) {
    ncb = (ncb * (n-i)) % m;
  }
  for (int i = 0; i < b; i++) {
    ncb = (ncb * pow_mod(i+1, m-2, m) ) %m;
  }
  
  // --------------
  
  ll result = pow_mod(2, n, m);

  result = (result - 1) % m;
  if (result < 0) result += m;
  
  result = (result - nca) % m;
  if (result < 0) result += m;

  result = (result - ncb) % m;
  if (result < 0) result += m;

  cout << result << endl;
  

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100000
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[100000];

int main(){
    cin >> n;
    rep(i,n){
        int tmp; cin >> tmp;
        tmp--;
        a[tmp]++;
    }
    ll ans = 0;
    rep(i,100000){
        if(a[i] >= 3){
            if(a[i]%2 == 0){
                ans += a[i]/2-1;
                a[i] = 2;
            } else{
                ans += a[i]/2;
                a[i] = 1;
            }
        }
    }
    ll cnt = 0;
    rep(i,100000){
        if(a[i] == 2) cnt++;
    }
    ans += (cnt+1)/2;
    cout << n-ans*2 << endl;
}



Measured memory_bytes: 640
import collections

N = int(input())
A = tuple(map(int, input().split()))

c = collections.Counter(A)

total = sum([ c[n]*(c[n] -1) //2 for n in c])

for k in range(N):
    n = A[k]
    print( total - c[n]*(c[n]-1) // 2 + (c[n] - 1)*(c[n] -2) //2)



Measured memory_bytes: 97356
A,B,C,X,Y = map(int,input().split())
base = A * X + B * Y
advanse = 0
if X > Y:
	advanse = (C * Y) * 2 + A * (X-Y)
else:
	advanse = (C * X) * 2 + B * (Y-X)
advanse2 = C * max(X,Y) * 2
print(min(base,advanse, advanse2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	ll ans1= 0, ans2 = 0;
	for(int i = 0; ; i++)
	{
		for(int j = 0; ; j++)
		{
			ll y = 100*(i)*a+j*100*b;
			if(y>=f) break;
			for(int k = 0; ; k++)
			{
				for(int h = 0; ; h++)
				{
					ll sugar = c*k+d*h;
					if(y+sugar<=f && (e*y/100)>=sugar)
					{
						if(ans1>0)
						{
							if(((double(100*sugar))/(sugar+y))>((double(100*ans2))/(ans1)))
							{
								ans1 = y+sugar; ans2 = sugar;
								if(sugar==(e*y/100))
								{
									cout<<ans1<<" "<<ans2<<endl;
									exit(0);
								}
							}
						}
						else
						{
							ans1 = y+sugar; ans2 = sugar;
							if(sugar==(e*y/100) && sugar!=0)
							{
								cout<<ans1<<" "<<ans2<<endl;
								exit(0);
							}
						}
					}
					if(sugar>(e*y/100))
						break;
				}
				if(k*c>(e*y/100))
					break;
			}
		}
		if(100*i*a>=f)
			break;
	}
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}

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

int main(){
    int a, b, n;
    cin >> n;
    int cnt=0;
    int flag=0;

    for(int i = 0; i < n; i++){
        cin >> a >> b;
        if(a==b){
            cnt++;
        }else{
            cnt=0;
        }
        if(cnt==3){
            flag=1;
            break;
        }
    }

    if(flag==1){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 3632
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

N  = int(input())
Gb = [ [] for _ in range(N) ]
Gu = [ [] for _ in range(N) ]
Es = {}

for n in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())

    Es[f'{a:06}{b:06}'] = None

    Gb[a].append(b)
    Gb[b].append(a)
    Gu[a].append(b)

colors = list(range(max(map(len, Gb))))

def dfs(base_node, edge_color):
    global Es

    valid_colors = filter(lambda color: color != edge_color, colors)

    for child_node, color in zip(Gu[base_node], valid_colors):
        Es[f'{base_node:06}{child_node:06}'] = color + 1

        dfs(child_node, color)

print(len(colors))

dfs(0, None)

for color in Es.values():
    print(color)

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

int f(string n) {
    int cnt = 0;
    while (n != "6174") {
        sort(n.begin(),n.end());
        int l = stoi(n);
        sort(n.begin(),n.end(), greater<int>());
        int s = stoi(n);
        if (s == l) {
            return -1;
        }
        ostringstream str;
        str << setfill('0') << setw(4) << s-l;
        n = str.str();
        cnt ++;
    }
    return cnt;
}

bool solve() {
    string n; cin >> n;
    if (n == "0000") return false;
    int cnt = f(n);
    if (cnt == -1) cout << "NA" << endl;
    else cout << cnt << endl;

    return true;
}

int main() {
    while (solve()) {}
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define INF 1e9;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
int main(){
	ll a,b;
	cin>>a>>b;
	ll ans=0;
	if(b==1){
		cout<<"0";
		return 0;
	}
	for(ll i=0;;i++){
		if(i==0){
			ans++;
			b-=a;
		}
		else{
			ans++;
			b-=a;
			b++;
		}
		if(b<=0){
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>

int main(){
  int n,k;
  std::cin >> n >> k;
  long long * d = new long long[n]; 
  long long * h = new long long[n]; 
  for(int i=0;i<n;i++){
    std::cin >> h[i];
    d[i] = LLONG_MAX;//INT_MAX;
  }
  
  d[0] = 0;
  for(int i=1;i<n;i++){
    int s = std::max(0, i-k);
    for(int j=s;j<i;j++)
	  d[i] = std::min(d[i], std::abs(h[i]-h[j])+d[j]);
  }
  
  std::cout << d[n-1];
  
  delete h;
  delete d;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("O3")  
#define pb push_back
#define F first
#define S second
using ll = long long;
using namespace std;



void solve(){
	   int n;
	   cin>>n;
	   int ans=(((n+999)/1000)*1000) - n;
	   cout<<ans<<'\n';
	
	






	
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}






Measured memory_bytes: 3592
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 8888;

bool can(vector<int> dst, int goal, bool bgn) {
    bitset<2 * N> used;
    used.set(N);
    for (int x : dst) {
        if (bgn) {
            used <<= x;
            bgn = false;
            continue;
        }
        used = (used << x) | (used >> x);
    }
    return used[N + goal];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    string s;
    cin >> s;
    vector<vector<int>> dst(2);
    int coord = 0, cur = 0;
    for (char c : s) {
        if (c == 'F') ++cur;
        else {
            dst[coord].eb(cur);
            cur = 0;
            coord ^= 1;
        }
    }
    dst[coord].eb(cur);
    int x, y;
    cin >> x >> y;
    cout << (can(dst[0], x, s[0] == 'F') && can(dst[1], y, false) ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 384
import sys
from collections import deque
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = lambda x: sys.stdout.write(str(x))
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = False

def main():

    N = II()
    t = [-1] * N


    E = [  [] for _ in range(N)]
 
    reached = [False] * N
    for _ in range(N-1):
        u,v,w = LMIIS()
        u -=1
        v -=1
        E[u].append((v,w))
        E[v].append((u,w))
    dbg(E)
    t[E[0][0][0]] = 0

     
    # def search(u):
    #     for v,w in E[u]:
    #         if t[v] == -1:
    #             t[v] = t[u] if w % 2 == 0 else t[u]^1
    #             search(v)
                

    # search(E[0][0][0])
    reached = [False] * N
    q = deque()
    q.append(E[0][0][0])
    while q:
        u = q.pop()
        reached[u] = True
        for v,w in E[u]:
            if reached[v] != True and  t[v] == -1:
                t[v] = t[u] if w % 2 == 0 else t[u]^1
                q.append(v)

                



    for i in t:
        write(i)
        write(' ')






    pass
if __name__ == '__main__':
    main()

Measured memory_bytes: 65184
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m, k = map(int, input().split())
uf = UnionFind(n)
from collections import defaultdict
block = defaultdict(int)
uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    block[a-1] -= 1
    block[b-1] -= 1
    uf.union(a-1, b-1)

for _ in range(k):
    c, d = map(int, input().split())
    if uf.same(c-1, d-1):
        block[c-1] -= 1
        block[d-1] -= 1

for i in range(n):
    print(uf.size(i) + block[i] - 1)

Measured memory_bytes: 19028
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
string s;
map<int,int>mm;
int main()
{
    mm[0]=1;
	int inv = 1 ;
    cin >> s;
    int num = 0 ;
    long long ans = 0 ;
    for(int i=s.size()-1;i>=0;i--){
        num = (num+(s[i]-'0')*inv)%2019;
        ans+=mm[num];
        mm[num]++;
		inv = inv*10%2019;
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3736
def main():
    X=int(input())

    flag=0
    for A in range(-118,120):
        for B in range(-119,119):
            if pow(A,5)-pow(B,5)==X:
                print("{} {}".format(A,B))
                flag=1
        if flag==1:
            break
if __name__=="__main__":
    main()

Measured memory_bytes: 9120
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


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

    if(s == INF){
        rep(i,n){
            if(i < k){
                cout << INF << " ";
            }else{
                cout << INF -1<< " ";
            }
        }
    }else{
        rep(i,n){
            if(i < k){
                cout << s << " ";
            }else{
                cout << INF << " ";
            }
            
        }
        cout << endl;
    }    

}


Measured memory_bytes: 1280
// Problem : C - One Quadrillion and One Dalmatians
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	cin>>n;
	string s;
	while(n>0)
	{
		if(n%26==0)
		s+='z',n--;
		else
		s+=(char)(96+n%26);
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout<<s;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define endl "\n"
    #define sz(x) (int)(x).size()
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
/*.....................................................................................................................*/

    ll mod =(ll)1e9+7;
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
    long long binpow(long long x, long long p) 
    {
        if (p == 0) return 1;
    	if (p == 2 || (p & 1)) return mult(x, binpow(x, p - 1));
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
    // bool check(ll x){}
    ll binsearch(ll l,ll r)
    {
        while(l<r)
        {
            ll mid=(l+r)/2;
            // if(check(mid))r=mid;
            // else l=mid+1;
        }
        return l;
    }
    const ll man=(ll)1e3+5;
    vector<ll>adj[man];
    bool vis[man][man];
    ll d[man],depth[man],par[man];
    void addedge(ll u,ll v){adj[u].pb(v);adj[v].pb(u);}
    ll dx[4]={1,-1,0,0};ll dy[4]={0,0,1,-1};
/*........................................................................................................................*/


signed main()/*Check flow...question galat mat padhna */
{
    fast;
    read(x);
    string s;
    cin>>s;
    x%=26;
    for(auto c:s)
    {
        ll a=c-'A';
        a+=x;
        a%=26;
        cout<<(char)('A'+a);
    }
    cout<<endl;
}



Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int dist(pii a, pii b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}

bool is_even(string a){
    
    int len = (int)a.size();
    return (a.substr(0,len/2) == a.substr(len/2,len));
    
}

int main() {
    int n,k;cin>>n>>k;
    vint l(n);cin>>l;
    sort(all(l),greater<int>());
    
    int ans = 0;
    for(auto i=0;i<k;i++){
        ans+=l[i];
    }
    cout << ans << endl;
    
    return 0;
}







Measured memory_bytes: 256
import java.util.*;

@SuppressWarnings("unchecked")

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String[] s = new String[100];
		ArrayList<String> list = new ArrayList<String>();
		PriorityQueue<Integer>[] que = new PriorityQueue[100];
		for(int i=0;i<100;i++){
			que[i] = new PriorityQueue<Integer>();
		}
		
		int k=0;
		String t = "";
		int n = 0;
		while(sc.hasNext()){
			t = sc.next();
			n = sc.nextInt();
			if(list.indexOf(t)==-1){
				list.add(t);
				s[k] = t;
				que[k].add(n);
				k++;
			}else{
				que[list.indexOf(t)].add(n);
			}
		}
		Collections.sort(list);
		
		for(int i=0;i<list.size();i++){
			t = list.get(i);
			System.out.println(t);
			for(int j=0;j<k;j++){
				if(s[j].compareTo(t)==0){
					n = que[j].size();
					for(int p=0;p<n;p++){
						if(p!=0) System.out.print(" ");
						System.out.print(que[j].poll());
					}	
				}
			}
			System.out.println();
		}
	
	}	
}

Measured memory_bytes: 20444
#include <stdio.h>

int main(){
  char ch;
  while(1){
    scanf("%c",&ch);
    if(ch == '\n')break;

    if(isupper(ch)){
      ch=tolower(ch);
    } else if(islower(ch)){
      ch=toupper(ch);
    }
    printf("%c",ch);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let mut s: String = sc.read();

    let patterns = vec!["dream", "dreamer", "erase", "eraser"];
    'again: while s.len() > 0 {
        for &pat in &patterns {
            if s.ends_with(pat) {
                s.truncate(s.len() - pat.len());
                continue 'again;
            }
        }
        println!("NO");
        return;
    }
    println!("YES");
}


Measured memory_bytes: 2284
'use strict';
(function(stdin) {
  //declare function
  function firstTest(array) {
    if (array[0] < 0 || array[1] < 0) {
      return 'F';
    }
    var sum = array[0] + array[1];
    var border = [80, 65, 50, 30, 0];
    var grade = ['A', 'B', 'C', secondTest(array[2]), 'F'];
    for (var i = 0; i < 5; i++) {
      if (sum >= border[i]) {
        return grade[i];
      }
    }
  }

  function secondTest(x) {
    return x >= 50 ? 'C' : 'D';
  }

  //declare variable
  var inputs = stdin.toString().trim().split('\n');
  var clone = inputs.slice(0, inputs.indexOf('-1 -1 -1')).map(function(v) {
    return v.split(' ').map(Number);
  });
  //main
  //display
  console.log(clone.map(firstTest).join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 15532
#include <cstdio>
int n;
int a[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n-1;i++){
		if(a[i]-a[i+1]>=1){
//			printf("No");
//			return 0;
			a[i]--;
			for(int j=i+1;j<=n;j++){
				if(a[j]<a[i]){
					printf("No");
					return 0;
				}
			}
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
int n, x;
map<int, bool>vis;
int main()
{
	cin >> x >> n;
	while (n--)
	{
		int a;
		cin >> a;
		vis[a] = 1;
	}
	if (!vis[x])
	{
		cout << x;
		return 0;
	}
	bool flag = 1;
	int l = x - 1, r = x + 1;
	while (flag)
	{
		if (!vis[l])
		{
			cout << l;
			flag = 0;
		}
		else if (!vis[r])
		{
			cout << r;
			flag = 0;
		}
		else l--, r++;
	}
}

Measured memory_bytes: 3648
fun main(args: Array<String>) {
    val (n, coin) = readLine()!!.split(" ").map(String::toInt)
    var noAnser = true
    loop@for (i in n downTo 0) {
            for (j in (n-i) downTo 0) {
                val z = n-i-j
                if (0 <= z && z <= n) {
                    if (coin == (i*10000 + j*5000 + z*1000)){
                        println("${i} ${j} ${z}")
                        noAnser = false
                        break@loop
                    }       
                } 
            }
        }
    if (noAnser) {
        println("-1 -1 -1")
    }
}

Measured memory_bytes: 38052
#include<stdio.h>
#include<string.h>
int n[7],m[7];
int i,q,j,k,a=0,l;
void dice_S(){
  int tmp;
  tmp = n[2];
  n[2]=n[1];
  n[1]=n[5];
  n[5]=n[6];
  n[6]=tmp;
}
void dice_E()
{
  int tmp;
  tmp = n[6];
  n[6]=n[3];
  n[3]=n[1];
  n[1]=n[4];
  n[4]=tmp;
}
//縦方向，横方向で重複しないようS・Eのみ
int main()
{
  for(i=1; i<=6; i++)
    scanf("%d",&m[i]);
  scanf("%d",&q);
  int top[q],front[q];

  for(i=0; i<q; i++){
    k=0;
    a=0;
    scanf("%d %d",&top[i],&front[i]);
    for(j=1; j<=6; j++)
      n[j]=m[j];//配列の中身を固定

    if(n[1]==top[i]&&n[2]==front[i]){//初期でそろってたらif文を抜けて出力
      k=1;
      printf("%d\n",n[3]);
    }

   if(k==0){//初期でそろってない場合
      for(j=0; j<4; j++){
	for(l=0; l<4; l++){
	  //	  printf("%d %d %d %d %d %d %d %d\n",n[1],n[2],n[3],n[4],n[5],n[6],top[i],front[i]);
	  dice_S();
	  a++;
	  if(n[1]==top[i]&&n[2]==front[i]){
	    k=1;
	    printf("%d\n",n[3]);
	    break;
	  }
	  if(a==4){
	    dice_E();
	    a=0;
	  }
	}
	if(k==1)
	  break;
      }
      //上記でひょうじされない場合（n[5])
      if(k==0){
	dice_S();
	dice_E();
	for(j=0; j<4; j++){
	  dice_S();
	  if(n[1]==top[i]&&n[2]==front[i]){
	    k=1;
	    printf("%d\n",n[3]);
	    break;
	  }
	}
      }
      //n[2]
      if(k==0){
	dice_E();
	dice_E();
	for(j=0; j<4; j++){
	  dice_S();
	  if(n[1]==top[i]&&n[2]==front[i]){
	    k=1;
	    printf("%d\n",n[3]);
	    break;
	  }
	}
      }
   }
  }

return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}










int main() {

	int n,m;
  cin >> n >> m;
  if (n==m) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()
        var l = 1
        var r = N
        repeat(M) {
            val L = sc.next().toInt()
            val R = sc.next().toInt()
            if (l < L) l = L
            if (r > R) r = R
        }
        pw.println(max(0, r - l + 1))
    }
}


Measured memory_bytes: 52796
# include <algorithm>
# include <iostream>
# include <cmath>
# include <string>
# include <vector>
#include <numeric>

typedef long long int ll;
#define rep(i,n) for(ll i=0; i<n; i++)
#define Rep(i,n) for(ll i=1; i<=n; i++)


using namespace std;

int main() {

    ll N,W,a,b,c, wi, vi;
    cin >> N >> W;
    ll w[N+4], v[N+4];
    Rep(i,N){
        cin >> wi >> vi;
        w[i] = wi;
        v[i] = vi;
    }

    ll dp[N+4][W+4];
    rep(i,W+1){
        dp[0][i] = 0;
    }
    Rep(i,N){
        rep(j,W+1){
            if (w[i] <= j){
                dp[i][j] = max (dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    // Rep(i,N){
    //     cout << dp[i][W] << endl;
    // }

    cout << dp[N][W] << endl;

    return 0;
}


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

using lint = long long;
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

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

  lint formar_sums[n + 1];
  priority_queue<lint, vector<lint>, greater<lint>> formar;

  formar_sums[0] = 0;
  for (lint i = 0; i < n; i++) {
    formar.push(a[i]);
    formar_sums[0] += a[i];
  }
  for (lint d = 1; d <= n; d++) {
    formar_sums[d] = formar_sums[d - 1];

    formar_sums[d] += a[n + d - 1];
    formar.push(a[n + d - 1]);
    formar_sums[d] -= formar.top();
    formar.pop();
  }

  lint latter_sums[n + 1];
  priority_queue<lint> latter;

  latter_sums[n] = 0;
  for (lint i = 2 * n; i < 3 * n; i++) {
    latter.push(a[i]);
    latter_sums[n] += a[i];
  }
  for (lint d = n - 1; d >= 0; d--) {
    latter_sums[d] = latter_sums[d + 1];

    latter_sums[d] += a[n + d];
    latter.push(a[n + d]);
    latter_sums[d] -= latter.top();
    latter.pop();
  }

  lint ans = formar_sums[0] - latter_sums[0];
  for (lint d = 1; d <= n; d++) {
    ans = max(ans, formar_sums[d] - latter_sums[d]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5876
#include <cstdio>
#include <cctype>
#include <array>
#include <set>
#include <queue>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int n = 0, c = gcu();
	// bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	return n; }
	// return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
//template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

struct board {
	enum {size = 3};
	struct pos {int r, c;};
	typedef array<array<int, size>, size> arr;
	arr b;
	pos p;
	int cnt = 0;

	void read() {
		for (int i = 0; i < size; i++)
			for (int j = 0; j < size; j++) {
				b[i][j] = in();
				if (!b[i][j])
					p.r = i, p.c = j;
			}
	}
	void print() {
		for (auto &r: b) {
			for (int &c: r)
				out(&c == &r[0]?"":" ", c);
			out('\n');
		}
		out('\n');
	}

	int solver() {
		const arr end = {1, 2, 3, 4, 5, 6, 7, 8, 0};
		set<arr> m;
		queue<board> q;
		q.push(*this);
		while (!q.empty()) {
			board a = q.front();
			q.pop();
			if (a.b == end)
				return a.cnt;
			auto it = m.find(a.b);
			if (it != m.end())
				continue;
			m.insert(a.b);
			pos to[] = {
				a.p.r + 1, a.p.c,
				a.p.r, a.p.c + 1,
				a.p.r - 1, a.p.c,
				a.p.r, a.p.c - 1
			};
			for (pos o: to) {
				if (0 <= o.r && o.r < size && 0 <= o.c && o.c < size) {
					board c = a;
					swap(c.b[a.p.r][a.p.c], c.b[o.r][o.c]);
					c.p = o;
					c.cnt = a.cnt + 1;
					q.push(c);
				}
			}
		}
		return -1;
	}
};

int main() {
	board b;
	b.read();
	out(b.solver(), '\n');
}



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

int main() {
	int n;
	int h;
	long s=0;
	while(cin>>n){
		for(h=n;h<600;h+=n){
			s+=h*h*n;
		}
		cout<<s<<endl;
		s=0;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 2984
#include <stdio.h>

int main(){


  int i,j,N,A[100],v,k;

  scanf("%d ",&N);

  for(i=0;i<N;i++){

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

  }
  
  for(k=0;k<N;k++){
    if(k==N-1)
    printf("%d\n",A[k]);
    else printf("%d ",A[k]);
  }

      
  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j] > v){
      A[j+1]=A[j];
      j--;
    }    
    A[j+1]=v;
    for(k=0;k<N;k++){
      if(k==N-1)
	printf("%d\n",A[k]);
      else printf("%d ",A[k]);
    }
  }

  return 0;
}
  
  
    
  



Measured memory_bytes: 2692
n = int(input())
S = input()
ans = 0
def ok(i):
    v = str(i).zfill(3)
    j = 0
    for s in S:
        if s == v[j]:
            j += 1
            if j == 3:
                return True
    else:
        return False

for i in range(1000):
    ans += ok(i)
print(ans)

Measured memory_bytes: 9264
#include <math.h>
#include <iostream>
#include <vector>
using namespace std;

pair<long long int, long long int> recursive(
    vector<long long int>& a, int l, int r,
    vector<vector<pair<long long int, long long int>>>& table) {
  if (table[l][r].first != -1) return table[l][r];
  if (r - l == 1) {
    int sum = a[l] + a[r];
    table[l][r] = {sum, sum};
    return table[l][r];
  } else if (l == r) {
    table[l][r] = {a[l], 0};
    return table[l][r];
  }

  long long int minCost = -1;
  long long int value = 0;
  for (int i = l; i < r; ++i) {
    pair<long long int, long long int> result1 = recursive(a, l, i, table);
    pair<long long int, long long int> result2 = recursive(a, i + 1, r, table);
    long long int cost =
        result1.first + result2.first + result1.second + result2.second;
    if (minCost == -1 || cost < minCost) {
      value = result1.first + result2.first;
      minCost = cost;
    }
  }
  table[l][r] = {value, minCost};
  return {value, minCost};
}

int main() {
  int N;
  cin >> N;
  vector<long long int> a(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  vector<vector<pair<long long int, long long int>>> table(
      N, vector<pair<long long int, long long int>>(N, {-1, -1}));
  pair<long long int, long long int> ans = recursive(a, 0, a.size() - 1, table);
  cout << ans.second;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

int32_t main()
{
	int t=1;
	while(t--)
	{
		int n,m;
		int cnt=0;
		cin >> n >> m;
		for(int i=0;i<n;i++)
		{
			int x,y;
			cin >> x >> y;
			int z=x*x+y*y;
			if(z<=m*m)
			cnt++;
		}
		cout << cnt;		
	}
}




Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
    long long int N, K;
    long long int temp1, temp2;

    // input
    scanf("%lld %lld", &N, &K);

    temp1 = N % K;
    if (temp1 < 0) {
        temp1 *= -1;
    }
    temp2 = temp1 - K;
    if(temp2 < 0) {
        temp2 *= -1;
    }
    // printf("%lld, %lld\n", temp1, temp2);
    if (temp1 > temp2) {
        printf("%lld\n", temp2);
    } else {
        printf("%lld\n", temp1);
    }
    return 0;
}

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

int main(){
  int a;
  cin>>a;
  if(a<10)cout<<a<<endl;
  else if(a<100)cout<<9<<endl;
  else if(a<1000)cout<<a-90<<endl;
  else if(a<10000)cout<<909<<endl;
  else if(a<100000)cout<<a-9090<<endl;
  else cout<<90909<<endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	char s[12];
	scanf("%s",s);
	int i,j,len=0,maxlen=0;
	for(i=0;s[i]!='\0';i++){
		if((s[i]=='A')||(s[i]=='T')||(s[i]=='C')||(s[i]=='G')){
			len++;
			for(j=1;(s[i+j]!='\0')||(len!=0);j++){
				if((s[i+j]=='A')||(s[i+j]=='T')||(s[i+j]=='C')||(s[i+j]=='G')){
					len++;
				}else{
					maxlen=(maxlen<len?len:maxlen);
					len=0;
				}
			}
		}
	}
	printf("%d",maxlen);
	return 0;
}

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


Measured memory_bytes: 2140
from collections import defaultdict

N = int(input())
di = defaultdict(int)

for i in range(1, N+1):
    k = str(i)[0] + str(i)[-1]
    di[k] += 1
# print(di)

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += di[str(i)+str(j)] * di[str(j)+str(i)]

print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
int xx[1001];int yy[1001];
int main()
{
	cin>>n>>m>>xx[1]>>yy[1];
	for(int i=2;i<=n+1;i++)
	{
		cin>>xx[i];
	}
	for(int i=2;i<=m+1;i++)
	{
		cin>>yy[i];
	}
	sort(xx+1,xx+2+n);
	sort(yy+1,yy+2+m);
	for(int i=-100;i<=100;i++)
	{
		if(xx[n+1]<i&&i<=yy[1]&&xx[1]<yy[1])
		{
			cout<<"No War";
			return 0;
		}
	}
	cout<<"War";
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = []
for i in range(M):
    ks = list(map(int, input().split()))
    k = ks[0]
    s = ks[1:]
    S.append(s)
P = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    flag = 0
    b = bin(i)[2:]
    b = '0' * (N-len(b)) + b
    for j in range(M):
        tmp = 0
        switches = S[j]
        for k, v in enumerate(switches):
            if b[v-1] == '1':
                tmp += 1
        if tmp % 2 != P[j]:
            flag = 1
            break
    if flag == 0:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;

struct node{
  int key;
  node *right,*left,*parent;
};

node *root, *NIL;

//insert/////
void insert(int k){
  node *y= NIL;
  node *x= root;
  node *z;

  z = (node *)malloc(sizeof(node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x= x->left;
    }
    else {
      x= x->right;
    }
  }

  z->parent =y;
  if(y== NIL){
    root =z ;
  }
  else {
    if(z->key < y->key){
      y->left=z;
    }
    else{
      y->right =z;
    }
  }
}

node * find(node *x,int k){
  while(x != NIL && k != x->key){
    if(k< x->key){
      x= x->left;
    }
    else x= x->right;
  }
  return x;
}

void inorder(node *a){
  if(a== NIL) return;
  inorder(a->left);
  printf(" %d",a->key);
  inorder(a->right);
}
void preorder(node *a){
  if(a == NIL) return;
  printf(" %d",a->key);
  preorder(a->left);
  preorder(a->right);
}

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    cin >> com;
    if(com == "insert"){
      cin >> x;
      insert(x);
    }
    else if(com == "find"){
      cin>> x;
      node *a = find(root, x);
      if(a == NIL){
        cout<< "no"<<endl;
      }
      else if(a != NIL){
        cout<<"yes"<<endl;
      }
    }
    else if(com == "print"){

      inorder(root);
      cout<< endl;
      preorder(root);
      cout << endl;
    }
  }

  return 0;
}



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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::string S;
  std::cin >> S;

  ll ans = 0;
  rep(i, 0, N - 3 + 1) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ans++;
  }
  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[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;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
/******* all required header files *******/
#include<iostream>
#include<algorithm>
#include<cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

/*****All definitions*******/
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vs vector<string>
#define mp make_pair
#define ll long long int
/***************************/

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	string str;
	cin >> str;
	int s = str.size();
	if (s <= n)
		cout << str;
	else {
		for (int i = 0 ; i < n; i++)
		{
			cout << str[i];
		}
		cout << "...";
	}
	return 0;
}


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

#define nl "\n"
#define forn(i,p) for(ll i = 0; i < p; ++i)
#define ll long long

using namespace std;

int main(){
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.setf(ios::fixed, ios::floatfield);    

    ll a, b;
    cin >> a >> b;

    if(b*2 < a) {cout << (a - b*2) << nl;}
    else cout << 0;

    
    return 0;
}

Measured memory_bytes: 256
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b2 = []
t = k
start = 0
while True:
  if start == len(b):
    break
  else:
    if t - b[start] < 0:
      break
    else:  
      t -= b[start]
      b2.append(b[start])
      start += 1
num = start
lst = [start]
M = start

for i in range(len(a)):
  if a[i] > t and b2 == []:
    print(M)
    sys.exit()
  while a[i] > t and b2 != []:
    b_ = b2.pop()
    t = t+b_
    num -= 1
    
  if a[i] <= t:
    t -= a[i]
    num += 1
  
 
  if M < num:
    M = num
  lst.append(num)    
    
  
  
  
  
print(M)    
  

Measured memory_bytes: 40600