akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[1000];
	int i = 0;

	//	getline(cin, hoge);

	while(1){
	  hoge[i] = getchar();
	  //	  scanf("%c",&hoge[i]);
	  if(hoge[i]=='\n') continue;
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;
	bool now[200] = {};
	int b=0;
 //????????§??????????????????

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
		b++;
		now[b] = false;
	  }else if(hoge[a]==')'){
		if(now[b] == false) {
		  mini--;
		  b--;
		}else{
		  mini = 100;
		  break;
		}
	  }else if(hoge[a]=='['){
		big++;
		b++;
		now[b] = true;
	  }else if(hoge[a]==']'){
		if(now[b] == true){
		  big--;
		  b--;
		}else{
		  big = 100;
		  break;
		}
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}

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

using namespace std;

int num[200010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    int fla=0;
    long long cnt=0;
    if(num[1]!=0)
        fla=1;
    for(int i=2;i<=n;i++)
    {
        if(num[i]>num[i-1])
        {
            if((num[i]-num[i-1])>1)
                fla=1;
            else
                cnt++;
        }
        else
        {
            cnt+=num[i];
        }
    }
    if(fla)
        printf("-1\n");
    else
    printf("%lld\n",cnt);
    return 0;
}


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

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

int main() {
    int K;cin >> K;
    int sum = 0;
    for (int i = 1;i < K + 1;i++){
        for (int j = 1;j < K + 1;j++){
            for (int k = 1;k < K + 1;k++){
                int GCD = gcd(gcd(i,j),k);
                sum += GCD;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<math.h>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define INF 1000000007;

int main(){
  int K,S,ans=0;

  cin >> K >> S;
  rep(i,K+1){
    REP(j,i,K+1){
      REP(k,j,K+1){
        if(i+j+k==S){
          if(i==j&&j==k) ans++;
          else if(i==j||j==k) ans+=3;
          else ans+=6;
        }
      }
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
#include <assert.h>
using namespace std;
#define ll long long
#define ppi pair<int, int>
#define mp make_pair
const int N = 2e5 + 2, K = 20;
const int mod = 1e9 + 7;
int dp[N], arr[N];
inline int dis(int a, int b)
{
	return abs(arr[a] - arr[b]);
}
int main()
{
//#ifndef ONLINE_JUDGE
//	freopen("inp.txt", "r", stdin);
//#endif
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	dp[n - 1] = 0;
	dp[n - 2] = dis(n - 1, n - 2);
	for (int i = n - 3; i >= 0; i--)
		dp[i] = min(dp[i + 1] + dis(i, i + 1), dp[i + 2] + dis(i, i + 2));
	cout << dp[0];
	return 0;
}

Measured memory_bytes: 1024
import numpy as np

h,w,k=list(map(int,input().strip().split()))
s=[]
for i in range(h):
    s.append(input().strip())

ans=[[0 for i in range(w)] for j in range(h)]
counter=0
flag=0
for i in range(h):
    jflag=0
    if flag==0:
        counter+=1
    for j,val in enumerate(s[i]):
        if val=='#':
            if jflag==0:
                jflag=1
            else:
                counter+=1
        ans[i][j]=counter
        if flag>0:
            for k in range(1,flag+1):
                ans[i-k][j]=counter
    if jflag==0:
        flag+=1
    else:
        flag=0
if k<counter:
    for k in range(0,flag):
        ans[i-k][:]=ans[i-flag][:]
        
for i in range(h):
    print(*ans[i])


Measured memory_bytes: 16520
import sys

input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    root = {i:i for i in range(n)}
    
    for i in range(m):
        s, t = map(int, input().split())
        
        r, c = s, 0
        while root[s] != s: s, c = root[s], c+1
        while root[t] != t: root[t], t = s, root[t]
        root[t] = s
        
        if c > 10: 
            while root[r] != s: root[r], r = s, root[r]
        
    for i in range(int(input())):
        s, t = map(int, input().split())
        
        while root[s] != s: s = root[s]
        while root[t] != t: t = root[t]
        
        if s == t: print('yes')
        else: print('no')

if __name__ == '__main__':
    main()




Measured memory_bytes: 16128
#include "iostream"
#include "string"
#include "vector"

using namespace std;

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, sum = 0;
ll A[500000] = {}, B[500000] = {}, ruiseki[500000] = {}, dp[100][10] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S, T;
bool check = false, check2 = false;

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

int main() {
	sum = 1;
	//Code Line
	cin >> a;
	if (a == 1)cout << 0 << endl;
	else cout << (1 + a) * a / 2 - a << endl;


	return 0;
}




Measured memory_bytes: 256
loop {
	e = m = gets.to_i
	break if e == 0
	loop.with_index { |_, z|
		break if(z**3 > e)
		y = Math.sqrt(e - z**3).to_i
		m = [m, e+y+z-y**2-z**3].min
	}
	puts m
}

Measured memory_bytes: 6124
import sys
from operator import itemgetter

read = sys.stdin.buffer.read
INF = 1 << 60


def main():
    N, M, *AB = map(int, read().split())

    Q = [0] * M
    for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
        Q[i] = (a - 1, b - 1)

    Q.sort(key=itemgetter(1))

    ans = 0
    last = -1
    for a, b in Q:
        if last < a:
            last = b - 1
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32324
#include <stdio.h>

int main() {

    int i;
    int n, m;
    int ans = 0;

    scanf("%d %d", &n, &m);

    if(n >= 2) {
        ans = ans + n * (n-1) / 2;
    }
    if(m >= 2) {
        ans = ans + m * (m-1) / 2;
    }

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fir first
#define sec second
using ll = long long;


int main()
{
    int n,m;
    std::cin >> n >> m;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        a[i] %= m;
    }
    std::vector<ll> sum(n + 1);
    for(int i = 0; i < n; i++)sum[i + 1] = sum[i] + a[i];
    std::map<ll,ll> mp;
    for(int i = 0; i <= n; i++)mp[sum[i] % m]++;
    ll cnt = 0;
    for(auto i :mp){
        cnt += (i.sec * (i.sec - 1)) / 2;
    }
    std::cout << cnt << std::endl;
    
}


Measured memory_bytes: 5376
#include<iostream>
#include<stdlib.h>
using namespace std;
int f(int s){
	if((s&1)==0)
		return s/2;
	else
		return 3*s+1;
}
int main(){
	int s;
	cin>>s;
	int *mem;
	int c=0;
	mem=(int*)malloc(sizeof(int)*1000000);
	while(mem[s]!=1){
		mem[s]=1;
		s=f(s);
		c++;
	}
	cout<<c+1;
	return 0;
}

Measured memory_bytes: 256
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

/*
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
Tree<int>tr;
*/

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

set<int>s;
int n;
int pos[1 << 17];
int x;
int ans;

int32_t main(){_
	//freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> x;
		pos[x] = i;
	}
	s.insert(0);
	s.insert(n + 1);
	for(int i = n;i >= 1;i--){
		auto ita = s.upper_bound(pos[i]);
		auto itb = ita;itb--;
		int f = 0;
		if(*ita != n + 1){
			f += (pos[i] - *itb) * (*(next(ita)) - *ita);
		}
		if(*itb != 0){
			f += (*ita - pos[i]) * (*itb - *prev(itb));
		}
		ans += f * i;
		s.insert(pos[i]);
	}
	rc(ans);
	return 0;
}











Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int p[3], j[2];
  for(int i = 0; i < 3; i++)
    cin >> p[i];
  for(int i = 0; i < 2; i++)
    cin >> j[i];
  printf("%d\n", min(j[0], j[1]) + min(min(p[0], p[1]), p[2]) - 50);
  return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

struct Node{
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil -> next;
	while(cur != nil && cur -> key != key){
		cur = cur -> next;
	}
	return cur;
}

void init(){
	nil = new Node;
	nil -> next = nil;
	nil -> prev = nil;
}

void printList(){
	Node *cur = nil -> next;
	int isf = 0;
	while(1){
		if(cur == nil) break;
		if(isf++ > 0) printf(" ");
		printf("%d", cur -> key);
		cur = cur -> next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if(t == nil) return;
	t -> prev -> next = t -> next;
	t -> next -> prev = t -> prev;
	delete(t);
}

void deleteFirst(){
	deleteNode(nil -> next);
}

void deleteLast(){
	deleteNode(nil -> prev);
}

void deleteKey(int key){

	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x = new Node;
	x -> key = key;

	x -> next = nil -> next;
	nil -> next -> prev = x;
	nil -> next = x;
	x -> prev = nil;
}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for(i = 0; i < n; i++){
		scanf("%s%d", com, &key);
		if(com[0] == 'i') {insert(key); np++; size++;}
		else if(com[0] == 'd'){
			if(strlen(com) > 6){
				if(com[6] == 'F') deleteFirst();
				else if(com[6] == 'L') deleteLast();
			}else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}




Measured memory_bytes: 34436
X = int(input())

count = 0

for i in range(2, X+1, 1):
    if X % i == 0:
        count += 1
    
if count == 1:
    print(X)
else:
    while True:
        count = 0
        X += 1
        for i in range(2, X+1, 1):
            if X % i == 0:
                count += 1
        if count == 1:
            print(X)
            break

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

int main(void){
	int a,b;
	cin >> a >> b;
	int d = a / b;
	int r = a % b;
	double f = (double)a / b;
	cout << fixed << setprecision(12);
	cout << d << " " << r << " " << f << "\n";
	return 0;

}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp    make_pair
#define pb    push_back
#define F     first
#define pi 	  3.14159265358979323846
#define S     second
#define ll    long long
#define ld    long double
#define sz(s) (ll)s.size() 
#define vl    vector < ll >
#define pll   pair < ll, ll >
#define ml    map < ll, ll >
#define mod   1000000007
#define MAXN  50005 
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define inv(i,a,b)  for(ll i=a;i>=b;i--)
#define all(a)  (a).begin(),(a).end()
using namespace std;
int main(){
	IOS;
	ll n,i,m,ans;
	cin>>n>>m;
    if(m%2==0){
    	m/=2;
    	if(m>=n && m<=2*n)cout<<"Yes";
    	else cout<<"No";
	}
	else cout<<"No";
}

Measured memory_bytes: 3648
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, w = ns()
    dp = [INF for _ in range(n * 100 + 1)]
    dp[0] = 0

    for _ in range(n):
        vi, wi = ns()
        for i in range(n * 100 - vi, -1, -1):
            if dp[i] == INF:
                continue
            if dp[i] + wi <= w:
                dp[i + vi] = min(dp[i + vi], dp[i] + wi)

    for i in range(n * 100, -1, -1):
        if dp[i] != INF:
            print(i)
            exit(0)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7436
#include<stdio.h>
int main(void){
  long x,y,L,S,Sub;
  scanf("%ld%ld",&x,&y);
  if(x>y){L=x;S=y;}else{L=y;S=x;}
  while(L%S!=0){
    Sub=L;
    L=S;
    S=Sub%S;
  }
  printf("%ld\n",S);
  return 0;
}

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


int main()
{
	vector<char> s(4);
	for (int i = 0; i < 4; i++) {
		cin >> s.at(i);
	}
	sort(s.begin(), s.end());

	string ans = "No";
	if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2)) {
		ans = "Yes";
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,c,mx=0,mx2,ch=0;
  cin >> n;
  vector<int> vec(n);
  for (int i=0; i<n; i++) {
    cin >> vec.at(i);
    c = vec.at(i);
    mx = max(mx,c);
  }
  for (int i=0; i<n; i++) {
    if (mx == vec.at(i)) ch++;
  }
  for (int i=0; i<n; i++) {
    c = vec.at(i);
    if (c != mx&&mx2 < c) mx2 = c;
  }
  if (mx2 == 0) mx2 = mx;
  for (int i=0; i<n; i++) {
    if (vec.at(i) == mx&&ch == 1) cout << mx2 << endl;
    else cout << mx << endl;
  }
}

Measured memory_bytes: 2432
#include<iostream>

using namespace std;

int main(){
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	long long ans  = (n*x)-(n-k)*(x-y);
    if(n>=k)cout<<ans<<endl;
    else cout<<n*x<<endl;
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC109 D

h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]

cnt = 0
ans = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] == 0 or a[i][j] % 2 == 0:
                continue
            if j != w-1:
                a[i][j+1] += 1
                a[i][j] -= 1
                cnt += 1
                ans.append([i+1,j+1,i+1,j+2])
            elif j == w-1:
                if i+1 < h:
                    a[i+1][j] += 1
                    a[i][j] -= 1
                    cnt += 1
                    ans.append([i+1,j+1,i+2,j+1])
    else:
        for j in range(w)[::-1]:
            if a[i][j] == 0 or a[i][j] % 2 == 0:
                continue
            if j != 0:
                a[i][j-1] += 1
                a[i][j] -= 1
                cnt += 1
                ans.append([i+1,j+1,i+1,j])
            elif j == 0:
                if i+1 < h:
                    a[i+1][j] += 1
                    a[i][j] -= 1
                    cnt += 1
                    ans.append([i+1,j+1,i+2,j+1])
print(cnt)
for y_ , x_ , y,x in ans:
    print(y_ , x_ , y, x)


Measured memory_bytes: 71132
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  readln();
  auto N = readln.split.to!(ulong[]);

  string solve() {
    return N
      .filter!(x => x % 2 == 0)
      .filter!(x => x % 5 != 0 && x % 3 != 0)
      .array
      .length > 0 ? "DENIED" : "APPROVED";
  }

  solve().writeln;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine
import scala.collection.immutable.HashMap

object Main {

  def main(args:Array[String]) = {
    val r = readLine.split(" ")
    var (w1,max,w2,freq) = ("",0,"",0)
    val freqs = r.foldLeft(HashMap[String,(Int,Int)]()) { (x,y) =>
      if(x.contains(y)) x.updated(y,(x(y)._1+1,x(y)._2)) else x ++ HashMap[String,(Int,Int)]( y -> (0,y.length) )
    }

    for(s <- freqs) {
      if(max < s._2._2) { max = s._2._2;w1 = s._1 }
      if(freq < s._2._1) { freq = s._2._1;w2 = s._1 }
    }

    println(w2 + " " + w1)
  }
}

Measured memory_bytes: 43536
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>

using namespace std;


int main(int argc, const char * argv[]) {
    

    int n, ans = 0;
    int min = 2 * 100000 + 1;
    
    cin >> n;
    
    int p[n];
    
    for(int i=0; i<n; i++)
    {
        cin >> p[i];
        
        if (min > p[i])
        {
            min = p[i];
            ans++;
        }
        
        //if(p[i] == 1) break;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

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

  int cnt_n = 0, cnt_w = 0, cnt_s = 0, cnt_e = 0;
  for (int i=0; i<s.size(); i++) {
    if (s[i] == 'N')
      cnt_n++;
    else if (s[i] == 'W')
      cnt_w++;
    else if (s[i] == 'S')
      cnt_s++;
    else if (s[i] == 'E')
      cnt_e++;
  }

  string ans = "";
  if ((cnt_n != 0 && cnt_s == 0) || (cnt_s != 0 && cnt_n == 0) ||
      (cnt_w != 0 && cnt_e == 0) || (cnt_e != 0 && cnt_w == 0))
    ans = "No";
  else
    ans = "Yes";

  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;



//DONT WASTE YOUR TIME......i said don't waste -_- 
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

ll gg[N];
int main() {
 	// freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll n,i,j,k,a,b,c,x,y,z;
	sc(n);
	j=0;
	for(i=1;i<=n;i++){
		sc(gg[i]);
		j+=abs(gg[i]-gg[i-1]);
	}
	j+=abs(gg[n]);
	k=j;
	for(i=1;i<=n;i++){
		if(i<n){
			j-=abs(gg[i]-gg[i-1]);
			j-=abs(gg[i+1]-gg[i]);
			j+=abs(gg[i+1]-gg[i-1]);
		}
		else{
			j-=abs(gg[i]-gg[i-1]);
			j-=abs(gg[i]);
			j+=abs(gg[i-1]);
		}
		pr(j);
		j=k;
	}

}

Measured memory_bytes: 2048
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define dbgarrmint(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j].x<<" ";}cerr<<endl;}
#else
#define dbg(...)
#define dbgmap(...)
#define dbgarr(...)
#define dbgdp(...)
#define dbgmint(...)
#define dbgarrmint(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    ll x;
    cin>>x;
    ll cnt = 0;
    while(1){
        cnt++;
        if(cnt*x % 360 == 0){
            break;
        }
    }
    out(cnt);

    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
    solve();
}


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

int main(){
    int a; string s;
    cin >> a >> s;
    cout << ((a >= 3200)? s : "red") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX=1001001;
const ll MOD=1000000007;
int main()
{
    ll h, w, a, b;
    cin >> h>>w>>a >> b;
    vector<vector<ll>>d(h, vector<ll>(w));
    rep(i, h) {
        rep(j, w) {
            if ((i>=b&&j>=a)||(i<b&&j<a)) {
                d[i][j]=1;
            }
        }
    }
    rep(i, h) {
        rep(j, w) {
            cout<<d[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 11100
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k; cin>>n>>k; int a[n];
    for (int i = 0; i < n; i++) cin>>a[i];
    sort(a, a+n);
    int sum=0;
    for (int i = 0; i < k; i++)sum+=a[n-1-i];
    cout<<sum<<'\n';
    }
    

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		BigInteger X = new BigInteger(scan.next());
		BigInteger Y = new BigInteger(scan.next());
		BigInteger Ai = X;
		int sum = 0;
		while(Ai.compareTo(Y) != 1) {
			Ai = Ai.multiply( BigInteger.valueOf(2) );
			sum++;
		}
		System.out.println(sum);
		scan.close();
	}
 
}

Measured memory_bytes: 27060
n=int(input())
#print(n)

#l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
l='abcdefghijklmnopqrstuvwxyz'
#print(len(l))

ansl=[0 for i in range(26)]
#print(ansl)

s=input()  
for j in range(26):
      ansl[j]=s.count(l[j])

if n > 1:
  for i in range(1,n):
    s=input()  
    for j in range(26):
      ansl[j]=min(s.count(l[j]),ansl[j])

ans=''
for i in range(26):
  for j in range(ansl[i]):
    ans+=l[i]
    
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
	long int a,b,k;
	
	scanf("%ld%ld%ld",&a,&b,&k);
	
	if(k>=a+b){
		printf("0 0");
	}else{
		if(k>=a)
			printf("%ld %ld",0,a+b-k);
		else
			printf("%ld %ld",a-k,b);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

const int Nmax = 300;

void wf(long long cost[Nmax][Nmax], long long output[Nmax][Nmax], int N){
  for(int i=0; i<N; i++)
    for(int j=0; j<N; j++)
      output[i][j] = cost[i][j];

  for(int k=0; k<N; k++)
    for(int i=0; i<N; i++)
      for(int j=0; j<N; j++)
        output[i][j] = min(output[i][j], output[i][k] + output[k][j]);
}

bool is_needed(long long cost[Nmax][Nmax], int N, int i, int j){
  for(int k=0; k<N; k++){
    if(k != i && k != j &&
       cost[i][j] == cost[i][k] + cost[k][j])
      return false;
  }
  return true;
}

int main(){
  long long A[Nmax][Nmax];
  long long shortest_pathes[Nmax][Nmax];

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

  wf(A, shortest_pathes, N);

  bool ret = true;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(A[i][j] != shortest_pathes[i][j]){
        ret = false;
        break;
      }
    }
    if(!ret) break;
  }

  if(ret){
    long long sum = 0;
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        if(i < j && is_needed(A, N, i, j)){
          sum += A[i][j];
        }
      }
    }
    cout << sum << endl;
  }
  else cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, y, a, b, c, k;
  a = -1;
  b = -1;
  c = -1;
  in2(n, y);
  rep(i, n + 1){
    rep(j, n + 1){
      k = y - 10000 * i - 5000 * j;
      if(k >= 0 && k / 1000 == n - i - j){
        a = i;
        b = j;
        c = k / 1000;
      }
    }
  }
  out(a);
  hina;
  out(b);
  hina;
  out(c);
  memi;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    int A[N][2];
    for (int i=0; i<N; i++){
        cin >> A[i][0] >> A[i][1];
    }
    int B[M][2];
    for (int i=0; i<M; i++){
        cin >> B[i][0] >> B[i][1];
    }

    for (int i=0; i<N; i++){
        int d, D;
        int a;
        for (int j=0; j<M; j++){
            d = abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1]);
            if (d < D || j == 0){
                D = d;
                a = j+1;
            }
        }
        cout << a << endl;
    }
}

Measured memory_bytes: 256
N, T = map(int, input().split())
A = list(map(int, input().split()))

m = A[0]
l = []
for i in range(1, N):
    if A[i] < m:
        m = A[i]
    else:
        d = A[i] - m
        l.append(d)
print(l.count(max(l)))

Measured memory_bytes: 14228
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		String T = sc.next();
		sc.close();

		char[] s = S.toCharArray();
		char[] t = T.toCharArray();

		int ans = 0;

		for(int i=0;i<s.length;i++) {
			if(s[i]==t[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
fun main(args: Array<String>){
    val ret = if(getSentences().sorted() == listOf(5, 5, 7)){
        "YES"
    }else{
        "NO"
    }

    println(ret)
}

fun getSentences(): List<Int>{
    return readLine()!!.split(" ").map { it.toInt() }
}

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

using namespace std;

const int MAXN = 1E5;
bool good[MAXN];

int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    for (int i = 0; i < n; i++)
    {
        good[i] = (s[i] == '1');
    }
    int left = 0;
    int right = 0;
    for (int i = 0; i < k && right < n; i++)
    {
        while (right < n && good[right])
        {
            right++;
        }
        while (right < n && !good[right])
        {
            right++;
        }
    }
    while (right < n && good[right])
        right++;
    int ans = right;
    while (left < n)
    {
        while (left < n && good[left])
        {
            left++;
        }
        while (left < n && !good[left])
        {
            left++;
        }
        while (right < n && !good[right])
            right++;
        while (right < n && good[right])
            right++;
        ans = max(ans, right - left);
    }
    cout << ans << endl;
    return 0;
}


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

int main () {
    int N, M; cin >> N >> M;
    vector<long long int> a(N, 0);
    vector<long long int> b(N, 0); 
    rep(i, N) cin >> a[i] >> b[i];
    vector<long long int> c(M, 0);
    vector<long long int> d(M, 0);
    rep(i, M) cin >> c[i] >> d[i];

    rep (i, M) cerr << d[i] << endl;
    rep(i, N) {
        int check = 1;
        long long int max = INT_MAX;
        rep(j, M) {
            long long int e = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if (max > e) {
                max = e;
                check = j+1;
            }
        }
        cout << check << endl;
    }
}


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

while True:
    n = int(raw_input())
    if n == 0:
        break
    A = [int(raw_input()) for i in range(n)]
    sum = [[0 for i in range(n)] for j in range(n)]
    sum[0][0] = Max = A[0]
    for i in range(1, n):
        sum[0][i] = sum[0][i-1] + A[i]
        Max = max(Max, sum[0][i])
    for i in range(1, n):
        for j in range(i, n):
            sum[i][j] = sum[i][j-1] + A[j]
            Max = max(Max, sum[i][j])
    print Max

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

if n == 1:
    print('a')
    exit()

if n == 2:
    print('aa')
    print('ab')
    exit()

words = 'abcdefghijklm'
ans = [['', -1]]

for i in range(1, n+1):
    usable = list(words[:i])
    news = []
    for candidate, limit in ans:
        for num, word in enumerate(usable):
            if num > limit + 1:
                break
            new = candidate + word
            news.append([new, max(limit, num)])
    ans = news

result = [word for word, limit in ans]
result.sort()
for res in result:
    print(res)

Measured memory_bytes: 25716
//abc165-D//

//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
//#include <string.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s == "ARC")
        cout << "ABC" <<endl;
    else
        cout << "ARC"<<endl;
    return 0;
}


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

using namespace std;

#define llong unsigned long long
#define sz(v) ((int)v.size())
#define ii pair<int, int>
#define xx first
#define yy second
#define rep(i,n) for (int i = -1; ++i < n; )

int n, p;
llong cnt[2];

llong comb[60][60] = {0};

int main() {
  cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> p;
  rep(i, n) {
    int num; cin >> num;
    cnt[num&1] ++;
  }

  comb[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    comb[i][0] = 1;
    for (int f = 1; f <= i; ++f)
      comb[i][f] = comb[i - 1][f - 1] + comb[i - 1][f];
  }

  llong ne = 1ull << cnt[0];
  llong no = 0;

  for (llong i = 0; i <= cnt[1]; ++i)
    if (((int)i & 1) == p) no += comb[cnt[1]][i];
  llong ans = no * ne;
  cout << ans;
  

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
ll frac[1001001];


int main(){
    int n,m;
    cin>>n>>m;
    frac[0]=1;
    for(int i=1;i<=n+m;i++){
        frac[i]=frac[i-1]*i;
        frac[i]%=MOD;
    }
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    if(abs(n-m)==1){
        ans*=frac[n];
        ans%=MOD;
        ans*=frac[m];
        ans%=MOD;
    }else{
        ans*=frac[n];
        ans%=MOD;
        ans*=frac[m];
        ans%=MOD;
        ans*=2;
        ans%=MOD;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 5028
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs 
cout <<lcs; 
} 

/* Driver program to test above function */
int main() 
{ 
string X,Y;
  cin>>X>>Y;
  int m,n;
  m=X.length();
  n=Y.length();
lcs(X, Y, m, n); 
return 0; 
} 


Measured memory_bytes: 38792
from bisect import bisect_left
N, Q = map(int, input().split())
S = str(input())
LR = [list(map(int, input().split())) for i in range(Q)]

ans_list = []
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        ans_list.append(i-1)


for l, r in LR:
    i = bisect_left(ans_list, l-1)
    j = bisect_left(ans_list, r-1)
    print(j-i)

Measured memory_bytes: 30292
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(auto &a : A) cin >> a;
    sort(A.begin(), A.end());
    ll ans = 0;
    reverse(A.begin(), A.end());
    ll cnt = N - 1;
    ll po = 0;
    for(ll i = 0; i < N; i++){
        if(cnt > 0){
            ans += A[i] * min<ll>(2, cnt);
            if(cnt == 1) po++;
            cnt -= min<ll>(cnt, 2);
        }else if(po < 2){
            ans -= A[i];
            po++;
        }else{
            ans -= A[i] * 2;
        }
    }
    ll tmp = 0;
    cnt = N - 1;
    po = 100;
    for(ll i = 0; i < N; i++){
        if(cnt > 0){
            if(cnt <= 2){
                tmp += A[i];
                cnt--;
            }else{
                tmp += A[i] * 2;
                cnt -= 2;
            }
        }else if(po < 2){
            tmp -= A[i];
            po++;
        }else{
            tmp -= A[i] * 2;
        }
    }
    cout << max(tmp, ans) << endl;
    return 0;
}


Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const inf = 1 << 40

	n, m := nextInt(), nextInt()

	a, d := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = nextInt()
		b := nextInt()
		for j := 0; j < b; j++ {
			c := nextInt() - 1
			d[i] |= (1 << uint(c))
		}
	}

	dp := make([][]int, m+1)
	for i := range dp {
		dp[i] = make([]int, 1<<uint(n))
		for j := range dp[i] {
			dp[i][j] = inf
		}
	}
	dp[0][0] = 0
	for i := 0; i < m; i++ {
		for j := 0; j < (1 << uint(n)); j++ {
			dp[i+1][j] = min(dp[i+1][j], dp[i][j])
			dp[i+1][j|d[i]] = min(dp[i+1][j|d[i]], dp[i][j]+a[i])
		}
	}

	if dp[m][(1<<uint(n))-1] == inf {
		puts(-1)
	} else {
		puts(dp[m][(1<<uint(n))-1])
	}
}


Measured memory_bytes: 33920
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import java.io.*;
//import java.util.stream.IntStream;



class Node{
    static int INFTY = Integer.MAX_VALUE;

    int id;
    int d = INFTY;   // startからの距離(更新する)
    //int parent;
    //int color = 1;
    Map<Integer, Integer> children = new TreeMap<>(); // <id, distance>

    Node(){};

    Node(int id){
        this.id = id;
    }

}

public class Main {
    static int INFTY = Integer.MAX_VALUE;

    static Node[] nodes;
    //static int[] d;         // startからの最短距離
    //static Set<Integer> T;  // 全域木
    //static Set<Integer> V;  // 探索前

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int n = sc.nextInt();
            nodes = new Node[n];
            //d = new int[n];
            //Arrays.fill(d, INFTY);

            for(int i=0;i<n;i++){
                int id = sc.nextInt();
                int numChild = sc.nextInt();
                nodes[i] = new Node(id);
                for(int j=0;j<numChild;j++){
                    int child = sc.nextInt();
                    int weight = sc.nextInt();
                    nodes[id].children.put(child, weight);
                }
            }

            Queue<Node> queue = new PriorityQueue<>((o1,o2)->{return o1.d-o2.d;});  // 全域木からの距離でソート
            
            queue.add(nodes[0]);
            //nodes[0].color = 1;
            nodes[0].d = 0;
            while(!queue.isEmpty()){
                Node u = queue.poll();
                //if(u.cost + d[u.parent] > d[u.id]){continue;}
                

                for(Map.Entry<Integer, Integer> entry : u.children.entrySet()){
                    int id = entry.getKey();
                    int cost = entry.getValue();
                    if(nodes[id].d < nodes[u.id].d + cost){continue;}

                    nodes[id].d = nodes[u.id].d + cost;
                    //nodes[id].color = 1;
                    queue.add(nodes[id]);
                }
                
            }
            
            StringBuffer buf = new StringBuffer();
            for(int i=0;i<n;i++){
                buf.append(i + " " + nodes[i].d + '\n');
            }
            System.out.print(buf);
        
    }



}





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

int main(){
  int T[101][101], r, c;
  cin >> r >> c;

  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) cin >> T[i][j];

  for (int i = 0; i <= r; i++) T[i][c] = 0;
  for (int j = 0; j <= c; j++) T[r][j] = 0;

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      T[i][c] += T[i][j];
      T[r][j] += T[i][j];
      T[r][c] += T[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if ( j ) cout << " " ;
      cout << T[i][j] ;
    }
    cout << endl;
  }


return 0;
}

Measured memory_bytes: 3108
// Problem : B - Mix Juice
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,k;
		cin>>n>>k;
		int arr[n];
		for(int i=0;i<n;++i)
		cin>>arr[i];
		sort(arr,arr+n);
		int sum = 0;
		for(int i=0;i<k;++i)
		sum+=arr[i];
		cout<<sum;		
    }
    return 0;
}


Measured memory_bytes: 3624
from heapq import heappush, heappop

K = int(input())
adjL = [[] for i in range(K)]
for i in range(K):
    adjL[i].append(((i + 1) % K, 1))  # i→(i+1) に、重み1の辺を張る
    adjL[i].append(((i * 10) % K, 0)) # i→(i*10)に、重み0の辺を張る

# ダイクストラ法
cost = [float('inf')] * K
cost[1] = 0
PQ = []
heappush(PQ, (0, 1)) # 1からスタート
while PQ:
    cNow, vNow = heappop(PQ)

    if vNow == 0: break # 0に到達したら終了
    if cNow > cost[vNow]: continue

    for v2, wt in adjL[vNow]:
        c2 = cNow + wt
        if c2 < cost[v2]:
            cost[v2] = c2
            heappush(PQ, (c2, v2))

# 「1→0への最短経路長」+1が求める答え
print(cost[0] + 1)


Measured memory_bytes: 38272
#include <iostream>

using namespace std;

int main()
{string s,x,ww;
cin>>s>>x;
ww=s;
if(s==x){cout<<"Yes"<<endl;}
else{
int y=s.size(),c=0;
while(true){
    char q;
    q=  s[y-1];;
for(int i=y-1;i>=1;i--){
    s[i]=s[i-1];
}
  s[0]=q;
    if(s==x){c++;
    break;}
   // y--;
   if(s==ww){c=0;
   break;}
}
if(c!=0){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}
}
    return 0;
}

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

using namespace std;

void solve() {
    string s; cin >> s;
    int n = s.size();
    int l1 = 0, r1 = (n - 1) /2 - 1;
    int l2 = (n + 3) / 2 - 1, r2 = n - 1;
    int flag = 1;
    for ( ; l1 <= r1; l1++, r1--) {
        flag &= (s[l1] == s[r1]);
    }
    for ( ; l2 <= r2; l2++, r2--) {
        flag &= (s[l2] == s[r2]);
    }
    for (int l = 0, r = n - 1; l <= r; l++, r--) {
        flag &= (s[l] == s[r]);
    }
    if (flag) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 256
def mainFunc():
    nextSunday = {
        'SUN': 7,
        'MON': 6,
        'TUE': 5,
        'WED': 4,
        'THU': 3,
        'FRI': 2,
        'SAT': 1
    }

    print(nextSunday[input()])



mainFunc()

Measured memory_bytes: 2940