akhauriyash/Code-Regression huggingface dataset:
#ifdef _WIN32
#define DEBUG	1
#endif

#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

#ifdef DEBUG
#include "include.h"
#else
inline void wait(){}
inline void dout(const char *arg, ...){}
#endif

template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}

#define CLIP(ptr, min, max) {if((min)<=(max)){if(ptr<(min)){ptr=(min);}if(ptr>(max)){ptr=(max);}}}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI/180)
#define Cos(deg) cos((deg)*MATH_PI/180)
#define Tan(deg) tan((deg)*MATH_PI/180)
#define Rad(deg) ((deg)*MATH_PI/180)
#define ff(param, num) for(int param=0 ; param<num ; ++param)
#define fi(num) for(int i=0 ; i<num ; ++i)
#define fj(num) for(int j=0 ; j<num ; ++j)
#define fk(num) for(int k=0 ; k<num ; ++k)
#define fl(num) for(int l=0 ; l<num ; ++l)
#define fn(num) for(int n=0 ; n<num ; ++n)
#define ffr(param, num) for(int param=num-1 ; param>=0 ; --param)
#define fir(num) for(int i=num-1 ; i>=0 ; --i)
#define fjr(num) for(int j=num-1 ; j>=0 ; --j)
#define fkr(num) for(int k=num-1 ; k>=0 ; --k)
#define flr(num) for(int l=num-1 ; l>=0 ; --l)
#define fnr(num) for(int n=num-1 ; n>=0 ; --n)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
signed main() {

	int ii, jj, kk, ll;
	int N;
	int ret = 0;
	int flag = 0;
	char cbuf[8192];

	int M;
	gi2(N, M);

	int K;
	int table[30] = {0};
	fn(N){
		gi(K);
		fi(K){
			gi(ii);
			table[ii-1]++;
		}
	}
	fn(M){
		if(table[n] == N) ret++;
	}

	ans(ret);

	wait();

	return 0;
}

Measured memory_bytes: 256
num, yen = map(int,input().split(" "))
num_max = yen/1000
isPossible = False

for i in range(num+1):
	if(isPossible):
		break
	for j in range(num+1):
		# print("hey?")
		if(num == num_max-i*4-j*9 and num-j-i >= 0):
			print(j,i,num-j-i)
			isPossible = True
			break
if(not isPossible):
	print("-1 -1 -1")

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main() {
    string a,b;
    cin >> a >> b;
    string ans;

    if (a.size() > b.size()) ans = "GREATER";
    else if (a.size() < b.size()) ans = "LESS";
    else if (a > b) ans = "GREATER";
    else if (a < b) ans = "LESS";
    else ans = "EQUAL";

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int H, W, M;
    cin >> H >> W >> M;
    map<pii,bool> mp;
    vector<int> bh(H), bw(W);
    REP(i,M) {
        int h, w;
        cin >> h >> w;
        h--; w--;
        bh[h]++; bw[w]++;
        mp[{h,w}] = true;
    }
    vector<pii> bhr, bwr;
    REP(i,H) bhr.emplace_back(bh[i],i);
    REP(i,W) bwr.emplace_back(bw[i],i);
    sort(RALL(bhr));
    sort(RALL(bwr));

    int ans = 0;
    int hmax = bhr[0].first;
    int hi = 0;
    bool loop = true;
    while(bhr[hi].first == hmax && hi < H) {
        int wmax = bwr[0].first;
        int wi = 0;
        while(bwr[wi].first == wmax && wi < W) {
            bool bomb = mp[{bhr[hi].second,bwr[wi].second}];
            ans = max(ans,bhr[hi].first + bwr[wi].first + (bomb ? -1:0));
            if (!bomb) {
                loop = false;
                break;
            }
            wi++;
        }
        if (!loop) break;
        hi++;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 32716
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int digitSum(int n,int digit=8) {
	// digit > 2
	int x = 1;
	FOR(i,0,digit){
		x *= 10;
	}
	int sum = 0;
	FOR(i, 0, digit) {
		sum += n / x;
		n %= x;
		x /= 10;
	}
	sum += n;
	return sum;
}


int main()
{
	string forFill = "";
	vector<string> a(102);
	int height, width;
	cin >> height >> width;
	FOR(i, 0, width + 2) {
		forFill += '#';
	}
	fill(a.begin(), a.end(), forFill);
	FOR(i, 1, height+1) {
		cin >> a[i];
		a[i] = "#" + a[i] + "#";
	}
	FOR(i, 0, height + 2) {
		cout << a[i] << endl;
	}
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
const int MaxN = 1e5 + 4;
typedef long long LL;
int a[MaxN];
int main(){
	int n,k;
	cin>>n>>k;
	int ans = 0;
	int Min = 10000005;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
		Min = min(Min,a[i]);
	}int pos = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] == Min){
			pos = i;
			break;
		}
	}int t = pos;
	if(t > k && t < n-k){ 
		while(t){
			ans++;
			t -= k;
			if(t <= 0) break;
			t++;
		}int x = n-pos+1;
		while(x){
			ans++;
			x -= k;
			if(x <= 0) break;
			x++;
		}
		if(n%2 && k % 2) cout<<ans-1<<endl;
		else cout<<ans<<endl;
		return 0;
	}
	else {
		while(n){
			ans++;
			n -= k;
			if(n <= 0) break;
			n++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();
    if((100*r+10*g+b)%4==0){
      System.out.println("YES");}
    else{System.out.println("NO");}
  }
}


Measured memory_bytes: 23764
class QuickUnion:
    def __init__(self, n):
        self.conn = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def union(self, a, b):
        ra = self._root(a)
        rb = self._root(b)

        if ra == rb:
            return

        if self.size[ra] > self.size[rb]:
            self.conn[rb] = ra
            self.size[ra] += self.size[rb]
        else:
            self.conn[ra] = rb
            self.size[rb] += self.size[ra]

    def connected(self, a, b):
        ra = self._root(a)
        rb = self._root(b)

        return ra == rb

    def _root(self, a):
        p = self.conn[a]
        while p != a:
            pp = self.conn[p]
            self.conn[a] = pp
            a, p = p, pp

        return a


def run():
    n, m = [int(i) for i in input().split()]
    u = QuickUnion(n)

    for _ in range(m):
        x, y = [int(i) for i in input().split()]
        u.union(x, y)

    q = int(input())

    for _ in range(q):
        x, y = [int(i) for i in input().split()]
        if u.connected(x, y):
            print('yes')
        else:
            print('no')


if __name__ == '__main__':
    run()



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

int h, w;

int main (void){
	while(true){
		cin >> w >> h;
		if(!h&&!w)break;
		vector<string> s(h);
		for(int i = 0; i < h; ++i){
			cin >> s[i];
		}
		queue<pair<int, int>> q;
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){
				if(s[i][j] == '@'){
					q.push(make_pair(i,j));
				}
			}
		}
		int dx[] = {0,1,0,-1};
		int dy[] = {1,0,-1,0};
		int cnt = 1;
		while(!q.empty()){
			int x = q.front().first;
			int y = q.front().second;
			q.pop();
			for(int dir = 0; dir < 4; ++dir){
				int nx = x + dx[dir];
				int ny = y + dy[dir];
				if(nx<0||nx>=h||ny<0||ny>=w) continue;
				if(s[nx][ny]=='.'){
					q.push(make_pair(nx,ny));
					s[nx][ny] = '!';
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;
bool compare(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    return a.second < b.second;
}
int ans = 0;int n;
void fx(ll a,int x,int y,int z){
    if(a>n){
        return;
    }else if(x>0 and y>0 and z>0){
        ans += 1;
    }
    fx(a*10+3,x+1,y,z);
    fx(a*10+5,x,y+1,z);
    fx(a*10+7,x,y,z+1);
}
int main(){
    cin >> n;
    fx(3,1,0,0);fx(5,0,1,0);fx(7,0,0,1);
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	vs := make([]int,n)
	cs := make([]int,n)
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		vs[i] = v
	}

	for i := 0; i < n; i++ {
		var c int
		fmt.Scan(&c)
		cs[i] = c
	}

	ans := 0
	for i := 0; i < n; i++ {
		if vs[i] > cs[i] {
			ans += vs[i] - cs[i]
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
N = int(input())
AB = []
for i in range(N):
	A, B = map(int, input().split())
	AB.append((A + B, A, B))
AB.sort()
AB.reverse()
ans = 0
for i in range(N):
	if i % 2 == 0:
		ans += AB[i][1]
	else:
		ans -= AB[i][2]
print(ans)

Measured memory_bytes: 61308
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 1e9 + 7;

unsigned long long n, m, sum;
int main()
{
	sum = 1;
	scanf("%lld %lld", &n, &m);
	int tt = max(n,m) - min(n,m);
	if(tt > 1) printf("0\n");
	else {
		if(n == m) {
			n++;
			m++;
			while(n--)
			{
				if(n == 0) break;
				sum = ((sum % MAXN) * n) % MAXN;
				sum = sum % MAXN;
			}
			while(m--)
			{
				if(m == 0) break;
				sum *= m;
				sum = sum % MAXN;
			}
			sum = sum * 2;
			sum = sum % MAXN;
		}
		else {
			int p = max(n, m);
			int o = min(n, m);
			o++;
			p++;
			while(o--)
			{
				if(o == 0) break;
				sum = ((sum % MAXN) * o) % MAXN;
				sum = sum % MAXN;
			}
			while(p--)
			{
				if(p == 0) break;
				sum = ((sum % MAXN) * p) % MAXN;
				sum = sum % MAXN;
			}
		}
		printf("%lld\n", sum);
	}
}

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

int main()
{
    int s,t,d,ans;
    scanf("%d %d %d",&d,&t,&s);
    ans=d/s;
    if(d%s>0)ans++;
    if(ans<=t)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;
	vi alph(26);
	rep(i, s.size())alph[s[i] - 'a']++;
	ll same = 0;
	for (int x : alph)same += (ll)x * (x - 1) / 2;
	cout << (ll)s.size() * (s.size() - 1) / 2 - same + 1 << endl;

}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int x, a, b;
    cin >> x >> a >> b;
    int d1 = abs(x - a), d2 = abs(x - b);
    cout << (d1 < d2 ? 'A' : 'B') << endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations as perm


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


def getCost(p):
    ret = 0
    for i, ni in zip(p, p[1:]):
        x, y = XY[i]
        nx, ny = XY[ni]
        ret += ((nx-x)**2+(ny-y)**2)**0.5
    return ret


N = int(input())
XY = [inpl() for i in range(N)]

ans = sum(getCost(p) for p in perm([i for i in range(N)]))

f = 1
for i in range(1, N + 1):
    f *= i
print(ans / f)


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

const int MAX_N = 200001;

int main(){
  int N,K;
  cin >> N >> K;
  int count[MAX_N];
  for(int i = 0 ; i < MAX_N ; i++){
    count[i] = 0;
  }

  for(int i = 0 ; i < N; i++){
    int tmp;
    cin >> tmp;
    count[tmp]++;
  }

  vector<int>vec;

  for(int i = 0 ; i < MAX_N ; i++){
    if(count[i] == 0)continue;
    vec.push_back(count[i]);
  }

  sort(vec.begin(),vec.end());

  int sum = 0;

  for(int i = 0 ; i < (int)vec.size() - K ; i++){
    sum += vec[i];
  }

  cout << sum << endl;

  return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).OrderByDescending(i => i).ToArray();

            Console.WriteLine(input[0] * 10 + input[1] + input[2]);
        }
    }
}

Measured memory_bytes: 13396
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


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


bool compare(pair<string, int> a, pair<string, int >b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    pair<string, int> P;
    vector < pair<string, int>> v,v2;
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> P.first >> P.second;

        v.push_back(P);
        v2.push_back(P);
    }
    sort(v.begin(), v.end(),compare);

    for (int i = 0; i < n; i++) {
        //cout << v[i].first << " " << v[i].second << endl;
        for (int j = 0; j < n; j++) {
            if (v[i].first == v2[j].first) {
                if (v[i].second == v2[j].second) {
                    cout << j + 1 << endl;
                }
            }
        }
    }
    return 0;
}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int dp[100005][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;

    rep(i, n) {
        { // a+b = 0
            if (s[i] == '0') {
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
            } else {
                dp[i + 1][1] = (dp[i][0] + dp[i][1]) % MOD;
            }
        }
        { // a+b = 1
            if (s[i] == '0') {
                (dp[i + 1][1] += dp[i][1] * 2 % MOD) %= MOD;
            } else {
                (dp[i + 1][0] += dp[i][0] * 2 % MOD) %= MOD;
                (dp[i + 1][1] += dp[i][1] * 2 % MOD) %= MOD;
            }
        }
    }

    int ans = (dp[n][0] + dp[n][1]) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll A,B;cin >> A >> B;
  if((A+B)&1)cout << "IMPOSSIBLE" << endl;
  else cout << (A+B)/2 << endl;
  return 0;
}


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

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

	string S, T;

	cin >> S >> T;

	int tekichu = 0;
	for (int i = 0; i < 3; i++)
	{
		tekichu += (S[i] == T[i]) ? 1 : 0;
	}

	cout << tekichu;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
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>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

vector<ll> BellmanFord(vector<vector<pair<ll,ll>>> graph,int s) {
    int n=sz(graph);
    vector<ll> dist(n,LINF);
    dist[s]=0;
    
    rep(i,n-1) {
        rep(from,n) {
            for(auto p:graph[from]) {
                int to=p.first;
                ll cost=p.second;
                chmin(dist[to],(dist[from]==LINF ? LINF : dist[from]+cost));
            }
        }
    }
    
    rep(i,n+1) {
        rep(from,n) {
            for(auto p:graph[from]) {
                int to=p.first;
                ll cost=p.second;
                if(chmin(dist[to],(dist[from]==LINF ? LINF : dist[from]+cost))) {
                    dist[to]=-LINF;
                }
            }
        }
    }
    
    return dist;
}

int main() {
    int n,m;
    ll p;
    cin>>n>>m>>p;
    vector<vector<pair<ll,ll>>> graph(n);
    while(m--) {
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--;b--;
        graph[a].emplace_back(b,-c+p);
    }
    
    auto d=BellmanFord(graph,0);
    cout<<(d[n-1]==-LINF ? -1 : max(-d[n-1],0LL))<<endl;
}


Measured memory_bytes: 768
import collections
n = int(input())
a = list(map(int,input().split()))
 
u = collections.Counter(a)
 
sume = 0
for i in u.values():
    sume += int(i*(i-1)/2)
 
for k in range(n):
    s = u[a[k]]
    print(sume-s+1)

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
if (A+B>C+D){
    cout<<"Left"<<endl;
}else if(A+B==C+D){
    cout<<"Balanced"<<endl;
}else{
     cout<<"Right"<<endl;
}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;


int main(){
    ll N;
    cin >> N;
    ll ans = 1;
    repf(i, 1, N+1){
        ans = (ans * i) % mod;
    }
    cout << ans << endl;
}

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

typedef long long ll;

using namespace std;
int main(){
    int n;cin >> n;
    int sum=0;
    int tmp=n;
    while(tmp>=1){
        sum+=(tmp%10);
        tmp/=10;
    }
    if(n%sum==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

constexpr int P = 1'000'000'007;

char s[500'005];
int n, next1[500'005], next2[500'005];

void getNext (int *next, char *p) {
	int t;
	t = next[0] = -1;
	int j = 0;
	while (j < n) {
		if (t < 0 || p[j] == p[t]) {//匹配
			j++, t++;
			next[j] = t;
		}
		else //失配
			t = next[t];
	}
}

int main () {
	std::cin >> (s+1);
	n = strlen (s+1);
	bool same = true;
	for (int i = 1; i < n; ++i)
		if (s[i] != s[i+1])
			same = false;
	getNext (next1, s+1);
	std::reverse (s+1, s+1+n);
	getNext (next2, s+1);
	if (n % (n - next1[n]) != 0 || next1[n] == 0) {
		std::cout << 1 << "\n1\n";
	} else if (same) {
		std::cout << n << "\n1\n";
	} else {
		int ans = 0;
		for (int i = 1, j = n-1; i <= n-1; ++i, --j) {
			bool flag = true;
			if (i % (i - next1[i]) == 0 and i > (i - next1[i])) flag = false;
			if (j % (j - next2[j]) == 0 and j > (j - next2[j])) flag = false;
			if (flag) ans++;
		}
		std::cout << 2 << "\n" << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 4608
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int count_range(const vector<int>& v, int a, int b){
    int cnt=0;
    for(uint i=0; i<v.size(); ++i){
        if(a <= v[i] && v[i] <=b){ ++cnt; }
    }
    return cnt;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M, X; cin >> N >> M >> X;
    vector<int> vA(M); for(int i=0; i<M; ++i){ cin >> vA[i]; }
    int num1 = count_range(vA, 0, X); // 0 -> X
    int num2 = count_range(vA, X, N); // X -> N
    
    cout << min(num1, num2) << endl;
    
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
c=[input() for i in range(H)]
res=0
for i in range(W-1):
    dp=[[0 for j in range(H+1)] for k in range(H+1)]
    table=[[0 for j in range(H+1)] for k in range(H+1)]
    for j in range(1,H+1):
        for k in range(1,H+1):
            table[j][k]=table[j-1][k-1]+(c[j-1][i]==c[k-1][i+1])

    for j in range(1,H+1):
        for k in range(1,H+1):
            cost=table[j][k]
            dp[j][k]=cost+min(dp[j-1][k],dp[j][k-1])
    res+=dp[H][H]

print(res)


Measured memory_bytes: 226972
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;

int main(void){
  int A,B,T;
  cin >> A >> B >> T;
  cout << (T/A)*B << endl;
  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end

ll dp[201000]={};

int main(){
   int n; cin>>n;
   vector<int> a(n); rep(i,0,n)cin>>a[i];
   vector<ll> sum(n); rep(i,0,n)sum[i]=a[i]+(i?sum[i-2]:0);
   rep(i,1,n){
      if(i&1)dp[i]=max(dp[i-2]+a[i],sum[i-1]);
      else dp[i]=max(dp[i-2]+a[i],dp[i-1]);
   } printf("%lld\n",dp[n-1]);
   return 0;
}


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

typedef signed long long ll;
const int MX = 105;
int A[MX];

int main() {
    int n, ans = 0;
    cin >> n;
    for(int i = 0; i < n; cin >> A[i], i++); 
    sort(A, A + n);
    for(int i = 1; i < n; i++) {
        ans += A[i] - A[i - 1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
 
int main() {
  int N, v[1005], i;
  double X;
  scanf("%d", &N);
  for (i=0; i<N; i++) scanf("%d", &v[i]);
  sort(v, v+N); // 配列
  X=double((double)v[0]+(double)v[1])/2.0;
  for (i=2; i<N; i++) X=double(X+(double)v[i])/2.0;
  printf("%f", X);
  return 0;
}

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

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2 - (y2-y1);
    int y3 = y2 + (x2-x1);
    int x4 = x1 - (y2-y1);
    int y4 = y1 + (x2-x1);
    cout << x3 << " " << y3 << " " << x4 << " " << y4<< endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a<b&&b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26360
s = input()
s1 = int(s[0]+s[1])
s2 = int(s[2]+s[3])
if s1 == s2 == 0:
    print('NA')
elif s1 <= 12 and s2 <= 12 and s1 >= 1 and s2 >= 1:
    print('AMBIGUOUS')
elif s1 <= 12 and s1 >= 1:
    print('MMYY')
elif s2 <= 12 and s2 >= 1:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a;}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b;}

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

    int n;
    cin >> n;
    ll ans = 1;
    rep(i, n) {
        ll a;
        cin >> a;
        ans = lcm(ans, a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660
import sys,collections
from collections import deque
from operator import itemgetter
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,k = Is()
a = Is()
d = collections.defaultdict(int)
for i in range(len(a)):
    d[a[i]] += 1 
dl = sorted(list(d.items()),key=itemgetter(1))
ans = 0
for i in range(len(dl)):
    if len(d) <= k:
        break
    ans += dl[i][1]
    del d[dl[i][0]]
print(ans)

Measured memory_bytes: 41060
#include <stdio.h>

void mySwap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void mySort(int* data, int len)
{
    int i, j;
    for (i = 0; i < len; i++) {
        for (j = i; j < len; j++) {
            if (data[j] > data[i]) {
                mySwap(data + j, data + i);
            }
        }
    }
}

int main(void)
{
    int i, j;
    int points[2][10];
    int answers[2] = {0};
    for (i = 0; i < 2; i++) {
        for (j = 0; j < 10; j++) {
            scanf("%d", &points[i][j]);
        }
    }
    mySort(points[0], 10);
    mySort(points[1], 10);
    for (i = 0; i < 2; i++) {
        for (j = 0; j < 3; j++) {
            answers[i] += points[i][j];
        }
    }
    printf("%d %d\n", answers[0], answers[1]);
    return (0);
}

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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)

#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 6;

int n , a[maxn];
int res = 1;
int l[maxn] , r[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    for(int i = 1 ; i <= n ; ++i){
        l[i] = __gcd(l[i - 1] , a[i]);
    }
    for(int i = n ; i >= 1 ; --i){
        r[i] = __gcd(r[i + 1] , a[i]);
    }
    for(int i = 1 ; i <= n ; ++i){
        res = max(res , __gcd(l[i - 1] , r[i + 1]));
    }
    cout << res;
    cerr << __gcd(0,0);
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include <unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;
//struct edge {int to,cost;};
#define VMAX 200+10
    ll N,Q,A[int(1e5+10)],ans;
    int s[100000],t[100000],c[100000];
    std::unordered_set<int> Ci[31],Ce[31];
int main(){
    //std::ios_base::sync_with_stdio(false);
    cin>>N>>Q;
    REP(i,N){
        cin>>s[i]>>t[i]>>c[i];
        A[s[i]-1]++;
        A[t[i]-1]--;
        Ci[c[i]-1].insert(s[i]);
        Ce[c[i]-1].insert(t[i]);
    }
    ans=A[0];
    REP(i,100000){
        A[i+1]+=A[i];
        int temp=0;
        REP(j,Q){
            if(Ce[j].find(i+2)!=Ce[j].end()&&Ci[j].find(i+2)==Ci[j].end()){
                temp++;
            }
        }

        /*if(A[i]+temp>A[i+1]){
            ans=max(ans,(A[i+1]+temp));
        }
        else */ans=max(ans,A[i+1]+temp);
        if(i<100){DEB(temp)DEB(A[i+1])DEB(A[i])END}

    }



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



Measured memory_bytes: 13696
N = int(input())
S = input()
E = [0]*N
W = [0]*N
if S[0] == 'E':
    E[0] = 1
else:
    W[0] = 1
for i in range(1,len(S)):
    if S[i] == 'E':
        E[i] = E[i-1]+1
        W[i] = W[i-1]
    else:
        W[i] = W[i-1]+1
        E[i] = E[i-1]
MIN = float('inf')
for i in range(N):
    if i == 0:
        MIN = min(MIN,E[N-1]-E[0])
    elif i == N-1:
        MIN = min(MIN,W[N-2])
    else:
        MIN = min(MIN,W[i-1]+E[N-1]-E[i])
print(MIN)

Measured memory_bytes: 18716
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define int long long
//#define int __int128
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")

#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")

#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const int N = 5005, MOD = 1e9 + 7;

int dp[N][3];
int D[N][2];
int d[N];
int ans;

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    int n, a, b;
    cin >> n >> a >> b;
    if (a > b)
        swap (a, b);
    ans = 1;
    for (int i = 0; i < n; i++)
        ans = ans * 2 % MOD;
    if (a == 1){
        cout << ans << endl;
        return 0;
    }
    d[0] = 1;
    for (int i = 1; i <= n; i++){
        d[i] = d[i-1];
        for (int j = 0; j <= i - a; j++)
            d[i] += d[j];
        d[i] %= MOD;
    }
    D[1][1] = 1;
    for (int i = 2; i <= n+1; i++){
        D[i][1] = (D[i-1][1] + D[i-1][0]) % MOD;
        for (int j = 1; j <= i - a; j++)
            D[i][0] += D[j][1];
        D[i][0] %= MOD;
        //cout << i << " " << D[i][0] << " " << D[i][1] << endl;
    }
    dp[0][0] = 1;
    dp[0][1] = 1;
    dp[0][2] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = max (0ll, i-b+1); j < i; j++){
            if (j)
                dp[i][1] += dp[j][0] * D[i-j][1];
            else
                dp[i][1] += dp[j][0] * D[i-j+1][1];
            dp[i][1] %= MOD;
            if (i <= n){
                if (j)
                    dp[i][2] += dp[j][0] * D[i-j+1][1];
                else
                    dp[i][2] += dp[j][0] * d[i-j];
                dp[i][2] %= MOD;
            }
        }
        for (int j = max (0ll, i-a+1); j < i; j++)
            dp[i][0] += dp[j][1];
        dp[i][0] %= MOD;
        dp[i][2] += dp[i][0];
        dp[i][2] %= MOD;
        //cout << i << " " << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
    }
    //cout << dp[n][2] << endl;
    cout << (ans - dp[n][2] + MOD) % MOD << endl;
}


Measured memory_bytes: 3808
#include<cstdio>
using namespace std;
long long n,a,b;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a>b)
	{
		printf("0");
		return 0;
	}
	if(n==1)
	{
		if(a==b)
		printf("1");
		else
		printf("0");
		return 0;
	}
	long long ans=(b-a)*(n-2)+1;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n,a,b; cin >> n >> a >> b;
    if((b-a) % 2 == 0){
        cout << "Alice" << endl;
        return 0;
    }
    cout << "Borys" << endl;
}

 

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

using namespace std;
typedef map<int, int> iimap;

int main() {
    int n, a;
    iimap m;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a;
        m[a]++;
    }
    int r = 0;
    for(auto itr=m.begin(); itr!=m.end(); itr++) {
        if(itr->second % 2) r++;
    }
    cout << r << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(void) {

	int m,f,r,i,j=0;
	char a;
	int b[1000];

	while(1){
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		
		scanf("%d%d%d",&m,&f,&r);
		
		if(m==-1||f==-1){
			a='F';
		}else if(m+f>=80){
			a='A';
		}else if(m+f>=65){
			a='B';
		}else if(m+f>=50||(m+f>=30&&r>=50)){
			a='C';
		}else if(m+f>=30){
			a='D';
		}else {
			a='F';
		}
		b[j]=a;
		j++;

	}
	
	for(i=0;i<j;i++){
			if(i==(j-1)){
				break;
			}
			printf("%c",b[i]);
			if(i<(j-1)){
			printf("\n");
			}
	}
	return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

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

signed main(){
    int N, M; cin >> N >> M;
    vector<int> sw( M );
    REP( i, M ){
        int k; cin >> k;
        REP( j, k ){
            int s; cin >> s;
            s = pow( 2, s - 1 );
            sw[i] += s;
        }
    }
    vector<int> p( M );
    REP( i, M ) cin >> p[i];

    int ans = 0;
    for( int bit = 0; bit < 1 << N; bit++ ){
        bool ok = true;
        REP( i, M ){
            int on = sw[i] & bit;
            int cnt = 0;
            REP( j, N ){
                if( on & 1 ) cnt++;
                on >>= 1;
            }
            if( cnt % 2 != p[i] ) ok = false;
        }
        if( ok ) ans++;
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
c = {}
for i in range(3):
  c[i] = list(map(int, input().split()))
tfc = 0
for i in range(101):
  if tfc == 3:
    break
  else:
    tfc = 0
  cx = []
  for j in c.values():
    for k in j:
      cx.append(k)
  if i > max(cx):
    break
  b = []
  for j in range(3):
    b.append(c.get(0)[j] - i)
  for j in range(3):
    p = []
    for k in range(3):
      p.append(c.get(j)[k] - b[k])
    if min(p) == max(p):
      tfc += 1
if tfc == 3:
  print('Yes')
else:
  print('No')

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// union-find tree with potential(struct)
// https://qiita.com/drken/items/cce6fc5c579051e64fab

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

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

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

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

	int n,m;
	cin >> n >> m;	

	UnionFind<ll> uf(n);

	rep(i,m){
		ll l, r, d;
		cin >> l >> r >> d;

		l--;
		r--;

		if(uf.issame(l,r) && uf.diff(l,r) != d) {
			cout << "No" << endl;
			return 0;
		}

		uf.merge(l,r,d);
	}

	cout << "Yes" << endl;	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    int sm = 0;
    for(auto &x: a) {
        cin >> x;
        sm += x;
    }
    double base = sm/(4.0*m);
    int cnt = 0;
    for(auto x: a) {
        if(x >= base)cnt++;
    }    
    cout << (cnt >= m?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);
 
int main () {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;
  vector<ll> A(n);
  for (ll i = 0; i < n; ++i) cin >> A[i];
  sort(A.rbegin(), A.rend());
  ll ans = A[0];
  int i_ans = 1;
  int flip = false;
  for (int i = 2; i < n; ++i) {
    ans += A[i_ans];

    if (flip) ++i_ans;
    flip = !flip;
  }
  cout << ans << endl;

}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  long long sum = 0;
  int cnt = 0;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    if (A[i] < 0) cnt++;
    sum += abs(A[i]);
  }

  long long minval = sum;
  for (int i=0; i<N; i++) {
    long long a = abs(A[i]);
    minval = min(minval, a);
  }

  if (cnt % 2 == 0) {
    cout << sum << endl;
  } else {
    cout << (sum-minval) - minval << endl;
  }

  return 0;
}


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

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string ans = "";
    rep(i, 0, tx - sx)
        ans += "R";
    rep(i, 0, ty - sy)
        ans += "U";
    
    rep(i, 0, tx - sx)
        ans += "L";
    rep(i, 0, ty - sy)
        ans += "D";
    
    ans += "LU";
    rep(i, 0, ty - sy)
        ans += "U";
    rep(i, 0, tx - sx)
        ans += "R";
    ans += "RD";

    ans += "RD";
    rep(i, 0, ty - sy)
        ans += "D";
    rep(i, 0, tx - sx)
        ans += "L";
    ans += "LU";
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MAXN=105;

int n, k, d, c;

struct node{
    vector<int> adj;
};

node dsu[MAXN];

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        cin>>d;
        for(int j=0;j<d;j++){
            cin>>c;
            dsu[c].adj.push_back(i);
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(dsu[i].adj.empty())cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3664
///created: 11/Jul/2019 16:16:30

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
const int modulo = 1e9 + 7;

#ifdef LOCAL_DEBUG_NTV1612
template<class __Ty>
string to_string(__Ty a) {
	string res = "[ ";
	bool f = true;
	for (auto &p : a) { res += (f ? string("") : string(", ")) + to_string(p); f = false;	}
	return res + " ]";
}
void _debug() { fprintf(stderr, "\n"); }
template<typename __Ty_head, typename... __Ty_tail>
void _debug(__Ty_head head, __Ty_tail... tail) { fprintf(stderr, "%s ", to_string(head).c_str()); _debug(tail...); }
#define debug(...) fprintf(stderr, "DEBUG [%s]: ", #__VA_ARGS__), _debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

template<class __Ty> bool mini(__Ty& a, __Ty b) { return a > b ? ((a = b) | 1) : (0); }
template<class __Ty> bool maxi(__Ty& a, __Ty b) { return a < b ? ((a = b) | 1) : (0); }
template<class __Ty> __Ty add(__Ty a, __Ty b) { return (a + b) % (__Ty(modulo)); }
template<class __Ty> __Ty sub(__Ty a, __Ty b) { __Ty m(modulo); return ((a - b) % m + m) % m; }

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int L;
	cin >> L;
	vector<int> f;
	while (L) {
		f.push_back(L & 1);
		L >>= 1;
	}
	f.pop_back();
	reverse(f.begin(), f.end());
	typedef tuple<int, int, int> tyans;
	vector<tyans> ans;
	for (int i = 1; i < 20; ++i)
		ans.push_back(make_tuple(i, i + 1, 0));
	for (int i = 0, sum = 0; i < int(f.size()); ++i) {
		if (f[i] == 1) {
			ans.push_back(make_tuple(i + 1, i + 2, sum + 1));
			ans.push_back(make_tuple(1, i + 2, (sum + 1) * 2));
			sum = (sum + 1) * 2;
		}
		else {
			ans.push_back(make_tuple(i + 1, i + 2, sum + 1));
			sum = 2 * sum + 1;
		}
	}
	printf("%d %d\n", 20, int(ans.size()));
	for (tyans &t : ans) {
		int u, v, w;
		tie(u, v, w) = t;
		printf("%d %d %d\n", u, v, w);
	}
	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 a[] = new int[N];
		int max1 = a[0];
		int max2 = a[0];
		int idx = 0;
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			if (max1 < a[i]) {
				idx = i;
				max1 = a[i];
			} else if(max2 <= a[i]) {
				max2 = a[i];
			}
		}
		for (int i = 0; i < a.length; i++) {
			if (i != idx) {
				System.out.println(max1);
			} else {
				System.out.println(max2);
			}
		}
	}
}


Measured memory_bytes: 85256
import sys
sys.setrecursionlimit(200001)
mod = 10**9 + 7
def go(v):
    global tmp
    tmp += 1
    used[v] = True
    for i in range(len(g[v])):
        if not used[g[v][i]]:
            go(g[v][i])
def solve():
    n, m = map(int, input().split())
    global g, used, tmp
    tmp = 0
    g = [[] for i in range(n + 1)]
    ans = 0
    d = {}
    used = [False for i in range(n + 1)]
    for i in range(m):
        x, y = map(int, input().split())
        if (x, y) not in d:
            g[x].append(y)
            g[y].append(x)
            d[(x, y)] = 1
    for i in range(1, n + 1):
        if not used[i]:
            tmp = 0
            go(i)
            ans = max(ans, tmp)
    print(ans)
t = 1
while t > 0:
    solve()
    t -= 1

Measured memory_bytes: 707164