akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    V keep(10);  fill(ALL(keep), 0);
    REP(i , 3){
      int input;  cin >> input;
      keep[input] += 1;
    }

    for(int x : keep)
      if(x == 2){ cout << "Yes" << endl;  return 0; }

    cout << "No" << endl;
    
	return 0;
}


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

#define fi first
#define se second
#define ep emplace_back
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m; cin >> n >> m;
  
  map<int,int> mp;
  rep(i, m) {
    int a, b; cin >> a >> b;
    ++mp[a], ++mp[b];
  }

  rep2(i, 1, n) cout << mp[i] << endl;
  
  return (0);
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
int dp[6005][6005];
 
int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;
 
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
            }
            dp[i][j] = max(dp[i][j], dp[i][j-1]);
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
        }
    }
    string res = "";
    int i = n, j = m;
    while(i > 0 && j > 0){
        if(s[i-1] == t[j-1]){
            i--;
            j--;
            res += s[i];
        }
        else if(dp[i-1][j] == dp[i][j]) i--;
        else j--;
    }
    reverse(res.begin(), res.end());
    cout << res;
    return 0;
}

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

int main() {
  int a , b ;
  cin >> a >> b ;
  
  if(a <= b){
   cout << a << endl;
  }
  
  else{
   cout << a-1 << endl;
  }
  
  // ここにプログラムを追記
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val l = (0 until n).map { sc.next().toInt() }
    println(problem067b(k, n, l))
}

fun problem067b(k: Int, n: Int, l: List<Int>): Int {
    return l.sortedDescending().take(k).sum()
}

Measured memory_bytes: 34252
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    char a[3];
    
    cin >> a;
    
    int b = sizeof a;
    
    int c = 0;
    
    for (int i = 0; i < b; i++) {
        if (a[i] == '1') c++;
    }
    
    cout << c << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x, y = [None]*n, [None]*n

for i in range(n):
    x[i], y[i] = map(int, input().split())


def dist(i, j):
    return ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5


total = 0
for i in range(n-1):
    for j in range(i+1, n):
        total += dist(i, j)

print(2*total/n)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string s;
    cin >> s;
    
    int cnt = 0;
    for(int i = 0; i < s.length()-1; i++) {
        if (s[i] != s[i+1]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3760
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

int i,j,A,B,C,D;

int main()
{
  cin>>A>>B>>C>>D;
  
  if((C-1)/B<=(A-1)/D) cout <<"Yes";
  else cout <<"No";
  
  
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>

int main(void)
{
  char s[250000];
  scanf("%s",s);
  int start=0;
  int end=strlen(s);
  while(s[start]!='A'){
    start++;
  }
  while(s[end]!='Z'){
    end--;
  }
  printf("%d\n",end-start+1);
  return 0;
}


Measured memory_bytes: 384
import cmath
EPS = 1e-10

#外積
def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag

#3点が反時計回りか
#一直線上のときの例外処理できていない→とりあえずT
def CCW(p, q, r):
	one, two = q-p, r-q
	if OuterProduct(one, two) > -EPS:
		return True
	else:
		return False

#凸包リストを返す
def ConvexHull(dots):
	dots.sort(key=lambda x: (x.imag, x.real))
	res1 = [dots[0]]
	for d in dots[1:]:
		if len(res1) == 1:
			res1.append(d)
		else:
			while len(res1) > 1 and not CCW(res1[-2], res1[-1], d):
				res1.pop()
			res1.append(d)
	dots.reverse()
	res2 = [dots[0]]
	for d in dots[1:]:
		if len(res2) == 1:
			res2.append(d)
		else:
			while len(res2) > 1 and not CCW(res2[-2], res2[-1], d):
				res2.pop()
			res2.append(d)
	return res1[:-1] + res2[:-1]

n = int(input())
dots = []
for _ in range(n):
	x, y = map(int, input().split())
	dots.append(complex(x, y))

ch = ConvexHull(dots)
print(len(ch))
for v in ch:
	print(round(v.real), round(v.imag))


Measured memory_bytes: 22260
#include<bits/stdc++.h>
using namespace std;
main()
{
long long int n,i,j,k,c=0,first=0,temp,count=pow(10,15);
cin>>n;
long long int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
c+=a[i];
}
for(i=0;i<n-1;i++)
{
first+=a[i];
temp=abs(first-(c-first));
if(temp<count)
{
count=temp;
}
}

cout<<count;



}

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

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

ll count_S(const std::vector<char>& S, const int& N) {
  ll cnt {};
  for (auto i = 1;i < N;++i) {
    if (S[i] == S[i-1]) ++cnt;
  }
  return cnt;
}

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<char> S(N);
  rep(i, N) std::cin >> S[i];
  ll c {};
  for (int i = 1;i < N;++i) {
    if (S[i] != S[i-1]) ++c;
  }
  ll answer {N-1-c+2*K};
  if (answer > N-1) answer = N-1;
  std::cout << answer << '\n';
}


Measured memory_bytes: 384
l = []

N = int(input())

t = input()
last = t[-1]
l.append(t)

ans = 'Yes'
for _ in range(N-1):
    t = input()
    if t[0] != last or t in l:
        ans = 'No'
    l.append(t)
    last = t[-1]
print(ans)


Measured memory_bytes: 3316
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#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;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N, X, T;
    in3(N, X, T);

    int count = N / X;
    if (N % X != 0) count++;

    outl(count * T);
    return 0;
}

Measured memory_bytes: 3616
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            cnt = 500*i + 100*j + 50*k
            if cnt==x:
                ans+=1
print(ans)

Measured memory_bytes: 3064
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const double PI=acos(-1);
typedef long long ll;
typedef pair<int,int> pi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
//debug
#define deb printf("begin\n");
#define dee printf("end\n");
#define def printf("find\n");
#define dey printf("Yes\n");
#define den printf("No\n");
#define dew printf("wrong\n");
void read(int&x){
	x=0;int f=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if (ch=='-')f=-1,ch=getchar();
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//--------------------------head--------------------------//

#define logn 19
#define maxn 200005
int n,v,a[maxn];
int bit[logn],cntbit;

int lowbit(int x){return x&(-x);}


int toL[maxn][logn],fL[1<<logn];
void workL(){
	Rep(j,0,cntbit){toL[1][j]=1;rep(i,1+1,n)
		if (a[i]-a[i-1]<=bit[j])toL[i][j]=toL[i-1][j];
		else toL[i][j]=i;
	}
	/*
	Rep(j,0,cntbit){
		rep(i,1,n)printf("%d ",toL[i][j]);printf("\n");
	}*/
	Rep(i,0,1<<cntbit)fL[i]=n+1;
	Rep(i,0,1<<cntbit){
		for (int j=i;j;j-=lowbit(j))
			fL[i]=min(fL[i],toL[fL[i-lowbit(j)]-1][(int)log2(lowbit(j))]);
	}
	// Rep(i,0,1<<cntbit)printf("%d ",fL[i]);printf("\n");
}

int toR[maxn][logn],fR[1<<logn];
void workR(){
	Rep(j,0,cntbit){toR[n][j]=n;per(i,n-1,1)
		if (a[i+1]-a[i]<=bit[j])toR[i][j]=toR[i+1][j];
		else toR[i][j]=i;
	}
	/*
	Rep(j,0,cntbit){
		rep(i,1,n)printf("%d ",toR[i][j]);printf("\n");
	}*/
	Rep(i,0,1<<cntbit)fR[i]=1-1;
	Rep(i,0,1<<cntbit){
		for (int j=i;j;j-=lowbit(j)){
			// printf("%d %d %d\n",i,lowbit(j),(int)log2(lowbit(j)));
			fR[i]=max(fR[i],toR[fR[i-lowbit(j)]+1][(int)log2(lowbit(j))]);
		}
	}
	// Rep(i,0,1<<cntbit)printf("%d ",fR[i]);printf("\n");
}

int f[maxn][logn];
void work(){
	Rep(i,1,n)f[i][0]=a[i+1]-a[i];
	Rep(j,1,logn)Rep(i,1,n-(1<<j)+1)
		f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
	/*
	Rep(j,0,logn){
		Rep(i,1,n-(1<<j)+1)
			printf("%d ",f[i][j]);
		printf("\n");
	}*/
}
int getmax(int L,int R){
	int j=(int)log2(R-L+1);
	return max(f[L][j],f[R-(1<<j)+1][j]);
}

int num_possible[maxn];
int main(){
	//freopen("Camel and Oases.in","r",stdin);
	//freopen("Camel and Oases.out","w",stdout);
	read(n);read(v);rep(i,1,n)read(a[i]);
	for (int i=v;i;i>>=1)bit[cntbit++]=i>>1;
	//rep(i,1,n)printf("%d ",a[i]);printf("\n");
	//Rep(i,0,cntbit)printf("%d ",bit[i]);printf("\n");
	workL();workR();work();
	Rep(i,0,1<<cntbit){
		int R=fL[i]-1,L=fR[((1<<cntbit)-1)^i]+1;
		//printf("%d %d %d %d %d\n",i,((1<<cntbit)-1)^i,L,R,getmax(L,R-1));
		if (L>R){rep(i,1,n)printf("Possible\n");return 0;}
		if (L==R||getmax(L,R-1)<=v)num_possible[L]++,num_possible[R+1]--;
	}
	//rep(i,1,n)printf("%d ",num_possible[i]);printf("\n");
	rep(i,1,n)num_possible[i]+=num_possible[i-1];
	rep(i,1,n)if (num_possible[i])printf("Possible\n");else printf("Impossible\n");
	return 0;
}

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


int main() {

  int N, K;
  string S;
  cin >> N >> K >> S;

  // 0 が何個、1 が何個ならんでいるかを保持する配列
  vector<int> v;
  
  // 今見ている数 1 or 1
  int current = 1;
  
  // 今見ている数が何個並んでいるか
  int count = 0;

  for (int i = 0; i < N; i++) {
    if (S[i] == (char) '0' + current) {
      count++;
    } else {
      v.push_back(count);
      current = 1 - current;
      count = 1;
    }
  }
  // 最後の分
  if (count != 0) {
    v.push_back(count);
  }

  // 1-0-1-0-1 と 1 を最後にする
  if (v.size() % 2 == 0){
    v.push_back(0);
  }

  int answer = 0;
  int add = 2 * K + 1;

  int left = 0;
  int right = 0;
  int tmp = 0;

  for (int i = 0; i < v.size(); i += 2) {
  
    int nextLeft = i;
    int nextRight = min(i + add, (int) v.size());

    // 左端を移動する
    while (nextLeft > left) {
      tmp -= v[left];
      left++;
    }

    // 右端を移動する
    while (nextRight > right) {
      tmp += v[right];
      right++;
    }
    
    answer = max(answer, tmp);
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, K;
  cin >> N >> K;
  if(K == 1)
    cout << 0 << endl;
  else
    cout << N - K << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <queue>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

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

  i64 N, M, L;
  i64 i, j, k;
  cin >> N >> M >> L;  
  vvi D(N, vi(N, 1000000000LL * 400LL));
  REP(0, M, i) {
    i64 A, B, C;
    cin >> A >> B >> C;    
    D[A-1][B-1] = C;
    D[B-1][A-1] = C;
  }

  REP(0, N, i) {
    REP(0, N, j) {
      REP(0, N, k) {	
	D[j][k] = min(D[j][k], D[j][i] + D[i][k]);
      }
    }
  }

  vvi E(N, vi(N, 1000));
  REP(0, N, i) {
    REP(0, i, j) {
      if(D[i][j] <= L) {
	E[i][j] = 1;
	E[j][i] = 1;
      }
    }
  }
  
  REP(0, N, i) {
    REP(0, N, j) {
      REP(0, N, k) {
	E[j][k] = min(E[j][k], E[j][i] + E[i][k]);
      }
    }
  }

  i64 Q, q;
  cin >> Q;
  REP(0, Q, q) {
    i64 s, t;
    cin >> s >> t;
    s--;
    t--;
    if(E[s][t] == 1000) {
      cout << -1 << endl;
    }
    else {
      cout << E[s][t] - 1 << endl;
    }
  }
  
  return 0;
}


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


int main()
{
  int n, m;
  int x[20];
  int y[20];
  char d[30];                   // ??????
  int s[30];                    // ?§???????

  bool grid[21][21];

  while (1)
  {
    cin >> n;
    if (n == 0) return 0;
    for (int i=0;i<n;i++) cin >> x[i] >> y[i];
    cin >> m;
    for (int i=0;i<m;i++) cin >> d[i] >> s[i];

    for (int i=0;i<21;i++)
      for (int j=0;j<21;j++) grid[i][j]=false;

    int posx = 10, posy = 10;
    grid[posx][posy]=true;

    for (int i=0;i<m;i++)
    {
      for (int k=0;k<s[i];k++)
      {
        switch (d[i])
        {
        case 'E': posx = min(posx+1, 20); break;
        case 'W': posx = max(posx-1, 0); break;
        case 'N': posy = min(posy+1, 20); break;
        case 'S': posy = max(posy-1, 0); break;
        }
        grid[posx][posy]=true;
      }
    }

    int r=n;
    for (int i=0;i<n;i++)
      if (grid[x[i]][y[i]]) r--;
    if (r==0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1152
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'



void solve(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m+1, 0);
  forn(i,n){
    int k;
    cin >> k;
    forn(j, k){
      int x;
      cin >> x;
      a[x] += 1;
    }
  }
  int ans = 0;
  forn(i, m+1){
    ans += a[i] == n;
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 


*/

Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>

using namespace std;

int a, b;

void solve(int n) {
	if (!n) return;
	++b, solve(n / 10);
}

int main() {
	while (scanf("%d%d", &a, &b) != EOF) {
		a += b, b = 0;
		solve(a);
		printf ("%d\n", b); 
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

ll dp[100010];

int fibo(int n)
{
	dp[0] = dp[1] = 1;
	for(int i = 2;i <= n; i++ )dp[i]= (dp[i-1]+dp[i-2])%1000000007;
	return dp[n];
}

int main()
{

	rep(i,100010)dp[i]=-1;
	int n,m;
	cin >> n>>m;
	if(n==1)
	{
		cout<<1<<endl;
		return 0;
	}
	if(m==0)
	{
		cout<<fibo(n)<<endl;
		return 0;
	}
	vector<int> a(n+1);
	rep(i,n+1)a[i]=0;
	rep(i,m)
	{
		ll foo; cin >> foo;
		a[foo]=1;
	}

	ll count =0;
	ll ans = 1;
	rep(i,n+1)
	{
		if(!a[i])count++;
		if(a[i])
		{
			//cout << count << endl;
			if(count==0)ans*=0;
			ans*=fibo(count-1);
			count=0;
			ans %= 1000000007;
		}
		
	}
	ans*=fibo(count-1);
	ans %= 1000000007;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
import math
N,D = map(int, input().split())
n=N
e = [[int(i) for i in input().split()] for i in range(n)]
Num=0
for x in range(0,N):
    for y in range(x+1,N):
        S=0
        for z in range(0,D):
            S=S+(e[x][z]-e[y][z])**2
        A=math.sqrt(S)
        if A%1==0:
            Num=Num+1


print(Num)



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

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

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

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}
/**
double cosine_rule(double a,double b,double c)
{
    double res=(a*a+b*b-c*c)/(2*a*b);
    res=acos(res);
    return res;
}
*/
ll arr[mx];
ll dp[mx];
int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    ll tst,a,b,c,k,n,m,res=0,ans=0,t=0;
    sl(n);
    for(ll i=1;i<=n;i++)
        sl(arr[i]);
    dp[2]=abs(arr[1]-arr[2]);
    for(ll i=3;i<=n;i++)
    {
        a=dp[i-1]+abs(arr[i-1]-arr[i]);
        b=dp[i-2]+abs(arr[i-2]-arr[i]);
        dp[i]=min(a,b);
    }
    res=dp[n];
    printf("%lld\n",res);


    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  int length=0;
  string text;
  
  cin >> length;
  cin >> text;
  
  if( (length < 1) || (length > 100) || (length%2 != 0) ){
    cout << "No" << endl;
  }else{
    size_t size = text.length();
    string halfText = text.substr(0, size/2);
    if( text == halfText + halfText ){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
};

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var H, N int
	fmt.Scanf("%d %d\n", &H, &N)
	sum := 0
	for i := 0; i < N; i++ {
		var A int
		fmt.Scan(&A)
		sum += A
	}
	if sum >= H {
		fmt.Println("Yes")

	} else {
		fmt.Println("No")
	}
}


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


int main() {
    int N,L; cin >> N >> L;
    vector<string> V(N);
    for(int i=0;i<N;i++){
        cin >> V.at(i);
    }

    sort(V.begin(),V.end());
    
    string A="";
    for(int i=0;i<N;i++){
        A+=V.at(i);
    }
    cout << A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    double r;
    cin >> r;
    double ans = r * 2 * M_PI;
    printf("%.16f\n", ans);
}

Measured memory_bytes: 3784
n = int(input())
p = 10**9 + 7

def fact(n):
    n_ = 1
    yield n_
    for i in range(1, n+1):
         n_ = (n_*i) % p
         yield n_

def invfact(n, f, p):
    m = pow(f[n], p-2, p)
    yield m
    for i in range(n, 0, -1):
        m = m * i % p
        yield m

ans = 0
m = n - 1
f = list(fact(m))
rf = list(invfact(m, f, p))
rf.reverse()
perm = 0

for k in range((n+1)//2, n):
    perm_ = f[k-1] * rf[2*k-n] %p * f[k] % p
    ans += (perm_ - perm) %p * k % p
    ans %= p
    perm = perm_

print(ans)

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

vector<long long> calc_divisor(long long N) {
  vector<long long> res;
  for (long long i = 1LL; i*i <= N; i++) {
    if (N % i == 0) {
      res.push_back(i);
      long long j = N / i;
      if (j != i) res.push_back(j);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  long long N; cin >> N;
  int ans = 0;
  for (long long v : calc_divisor(N)) {
    if (v == 1) continue;
    long long tmp = N;
    while (tmp % v == 0) tmp /= v;
    tmp %= v;
    if (tmp == 1) ans++;
  }
  ans += calc_divisor(N-1).size() - 1;
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;

int main(void) {
  int n;
  cin >> n;
  cout << (n-2) * 180 << endl;
  return 0;
}


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

int main()
{
    long long int n,d,ans=0;
    cin>>n>>d;
    while(n--)
    {
        long long int a,b;
        cin>>a>>b;
        if((a*a+b*b)<=d*d)
        ans++;
    }
    cout<<ans;
}

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

#define ll long long int
#define vi vector<int>

int main() {

    ll A, B, K;
    cin >> A >> B >> K;

    if (A >= K) {
        cout << A - K << " " << B << endl;
    } else if (A + B >= K) {
        cout << 0 << " " << A + B - K << endl;
    }
    else {
        cout << 0 << " " << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

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

  ll siz = (ll)s.size();

  if (siz % 2 == 1) {
    puts("No");
    return 0;
  }

  rep(i, siz / 2) {
    bool cond = s.substr(2 * i, 2) == "hi";
    if (!cond) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");

  return 0;
}


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

typedef long long ll;

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

    ll N, A, B;

    cin >> N >> A >> B;

    ll a = N / (A + B);
    ll m = N % (A + B);
    if(m < A) {
        cout << a * A + m << endl;
    } else {
        cout << a * A + A << endl;
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

int n;
vector<LL> a,asum;

int main(){
  cin>>n;
  REP(i,n){
    a.push_back(0);
    asum.push_back(0);
    cin>>a[i];
  }
  asum.push_back(0);
  LL ret=-1000000000,su=0;
  REP(i,n)su+=a[i];
  sort(ALL(a));
  reverse(ALL(a));
  REP(i,n)asum[i+1]=asum[i]+a[i];
  int pos=0;
  FOR(i,1,n){
    LL cand = 2*asum[i]-su;
    if(ret < cand){
      ret=cand;
      pos=i;
    }
  }
  cout<<ret<<endl;
  LL now=a[pos];
  REP(i,n-1){
    if(i<pos-1){
      cout<<now<<" "<<a[i]<<endl;
      now-=a[i];
    }else if(i==(pos-1)){
      cout<<a[pos-1]<<" "<<now<<endl;
      now=a[pos-1]-now;
    }else{
      cout<<now<<" "<<a[i+1]<<endl;
      now-=a[i+1];
    }
  }
  return 0;
}


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

int main() {
	int n,x,t=0;
	cin >> n;
	for(int i=0;i<n;++i){
		cin >> x;
		for(int j=2; j<(int)pow((double)x,0.5)+1; ++j) {
			if(x%j==0) {
				++t;
				break;
			}
		}
	}
	cout << (n-t) << endl;
	return 0;
}

Measured memory_bytes: 3336
#include "bits/stdc++.h"

#define sz(x) (int)x.size()
#define ld long double
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

ld a, b;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    cout << setprecision(40);
    cout << floor(a * b);
    return 0;
}

Measured memory_bytes: 3808
//
//  main.cpp
//  Kyo-pro realActive
//
//  Created by hiroaki on 2019/05/03.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
using namespace std;

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


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

int main(){
  int N;
  int people=0;
  cin >> N;
  
  for(int i=0;i<N;i++){
  	int l, r;
    cin >> l >> r;
    
    people+=r-l+1;
  }
  
  cout << people << endl;
}

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

int main(void) {
  int n[4], a[4] = {1, 9, 7, 4}, sum = 0;
  for (int i = 0; i < 4; i++) {
    cin >> n[i];
  }
  for (int i = 0; i < 4; i++) {
    bool isFind = false;
    for (int j = 0; j < 4; j++) {
      if (a[j] == n[i]) {
        sum += j;
        isFind = true;
      }
    }
    if (!isFind) {
      cout << "NO" << endl;
      return 0;
    }
  }
  if (sum == 6)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
input = gets.chomp.split(" ").map(&:to_i)
w = input[0]
h = input[1]
x = input[2]
y = input[3]

w2 = w/2.0
h2 = h/2.0

s = w*h/2.0

print sprintf("%.9f",s) 

if x == w2 and y == h2 
    print " 1\n"
else
    print " 0\n"
end

Measured memory_bytes: 1788
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def ceil(x, y):
    return -(-x // y)


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    sa = sum(B) - sum(A)

    x = 0
    y = 0
    for i in range(N):
        if A[i] == B[i]:
            continue
        elif A[i] > B[i]:
            x += A[i] - B[i]
        else:
            y += ceil(B[i] - A[i], 2)

    if x <= sa and y <= sa:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 10480
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    bool isFliped = false;

    int q;
    cin >> q;

    vector<char> top;
    vector<char> back;
    REP(i, q) {
        int type;
        cin >> type;

        if (type == 1) {
            isFliped = !isFliped;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            if ((isFliped && f == 1) || (!isFliped && f != 1))
            {
                top.push_back(c);
            }
            else {
                back.push_back(c);
            }
        }
    }

    if (isFliped) {
        REP(i, top.size()) {
            cout << top[top.size() - i - 1];
        }
        std::reverse(s.begin(), s.end());
        cout << s;
        REP(i, back.size()) {
            cout << back[i];
        }
    }
    else {
        REP(i, back.size()) {
            cout << back[back.size() - i - 1];
        }
        cout << s;
        REP(i, top.size()) {
            cout << top[i];
        }
    }

    return 0;
}


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

lint C, D;

lint f(lint x){
    lint lcm = C / gcd(C, D) * D;
    return x - x / C - x / D + x / lcm;
}

int main(){
    lint A, B;
    cin >> A >> B >> C >> D;
    cout << f(B) - f(A - 1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
ll n,u,v,ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++) ans+=i*(n-i+1);
	for(int i=1;i<n;i++){
		u=read(),v=read();
		if(u>v) swap(u,v);
		ans-=u*(n-v+1);
	}
	printf("%lld\n",ans);
	return 0;
}

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

class Team {

    final int no;
    final int ans;
    int rank;

    Team( int no, int ans ) {
	this.no = no;
	this.ans = ans;
    }
}

class ComparatorAns implements Comparator<Team> {
    public int compare( Team t1, Team t2 ) {
	return Double.compare( t2.ans, t1.ans );
    }    
}

class ComparatorTeamNo implements Comparator<Team> {
    public int compare( Team t1, Team t2 ) {
	return Double.compare( t1.no, t2.no );
    }    
}

class Main {

    public static void main(String[] args) {

	Scanner stdin = new Scanner(System.in);
	ArrayList<Team> list = new ArrayList<Team>();
	
	while( true ) {

	    String[] input = stdin.nextLine().split( "," );
	    final int team = Integer.parseInt( input[0] );
	    final int ans  = Integer.parseInt( input[1] );

	    if ( team == 0 && ans == 0 ) {
		break;
	    }
	    list.add( new Team( team, ans ) );	    
	}

	Collections.sort( list, new ComparatorAns() );
	int befAns = list.get( 0 ).ans;
	int rank = 1;
	for ( Team t : list ) {
	    if ( t.ans < befAns ) {
		rank++;
		befAns = t.ans;
	    }
	    t.rank = rank;
	}

	Collections.sort( list, new ComparatorTeamNo() );

	while( stdin.hasNextLine() ) {

	    final int teamNo = Integer.parseInt( stdin.nextLine() );
	    for ( Team t : list ) {
		if ( t.no == teamNo ) {
		    System.out.println( t.rank );
		    break;
		}
	    }	    
	}	
    }    
}

Measured memory_bytes: 17192
n, k = map(int, input().split())

a = list(map(int, input().split()))

ng = 0
ok = 10 ** 9 + 1

def check(x):
    cnt = 0
    for l in a:
        cnt += (l-1)//x
    return cnt <= k

while abs(ok-ng) > 1:
    m = (ok + ng) // 2
    if check(m):
        ok = m
    else:
        ng = m

print(ok)

Measured memory_bytes: 103592
//
// Created by Tatsuhiro Hashimoto on 2020/05/04.
//
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define FSP(n) cout << fixed << setprecision(n);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
static inline ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b);}
static inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define prepare cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A) {
    if (A.size() == N + 1) {
        int now = 0;
        for (int i = 0; i < Q; ++i) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(now, ans);
        return;
    }
    A.push_back(A.back());
    while (A.back() <= M) {
        dfs(A);
        A.back()++;
    }
}

signed main() {
    prepare
    cin >> N >> M >> Q;
    a = b = c = d = vector<int>(Q, 0);
    for (int i = 0; i < Q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1, 1));
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include<iostream>
using namespace std;
int n,t[10000],cnt,size,j;
int check(){
  for(int i=0;i<n;i++){
    if(t[i]!=i+1)return 0;
  }
  return 1;
}
int main(){

  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>t[i];
    for(cnt=0;cnt<=10000;cnt++){
      if(check())break;
      for(int i=0;i<n;i++)t[i]--;
      t[n]=n;
      n++;
      j=0;
      for(int i=0;i<n;i++)if(t[i])t[j++]=t[i];
      n=j;
    }
    if(cnt>10000)cout<<"-1"<<endl;
    else cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_FiveVariables_170
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            for (int i = 0; i < inputLongArray.Length; i++)
            {
                if (inputLongArray[i] == 0)
                {
                    Console.WriteLine(i+1);
                    break;
                }
            }

            Console.Out.Flush();
        }
    }
}


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

int main(){
    int n,q,cnt = 0;
    int s[10000];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        int tmp; cin >> tmp;
        for(int j = 0; j < n; j++){
            if(tmp == s[j]){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	// 標準入力からデータを読み込む準備
	try (Scanner sc = new Scanner(System.in)) {

		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			 values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1; 
			// aとbを使ってvaluesを操作しよう
			int t = values[a];
			values[a]= values[b];
			values[b]=t;
			
		}
		// valuesを出力しよう
		for (int i = 0; i < w; i++) {
			System.out.println(values[i]);
		}
	}

	}
}


Measured memory_bytes: 26104
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vll pm = {-1,+1};
    vll x(n),y(n),z(n);
    REP(i,n){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ans = 0;
    REP(xpm,2){
        REP(ypm,2){
            REP(zpm,2){
                vll xyz(n);
                REP(i,n){
                    xyz[i]=x[i]*pm[xpm]+y[i]*pm[ypm]+z[i]*pm[zpm];
                }
                sort(rALL(xyz));
                ll tmp=0;
                REP(i,m){
                    tmp+=xyz[i];
                }
                ans=max(ans,tmp);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int t = sc.nextInt();

		int ans = (n / x + (n % x == 0 ? 0 : 1)) * t;
		System.out.println(ans);
		
		sc.close();
	}

}




Measured memory_bytes: 27108
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >>a>>b>>n;
  lol ans=b/n-a/n;
  if(a%n==0) ans++;
  cout <<ans<<'\n';

  return(0);
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO

    ll n, a, b;

    cin >> n >> a >> b;

    ll cnt = n / (a + b);

    ll rem = (n - cnt * (a + b));

    cout << cnt * a + min(rem, a);

}









Measured memory_bytes: 256
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {
	
	public void solve(InputReader in, PrintWriter out) {
		long n = in.nextLong(), m = in.nextLong();
		
		long ans = Math.min(m/2, n);
		long nn = n - ans, mm = m - ans * 2;
		
		if (mm > 0)
			ans += mm / 4;
		
		out.println(ans);
	}
}

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 int nextInt() {
		return Integer.parseInt(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


Measured memory_bytes: 22864