akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>

int main() {
    string s;
    cin >> s;
    int l = s.length();
    vector<int> ans(l, 0);
    int cnt;
    
    rep(i, 2) {
        cnt = 0;
        
        rep(ii, l) {
            if (s[ii] == 'R') {
                cnt++;
            }
            else {
                ans[ii - 1] += (cnt + 1) / 2;
                ans[ii] += cnt / 2;
                cnt = 0;
            }
        }
        
        reverse(s.begin(), s.end());
        reverse(ans.begin(), ans.end());
        
        rep(ii, l) {
            s[ii] = ((s[ii] == 'R') ? 'L' : 'R');
        }
    }
    
    rep(i, l) {
        cout << (i ? " " : "") << ans[i];
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

    int ans = 0;
    for (int i = 0; i <= n-3; ++i) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int y = scanner.nextInt();
        if (y % 1000 != 0) System.out.println("-1 -1 -1");
        else {
            y/=1000;
            int tens = -1, fives = -1, ones = -1;
            boolean found = false;
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= n; j++) {
                    int a = 10*i + 5*j;
                    if (a >= 0 && a <= y && (i + j + y - a) == n){
                        tens = i; fives = j; ones = y - a;
                        found = true;
                        break;
                    }
                }
                if (found) break;
            }
            if (found) System.out.println(tens + " " + fives + " " + ones);
            else System.out.println("-1 -1 -1");
        }
        
    }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long
#define inf 10000000

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

vector<int> A, B;
int n;

void read_in() {
	scanf("%d", &n);
	int a, b;
	for (int i = 0; i < n; ++i) {
		// scanf("%d%d", &a, &b);
		// A.push_back(a);
		// B.push_back(b);
		scanf("%d", &a);
		A.push_back(a);
	}
	for (int i = 0; i < n; ++i) {
		// scanf("%d%d", &a, &b);
		// A.push_back(a);
		// B.push_back(b);
		scanf("%d", &b);
		B.push_back(b);
	}
}
class Card {
public:
	int val;
	int n;
	Card(int _val, int _n): n(_n), val(_val) {}
};
bool cmpc(const Card &a, const Card &b) {
	return a.val < b.val;
}
vector<int> getS(int S) {
	vector<int> res;
	vector<int> resa;
	res.clear();
	vector<Card> odd, even;
	for (int i = 0; i < n; ++i) {
		if ((i % 2) ^ ((S >> i) & 1)) {
			odd.push_back(Card((((S >> i) & 1) ? B[i] : A[i]), i));
		}
		else {
			even.push_back(Card((((S >> i) & 1) ? B[i] : A[i]), i));
		}
	}
	// cout << "S = " << S << endl;
	// cout << odd.size() << ' ' << even.size() << endl;
	int oddn = n / 2, evenn = (n + 1) / 2;
	if (oddn != odd.size() || evenn != even.size()) {
		return res;
	}
	sort(odd.begin(), odd.end(), cmpc);
	sort(even.begin(), even.end(), cmpc);
	for (int i = 0; i < n; ++i) {
		if (i % 2) {
			res.push_back(odd[i / 2].n);
			resa.push_back(odd[i / 2].val);
		}
		else {
			res.push_back(even[i / 2].n);
			resa.push_back(even[i / 2].val);
		}
	}
	for (int i = 0; i < n - 1; ++i) {
		if (resa[i] > resa[i + 1]) {
			return vector<int>();
		}
	}
	return res;
}

void calc() {
	int res = inf;
	for (int S = 0; S < (1 << n); ++S) {
		vector<int> od = getS(S);
		if (od.size() == 0) {
			continue;
		}
		int dis = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (j < i && od[j] > od[i]) {
					++dis;
				}
				if (j > i && od[j] < od[i]) {
					++dis;
				}
			}
		}
		res = min(res, dis / 2);
	}
	if (res == inf) {
		cout << (-1) << endl;
	}
	else {
		cout << res << endl;
	}
}
int main() {
	read_in();
	calc();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define f first
#define s second

vi c[100005];
bool visit[100005];
int ind[100005];
int dp[100005];

void dfs(int x){
	visit[x] = true;
	for(int y : c[x]){
		dp[y] = max(dp[y], dp[x] + 1);
		ind[y]--;
		if(ind[y] == 0){
			dfs(y);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int a, b;
		cin >> a >> b;
		c[a].pb(b);
		ind[b]++;
	}	
	for(int i = 1; i <= n; i++){
		if(!visit[i] && !ind[i]){
			dfs(i);
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

int main()
{
	int A,B,X;

	cin >> A >> B >> X;

	if (X >= A && X - A <= B) {
		std::cout << "YES";
	}
	else {
		std::cout << "NO";
	}
		

	//printf("%.9f", ans);
	//std::cout << "Yes";

	return 0;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}
	return s
}

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	s, _ := nextString(), nextString()
	a, b := nextInt(), nextInt()
	u := nextString()
	if u == s {
		fmt.Printf("%d %d\n", a-1, b)
	} else {
		fmt.Printf("%d %d\n", a, b-1)
	}
}


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


int main()
{
	int x, y;
	cin >> x >> y;

	while (x != 0 || y != 0){
		if (x <= y){
			cout << x << " " << y << endl;
		}
		else{
			cout << y << " " << x << endl;
		}

		cin >> x >> y;
	}
	
	return 0;
}


Measured memory_bytes: 3080
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
p.sort(reverse=True)
topP = p[:X]

q = list(map(int, input().split()))
q.sort(reverse=True)
topQ = q[:Y]

r = list(map(int, input().split()))
r.sort(reverse=True)

concat = topP + topQ + r
concat.sort(reverse=True)
top = concat[:X+Y]

print(sum(top))

Measured memory_bytes: 24852
import itertools
x = int(input())
a = x // 100
b = x - a * 100
arr = [0, 1, 2, 3, 4, 5]
ans = 0
for v in itertools.combinations_with_replacement(arr, a):
    k = sum(list(v))
    if k == b:
      ans = 1
      break
print(ans)

Measured memory_bytes: 9040
# ITP1_5_C
# チェスボードの描画

while 1:
	H, W = map(int, input().split())
	if H == W == 0:
		break
	for i in range(H):
		for j in range(W):
			if (i + j) % 2 == 0:
				print("#", end="")
			else:
				print(".", end="")
		print()
	print()



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

if n < 2:
    print(n)
elif 2 <= n < 4:
    print(2)
elif 4 <= n < 8:
    print(4)
elif 8 <= n < 16:
    print(8)
elif 16 <= n < 32:
    print(16)
elif 32 <= n < 64:
    print(32)
elif 64 <= n:
    print(64)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
#define inf 1e12+7
typedef long long ll;


int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    if(a1 + a2 + a3 >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}


Measured memory_bytes: 256
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, m = 0, x = 0, y = 0;
	cin >> n >> m;
	vector<int> deg(n, 0);
	for (int i = 0; i < m; ++i)
	{
		cin >> x >> y;
		++deg[x]; ++deg[y];
	}
	for (auto &i : deg)
		if (i & 1)
		{
			cout << "NO" << endl;
			return 0;
		}
	cout << "YES" << endl;
}

Measured memory_bytes: 3716
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main(){

double A,B,H,M;
cin>>A>>B>>H>>M;
double A_x,A_y,B_x,B_y;


A_x = A*cos(PI/2-H/12*2*PI-M/60*2*PI/12);
A_y = A*sin(PI/2-H/12*2*PI-M/60*2*PI/12);
B_x = B*cos(PI/2-M/60*2*PI);
B_y = B*sin(PI/2-M/60*2*PI);

double ans = sqrt(pow((A_x - B_x),2)+ pow((A_y - B_y),2));

cout << fixed << setprecision(20) << ans << endl;
return 0;

}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define A first
#define B second
#define db double
#define lowbit(p) (p&(-p))
using namespace std;
inline void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
#define M 100005
map< int,int >id[M];
struct ed{
	int x,l,nx;
}e[M*12];
int nx[6*M],dis[6*M],n,m,ecnt=1;
bool mark[6*M];
int tot,r[2],Q[2][6*M];
inline void add(int x,int y,int l){
	e[ecnt]=(ed){y,l,nx[x]};
	nx[x]=ecnt++;
}
void bfs(int s,int t){
	int x,now=0,i,tmp;
	memset(dis,63,sizeof(dis));
	dis[s]=0;
	Q[now][++r[now]]=s;
	
	for (;r[now];now=!now){
		for (;r[now];){
			x=Q[now][r[now]--];
			if (mark[x])continue;
			mark[x]=1;
			if (x==t){
				printf("%d\n",dis[t]);
				return ;
			}
			for (i=nx[x];i;i=e[i].nx){
				if (dis[x]+e[i].l<dis[e[i].x]){
					dis[e[i].x]=dis[x]+e[i].l;
					tmp=now^e[i].l;
					Q[tmp][++r[tmp]]=e[i].x;
				}
			}
		}
	}
	printf("-1\n");
}
inline int cal(int x,int col){
	int &res=id[x][col];
	if (res)return res;
	res=++tot;
	add(x,res,1);
	add(res,x,0);
	return res; 
}
int main(){
	int Caseid;
// 	freopen("8.in","r",stdin);
//	read(Caseid);
	read(n); read(m);	
	int i,x,y,c;
	tot=n;
	for (i=1;i<=m;i++){
		read(x); read(y); read(c);
		x=cal(x,c);
		y=cal(y,c);
		add(x,y,0);
		add(y,x,0);
	}
	bfs(1,n);
	return 0;
}

Measured memory_bytes: 45824
fun int() = readLine()!!.toInt()
fun list() = readLine()!!.split(" ").map {it.toInt()}

fun main() {
	val n = int()
	val a = list()
	var c = 0
	for(i in 0 until n)
		for(j in i+1 until n)
			for(k in j+1 until n)
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]
						&&a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[k]+a[i]>a[j])
					++c
	println(c)
}


Measured memory_bytes: 38640
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      int N = sc.nextInt();
      int[] L = new int[N];
      int max =0, total =0;
      for (int i=0; i<N; i++) {
        L[i] = sc.nextInt();
        max = Math.max(L[i],max);
        total += L[i];
      }
      if(max < total - max) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 200000
#define add(x,y) (e[++ee].nxt=lnk[x],e[lnk[x]=ee].to=y)
using namespace std;
int n,ee,lnk[N+5];struct edge {int to,nxt;}e[N<<1];
class FastIO
{
	private:
		#define FS 100000
		#define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
		#define D isdigit(c=tc())
		char c,*A,*B,FI[FS];
	public:
		I FastIO() {A=B=FI;}
		Tp I void read(Ty& x) {x=0;W(!D);W(x=(x<<3)+(x<<1)+(c&15),D);}
}F;
int q[N+5],d[N+5];I int BFS(CI x)
{
	RI i,k,f=0,H=1,T=1;for(i=1;i<=n;++i) d[i]=0;d[q[1]=x]=1;
	W(H<=T) for(i=lnk[k=q[H++]];i;i=e[i].nxt)
		!d[e[i].to]&&(d[q[++T]=e[i].to]=d[k]+1)>d[f]&&(f=e[i].to);return f;
}
int main()
{
	RI i,x,y;for(F.read(n),i=1;i^n;++i) F.read(x),F.read(y),add(x,y),add(y,x);
	return x=BFS(1),puts((d[BFS(x)]-2)%3?"First":"Second"),0;
}

Measured memory_bytes: 9200
n = int(input())
a = [int(i) for i in input().split()]
def f(x):
	k = 0
	for i in a: k+=(i+x-n)//(n+1)+1
	return k<=x
for i in range(max(0,sum(a)-n*(n-1)),51*(10**16)):
	if f(i): break
print(i)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)

struct edge{int to,cap,rev;};

vector<edge> g[1002];
bool used[1002];

void addEdge(int from,int to,int cap){
	edge e;
	e.to=to;e.cap=cap;e.rev=g[to].size();
	g[from].push_back(e);
	e.to=from;e.cap=0;e.rev=g[from].size()-1;
	g[to].push_back(e);
}

int dfs(int v,int t,int f){
	if(v==t)return f;
	used[v]=1;
	rep(i,g[v].size()){
		edge &e=g[v][i];
		if(!used[e.to]&&e.cap>0){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				g[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int maxFlow(int s,int t){
	int flow=0;
	for(;;){
		fill(used,used+1001,0);
		int f=dfs(s,t,INF);
		if(!f)return flow;
		flow+=f;
	}
}

int gcd(int a,int b){
	if(!b)return a;
	return gcd(b,a%b);
}

int m,n,k,a[1002];

int main(){
	while(cin>>m>>n&&m){
		rep(i,m+n+2)g[i].clear();
		rep(i,m+n)cin>>a[i];
		int S=m+n,G=S+1;
		rep(i,m)addEdge(S,i,1);
		rep(i,n)addEdge(m+i,G,1);
		rep(i,m)rep(j,n)if(gcd(a[i],a[m+j])>1){addEdge(i,m+j,1);}
		cout<<maxFlow(S,G)<<endl;
	}
}

Measured memory_bytes: 7408
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;
}
bool compare(int a, int b) {
	return a > b;
}
int main() {
	fio;
	ll a, b, x, y;
	cin >> a >> b >> x >> y;
	cout << max((a * x), max((a * y), max((b * x), (b * y))));
	return 0;
}

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

int main(){
  int N,M,X,Y,x,y,Xmax,Ymin;
  cin >> N >> M >> X >> Y;
  Xmax = X;
  Ymin = Y;
  for(int i;i<N;i++){
    cin >> x;
    if(Xmax < x){
      Xmax = x;
    }
  }
  for(int j;j<M;j++){
    cin >> y;
    if(Ymin > y){
      Ymin = y;
    }
  }
  if(Ymin <= Xmax){
    cout << "War";
  }else{
    cout << "No War";
  }
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN,"%d%d", $k,$s);
  $count =0;
  for($x=0; $x<=$k; $x++){
      for($y=0; $y<=$k; $y++){
          $z = $s-($x+$y);
          if($z >= 0 && $z <= $k){
              if($z+$x+$y == $s){
                  $count++;
              }
          }
      }
  }
  echo $count;

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int index(string s){
    if(s[0] == 'M') return 0;
    if(s[0] == 'A') return 1;
    if(s[0] == 'R') return 2;
    if(s[0] == 'C') return 3;
    if(s[0] == 'H') return 4;
    return -1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<ll> cnt(5, 0);
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        int hoge = index(s);
        if(hoge == -1)  continue;
        ++cnt[hoge];
    }
    ll res = 0;
    for(int i = 0; i < 5; ++i){
        for(int j = i+1; j < 5; ++j){
            for(int k = j+1; k < 5; ++k){
                res += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
num = int(input())
pos = list(map(int,input().split()))
maxpos = max(pos)
minhealth = 1e9
count = 0
for i in range(maxpos+1):
    for j in pos:
        count += (j-i)**2
    minhealth = min(minhealth, count)
    count = 0
print(minhealth)


Measured memory_bytes: 9156
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;

signed main(){
    
    int w,h;
    cin >> w >> h;
    vector<pair<int,int>> al;
    rep(i,w){
        int p;cin >> p;
        al.pb(MP(p,1));
    }
    rep(i,h){
        int p;cin >> p;
        al.pb(MP(p,0));
    }
    SORT(al);
    int ans = 0;
    int hp = h+1;
    int wp = w+1;
    for(int i = 0;i < w+h;i++){
        if(al[i].se == 1){
            ans += hp*al[i].fi;
            wp--;
        }else{
            ans += wp*al[i].fi;
            hp--;
        }
    }
    cout << ans << endl;

    
    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://codefestival_2016_qualB.contest.atcoder.jp/tasks/codefestival_2016_qualB_c


Measured memory_bytes: 6384
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
	int n,m,k,f;
  	cin >> n >> m;
  	int a[n][m]={0};
  	for(int i=0;i<n;i++){
    	cin >> k;
          for(int j=0;j<k;j++){
            cin >> f;
          a[i][f-1]=1;
          }
    }
  	int ans=0;
  	for(int i=0;i<m;i++){
    	bool falg=true;
      	for(int j=0;j<n;j++){
        	if(a[j][i]!=1){
            	falg=false;
              	break;
            }
        }
      if(falg)
        ans++;
    }
  	cout << ans << '\n';
  	return 0;
}

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

const int INF = 0x3f3f3f3f;
struct Edge{
	int from, to, cap;
	int flow, cost;
	Edge(int u = 0, int v = 0, int c = 0, int f = 0, int o = 0):
		from(u), to(v), cap(c), flow(f), cost(o){}
};
struct MCMF{
	int N, ver;
	vector<Edge> edges;
	vector< vector<int> > adj;
	vector<int> d, p, a, inq;

	MCMF(int Num): N(Num + 20), ver(Num), edges(0), adj(N), d(N), p(N), a(N), inq(N) { }

	inline void addEdge(int u, int v, int ca, int co){
		if(u == v) return;
		edges.emplace_back(u, v, ca, 0, co);
		adj[u].emplace_back(edges.size() - 1);
		edges.emplace_back(v, u, 0, 0, -co);
		adj[v].emplace_back(edges.size() - 1);
	}

	inline bool SPFA(int s, int t, int& flow, long long& cost){
		fill(d.begin(), d.end(), INF);
		fill(inq.begin(), inq.end(), 0);
		d[s] = 0, inq[s] = 1, p[s] = 0, a[s] = 0x3f3f3f3f;
		queue<int> q({s});
		
		while(!q.empty()){
			int u = q.front(); q.pop();
			inq[u] = 0;
			for(int i : adj[u]) {
				Edge &e = edges[i];
				if(e.cap > e.flow && d[e.to] > d[u] + e.cost){
					d[e.to] = d[u] + e.cost;
					p[e.to] = i;
					a[e.to] = min(a[u], e.cap - e.flow);
					if(!inq[e.to]){
						q.push(e.to);
						inq[e.to] = 1;
					}
				}
			}
		}
		if(d[t] >= 0x3f3f3f3f) return false;
		flow += a[t];
		cost += 1LL * d[t] * a[t];
		for(int u = t; u != s; u = edges[p[u]].from){
			edges[p[u]].flow += a[t];
			edges[p[u] ^1].flow -= a[t];
		}
		return true;
	}
	inline int minCostMaxFlow(int s, int t, ll& cost){
		int flow = 0; cost = 0;
		while(SPFA(s, t, flow, cost)) continue;
		return flow;
	}
};

int main() {
    int n, m, p, s, t;
	scanf("%d%d%d%d%d", &n, &m, &p, &s, &t);
	MCMF mcmf(n);
	for(int i = 1; i <= m; ++i){
		static int u, v, w, c;
		scanf("%d%d%d%d", &u, &v, &w, &c);
		mcmf.addEdge(u, v, c, w);
	}
    double ans = 1e19;
    int flow = 0; ll cost = 0;
    while(mcmf.SPFA(s, t, flow, cost)) {
        ans = min(ans, (double)(cost + p) / double(flow));
    }
    printf("%.10f\n", ans);

	return 0;
}



Measured memory_bytes: 3408
#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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.rbegin(), a.rend());
    sort(f.begin(), f.end());
    ll ng = -1, ok = 1e12;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        ll cost = 0;
        rep(i,n){
            cost += max(a[i] - min(a[i], mid/f[i]), 0LL);
        }
        if(cost <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 3456
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
    if s[i][2] > 0:
        a,b,c = s[i][0],s[i][1],s[i][2]
        break

for i in range(101):
    for j in range(101):
        h = abs(a-i)+abs(b-j)+ c
        co = 0
        for r in range(n):
            t = h - abs(i - s[r][0]) - abs(j - s[r][1])
            if s[r][2] != max(t,0):
                co = 1
                break
        if co == 0:
            x = i
            y = j
            break
    if co == 0:
        break

print("{} {} {}".format(x,y,h))

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

using namespace std;

const int INF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    for (auto ans : {1, 2, 3}){
        if (ans != a && ans != b)
            cout << ans;
    }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, x, y)   for (__typeof(x) i = x; i < y; i++)
#define repr(i, x, y)   for (__typeof(x) i = x; i > y; i --)
#define endl "\n"
#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define rSort(x)                     sort((x).rbegin(),(x).rend())
#define X                           first
#define Y                           second
#define sep                         ' '
#define SZ(x)                       ll(x.size())
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define pb                          push_back
#define mp                          make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define first X
#define second Y

const ll N = 1e6 + 7;
const ll M = 1e17 + 7;

int32_t main()
{
     IOS;
     ll a,b;
     cin >> a >> b;
     cout << a*b;
     
}

Measured memory_bytes: 3624
#include <stdio.h>          // printf(), scanf()
 
void
east(int dice[6])
{
    int t = dice[2];
    dice[2] = dice[0]; /* 3 ??? 1 */
    dice[0] = dice[3]; /* 1 ??? 4 */
    dice[3] = dice[5]; /* 4 ??? 6 */
    dice[5] = t;       /* 6 ??? 3 */
}
 
void
south(int dice[6])
{
    int t = dice[1];
    dice[1] = dice[0]; /* 2 ??? 1 */
    dice[0] = dice[4]; /* 1 ??? 5 */
    dice[4] = dice[5]; /* 5 ??? 6 */
    dice[5] = t;       /* 6 ??? 2 */
}
 
void
rotate(int dice[6])
{
    int t = dice[3];
    dice[3] = dice[1]; /* 4 ??? 2 */
    dice[1] = dice[2]; /* 2 ??? 3 */
    dice[2] = dice[4]; /* 3 ??? 5 */
    dice[4] = t;       /* 5 ??? 4 */
}
 
int
main(int argc, char** argv)
{
    int dice[6];
    int u, v;
    int q;
    int i, j;
 
    for (i = 0; i < 6; ++i)
        scanf("%d", &dice[i]);
 
    scanf("%d", &q);
    for (i = 0; i < q; ++i)
    {
        scanf("%d %d", &u, &v);
        for (j = 0; j < 4; ++j)
        {
            if (dice[1] == v)
                break;
 
            south(dice);
        }
 
        if (dice[1] != v) /* dice[2]????????¢???????????????????????? */
        {
            for (j = 0; j < 4; ++j)
            {
                if (dice[1] == v) /* dice[2]????????¢??? */
                    break;
 
                rotate(dice);
            }
        }
 
        for (j = 0; j < 4; ++j)
        {
            if (dice[0] == u) /* dice[1]????????¢??? */
                break;
 
            east(dice);
        }
 
        printf("%d\n", dice[2]); /* dice[3]????????´??¢ */
    }
 
    return 0;
}


Measured memory_bytes: 2036
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args) {
            List<int> Str = new List<int>{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1};
            var arg = new List<string>(ReadLine().Split(' ')).Select(int.Parse).ToList<int>();
            WriteLine(
                (Str.IndexOf(arg[0]) == Str.IndexOf(arg[1]) ? "Draw" :
                (Str.IndexOf(arg[0]) > Str.IndexOf(arg[1]) ? "Alice" : "Bob")));

            ReadLine();


        }
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
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; }

int Dist(int x, int y) {
  if (x <= y) return y - x;
  return inf;
}

void _main() {
  int x, y;
  cin >> x >> y;

  int ans = min({Dist(x,y), Dist(-x,y)+1, Dist(x,-y)+1, Dist(-x,-y)+2});
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A[51];
long long DP[51][2];
int main()
{
  int N,P;
  cin >> N >> P;

  for (int k = 0; k < 50; k++)
    for (int j = 0; j < 50; j++)
      DP[k][j] = 0;
  DP[0][0] = 1;

  for (int i = 1; i < N; i++)
    cin >> A[i];

  for (int i = 1; i <= N; i++){
    DP[i][0] += DP[i-1][0];
    DP[i][1] += DP[i-1][1];
    if (A[i]%2 == 0) {
      DP[i][0] += DP[i-1][0];
      DP[i][1] += DP[i-1][1];
    }
    else {
      DP[i][0] += DP[i-1][1];
      DP[i][1] += DP[i-1][0];
    }
  }

  cout << DP[N][P] << endl;
}

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

int main(void) {
  int n; cin >> n;
  vector<long long> ys(10000001, 1);
  
  for (int i=2; i<10000001; i++) {
    int t = i;
    while (t < 10000001) {
      ys[t] += 1;
      t += i;
    }
  }
  
  vector<long long> kfk(10000001, 0);
  
  for (long long i=1; i<10000001; i++) {
    kfk[i] = kfk[i-1] + i * ys[i];
  }
  
  cout << kfk[n] << endl;
}

Measured memory_bytes: 159520
import java.io.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int i = 1;
		int x;

		while((x = Integer.parseInt(s = br.readLine())) != 0){
			System.out.println("Case " + i + ": " + x);
			i++;
		}
	}
}

Measured memory_bytes: 27180
#include<stdio.h>
int main(void){
	int n,m,i,sum,ans;
	int	masu[1000],sai;

	while(1){
		sum=ans=0;
		scanf("%d%d",&n,&m);
		if(n==0&&m==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&masu[i]);
		}
		for(i=0;i<m;i++){
			scanf("%d",&sai);
			if(sum<n){
				sum+=sai+masu[sum+sai];
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 604
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String st;
	    int[] p = new int[101];
	    int max = 0;
	    while((st=sc.readLine())!=null)
		p[Integer.valueOf(st)]++;
	    
	    for(int i=0; i<101; i++)
		if(p[i]>max)
		    max = p[i];
	    for(int i=0; i<101; i++)
		if(p[i] == max)
		    System.out.println(i);
	}
	catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9100
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main(string[] args) {
        int N = int.Parse(ReadLine());
        var primeList = Prime(55555);
        var list = primeList.Where(i => i.ToString().EndsWith("1"));

        WriteLine(String.Join(" ", list.Take(N)));
    }


    static List<int> Prime(int max) {
        int prime;
        double sqrtMax = Math.Sqrt(max);
        var primeList = new List<int>();

        var searchList = Enumerable.Range(2, max - 1).ToList();
        do {
            prime = searchList.First();
            primeList.Add(prime);
            searchList.RemoveAll(i => i % prime == 0);
        } while (prime < sqrtMax);

        primeList.AddRange(searchList);
        return primeList;
    }
}

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  vector<int> ans;
  while(cin >> n,n){
    int count = 0;
    string s0 = "",s1;
    for(int i = 0;i < n;i++){
      cin >> s1;
      if(s1 == "lu" && s0 == "ru")count++;
      if(s1 == "ru" && s0 == "lu")count++;
      if(s1 == "ld" && s0 == "rd")count++;
      if(s1 == "rd" && s0 == "ld")count++;
      s0 = s1;
    }
    ans.push_back(count);
  }
  for(int i = 0;i < ans.size();i++)cout << ans[i] << endl;
}


Measured memory_bytes: 3148
<?php
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);
$arr1 = str_split($s);
$arr2 = str_split($t); 
$n = strlen($s);
$ans = 'Yes';
for($i=0;$i<$n;++$i){
  if($arr1[$i] != $arr2[$i]){   
    $ans ='No';
    break;
  }
}
echo $ans;
?>

Measured memory_bytes: 16184
#include<iostream>
#include<vector>
#include<map>
#include<stack>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
vector<vector<int>> getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;

int N,M;
vector<string> A,B;
bool search(int x, int y);
int main(){
	int W,a,b;
	cin >> W>>a>>b;
	if(a>b){
		int tmp = a;
		a = b;
		b = tmp;
	}
	int dis = b-(a+W);
	int ans = (dis<0)? 0:dis;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s;
    cin>>s;
    s.erase(unique(s.begin(),s.end()),s.end());
    cout<<s.size()-1<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    int a, n, i, min=1000000, max=-1000000;
    long long sum =0;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a);
        sum=sum + a;
        if(min>a){
        min=a;    
        }
        if(max<a){
            max=a;
        }
    }
    printf("%d %d %lld\n", min, max, sum);
    
    return 0;
}



Measured memory_bytes: 2104
/*
    _____
  .'|||||'.
 /  >   <  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
    |||||
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
int n,a[100010],b[100010];

int main()
{
    scanf("%d",&n);
    int num=0;
    int ans=0;
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        ans^=a[i];
        if (a[i]==0) num++;
    }
    if (ans==0) printf("Yes\n"); else printf("No\n");
    /*
    if (num==n)
    {
       printf("Yes\n");
       return(0);
    }
    sort(a+1,a+1+n);
    int k=1;
    b[k]=a[1];
    for (int i=2;i<=n;i++)
    {
        if (a[i]!=a[i-1])
        {
            k++;
            b[k]=a[i];
        }
    }
    if (n%3==0)
    {
       if (k==3&&b[1]^b[2]==b[3])
       {
           int num1=0;
           int num2=0;
           int num3=0;
           for (int i=1;i<=n;i++)
           {
               if (a[i]==b[1]) num1++;
               if (a[i]==b[2]) num2++;
               if (a[i]==b[3]) num3++;
           }
           if (num1==num2&&num2==num3)
           {
               printf("Yes\n");
               return(0);
           }
       }
       if (k==2&&b[1]==0&&num==n/3)
       {
           printf("Yes\n");
           return(0);
       }
    }
    if (n%3==2&&k==2&&b[1]==0&&(n-2)/3==num-1)
    {
        printf("Yes\n");
        return(0);
    }
    printf("No\n");*/
    return(0);
}


Measured memory_bytes: 640
import java.util.*;

class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
	
		int numA = scanner.nextInt();
		int numB = scanner.nextInt();
		
		if (numA >= 1 && numA <= 3 && numB >= 1 && numB <= 3) {
			//System.out.println("A = " + numA);
			//System.out.println("B = " + numB);
			
			int numAB = numA * numB;
			//System.out.println("A * B = " + numAB);
			
			if (numA == 2 || numB == 2) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		}
		
	}
}

Measured memory_bytes: 23508
#include "bits/stdc++.h"
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int h, w, d;
  cin >> h >> w >> d;
  // map<Pii, int> p2i;
  map<int, Pii> i2p;
  rep(i, h) {
    rep(j, w) {
      int x;
      cin >> x;
      x--;
      // p2i[Pii(i, j)] = x;
      i2p[x] = Pii(i, j);
    }
  }

  vvi s(d, vi{0});
  rep(x, h * w) {
  // rep(i, h) {
  //   rep(j, w) {
      // int x = p2i[Pii(i, j)];
      int i, j;
      tie(i, j) = i2p[x];
      int y = x + d;
      if (y >= h * w) continue;
      int ii, jj;
      tie(ii, jj) = i2p[y];
      s[x % d].push_back(abs(i - ii) + abs(j - jj));
    // }
  }

  // printVV(s);

  rep(k, d) {
    rep2(l, 1, s[k].size()) {
      s[k][l] += s[k][l - 1];
    }
  }

  // printVV(s);

  int q;
  cin >> q;
  rep(t, q) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    int k = a % d;
    int l1 = a / d;
    int l2 = b / d;
    // cerr << "k = " << k << ", l1 = " << l1 << ", l2 = " << l2 << endl;
    cout << s[k][l2] - s[k][l1] << endl;
  }

}


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

using namespace std;

int Result[7];

int main() {
	int n, age;

	while (cin >> n, n) {
		memset(Result, 0, sizeof(Result));

		for (int i = 0; i < n; i++) {
			cin >> age;

			age /= 10;
			if (age > 6) {
				age = 6;
			}
			Result[age]++;
		}

		for (int i = 0; i < 7; i++) {
			cout << Result[i] << endl;
		}
	}
	

	return 0;
}


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

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


int main()
{
	int n;
	cin >> n;
	int ans = 0, tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		ans = gcd(tmp, ans);
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

ll a;
ll b;

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

    cin >> a >> b;

    if (a * b < 0 || a == 0 || b == 0) {
        cout << "Zero" << endl;
    } else if (0 < a || a == b) {
        cout << "Positive" << endl;
    } else {
        if ((b - a - 1) % 2 == 1) {
            cout << "Negative" << endl;
        } else {
            cout << "Positive" << endl;
        }
    }

    return 0;
}



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

using namespace std;

typedef long long ll;

ll n;
ll x[1010], y[1010], h[1010];

vector<ll> v(3);

/*
4
2 3 5
2 1 5
1 2 5
3 2 5

>> 0 0 5
*/

int main(){
    cin >> n;
    for (int i = 0; i < n;i++){
        cin >> x[i] >> y[i] >> h[i];
        // もしh[i] が 0 だった場合、他の式にエラーが起こることを考えられなかった。
        // 有効なものを利用したい。
        if (h[i] > 0){
            v[0] = x[i];
            v[1] = y[i];
            v[2] = h[i];
        }
    }
    for (int i = 0; i <= 100; i++){
        for (int j = 0; j <= 100; j++){
            // (i,j)に頂点があると考える。

            ll H = abs(v[0] - i) + abs(v[1] - j) + v[2];
            H = max(H, 0LL);
                    
            bool check = true;
            for (int k = 0; k < n; k++){
                ll H_next = max(H - abs(x[k]-i) - abs(y[k]-j), 0LL);
                if (H_next != h[k]){
                    check = false;
                }
            }
            if (check){
                cout << i <<" " << j << " " << H << endl;
            }
        }
    }
}


Measured memory_bytes: 256
# 153716888
MOD = (10**9) + 7
s = gets.chomp
l = s.size
m = 13
dma = {
 10  =>  1,
 9   => 10,
 12  =>  9,
 3   => 12,
 4   =>  3,
 1   =>  4
}
b = [1, 10, 9, 12, 3, 4][l%6]
hatena = '?'
before = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
curr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
l.times do |i|
  curr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  b = dma[b]
  if s[i] == hatena
    m.times do |j|
      csp = 0
      10.times { |k| csp = (csp + before[(j+k*b)%m])%MOD }
      curr[j] = csp%MOD
    end
  else
    k = s[i].to_i
    m.times do |j|
      curr[j] = before[(j+k*b)%m]%MOD
    end
  end
  before = curr
end
p curr[8]


Measured memory_bytes: 2172
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val n  = sc.nextInt()
  val list = (for (i <- 0 until n) yield (i, sc.nextLong(), sc.nextLong(), sc.nextLong(), sc.nextLong())).toList
 
  type XAux = (Int, Int, Long, Long, Long) // (id, state, x aux, top, bottom)
  type YAux = (Int, Int, Long) // (id, state, y aux)

  val xlist = (for ((i,l,t,r,b) <- list) yield List((i,0,l,t,b), (i,1,r,t,b))).flatten.sortBy(_._3)

  def area(x:Long, p:Long, ylist:List[YAux]):Long = {
    def iter(yl:List[YAux], c:Int, p:Long, ac:Long):Long = {
      if (yl.isEmpty) ac
      else {
        val (i,s,y) = yl.head
        (s, c) match {
          case (0, 0) => iter(yl.tail, c+1, y, ac)
          case (0, _) => iter(yl.tail, c+1, p, ac)
          case (1, 1) => iter(yl.tail, c-1, p, ac+y-p)
          case (_, _) => iter(yl.tail, c-1, p, ac)
        }
      }
    }
    iter(ylist.sortBy(_._3), 0, 0, 0)*(x-p)
  }

  def solver(xl:List[XAux], yl:List[YAux], c:Int, p:Long, acc:Long):Long = {
    def addRect(yl:List[YAux], xr:XAux):List[YAux] = {
      val (i,s,x,t,b) = xr
      if (b < t) (i,0,b)::(i,1,t)::yl else (i,0,t)::(i,1,b)::yl
    } 

    if (xl.isEmpty) acc
    else {
      val (i, s, x, t, b) = xl.head
      (s, c) match {
        case (0, 0) => solver(xl.tail, addRect(yl, xl.head), c+1, x, acc)
        case (0, _) => solver(xl.tail, addRect(yl, xl.head), c+1, x, acc+area(x, p, yl))
        case (_, _) => solver(xl.tail, yl.filter(_._1 != i), c-1, x, acc+area(x, p, yl))
      }
    } 
  }

  println(solver(xlist, Nil, 0, 0, 0))
}



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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> ans(N, 0);
  rep(i,Q) {
    int a;
    cin >> a;
    a--;
    ans[a]++;
  }

  rep(i,N) {
    if (K-Q+ans[i] > 0) cout << "Yes\n";
    else cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 1024
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	table := [10]string{
		"* = ****",
		"* =* ***",
		"* =** **",
		"* =*** *",
		"* =**** ",
		" *= ****",
		" *=* ***",
		" *=** **",
		" *=*** *",
		" *=**** ",
	}
	input := make([]string, 0)
	for scanner.Scan() {
		input = append(input, scanner.Text())
	}
	n := len(input)
	cnt := 0
	for cnt < n {
		tmp := strings.Split(fmt.Sprintf("%05s", input[cnt]), "")
		ans := make([]string, 0)
		for _, v := range tmp {
			iv, _ := strconv.Atoi(v)
			ans = append(ans, table[iv])
		}
		for i := 0; i < 8; i++ {
			for j := 0; j < 5; j++ {
				fmt.Print(string(ans[j][i]))
			}
			fmt.Println()
		}
		if cnt != n-1 {
			fmt.Println()
		}
		cnt++
	}
}



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

int main(){
  vector<int> a(5);
  for(int i = 0; i < 5; i++){
    cin >> a.at(i);
  }
   for(int i = 0; i < 5; i++){
    if(a.at(i) == 0){
      cout << i+1 << endl;
    }
  }
}

Measured memory_bytes: 3588
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m;
ll ans;
inline int abs(int x){return (x>0)?x:-x;}
inline void init(){
	scanf("%d%d",&n,&m);
	if (abs(n-m)>1) {
		puts("0");
		exit(0);
	} 
}
inline void solve(){
	ans=1;
	for (int i=1;i<=n;i++){
		(ans*=i)%=mod;
	}
	for (int i=1;i<=m;i++){
		(ans*=i)%=mod;
	}
	if (n==m) ans=ans*2%mod;
	printf("%lld\n",ans);
}
int main(){
	init();
	solve();
	return 0;
} 

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n, m;
char buf[3005];
int a[3005], le[3005], ri[3005];
int from[3005], to[3005];
int lsum[3005], rsum[3005];
int d[3005], nd[3005];

inline void add(int &x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

int main() {
    scanf("%d%d", &n, &m);
    scanf("%s", buf);
    forn(i, n) {
        a[i] = buf[i] - '0';
    }
    forn(i, m) {
        scanf("%d%d", from + i, to + i);
        --from[i];
        --to[i];
    }
    forn(i, n) {
        le[i] = a[i];
    }
    forn(i, m) {
        int z = 0, o = 0;
        for (int j = from[i]; j <= to[i]; ++j) {
            if (le[j] == 0) ++z;
            else ++o;
        }
        for (int j = from[i]; j <= to[i]; ++j) {
            if (z) {
                --z;
                le[j] = 0;
            } else {
                le[j] = 1;
            }
        }
    }

    forn(i, n) {
        ri[i] = a[i];
    }
    forn(i, m) {
        int z = 0, o = 0;
        for (int j = from[i]; j <= to[i]; ++j) {
            if (ri[j] == 0) ++z;
            else ++o;
        }
        for (int j = from[i]; j <= to[i]; ++j) {
            if (o) {
                --o;
                ri[j] = 1;
            } else {
                ri[j] = 0;
            }
        }
    }

    lsum[0] = rsum[0] = 0;
    forn(i, n) {
        lsum[i + 1] = lsum[i] + le[i];
        rsum[i + 1] = rsum[i] + ri[i];
    }
    memset(d, 0, sizeof d);
    d[0] = 1;
    forn(i, n) {
        memset(nd, 0, sizeof nd);
        for (int j = lsum[i]; j <= rsum[i]; ++j) {
            add(nd[j], d[j]);
            add(nd[j + 1], d[j]);
        }
        for (int j = lsum[i + 1] - 1; j >= max(0, lsum[i + 1] - 5); --j) {
            nd[j] = 0;
        }
        for (int j = rsum[i + 1] + 1; j <= min(n, rsum[i + 1] + 5); ++j) {
            nd[j] = 0;
        }
        memcpy(d, nd, sizeof d);
    }
    int ans = 0;
    forn(i, n + 1) {
        add(ans, d[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int c=a+b;
	if(a%3==0||b%3==0||c%3==0) cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0; 
 } 

Measured memory_bytes: 256