akhauriyash/Code-Regression huggingface dataset:
<?php

fscanf(STDIN, "%d %d", $n, $d);

$points = [];
for ($i = 0; $i < $n; ++$i) {
    $input = trim(fgets(STDIN));
    $points[] = explode(' ', $input);
}

$count = 0;
for ($i = 0; $i < $n - 1; ++$i) {
    for ($j = $i + 1; $j < $n; ++$j) {

        $sum = 0;
        for ($k = 0; $k < $d; ++$k) {
            $sum +=  pow($points[$j][$k] - $points[$i][$k], 2);
        }

        if (strpos(sqrt($sum), '.') === false) {
            ++$count;
        }
    }
}

echo $count;


Measured memory_bytes: 4604
#include<iostream>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int i,k;
  int a[105]={};
  for(i=0;i<n;i++) cin >> a[i];
  for(k=1;k<=m;k++){
    for(i=0;i<n-1;i++){
      if(a[i]%k>a[i+1]%k) swap(a[i],a[i+1]);
    }
  }
  for(i=0;i<n;i++) cout << a[i] << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
using namespace std;
 
int arr[200005];
int n;
 
long long dnc(int from, int to){
    if(from>=to-1)
        return 0;
     
    long long num=0;
    int mid=(from+to)/2;
    num+=dnc(from, mid);
    num+=dnc(mid, to);
     
    int i=from, j=mid, cnt=0;
    while(i<mid && j<to){
        if(arr[i]>arr[j]){
            num+=j-i-cnt++;
            j++;
        }
        else{
            i++;
        }
    }
     
    sort(arr+from, arr+to);
    return num;
}
 
int main() {
    ios_base::sync_with_stdio(0);
     
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> arr[i];
    }
     
    cout << dnc(0, n) << endl;
     
    return 0;
}


Measured memory_bytes: 3952
import sys

def dfs(u,D):
    sys.setrecursionlimit(10**6)
    for v,w in tree[u]:
        if d[v]==-1:
            d[v]=(D+w)%2
            dfs(v,D+w)

N=int(input())
d=[-1 for _ in range(N)]
d[0]=0
tree=[[] for _ in range(N)]

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    tree[u].append([v,w])
    tree[v].append([u,w])

dfs(0,0)
for i in d:
    print(i%2)

Measured memory_bytes: 87224
#include<bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b; i++)
#define fd(i,a,b) for(int i = a; i > b;i--)
#define long long ll
#define fl(i,a,b) for(ll i = a; i < b; i++)
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VS vector<string>
#define VL vector<long long>
#define VC vector<char>
#define VF vector<float>
#define PB push_back
#define F first
#define S second
#define fa(i,skill) for(auto i : skill)
#define fr(i,skill) for(VI :: reverse_iterator i = skill.rbegin(); i != skill.rend(); i++)
using namespace std;
 /*void edit(VI &skill,int n)
{
    f(i,0,n)
        {
            int x;
            cin >> x;
            skill.PB(x);
        }
}
*/
int main()
{
	string s;
	/*cin.ignore();*/
	cin >> s;
	VI ans;
	int j = 0;
	f(i,0,3)
	{
		if(s[i] == 'R')
			j++;
		else
		{
			ans.PB(j);
			j = 0;
		}
	}
	ans.PB(j);
	VI :: iterator it = max_element(ans.begin(), ans.end()) ;
	cout << *it << "\n";
    return 0;
}


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

int main(int argc, char const *argv[])
{
    int a,b,c;
    cin >> a >> b >> c;
    if( a<b && b<c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


// aiはlevel iの層の厚さ
// piはlevel iのパティの数
ll a[52], p[52]; 

ll f(int N, ll X) {
    if (N == 0) {
        if (X <= 0) {
            return 0;
        } else {
            return p[0];
        }
    } else if (X <= (a[N-1] + 1)) {
        return f(N-1, X-1);
    } else if (X == (a[N-1] + 2)) {
        return f(N-1, X-1) + 1;
    } else {
        return p[N-1] + 1 + f(N-1, X-2-a[N-1]);
    }
}

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    ll X; cin >> X;

    a[0] = 1;
    p[0] = 1;
    repr(i, 1, 51) {
        a[i] = a[i-1] * 2 + 3;
        p[i] = p[i-1] * 2 + 1;
    }

    cout << f(N, X) << endl;
    return 0;
}

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

#define ll long long int

map<ll,int> m;

void modify(ll x,int k){
	for(int i=0;i<4;i++){
		m[x]+=k;
		x=(x>>10)|((x&1023)<<30);
	}
}

ll Hash(ll a,ll b,ll c,ll d){
	return (a<<30)|(b<<20)|(c<<10)|d;
}

ll f[400][4],h[400],tmp[4];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>f[i][0]>>f[i][1]>>f[i][2]>>f[i][3];
		h[i]=Hash(f[i][0],f[i][1],f[i][2],f[i][3]);
		modify(h[i],1);
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		modify(h[i],-1);
		for(int j=i+1;j<n;j++){
			modify(h[j],-1);
			for(int k=0;k<4;k++){
				tmp[0]=Hash(f[i][3],f[i][2],f[j][(k+1)%4],f[j][k]);
				tmp[1]=Hash(f[i][2],f[i][1],f[j][(k+2)%4],f[j][(k+1)%4]);
				tmp[2]=Hash(f[i][1],f[i][0],f[j][(k+3)%4],f[j][(k+2)%4]);
				tmp[3]=Hash(f[i][0],f[i][3],f[j][k],f[j][(k+3)%4]);
				ll z=1;
				if(m[tmp[0]]==0||m[tmp[1]]==0||m[tmp[2]]==0||m[tmp[3]]==0)	continue;
				for(int l=0;l<4;l++){
					z*=m[tmp[l]];
					modify(tmp[l],-1);
				}
				ans+=z;
				for(int l=0;l<4;l++)
					modify(tmp[l],1);
			}
			modify(h[j],1);
		}
	}
	cout<<ans<<endl;
		
}


Measured memory_bytes: 20352
import java.io.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();

		long ans = 1;
		for(int i=1;i<=N;i++){
			ans=(ans*i)%MOD;
		}
		System.out.println(ans);
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21076
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 710
int n,m;
vector<int> v[N];

int c[N],cnt1,cnt2,flag;
void dfs(int x,int nc){
    if(c[x]!=-1){
	if(c[x]!=nc)flag=1;
	return;
    }
    c[x]=nc;
    if(nc==0)cnt1++;
    if(nc==1)cnt2++;
    for(auto i:v[x]){
	dfs(i,1-nc);
    }
}

bool dp[N],cop[N];
bool th[N][N];
int main(){
    cin>>n>>m;
    lol(i,n)lol(j,n)th[i][j]=1;
    lol(i,m){
	int a,b;cin>>a>>b;a--,b--;
	th[a][b]=0,th[b][a]=0;
    }
    lol(i,n)lol(j,n){
	if(th[i][j]==1&&i!=j){
	    v[i].push_back(j);
	}
    }
    lol(i,n)c[i]=-1,dp[i]=0;
    dp[0]=1;
    lol(i,n){
	if(c[i]==-1){
	    cnt1=cnt2=flag=0;
	    dfs(i,0);
	    if(flag==1){
		cout<<"-1"<<endl;
		return 0;
	    }
	    if(cnt1>cnt2)swap(cnt1,cnt2);
	    cnt2-=cnt1;
	    //cout<<"%"<<cnt1<<" "<<cnt2<<endl;
	    lol(j,N)cop[j]=0;
	    for(int j=0;j<N-cnt1;j++){
		cop[j+cnt1]=dp[j];
	    }
	    for(int j=N-cnt2;j>=0;j--){
		cop[j+cnt2]|=cop[j];
	    }
	    lol(j,N)dp[j]=cop[j];
	}
    }
    //lol(i,n)cout<<dp[i]<<" ";cout<<endl;
    for(int i=n/2;i>=0;i--){
	if(dp[i]==1){
	    int ans=i*(i-1)+(n-i)*(n-i-1);
	    cout<<ans/2<<endl;
	    return 0;
	}
    }
    
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
const int INF=INT_MAX;

int n;
vector<int>vec;
vector<int>graph[200005];
vector<int>dp;
int ans[200005];

void dfs(int pos,int from);
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int data;
    cin>>data;
    vec.push_back(data);
    dp.push_back(INF);
  }
  
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  
  dfs(0,-1);
  for(int i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }
  return(0);
}

void dfs(int pos,int from){
  int target=vec[pos];
  vector<int>::iterator itr=lower_bound(dp.begin(),dp.end(),target);
  int stack=*itr;
  *itr=target;
  ans[pos]=lower_bound(dp.begin(),dp.end(),INF)-dp.begin();
  
  for(int i=0;i<graph[pos].size();i++){
    int next=graph[pos][i];
    if(next!=from){
      dfs(next,pos);
    }
  }

  *itr=stack;
  return;
}

Measured memory_bytes: 27908
n = int(input())
list_x = list(map(int, input().split()))
sub_list = sorted(list_x)

a = sub_list[n // 2]
b = sub_list[n // 2 - 1]

for one_x in list_x:
  if one_x <= b:
    print(a)
  else:
    print(b)

Measured memory_bytes: 25472
#include <bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
#define pb(s) push_back(s)
#define inf 0x3f3f3f3f
#define mn 100010
typedef long long ll;
using namespace std;

int ans[1010][1010]={0};
int main()
{
    int h,w,a,b,i,j;
    scanf("%d%d%d%d",&h,&w,&a,&b);
    for (i=1;i<=h-b;i++)
    for (j=1;j<=w-a;j++)
        ans[i][j]=1;
    for (i=h-b+1;i<=h;i++)
    for (j=w-a+1;j<=w;j++)
        ans[i][j]=1;
    for (i=1;i<=h;i++)
    {
        for (j=1;j<=w;j++)
        printf("%d",ans[i][j]);
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 5120
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    VI cnt(4);
    REP(i,6){
        cnt[in() - 1]++;
    }
    int ma = 0;
    REP(i,4) ma = max(cnt[i], ma);
    cout << (ma < 3 ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  int a[4];
  for (int i = 0; i < 4; i++) a[i] = s[i] - '0';
  string ans;
  for (int i = 0; i < (1 << 3); i++) {
    int sum = a[0];
    ans = s[0];
    for (int j = 0; j < 3; j++) {
      if (i & (1 << j)) {
        sum += a[j + 1];
        ans += '+';
      } else {
        sum -= a[j + 1];
        ans += '-';
      }
      ans += s[j + 1];
    }
    if (sum == 7) break;
  }
  ans += "=7";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  cin >> n;
  vi a(n);
  REP(i,n) cin >> a.at(i),a.at(i)--;
  cout << accumulate(ALL(a),0) << endl;
}



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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	string a, b;
	cin >> a >> b;
	if(a.size() > b.size()){
		puts("GREATER");
	}else if(a.size() < b.size()){
		puts("LESS");
	}else{
		if(a > b){
			puts("GREATER");
		}else if(a < b){
			puts("LESS");
		}else{
			puts("EQUAL");
		}
	}

	
	return 0;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++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 irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  vector<ll> h(n);
  rep(i,n) cin>>h[i];
  
  ll l=0, r=1e10;
  while((r-l)>1){
    ll m=(r+l)/2;
    
    bool ok=true;
    ll cnt=0;
    rep(i,n){
      ll rem=h[i]-b*m;
      if(rem<=0) continue;
      cnt+=(rem+(a-b)-1)/(a-b);
      if(cnt>m){
        ok=false;
        break;
      }
    }
    if(ok) r=m;
    else l=m;
  }
  cout<<r<<endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    int ans = 0;
    for(int i=0; i<N; i++) for(int j=0; j<i; j++) for(int k=0; k<j; k++){
        if(A[i] != A[j] && A[j] != A[k] && A[i] < A[j]+A[k]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> S(N);
  for(int i = 0;i < N; i++){
    cin >> S.at(i);
  }
  vector<int> Cost(N);
  Cost.at(0) = 0;
  Cost.at(1) = abs(S.at(1) - S.at(0));
  for(int k = 2;k < N;k++){
    if(Cost.at(k - 1) + abs(S.at(k- 1) - S.at(k)) < Cost.at(k - 2) + abs(S.at(k - 2) - S.at(k))){
      Cost.at(k) = Cost.at(k - 1) + abs(S.at(k - 1) - S.at(k));
    }
    else{
      Cost.at(k) = Cost.at(k - 2) + abs(S.at(k - 2) - S.at(k));
    }
  }
  cout << Cost.at(N - 1) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
    string s1;
    cin >> s1;
    string s2 = "ABC";
    if (s1.compare(s2) == 0) {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
// 26
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &os, pair<A, B> &p) {
  return os << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  rep(i, (int)v.size()) os << setw(7) << left << v[i];
  return os << endl;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &os, map<A, B> &m) {
  for (auto &kv : m) os << kv;
  return os;
}
// 3
void _main(int tc) {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> isWinning(k + 1, -1);
  function<bool(int)> f = [&](int stones) -> bool {
    if (stones == 0) return 0;
    if (isWinning[stones] != -1) return isWinning[stones];
    for (int& x : a) {
      if (stones - x >= 0 && !f(stones - x)) {
        isWinning[stones] = 1;
      }
    }
    if (isWinning[stones] == -1) isWinning[stones] = 0;
    return isWinning[stones];
  };


  cout << (f(k) ? "First" : "Second") << endl;

  // vector<bool> isWinning(k + 1);
  // rep(stones, k + 1) {
  //   for (int &x : a) {
  //     if (stones - x >= 0 && !isWinning[stones - x]) isWinning[stones] = true;
  //   }
  // }
  // cout << (isWinning[k] ? "First" : "Second") << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq1 = priority_queue<T>;
template<typename T> using pq2 = priority_queue<T,vector<T>,greater<T>>;




ll rec(ll n){
    
    if(n==1) return 1;
    else return rec(n/2)*2+1;
    
}


int main()
{
    ll H;
    cin >> H;
    out(rec(H));
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A){
  ll odd = 0;
  for (int i = 0; i < N; i++) {
    if(A[i] % 2 == 1)odd++;
  }
  cout << (odd%2 == 0 &&( ((N-odd)+(odd/2))%2 == 0 || (N-odd)%2 == 0 || odd%2 == 0 ) ? YES : NO) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
}



Measured memory_bytes: 1024
from collections import deque
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    u,v=list(map(int,input().split()))
    g[u-1].append(v-1)
S,T=map(int,input().split())
S-=1;T-=1
INF=10**9
U=[[INF]*n for i in range(3)]
U[0][S]=0
que=deque([(0,S)])
while que:
    t,v=que.popleft()
    u=(t+1)%3
    if t==2:
        U[t][v]+=1
    for w in g[v]:
        if U[u][w]!=INF:
            continue
        que.append((u,w))
        U[u][w]=U[t][v]
print(U[0][T] if U[0][T]<INF else -1)


Measured memory_bytes: 62316
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){

  int n,m,a,b,d[1000],i;
  vector <int> dust;
  cin>>n>>m>>a>>b;
  for(i=0;i<n;i++) cin>>d[i];

  for(i=0;d[i]>=a;i++) dust.push_back(d[i]);
  int how=dust.size();
  if(n-how>=m){
    cout<<how<<endl;
    return 0;
  }
  reverse(dust.begin(),dust.end());
  for(i=0;i<dust.size()&&dust[i]<=b;i++) how--;
  cout<<how<<endl;

  return 0;
}

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

#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define print(a) cout << a << "\n"
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

#define MAX 250000



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

  int prim[MAX];
  REP(i, MAX) {
    prim[i] = 1;
  }
  prim[0] = 0;
  prim[1] = 0;
  FOR(i, 2, sqrt(MAX)) {
    if(prim[i] == 0) continue;
    FOR(j, 2, MAX) {
      if(i * j > MAX) {
        break;
      }
      prim[i * j] = 0;
    }
  }

  vector<int> p;
  REP(i, MAX) {
    if(prim[i] == 1) {
      p.push_back(i);
    }
  }

  bool flag = true;
  int N, P;

  while(true){
    int count = 0;
    cin >> N >> P;
    if(N + P == -2) break;

    vector<int> sum;

    REP(i, p.size()) {
      if(count > 15){
        break;
      }
      if(p[i] > N) {
        count++;
        FOR(j, i, P + i) {
          sum.push_back(p[i] + p[j]);
        }
      }
    }

    sort(ALL(sum));

    cout << sum[P - 1] << endl;
  }

  return 0;
}



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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll big_mod(ll base, ll power, ll mod)
{
    if (power == 0) return 1 ;
    ll n = big_mod(base, power / 2, mod) % mod ;
    n = (n * n) % mod ;
    if (power % 2 != 0) {
        n = ((base % mod) * (n % mod)) % mod ;
    }
    return n ;
}

int main()
{
    ll n, ans ;
    cin >> n ;
    ans = big_mod(10, n, MOD) - big_mod(9, n, MOD) - big_mod(9, n, MOD) + big_mod(8, n, MOD) ;
    while (ans <= 0) {
        ans += MOD ;
    }
    ans %= MOD ;

    cout << ans ;


    return 0 ;
}


Measured memory_bytes: 3588
h, w = map(int, input().split())
s = []

for i in range(h):
    a = input()
    s.append([str(m) for m in list(str(a))])

#print(s)
p = 0
for i in range(h):
    for j in range(w):
        if i > 0 and j > 0 and i < h - 1 and j < w - 1:
            if s[i][j] == "#" and s[i - 1][j] == s[i][j - 1] == s[i][j + 1] == s[i + 1][j] == ".":
                print("No")
                p = 1
                break
        if i == 0 and j != 0 and j != w - 1:
            if s[i][j] == "#" and s[i][j - 1] == s[i][j + 1] == s[i + 1][j] == ".":
                print("No")
                p = 1
                break
        if i == h - 1 and j != 0 and j != w - 1:
            if s[i][j] == "#" and s[i - 1][j] == s[i][j - 1] == s[i][j + 1] == ".":
                print("No")
                p = 1
                break
        if j == 0 and i != 0 and i != h - 1:
            if s[i][j] == "#" and s[i - 1][j] == s[i][j + 1] == s[i + 1][j] == ".":
                print("No")
                p = 1
                break
        if j == w - 1 and i != 0 and i != h - 1:
            if s[i][j] == "#" and s[i - 1][j] == s[i][j - 1] == s[i + 1][j] == ".":
                print("No")
                p = 1
                break
        if i == 0 and j == 0:
            if s[i][j] == "#" and s[i][j + 1] == s[i + 1][j] == ".":
                print("No")
                p = 1
                break
        if i == 0 and j == w - 1:
            if s[i][j] == "#" and s[i][j - 1] == s[i + 1][j] == ".":
                print("No")
                p = 1
                break
        if i == h - 1 and j == 0:
            if s[i][j] == "#" and s[i - 1][j] == s[i][j + 1] == ".":
                print("No")
                p = 1
                break
        if i == h - 1 and j == w - 1:
            if s[i][j] == "#" and s[i - 1][j] == s[i][j - 1] == ".":
                print("No")
                p = 1
                break

    else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
        continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
    break  # 外側のforを抜ける

if p == 0:
    print("Yes")

Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  vector<ll> A(N);
  vector<ll> b(N+1);
  rep(i,N){
    cin>>A[i];
    ++b[A[i]];
  }
  
  ll sum=0;
  for(int i=1;i<=N;++i){
    ll c=b[i]*(b[i]-1)/2;
    sum+=c;
  }
  
  vector<ll> ans(N);
  rep(i,N){
    ans[i]=sum-(b[A[i]]-1);
    cout<<ans[i]<<endl;
  }
  
}


Measured memory_bytes: 8832
#include <iostream>
#include <ctype.h>

using namespace std;

int main () {
    char c;
    int alpha[26] = {};
    while (cin >> c) {
        if (isalpha(c)) {
            c = tolower(c);
            alpha[c - 'a']++;
        }
    }

    for (int i = 0; i < 26; i++) cout << (char)(i + 'a') << " : " << alpha[i] << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1010,p=1e9+7;
int inc(int x,int y){x+=y;return x>=p?x-p:x;}
int dec(int x,int y){x-=y;return x<0?x+p:x;}
int mul(int x,int y){return (ll)x*y%p;}
int power(int x,ll y){
	int ans=1;
	for (;y;y>>=1,x=mul(x,x))
		if (y&1) ans=mul(ans,x);
	return ans;
}
int n,m;ll k;
char s[N][N],t[N][N];
struct matrix{
	int a[3][3];
	matrix(){memset(a,0,sizeof a);}
	int *operator [] (const int x){return a[x];}
	void operator *= (const matrix &x){
		static int ans[3][3];
		for (int i=0;i<3;i++)
		for (int j=0;j<3;j++){
			ll calc=0;
			for (int k=0;k<3;k++) calc+=(ll)a[i][k]*x.a[k][j];
			ans[i][j]=calc%p;
		}
		memcpy(a,ans,sizeof a);
	}
}x,ans,I;
matrix power(matrix x,ll y){
	matrix ans=I;
	for (;y;y>>=1,x*=x)
		if (y&1) ans*=x;
	return ans;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&k);
	if (k<=1) return puts("1"),0;
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	int cnt=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
		if (s[i][j]=='#') cnt++;
	bool X=0,Y=0;
	for (int i=1;i<=n;i++)
		if (s[i][1]=='#'&&s[i][m]=='#') X=1;
	for (int i=1;i<=m;i++)
		if (s[1][i]=='#'&&s[n][i]=='#') Y=1;
	if (X&&Y) return puts("1"),0;
	if (!X&&!Y) return printf("%d\n",power(cnt,k-1)),0;
	if (Y){
		for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			t[j][i]=s[i][j];
		swap(n,m);
		memcpy(s,t,sizeof s);
	}
	int border=0,connect=0;
	for (int i=1;i<=n;i++)
		if (s[i][1]=='#'&&s[i][m]=='#') border++;
	for (int i=1;i<=n;i++)
	for (int j=1;j<m;j++)
		if (s[i][j]=='#'&&s[i][j+1]=='#') connect++;
	I[0][0]=I[1][1]=I[2][2]=1;
	x[0][0]=cnt;	x[0][1]=0;			x[0][2]=0;
	x[1][0]=0;		x[1][1]=border;	x[1][2]=connect;
	x[2][0]=0;		x[2][1]=0;			x[2][2]=cnt;
	ans[0][0]=cnt;	ans[0][1]=border;	ans[0][2]=connect;
	ans*=power(x,k-2);
	printf("%d\n",dec(ans[0][0],ans[0][2]));
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

bool compare(string s, string t) {
  if(s.size() > t.size())
    return true;
  else if(s.size() < t.size())
    return false;
  else
    return s > t;
}

int main() {
  string s, t;
  cin >> s >> t;
  int m = s.size();
  int n = t.size();
  if(s == t)
    cout << "EQUAL" << endl;
  else if(compare(s, t))
    cout << "GREATER" << endl;
  else
    cout << "LESS" << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

int main()
{
	int a[4];
	for (int i = 1; i < 4; ++i)
		scanf("%d", a+i);
	sort(a+1, a+4);
	if (a[1] == a[2] && a[2] == 5 && a[3] == 7)
		printf("YES\n");
	else 
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <stack>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
  string word;
  stack<int> S;
  while(cin >> word) {
    if (word == "+") {
      int n = S.top(); S.pop();
      n += S.top(); S.pop();
      S.push(n);
    }
    else if (word == "-") {
      int n = -S.top(); S.pop();
      n += S.top(); S.pop();
      S.push(n);
    }
    else if (word == "*") {
      int n = S.top(); S.pop();
      n *= S.top(); S.pop();
      S.push(n);
    }
    else {
      S.push(atoi(word.c_str()));
    }
  }
  cout << S.top() << endl;
}

Measured memory_bytes: 3140
#include<stdio.h>
int main(void){
   int a[100][100], x, y, i, s, sum = 0, Max = 0;
   for ( y = 0; y < 12; y++ ) {
      for ( x = 0; x < 12; x++ ) {
         a[x][y] = 0;
      }
   }
   while ( scanf("%d,%d,%d", &x, &y, &s) != EOF ) {
      x += 2;
      y += 2;
      a[x][y-1]++;
      a[x-1][y]++;
      a[x][y]++;
      a[x+1][y]++;
      a[x][y+1]++;
      if ( s == 2 || s == 3) {
         a[x-1][y-1]++;
         a[x+1][y-1]++;
         a[x-1][y+1]++;
         a[x+1][y+1]++;
         if ( s == 3 ) {
            a[x][y-2]++;
            a[x-2][y]++;
            a[x+2][y]++;
            a[x][y+2]++;
         }
      }
   }
   for ( y = 2; y < 12; y++ ) {
      for ( x = 2; x < 12; x++ ) {
         if ( a[x][y] == 0 ){
            sum++;
         } else if ( a[x][y] > Max ) {
            Max = a[x][y];
         }
      }
   }
   printf("%d\n%d\n", sum, Max);
   return 0;
}

Measured memory_bytes: 1712
#左右非対称であることが気になる。多分単調増加に対してWAだろう。

n,x = gets.chomp.split(" ").map{|str| str.to_i}
a = gets.chomp.split(" ").map{|str| str.to_i}

sum = 0

if a[0] > x then
	sum += a[0] - x
	a[0] = x
end

for i in 1...n do
	subsum = a[i-1] + a[i]
	if subsum > x then
		eat = subsum - x
		sum += eat
		a[i] -= eat
	end
end

puts sum

Measured memory_bytes: 9604
def main():
    n, m = map(int, input().split())
    ac = [0] * n
    pena = [0] * n
    for i in range(m):
        p = input().split()
        if ac[int(p[0])-1] > 0:
                continue
        elif p[1] == "AC":
            ac[int(p[0])-1] += 1
        else:
            pena[int(p[0])-1] += 1
    for i in range(n):
        if ac[i] == 0:
            pena[i] = 0
    print(sum(ac), sum(pena))

if __name__ == '__main__':
    main()

Measured memory_bytes: 4596
def get_i(i)
  if $s[i] != i
    nums = []
    loop do
      nums << $s[i]
      $s[i] = $s[$s[i]]
      break if $s[i] == $s[$s[i]]
    end
    nums.each {|j| $s[j] = $s[i]}
    $s[i]
  else
    i
  end
end

n, q = gets.split.map(&:to_i)
$s = (0...n).to_a

q.times do
  com, x, y = gets.split.map(&:to_i)
  xi = get_i(x)
  yi = get_i(y)
  case com
  when 0
    $s[xi] = yi if xi != yi
  when 1
    puts xi == yi ? '1' : '0'
  end
end

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

typedef long long ll;
const int maxn=407;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n,c;
int a[maxn],b[maxn];
int dp[407][407]; //children, candy

int ppow(int x,int y)
{
    if (y==0) return 1;
    int ret=ppow(x,y/2);
    ret=ret*ret%mod;
    if (y&1) ret=ret*x%mod;
    return ret;
}

int p[407][407];

int32_t main()
{
    IOS
    for (int i=0;i<=400;i++)
    {
        for (int j=1;j<=400;j++) p[i][j]=ppow(j,i);
        for (int j=1;j<=400;j++) p[i][j]=(p[i][j-1]+p[i][j])%mod;
    }
    cin>>n>>c;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++) cin>>b[i];

    dp[0][0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<=c;j++)
        {
            for (int k=0;k<=j;k++)
            {
                dp[i][j]=(dp[i][j]+(p[j-k][b[i]]+mod-p[j-k][a[i]-1])*dp[i-1][k]%mod)%mod;
            }
        }
    }
    cout<<dp[n][c]<<endl;
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
 
const ll M=1e5+5,LG=19,SM=4000+5,inf=1e9+1;
ll mod=1e9+7;
 
typedef basic_string<int> bsll;

bool isavl[M];
bsll avals;

bsll tajz(ll &x)
{
    bsll r1,r2;
    ll cnt=0;
    for (int p:avals)
    {
        //if (p*p>x) break;
        if (x%p!=0) continue;
        cnt=0;
        while (x%p==0)
        {
            x/=p;
            cnt++;
        }
        if (cnt%3==1) r1+=p;
        else if (cnt%3==2) r2+=p;
    }
    if (x!=1)
    {
        ll y=sqrt(x);
        if (y*y==x)
        {
            r2+=y;
        }
        else
        {
            r1+=x;
        }
    }
    x=1;
    r1+=-1;
    r1+=r2;
    return r1;
}

ll n;
ll res;

bsll swp(bsll a)
{
    ll x=-1;
    bsll r1,r2;
    For(i,0,inf)
    {
        if (a[i]==-1)
            break;
        x=i;
        r1+=a[i];
    }
    x+=2;
    For(i,x,SZ(a))
    {
        r2+=a[i];
    }
    r2+=-1;
    r2+=r1;
    return r2;
}

bsll ar[M];
ll ted[M];

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    For(i,2,M/10)
    {
        if (isavl[i]) continue;
        avals+=i;
        for (ll j=2*i;j<M;j+=i)
            isavl[j]=1;
    }
    bool hv1=0;
    For(i,0,n)
    {
        ll x;
        cin >> x;
        ar[i]=tajz(x);
        if (x==1 && SZ(ar[i])==1) hv1=1;
        if (x!=1) res++,i--,n--;
        /*for (ll f:ar[i])
            cout << f << ' ';
        ER(x);//*/       
    }   
    if (n==0)
    {
        cout << res+hv1;
        return 0;
    }
    sort(ar,ar+n);
    For(i,0,n)
    {
        if (i!=0 && ar[i]==ar[i-1])
            continue;
        ll x=i;
        while (x<n && ar[i]==ar[x]) x++;
        ted[i]=x-i;
    }
    For(i,0,n)
    {
        if (i!=0 && ar[i]==ar[i-1]) continue;
        bsll bb=swp(ar[i]);
        ll x=LB(ar,n,bb);
        //cout << i << ' ' << x << " ... ";
        if (x==n || ar[x]!=bb)
            res+=ted[i];
        else
            if (x>i) res+=max(ted[i],ted[x]);
    }   
    cout << res+hv1;
}

Measured memory_bytes: 8704
// 解き直し.
// ABC 131解説.
// https://img.atcoder.jp/abc131/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 1e5 + 1;
// const int MAX_V = 8;
using LL = long long;
int cX[MAX_V], cY[MAX_V];  // 各頂点X, Y ごとに, 連結成分番号を保存.
LL cVX[MAX_V], cVY[MAX_V]; // 各連結成分 の X, Y の 頂点数を保存.
vector<int> X[MAX_V], Y[MAX_V];

// 深さ優先探索(depth-first search).
// https://ja.wikipedia.org/wiki/深さ優先探索
// @param x: 探索開始の頂点X番号.
// @param l: 連結成分番号(※1以上).
// @return : 特に無し.
void dfs(int x, int l){

    // 1. 終了条件設定.
    // -> 連結成分番号が設定済みであれば, 終了.
    if(cX[x] > 0) return;
    
    // 2. 頂点 X について, 連結成分情報 を 設定.
    cX[x] = l, cVX[l]++;
    
    // 3. 頂点 X に, 隣接する 頂点 Y を 探索.
    for(auto &y : X[x]){
        
        if(cY[y] > 0) continue;
        // 3-1. 頂点 Y に, 連結成分 l を設定し, 連結成分のカウンターを +1 更新.
        cY[y] = l, cVY[l]++;
        
        // 3-2. 頂点 Y に, 隣接する 頂点 X を 探索(再帰処理).
        for(auto &nx : Y[y]){
            if(cX[nx] > 0) continue;
            dfs(nx, l);
        }
    }
}

int main() {

    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);

    // 以下, 解説通り.
    // 2. グラフ作成.
    for(int i = 0; i < N; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        // u -> v
        X[u].push_back(v);
        // v -> u
        Y[v].push_back(u);
    }
    
    // グラフ情報確認.
    // for(int i = 1; i < MAX_V; i++){
    //     if(X[i].size() > 0) for(auto &p : X[i]) printf("%d %d\n", i, p);
    // }
    
    // 3. 連結成分に分解.
    int c = 0;
    for(int i = 1; i < MAX_V; i++) if(X[i].size() > 0 && cX[i] == 0) c++, dfs(i, c);
    
    // グラフ連結情報確認.
    // for(int i = 1; i < MAX_V; i++){
    //     printf("cX[%d], cY[%d] = [%d, %d]\n", i, i, cX[i], cY[i]);
    //     printf("cVX[%d], cVY[%d] = [%lld, %lld]\n", i, i, cVX[i], cVY[i]);
    // }
    
    // 4. 後処理.
    // ※各連結成分 の X, Y の 頂点数(cVX, cVY) について, long long で 計算しないと, 
    // テストケース(09.txt, 10.txt, 11.txt, 15.txt) で, WA となるので要注意.
    LL ans = 0;
    for(int i = 1; i < MAX_V; i++){
        if(cVX[i] == 0 || cVY[i] == 0) break;
        ans += cVX[i] * cVY[i];
    }
    ans -= N; // 連結済 の 辺数 を 減算.
    printf("%lld\n", ans);
    return 0;

}

Measured memory_bytes: 12288
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)

int main(){
	string x;
	cin >> x;
	int b = 0;
	int ans = x.length();
	REP(i, (int)x.length()){
		if(x[i]=='S'){
			b++;
		}else{
			b--;
			if(b >= 0){
				ans -= 2;
			}else{
				b = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
//abc138_a.cpp
//Sun Aug 18 20:46:36 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a;
	cin >> a;
	string s;
	cin >> s;

	if (a>=3200){
		cout << s << endl;
	}else {
		cout << "red" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> c(10, vector<int>(10, 0));

void floyd()
{
    for (int k = 0; k <= 9; k++) {
        for (int i = 0; i <= 9; i++) {
            for (int j = 0; j <= 9; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
}

int main(int argc, const char * argv[]) {
    int H, W; cin >> H >> W;
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            int inp; cin >> inp;
            c[i][j] = inp;
        }
    }
    
    floyd();
    
    int sum = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            int inp; cin >> inp;
            if(inp == -1 || inp == 1) {
                sum += 0;
            } else {
                sum += c[inp][1];
            }
        }
    }
    
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}
#define MAX 2000001
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ll X, Y;
  COMinit();
  cin >> X >> Y;
  ll S = X + Y;
  if (S % 3 > 0) {
    cout << 0 << endl;
  } else {
    ll dan = S / 3;
    cout << COM(dan, X - dan) << endl;
  }
  return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  int count,ans=0;
  for(int i=1;i<=n;i+=2){
    count=0;
    for(int j=1;j<=i;j++){
      if(i%j==0) count++;
    }
    if(count==8) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;

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

    int n; cin >> n;
    vector<int> a(n);
    int max_a = 0;
    rep(i, n){
        cin >> a[i];
        max_a = max(max_a, a[i]);
    }
    vector<int> d(max_a + 1, 0);
    rep(i, max_a + 1) d[i] = i;

    for(int i = 2; i * i <= max_a; i++){
        if(d[i] < i) continue;
        for(int j = i * i; j <= max_a; j += i){
            if(d[j] == j) d[j] = i;
        }
    }
    vector<int> count(max_a + 1, 0);
    rep(i, n){
        int x = a[i];
        while(x > 1){
            count[d[x]]++;
            int cur = d[x];
            while(x % cur == 0){
                x /= cur;
            }
        }
    }
    //rep(i, max_a + 1) cout << count[i] << endl;
    bool flag = true;
    rep(i, max_a + 1){
        if(count[i] >= 2) flag = false;
    }
    int GCD = a[0];
    rep(i, n) GCD = gcd(a[i], GCD);

    if(flag) cout << "pairwise coprime" << endl;
    else if(GCD == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

Measured memory_bytes: 15052
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans = sum(B)
    for i in range(N-1):
        if A[i+1] == A[i]+1:
            ans += C[A[i]-1]

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>

using namespace std;


int main(){
  int n;
  cin >> n;
  long long sum = 0;
  vector<long long> p(n);
  for(int i = 0; i < n ;i++){
    cin >> p[i];
    sum += p[i];
  }
  sort(p.begin(), p.end());
  for(int i = 0; i < n ;i++){
    if(sum%10==0){
      if(p[i] % 10 != 0){
        sum -= p[i];
      }
    }else{
      cout << sum << endl;
      return 0;
    }
  }

  cout << (sum%10 == 0 ? 0 : sum)  << endl;
  return 0;
} 


Measured memory_bytes: 256