akhauriyash/Code-Regression huggingface dataset:
import bisect
A, B, Q = map(int, input().split())

INF = 10 ** 11 + 1
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]

"""
def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	if hi < lo:
		return lo
	mi = (lo + hi) // 2
	if v < a[mi]:
		return bsr(a, v, lo, mi - 1)
	else:
		return bsr(a, v, mi + 1, hi)
"""

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	cost = []
	for m in [S[sr], S[sl]]:
		for n in [T[tr], T[tl]]:
			cost += [abs(x - m) + abs(m - n), abs(x - n) + abs(m - n)]
	#print(sr, sl, tr, tl, cost)
	print(min(cost))
	#break


Measured memory_bytes: 16132
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <iostream>
#include <sstream>
#include <vector>
#include <iterator>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
 
#define    pi          acos(-1)
#define    ll          long long
#define    mp          make_pair
#define    pb          push_back
#define    vi          vector <int>
//#define    vs          vector <string>
#define    maxx(a,b,c) max(a,max(b,c))
#define    minn(a,b,c) min(a,min(b,c))
#define    all(x)      (x).begin(),(x).end()
#define    fill(x,y)   memset(x, y, sizeof(x))
#define    trace(x)    cout << #x << " = " << x << endl
#define    bug         cout << "Bug check" << endl
#define    eps         1e-10
#define    endl        '\n'
 
using namespace std;

int main(){
	//freopen("in.txt","r", stdin);
	//freopen("out.txt","w", stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);

	map <string,int> m;
	map <string,int>::iterator it;
	int n; cin >> n;
	cin.ignore();
	while(n--){
		string s; cin >> s;
		if(m.count(s)==0) m[s]=1;
		else m[s]++;
	}
	vector < pair <int,string> > v;
	vector < pair <int,string> >::iterator it2;
	for(it=m.begin();it!=m.end();it++){
		v.pb(mp(it->second,it->first));
	}
	sort(all(v));
	reverse(all(v));
	it2 = v.begin();
	int a = it2->first;
	vector < string > vs;
	for(it2=v.begin();it2!=v.end();it2++){
		if(it2->first==a){
			vs.pb(it2->second);
		}
	}
	sort(vs.begin(),vs.end());
	for(int i=0;i<vs.size();i++){
		cout << vs[i] << endl;
	}
 	return 0;
}

Measured memory_bytes: 33260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 12345678901234


struct UnionFind {
    int n, cnt;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sz[find(x)];
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};

int main(){
    ll i,j;
    ll n,m;
    cin>>n>>m;
    ll k=n;
    UnionFind uf(n);
    for(i=0;i<m;i++){
        ll x,y,z;
        cin>>x>>y>>z;
        x--;
        y--;
        if(!uf.same(x,y)){
            uf.unite(x,y);
            k--;
        } 
    }
    cout<<k<<endl;

    
    return 0;
}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(k>a){
        ans += a;
        k-=a;
    }
    else{
        COUT(k);
        return 0;
    }
    if(b>=k){
        COUT(ans);
        return 0;
    }
    else{
        k-=b;
    }
    if(k>0){
        ans -= k;
    }
    COUT(ans);
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int N;
  cin >> N;
  ll res = 1LL;
  for (int i = 1; i < N + 1; i++) {
    res = res * i % MOD;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import sys
import queue

input = sys.stdin.buffer.readline
INF = 10 ** 9

N = int(input())
path = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)

#find the longest path by trying BFS twice.
q = queue.Queue()
depth = [INF] * N
q.put(0)
depth[0] = 1
while not q.empty():
    node = q.get()
    for next_node in path[node]:
        if depth[next_node] > depth[node] + 1:
            depth[next_node] = depth[node] + 1
            q.put(next_node)

#The 'node' gives one end of the longest path.
q = queue.Queue()
depth = [INF] * N
q.put(node)
depth[node] = 1
while not q.empty():
    node = q.get()
    for next_node in path[node]:
        if depth[next_node] > depth[node] + 1:
            depth[next_node] = depth[node] + 1
            q.put(next_node)

length = depth[node]

if length % 3 == 2:
    print("Second")
else:
    print("First")

Measured memory_bytes: 93640
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	string s;
	int n, k;
	cin >> n >> k >> s;
	s[k-1] = tolower(s[k-1]);
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#line 1 "test/aoj/GRL_3_C.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C"

#line 1 "test/aoj/../../graph/strongly-connected-components.cpp"
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

#line 1 "test/aoj/../../graph/template.cpp"
#include <vector>

using namespace std;

template< typename T >
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : cost((int)1), from(f), to(t) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

template< typename T >
using Edges = vector< Edge< T > >;
template< typename T >
using Graph = vector< Edges< T > >;
#line 7 "test/aoj/../../graph/strongly-connected-components.cpp"
using namespace std;

template< typename T >
struct stronglyConnectedComponents {
  using graph = Graph<T>;
  const int V;
  graph g, rg;
  vector<bool> visit;
  vector<int> comp, order;
  vector<vector<int>> components;

  stronglyConnectedComponents(const graph &g) : V(g.size()), g(g), rg(V), visit(V, false), comp(V, -1) {
    // 辺の向きを逆にしたグラフを構築
    for (int v = 0; v < V; ++v) {
      for (auto &e : g[v]) { 
        rg[e.to].emplace_back(e.to, e.from);
      }
    }
  }

  // 同じ強連結成分に属していればtrueを返す
  bool same(int s, int t) {
    assert(comp[s] != -1 && comp[t] != -1);
    return comp[s] == comp[t];
  }

  void dfs(int sv) { 
    if (visit[sv]) return;
    visit[sv] = true;
    for (auto &e : g[sv]) { 
      dfs(e.to);
    }
    order.push_back(sv);
  }

  void rdfs(int sv, int cnt) { 
    if (comp[sv] != -1) return;
    comp[sv] = cnt;

    if (components.size() <= cnt) { 
      vector<int> v;
      components.push_back(v);
    }
    components[cnt].push_back(sv);

    for (auto &e : rg[sv]) { 
      rdfs(e.to, cnt);
    }
  }

  void build() {
    for(int i = 0; i < V; i++) { dfs(i); } 
    assert(order.size() == V);
    reverse(order.begin(), order.end()); // dfsでつけた番号を逆順にする
    int cnt = 0; // 強連結成分毎のid
    for (int v : order) { 
      if (comp[v] != -1) continue;
      rdfs(v, cnt);
      // 強連結成分の頂点をループの順に並び替え
      if (components[cnt].size() > 1) {
        reverse(components[cnt].begin()+1, components[cnt].end());
      }
      ++cnt;
    }
  }
};
#line 4 "test/aoj/GRL_3_C.test.cpp"

int main() {
  int V, E;
  cin >> V >> E;
  Graph<int> graph(V);
  for (int i = 0; i < E; ++i) {
    int x, y;
    cin >> x >> y;
    graph[x].emplace_back(x, y);
  }
  stronglyConnectedComponents<int> scc(graph);
  scc.build();
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) { 
    int u, v;
    cin >> u >> v;
    if (scc.same(u, v)) { cout << "1" << endl; }
    else { cout << "0" << endl; }
  }
}



Measured memory_bytes: 5204
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

int main() {
	string s;
	cin >> s;
	
	REP(i, s.length()) {
		cout << s[i];
		if (i == 3) cout << " ";
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    ll A, B, N;
    cin >> A >> B >> N;
    ll x = min(B - 1, N);
    cout << (A * x) / B << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include<math.h>
typedef long long ll;
using namespace std;
vector<vector<int>>comp;
vector<int>onecycle;
vector<int>clength;
vector<int>v9;
vector<int>v8;
int cycle_start;
int cycle_end;
vector<int>vbip1;
vector<int>vbip2;
#define FIO  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main()
{
    ll n,W;
    cin>>n>>W;
    ll i,j;
    ll w[n],v[n];
    ll sum=0;
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
        sum+=v[i];
    }
    
    ll dp[n+1][sum+1];
    for(i=0;i<n+1;i++)
    {
        for(j=0;j<sum+1;j++)
        {
            dp[i][j]=INT_MAX;
        }
    }
    for(i=0;i<n+1;i++)
    {
        for(j=0;j<sum+1;j++)
        {
            if(j==0)
            {
                dp[i][j]=0;
            }
            else if(i==0)
            {
                dp[i][j]=INT_MAX;
            }
            else
            {
                if(j-v[i-1]>=0)
                {
                    dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]);
                }
                else
                {
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
    }
    ll max1=0;
    for(i=0;i<n+1;i++)
    {
        for(j=0;j<sum+1;j++)
        {
            if(dp[i][j]<=W)
            {
                max1=max(j,max1);
            }
        }
    }
    cout<<max1;
    
    
}


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

int main() {
	int N, M; cin >> N >> M;

	vector<vector<int>> vec(M);

	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : vec[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
	int student[30],a=0,i=0;
	for(i=0;i<30;i++)
		student[i]=0;
	for(i=0;i<28;i++){
		scanf("%d",&a);
		student[a-1]=1;
	}
	for(i=0;i<30;i++){
		if (student[i]==0)
			printf("%d\n",i+1);
	}
	return 0;
}

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

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

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

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

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

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

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

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

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

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

const int NMAX = 100;
bool flag;


int main(){
    CIN(N);
    vi v(N);
    rep(i,N)cin>>v[i];
    int ans=0;
    Rep(i,1,N-1){
        if(v[i]<v[i-1]&&v[i]>v[i+1])ans++;
        else if(v[i]>v[i-1]&&v[i]<v[i+1])ans++;
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
   int A , B , C ;
   cin >> A >> B >> C ;
    if (1 <= A && B && C <= 9){
            if (A == B && A == C)
            {
                cout << "No" << endl ;
            }
    else if (A == B || A == C || B == C)

        cout << "Yes" << endl ;
    else

        cout << "No" << endl ;

  }
     return 0;
}


Measured memory_bytes: 3536
import math
def input_parser():
    N=int(input())
    return N

N=input_parser()
power=1
rem_power=1
bignum=10**9+7
for i in range(0,N,1):
    rem_power=(rem_power*(i+1)) % bignum
rem=rem_power


# logpower = math.log(1,bignum)
#
# for i in range(0,N,1):
#     print("hoge")a
#     plus=math.log((i+1),bignum)
#     rem_plus=plus-math.floor(plus)
#     logpower = logpower + rem_plus
#     logpower = logpower - math.floor(logpower)
#
# rem = bignum ** logpower

def output_parser(output):
    print(output)

output_parser(round(rem))

Measured memory_bytes: 3316
from itertools import accumulate

n = int(input())
a1 = list(accumulate(map(int, input().split())))
a2 = list(accumulate(map(int, input().split())))
s2 = a2[-1]
ans = a1[0]
for i in range(1, n):
    ans = max(ans, a1[i] - a2[i - 1])
print(ans + s2)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
    ll n;
    cin>>n;
    ll i=0;
    while(n>0){
        n=n-1000;
    }
    cout<<-n<<endl;
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;
#define OUT(v) cout<<v<<endl

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

  int count_S = 0, count_T = 0;
  for (const auto& e : X) {
    if (e == 'T') {
      if (count_S > 0)
        --count_S;
      else
        ++count_T;
    } else
      ++count_S;
  }
  OUT(count_S + count_T);

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n,a,b;
    scanf("%d",&n);
    for(a=1;a<10;a++)
    {
        for(b=1;b<10;b++)
        {
            if(n==a*b)
            {
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 128
N=int(input())
for i in range (1,N+1):
    a,b,c=map(int,input().split())
    x=max(a,b,c)
    y=min(a,b,c)
    z=a+b+c-x-y
    if x**2==y**2+z**2:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5596
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
#include <cmath>
#include <stack>
#include <bitset>

using namespace std;

#define int long long
#define MAX 1e18

signed main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int x = min(a, k);
    int y = min(b, k - x);
    int z = min(c, k - x - y);
    int ans = x - z;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
n = int(input())
s = input()
s += s[0]
pat = ["WW","WS","SW","SS"]

for j in pat:
    now = j
    flag = True
    for i in range(1,n+1):
        if (now[i] == "S" and s[i] == "o") or (now[i] == "W" and s[i] == "x"):
            now += now[i-1]
        else:
            if now[i-1] == "S":
                now += "W"
            else:
                now += "S"
    if now[0] == now[-2] and now[1] == now[-1]:
        print(now[:-2])
        exit()

print(-1)


Measured memory_bytes: 3572
import copy
def bubble(box,n):
    for i in range(n):
        p=n-1
        while p!=i:
            if box[p][1]<box[p-1][1]:
                box[p],box[p-1]=box[p-1],box[p]
            p -=1
    return box

def selection(box,n):
    for i in range(n):
        mini=i
        for j in range(i,n):
            if box[j][1]<box[mini][1]:
                mini=j
        if box[i][1]>box[mini][1]:
            box[i],box[mini]=box[mini],box[i]
    return box

n=int(input())
A=list(input().split())
B=copy.deepcopy(A)

bubble=bubble(A,n)
print(*A)
print("Stable")
selection=selection(B,n)
print(*B)
print("Stable" if A==B else "Not stable")


Measured memory_bytes: 6344
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

bool query(int a, int b){
	cout << "? " << a << " " << b << endl;
	string s; cin >> s;
	return s[0] == 'Y';
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int a, b; cin >> a >> b;
	if(a <= b){
		cout << "Impossible" << endl;
		return 0;
	}
	int cnt = b, n = a + b, nxt = 1;
	vi v(1);
	rep(i, n){
		if(query(v.back(), nxt)) v.pb(nxt++);
		else{
			nxt++; cnt--; v.pop_back();
			if(v.empty()) v.pb(nxt++);
		}
		if(v.size() > cnt) break;
	}
	string ans;
	rep(i, n) ans += query(v.back(), i) ? '1' : '0';
	cout << "! " << ans << endl;
	return 0;
}

Measured memory_bytes: 724
#include<stdio.h>
#include<iostream>
using namespace std;
#include<cstring>
const int N=400+5;
typedef long long LL;
const int Mod=1e9+7;
int main()
{
	int n,c;
	scanf("%d%d",&n,&c);
	static int a[N],b[N];
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	for(int i=1;i<=n;++i)scanf("%d",b+i);
	
	static LL s[N][N];
	for(int i=1;i<=400;++i)
	{
		s[i][0]=1;
		for(int j=1;j<=c;++j)s[i][j]=s[i][j-1]*i%Mod;
		for(int j=c;j>=0;--j)(s[i][j]+=s[i-1][j])%=Mod;
	}
	
	static LL f[N];
	f[0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=c;j>=0;--j)
		{
			(f[j]*=s[b[i]][0]-s[a[i]-1][0])%=Mod;
			for(int k=j;k;--k)(f[j]+=f[j-k]*(s[b[i]][k]-s[a[i]-1][k]))%=Mod;
		}
	}
	
	cout<<(f[c]+Mod)%Mod<<endl;
}

Measured memory_bytes: 1536
s, t = readlines.map(&:chomp)

kekka = t.size
schar = s.chars
tchar = t.chars

((s.size + 1) - t.size).times do |i|
  diff = 0
  tchar.each_with_index do |str, j|
	diff += 1 if str != schar[j+i]
  end
  kekka = [kekka, diff].min
end

p kekka

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

int main() {
  int N;
  string s, ans = "No";
  cin >> N >> s;
  
  if (N%2 == 0) {
    for (int i = 0; i < N/2; i++) {
      if (s[i] != s[N/2+i]) break;
      if (s[i] == s[N/2+i] && i == N/2-1) ans = "Yes";
    }
  }
  
  cout << ans << endl;;
}

Measured memory_bytes: 3612
p,q,r,s=map(int,input().split())
x=r-p
y=s-q
print('U'*y+'R'*x+'D'*y+'L'*x+'L'+'U'*(y+1)+'R'*(x+1)+'D'+'R'+'D'*(y+1)+'L'*(x+1)+'U')

Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		double r = in.nextDouble();

		//System.out.println((r*r*Math.PI) + " " + (2*r*Math.PI));
		System.out.printf("%.10f %.10f\n",(r*r*Math.PI),(2*r*Math.PI));

		//System.out.printf("%.10f %.10f\n",r*r*Math.PI,(2*r)*Math.PI)

	}

}



Measured memory_bytes: 28292
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

combination table(3e6);

lint number_in_box(int sum, int odd, int n){
    if((sum - odd) % 2){
        return 0;
    }else{
        int x = (sum - odd) / 2;
        return table.C(n + x - 1, x) * table.C(n, odd) % mod;
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    lint ans = 0;
    for(int i = 0; i <= M; i++){
        ans += number_in_box(3 * M, i, N);
        ans %= mod;
    }
    for(int i = 0; i <= M - 1; i++){
        ans += mod - number_in_box(M - 1, i, N - 1) * N % mod;
        ans %= mod;
    }
    for(int i = 0; i <= M; i++){
        ans += mod - number_in_box(M - 2, i, N) * N % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 47104
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const ll INF = 1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;
    vector<ll> dp(h+2, INF);
    dp[0] = 0;
    rep(i,n){
        int a, b;
        cin >> a >> b;
        rep(j,h+1){
            int id = max(0, j-a);
            chmin(dp[j], dp[id] + b);
        }
    }
    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

//mCk
modint calc(ll n, ll k) {
	modint res = 1;
	rep1(i, k) {
		res = res / (modint)i;
		res = res * (modint)(n + 1 - i);
	}
	return res;
}
void solve() {
	ll n, a, b; cin >> n >> a >> b;
	modint ans = mod_pow(2, n,mod)-1;
	ans -= calc(n, a);
	ans -= calc(n, b);
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
	return 0;
}


Measured memory_bytes: 4352
import random
import time
import numpy as np

def search(day, schedule, c, s, satisfy):
    score = 0
    date = [0] * 26
    for d in range(day):
        tmp = 0
        contest = 0
        nmax = -float('inf')
        for i in range(26):
            tmp += c[i] * (d + 1 - date[i])
        for i in range(26):
            tmp2 = s[d][i] - tmp + c[i] * (d + 1 - date[i])
            if nmax < tmp2:
                nmax = tmp2
                contest = i
        
        date[contest] = d + 1
        satisfy.append(tmp - c[contest] * (d + 1 - date[contest]))
        schedule.append(contest)
        score += s[d][contest] - satisfy[d]

    return score
    
# def decrease(day, schedule, c, s, satisfy):
#     ret = 0
#     date = [0] * 26

#     for d in range(day):
#         now = schedule[d] + 1
#         date[now - 1] = d + 1
#         tmp = 0
#         for i in range(26):
#             tmp += c[i] * (d+1 - date[i])
#         ret += tmp
#         satisfy.append(tmp)

#     return ret

def change(_from, _to, schedule, c, s, satisfy):
    ret = 0
    date = [0] * 26

    for d in range(_to):
        if d < _from:
            ret += satisfy[d]
            continue

        now = schedule[d] + 1
        date[now - 1] = d + 1
        tmp = 0
        for i in range(26):
            tmp += c[i] * (d+1 - date[i])
        ret += tmp
        satisfy[d] = tmp

    return ret

def Main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]
    
    dissatisfy=[]
    schedule = []
    score = 0
    start = time.time()

    #最大値を足すだけ
    # for i in range(D):
    #     schedule.append(np.argmax(s[i]))
    #     score += np.max(s[i])
    ans = search(D, schedule, c, s, dissatisfy)
    for i in range(D):
        score+=s[i][schedule[i]]
    
    while time.time() - start < 1.85:
        contest = random.randint(0, 25)
        day = random.randint(0, D - 1)
        if schedule[day] == contest:
            continue

        save = dissatisfy.copy()
        dec2 = change(day + 1, D, schedule, c, s, dissatisfy)
        score2 = score - s[day][schedule[day]] + s[day][contest]

        if ans < score2 - dec2:
            ans = score2 - dec2
            score = score2
            schedule[day] = contest
        else:
            dissatisfy = save

    for i in range(D):
        print(schedule[i] + 1)

if __name__ == "__main__":
    Main()

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

const long long MOD = 1000000007;
using ll = long long;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

void solve(long long N, long long M){
    COMinit();
    ll ans = (COM(M, N) * fac[N])% MOD % MOD;
    ll calc = 0;
    for(int i = 1;i <= N;i++){
        if(i % 2 == 1)calc += COM(N, i) % MOD * fac[N - i] % MOD * COM(M - i, N - i) % MOD;
        else calc -= COM(N, i) % MOD * fac[N - i] % MOD * COM(M - i, N - i) % MOD;
        calc += MOD;
        calc %= MOD;
    }
    //cout<<fac[N] * COM(M, N)<<endl;
    calc = fac[N] * COM(M, N) - calc;
    calc += MOD;
    calc %= MOD;
    cout<<ans * calc % MOD<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 15656
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

def get(x):
    return sum(map(int,str(x)))

n=int(input())
ans=10**9
for i in range(1,n):
    s=get(i)+get(n-i)
    if ans>s: ans=s
print(ans)

Measured memory_bytes: 44068
#include <cstdio>
const int MAXR = 10;
const int MAXC = 10000;
int R, C;
int a[MAXR][MAXC];
#include <algorithm>
void reverse(int x) {
    for (int i = 0; i < C; ++i)
        a[x][i] = !a[x][i];
}
int dfs(int cur) {
    int ans = 0;
    if (cur == R) {
        for (int j = 0; j < C; ++j) {
            int cnt = 0;
            for (int i = 0; i < R; ++i)
                cnt += a[i][j];
            ans += std::max(cnt, R - cnt);
        }
    }
    else {
        ans = dfs(cur + 1);
        reverse(cur);
        ans = std::max(ans, dfs(cur + 1));
        //reverse(cur);
    }
    return ans;
}
int solve() {
    return dfs(0);
}
int main() {
    while (scanf("%d%d", &R, &C), R) {
        for (int i = 0; i < R; ++i)
            for (int j = 0; j < C; ++j)
                scanf("%d", &a[i][j]);
        printf("%d\n", solve());
    }
    return 0;
}


Measured memory_bytes: 2944
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

void dfs(vector< vector<int> >& p, int c, int x, int y) {
	p[y][x] = 0;
	int h = p.size(), w = p[0].size();
	for (int k = 0; k < 4; k++) {
		int _x = x + dx[k], _y = y + dy[k];
		if (_x >= 0 && _x < w && _y >= 0 && _y < h && p[_y][_x] == c)
			dfs(p, c, _x, _y);
	}
}

int hoge(vector< vector<int> >& p, int c) {
	dfs(p, p[0][0], 0, 0);
	int h = p.size(), w = p[0].size(), cnt = 0;
	for (int y = 0; y < h; y++)
		for (int x = 0; x < w; x++)
			if (p[y][x] == 0) {
				p[y][x] = c;
				cnt++;
			}
	return cnt;
}

int main() {
	for (;;) {
		int h, w, c; cin >> h >> w >> c;
		if (h == 0) break;
		vector< vector<int> > p(h, vector<int>(w));
		for (int y = 0; y < h; y++)
			for (int x = 0; x < w; x++)
				cin >> p[y][x];
		int maxi = 0;
		for (int z = 0; z < 1296; z++) {
			int _z = z;
			vector< vector<int> > _p = p;
			for (int t = 0; t < 4; t++) {
				hoge(_p, 1 + _z % 6);
				_z /= 6;
			}
			hoge(_p, c);
			maxi = max(maxi, hoge(_p, 0));
		}
		cout << maxi << endl;
	}
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
main(){
    vector<int> G[100010],T[100010];
    queue<int> topological,zeroVertex;
    int out[100010]={},in[100010]={},dfs[100010]={};
    int p,n,m,a,b,k;
    cin>>n>>m;
    for(int i=0;i<n-1+m;i++){
        cin>>a>>b;
        G[a].push_back(b);
        T[b].push_back(a);
        out[a]++;
        in[b]++;
    }
    for(int i=1;i<n+1;i++){
        if(in[i]==0){
            zeroVertex.push(i);
            break;
        }
    }

    while(!zeroVertex.empty()){
        int x=zeroVertex.front();
        zeroVertex.pop();
        topological.push(x);
        for(int i=0;i<G[x].size();i++){
            k=G[x][i];
            in[k]--;
            if(in[k]==0){
                zeroVertex.push(k);
            }
        }
    }

    while(!topological.empty()){
        int x=topological.front();
        topological.pop();
        for(int i=0;i<G[x].size();i++){
            k=G[x][i];
            if(dfs[k]<dfs[x]+1)dfs[k]=dfs[x]+1;
        }
    }

  
    for(int i=1;i<n+1;i++){
        if(dfs[i]==0)cout<<0<<endl;
        else{
            for(int j=0;j<T[i].size();j++){
                if(dfs[T[i][j]]==dfs[i]-1){
                    cout<<T[i][j]<<endl;
                }
            }
        }
    }
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<double,double>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
///////

void solve(){
  ini(N,M);
  vi dp( (1 << N) , inf);

  rep(i,M){
    ini(a,b);
    int bit = 0;
    rep(_,b){
      ini(x); bit |= 1 << (x - 1);
    }
    amin(dp[bit] , a);
  }
  dp[0] = 0;
  // 高速ゼータ変換
  rep(i,N) rep(j,1<<N) if(!(j & (1 << i))){
    amin(dp[j] , dp[j | (1 << i)]);
  }
  //trc(dp);

  rep(i,1<<N){
    for(int j = i; j > 0 ; j = (j - 1) & i){
      amin(dp[i] , dp[i ^ j] + dp[j]);
    }
  }

  int ans;
  out((ans = dp[(1 << N) - 1]) == inf ? -1 : ans);
  
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int mycards[4][13] = {0};

	int n;
	cin >> n;

	char s;
	int number;
	for (int i = 0; i < n; i++) {
		cin >> s >> number;
		switch (s) {
		case 'S': mycards[0][number - 1] = 1; break;
		case 'H': mycards[1][number - 1] = 1; break;
		case 'C': mycards[2][number - 1] = 1; break;
		case 'D': mycards[3][number - 1] = 1; break;
		}
	}
	
	for (int j = 0; j < 4; j++) {
		for (int i = 0; i < 13; i++) {
			switch (j) {
			case 0:
				if (mycards[j][i] == 0) cout << "S " << i + 1 << "\n";
				break;
			case 1:
				if (mycards[j][i] == 0) cout << "H " << i + 1 << "\n";
				break;
			case 2:
				if (mycards[j][i] == 0) cout << "C " << i + 1 << "\n";
				break;
			case 3:
				if (mycards[j][i] == 0) cout << "D " << i + 1 << "\n";
				break;
			}
		}
	}
}

Measured memory_bytes: 1160
x=int(input())
l=[]
if x==2:
    print(2)
    exit()
for i in range(2,x):
    for j in l:
        if i%j==0:break
    else:
        l.append(i)
if x%2==0:x+=1
while True:
    for i in l:
        if x%i==0:
            x+=2
            break
    else:
        break
print(x)

Measured memory_bytes: 42648
#include <stdio.h>
int main(void){
  int n,i;
  scanf("%d",&n);
  int a[n];
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }
  int cnt = 0;
  int v[n];
  v[0] = a[0];
  for(i = 1; i < n; i++){
    v[i] = a[v[i-1]-1];
  }
  for(i = 0; i < n; i++){
    cnt++;
    if(v[i] == 2){
       printf("%d",i+1); break;
    }
  }
  if(cnt == n) printf("-1");
  return 0;
}


Measured memory_bytes: 896
def main():
	s=input()
	X,Y=map(int,input().split())
	p=[]
	F=T=0
	if s[0]=="T":
		p.append(0)
	for i in range(len(s)):
		if s[i]=="F":
			if T:
				p.append(T)
			T=0
			F+=1
		else:
			if F:
				p.append(F)
			F=0
			T+=1
	p.append(max(F,T))
	a=[]
	b=[]
	now=0
	for i in range(len(p)//2):
		if now==0:
			a.append(p[i*2])
		else:
			b.append(p[i*2])
		if p[i*2+1]%2==1:
			if now==0:
				now=1
			else:
				now=0
	if len(p)%2==1:
		if now==0:
			a.append(p[-1])
		else:
			b.append(p[-1])
	dp1=[0]*(2*len(s)+1)
	dp2=[0]*(2*len(s)+1)
	dp1[len(s)]=1
	dp2[len(s)]=1
	first=0
	for x in a:
		dp1_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp1_copy[i]=max(dp1[i-x],dp1_copy[i])
			if i+x<=2*len(s) and first:
				dp1_copy[i]=max(dp1[i+x],dp1_copy[i])
		dp1=dp1_copy.copy()
		first=1
	for x in b:
		dp2_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp2_copy[i]=max(dp2[i-x],dp2_copy[i])
			if i+x<=2*len(s):
				dp2_copy[i]=max(dp2[i+x],dp2_copy[i])
		dp2=dp2_copy.copy()
	print("Yes" if dp1[len(s)+X] and dp2[len(s)+Y] else "No")
if __name__ == '__main__':
	main()


Measured memory_bytes: 99160
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        x: usize,
    }
    println!("{}", 8 - (x - 400) / 200);
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const int INF = 1e+8+7;
ll n,m,l;
string s,t;
ll d[100],dp[500][500];
char field[100][100];

int main(){
  t = "";
  clr(dp,0);
  cin >> n;
  rep(i,0,n){
    cin >> s;
    rep(j,0,s.sz){
      dp[i][s[j]-'a']++;
    }
  }
  rep(i,0,26){
    bool f = false;
    m = INF;
    rep(j,0,n){
      if(dp[j][i] == 0){
        f = true;
        break;
      }
      m = min(m,dp[j][i]);
    }
    if(f)continue;
    rep(j,0,m){
      t += 'a'+i;
    }
  }
  print(t);
  return 0;
}

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

int main()
{
    int n,k,ar[113],i,ans,Max = 0;
    cin>>n>>k;
    for(i=1;i<=k;i++)
    {
        ar[i] = 1;
    }
    ans = n - k;
    ar[k] = ar[k] + ans;
    if(k==1)
    {
        cout<<"0"<<endl;
    }
    else
    {
        for(i=1; i<k; i++)
        {
            if((ar[i+1]-ar[i])>Max)
            {
                Max = ar[i+1] - ar[i];
            }
        }
        cout<<Max<<endl;
    }

    return 0;
}


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

        if(x%11<=6 && x%11!=0){
            System.out.println(x / 11 * 2 + 1);
        }
        else if(x%11>6 && x%11!=0){
            System.out.println(x / 11 * 2 + 2);
        }
        else if(x%11==0){
            System.out.println(x / 11 * 2);
        }
    }
}

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

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

  ll ans = 1e18;
  for (int i = 0; i < 1 << n; ++i) {
    vector<ll> aa = a;
    ll ma = aa[0];
    int cnt = 0;
    ll sum = 0;
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
	if (j > 0 && aa[j] <= ma) {
	  ll need = ma - aa[j] + 1;
	  sum += need;
	  aa[j] += need;
	}
      }
      if (j == 0 || aa[j] > ma) cnt++;
      ma = max(ma, aa[j]);
    }
    if (cnt >= k) ans = min(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256