akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    int center = (n-1)/2;
    ll ans = 0;
    if (n%2 == 0) {
        for (int i=0; i<n; i++) {
            if (i < center) {
                ans -= 2 * a.at(i);
            } else if (i == center) {
                ans -= a.at(i);
            } else if (i == center + 1) {
                ans += a.at(i);
            } else {
                ans += a.at(i) * 2;
            }
        }
    } else {
        ll buf1 = 0, buf2 = 0;
        for (int i=0; i<n; i++) {
            if (i < center) {
                buf1 -= 2 * a.at(i);
            } else if (i == center || i == center + 1) {
                buf1 += a.at(i);
            } else {
                buf1 += a.at(i) * 2;
            }
        }
        for (int i=0; i<n; i++) {
            if (i < center - 1) {
                buf2 -= 2 * a.at(i);
            } else if (i == center || i == center - 1) {
                buf2 -= a.at(i);
            } else {
                buf2 += a.at(i) * 2;
            }
        }
        ans = max(buf1, buf2);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

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

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

	ll n, d;
	cin >> n >> d;

	vector<ll> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];

	int ans = 0;
	rep(i, n){
		if(x[i] * x[i] + y[i] * y[i] <= d * d) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 6364
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
  print(0)
else:
  p = 1
  f = True
  for i in a:
    p *= i
    if(p > 1000000000000000000):
      f = False
      break
  if(f):
    print(p)
  else:
    print(-1)
  

Measured memory_bytes: 84620
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, m, ans;
bool g[10][10];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a][b] = g[b][a] = true;
    }
    vector<int> v(n);
    rep(i, 0, n) v[i] = i;
    do {
        ans++;
        rep(i, 0, n-1) {
            int x, y;
            x = v[i];
            y = v[i+1];
            if (!g[x][y]) {
                ans--;
                break;
            }
        }
    } while (next_permutation(v.begin()+1, v.end()));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int A = Integer.parseInt(sc.next());
	int B = Integer.parseInt(sc.next());
	int K = Integer.parseInt(sc.next());

	int pre = 1;
	int now = A;
	if(B-A+1 <= 2*K) {
	    for(int i = A; i<=B; i++) {
		System.out.println(i);
	    }
	    return;
	}
	for(int i=A; i<A+K; i++) {
	    System.out.println(i);
	}
	for(int i=K-1; i>=0; i--) {
	    System.out.println(B-i);
	}
    }
}

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

int main(){
    string ss;
    int count = 0;
    while( cin >> ss ){
        int i, j;
        for(i = 0, j = ss.length()-1; i < j; i++,j--){
            if( ss[i] != ss[j] ) break;
        }
        count += (i >= j);
    }
    cout << count << endl;
    return 0;
}

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

inline int read(){
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int N, M;
int total=0;
double sum;
int a[101];

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    //freopen(".in","r",stdin);
	//freopen(".out","w",stdout); 
	
	cin >> N >> M;
	
	for(int i=1; i<=N; i++){
		cin >> a[i];
		sum+=a[i];
	}
	
	sum/=(4*M);
	
	for(int i=1; i<=N; i++){
		if(a[i]>=sum){
			total++;
		}
	}
	
	if(total>=M){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	
	return 0;
}

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

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;
}

int N;
long long a[100010][3];
long long dp[100010][3];


void solve(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    long long res = 0;
    for(int j = 0; j < 3; j++) chmax(res, dp[N][j]);
    cout << res << endl;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; ++i) for(int j = 0; j < 3; ++j) cin >> a[i][j];
    solve();
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  ll a[105]={0};
  double sum = 0.0;
  rep(i,n) {
    cin>>a[i];
    sum+=a[i];
  }
  sum/=n;
  if(sum-int(sum) > 0.5){
    sum = (int)sum+1;
  } else {
    sum = (int)sum;
  }
  ll ans = 0;

  rep(i,n){
    ans += pow(a[i]-sum,2);
  }
  cout<<ans<<endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ll ans = 0;
  sum %= MOD;
  for(int i = 0; i < n; i++) {
    sum -= a[i];
    if(sum < 0) {
      sum += MOD;
    }
    ans += a[i] * sum % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

int main(){
	
	string str;
	cin>>str;
	
	int n=str.length();
	int count=0;
	for(int i=0,j=n-1;i<(n/2),j>=n/2;i++,j--){
		if(str[i]!=str[j]){
			count++;
		} 
	}
	
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
    int n, m;
    const int mod = 1000000007;
    cin >> n >> m;
    vector<int> broken(n + 1, 0);
    vector<int> dp(n + 2, 0);
    rep(i, m)
    {
        int a;
        cin >> a;
        broken[a] = 1;
    }
    for (int i = n; i >= 0; i--)
    {
        dp[n] = 1;
        if (broken[i])
        {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1024
/*==============================================*\
ID:          shahidul_brur
 
Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh
 
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int logn = 20;
bool eq(string a, string b)
{
    if(a.size()!=b.size()) return 0;
    int n = a.size();
    f0(i,n) if(a[i]!=b[i]) return 0;
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s, p;
    cin>>s;
    int k = 0, n = s.size();
    f0(i,n)
    {
        string t;
        t+=s[i];
        if(t==p && i+1<n){
            i++;
            t+=s[i];
        }
        if(t!=p){
            //cout << p << ". " << t << ".\n";
            k++;
        }
        p = t;
    }
    cout << k;
    return 0;
}


Measured memory_bytes: 720
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
//priority_queue<long long, vector<long long>, greater<long long>> pq;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long


const double pi = acos(-1.0);

LL mod = 1e9 + 7;
LL n, k;


int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif

  LL p = 1;
  for (int i = 1; i <= 100; i++) {
    p = p * 10 % mod;
  }

  LL ans = 0;
  cin >> n >> k;
  for (LL i = k; i <= n + 1; i++) {
    LL l = (p + p + i - 1) * i / 2;
    LL r = (p + n + p + n - i + 1) * i / 2;
    ans += (r - l + 1);
    ans %= mod;
    
  }
  cout << ans << endl;
  return 0;
}

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

string keitai(string s){
	string t="";
	char k1[6]=".,!? ";
		
	for(int i=0; i<s.size(); ++i){
		
		if(s[i]=='0') continue;
		else if(s[i]=='1'){
			int c1=0;
			do{
				++i;	
				++c1;
			}while(s[i]=='1');
			
			if(s[i]=='0') t += k1[(c1-1)%5];				
		}
		else{
			char c=s[i];
			int c2=0;
			do{
				++i;	
				++c2;
			}while(s[i]==c);
			if(s[i]=='0'){
				if('2'<=c && c<='6') t+='a'+((c-'2')*3)+((c2-1)%3);
				else if(c=='7') t+='p'+(c2-1)%4;
				else if(c=='8') t+='t'+(c2-1)%3;
				else if(c=='9') t+='w'+(c2-1)%4;
			}			
		}
	
	}
	
	return t;
}

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;	
		cout << keitai(s) << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n, k;
    cin >> n >> k;

    vector<pll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].S >> a[i].F;
    gsort(a);

    std::priority_queue<ll, vector<ll>, greater<>> pq;
    ll ans = 0;
    set<ll> use;

    ll tmp = 0;
    for(int i = 0; i < k; i++){
        tmp += a[i].F;
        if(use.find(a[i].S) != use.end()) pq.push(a[i].F);
        else use.insert(a[i].S);
    }
    ans = tmp + use.size() * use.size();
    for(int i = k; i < n && !pq.empty(); i++){
        if(use.find(a[i].S) != use.end()) continue;
        tmp -= pq.top();
        pq.pop();
        use.insert(a[i].S);
        tmp += a[i].F;
        ans = max(ans, tmp + (ll)use.size() * (ll)use.size());
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 5244
N = int(input())
D = [[int(i) for i in input().split()] for j in range(N)]
count = 0
for i in range(N-2):
  if(D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]):
    count += 1
if(count >= 1):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9104
def makePrime
  counter = 0
  prime = []

  n_prime = 1000000
  prime_check = Array.new(n_prime, true)
  prime_check[0] = prime_check[1] = false

  for i in 2...n_prime
    if prime_check[i]
      prime << i
      j = i*2
      while j < n_prime
        prime_check[j] = false
        j += i
      end
    end
  end

  return prime
end

prime = makePrime
while input = gets
  n = (input.chomp).to_i
  if n == 0
    break
  end

  sum = 0
  for i in 0...n
    sum += prime[i]
  end

  puts sum
end

Measured memory_bytes: 14668
n = int(input())
INF = 10 ** 9
dp = [INF] * (n + 1)
dp[0] = 0
for i in range(n):
  dp[i+1] = min(dp[i+1], dp[i] + 1)
  v = 6
  for j in range(1, 8):
    if i+1 >= v:
      dp[i+1] = min(dp[i+1], dp[i+1-v] + 1)
    v *= 6
  v = 9
  for j in range(1, 7):
    if i+1 >= v:
      dp[i+1] = min(dp[i+1], dp[i+1-v] + 1)
    v *= 9
print(dp[n])

Measured memory_bytes: 43116
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x)
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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

    //start from here

    read(n); readarr(a, n);

    map <int, int> mp;
    mp[a[1] + 1]++;

    int cnt = 0;

    fori (i, 2, n)
    {
    	cnt += mp[i-a[i]];
    	mp[a[i] + i]++;
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 27880
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cerr << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define X first
#define Y second
#define pb push_back
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define vi vector<int>
#define vii vector<vector<int>>
#define int long long
int32_t main(){ fast;
	int n; cin>>n;
	vi a(n);
	rep(i, n){
		cin>>a[i];
	}
	sort(all(a));
	int answer = 0;
	for(int i = 0; i < n - 2; i++){
		for(int j = i + 1; j < n - 1; j++){
			for(int k = j + 1; k < n; k++){
				if(a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]){
					answer++;
				}
			}
		}
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int comp(const void *left, const void *right){
	char l = *(char*)left;
	char r = *(char*)right;
	if (l < r) return -1;
	if (l > r) return +1;
	return 0;
}
int main(void){
	char s[4];
	scanf("%s", s);
	qsort(s, 3, sizeof(char), comp);
	if (!strcmp(s, "abc")) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    PrintWriter out = new PrintWriter(System.out);

    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    int n = Integer.parseInt(sl[0]);
    int m = Integer.parseInt(sl[1]);

    UnionFind uf = new UnionFind(n);

    int a[] = new int[m];
    int b[] = new int[m];
    long res[] = new long[m];

    for(int i = 0; i < m; i++)
    {
      s = r.readLine();
      sl = s.split(" ");
      a[i] = Integer.parseInt(sl[0]) - 1;
      b[i] = Integer.parseInt(sl[1]) - 1;
    }

    long z = (long)n * ((long)n - 1) / 2;

    for(int i = m - 1; i >= 0; i--)
    {
      res[i] = z;
      int x = a[i];
      int y = b[i];

      if(!uf.sim(x, y))
      {
        long xx = uf.getSize(x);
        long yy = uf.getSize(y);
        uf.union(x, y);
        z -= xx * yy;
      }
    }


    for(int i = 0; i < m; i++)
    {
      out.println(res[i]);
    }

    out.flush();
  }

  public static class UnionFind
  {
    int n;
    int parent[];
    int rank[];
    int size[];

    public UnionFind(int n)
    {
      this.n = n;
      parent = new int[n];
      rank = new int[n];
      size = new int[n];

      for(int i = 0; i < n; i++)
      {
        parent[i] = i;
        size[i] = 1;
      }
    }

    public int getSize(int x)
    {
      if(parent[x] == x)
      {
        return size[x];
      }
      return getSize(find(x));
    }

    public int union(int x, int y)
    {
      int fx = find(x);
      int fy = find(y);
      if(rank[fx] > rank[fy])
      {

        size[fx] += getSize(fy);
        parent[fy] = fx;
      }
      else if(rank[fx] < rank[fy])
      {
        size[fy] += getSize(fx);
        parent[fx] = fy;
      }
      else if(fx != fy)
      {
        size[fx] += getSize(fy);
        parent[fy] = fx;
        rank[fx]++;
      }

      return 0;
    }

    public int find(int x)
    {
      if(parent[x] == x)
      {
        return x;
      }
      parent[x] = find(parent[x]);
      return parent[x];
    }

    public boolean sim(int x, int y)
    {
      return find(x) == find(y);
    }
  }


}

Measured memory_bytes: 68624
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: usize = read_as_vec()[0];
    let s = read_as_string().chars().collect::<Vec<char>>();
    let t = read_as_string().chars().collect::<Vec<char>>();

    'outer: for i in 0..n{
        for j in 0..n-i{
            if s[i+j] != t[j]{
                continue 'outer;
            }
        }
        println!("{}", n+i);
        return;
    }
    println!("{}", n*2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];
//平方根　= sqrt




int main() {
  int n;
  cin >> n;
  vector<char> s;

  string x = to_string(n);
  int num = x.size();

  for (int i=0;i<num; i++) {
    s.push_back(x[i]);
  }
  
  int sum =0;
  for (char c:s) {
    if ('0' <= c && c <= '9')
      sum += c-'0';
  }

  if (n%sum==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    ll ans = N;

    repd(i, 1, N) {
        ans *= i;
        ans %= MOD;
    }
    repd(i, 1, M + 1) {
        ans *= i;
        ans %= MOD;
    }

    if (N == M) {
        ans *= 2;
        ans %= MOD;
    }
    else if (abs(N - M) >= 2) {
        ans = 0;
    }

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

Measured memory_bytes: 256
n = int(input())
S = [0] * 13
H = [0] * 13
C = [0] * 13
D = [0] * 13
for i in range(n):
	mark,val = raw_input().split()
	val = int(val)
	if mark=="S":
		S[val-1] = 1
	elif mark=="H":
		H[val-1] = 1
	elif mark=="C":
		C[val-1] = 1
	else: # mark=="D"
		D[val-1] = 1

for i in range(0,13):
	if S[i]==0: print "S %s" % (i+1)
for i in range(0,13):
	if H[i]==0: print "H %s" % (i+1)
for i in range(0,13):
	if C[i]==0: print "C %s" % (i+1)
for i in range(0,13):
	if D[i]==0: print "D %s" % (i+1)

Measured memory_bytes: 6448
package main

import (
	"fmt"
	"math"
)

func main() {
	var A, B, H, M float64
	fmt.Scan(&A, &B, &H, &M)
	ra := math.Pi / 6 / 60 * (60*H + M)
	rb := math.Pi / 30 * M
	diff := ra - rb
	ans := math.Sqrt(math.Pow(A, 2) + math.Pow(B, 2) - 2*A*B*math.Cos(diff))
	fmt.Println(ans)
}


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

#if 0
所用時間: 1h

感想: 思ったより実装すべきコード量が多かった。DisjointSetは今後も使う機会が多そうなので、クラス化してみた。
Pの配列を動的に確保するよう工夫した、良い復習になった。

#endif

int N, buff, M = 0, SUM = 0, A[101][101], cost[5000], dpt[5000], dst[5000];//A[Y][X]
vector<pair<int, int> > edges;

class disjointSet {
private:
    int* P;
    
public:
    disjointSet(){
        P = new int[100000];
    }
    disjointSet(int N){     
        P = new int[N];
    }
    ~disjointSet(){
        delete[] P;
    }

    void init(int N){ //木構造の初期化
        for(int i = 0; i <= N; ++i){
            P[i] = i;
        }
    }

    int root(int a){ //根の参照
        if(P[a] == a) return a;
        return (P[a] = root(P[a]));
    }

    bool is_same_set(int a, int b){ //同じ根か?
        return root(a) == root(b);
    }

    void unite(int a, int b){
        P[root(a)] = root(b); //aのrootをbの子にする
    }
};


void preprocess(){//辺の前処理
  for(int r = 0; r < N; ++r){
    for(int c = r+1; c < N; ++c){
      if (A[r][c] > -1) {
        cost[M] = A[r][c];
        dpt[M] = r;
        dst[M] = c;
        M++;
      }
    }
  }

  //for(int i = 0; i < M; ++i) cout << cost[i] << endl;

  for(int i = 0; i < M; ++i){
    edges.push_back(make_pair(cost[i], i));
  }
  // for(int i = 0; i < M; ++i) cout << edges[i].first << " " << edges[i].second << endl;

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

  // for(int i = 0; i < M; ++i) cout << edges[i].first << " " << edges[i].second << endl;

}

void solve(){
  disjointSet Union(100000);

  int ans = 0;
  preprocess();

  Union.init(N);

  for(int i = 0; i < M; ++i){
    int index = edges[i].second;
    if(Union.is_same_set(dpt[index], dst[index])) continue;
    else {
      Union.unite(dpt[index], dst[index]);
      // cout << "unite " << dpt[index] << " and " << dst[index] << endl;
      ans += cost[index];
    }
  }
  cout << ans << endl;
}

int main(){

cin >> N;

for(int i = 0; i < N; ++i){
  for(int j = 0; j < N; ++j){
    cin >> buff;
    A[i][j] = buff;
    }
  }

  //行列の表示
  // cout << "Matrix:" << endl;
  // for(int row=0; row < N; ++row){
  //   for(int col = 0; col < N; ++col){
  //     cout << A[row][col];
  //   }
  //   cout << endl;
  // }

  solve();
}



Measured memory_bytes: 3236
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
#define ll long long
int main(){
    ll i,j,s,a[2002]={};
    scanf("%lld",&s);
    a[3]=1;
    a[4]=1;
    a[5]=1;
    a[6]=2;
    for(i=7; i<=s; i++){
        for(j=3; j<=i-3; j++){
            a[i]+=a[j];
            a[i]=a[i]%1000000007;
        }
        a[i]++;
    }
    printf("%lld",a[s]);
    return 0;
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(0);cin.tie(0); 
  int a,b;
  cin>>a>>b;
  a=a*500;
  if(a>=b)
  cout<<"Yes";
  else if(a<b)
  cout<<"No";
  
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    int a,b;
    cin >> a >> b;
    if ((a+b)%2== 0) {
        cout << (a+b)/2 << "\n";
    } else {
        cout << "IMPOSSIBLE" << "\n";
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

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

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

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

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
int N;
vector<vector<pair<int,int>>>G;
vector<int> depth;
int root = 0;
vector<bool> use;
vector<vector<LL>>dist;
vector<vector<int>>oya;
void set_dat(int R,int x,int d,LL D) {
	oya[x][0] = R;
	use[x] = true;
	depth[x] = d;
	dist[x][0] = D;
	
	for (int i = 0; i < G[x].size(); ++i) {
		int ter = G[x][i].first;
		if (use[ter])continue;
		set_dat(x,ter, d + 1,dist[x][0]+G[x][i].second);
	}
}
void solve() {
	cin >> N;
	G = vector<vector<pair<int,int>>>(N);
	depth = vector<int>(N,0);
	use = vector<bool>(N, false);
	dist = vector<vector<LL>>(N, vector<LL>(20));
	oya = vector<vector<int>>(N, vector<int>(20));
	pair<int, int> edge;
	for (int i = 0; i < N-1; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		edge.first = b;
		edge.second = c;
		G[a].push_back(edge);
		edge.first = a;
		G[b].push_back(edge);
	}
	int Q, K;
	cin >> Q >> K;
	--K;
	root = K;
	set_dat(-1,root,0,0);
	/*
	for (int k = 0; k < 19; ++k) {
		for (int i = 0; i < N; ++i) {
			int A;
			A = oya[i][k];
			if (A == -1)continue;
			oya[i][k + 1] = oya[A][k];
		}
	}*/
	int x, y;
	for (int i = 0; i < Q; ++i) {
		cin >> x >> y;
		--x; --y;
		LL res = dist[x][0] + dist[y][0];
		cout << res << endl;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 43648
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
#define F(x,z,y)L x(L f){return z;}L y(L
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;F(M,f?B[f]+M(f^f&-f):0,D)a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}F(K,(a=X[f],n=X[b],a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]))),S)x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

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

int main(void){
  int k, s, count = 0, x, y;
  cin >> k >> s;
  for(x = 0; x <= k; x++){
    for(y = 0; y <= k; y++){
      if(0 <= s-x-y && s-x-y <= k) count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

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

    int x, y, z;
    int cnt = 0;

    scanf("%d %d %d", &x, &y, &z);

    x -= z;

    while(1){

        x -= z;

        if(x - y < 0){
            break;
        }

        x -= y;
        cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}

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

int search(int A[], int n, int key){
	int i = 0;
	A[n] = key;
	while (A[i]!=key) i++;
	return i != n;
}

int main(){
	int i, n, A[10000+1], q, key, sum = 0;

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

	cin >> q;
	for(i = 0; i < q; i++){
		cin >> key;
		if(search(A, n, key)) sum++;
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define R register
#define IN inline
#define W while
#define gc getchar()
#define ll long long
#define MX 405
#define SIZ 100500
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	for (; !isdigit(c); c = gc);
	for (;  isdigit(c); c = gc)
	x = (x << 1) + (x << 3) + c - 48;
}
int n, m, ans;
int a[SIZ], b[SIZ];
std::bitset <MX> st[MX];
bool out[MX];
int main(void)
{
	in(n), in(m);
	for (R int i = 1; i <= m; ++i)
	in(a[i]), in(b[i]);
	for (R int i = 1; i <= n; ++i)
	{
		st[i][i] = true;
		for (R int j = m; j; --j)
		{
			if (st[i][a[j]] && st[i][b[j]])
			{out[i] = true; goto gg;}
			if ((!st[i][a[j]]) && (!st[i][b[j]])) continue;
			st[i][a[j]] = st[i][b[j]] = true;
		}
		gg: ;
	}
	for (R int i = 1; i < n; ++i)
	for (R int j = i + 1; j <= n; ++j)
	ans += (!out[i]) && (!out[j]) && (st[i] & st[j]).none();
	printf("%d", ans);
}


Measured memory_bytes: 1024
using System;
using System.Text;

namespace Main
{
  class Program
  {
    static void Main(string[] args)
    {
      var lines = Console.ReadLine().Split(' ');
      var a = int.Parse(lines[0]);
      var b = int.Parse(lines[1]);
      var k = int.Parse(lines[2]);

      StringBuilder buf = new StringBuilder();
      if (b - a < k * 2)
      {
        for (var i = a; i <= b; i++)
            buf.Append(i).Append('\n');
      }
      else
      {
        for (var i = a; i < a + k; i++)
          buf.Append(i).Append('\n');
        for (var i = b - k + 1; i <= b; i++)
          buf.Append(i).Append('\n');
      }

      Console.Write(buf);
    }
  }
}


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

#define SAFE_DELETE( x ) { if ( x ){ delete x; x = NULL; } }

struct tCell{
	tCell() : x( 0 ), prev( NULL ), next( NULL ){}
	int x;
	tCell *prev, *next;
};

class MyArray{
public:
	MyArray() : mSize( 0 ), head( NULL ), tail( NULL ){
		head = new tCell;
		tail = new tCell;
		head->next = tail;
		tail->prev = head;
	}
	~MyArray(){
		for ( int i = mSize; i > 0; --i ){
			tCell* it = tail->prev;
			it->prev->next = it->next;
			it->next->prev = it->prev;
			SAFE_DELETE( it );
		}
		mSize = 0;
		SAFE_DELETE( tail );
		SAFE_DELETE( head );
	}
	void pushBack( int x ){
		tCell* it = new tCell;
		it->x = x;
		it->prev = tail->prev;
		it->next = tail;
		it->prev->next = it;
		it->next->prev = it;
		++mSize;
	}
	int size(){ return mSize; }

	int operator[]( int index ){
		tCell* it = head->next;
		for ( int i = 0; i < index; ++i ){
			it = it->next;
		}
		return it->x;
	}

private:
	int mSize;
	tCell *head, *tail;
};

int main(){
	int number;
	double weight, height;
	char c;
	MyArray list;

	while ( cin >> number >> c >> weight >> c >> height ){
		if ( ( weight / ( height * height ) ) >= 25.0 ){
			list.pushBack( number );
		}
	}

	for ( int i = 0; i < list.size(); ++i ){
		cout << list[ i ] << endl;
	}
	if ( !list.size() ){
		cout << "ツ該ツ督鳴づ按つオ" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mx 1000007
#define ll long long




int main(){
    int n,d;
    cin>>n>>d;
    int cnt=0;
    while(n--){
        double a,b;
        cin>>a>>b;
        abs(a);
        abs(b);
        double x=sqrt((a*a+b*b));
        if(x<=d)cnt++;
    }
    cout<<cnt<<endl;
}










Measured memory_bytes: 3704
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2
#define I 999999999

int g[N][N],n;

int prim(){
  int i,u,v;
  int d[N]={},p[N]={},color[N]={};
  int min,sum=0;
  
  for(i=0;i < n;i++){
    d[i]=I;
    color[i]=W;
    p[i]=-1;
  }
  d[0]=0;


  while(1){
    min=I;
    for(i=0;i < n;i++){
      if(color[i]!=B && d[i]<min){
	min=d[i];
	u=i;
      }
    }

    if(min == I)break;

    color[u]=B;

    for(v=0;v < n;v++){
      if(color[v]!=B && g[u][v]!=-1){
	if(g[u][v]<d[v]){
	  d[v]=g[u][v];
	  p[v]=u;
	  color[v]=G;
	}
      }
    }
  }
  for(i=0;i<n;i++)if(p[i]!=-1)sum+=g[i][p[i]];

  return sum;
}

int main(){
  int j,i;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    for(j=0;j<n;j++) scanf("%d",&g[i][j]);

  printf("%d\n",prim());
  return 0;
}



Measured memory_bytes: 2100
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

magicsq n = runST $ do
    arr <- newArray ((0,0),(n-1,n-1)) 0 :: ST s (STUArray s (Int,Int) Int)
    forM_ (zip [1..] (take n (iterate next' start) >>= take n . iterate next)) $ \(i, p) -> do
        writeArray arr p i
    sequence [concat <$> sequence [show' <$> readArray arr (x,y) | x <- [0..n-1]] | y <- [0..n-1]]
  where
    start = (div n 2, div n 2 + 1)
    next (x,y) = (mod (x+1) n, mod (y+1) n)
    next' (x,y) = (mod (x-1) n, mod (y+1) n)
    

show' n = replicate (4-length s) ' ' ++ s
  where
    s = show n

main = takeWhile (/=0) . map readInt . lines <$> getContents >>= mapM_ (mapM_ putStrLn . magicsq)

Measured memory_bytes: 4192
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

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

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n, k;
int a[N];

int main(){
  scanf("%d %d", &n, &k);
  for(int i = 1; i <= n; ++i){
    scanf("%d", a + i);
  }
  sort(a + 1, a + 1 + n);
  int g = a[1];
  for(int i = 2; i <= n; ++i){
    g = __gcd(a[i], g);
  }
  if(a[n] >= k && (a[n] - k) % g == 0){
    printf("POSSIBLE\n");
  } else{
    printf("IMPOSSIBLE");
  }
  return 0;
}


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

int main() {
  int a,b,c; cin >> a >> b >> c;
  vector<int>v{a,b,c};
  sort(v.begin(),v.end());
  int ans = v.at(0)+v.at(1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

import heapq
from collections import defaultdict
g1 = defaultdict(set)
for u, v in uv:
    g1[u-1].add(v-1)

s -= 1
t -= 1

dist = [[float('inf')] * 3 for _ in range(n)]
dist[s][0] = 0

q = [(0, s, 0)] # (dist, pos, kenken)
heapq.heapify(q)

while q:
    du, u, c = heapq.heappop(q)
    if dist[u][c] < du:
        continue
    c2 = (c + 1) % 3
    for v in g1[u]:
        if du + 1 < dist[v][c2]:
            dist[v][c2] = du + 1
            heapq.heappush(q, (dist[v][c2], v, c2))

if dist[t][0] != float('inf'):
    print(dist[t][0] // 3)
else:
    print(-1)


Measured memory_bytes: 128252
S = input()

cnt=1
flag=1

#S2 = list(map(str, S))
#print(S)
for s in S:
    if(cnt%2==0):
#        print("a",s)
        if not(s=='L' or s=='U' or s=='D'):
            flag=0
        cnt+=1
    else:
        if not(s=='R' or s=='U' or s=='D'):
#            print("b",s)
            flag=0
        cnt+=1
#    print("cnt",cnt)
            
if(flag==1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    long long n,T;
    cin>>n>>T;
    vector<long long>t(n);
    long long sum=0;
    for(int i=0;i<n;i++)cin>>t[i];
    if(n==1){
        cout<<T<<endl;
        return 0;
    }
    for(int i=1;i<n;i++){
        if(t[i]-t[i-1]>T)sum+=T;
        else sum+=t[i]-t[i-1];
    }
    sum+=T;
    cout<<sum<<endl;
}

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

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string name1, name2;
  cin >> name1 >> name2;
  int length = name1.length();
  cout << ((name1 + name2[length] == name2)? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;cin>>n;
    vector<int> a(n);
    for(int i = 0; n > i; i++){
    	cin>>a[i];
    }
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    cout << a.size() << endl;
}
        


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	string s;
	cin >> s;
	string a = "festival";
	s = s.substr(0 , sz(s) - sz(a));
	cout << s << nl;
	


	return 0;
}

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(A) A.begin(), A.end()
#define SZ(A) (ll)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 1e6;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k, sum = 0;
	cin >> n >> k;
	ll a[n], mx = 0;
	for (ll i = 0; i < n; i++) cin >> a[i];
	for (ll i = 0; i < k; i++) sum += a[i];
	if ((k + sum) > mx) mx = (k + sum);
	for (ll i = k; i < n; i++) {
		sum -= a[i - k];
		sum += a[i];
		if ((k + sum) > mx) mx = (k + sum);
	}
	if (mx % 2 == 0) cout << mx / 2 << "\n";
	else cout << mx / 2 << ".5" << "\n";
 	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

struct x {
    string s;
    int p;
    int i;
};
int main() {
    int n;
    cin >> n;
    vector<x> v;
    rep(i, n) {
        string str;
        int p;
        cin >> str >> p;
        struct x tmp;
        tmp.s = str;
        tmp.p = p;
        tmp.i = i;
        v.push_back(tmp);

    }
    sort(v.begin(), v.end(), [](struct x a, struct x b) {
                                 if (a.s == b.s) {
                                     return a.p > b.p;
                                 } else {
                                     return a.s < b.s;
                                 }
                             });

    for (auto i: v) {
        cout << i.i + 1<< endl;
    }
    return 0;
}


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

#define int long long

int n,a[3005];
int f[3005][3005];

signed main()
{
	cin>>n;
	for(int i=1;i<=n;cin>>a[i++]);
	for(int i=1;i<=n;f[i][i]=a[i],i++);
	for(int i=2;i<=n;i++)
		for(int l=1;l+i-1<=n;l++)
		{
			int r=l+i-1;
			f[l][r] = max(a[l]-f[l+1][r],-f[l][r-1]+a[r]);
		}
	cout<<f[1][n]<<endl;
	
	return 0;
}

Measured memory_bytes: 70016
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    double lhs, rhs;
    int al = 0;
    int ar = 0;
    int bl = 0;
    int br = 0;
    int cl = 0;
    int cr = 0;
    int dl = 0;
    int dr = 0;
    while (cin>>lhs>>rhs) {
        if (lhs >= 1.1) al++;
        if (rhs >= 1.1) ar++;
        if (1.1 > lhs && lhs >= 0.6) bl++;
        if (1.1 > rhs && rhs >= 0.6) br++;
        if (0.6 > lhs && lhs >= 0.2) cl++;
        if (0.6 > rhs && rhs >= 0.2) cr++;
        if (0.2 > lhs && lhs >= 0.1) dl++;
        if (0.2 > rhs && rhs >= 0.1) dr++;
    }
    cout<<al<<" "<<ar<<endl;
    cout<<bl<<" "<<br<<endl;
    cout<<cl<<" "<<cr<<endl;
    cout<<dl<<" "<<dr<<endl;
    return 0;
}


Measured memory_bytes: 3052
n, k = map(int, input().split())
A = set([int(i) for i in input().split()])
num = set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) - A

for i in range(n, n * 10 + 1):
    for j in list(str(i)):
        if int(j) not in num:
            break
    else:
        print(i)
        break

Measured memory_bytes: 3064
/*
  A - Shiritori
  Contest 060
  Rakesh Kumar --> 24/08/2020
 */

#include <bits/stdc++.h>

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

    std::string s;
    std::getline(std::cin, s);
    std::istringstream iss(s);
    std::string a;
    std::string b;
    std::string c;
    iss >> a >> b >> c;
    if (a[a.size() - 1] == b[0] &&
        b[b.size() - 1] == c[0])
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;

    return 0;
}


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

int main(){

	int s,m,h;

	cin >> s;

	h = s / 60 / 60;
	s = s - h*60*60;
	m = s / 60;
	s = s - m * 60;

	cout << h << ":" << m << ":" << s << endl;
	
	return 0;
}


Measured memory_bytes: 3096
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
V<int> v[1000005];
int a[1005][1005],id[1005][1005],num[1000005];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,cnt=0;
	cin>>n;
	rep(i,1,n)FOR(j,i+1,n)id[i][j]=id[j][i]=++cnt;
	FOR(i,1,n){
		rep(j,1,n)cin>>a[i][j];
		rep(j,1,n-1)v[id[i][a[i][j]]].PB(id[i][a[i][j+1]]),num[id[i][a[i][j+1]]]++;
	}
	queue<P<int,int> > q;
	FOR(i,1,cnt){
		if(!num[i]){
			q.emplace(MP(i,1));
		}
	}
	P<int,int> cur;
	int ans=0;
	while(!q.empty()){
		cur=q.front();q.pop();
		ans=max(ans,cur.S);
		for(auto u:v[cur.F]){
			num[u]--;
			if(!num[u])q.emplace(MP(u,cur.S+1));
		}
	}
	FOR(i,1,cnt){
		if(num[i]){
			cout<<-1;RE 0;
		}
	}
	cout<<ans;
	RE 0;
}




Measured memory_bytes: 51072