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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAXE { 3 }, MAXN { 110 }, MAXK { 4 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll st[MAXN][MAXE][MAXK];

ll solve(const string& s, int K)
{
    int N = s.size();
    vector<int> ds(N);

    for (int i = 0; i < N; ++i)
        ds[i] = (s[i] - '0');

    memset(st, 0, sizeof st);

    for (int d = 1; d < ds[0]; ++d)
        st[0][0][1]++;

    st[0][0][0] = 1;
    st[0][1][1] = 1;

    for (int i = 1; i < N; ++i)
    {
        st[i][0][0] = 1;

        for (int k = 1; k <= 3; ++k)
        {
//cout << "i = " << i << ", k = " << k << ", ds[" << i << "] = " << ds[i] << endl;
            st[i][0][k] = st[i - 1][0][k];
//cout << "1. st[" << i << "][" << 0 << "][" << k << "] = " << st[i][0][k] << endl;
            st[i][0][k] += 9*st[i - 1][0][k - 1];
//cout << "2. st[" << i << "][" << 0 << "][" << k << "] = " << st[i][0][k] << endl;

            st[i][0][k] += (ds[i] ? st[i - 1][1][k] : 0);
//cout << "3. st[" << i << "][" << 0 << "][" << k << "] = " << st[i][0][k] << endl;

            for (int d = 1; d < ds[i]; ++d)
                st[i][0][k] += st[i - 1][1][k - 1];

            st[i][1][k] += (ds[i] == 0 ? st[i - 1][1][k] : 0);
            st[i][1][k] += (ds[i] ? st[i - 1][1][k - 1] : 0);
        }
    }

#ifdef DEBUG
    for (int i = 0; i < N; ++i)
        for (int k = 0; k <= 3; ++k)
            for (int e = 0; e < 2; ++e)
                cout << "st[" << i << "][" << e << "][" << k << "] = " << st[i][e][k] << endl;
#endif

    ll ans = st[N - 1][0][K] + st[N - 1][1][K];

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    string N;
    int K;

    cin >> N >> K;

    auto ans = solve(N, K);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;
int m;

int sum;

void input() {
  sum = 0;

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    int t;
    cin >> t;

    sum += t;
  }
}

void solve() {
  cout << max(-1, n - sum) << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 4;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

/*[DSU TEMPLATE] int dsu[501], ranks[501];

void resetDSU(){
    for(int i = 0; i < 501; ++i){
        dsu[i] = i; ranks[i] = 0;
    }
}
int find(int node){
    if(dsu[node] == node) return node;
    return dsu[node] = find(dsu[node]);
}
void combine(int a, int b){
    a = find(a); b = find(b);
    if(ranks[a] < ranks[b]){ dsu[a] = b; }
    else if(ranks[a] > ranks[b]){ dsu[b] = a; }
    else { dsu[a] = b; ranks[b]++; }
}*/

int counter[100002];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    int dup = 0, uni = 0;

    for(int i = 0; i < n; ++i){
        int j;
        cin >> j;
        counter[j]++;
        if(counter[j] > 1)
            dup++;
        else
            uni++;
    }

    if(dup % 2 == 1)
        --uni;

    cout << uni;

    return 0;
}


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

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

#define dist(x1,y1,x2,y2) (abs(x1-x2) + abs(y1-y2))
#define par(x) ((x)&1)

int main() {

	int n;
	cin >> n;

	int t,x,y;
	int pt=0, px=0, py=0, d;
	rep (i, n) {
		cin >> t >> x >> y;

		d = dist(px,py,x,y);
		if (d > t-pt || par(d) != par(t-pt))
			return log("No"), 0;

		pt=t, px=x, py=y;
	}

	log("Yes");

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
		if(a[i]>a[i+1]) {
			if(a[i]-a[i+1]>=2) {
				printf("No");
				return 0;
			}
			a[i+1]++;
		}
	printf("Yes");
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


int w,n;
vector<vi> v(1010,vi(1010,-1));
vector<pii> p(1010,pii(0,0));

void init(){
	rep(i,1010){
		rep(j,1010){
			v[i][j]=-1;
		}
	}
}

int calc(int i,int j){
	if(i>=n)return 0;
	if(v[i][j]!=-1)return v[i][j];
	int ret;
	if(j-p[i].se<0)ret=calc(i+1,j);
	else {
		ret=max(calc(i+1,j),p[i].fi+calc(i+1,j-p[i].se));
	}

	// rep(i,n){
	// 	rep(j,w+1){
	// 		printf("%3d ",v[i][j]);
	// 	}
	// 	cout<<endl;
	// }
	// cout<<endl;


	return v[i][j]=ret;
}

int main(){
	char c;
	int Case=0;
	int a,b;
	while(cin>>w && w>0){
		init();
		cin>>n;
		rep(i,n){
			cin>>p[i].fi>>c>>p[i].se;
		}
		a=calc(0,0);
		for(int i=1; i<=w; i++){
			//init();
			if(a<calc(0,i)){
				a=calc(0,i);
				b=i;
			}
		}
		
		cout<<"Case "<<(++Case)<<":"<<endl;
		cout<<a<<endl;
		cout<<b<<endl;
		
	}
}

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

int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  int ans=0;
  for(int i=0;i<k;++i){
    if(a>0){
      a--;
      ans++;
    }else if(a==0 && b>0){
      b--;
    }else{
      c--;
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
h,w,k = map(int,input().split())
li = [input() for _ in range(h)]

lis = [0]*h
for i in range(h):
  lis[i] = li[i].count("#")
#print(lis)
ans = [[0]*w for _ in range(h)]
Flag = True
top = 0
while Flag:
  if lis[top] == 0:
    top += 1
  else:
    Flag = False
#print(top)

cnt = 1
for i in range(top,h):
  if lis[i] == 0:
    for j in range(w):
      ans[i][j] = ans[i-1][j]
  else:
    cnt2 = 0
    Flag2 = True
    for j in range(w):
      ans[i][j] = cnt
      if li[i][j] == "#" and Flag2 == True:
        cnt += 1
        cnt2 += 1
      if cnt2 == lis[i] and Flag2 == True:
        Flag2 = False
        cnt -= 1
    cnt += 1

for i in reversed(range(top)):
  for j in range(w):
    ans[i][j] = ans[i+1][j]

for i in range(h):
  for j in range(w):
    print(ans[i][j],end=" ")
  print("")

Measured memory_bytes: 7580
import sys
k=int(input())
l=[]
x=7%k
if x == 0:
  print(1)
  sys.exit()
for i in range(2,k+1):
  num=(x*10+7)%k
  x=num
  l.append(num)
  if num==0:
    print(i)
    break
if 0 not in l:
  print(-1)

Measured memory_bytes: 48572
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main () {

    int N,K;
    cin >> N >> K;
    vector < ll > x(N);
    REP(i,N) cin >> x[i];

    ll ans = 1e18;
    for (int i = 0; i <= N - K; i++) {
        ll min_p = x[i];
        ll max_p = x[i + K - 1];
        if (min_p < 0 && max_p < 0) ans = min(ans, -min_p);
        if (min_p < 0 && max_p >= 0) {
            ll min_t = min(-min_p, max_p);
            ll max_t = max(-min_p, max_p);
            ans = min(ans, min_t * 2 + max_t);
        }
        if (min_p >= 0 && max_p >= 0) ans = min(ans, max_p);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int n,ans=0;
	cin >> n;
	vector<int> x(n);
	for(int i = 0 ; i < n ; i += 1){
		cin >> x[i];
	}
	int last = x[n-1],tot=0;
	for(int i = n-2 ; i >= 0 ; i -= 1){
		if(x[i] >= last){
			tot += 1;
		}else{
			ans = max(ans,tot);
			tot = 0;
		}
		last = x[i];
	}
	cout << max(ans,tot) << endl;
}

Measured memory_bytes: 640
#include <cstdio>

const int MN = 100005;

int N, L, A[MN];

int main() {
	scanf("%d%d", &N, &L);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	int ok = 0;
	for (int i = 1; i < N; ++i) if (A[i] + A[i + 1] >= L) ok = i;
	if (!ok) return puts("Impossible"), 0;
	puts("Possible");
	for (int i = 1; i < ok; ++i) printf("%d\n", i);
	for (int i = N - 1; i >= ok; --i) printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 1152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] arr = (in.nextLong() + "").toCharArray();

            int ans = 0;

            for (int i = 0; i < arr.length; i++) {
                if (arr[i] < '9') {
                    if (ans > 0) {
                        ans--;
                        ans += 9 * (arr.length - i);
                        out.println(ans);
                        return;
                    }
                    if (!restNines(arr, i + 1)) {
                        ans += arr[i] - '0' - 1;
                    } else {
                        ans += arr[i] - '0';
                    }
                    ans += 9 * (arr.length - i - 1);
                    out.println(ans);
                    return;
                }
                ans += 9;
            }

            out.println(ans);
        }

        private boolean restNines(char[] arr, int i) {
            if (i == arr.length) return true;
            for (int j = i; j < arr.length; j++) {
                if (arr[j] != '9') return false;
            }
            return true;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 23380
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

ans = []

def dfs(m):
    if m == 1:
        ans.append(1)
        return 0
    elif m == 2:
        ans.append(2)
        return 0
    elif m == 3:
        ans.append(2)
        ans.append(1)
        return 0
    elif m == 4:
        ans.append(3)
        ans.append(1)
        return 0
    elif m == 5:
        ans.append(3)
        ans.append(2)
        return 0
    else:
        k = ceil(sqrt(1+8*m))//2
        ans.append(k)
        dfs(m-k)

n = INT()
dfs(n)
for x in ans:
    print(x)

Measured memory_bytes: 13976
#include <stdio.h>

int eval1(char *exp)  // multiplication-first rule
{
	int result;
	int factor;
	int p;
	
	p = 0;
	
	result = 0;
	factor = exp[p++] - '0';
	
	while (exp[p] != '\0'){
		if (exp[p] == '+'){
			p++;
			result += factor;
			factor = exp[p++] - '0';
		}
		else if (exp[p] == '*'){
			p++;
			factor *= exp[p++] - '0';
		}
	}
	result += factor;
	
	return (result);
}

int eval2(char *exp)  //  left-to-right rule
{
	int result;
	int p;
	
	p = 0;
	
	result = exp[p++] - '0';

	while (exp[p] != '\0'){
		if (exp[p] == '+'){
			p++;
			result += exp[p++] - '0';
		}
		else if (exp[p] == '*'){
			p++;
			result *= exp[p++] - '0';
		}
	}

	return (result);
}

int main(void)
{
	char exp[20];
	int res1, res2;
	int bob;
	
	scanf("%s", exp);
	scanf("%d", &bob);
	
	res1 = eval1(exp);
	res2 = eval2(exp);

// printf("<%d %d>\n", res1, res2);
	
	
	if (res1 == bob && res2 == bob){
		printf("U\n");
	}
	else if (res1 == bob && res2 != bob){
		printf("M\n");
	}
	else if (res1 != bob && res2 == bob){
		printf("L\n");
	}
	else {
		printf("I\n");
	}
	
	return (0);
}

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

long long int N, dp[101010], c[12] = {1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049};

int main(){
    dp[0] = 0;
    fill(dp + 1, dp + 101010, 999999999);
    for(int i = 1; i < 101010; ++i){
        for(auto j : c){
            if(i >= j)dp[i] = min(dp[i], dp[i - j] + 1);
        }
    }
    scanf("%lld", &N);
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
p = list(map(int,input().split()))
l = [0]*3
count = 0
for i in range(1,n-1):
  l[0] = p[i-1]
  l[1] = p[i]
  l[2] = p[i+1]
  l.sort()
  if l[1] == p[i]:
    count += 1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int dice[6], x, i;
	char d[101];
	for(i = 0; i < 6; i++){
		scanf("%d", &dice[i]);
	}
	scanf("%s", d);
	for(i = 0; d[i] != '\0'; i++){
		if(d[i] == 'N'){
			x = dice[0];
			dice[0] = dice[1];
			dice[1] = dice[5];
			dice[5] = dice[4];
			dice[4] = x;
		} else if(d[i] == 'S'){
			x = dice[0];
			dice[0] = dice[4];
			dice[4] = dice[5];
			dice[5] = dice[1];
			dice[1] = x;
		} else if(d[i] == 'E'){
			x = dice[0];
			dice[0] = dice[3];
			dice[3] = dice[5];
			dice[5] = dice[2];
			dice[2] = x;
		} else if(d[i] == 'W'){
			x = dice[0];
			dice[0] = dice[2];
			dice[2] = dice[5];
			dice[5] = dice[3];
			dice[3] = x;
		}
	}
	printf("%d\n", dice[0]);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 998244353;

int main() {
    // your code goes here
    ll a,c=0;
    char b[10];
    cin >> a >> b;
    c+=(b[0]-'0')*100;
    c+=(b[2]-'0')*10;
    c+=(b[3]-'0')*1;
    c=a*c;
    cout << (c-c%100)/100 << endl;
    return 0;
}

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

int m,n,num[26]; char s[100009];
int main(){
	scanf("%d%d",&m,&n);
	int s1=(m>>1)*(n>>1),s2=(m&1)*(n>>1)+(m>>1)*(n&1),s3=m&n&1;
	int i,j;
	for (i=1; i<=m; i++){
		scanf("%s",s+1);
		for (j=1; j<=n; j++) num[s[j]-'a']++;
	}
	for (i=0; i<26; i++){
		while (num[i]>=4 && s1){ num[i]-=4; s1--; }
		while (num[i]>=2 && s2){ num[i]-=2; s2--; }
		while (num[i] && s3){ num[i]--; s3--; }
		if (num[i]) break;
	}
	puts(i<26?"No":"Yes");
	return 0;
}


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

int main() {
  int a, b, c, k, i;
  
  cin >> a >> b >> c >> k;
  
  if (a >= k) {
    cout << k << endl;
  }
  else if ((a + b) >= k) {
    cout << a << endl;
  }
  else {
    cout << a + - (k-(a+b)) << endl;
  }
}


Measured memory_bytes: 3596
from functools import reduce
import math


n = int(input())
l1  =  list(map(int,input().split()))
l2  =  list(map(int,input().split()))

sum1 = sum2 = sum3 = 0
max = 0
for i in range(0,n):
    sum1 += abs(l1[i] - l2[i])
    sum2 += pow(abs(l1[i] - l2[i]),2)
    sum3 += pow(abs(l1[i] - l2[i]),3)
    if ( max < abs(l1[i] - l2[i])):
        max = abs(l1[i] - l2[i])


print (sum1)
print (math.sqrt(sum2))
print (math.pow(sum3,1.0/3.0))
print (max*1.0)



Measured memory_bytes: 6356
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
r, d, x = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

ans = []
for i in range(1,11):
    x = r*x - d
    ans.append(x)
print(*ans)

Measured memory_bytes: 9164
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();

    int[] dp = new int[n];

    List<Integer>[] lists = new ArrayList[n];

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        for (int i=0; i<n; i++) lists[i] = new ArrayList<>();
        for (int i=0; i<m; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            lists[x].add(y);
        }

        Arrays.fill(dp, -1);

        int ret = 0;
        for (int i=0; i<n; i++) ret = Math.max(ret, rec(i));

        System.out.println(ret);

//        for (int i=0; i<n; i++) System.out.println(dp[i]);

    }

    int rec(int v) {
        if (dp[v] != -1) return dp[v];

        int ret = 0;
        for (int nv: lists[v]) {
            ret = Math.max(ret, rec(nv) + 1);
        }
        dp[v] = ret;
        return dp[v];
    }
}



Measured memory_bytes: 102444
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a-b==b-c){//按公式模拟
    cout<<"YES";//谁抄谁稻花香里说丰年
    return 0;
    }
    cout<<"NO"<<endl;//谁抄谁稻花香里说丰年
    return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba") {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
    return 0;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BNiceShopping solver = new BNiceShopping();
        solver.solve(1, in, out);
        out.close();
    }

    static class BNiceShopping {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 最小値同士か割引を試せばよい
            int a = in.nextInt();
            int b = in.nextInt();
            int m = in.nextInt();
            int[] ref = new int[a];
            int[] wav = new int[b];
            int mre = Integer.MAX_VALUE;
            int mwa = Integer.MAX_VALUE;
            int res = Integer.MAX_VALUE;
            for (int i = 0; i < a; i++) {
                ref[i] = in.nextInt();
                mre = Math.min(mre, ref[i]);
            }
            for (int i = 0; i < b; i++) {
                wav[i] = in.nextInt();
                mwa = Math.min(mwa, wav[i]);
            }

            res = Math.min(res, mre + mwa);

            for (int i = 0; i < m; i++) {
                int x = in.nextInt() - 1;
                int y = in.nextInt() - 1;
                int n = in.nextInt();
                res = Math.min(res, ref[x] + wav[y] - n);
            }

            out.println(res);
        }

    }
}



Measured memory_bytes: 131672
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  vector<int> ls(n+1), lt(m+1);
  for (int i = 0; i < n; ++i) {
    ls[i+1] = ls[i];
    if (s[i] == 'A') ls[i+1] += 1;
    else ls[i+1] += 2;
    ls[i+1] %= 3;
  }
  for (int i = 0; i < m; ++i) {
    lt[i+1] = lt[i];
    if (t[i] == 'A') lt[i+1] += 1;
    else lt[i+1] += 2;
    lt[i+1] %= 3;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) { 
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int is = (ls[b]-ls[a-1]+3)%3;
    int it = (lt[d]-lt[c-1]+3)%3;
    if (is == it) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

}


Measured memory_bytes: 1664
while True:
    n, p = [ int(i) for i in input().split() ]

    if n == p == 0:
        break

    # print("start: ", n, p)

    leaders = [0] * n
    result = 0
    index = 0
    stone_num = p

    while True:

        if stone_num > 0:
            leaders[index] += 1
            stone_num -= 1

            # ??¨??¨????????£??????????????????
            if leaders[index] == p:
                result = index
                break
                
        elif leaders[index] > 0:
            stone_num = leaders[index]
            leaders[index] = 0

        index = (index + 1) % n


    print(result)

Measured memory_bytes: 7696
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto a = aryread();
    auto up = new long[](n);
    foreach (e; a)
    {
        up[e - 1]++;
    }
    foreach (e; up)
        e.writeln();
}

bool is_exist(string s, char c)
{
    return (s.countUntil(c) >= 0);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 11660
package main

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

var (
	scanner *bufio.Scanner
	buffer  *bufio.Writer
	writer  io.Writer
)

func main() {
	defer flush()
	initWordScanner()
	initBufWriter()

	a := readInt()
	b := readInt()
	c := readInt()
	x := readInt()

	for i := 0; i <= x; i++ {
		for j := 0; j <= x-i; j++ {
			for k := 0; k <= x-i-j; k++ {
				ta := a * int(math.Pow(2, float64(i)))
				tb := b * int(math.Pow(2, float64(j)))
				tc := c * int(math.Pow(2, float64(k)))
				if ta < tb && tb < tc {
					println("Yes")
					flush()
					os.Exit(0)
				}
			}
		}
	}

	println("No")
}

func initLineScanner() {
	scanner = bufio.NewScanner(os.Stdin)
	buf := make([]byte, 1e4)
	scanner.Buffer(buf, bufio.MaxScanTokenSize)
}

func initWordScanner() {
	initLineScanner()
	scanner.Split(bufio.ScanWords)
}

func readLine() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func readInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func readFloat() float64 {
	scanner.Scan()
	n, err := strconv.ParseFloat(scanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func readRunes() []rune {
	scanner.Scan()
	var ns []rune
	for _, v := range scanner.Text() {
		ns = append(ns, v)
	}
	return ns
}

func readString() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func readStrings() []string {
	scanner.Scan()
	var ss []string
	for _, v := range scanner.Text() {
		ss = append(ss, string(v))
	}
	return ss
}

func initWriter() {
	buffer = nil
	writer = os.Stdout
}

func initBufWriter() {
	buffer = bufio.NewWriter(os.Stdout)
	writer = buffer
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(writer, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(writer, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func flush() {
	if writer != nil {
		buffer.Flush()
	}
}

func string2int(s string) int {
	n, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return n
}

func int2string(n int) string {
	s := strconv.Itoa(n)
	return s
}

func string2float(s string) float64 {
	n, e := strconv.ParseFloat(s, 64)
	if e != nil {
		panic(e)
	}
	return n
}

func sum(ns []int) int {
	s := 0
	for _, n := range ns {
		s += n
	}
	return s
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

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


Measured memory_bytes: 1776
import math
a, b, h, m = list(map(int, input().split()))

deg_m = (m / 60) * 360
deg_h = ((60 * h + m) / 720) * 360
deg = abs(deg_h - deg_m)
deg = math.radians(min(360 - deg, deg))
x2 = b ** 2 + a ** 2 - 2 * b * a * math.cos(deg)

print(x2**0.5)

Measured memory_bytes: 9452
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      if(n<3){cout<<0; return 0;}
      ll dp[n+1]={0,0,0,1};
      for(int i=4;i<=n;i++){
        dp[i]=1;
        for(int j=0;j<=i-3;j++){
          dp[i]=(dp[i]+dp[j])%M;
        }
      }
      cout<<dp[n];
}

Measured memory_bytes: 3648
import math
import fractions
from functools import reduce

n,x = map(int,input().split())
xList=list(map(int,input().split()))

saList=[]
for i in range(len(xList)):
  saList.append(abs(x-xList[i]))

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
print(gcd_list(saList))

Measured memory_bytes: 16308
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

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


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        vector<ll> d(n + 1);
        REPS(i, n) {
            cin >> d[i];
            d[i] += d[i - 1];
        }
        ll sum = d.back();
        auto nearest = [&](ll x, int l, int r) {
            auto i = upper_bound(d.begin() + l, d.begin() + r, x) - d.begin();
            if (i == r) return d[i - 1];
            if (i == l) return d[i];
            if (abs(x - d[i]) < abs(x - d[i - 1])) return d[i];
            return d[i - 1];
        };
        ll ans = sum;
        for(int i=2;i+2<=n;i++) {
            REP(k, 4) {
                ll center = d[i];
                ll lc = nearest((center + !!(k & 1)) / 2, 1, i);
                ll rc = nearest(center + (sum - center + !!(k & 2)) / 2, i + 1, n);
                if (lc <= 0 || center <= lc || rc <= center || sum <= rc) continue;
                ans = min(ans, max({lc, center - lc, rc - center, sum - rc}) -
                               min({lc, center - lc, rc - center, sum - rc}));
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
    int c1x,c2x,c1y,c2y,c1r,c2r;
    int d,r1,r2;

    cin >> c1x >> c1y >> c1r;
    cin >> c2x >> c2y >> c2r;

    d = (c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y);
    r1 = (c1r+c2r)*(c1r+c2r);
    r2 = (c1r-c2r)*(c1r-c2r);

    if(d > r1) cout << 4 << endl;
    else if(d == r1) cout << 3 << endl;
    else if(d < r1 && d > r2) cout << 2 << endl;
    else if(d == r2) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    vector<int> v(N);
    set<int> s;
    rep(i, N){
        cin >> v[i];
        s.insert(v[i]);
    }
    int base = v.size();
    int ans = s.size();

    if(base == ans){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
void Main(){
    int A = read(), B = read();
    printf("%d\n", max(A+max(B,A-1),B+max(A,B-1)));
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()

    ans = 1-(N//2)/N
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define per(i,l,r) for (int i=l;i>=r;i--)
typedef long long ll;
using namespace std;
const int maxn=100500;
const ll mm=1e9+7;
int n,m;
ll fac[maxn],inv[maxn],r[maxn],a[maxn],sum[maxn];
ll ans;
ll Pow(ll x,ll y){
    ll ans=1;
    while (y){
        if (y&1) ans=ans*x%mm;
        x=x*x%mm;
        y/=2;
    }
    return ans;
}
int main(){
    scanf("%d",&n);
    int N=100000;
    fac[0]=1; rep(i,1,N) fac[i]=fac[i-1]*i%mm;
    inv[N]=Pow(fac[N],mm-2); per(i,N,1) inv[i-1]=inv[i]*i%mm;
    r[0]=1; per(i,N,1) r[i]=inv[i]*fac[i-1]%mm;
    rep(i,1,n) scanf("%lld",&a[i]);
    rep(i,1,n) sum[i]=(sum[i-1]+fac[n]*r[i]%mm)%mm;
    ll ans=0;
    rep(i,1,n) (ans+=(sum[i]+sum[n-i+1]-fac[n]+mm)%mm*a[i]%mm)%=mm;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main (){ 
    int n,d ;
    long long int ara[100];
    cin >> n;
    ara[0]= 2;
    ara[1]= 1;

    for (int i = 2 ; i <= n ;i++ )
    	ara[i]= ara[i-1]+ ara[i-2];

     cout <<  ara[n] << endl;
   
return 0;

}	

Measured memory_bytes: 256
def resolve():
    n=int(input())
    A=[int(i) for i in input().split()]
    def check(A,flag): # flag=Trueなら上から、Falseなら下から
        cumsum=0
        ans=0
        for a in A:
            cumsum+=a
            if cumsum<=0 and flag:
                ans+=1-cumsum
                cumsum=1
            elif cumsum>=0 and (not flag):
                ans+=1+cumsum
                cumsum=-1
            flag = (not flag)
        return ans
    print(min(check(A,True),check(A,False)))
resolve()

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

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> ans(n, k - q);
    for (int i = 0; i < q; i++) {
        int idx;
        cin >> idx;
        ans[idx - 1]++;
    }
    for (int i = 0; i < n; i++) {
        cout << (ans[i] > 0 ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

using namespace std;


int ans[200009];


int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		if (a == 1)
		{
			ans[b]++;
		}
		if (b == 1)
		{
			ans[a]++;
		}
		if (a == n)
		{
			ans[b]++;
		}
		if (b == n)
		{
			ans[a]++;
		}
		if (ans[b] == 2 || ans[a] == 2)
		{
			printf("POSSIBLE");
			return 0;
		}
	}
	printf("IMPOSSIBLE");
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define PI (acos(-1))
#define M_E (2.718281828459045)
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 200005
ll dp[asz][13];
ll solve(ll ind,ll m,string &s,ll ml)
{
    if(ind==-1)return m==5;
    if(dp[ind][m]!=-1)return dp[ind][m];
    if(s[ind]!='?')
        return dp[ind][m]=solve(ind-1,(m+ml*(s[ind]-'0'))%13,s,ml*10%13);
    dp[ind][m]=0;
    for(ll i=0;i<10;i++)
    {
        dp[ind][m]+=solve(ind-1,(m+ml*i)%13,s,ml*10%13);
        dp[ind][m]%=mod;
    }
    return dp[ind][m];
}
int main()
{
    fastread;
    string s;
    cin>>s;
    memset(dp,-1,sizeof dp);
    cout<<solve((ll)s.size()-1,0,s,1)<<endl;
    return 0;
}


Measured memory_bytes: 28752
#include<bits/stdc++.h>
using namespace std;
#if defined __has_include
# if __has_include(<bits/debug_aamir.h>)
#  define dbg(...) DEBUG(#__VA_ARGS__, __VA_ARGS__);
#  include<bits/debug_aamir.h>
# else
#  define dbg(...)
# endif
#endif

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll, ll> pll;
#define sz(x) int(x.size())
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define rep(i, begin, end) for(__typeof(begin) i=begin; i<end; i++)
#define per(i, begin, end) for(__typeof(begin) i=begin; i>=end; i--)
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;


template<typename T>
T gcd(T a, T b){	return b ? gcd(b, a%b): a; }
template<typename T>
T lcm(T a, T b){	return a/gcd(a, b) * b;		}

const int nax=102, vax=1e5+10;
vector<vi> dp(nax, vi(vax, INF));
vii vw(nax);

int main()
{
	fastio;
	int n, W;
	cin >> n >> W;
	rep(i, 0, n)	cin >> vw[i].se >> vw[i].fi;
	dp[0][0] = 0;
	rep(i, 0, n){
		rep(j, 0, vax){
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]); // Not selecting current.
			if(dp[i][j]+vw[i].se <= W && j+vw[i].fi<vax)
				dp[i+1][j+vw[i].fi] = min(dp[i+1][j+vw[i].fi], dp[i][j] + vw[i].se);
		}
	}
	for(int i=vax-1; i>=0; i--)	if(dp[n][i] <= W){
		printf("%d\n", i);
		break;
	}
}



Measured memory_bytes: 43444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

ll dp[100010][13]={0};

long long modpow(long long a, long long n, long long mod) {//a^n(mod)を求める
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;//次の準備
        n >>= 1;
    }
    return res;
}

signed main(){
  string s;cin>>s;
  reverse(all(s));

  if(s.at(0)=='?')rep(i,10)dp[0][i]=1;
  else dp[0][s[0]-'0']=1;

  for(int i=1;i < siz(s);i++)
  {
    if(s.at(i)=='?'){
      for(int j=0;j < 13;j++)
      {
        for(int k=0;k < 10;k++)//?
        {
          (dp[i][(j+modpow(10,i,13)*k)%13]+=dp[i-1][j]) %=mod; 
        }
      }
    }else{
      int x=s[i]-'0';
      for(int j=0;j < 13;j++)
      {
        (dp[i][(j+modpow(10,i,13)*x)%13]+=dp[i-1][j]) %=mod;
      }
    }
  }

  cout<<dp[siz(s)-1][5]<<endl;

}

Measured memory_bytes: 10624
def StrongConnectedComponent(g,S):
    from collections import deque
    S = deque() #逆辺で帰りがけが遅い順にpopされるスタック
    #まず逆辺でDFS、帰りがけに S に積む
    q = deque()
    n = len(g)
    gp = [1]*n # 1 -> 0 -> -1
    for i in range(n):
        if gp[i] == 1:
            q.append(i)
            while q:
                v = q.pop()
                #帰りがけ
                if v < 0:
                    if gp[~v] == 0:
                        gp[~v] = -1
                        S.append(~v)
                #未処理
                elif gp[v] == 1:
                    q.append(~v)
                    gp[v] = 0
                    for c in rg[v]:
                        # 子が未処理
                        if gp[c] == 1:
                            q.append(c)
    q = deque()
    gp = [-1]*n
    # Sのpop順にDFS
    #この段階で gp = [-1]*n（使いまわす）
    g_scc = []
    cnt = 0
    while S:
        v = S.pop()
        if gp[v] == -1:
            q.append(v)
            gp[v] = cnt
            sv = set()
            while q:
                w = q.pop()
                for c in g[w]:
                    if gp[c] == -1:
                        q.append(c)
                        gp[c] = gp[w]
                    elif gp[c] != cnt:
                        sv.add(gp[c])
            cnt += 1
            g_scc.append(sv)

    return gp, g_scc

###########################################################################                        
###########################################################################                        

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,*w = [int(i) for i in read().split()]

n,m = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
rg = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int, readline().split())
    g[a].append(b)
    rg[b].append(a)



gp, scc = StrongConnectedComponent(g,rg)

#print(gp)
#print(scc)


v = max(gp)+1
ans = [[] for _ in range(v)]
for i, gpi in enumerate(gp):
    ans[gpi].append(i)

print(v)
for lst in ans[::-1]:
    print(len(lst), end=" ")
    print(*lst)


Measured memory_bytes: 324360
#include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+7,MOD=1e9 + 7;
void solve(){
    set<int>s;
    int n,k;cin>>n>>k;
    for(int i=0;i<k;i++){
        int d;cin>>d;
        while(d--){
            int x;cin>>x;
            s.insert(x);
        }
    }
    cout<<n-s.size()<<endl;
}
int main (){
    int t=1;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3640
N = int(input())
S = list(input())

ans = 10**9

T = "#."
W = '.'
B = '#'

dp_blk = [0]*(N+1)
dp_wht = [0]*(N+1)

if all([B==c for c in S]) or all([W==c for c in S]):
    print(0)
    exit(0)

for ix in range(N):
    if S[ix] == B:
        dp_blk[ix+1] += dp_blk[ix] + 1
        dp_wht[ix+1] += dp_wht[ix]
    else:
        dp_wht[ix+1] += dp_wht[ix] + 1
        dp_blk[ix+1] = dp_blk[ix]

# print("dp_blk", dp_blk)
# print("dp_wht", dp_wht)

for lix in range(N+1):
    b_flip = dp_blk[lix]
    w_flip = dp_wht[N] - dp_wht[lix]
    flip = b_flip + w_flip
    # print(lix, flip)
    if ans > flip:
        ans = flip

# ab = N - dp_blk[N]
# aw = N - dp_wht[N]
# ans = min(ab, aw, ans)
    
print(ans)

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

int main() {
    int K,A,B;
    cin >> K;
    cin >> A >> B;
    int i=A;
    int counter=0;
    while(i<B+1){
        
        if (i%K==0){
            counter=1;
        }
        i++;

    }
    if(counter==1){
        cout << "OK" <<endl;

    }
    else{
        cout << "NG" <<endl;
    }
  
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  
  int h;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> h;
    if (K <= h) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;

int main()
{
	ll a,b,x;
	cin >> a >> b >> x;
	ll cnt = 0, i;
	ll a1, b1;
	a1 = ((a + x - 1) / x) * x;
	cnt = (b - a1 + x) / x;	
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
Str = input()
N = False
W = False
S = False
E = False

for i in Str:
    if i == 'N':
        N = True
    if i == 'W':
        W = True
    if i == 'S':
        S = True
    if i == 'E':
        E = True
if (N == True and S == False) or (N == False and S == True):
    print("No")
elif (W == True and E == False) or (W == False and E == True):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
inline int read() {
	int f=1,sum=0;
	char x=getchar();
	for(;(x<'0'||x>'9');x=getchar()) if(x=='-') f=-1;
	for(;x>='0'&&x<='9';x=getchar()) sum=sum*10+x-'0';
	return f*sum;
}

#define M 105
int n;
int tot,a[M];

int main () {
//freopen("a.in","r",stdin);
	n=read(),tot=read();
	for1(1,n,i) a[i]=read();
	sort(a+1,a+n+1);
	int ans=0;
	for1(1,n-1,i) if(tot>=a[i]) ++ans,tot-=a[i];
	if(tot==a[n]) ++ans;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>

int main(void)
{
    int w, h, x, y ,r;
    std::cin >> w >> h >> x >> y >> r;
    if((y+r > h)||(y-r < 0)||(x+r > w)||(x-r < 0))
        std::cout << "No" << std::endl;
    else
        std::cout << "Yes" << std::endl;
    return 0;
}


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

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

    for (int i = 0; i < s.length(); i++) {
        if (s.at(i) != t.at(i)) {
            cout << "No" << endl;
            return 0;
        }
    }

    if (t.length() != s.length() + 1) {
        cout << "No" << endl;
        return 0;        
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

long long go(std::vector<long long> a) {
	int n = (int) a.size();
	long long ans = 0;
	while(1) {
		long long got = 0;
		for(auto &x : a) {
			got += x / n;
			x = (x % n) - x / n;
		}
		ans += got;
		if(got == 0) break;
		for(auto &x : a) {
			x += got;
		}
	}
	return ans;
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	long long k;
	std::cin >> k;
	int n = 50;
	std::vector<long long> ans(n, (k / n) + (n - 1));
	for(int i = 0; i < (int) (k % n); i++) {
		ans[i] += n;
		for(int j = 0; j < n; j++) {
			if(i != j) ans[j] = std::max(0LL, ans[j] - 1);
		}
	}
	std::cout << n << '\n';
	for(int i = 0; i < n; i++) {
		std::cout << ans[i] << (i + 1 == n ? '\n' : ' ');
	}
	//std::cout << "got " << go(ans) << " should be " << k << '\n';
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s; cin >> s;
    map<char,int> mp;
    rep(i,s.size())mp[s[i]]++;
    ll res = min(mp['0'],mp['1']);
    cout << res * 2 << endl;
}


Measured memory_bytes: 512