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

using namespace std;

#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<"\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3600
def dsum(n)
  m = n
  ret = 0
  while m > 0
    ret += m % 10
    m /= 10
  end
  ret
end

n = gets.to_i
ans = Float::INFINITY
for a in 1...n do
  b = n - a
  ans = [dsum(a) + dsum(b), ans].min
end
p ans

Measured memory_bytes: 1788
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 count = 0;

    for (int i = 0;i<n ;i++ ) {
      l[i] = sc.nextInt();
    }

    Arrays.sort(l);

    for (int i = 0;i<n-2 ;i++ ) {
      for (int j = i+1;j<n-1 ;j++ ) {
        for (int t = j+1;t<n ;t++ ) {
          if (l[i]!=l[j]&&l[i]!=l[t]&&l[j]!=l[t]) {
              if (l[t]<l[i]+l[j]) {
                count++;
              }
          }
        }
      }
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 36500
N,M=map(int,input().split())
k=[]
s=[]
ans=0

for i in range(M):
    l=list(map(int,input().split()))
    k.append(l[0])
    s.append(l[1:])
p=list(map(int,input().split()))

for i in range(2**N): #スイッチのon/off 2**N通り
    light=0
    b=bin(i)[2:].zfill(N) #i番目のスイッチのon/offはb[i]の0/1で決まる
    for j in range(M): #豆電球,M通り
        cond=0
        for l in range(k[j]): #豆電球jにつながったスイッチs[j][l]
            cond+=(int(b[s[j][l]-1]))
        if cond%2==p[j]:
            light+=1
    if light==M:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<int,int>;
using namespace std;
template<class T>T chmin(T a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T b,T a){if(a<b){a^=b;b^=a;a^=b;return 1;}return 0;}

ll n;
vector<ll> p;
void input(){
    cin>>n;
    p.resize(n);
    for(int i = 0; i < n; ++i) {
        cin>>p[i];
    }
}
void src(){
    ll count=0;
    for(int i = 0; i < n; ++i) {
        if(p[i]!=i+1) count++;
    }
    cout<<(count==2 or count==0 ? "YES":"NO");
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc069A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            Console.WriteLine((A - 1) * (B - 1));
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional> // for less 
    using namespace __gnu_pbds; 
    using namespace std;
    //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;    
    #define ll            long long
    #define pb            push_back
    #define ppb           pop_back
    #define si            set <ll>
    #define endl          '\n'
    #define fr            first
    #define sc            second
    #define mii           map<ll,ll>
    #define msi           map<string,ll>
    #define mis           map<ll,string>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define all(v)        v.begin(),v.end()
    //#define sort(v)       sort(all(v))
    #define pii           pair<ll ,ll >
    #define vi            vector<ll >
    #define vii           vector<pair<ll,ll>>
    #define vs            vector<string>
    #define sz(x)         (ll)x.size()
    #define M             1000000007
    #define bs            binary_search
    #define rev(a)        reverse(all(a));
    #define sp(n)         setprecision(n)
    #define spl           " "
    #define arr(a,n)      rep(i,0,n) cin>>a[i]
    #define mod           998244353
    #define print_vector(a)  for(auto t:a) cout<<t<<" ";cout<<endl;
    #define print_arr(a,n)   rep(i,0,n) cout<<a[i]<<" "; cout<<endl;        
    #define show(a,n)     for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    #define debug(x)      cout << #x << " is " << x << endl;
    #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    #define INF           1ll<<31
    #define hi            cout<<"hi"<<endl;
    const ll maxn=int(3e5)+500;
    const ll maxa=(1<<20)+3;
    ll bpow(ll a, ll b, ll mm = M)
    {
        ll res = 1;
     
        while(b)
        {
            if(b & 1)
                res = (res * a) % mm;
            a = (a * a) % mm;
     
            b >>= 1;
        }
     
        return res;
    }
    bool cmp(pair<ll,ll> a,pair<ll,ll> b)
    {
      if(a.sc!=b.sc) return a.sc<b.sc;
      else return a.fr<b.fr;
    }
    void solve()
    {
      ll n;
      cin>>n;
      std::vector<pair<ll,ll>> v(n);
      rep(i,0,n) cin>>v[i].fr>>v[i].sc;
      sort(all(v),cmp);
      rep(i,1,n) v[i].fr+=v[i-1].fr;
      rep(i,0,n) if(v[i].fr>v[i].sc) {cout<<"No"<<endl; return;}
      cout<<"Yes";

    } 
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
        //cin>>t;
        while(t--) solve();
    }

  

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

ll N;
int dfs(ll n, bool a, bool b, bool c){
	if (n > N){
		return 0;
	} // end if

	int res = 0;

	if (a && b && c){
		++res;
	} // end if

	res += dfs(10LL * n + 3LL, true, b, c);
	res += dfs(10LL * n + 5LL, a, true, c);
	res += dfs(10LL * n + 7LL, a, b, true);

	return res;
}

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

	cin >> N;
	int res = dfs(0LL,false,false,false);

	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  string s,t;cin>>s>>t;
  t=t+s;
  cout<<t<<endl;
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	int d[n];
	int count = 0;
	for(int i = 0;i < n;i++){
		cin >> d[i];
	}
	sort(d,d+n);
	int a = d[n/2 -1];
	int b = d[n/2];
	cout << b-a << endl;
}

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    int plug = 1;
    int tap = 0;
    while(plug<B){
        tap ++;
        plug = plug + A - 1;
    }
    cout << tap << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    cin>>n;
    std::vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin>>v[i];
    sort(v.begin(),v.end());
    cout<<v.back()-v.front()<<endl;
}

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

int n,a[maxn],g1[maxn],g2[maxn];

int gcd(int i,int j)
{
    return j==0?i:gcd(j,i%j);
}

int main()
{
    int i,s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    g1[1]=a[1];
    g2[n]=a[n];
    for(i=2;i<=n;i++)
    {
        g1[i]=gcd(a[i],g1[i-1]);
        g2[n-i+1]=gcd(a[n-i+1],g2[n-i+2]);
    }
    for(i=2;i<n;i++) s=max(s,gcd(g1[i-1],g2[i+1]));
    s=max(s,max(g1[n-1],g2[2]));
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void) {
	int x,i;
	i=1;
	while(1){
    	scanf("%d", &x);
    		if ( x == 0 ) break;
		printf("Case %d: %d\n",i,x);
		i=i+1;
	}
	return 0;
}



Measured memory_bytes: 2576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <ctime>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
#define ez(i,x) for(int i = h[x]; i; i = e[i].next)
#define fi first
#define se second
#define MS(x) memset(x, 0, sizeof(x))
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,1,n) scanf("%d", &a[i-1]);
	sort(a.begin(),a.end());
	long long b = 0;
	rep(i,0,k-1) b += a[i];
	cout << b << endl;
}

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

int main(void) {
  int n, q, cnt = 0;
  int A[100000];
  
  cin >> n;
  for (int i = 0; i < n; i++) A[i] = []{ int v; cin >> v; return v; }();
  
  cin >> q;
  for (int i = 0; i < q; i++) {
    int v;
    cin >> v;
    if (binary_search(A, A+n, v)) cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1548
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<bool,int>> cor(n, {false, 0});

    int ac = 0, wa = 0;
    auto cnt = [&](int i, string s){
        if(s == "AC" && !cor[i-1].first){
            ac++;
            wa += cor[i-1].second;
            cor[i-1].first = true;
        }
        else if (s == "WA" && !cor[i-1].first){
            cor[i-1].second++;
        }
    };
    int p;
    string s;
    for(int i = 0; i< m;i++){
        cin >> p >> s;
        cnt(p, s);
    }

    cout << ac << " " << wa << endl;

    return 0;
}

Measured memory_bytes: 4052
#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 req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








      

 
int main(){
   int h,w,k;
   cin >> h >> w >> k;
   vector <string> c(h);
   
   rep (i,h) cin >> c[i];
    

  // {0, 1, ..., n-1} の部分集合の全探索
  int ans=0;
  for (int t = 0;t < (1<<h); ++t){
    for (int y = 0; y < (1<<w); ++y){
        vector<string> S=c;
        for (int i = 0; i < h; ++i) {
            if (t & (1<<i)) { // 列挙に i が含まれるか
            rep (j,w) S[i][j]='r';
            }

        for (int j = 0;j < w;j++){
              if (y & (1<<j)) {
                rep (i,h) S[i][j]='r';
              }               
            }
        }
        int cnt=0;
      rep (i,h){
        rep (j,w){
          if (S[i][j]=='#') cnt++;
        }
      }
      if (cnt==k) ans++;
    }
   
}
 cout << ans << endl;
}


Measured memory_bytes: 3596
n = [int(x) for x in input()]
op_cnt = len(n)-1
sum =0
for i in range (2**op_cnt):
  op = ['']*op_cnt
  for j in range(op_cnt):
    if ((i >>j)&1):
      op[op_cnt-1-j] ='+'
  formula =''

  for p_n, p_o in zip(n, op+[""]):
    formula += (str(p_n) + p_o)
  sum +=eval(formula)

print(sum)

Measured memory_bytes: 3064
import sys

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

N = int(sys.stdin.readline().strip())
As = list(map(int, sys.stdin.readline().strip().split()))

left = [0] * N
right = [0] * (N+1)

for i in range(1, N):
    left[i] = gcd(left[i-1], As[i-1])
for i in range(N-1, -1, -1):
    right[i] = gcd(right[i+1], As[i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(left[i], right[i+1]))
print(ans)




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

using namespace std;

const int maxn = 1e5 + 20;
const int mod = 1e9 + 7;

long long a[maxn];
long long b[maxn];

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n, s1 = 0, s2 = 0, t1 = 0, t2 = 0, x, y;
    cin >> x >> y;
    if (x == 0 && y == 0){cout << "Brown" << endl; return 0;}
    if (abs(x - y) <= 1){cout << "Brown" << endl; return 0;}
    cout << "Alice" << endl;

    return 0;
}











Measured memory_bytes: 256
s=input()
l=len(s)
n=2**(l-1)
total=0
for i in range(n):
    buf=s[0]
    for j in range(l-1):
        if ((i>>j)&1):
            total+=int(buf)
            buf=s[j+1]
        else:
            buf+=s[j+1]
    total+=int(buf)
print(total)

Measured memory_bytes: 3060
package main
 
import (
	"bufio"
	"os"
	"sort"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}
 
func scanString() string {
	sc.Scan()
	return sc.Text()
}
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func calcmax(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	var N int
	var S string
	N = scanInt()
	max := 0
	m := map[string]int {}
	for i := 0; i < N; i++ {
	    S = scanString()
		m[S] = m[S] + 1
		max = calcmax(max, m[S])
	}
	l := []string {}
	for k, v := range m {
		if v == max {
			l = append(l, k)
		}
	}
	sort.Slice(l, func(i, j int) bool { return l[i] < l[j] })
	var wr = bufio.NewWriter(os.Stdout)
	for _, v := range l {
		wr.WriteString(v + "\n")
	}
	wr.Flush()
}


Measured memory_bytes: 32204
import sys

input = sys.stdin.readline


def ii():
    return int(input())


def il():
    return list(map(int, input().split()))


K, S = il()
c = 0
for x in range(K + 1):
    for y in range(K + 1):
        if 0 <= (S - (x + y)) <= K:
            c += 1
print(c)


Measured memory_bytes: 3060
#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 + 100, INF = 1e9 + 10, MOD = 1e9 + 7;

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

const int N = 1e5 + 100;
bool used[SIZE];
vector<ll> s;
vector<vector<ll>> gr;
ll mxDist[SIZE];
ll k;

ll ans = 0;
void dfs(int v) {
    ll dst = 0;
    for (auto to : gr[v]) {
        dfs(to);
        if (mxDist[to] + 1 == k && v != 0) {
            mxDist[to] = -INF;
            ans++;
        }
        dst = max(dst, mxDist[to] + 1);
    }

    mxDist[v] = dst;
}
signed main()
{
    fastInp;

    ll n;
    cin >> n >> k;

    vector<ll> vec(n);
    for (int i = 0; i < n; i++) cin >> vec[i];

    if (vec[0] != 1) ans++;
    vec[0] = 1;
    
    gr.resize(n);
    for (int i = 1; i < n; i++) {
        gr[vec[i] - 1].push_back(i);
    }

    dfs(0);

    cout << ans;

    return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N); for (int i = 0; i < N; ++i) cin >> A[i];
  vector<int> v(A), B;
  sort(begin(v), end(v));
  for (auto&& x : A) B.push_back(lower_bound(begin(v), end(v), x) - begin(v));
  int ans = 0; for (int i = 0; i < N; ++i) ans += (i % 2 != B[i] % 2);
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n, m;
vector<int> g[8];
int cnt;

void dfs(int cn, int s) {
	if (s == (1LL<<n)-1){
		cnt++;
		return;
	}
	
	REP(i,g[cn].size()){
		int to = g[cn][i];
		
		if ((s>>to) & 1) continue;
		
		dfs(to, s|(1LL<<to));
	}
}

int main(){
	cin >> n >> m;
	
	REP(i,m){
		int a, b;
		cin >> a >> b;
		
		a--;
		b--;
		
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	dfs(0,1);
	
	cout << cnt << endl;
	
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	int sum = 0;
	vector<int> ans;
	for (int i = 1; i <= n && sum < n; i++) {
		sum += i;
		ans.push_back(i);
	}
	int over = sum - n;
	for (int x : ans) {
		if (x != over) cout << x << endl;
	}
}


Measured memory_bytes: 384
all_num, select_num = map(int, input().split())
dice = [int(a) for a in input().split()]

for i in range(all_num - (select_num - 1)):
    if i == 0:
        max_sum = this_sum = sum(dice[i:(i + select_num)])
    else:
        this_sum = this_sum - dice[i - 1] + dice[i + select_num - 1]

        if this_sum > max_sum:
            max_sum = this_sum

print((max_sum + select_num) * 0.5)

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


#----------
N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#----------
flag_plus_minus = ""
count = 0
if len(A_list) == 1:
    count = 1
else:

    for i in range(len(A_list)-1):
        diff = A_list[i+1] - A_list[i]
    
        if flag_plus_minus == "" :
            flag_plus_minus = str((diff > 0) - (diff < 0))
            count += 1

        if flag_plus_minus == "0" :
            flag_plus_minus = str((diff > 0) - (diff < 0))
        
        if flag_plus_minus != "" and A_list[i] != A_list[i+1] :
            if ( diff * int(flag_plus_minus) ) < 0:
                flag_plus_minus = ""
                
                if i == (len(A_list)-1) - 1:
                    count += 1
        
print(count)


Measured memory_bytes: 14252
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b)
        printf("a > b\n");
    else if(a<b)
        printf("a < b\n");
    else if(a==b)
        printf("a == b\n");
        return 0;
}



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

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef long long int llint;


int main() {
    fast_io;
	llint n;
	cin >> n;
	vector<llint> v(n);
	unordered_map<llint, llint> m; 
	for(auto &i : v) cin >> i;
    llint sum=0;
	for (llint i = 0; i < n; i++) m[v[i]]++,sum+=v[i];
	llint q;
	cin >> q;
	//llint sum = accumulate(v.begin(), v.end(), 0);
	
	for(llint i = 0; i < q; i++){
		llint a,b;
		cin >> a >> b ;
		
		sum = sum - (1LL*a*m[a]) +(1LL*b*m[a]);
		
		m[b] += m[a];
		
		m[a] = 0;

		cout << sum << endl;		
	}
	
}


Measured memory_bytes: 7892
//Name: Surf Smelt Fishing Contest
//Level: 1
//Category: やるだけ
//Note:

#include <iostream>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;

    int winner, winner_v = -1;
    for(int i = 0; i < N; ++i) {
        int a, v;
        cin >> a >> v;
        if(v > winner_v || (v == winner_v && a < winner)) {
            winner = a;
            winner_v = v;
        }
    }
    cout << winner << ' ' << winner_v << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1192
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:i32 = read();
    let mut a: Vec<i32> = (0..n).map(|_| read()).collect();
    a.sort();
    a.reverse();
    let a1 = a.iter().zip(0..n).fold(0, |a, (x,i)| {
        if i % 2 == 0 { a + x } else { a } });
    let a2 = a.iter().zip(0..n).fold(0, |a, (x,i)| {
        if i % 2 != 0 { a + x } else { a } });
    println!("{}", (a1 - a2).abs());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;

//けんちょん式 Union-Find
struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x)
    {
        return -par[root(x)];
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<P> AB(m);
    rep(i, m)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        AB[i].first = a;
        AB[i].second = b;
    }

    ll ans = 0;
    //iコめの辺がなかったとき橋になるか？
    rep(i, m)
    {
        UnionFind uf(n);
        rep(j, m)
        {
            if (j == i)
                continue;
            uf.merge(AB[j].first, AB[j].second);
        }

        //橋チェック
        bool ok = false;
        rep(p, n)
        {
            rep(q, n)
            {
                if (p == q)
                    continue;
                if (!uf.issame(p, q))
                {
                    ok = true;
                }
            }
        }
        if (ok)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
// --------------
// Tejas Pandey  |
// 24 - 08 - 19  |
// JSC 2019 QF   |
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		ll n,k;
		cin >> n >> k;
		ll a[n];
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		ll fk = ((k * (k+1))/2)%mod,bk = ((k * (k-1))/2)%mod;
		//cout << fk << " " << bk << "\n";
		ll ans = 0;
		for(int i = 0;i < n;i++){
			ll ninv = 0,inv = 0;
			for(int j = i+1;j < n;j++){
				if(a[i] > a[j])
				inv++;
				else if(a[i] < a[j])
				ninv++;
			}
			ans = (ans + (fk * inv)%mod)%mod;
			ans = (ans + (bk * ninv)%mod)%mod;
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int A, B, ans, n;
	cin >> A >> B;
	ans = (B - 1) / (A - 1);
	if ((B - 1) % (A - 1) != 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i+=2) {
        int tmp = 0;
        for(int j=1; j<=n; j++) {
            // cout << i << " " <<j << " " << i%j << endl;
            if (i%j==0) tmp++;
        }
        if (tmp==8) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    rep (i, a.size()) cin >> a[i];
    sort(all(a));
    vector<int> b;
    map<int, bool> m;
    rep (i, n) {
        bool ok = true;
        if (i > 0 && a[i] == a[i - 1]) ok = false;
        if (i < n - 1 && a[i] == a[i + 1]) ok = false;
        if (ok) b.push_back(a[i]);
        else m[a[i]] = true;
    }
    // rep (i, b.size()) eprintf("%d ", b[i]); eprintf("\n");
    int ans = 0;
    rep (i, b.size()) {
        bool ok = true;
        for (int j = 1; j * j <= b[i]; j++) {
            if (b[i] % j != 0) continue;
            if (m[j] || m[b[i] / j]) {
                // eprintf("%d %d %d\n", b[i], j, b[i]/j);
                ok = false;
                break;
            }
        }
        if (ok) {
            ans++;
            // eprintf("%d\n", b[i]);
        }
        m[b[i]] = true;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 33660
#include <stdio.h>
#define MAX_NUM (50)

int main() {
    int m[MAX_NUM] = {0}, f[MAX_NUM] = {0}, r[MAX_NUM] = {0};
    int i, j;
    
    i = 0;
    while(1) {
        scanf("%d %d %d", &m[i], &f[i], &r[i]);
        if(m[i] == -1 && f[i] == -1 && r[i] == -1) break;
        i++;
    }
    
    for(j = 0; j < i; j++) {
        if(m[j] == -1 || f[j] == -1) {
            printf("F\n");
        } else if(m[j]+f[j] >= 80) {
            printf("A\n");
        } else if(m[j]+f[j] >= 65) {
            printf("B\n");
        } else if(m[j]+f[j] >= 50) {
            printf("C\n");
        } else if(m[j]+f[j] >= 30 && r[j] >= 50) {
            printf("C\n");
        } else if(m[j]+f[j] >= 30) {
            printf("D\n");
        } else {
            printf("F\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2136
import java.io.PrintWriter;
import java.util.BitSet;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        new Solver().solve(in, out);

        in.close();
        out.flush();
    }

    private static class Solver {
        public void solve(Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            char[] chars = s.toCharArray();
            BitSet bs = new BitSet(chars.length);
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == 'W') {
                    bs.set(i);
                }
            }

            if (bs.get(0) || bs.get(chars.length - 1)) {
                out.println(0);
                return;
            }

            BitSet ch = bs.get(1, chars.length);
            ch.xor(bs);

            BitSet lr = new BitSet(chars.length);
            int l = 1;
            long cases = 1;
            for (int i = 0; i < chars.length - 1; i++) {
                if (ch.get(i) ^ lr.get(i)) {
                    l++;
                    continue;
                }

                lr.set(i + 1);
                cases = (cases * l) % 1000000007;
                l--;
            }

            if (l != 0) {
                out.println(0);
                return;
            }

            for (int i = n; i > 1; i--) {
                cases = (cases * i) % 1000000007;
            }
            out.println(cases);
        }
    }
}

Measured memory_bytes: 28552
N = int(input())

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

cnt = {}

for x in a:
    if x not in cnt:
        cnt[x] = 1
    else:
        cnt[x] += 1

ans = 0

for key, value in cnt.items():
    if(key < value):
        ans += value - key
    elif(key > value):
        ans += value

print(ans)


Measured memory_bytes: 17780
import math

n,k=map(int,input().split())

def comb(n, r):
    if n-r>=0:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else: 
        return 0

for i in range(1,k+1):
    a = comb(k-1, i-1)
    b = comb(n-k+1, i)
    print((a*b)%(10**9+7))


Measured memory_bytes: 3316
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

	
    public static void main(String[] args) {
    	
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
      
        if(a+b>=c)
        	System.out.println("Yes");
        else
        	System.out.println("No");
        in.close();
    }

	
}


Measured memory_bytes: 23124
N=int(input())
W=list(input() for i in range(N))

for i in range(N-1):
	if W.count(W[i]) == 2:
		print("No")
		break
	if W[i][-1] != W[i+1][0]:
		print("No")
		break
else:
	print("Yes")

Measured memory_bytes: 9124
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


    EXPLAINATION BELOW->
   

*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
  int n,k,i,d,t;cin>>n>>k;
  set<int>s;
  fo(i,0,k)
  {
     cin>>d;
     while(d--){cin>>t;s.insert(t);}
  }
  cout<<n-(int)sz(s)<<"\n";
  
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3664
#include<stdio.h>
#include<stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if(*(int *)n1 >*(int *)n2)
	{
		return -1;
	}
	else if(*(int *)n1 < *(int *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
}
}

int main(void)
{
	int n,i,score1=0,score2=0;
	int a[101]={0};
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	
	qsort(a, sizeof(a)/ sizeof(a[0]),sizeof(int),cmpnum);
	
	for(i=0;i*2<n;i++){
		score1+=a[2*i];
		score2+=a[2*i+1];
	}
	printf("%d",score1-score2);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    cin>>N;
    int ans=0;
    vector<int>A(N);
    REP(i,N){
        cin>>A[i];
    }
    sort(A.rbegin(),A.rend());
    REP(i,N){
        if(i%2==0)ans+=A[i];
        else ans-=A[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> d(N, 0);
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			ans += (d[i] * d[j]);
		}
	}
	cout << ans << endl;
	return 0;
}


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

constexpr int MOD = 1000000007;
int fact[200005];
int finv[200005];
int idx[100005];
int ans[100005];

int C(int n, int m)
{
    return fact[n] * 1ll * finv[m] % MOD * finv[n - m] % MOD;
}

int main()
{
    fact[0] = 1;
    for (int i = 1; i <= 200000; i++) fact[i] = fact[i - 1] * 1ll * i % MOD;

    finv[200000] = 750007460;
    for (int i = 199999; i >= 0; i--) finv[i] = finv[i + 1] * 1ll * (i + 1) % MOD;

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

    int a, b;

    for (int i = 1; i <= n + 1; i++)
    {
        int x;
        scanf("%d",&x);
        if (idx[x] == 0) idx[x] = i;
        else
        {
            a = idx[x];
            b = i;
            break;
        }
    }

    for (int i = 1; i <= n + 1; i++)
    {
        ans[i] = C(n + 1, i);
    }

    int L = a - 1;
    int R = n - b + 1;

    for (int i = 0; i <= L + R; i++)
    {
        ans[i + 1] = (ans[i + 1] + MOD - C(L + R, i)) % MOD;
    }

    for (int i = 1; i <= n + 1; i++) printf("%d\n", ans[i]);
}


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

using namespace std;

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

  int n;cin>>n;
  std::vector<int> v;
  for(int i=0;i<n;i++){
      int a;cin>>a;
      v.push_back(a);
  }
  sort(v.begin(),v.end());
  int res=10000001;
  for(int i=-100;i<=100;i++){
      int tmp=0;
      for(int j=0;j<n;j++) tmp+=(v[j]-i)*(v[j]-i);
      res=min(res,tmp);
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int x,a,b;
	cin>>x>>a>>b;
	cout << (abs(x-a)<abs(x-b)?"A":"B") << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

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

int main() {
	int N;
	scanf("%d", &N);
	map<string, int> judge;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		judge[s]++;
	}
	cout << "AC x " << judge["AC"] << endl;
	cout << "WA x " << judge["WA"] << endl;
	cout << "TLE x " << judge["TLE"] << endl;
	cout << "RE x " << judge["RE"] << endl;
	return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

    int N; cin >> N;
    vector<int> a;
    REPS(i, 1, 9) {
        REPS(j, 1, 9) {
            a.pb(i * j);
        }
    }
    for (int x : a) {
        if (x == N) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;
struct Edge{
    ll to,id;
};
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v,int c=-1,int p=-1){
    int k=1;
    rep(i,g[v].size()){
        int u=g[v][i].to,ei=g[v][i].id;
        if(u==p) continue;
        if(k==c) ++k;
        ans[ei]=k;++k;
        dfs(u,ans[ei],v);
    }
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>n;
    ll a,b;
    g.resize(n);
    ans=vector<int>(n-1);
    rep(i,n-1){
           cin >> a>>b;
           --a;
           --b;
           g[a].push_back((Edge){b,i});
           g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx=0;
    rep(i,n) mx=max(mx,int(g[i].size()));
    cout<<mx<<endl;
    rep(i,n-1){
        cout<<ans[i]<<endl;
    }
    //rep(i,n) cout<<d[i]<<" "<<endl;


    return 0;
}

Measured memory_bytes: 11136
people, menu = map(int, input().split())

base = [int(i) for i in input().split()]
base.pop(0)

d = {}
for b in base:
    d[b] = 1

for _ in range(people-1):
    tmp = [int(i) for i in input().split()]
    tmp.pop(0)
    for t in tmp:
        if t in d:
            d[t] += 1


cnt = 0
for v in d.values():
    if v == people:
        cnt += 1
print(cnt)


Measured memory_bytes: 3064
#include <stdio.h>

int main() {
	int i;
	int num;
	int *data;

	scanf("%d", &num);
	
	data = new int[num];
	for (i = 0; i < num; i++) scanf("%d", &data[i]);

	int min, max;
	long long int sum=0;
	min = max = data[0];
	for (i = 0; i < num; i++) {
		if (min > data[i])min = data[i];
		else if (max < data[i])max = data[i];
		sum += (long long int)data[i];
	}


	printf("%d %d %lld\n",min,max,sum);
	
	delete[] data;
	return 0;
}

Measured memory_bytes: 2748
a,b,c,x,y = map(int, input().split())
if b < a:
    a,b = b,a
    x,y = y,x
if c >= (a+b)/2:
    ans = a*x + b*y
else:
    ans = c*min(x,y)*2
    if x >= y:
        if 2*c > a:
            ans += (x-y)*a
        else:
            ans += (x-y)*2*c
    else:
        if 2*c > b:
            ans += b*(y-x)
        else:
            ans += c*(y-x)*2
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(a);cout<<3*a*a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
   ll A, B; cin >> A >> B;
   ll C = 0;
   cout << max(A-2*B, C);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,K; cin >> N >> K;
    int d,a;
    vector<int> res(N,0);
    int out=0;
    for(int i=0;i<K;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> a;
            a--;
            res[a]++;
        }
    }
    for(int i=0;i<N;i++){
        if(res[i]==0) out++;
    }
    cout << out << endl;
    return 0;
}


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

int main() {
  int n,m,x;
  int r=0,l=0,ans=0;
  cin >> n >> m >> x;
  int a[m];
  for(int i =0 ;i < m;i++){
  	cin >> a[i];
  }
  for(int i= 0;i <= n;i++){
    for(int j = 0 ;j < m;j ++){
    	if(i == a[j]){
          if(i < x){
  			l++;
            break;
          }else if(i > x){
			r++;
            break;
          }
        }
    }
  }
  cout << min(r,l) << endl;
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 1e16+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ans = 0;
   	int tmp1=inf,tmp;
    rep(i,n-1)
    {
    	cin>>tmp;
    	if(i==0) ans+=tmp;
    	else
    	{
    		ans+=min({tmp,tmp1});
    	}
    	tmp1 = tmp;
    }
    ans+=tmp;
    cout<<ans<<endl;
    return 0;

}
    

Measured memory_bytes: 256