akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
input = sys.stdin.readline

N,M,K = map(int,input().split())
friend = [list(map(int,input().split())) for _ in range(M)]
blocked = [list(map(int,input().split())) for _ in range(K)]

friendgraph = [[] for _ in range(N)]
blockgraph = [[] for _ in range(N)]

uf = UnionFind(N)

for i in range(M):
    a = friend[i][0]-1
    b = friend[i][1]-1
    uf.union(a,b)
    friendgraph[a].append(b)
    friendgraph[b].append(a)

for i in range(K):
    a = blocked[i][0]-1
    b = blocked[i][1]-1
    blockgraph[a].append(b)
    blockgraph[b].append(a)

ans = []

for i in range(N):
    res = uf.size(i)-1
    res -= len(friendgraph[i])
    for b in blockgraph[i]:
        if uf.same(i,b):
            res -= 1

    ans.append(res)

print(*ans)

Measured memory_bytes: 124636
//#pragma Gbb optimize("Ofast") 
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<time.h>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

string s;

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	if ((s[2] == s[3]) && (s[4] == s[5])) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5, M = 1e5;
const ll LINF = 1e18 + 5;
int v[10];
bool dp[N];
void init()
{
	for(int i=1;i<=6;i++) v[i] = 99 + i;
	dp[0] = 1;
	for(int i=1;i<=6;i++)
	{
		for(int j=v[i];j<=M;j++)
		{
			dp[j] |= dp[j-v[i]];
		}
	}
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	init();
 	int x;
 	cin >> x;
 	cout << dp[x];
	return 0;
}


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

Measured memory_bytes: 17300
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> w(n);
    forn(i, n) cin >> w[i];
    int l = accumulate(allele(w), 0);
    int f = 0;
    int ans = INT_MAX;
    forn(i, n)
        f += w[i],
        l -= w[i], ans = min(ans, abs(f - l));
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
/*
        ####   ####
     ###    ###    ###
   ###    Bravery    ###
  ###  Determination  ###
   ##  Perseverance   ##
    ##   Integrity   ##
     ##  Patience   ##
      ## Kindness  ##
        ##Justice##
         ##     ##
           ## ##
             #
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int n;
int main(){
	cin>>n;
	cout<<n*n*n;
	return 0;
}

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

using namespace std;

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

int main()
{
	int N;
	cin >> N;
	int res = -N;
	while (N--) {
		int a;
		cin >> a;
		res += a;
	}
	cout << res << endl;
	return 0;
}


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

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        if(a * 4ll < c)   cout << "Yes\n";
        else    cout << "No\n";
        return 0;
    }
    ll foo = c - a - b;
    if(foo <= 0){
        cout << "No\n";
        return 0;
    }
    foo = foo * foo;
    ll bar = a * b * 4;
    if(foo > bar)   cout << "Yes\n";
    else    cout << "No\n";
}

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

int N, M, Q;
vector<int> L, R, p, q;

void abc106d() {
  vector<vector<ll>> A(N + 1, vector<ll>(N + 1, 0)),
      S(N + 1, vector<ll>(N + 1, 0));
  for (int i = 0; i < M; i++) {
    A[L[i]][R[i]]++;
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      S[i][j] = A[i][j] + S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
    }
  }

  for (int i = 0; i < Q; i++) {
    int l = p[i], r = q[i];
    cout << S[r][r] - S[l - 1][r] - S[r][l - 1] + S[l - 1][l - 1] << '\n';
  }
}

int main() {
  cin >> N >> M >> Q;
  L.resize(M);
  R.resize(M);
  p.resize(Q);
  q.resize(Q);
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
  }
  for (int i = 0; i < Q; i++) {
    cin >> p[i] >> q[i];
  }
  abc106d();
  return 0;
}

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

int main(){
    //input
    long long N;
    cin >> N;
    long long A[N+1];
    long long i;
    bool zeroexist=0;
    for(i=1; i<=N; i++){
        cin >> A[i];
        if(A[i]==0){
            zeroexist=1;
        }
    }

    //calc
    long long seki=1;
    double test;
    for(i=1; i<=N; i++){
        if(zeroexist==1){
            break;
        }
        test = seki;
        if(test*A[i]>1000000000000000000){
            seki=-1;
            break;
        }
        seki = seki*A[i];
    }

    //answer
    if(seki>=0 && seki<=1000000000000000000 && zeroexist==0){
        cout << seki << endl;
    }else if(zeroexist==1){
        cout << 0 << endl;
    }else{
        cout << -1 << endl;
    }

    system("pause");
    return 0;
}

Measured memory_bytes: 4460
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin>>s;
    for(int i=0;i<(s.length()-1)/2;i++){
        if(s[i]!=s[s.length()-i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    string t;
    for(int i=0;i<(s.length()-1)/2;i++){
        t[i]=s[i];
    }
    if(t.length()%2==0){
        for(int i=0;i<(s.length()-1)/2/2;i++){
            if(t[i]!=t[(s.length()-1)/2-1-i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    else {
        for(int i=0;i<((s.length()-1)/2-1)/2;i++){
            if(t[i]!=t[(s.length()-1)/2-1-i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    string p;
    for(int i=0;i<(s.length()-1)/2;i++){
        p[i]=s[(s.length()+1)/2+i];
    }
    if(p.length()%2==0){
        for(int i=0;i<(s.length()-1)/2/2;i++){
            if(p[i]!=p[(s.length()-1)/2-1-i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    else {
        for(int i=0;i<((s.length()-1)/2-1)/2;i++){
            if(p[i]!=p[(s.length()-1)/2-1-i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}


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

char map[30][30];
int x, y;
int num;

int dfs(int sy, int sx)
{
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    int i;
    num++;
    map[sy][sx] = 'x';
    
    for (i = 0; i < 4; i++){
        if (0 <= sx + dx[i] && sx + dx[i] < x && 0 <= sy + dy[i] && sy + dy[i] < y && map[sy + dy[i]][sx + dx[i]] == '.'){
            dfs(sy + dy[i], sx + dx[i]);
        }
    }
    
    return (num);
}

int main(void)
{
    int i, j;
    int sy, sx;
    
    while (1){
        scanf("%d%d", &x, &y);
        
        if (!(x + y)){
            break;
        }
        getchar();
        for (i = 0; i < y; i++){
            for (j = 0; j < x; j++){
                scanf("%c", &map[i][j]);
                if (map[i][j] == '@'){
                    sy = i;
                    sx = j;
                }
            }
            getchar();
        }
        
        num = 0;
        printf("%d\n", dfs(sy, sx));
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <set>
#include <map>
#include <string>

using namespace std;

long mod = 1000000007;
bool isValid(int i)
{
    int before = 0;
    for(int j=0; j<7; j++)
    {
        if(before == 1 && (i & (1 << j)))
        {
            return false;
        }
        before = (i & (1 << j)) > 0;
    }

    return true;
}

int main() {
    int h, w, k;
    cin >> h; cin >> w; cin >> k;

    long dp[101][9] = {};
    dp[0][1] = 1;

    for(int i=0; i<h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            if(dp[i][j] > 0)
            {
                for(int l=0; l<1<<(w-1); l++)
                {
                    if(isValid(l))
                    {
                        //cout << l << endl;

                        if(j-2 >=0 && (l & (1 << (j-2))))
                        {
                            dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % mod;
                            //cout << "No.1" << endl;
                        }
                        else if(j-1 >= 0 && (l & (1 << (j-1))))
                        {
                            dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
                            //cout << "No.2" << endl;
                        }
                        else
                        {
                            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
                            //cout << "No.3" << endl;
                        }
                    }
                }
            }
        }
    }

    cout << dp[h][k] << endl;

    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n=0;
  cin >> n;
  vector<double> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  double d=0;
  for(int i=0;i<n;i++){
    d=d+1.0/v[i];
  }
  d=1.0/d;
  cout << d;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[100001];
int main()
{
	string s;
	int i,len,a=-1,z=-1;
	cin>>s;
	len=s.size();
	for(i=0;i<len;i++) 
	{
		if(s[i]=='A'&&a==-1) a=i;
		if(s[i]=='Z') z=i;
	}
	cout<<(z-a)+1;
}


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

int main()
{
    long long int a,b,c,x,y,m;
    cin>>a>>b>>c;
    m=(c-(a+b));
    x=m*m;
    y=4*a*b;
    if(m>0 && x>y)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

template <ll mod>
class Fp {
public:
    ll val;

private:
    inline void calc_mod(ll &v) {
        if (v >= mod)
            v -= mod;
    }

public:
    Fp() {}
    Fp(ll v) : val(v % mod) {
        if (val < 0)
            val += mod;
    }
    Fp operator+=(const Fp &in) {
        val += in.val;
        calc_mod(val);
        return *this;
    }
    Fp operator+(const Fp &in) const {
        return Fp(*this) += in;
    }
    Fp &operator-=(const Fp &in) {
        val -= in.val;
        calc_mod(val);
        if (val < 0)
            val += mod;
        return *this;
    }
    Fp operator-(const Fp &in) const {
        return Fp(*this) -= in;
    }
    Fp &operator*=(const Fp &in) {
        val = val * in.val % mod;
        return *this;
    }
    Fp operator*(const Fp &in) const {
        return Fp(*this) *= in;
    }
    Fp &operator/=(const Fp &in) {
        *this *= modpow(in, mod - 2);
        return *this;
    }
    Fp operator/(const Fp &in) const {
        return Fp(*this) /= in;
    }
    bool operator==(const Fp &in) const {
        return val == in.val;
    }
    bool operator!=(const Fp &in) const {
        return val != in.val;
    }
    friend Fp modpow(const Fp &in, ll n) {
        if (n == 0)
            return 1;
        if (n & 1) {
            return in * modpow(in * in, n / 2);
        } else {
            return modpow(in * in, n / 2);
        }
    }
};
using modll = Fp<mod>;
class Factorial {
public:
    vector<modll> fact, finv;
    Factorial(ll n) : fact(n + 1, modll(1)), finv(n + 1, modll(1)) {
        for (int i = 2; i <= n; i++) {
            modll tmp(i);
            fact[i] = fact[i - 1] * tmp;
            finv[i] = finv[i - 1] / tmp;
        }
    }
    modll com(const ll &n, const ll &k) {
        if (n < k || n < 0 || k < 0)
            return modll(0);
        return fact[n] * finv[k] * finv[n - k];
    }
};

int main() {
    cin >> N >> K;
    vector<vector<int>> tree(N);
    vector<bool> flag(N, 0);
    for (int i = 0; i < N - 1; i++) {
        cin >> A >> B;
        A--, B--;
        tree[A].push_back(B);
        tree[B].push_back(A);
    }
    modll ans = K;
    ll tmp = K;
    queue<int> q;
    for (int i = 0; i < tree[0].size(); i++) {
        ans *= (--tmp);
        q.push(tree[0][i]);
        flag[tree[0][i]] = true;
    }
    flag[0] = true;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        tmp = K - 2;
        for (int i = 0; i < tree[now].size(); i++) {
            int adj = tree[now][i];
            if (flag[adj] == true)
                continue;
            ans *= (tmp--);
            q.push(adj);
            flag[adj] = true;
        }
    }
    cout << ans.val << endl;
}

Measured memory_bytes: 6520
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] d = new int[n][2];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 2; j++) {
				d[i][j] = sc.nextInt();
			}
		}
		int num = 0;
		boolean cont = false;
		for(int i = 0; i < n; i++) {
			if(d[i][0]==d[i][1]) {
				cont = true;
				num++;
			}
			else{
				cont = false;
				num=0;
			}
			if(num>=3) break;
		}
		if(num<3)cont=false;
		System.out.println(cont? "Yes":"No");
	}
}

Measured memory_bytes: 36072
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

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

    if(S == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int X;
    cin >> X;
    for(int i = X;i < pow(10,6);i++) {
        bool ret = true;
        int C = 2;
        while(C * C <= i) {
            if(i % C == 0) {
                ret = false;
            }
            C++;
        }
        if(ret == true) {
            cout << i << endl;
            break;
        }
    }
}

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

enum {
  MAXN = 100000 + 5
};

const int MOD = 1e9 + 7;

int n;
int sum[MAXN];

void exec() {
  int i, x, ans;
  scanf("%d", &n);
  for (i=0; i<n; ++i)
    ++ sum[std::abs(i-(n-i-1))];
  ans = 1;
  for (i=0; i<n; ++i) {
    scanf("%d", &x);
    if (sum[x] == 0)
      return (void) puts("0");
    --sum[x];
  }
  for (i=0; i<n/2; ++i)
    ans = ans*2%MOD;
  printf("%d\n", ans);
}

int main() {
  if (fopen("C.in", "r") != NULL) {
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
  }
  exec();
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  //vector<int> P(M);
  //vector<int> Y(M);
  vector<pair<pair<int,int>,int>> py(M);
  for(int i=0; i<M; i++){
    cin >> py.at(i).first.first >> py.at(i).first.second;
    py.at(i).second = i;
  }
  sort(py.begin(),py.end());
  vector<string> num(M);
  int juni = 1;
  int ken = py.at(0).first.first;
  string numue;
  string numst;
  for(int i=0; i<M; i++){
    if(py.at(i).first.first != ken){
      ken = py.at(i).first.first;
      juni = 1;
    }
    numue = to_string(py.at(i).first.first);
    numst = to_string(juni);
    while(numue.size() != 6){
      numue = "0" + numue;
    }
    while(numst.size() != 6){
      numst = "0" + numst;
    }
    juni++;
    num.at(py.at(i).second) = numue+numst;
  }
 // for(int i=0; i<M; i++){
 //   cout << py.at(i).first.first << " " << py.at(i).first.second <<" "<< py.at(i).second << endl;
  //}
  for(int i=0; i<M; i++){
    cout << num.at(i) << endl;
  }
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
#define inf 1e18
#define N 1e5+5
#define ll long long int
using namespace std;
int main(void){
	//en("output.txt","w",stdout);
	//#endif
  int n,W,i,j,s=0;
  cin>>n>>W;
  int w[n],v[n];
  for(i=0;i<n;i++){
	cin>>w[i]>>v[i];
	s+=v[i];
	}	
  ll dp[s+1];
  for(i=0;i<=s;i++)
  dp[i]=inf;
  dp[0]=0;
  for(i=0;i<n;i++){
	  for(j=s-v[i];j>=0;j--)
	  dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
	}
	ll ans=0;
	for(i=0;i<=s;i++){
		if(dp[i]<=W)
		ans=i;
}
	cout<<ans;
  
}


Measured memory_bytes: 1024
import fractions
a,b,p,q=map(int,input().split())

pd=(b//p-(a-1)//p)
qd=(b//q-(a-1)//q)

c = p*q//fractions.gcd(p,q)
cd=(b//c-(a-1)//c)

ans= (b-a+1)-(pd+qd-cd)

print(ans)

Measured memory_bytes: 5048
s = input()
K = int(input())
sorted_s = sorted(list(set(s)))
l = len(s)

for c in sorted_s:
    str_list = set()

    for i, cc in enumerate(s):
        if cc == c:
            str_list |= set([s[i: i + j] for j in range(1, 6)])
            str_list = set(str_list)

    if K <= len(str_list):
        break
    K -= len(str_list)

print(sorted(list(str_list))[K-1])

Measured memory_bytes: 3064
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int n,m;
vector<int>adj[M];
int vis[M];
int flag=0;
int b=0,w=0;
void dfs(int u,int par)
{
    if(flag)return ;
    if(!par)
    {
        vis[u]=1;
        w++;
    }
    else
    {
        if(vis[par]==1)vis[u]=2,b++;
        else vis[u]=1,w++;
    }
    for(auto v:adj[u])
    {
        if(v==par)continue;
        if(vis[v]==0)
        {
            dfs(v,u);
        }
        else if(vis[v]==vis[u])
        {
            flag=1;
        }
    }
}
 main()

{
    fast
    cin>>n>>m;
    f(i,1,m)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0);
    if(flag)
    {
        int x=n*(n-1);
        x=x/2;
        x-=m;
        cout<<x<<endl;
        return 0;
    }
   cout<<(b*w)-m<<endl;
    return 0;

}



































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

int main()
{
	long long n;
	scanf("%lld",&n);
	long long x=sqrt(n);
	if(x*x==n)
	{
		string str;
		stringstream st;
		st<<x;
		st>>str;
		printf("%d\n",str.size()); 
	}
	else
	{
		for(long long i=x;i>=1;i--)
		{
			if(n%i==0)
			{
				long long nn=n/i;
				string str1;
				stringstream st;
				st<<nn;
				st>>str1;
				printf("%d\n",str1.size()); 
				break;
			}
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,h1,h2,k1,k2,H,K;
	scanf("%d%d%d%d%d%d%d%d",&h1,&h2,&k1,&k2,&a,&b,&c,&d);
	H=a*h1+h1/10*c+b*h2+h2/20*d;
	K=a*k1+k1/10*c+b*k2+k2/20*d;
	if(H>K)
	{
		printf("hiroshi\n");
	}
	else if(H<K)
	{
	printf("kenjiro\n");
	}
	else 
	{
		printf("even\n");
	}
	return 0;
}

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

namespace ABC_Training
{

    public class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            Console.WriteLine(ooo(n));
        }
        static double ooo(int x)
        {
            return (x+1)/2/(double)x;
        }
    }
}


Measured memory_bytes: 13140
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>


using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;



int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll x;
    cin >> x;

    ll ans = x / 11 * 2;
    int r = x % 11;
    if (r > 6) ans += 2;
    else if(r > 0) ans += 1;

    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a>b) System.out.println("a > b");
      else if(a==b)  System.out.println("a == b");
      else if(a<b) System.out.println("a < b");
    }
}



Measured memory_bytes: 26252
Scanf.scanf "%d %d %d %d" (fun a b c x ->
    let rec loop aa acc =
        let rec loop2 bb acc =
            let rec loop3 cc acc =
                if cc > c || aa * 500 + bb * 100 + cc * 50 > x then acc else
                    if aa * 500 + bb * 100 + cc * 50 = x then acc + 1 else
                        loop3 (cc + 1) acc
            in
            if bb > b || aa * 500 + bb * 100 > x then acc else loop2 (bb + 1) (loop3 0 acc)
        in
        if aa > a || aa * 500 > x then acc else loop (aa + 1) (loop2 0 acc)
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 21000000145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
struct edge { int to, cost; };
set<int>S;
signed main() {
	int n; cin >> n;
	if (n >= 1000)cout << "ABD"<<endl;
	else cout << "ABC" <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <iostream>
#include <cmath>
using namespace std;

int main(){
    long int A,B,C;
    cin>>A>>B>>C;
    if(C-A-B>0){
        if((C-A-B)*(C-A-B)-4*A*B>0){
            cout<<"Yes";
        }else{
            cout<<"No";
        }
    }else{
        cout<<"No";
    }



}

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

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll A,B; cin>>A>>B;
    ll num=B-A+1;
    ll ans=0;
    vll take;
    if(A==B){
        cout<<A<<endl;
        return 0;
    }
    if(A+1==B){
        ans=(A^B);
        cout<<ans<<endl;
        return 0;
    }
    else if(num>=3){
    if(A%2==1){
        take.push_back(A);
        A++;
        num--;
    }
    if(B%2==0){
        take.push_back(B);
        B--;
        num--;
    };
    if(num/2%2==1){
        ans=1;
    }
    else {
        ans=0;
    }
    for(ll v:take){
        ans^=v;
    }
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<map>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>

using namespace std;

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

const int MX = 100005;

int N;
int D[MX];

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		int a;
		scanf("%d", &a);
		D[a] ++;
	}
	int ans = 0;
	for(int i = 1; i+1 < MX; i++){
		ans = max(ans, D[i-1] + D[i] + D[i+1]);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 512
#include<iostream>
#include<utility>
#include<string>
#include<complex>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define rea(a) (a).real()
#define img(a) (a).imag()
#define both(a) (a).real(),(a).imag()
using namespace std;
typedef complex<int> pii;
typedef pair<string,string> pss;

int n,m;

void f(pii point,string s){
	if(point.real()>n || point.imag()>m)return;
	if(point.real()==n && point.imag()==m)cout<<s<<endl;
	else if(max(both(point))>=5 && min(both(point))<=3)return;
	else{
		f(point+pii(1,0),s+'A');
		f(point+pii(0,1),s+'B');
	}
}

int main(){
	cin>>n>>m;
	f(pii(0,0),"");
	return 0;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;


int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
  int K;

  while(cin >> K){
    puts_all(a[K-1]);
  }


  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=1e5+7;
int a[N],tmp[N];
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n=ri(),i,st,ed,nn,ans=0;
	for(i=1;i<=n;i++)	a[i]=tmp[i]=ri();
	sort(a+1,a+1+n);sort(tmp+1,tmp+1+n);
	nn=unique(tmp+1,tmp+1+n)-tmp-1;
	for(i=1;i<=nn;i++)
	{
		st=lower_bound(a+1,a+1+n,tmp[i])-a;
		ed=upper_bound(a+1,a+1+n,tmp[i])-a-1;
		if(ed-st+1>=tmp[i])	ans+=ed-st+1-tmp[i];
		else	ans+=ed-st+1;
	}
	wi(ans);putchar('\n');
	return 0;
}
/*
8
2 7 1 8 2 8 1 8



*/

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	int ans=0;
	for(long long i=2;i*i<=n;i++)
	{
		int cnt=0;
		if(n%i)
		{
			continue;
		}
		while(n%i==0)
		{
			n/=i;
			cnt++;
		}
		for(int j=1;j<=cnt;j++)
		{
			cnt-=j;
			ans++;
		}		
	
	}
	if(n>1)ans++;
	cout<<ans<<endl;
	
}

Measured memory_bytes: 3644
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
    	Scanner stdin = new Scanner(System.in);
        while (true) {
            int x = Integer.parseInt(stdin.next());
            int y = Integer.parseInt(stdin.next());
            if(x==0&&y==0) break;
            if(x<=y) System.out.println(x+" "+y);
            else System.out.println(y+" "+x);
        }
        stdin.close();
    }
}

Measured memory_bytes: 35328
#include<stdio.h>

int main()
{
  int a,b,c=100;
  scanf("%d%d",&a,&b);
  if(a<b)
    {
      c = a;
      a = b;
      b = c;
    }
  while(c != 0)
    {
      c = a%b;
      a = b;
      b = c;
    }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)

int main(){
  int n;
  cin>>n;
  lp(z,n){
    int a[5][5];
    lp(i,5){
      lp(j,5){
	cin>>a[j][i];
      }
    }
    int check,ans=0;
    lp(i,5){
      lp(j,5){
	lp(k,5-i){
	  lp(l,5-j){
	    check=0;
	    for(int m=k;m<=i+k;m++){
	      for(int n=l;n<=j+l;n++){
		if(a[n][m]==0){
		  check=1;
		  break;
		}
	      }
	      if(check==1) break;
	    }
	    if(check==0){
	      ans=max(ans,(i+1)*(1+j));
	    }
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        System.out.println(b + Math.min(a+b+1,c));
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 21076
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
L = 0
for i in range(N):
    ans += min(B[i] + L, A[i])
    L = max(B[i] - max(A[i] - L, 0), 0)
if L > 0:
    ans += min(L, A[N])
print(ans)

Measured memory_bytes: 18624
/*
  Contest 092
  A - Traveling Budget
  Rakesh Kumar --> 21/09/2020
 */

#include <bits/stdc++.h>

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

    int a = 0, b = 0, c = 0, d = 0;
    std::cin >> a >> b >> c >> d;
    std::cout << std::min(a, b) + std::min(c, d) << std::endl;

    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N=1000;
int lcs(string X,string Y){
 int c[N+1][N+1];
 int m=X.size();
 int n=Y.size();
 int maxl=0;
 X=' '+X;
 Y=' '+Y;
 for(int i=0;i<=m;i++)c[i][0]=0;
 for(int j=1;j<=n;j++)c[0][j]=0;
 for(int i=1;i<=m;i++){
  for(int j=1;j<=n;j++){
   if(X[i]==Y[j])c[i][j]=c[i-1][j-1]+1;
   else c[i][j]=max(c[i-1][j],c[i][j-1]);
   maxl=max(maxl,c[i][j]);
  }
 }
 return maxl;
}
int main(){
 string s1,s2;
 int n;cin>>n;
 for(int i=0;i<n;i++){
  cin>>s1>>s2;
  cout<<lcs(s1,s2)<<endl;
 }
 return 0;
}


Measured memory_bytes: 7008
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

void solve(ll n) {
  ll r = sqrt(n);
  ll ans = 0;
  for (ll i = 2; i <= r; i++) {
    ll num = n;
    while (num % i == 0) {
      num /= i;
    }
    if (num % i == 1) {
      ans++;
    }
    if ((i * i != n - 1) && (n - 1) % i == 0) {
      ans++;
    }
  }
  printf("%d\n", ans + 2);
}

int main() {
  ll n;
  int ans = 0;
  scanf("%lld", &n);
  if (n == 2) {
    printf("1\n");
  } else {
    solve(n);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    int64 ans = 1;
    vector a(n,0LL);
    for (int i=0; i<n; i++) cin >> a[i];

    if (any_of(a.begin(), a.end(), [](const int64& x){return x == 0LL;})) {
        cout << 0 << endl;
        return 0;
    }

    for (int i=0; i<n; i++) {
        if (__builtin_mul_overflow(ans, a[i], &ans) || ans > 1000000000000000000LL) {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;
}

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

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

  int p[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  int count = 0;
  for (int i = 1; i < n - 1; i++) {
    if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
        (p[i + 1] < p[i] && p[i] < p[i - 1])) {
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    l = len(s)
    ans = l
    for i in range(1, l):
        if s[i] != s[i - 1]:
            ans = min(ans, max(l - i, i))

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 70008
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int N;
	cin >> N;
	int A[200000];
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i] = A[i] - i - 1;
	}

	sort(A, A + N);

	long b; // median

	if (N % 2) {
		b = A[N / 2];
	}
	else {
		b = (A[N / 2 - 1] + A[N / 2]) / 2;
	}

	long ans = 0;

	for (int i = 0; i < N; ++i)
		ans += abs(A[i] - b);

	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
package main

import (
  "fmt"
)

func main() {
  var A, B int
  fmt.Scan(&A, &B)
  
  var ans int
  for i := 0; i < 2; i++ {
    if A > B {
      ans += A
      A -= 1
    } else {
      ans += B
      B -= 1
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void) {

	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x - r < 0 || x + r > W) {
		printf("No\n");
	}

	else if (y - r < 0 || y + r > H) {
		printf("No\n");
	}

	else if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
		printf("Yes\n");
	}

	


	return(0);

}


Measured memory_bytes: 2048
N, A, B, C = map(int, input().split())
l = [int(input())for _ in range(N)]


def f(a, b, c, n):
    if n == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else 10 ** 9
    ans = f(a, b, c, n + 1)
    ans = min(ans, f(a + l[n], b, c, n + 1) + 10)
    ans = min(ans, f(a, b + l[n], c, n + 1) + 10)
    ans = min(ans, f(a, b, c + l[n], n + 1) + 10)
    return ans


print(f(0, 0, 0, 0))


Measured memory_bytes: 44380
// C - Special Trains
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vector<int> C(N),S(N),F(N);
	rpz(i, N-1) cin>>C[i]>>S[i]>>F[i];

	rpz(i, N){
		int t = 0;
		rp(j, i, N-1){
			if(t < S[j]) t = S[j];
			else t += t%F[j]? F[j] - t%F[j]: 0;
			t += C[j];
		}
		cout<< t <<endl;
	}
}

Measured memory_bytes: 256
N = int(input())
In = [map(int, input().split()) for _ in range(N)]

s = (0, 0)
t = 0
success = True

for move in In:
    before_x, before_y = s
    tn, after_x, after_y = move

    dist_xy = abs(after_x - before_x) + abs(after_y - before_y)
    walk = tn - t

    if walk < dist_xy:
        success *= False

    if walk % 2 == 0 and dist_xy % 2 != 0:
        success *= False
    elif walk % 2 != 0 and dist_xy % 2 == 0:
        success *= False

    s = (after_x, after_y)
    t = tn

print("Yes" if success else "No")

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

int main(){
	int inning;
	int i, out = 0, hit = 0;
	int score = 0;
	char event[8];
	
	scanf("%d", &inning);
	
	while(inning != 0){
		scanf("%s", event);
		if(!strcmp(event, "HOMERUN")){
			score += hit + 1;
			hit = 0;
		}else if(!strcmp(event, "HIT")){
			hit++;
			if(hit == 4){
				score++;
				hit--;
			}
		}else if(!strcmp(event, "OUT")){
			out++;
		}
 		if(out == 3){
			inning--;
			out = 0;
			hit = 0;
			cout << score << endl;
			score = 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1208
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
values, counts = zip(*c.most_common())
values, counts = list(values), list(counts)
k = 0
for i in range(len(counts)):
  k += counts[i]*(counts[i]-1)//2
output = [0]*len(a)
for i in range(len(a)):
  temp = c[a[i]]
  if temp == 1:
    output[i] = k
  else:
    output[i] = k-temp*(temp-1)//2+(temp-1)*(temp-2)//2
  print(output[i])

Measured memory_bytes: 37024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
	ll n,x;
	cin>>n>>x;
	ll a[n];
	ll ans=0,sum=0;
	for(ll i=0;i<n;i++)
		cin>>a[i];
	for(ll i=0;i<n;i++)
	{
		sum+=a[i];
		if(sum<=x)
			ans++;
	}
	cout<<ans+1;
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


Measured memory_bytes: 3628
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def BellmanFord(E, N, source):
    #E:E[a]は頂点aを始点とする辺のリストであり、辺の終点bと辺の重みwが(b, w)の形で格納されている
    #N:頂点の数
    #source:始点
    #グラフの初期化
    d = [INF for _ in range(N)]
    d[source] = 0
    
    #辺の緩和
    for i in range(N):
        for j in range(N):
            e = E[j]
            if len(e) == 0:
                continue
            for edge in e:
                if d[edge[0]] > d[j] + edge[1]:
                    d[edge[0]] = d[j] + edge[1]
                    if i == N-1 and edge[0] == N-1:
                        return -1
    
    return d

N, M = MAP()
abc = [LIST() for _ in range(M)]
G = [[] for _ in range(N)]

for a, b, c in abc:
	G[a-1].append((b-1, -c))

dist = BellmanFord(G, N, 0)
if dist == -1:
	print("inf")
else:
	print(-dist[N-1])


Measured memory_bytes: 5960
#include <iostream>

using namespace std;

int n;
int a[100005];
int dp[100005];

int main(void)
{
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> a[i];

  for(int i = 2; i <= n; i++){
    dp[i] = dp[i-1] + abs(a[i-1] - a[i]);
    if(i-2 >= 1) dp[i] = min(dp[i], dp[i-2] + abs(a[i-2] - a[i]));
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		var a=sc.Ia2;
		var dl=new Dl(a,s[1]);
		Console.WriteLine(dl.Get(1,s[1]));
	}
}
public class Dl{
	private readonly int[][] d;
	public Dl(int[] a,long z){
		int n=a.Length,m=(int)Log(z,2)+1;
		d=new int[m][];
		d[0]=new int[n];
		for(int j=0;j<n;j++){d[0][j]=a[j];}
		for(int i=1;i<m;i++){
			d[i]=new int[n];
			for(int j=0;j<n;j++){d[i][j]=d[i-1][d[i-1][j]];}
		}
	}
	public int Get(int a,long b){
		for(int i = 0;1L<<i<=b;i++) {
			if(((1L<<i)&b)!=0){a=d[i][a];}
		}
		return a;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 85404