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

int f( long long a, long long b ) {
    int l1(1), l2(1);
    
    while( a /= 10 )
        l1 ++;
    while( b /= 10 )
        l2 ++;
    
    return max( l1, l2 );
}

int main( void ) {
    
    long long n;
    cin >> n;
    
    int ans = numeric_limits<int> :: max();
    for( int i = 1; 1LL * i * i <= n; i ++ )
        if( n % i == 0 ) ans = min( ans, f( i, n / i ) );
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    long a = sc.nextLong();
    long b = sc.nextLong();
    long k = sc.nextLong();
    long p = k - a;

    if(a>k){
      a = a-k;
    }else if(a<=k){
      a =0;
      b = b -p;
      if(b<0){
        b=0;
      }
    }

    System.out.println(a+" "+b);



  }

}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll k,sum=0;
int main(){
	ll i,j,l,t;
	cin>>k;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			t=__gcd(i,j); 
			for(l=1;l<=k;l++)
			{
				sum+=__gcd(t,l);
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

class Main{
 public static void main (String[] args) throws java.lang.Exception
 {
 InputStreamReader is = new InputStreamReader(System.in);
 BufferedReader br = new BufferedReader(is);
 Scanner scan = new Scanner(System.in);
 int su = scan.nextInt();
 int su2 = scan.nextInt();
 int menseki = su * su2;
 int nagasa = 2*(su +su2);
 System.out.println(menseki+" "+ nagasa);
 }
}


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

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

  std::string S;
  std::cin >> S;

  uint32_t c = 0;
  uint32_t l = 0;
  std::vector<uint32_t> v;
  for (uint32_t i = 0; i < S.size(); i++) {
    if ((S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')) {
      if (l == (i - 1)) {
        c++;
      } else {
        v.push_back(c);
        c = 1;
      }
      l = i;
    }
  }
  if (v.size() == 0 || v.back() != c) {
    v.push_back(c);
  }

  uint32_t m = 0;
  for (const auto& i: v) {
    m = std::max(i, m);
  }
  std::cout <<  m << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n; i++)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define int long long
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
int s[440][440];
bool used[440][440];
int tmp[2];
int w, h;
void dfs(int y, int x, int cl){
    tmp[cl]++;
    used[y][x] = 1;
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, -1, 0, 1};
    rep(i, 4){
        int X = x+dx[i];
        int Y = y+dy[i];
        if(X < 0 || Y < 0 || X >= w || Y >= h) continue;
        if(!used[Y][X] && s[Y][X] != cl){
            dfs(Y, X, s[Y][X]);
        }
    }
}

signed main(){
    cin >> h >> w;
    rep(i, h)rep(j, w){
        char x;
        cin >> x;
        s[i][j] = (x == '#' ? 0 : 1);
    }
    LL ans = 0;
    rep(i, h)rep(j, w){
        if(!used[i][j]){
            dfs(i, j, s[i][j]);
            ans += tmp[0]*tmp[1];
            memset(tmp, 0, sizeof(tmp));
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 21760
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	static boolean isPrime[] = new boolean[1000000];
	static int cnt,n;    //计数
	static int ans[] = new int[1000000];
	public static void initPrime() {
		Arrays.fill(isPrime, true);
		isPrime[1] = false;
		ans[1] = 0;
		for(int i=2;i<1000000;i++) {
			if(isPrime[i]) {
				ans[i] = ++cnt;
				for(int j=i*2;j<1000000;j+=i) {
					isPrime[j] = false;
				}
			}
			else
				ans[i] = cnt;
		}
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		initPrime();
		while(in.hasNext()) {
			int n = in.nextInt();
			System.out.println(ans[n]);
		}
		in.close();
	}
}


Measured memory_bytes: 31520
#include<iostream>
#include<math.h>
#define ll long long
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++)
using namespace std;


void Eratosthenes(/**/int X){
  ll N;N=pow(10,6);
  ll arr[N];
  for(int i=0; i<N; i++){
    arr[i]=1;
  }
  for(int i=2; i<sqrt(N); i++){
    if(arr[i]){
      for(int j=2; i*j<N; j++){
	arr[i*j] = 0;
      }
    }
  }

  for(int i=2; i<N; i++){
    if(arr[i]){
      /**/if(X<=i){
	cout << i << endl;
	return;
      }
    }
  }
}
int main(){
  int X;cin>>X;
  Eratosthenes(X);
  
}


Measured memory_bytes: 8064
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
string en="\n";
string t="hello";
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n)
    {
        s=0;
        Rep(i,n)
        {
            if((i%3==0&&i%5==0)||i%3==0||i%5==0) continue;
            else s+=i;
        }
        cout<<s<<en;
    }
}



Measured memory_bytes: 3624
S = input()
f, l = S[:2], S[2:]

if 1 <= int(f) <= 12 and 1 <= int(l) <= 12:
    print('AMBIGUOUS')
elif 1 <= int(f) <= 12:
    print('MMYY')
elif 1 <= int(l) <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 2940
N = int(input())
S = input()

# 0: S, 1: Wとする
X = ['S', 'W']
for P in [[0, 0], [0, 1], [1, 0], [1, 1]]:
    for i, s in enumerate(S[1:], start=1):
        if s == 'o' and P[i] == 0:
            P.append(P[i - 1])

        if s == 'o' and P[i] == 1:
            P.append(P[i - 1] ^ 1)

        if s == 'x' and P[i] == 0:
            P.append(P[i - 1] ^ 1)

        if s == 'x' and P[i] == 1:
            P.append(P[i - 1])

    P = P[:-1]
    # 確認
    for i in range(N):
        if (S[i] == 'o') and (P[i] == 0) and (P[i - 1] != P[(i + 1) % N]):
            break

        if (S[i] == 'o') and (P[i] == 1) and (P[i - 1] == P[(i + 1) % N]):
            break

        if (S[i] == 'x') and (P[i] == 0) and (P[i - 1] == P[(i + 1) % N]):
            break

        if (S[i] == 'x') and (P[i] == 1) and (P[i - 1] != P[(i + 1) % N]):
            break

    else:
        ans = [X[p] for p in P]
        print(''.join(ans))
        exit()

print(-1)


Measured memory_bytes: 8932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b:i--)

int main() {
    // your code goes here
    ll k,q,d[5005];
    cin >> k >> q;
    rep(i,0,k-1) cin >> d[i];
    rep(qs,1,q){
        ll n,x,m,e[5005],s[5005],zs=0,z2=0,a,b,memo,res,r2;
        cin >> n >> x >> m;
        x%=m;
        rep(i,0,k-1){
            e[i]=d[i]%m;
            if(e[i]==0) zs++;
            if(i==0) s[i]=e[0];
            else s[i]=s[i-1]+e[i];
        }
        n--;
        b=n%k; a=(n-b)/k;
        rep(i,0,b-1){
            if(e[i]==0) z2++;
        }
        if(b!=0) memo=(x+a*s[k-1]+s[b-1]);
        else memo=(x+a*s[k-1]);
        res=memo%m;
        res=(memo-res)/m;
        zs=zs*a+z2;
        cout << n-res-zs << endl;
    }
    return 0;
}

Measured memory_bytes: 384
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define dbgi(x) cout << #x << " = " << (x) << "\n";
#define dbgvi(x) cout << #x << " = "; for(int i = 0; i < (x.size()); ++i) cout << x[i] << " ";
#define mrk() cout << "HERE\n"
#define vi vector < int >
#define vs vector < string >
#define int long long
#define vii vector < vi >
#define viii vector < vii >
#define viiii vector < viii >
#define pii pair < int, int >
#define foru(i, a, b) for(int i = a; i < b; ++i)
#define ford(i, b, a) for(int i = b; i > a; --i)
using namespace std;

void no(){
    cout << "No";
    exit(0);
}

signed main(){
    int a, b;
    string s;
    cin >> a >> b >> s;
    foru(i, 0, a){
        int val = s[i] - '0';
        if(!(val >= 0 && val <= 9))no();
    }
    if(s[a] != '-')no();
    foru(i, a + 1, s.size()){
        int val = s[i] - '0';
        if(!(val >= 0 && val <= 9))no();
    }
    cout << "Yes";

}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class CPeaks {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    vector<vector<int>> road(N);
    rep(i, M) {
      int A, B;
      cin >> A >> B;
      road[A - 1].emplace_back(B - 1);
      road[B - 1].emplace_back(A - 1);
    }
    int ans = 0;
    rep(i, N) {
      if (road[i].empty()) {
        ans++;
        continue;
      }
      rep(j, road[i].size()) {
        if (H[i] <= H[road[i][j]]) {
          break;
        } else if (j == road[i].size() - 1) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
};


signed main() {
  CPeaks solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 9948
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <map>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

vi hurui(int Limit)
{
    vi ret;
    vi hh(Limit, -1);
    for (int i = 2; i <= (int)sqrt(Limit); i++)
    {
        if (hh[i] < 0)
        {
            ret.push_back(i);
            for (int j = 2*i; j < Limit; j += i)
                hh[j] = i;
        }
    }
    return ret;
}

int main()
{
    int N;
    map<int, int, less<int>> A;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        ++A[a];
    }

    constexpr int MAX_A = 1000000;
    vi kusi(MAX_A+1, 0);

    for (auto [a, i] : A)
    {
        for (int j = a; j <= MAX_A; j += a)
        {
            kusi[j] += i;
        }
    }
    
    int ans = 0;
    for (auto [a, i] : A)
        if (kusi[a] == 1) ++ans;
    
    cout << ans << endl;
}

Measured memory_bytes: 16548
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>


using namespace std;
#define out(s) cout<<(s)<<endl;
using ll = long long;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	out((a + b)*c / 2);
}

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

int main(){
  int N,K,Q,M;
  cin >> N >> K >> Q;
  vector<int> A(N,0);
  for(int i=0;i<Q;i++){
    cin >> M;
    A[M-1] ++;
  }
  for(int j=0;j<N;j++){
    if(K-Q+A[j]>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){

  int n ; cin>>n;
  int ar[n];
  for(int i=0;i<n;i++)
    cin>>ar[i];

  sort(ar,ar+n,greater<int>());
  int c=1;
  long long sum=ar[0];
  for(int i=1;i<=n-2;i+=2)
    sum+=(2*ar[c++]);
  if(n&1)
    sum-=ar[--c];
  cout<<sum;
}



Measured memory_bytes: 4412
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	int n; cin>>n;
	bool ans=true;
	int h;
	rep(i,n){
		cin>>h;
		if(h%2==0){
			if(h%3!=0 and h%5!=0) ans=false;
		}	
	}
	if(ans) cout<<"APPROVED";
	else cout<<"DENIED";

}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
ll = [list(map(int,input().split())) for j in range(M)]

a = [0]*N
b = [0]*N

for i in range(M):
    if ll[i][0] == 1:
        a[ll[i][1]-1] += 1
    if ll[i][1] == N:
        b[ll[i][0]-1] += 1

for i in range(N):
    if a[i] != 0 and b[i] != 0:
        print("POSSIBLE")
        exit()
    else:
        pass
print("IMPOSSIBLE")


Measured memory_bytes: 48572
#include <stdio.h>
 
int main()
{
    int k,n;
    scanf("%d %d", &k, &n);
 
   int a[n];
  for(int i=0; i<n; i++) {
    scanf("%d", &a[i]);
  }
  int max = 0;
  for(int i=0; i<n-1; i++) {
    if(a[i+1] - a[i] > max)
    max = a[i+1] - a[i];
  }
  
  if(a[0] - a[n-1] + k > max)
    max = a[0] - a[n-1] + k;
  
  printf("%d", k - max);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    for (ll i = 0; i < s.size(); i+=2)
    {
        cout << s[i];
    }
    cout << endl;
}

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    bool b = false;
    if ((r <= x) && (x <= (W - r))) {
        if ((r <= y) && (y <= (H - r))) {
            cout << "Yes" << endl;
            b = true;
        }
    }
    
    if (!(b)) cout << "No" << endl;
}


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

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
	cin.sync_with_stdio(false);
	ll n;
	cin>>n;
    ll lx = 0;
    ll ly = 0;
    ll lt = 0;
    rep(i,0,n){
        ll x,y,t;
        cin>>t>>x>>y;
        if(abs(x-lx)+abs(y-ly)<=(t-lt)&&
        ((abs(x-lx)+abs(y-ly))%2)==((t-lt)%2)){
            ;
        }else {
            cout<<"No"<<endl;
            return 0;
        }
        lx = x;
        ly = y;
        lt = t;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
def Inquiry(team):
	ranking=1
	score=team_score[0][1]
	for i in team_score:
		if score>i[1]:
			ranking+=1
			score=i[1]
		if i[0]==team:
			return ranking

team_score=[]
while True:

	x,y=map(int,input().split(','))
	if x==y==0:
		break
	team_score.append((x,y))

#print(team_score)
team_score.sort(key=lambda x:x[1],reverse=True)
#print(team_score)

while True:
	try:
		team=int(input())
		print(Inquiry(team))
	
	except EOFError:
		break

Measured memory_bytes: 7660
#include<iostream>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		if(a==0&&b==0)
			break;
		for(int i=0;i<a;i++){
			if(i%2==0){
				for(int j=0;j<b;j++){
					if(j%2==0){
						cout<<'#';
					}else{
						cout<<'.';
					}
				}
			}else{
				for(int j=0;j<b;j++){
					if(j%2==0){
						cout<<'.';
					}else{
						cout<<'#';
					}
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

//ll num[ten52];
//ll num2[ten52];
char cmap[10][10];


int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3,range;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    a=a1=a2=a3=a4=a5=a6=0;
    //float f,g,h;
    //string s,s1;
    //priority_queue<long long int> pq;
    //stack<int> stk;
    vector<pair<ll,ll>> vint;
    vector<ll> vtime;
    vector<pair<ll,ll>>::iterator iterl;
    vector<ll>::iterator itert;
    //map<pair<ll,ll>,ll> mp;
    //list<int> li;
    //map<string,int>::iterator iter;
    //set<int> sint;
    char now,pre,c;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a>>a1>>a2;
        vtime.push_back(a);
        vint.push_back(make_pair(a1,a2));
    }
    a=a1=a2=a3=a4=a5=a6=0;
    for(iterl=vint.begin(),itert=vtime.begin();iterl!=vint.end();iterl++,itert++)
    {
        a4=a1;a5=a2;a6=a3;
        a1=(*itert);
        a2=iterl->first;
        a3=iterl->second;
        n1=abs(a1-a4);
        n2=abs(a2-a5);
        n3=abs(a3-a6);
        if((n1%2)!=(n2+n3)%2)
        {
            cout<<"No";
            return 0;
        }
        else if(n1<(n2+n3))
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}



Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
ll S[MAX_N];

void solve() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b; a--;
		S[a]++; S[b]--;
	}
	rep(i, 0, N) S[i + 1] += S[i];
	cout << count(S, S + N, M) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
};

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll x, y, a, b, c;
  cin >> x >> y;
  cin >> a >> b >> c;

  ll p[a + 5];
  for (ll i = 1; i <= a; i++)
    cin >> p[i];

  ll q[b + 5];
  for (ll i = 1; i <= b; i++)
    cin >> q[i];

  ll r[c + 5];
  for (ll i = 1; i <= c; i++)
    cin >> r[i];

  sort(p + 1, p + a + 1, greater<ll>());
  sort(q + 1, q + b + 1, greater<ll>());

  multiset<ll> pq;
  ll res = 0;
  for (ll i = 1; i <= x; i++) {
    pq.insert(p[i]);
    res += p[i];
  }

  for (ll i = 1; i <= y; i++) {
    pq.insert(q[i]);
    res += q[i];
  }

  sort(r + 1, r + c + 1, greater<ll>());

  for (ll i = 1; i <= c; i++) {

    ll val = *pq.begin();

    if (r[i] <= val)
      break;
    res += r[i] - val;
    pq.erase(pq.begin());
    pq.insert(r[i]);
  }
  cout << res << en;

  return 0;
}

Measured memory_bytes: 11008
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    long L[N];
    L[0] = 2;
    L[1] = 1;
    REP(2, i, N + 1) {
        L[i] = L[i - 1] + L[i - 2];
    }

    cout << L[N] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>
#include<climits>

using namespace std;
typedef unsigned long long ll;

int main(){
    int n,m;
    while(cin>>n>>m,n){
        int city[102][102];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                city[i][j]=INT_MAX;
            }
            city[i][i]=0;
        }
        for(int i=0;i<m;i++){
            int a,b,c;
            cin>>a>>b>>c;
            city[a][b]=c;
            city[b][a]=c;
        }
        vector<int>que;
        vector<int>vec;
        vec.push_back(0);
        for(int i=1;i<n;i++){
            que.push_back(i);
        }
        int ret=0;
        while(!que.empty()){
            int mi=INT_MAX;
            int cur=-1,in;
            for(int j=0;j<que.size();j++){
                for(int i=0;i<vec.size();i++){
                    if(city[vec[i]][que[j]]<mi){
                        mi=city[vec[i]][que[j]];
                        cur=que[j];
                        in=j;
                    }
                }
            }
            ret+=mi;
            que.erase(que.begin()+in);
            vec.push_back(cur);
        }
        cout<<ret<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1264
#include<iostream>
#include<string>
using namespace std;
int main(){
  int w,h;
  string a[8];
  int an[8][8]={};
  cin >> h >> w;
  for(int i=0;i<h;i++){
    cin >> a[i];
  }
  an[0][0]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='#'){
	if(i!=0){
	  if(an[i-1][j]==1){
	    an[i-1][j]=0;
	    an[i][j]=1;
	  }
	}
	if(j!=0){
	  if(an[i][j-1]==1){
	    an[i][j-1]=0;
	    an[i][j]=1;
	  }
	}
	if(an[i][j]!=1){
	  i=h;
	  break;
	}
	
      }
    }
  }
  if(an[h-1][w-1]==1)cout << "Possible"<< endl;
  else cout << "Impossible"<< endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string>
#include<bitset>
#define LL long long

const int MAXN=57;
const int MAXM=10007;
const long long LLINF=9000000000000000000;
const int INF=2000000000;//careful because of floyed and so on
const int MOD=1000000007;
double eps=0.00000001;

using namespace std;

struct Point{
    int x,y;
};

const int u[4]={0,0,1,-1};
const int w[4]={1,-1,0,0};

int n,m,q;
char s[MAXN][MAXN];
vector<int> t[MAXN][MAXN];
int on[MAXN][MAXN];
int off[MAXN][MAXN];
int cost[MAXN][MAXN];
int x[MAXM],y[MAXM];
bool vis[MAXN][MAXN];
int d[MAXN][MAXN];

void work(int bx,int by,int ex,int ey){
    queue<Point>Q;
    memset(vis,0,sizeof(vis));
    Q.push((Point){bx,by});
    d[bx][by]=t[bx][by][t[bx][by].size()-1];
    vis[bx][by]=1;
    while (!Q.empty()){
            Point now=Q.front();
            Q.pop();
            for (int i=0;i<4;i++){
                    int x=now.x+u[i];
                    int y=now.y+w[i];
                    if (x<=0 || y<=0 || x>n || y>m || s[x][y]=='#' || vis[x][y]) continue;
                    vis[x][y]=1;
                    d[x][y]=d[now.x][now.y]+1;
                    Q.push((Point){x,y});
            }
    }
    Q.push((Point){ex,ey});
    while (!Q.empty()){
            Point now=Q.front();
            if (now.x==bx && now.y==by) break;
            t[now.x][now.y].push_back(d[now.x][now.y]);
            Q.pop();
            for (int i=0;i<4;i++){
                    int x=now.x+u[i];
                    int y=now.y+w[i];
                    if (x<=0 || y<=0 || x>n || y>m || s[x][y]=='#' || d[x][y]!=d[now.x][now.y]-1) continue;
                    Q.push((Point){x,y});
            }
    }
}

int main(){
    scanf("%d%d%d",&n,&m,&q);
    for (int i=1;i<=n;i++){
            scanf("%s",s[i]+1);
    }
    for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                    scanf("%d",&cost[i][j]);
            }
    }
    for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                    scanf("%d",&on[i][j]);
            }
    }
    for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                    scanf("%d",&off[i][j]);
            }
    }
    for (int i=1;i<=q;i++){
            scanf("%d%d",&x[i],&y[i]);
            x[i]++;
            y[i]++;
    }
    t[x[1]][y[1]].push_back(0);
    for (int i=2;i<=q;i++){
            work(x[i-1],y[i-1],x[i],y[i]);
    }
    int ans=0;
    for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                    if (t[i][j].size()>=1){
                            ans=ans+on[i][j]+off[i][j];
                    }
                    for (int k=1;k<(int)t[i][j].size();k++){
                            ans+=min(on[i][j]+off[i][j],(t[i][j][k]-t[i][j][k-1])*cost[i][j]);
                    }
            }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 6280
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}


int mod = 1e9 + 7;

// mod_power.cc
ll po(ll k, ll x) {
  if (x == 0) {
    return 1;
  }
  if (x == 1) {
    return k % mod;
  }
  ll y = po(k, x/2);
  y = y * y % mod;
  if (x % 2 == 1) {
    y = y * k % mod;
  }
  return y;
}

vll factorial;
vll inv_fact;
ll comb(ll x, ll y) {
  if (x < 0 || x < y) {
    return 0;
  }
  y = min(y, x-y);
  if (y == 0) {
    return 1;
  }
  ll ret = 1;
  ret = ret * factorial[x] % mod;
  ret = ret * inv_fact[y] % mod;
  ret = ret * inv_fact[x-y] % mod;
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  if (n <= 3) {
    int ans = 0;
    if (n == 2) {
      ans = 1;
    } else if (n == 3) {
      ans = 4;
    }
    printf("%d\n", ans);
    return 0;
  }

  factorial.assign(n+1, 0);
  inv_fact.assign(n+1, 0);
  factorial[0] = 1;
  inv_fact[0] = 1;
  rep (i, n) {
    factorial[i+1] = factorial[i] * (i+1) % mod;
    inv_fact[i+1] = po(factorial[i+1], mod-2) % mod;
    assert(factorial[i+1] * inv_fact[i+1] % mod == 1);
  }
  ll ans = 0;
  ll prev_cnt = 0;
  FOR (i, 2, n) {
    ll cnt = 1;
    cnt = cnt * comb(i-1, n-1-i) % mod;
    cnt = cnt * factorial[i] % mod;
    cnt = cnt * factorial[n-1-i] % mod;
    ll add = (cnt + mod - prev_cnt) * i % mod;
    prev_cnt = cnt;
    ans = (ans + add) % mod;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n,k;
    //int ans=0;
    cin >>n>>k;
    vector<int>p(n);
    vector<double>ex(n);
    double cnt=0.0;
    double ans=0.0;
    rep(i,n){
        cin>>p[i];
        ex[i]=(1.0+p[i])/2.0;
        clog<<ex[i]<<endl;
    }
    rep(i,n){
        ans+=ex[i];
        if(i >=k){
            ans-=ex[i-k];
        }
        chmax(cnt,ans);
    }
    printf("%.9lf\n",cnt);
}

Measured memory_bytes: 2560
n = int(input())
t, a = tuple(map(int, input().split()))
h = list(map(int, input().split()))
min=599
b=0


def kion(hi):
    return abs(a-t+0.006*hi)

for i in range(0,n):
    ne=kion(h[i])
    if min>ne:
        min=ne
        b=i+1

print(b)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    ll sum=0;
    cin>>s;
    for(int i=0;i<s.length();i++){
    	sum+=(s[i]-'0');
	}
	if(sum%9==0)
	cout<<"Yes";
	else
	cout<<"No";
    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N;
    scan(N);
    set<int> st;
    rep(i, N) {
        int a;
        scan(a);
        st.insert(a);
    }

    if (st.size() == N) {
        print("YES");
    } else {
        print("NO");
    }

    return 0;
}

Measured memory_bytes: 9600
import math
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B//a

def count(a,b,c):
    return b//c-(a-1)//c

A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)
print("{}".format(ans))


Measured memory_bytes: 3064
(defun yymm (aa bb)
  (let ((am (and (<= 1 aa) (<= aa 12)))
        (bm (and (<= 1 bb) (<= bb 12))))
    (cond ((and am bm) "AMBIGUOUS")
          (am "MMYY")
          (bm "YYMM")
          (t "NA"))))

(defun w_yymm (str)
  (if (not (= (length str) 4)) "NA"
    (let ((num (read-from-string str)))
      (if (not (numberp num)) "NA"
        (multiple-value-bind (aa bb) (floor num 100)
          (yymm aa bb))))))
#|
(print (yymm 17 00))
(print (yymm 01 12))
(print (yymm 19 05))
(print (w_yymm "abc"))
(print (w_yymm "123"))
(print (w_yymm "1700"))
(print (w_yymm "0112"))
(print (w_yymm "1905"))
(print (w_yymm "0000"))
|#

(let ((str (read-line)))
  (format t (w_yymm str)))


Measured memory_bytes: 15844
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const ll INF = 10000000000;//INFinity
using namespace std;//namespace

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}//transform
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//#define int long long // yabai

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=n;i>=0;i--)

#define ALL(obj) (obj).begin(),(obj)// iterator

#define pb(a) push_back(a)end()//push_back
#define mp make_pair// make_pair


int main(){

    // kokoni kaku
    ll x,y;
    ll sum=0;
    cin>>x>>y;
    ll n=x;
    while(n<=y){
        ++sum;
        n*=2;
    }

    cout<<sum<<endl;
    return 0;
}


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


int dp[20][50001];
int coin[20];
int n, m;


void makeDP(){
	for(int i = 0;i < 50001;i++){
		dp[0][i] = i;
	}
	for(int i = 0;i < m;i++){
		dp[i][0] = 0;
		dp[i][1] = 1;
	}
	for(int i = 1;i < m;i++){
		for(int j = 2;j <= n;j++){
			dp[i][j] = min(dp[i-1][j], ((j-coin[i])>-1)?dp[i][j-coin[i]]+1:dp[i-1][j]);
		}
	}
}


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

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

	makeDP();

	cout << dp[m-1][n] << endl;

	return 0;
}

Measured memory_bytes: 6996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
class UnionFind{
public:
  vector<int> Parent;
  
  UnionFind(int N){
    Parent = vector<int>(N+1,-1);
  }
  
  int root(int A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  int size(int A){
    return -Parent[root(A)];
  }
  
  bool connect(int A, int B){
    A = root(A);
    B = root(B);
    if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
    if(size(A) < size(B)) swap(A,B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};

int main(){
  int N,M;
  cin >> N >> M;
  int A[M],B[M];
  for(int i=0; i<M; i++) cin >> A[i] >> B[i];
  
  UnionFind Uni(N);
  
  long long ans[M];
  ans[M-1] = (long long) N * (N-1) / 2;
  
  for(int i=M-1; i>=0; i--){
    if(Uni.root(A[i]) != Uni.root(B[i])){
      ans[i-1] = (long long)ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
      Uni.connect(A[i],B[i]);
    }else ans[i-1] = ans[i];
  }
    
  for(int i=0; i<M; i++){
    cout << ans[i] << endl;
  }
  
  return 0;
}
    
    

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int x,a;
	cin >>x >>a;
	
	cout << (x<a? 0: 10) <<"\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    string first;
    string second;

    cin >> first;
    cin >> second;

    repeat (i, first.size()) {
        if (first[i] != second[second.size() - 1 - i]) {
            cout << "NO" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 892
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, L, R, H, W;


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

	cin >> N >> M;
	cout << max(0, (int)(N - M))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<bitset>
using namespace std;
const int N=50005,M=100005;
int n,m,T;
int x[M],y[M];
namespace Subtask1
{
bitset<N>f[N];
bool ans[M];
void print(int u)
{
	static bool book[N];
	book[u]=true;
	for(int i=m;i>=1;i--)
		if(!book[x[i]]) book[x[i]]=book[y[i]],ans[i]=1;
		else book[y[i]]=book[x[i]],ans[i]=0;
	for(int i=1;i<=m;i++)
		if(ans[i]) printf("v");
		else printf("^");
	return;
}
int main()
{
	for(int i=1;i<=n;i++)
		f[i][i]=true;
	for(int i=m;i>=1;i--)
		f[x[i]]=f[y[i]]=f[x[i]]|f[y[i]];
	bitset<N>res;
	for(int i=1;i<=n;i++)
		res[i]=1;
	for(int i=1;i<=n;i++)
		res&=f[i];
	if(res.count()==0) printf("-1");
	else print(res._Find_first());
	return 0;
}
}
namespace Subtask2
{
int siz[N],to[N];
bool ans[M];
int main()
{
	if(n<=2)
	{
		printf("-1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		to[i]=i,siz[i]=1;
	for(int i=m;i>=1;i--)
	{
		if(siz[to[x[i]]]>=n-1)
		{
			ans[i]=1;
			swap(x[i],y[i]);
		}
		siz[to[y[i]]]--;
		to[y[i]]=to[x[i]];
		siz[to[y[i]]]++;
	}
	for(int i=1;i<=m;i++)
		if(ans[i]) printf("v");
		else printf("^");
	return 0;
}
}
int main()
{
	scanf("%d%d%d",&n,&m,&T);
	for(int i=1;i<=m;i++)
		scanf("%d%d",&x[i],&y[i]);
	if(T==1) return Subtask1::main();
	else if(T==2) return Subtask2::main();
	return 0;
}


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

class Dice{
public:
  vector<int> d;
  void spin(string s){
    if(s == "S"){
      swap(d[0],d[4]);
      swap(d[4],d[1]);
      swap(d[4],d[5]);
    }
    if(s == "E"){
      swap(d[0],d[3]);
      swap(d[2],d[3]);
      swap(d[3],d[5]);
    }
    if(s == "N"){
      swap(d[0],d[1]);
      swap(d[1],d[5]);
      swap(d[4],d[5]);
    }
    if(s == "W"){
      swap(d[0],d[2]);
      swap(d[2],d[5]);
      swap(d[3],d[5]);
    }
    if(s == "C"){
      swap(d[1],d[3]);
      swap(d[2],d[3]);
      swap(d[4],d[3]);
    }
  }
};


int main(){

  Dice sai1,sai2;
  vector<int> in(6);
  for(int i=0; i<6; i++){
    cin >> in[i];
  }
  sai1.d = in;

  for(int i=0; i<6; i++){
    cin >> in[i];
  }
  sai2.d = in;
  
  string s = "CCCCECCCCECCCCECCCCSCCCCSSCCCC";
  bool is_same = true;
  for(int i=0; i<s.size(); i++){
    is_same = true;
    for(int j=0; j<6; j++){
      if(sai1.d[j] != sai2.d[j]){
	is_same = false; break;
      }
    }
    if(is_same) break;
    sai1.spin(s.substr(i,1));
  }
  if(is_same) cout <<"Yes\n";
  else  cout <<"No\n";

}

Measured memory_bytes: 1208
#include<stdio.h>
typedef struct{
  int flag[101];
}graph;
int main(){
  int x,i,j,num,num1,num2,max=0;
  scanf("%d",&x);
  graph g[++x];
  for(i=1;i<x;i++){
    scanf("%d",&num);
    scanf("%d",&num1);
    for(j=0;j<=100;j++)
      g[num].flag[j]=0;
    for(j=0;j<num1;j++){
      scanf("%d",&num2);
      if(num2>max)max=num2;    
      g[num].flag[num2]=1;
    }
  }
  for(i=1;i<x;i++){
    for(j=1;j<=max;j++){
      if(j==max){
	printf("%d\n",g[i].flag[j]);
      }
      else
	printf("%d ",g[i].flag[j]);
    }
  }
  return 0;
}
	       



Measured memory_bytes: 2108
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, d, tot;
double dis(ll x, ll y) {
	return sqrt(1.0*x*x+1.0*y*y);
}

int main() {
	scanf("%lld%lld", &n, &d);
	for(ll i=1;i<=n;i++) {
		ll x, y;
		scanf("%lld%lld", &x, &y);
		if(dis(x, y) - d <= 1e-6) {
			++tot;
		}
	}
	printf("%lld\n", tot);
	return 0;
}

Measured memory_bytes: 3780