akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

/*
    Squirrel Merchant
*/

int main() {
    ll n;
    cin >> n;
    ll a[3];
    ll b[3];
    cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] >> b[2];
    // 前処理
    rep(i,3){
        if(a[i] == b[i]){
            a[i] = 1001001001001001;
            b[i] = 1001001001001001;
        }
    }
    if(a[0] >= b[0]){
        swap(a[0], a[1]);
        swap(b[0], b[1]);
        swap(a[1], a[2]);
        swap(b[1], b[2]);
    }
    if(a[0] >= b[0]){
        swap(a[0], a[1]);
        swap(b[0], b[1]);
    }
    if(a[1] >= b[1]){
        swap(a[1], a[2]);
        swap(b[1], b[2]);
    }

    int A = 0;
    rep(i,3){
        if(a[i] < b[i])A++;
    }

    ll ans = n;

    if(A == 0){
        rep(ii, 5001){
            rep(jj, 5001){
                ll i = ii;
                ll j = jj;
                if(i * b[0] + j * b[1] > n)continue;
                ll tmp = n - i * b[0] - j * b[1];
                ll k = tmp / b[2];
                tmp -= k * b[2];
                tmp += i * a[0] + j * a[1] + k * a[2];
                ans = max(ans, tmp);
            }
        }
    }

    if(A == 1){
        ll i = n / a[0];
        n -= a[0] * i;
        n += b[0] * i;
        rep(ii, n+1){
            ll tmp = n;
            ll i = ii;
            if(i * b[1] > tmp)continue;
            tmp -= i * b[1];
            ll j = tmp / b[2];
            tmp -= b[2] * j;
            tmp += i * a[1] + j * a[2];
            ans = max(ans, tmp);
        }
    }

    if(A == 2){
        ll mid = n;
        rep(ii, n+1){
            ll tmp = n;
            ll i = ii;
            if(i * a[0] > tmp)continue;
            tmp -= i * a[0];
            ll j = tmp / a[1];
            tmp -= a[1] * j;
            tmp += i * b[0] + j * b[1];
            mid = max(mid, tmp);
        }
        ll i = mid / b[2];
        mid -= i * b[2];
        mid += i * a[2];
        ans = mid;
    }

    if(A == 3){
        rep(ii, 5001){
            rep(jj, 5001){
                ll i = ii;
                ll j = jj;
                if(i * a[0] + j * a[1] > n)continue;
                ll tmp = n - i * a[0] - j * a[1];
                ll k = tmp / a[2];
                tmp -= k * a[2];
                tmp += i * b[0] + j * b[1] + k * b[2];
                ans = max(ans, tmp);
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
turn = 'a'
a = input()
b = input()
c = input()

for i in range(len(a+b+c)):
    if turn == 'a':
        if len(a) == 0:
            print('A')
            break
        turn = a[0]
        a = a[1:]
    if turn == 'b':
        if len(b) == 0:
            print('B')
            break
        turn = b[0]
        b = b[1:]
    if turn == 'c':
        if len(c) == 0:
            print('C')
            break
        turn = c[0]
        c = c[1:]


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){	
	ll n, i;
	cin >> n;
	vector<ll>v(n);
	for(i = 0; i < n; i++)cin >> v[i];
	sort(all(v));
	vector<ll>ans;
	for(i = n - 1; i >= 1; i--){
		if(v[i] == v[i - 1]){
			ans.pb(v[i]);
			i--;
		}
	}
	ans.pb(0),ans.pb(0);
	cout << ans[0] * ans[1] << nl;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input1.txt","r",stdin);
//    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
	// cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,4) {
        if(s[i] == '+') {
            ans++;
        } else {
            ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
// verified (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A)
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
using cost_t=int;

struct Edge {
    int from, to;
    cost_t cost;
    Edge(int from, int to, cost_t cost) : from(from), to(to), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

cost_t mst(Graph& g){
    int n=g.size();
    cost_t res=0;
    using Item=pair<cost_t,int>;
    priority_queue<Item,vector<Item>,greater<>> que;
    que.push(Item(0,0));
    vector<int> used(n);
    while(!que.empty()){
        auto tmp=que.top(); que.pop();
        int v=tmp.second;
        if(used[v]) continue;
        used[v]=true;
        res+=tmp.first;
        for(auto &e:g[v]){
            if(!used[e.to]) que.push(Item(e.cost,e.to));
        }
    }
    return res;
}
int main(){
    int V,E;
    cin>>V>>E;
    Graph g(V);
    for(int i=0;i<E;i++){
        int s,t,w;
        cin>>s>>t>>w;
        g[s].push_back(Edge(s,t,w));
        g[t].push_back(Edge(t,s,w));
    }
    cout<<mst(g)<<endl;
    return 0;
}




Measured memory_bytes: 8020
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

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

  ll ans = 1000000000000000;

  FOR(i, 1, 1000001) {
    if (n % i == 0) {
      ans = min(i + (n / i) - 2, ans);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
    int ans=0,i,c=1,sum=0;
    for(i=0;i<3;i++)
    {
    	if(s[i]=='R' && c==1)
    	{
    	sum++;
    	ans++;
    }
    	if(s[i]=='S' && i!=2)
    	{
    	c=0;
    	ans=0;
    }
    	if(s[i]=='R' && c==0)
    	{
    	c=1;
    	sum++;
    	ans++;
    }
	}
	if(sum==1)
	ans=1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3620
package main

import "fmt"

func main() {
	// Code for C - 100 to 105
	var X int
	fmt.Scanf("%d", &X)

	var flag int = 0
	for i := 0; 100*i <= X; i++ {
		for j := 0; 100*i+101*j <= X; j++ {
			for k := 0; 100*i+101*j+102*k <= X; k++ {
				for l := 0; 100*i+101*j+102*k+103*l <= X; l++ {
					for m := 0; 100*i+101*j+102*k+103*l+104*m <= X; m++ {
						if (X-(100*i+101*j+102*k+103*l+104*m))%105 == 0 {
							flag = 1
							break
						}
					}
					if flag == 1 {
						break
					}
				}
				if flag == 1 {
					break
				}
			}
			if flag == 1 {
				break
			}
		}
		if flag == 1 {
			break
		}
	}

	if flag == 1 {
		fmt.Println("1")
	} else {
		fmt.Println("0")
	}
}


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

int main(){
    int h,w;
    
    cin >> h >> w;
    vector <vector <int>> m(h,vector <int> (w)),ans(h,vector <int> (w));
    string s,s2;
    rep(i,h){
        cin >> s;
        rep(j,w){
            s2=s[j];
            if(s2=="."){
                m[i][j]=0;
            }
            else{
                m[i][j]=1;
            }
        }
    }


    ans[0][0]=m[0][0];

    rep(i,w-1){
        if(m[0][i+1]==m[0][i]){
            ans[0][i+1]=ans[0][i];
        }
        else{
            if(m[0][i+1]==1 and m[0][i]==0){
                ans[0][i+1]=ans[0][i]+1;
            }
            else{
                 ans[0][i+1]=ans[0][i];
            }
        }
    }

    int x,y;


    rep(j,h-1){
        rep(i,w){
            if(i==0){
                if(m[j+1][0]==m[j][0]){
                    ans[j+1][0]=ans[j][0];
                }
        else{
            if(m[j+1][0]==1 and m[j][0]==0){
                ans[j+1][0]=ans[j][0]+1;
            }
            else{
                ans[j+1][0]=ans[j][0];
            }
        }
            }

            else{
                if(m[j+1][i]==m[j+1][i-1]){
                    x=ans[j+1][i-1];
                }
                else{
            if(m[j+1][i]==1 and m[j+1][i-1]==0){
                x=ans[j+1][i-1]+1;
            }
            else{
                 x=ans[j+1][i-1];
            }
        }

        y=ans[j][i];
        if(m[j+1][i]==1 and m[j][i]==0){
            ++y;
        }
                ans[j+1][i]=min(x,y);
            }
        }
    }

    cout << ans[h-1][w-1] << endl;


    

    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> G(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    deque<int> Q;
    stack<int> s;
    int cnt = 0;
    vector<int> visited(n, 0), num(n);
    s.emplace(0);
    vector<int> dp(n);
    vector<int> par(n);
    while(!s.empty()){
        int a = s.top(); s.pop();
        visited[a]++;
        num[a] = cnt++;
        Q.emplace_front(a);
        for (auto &&i : G[a]) {
            if(!visited[i]){
                s.emplace(i);
                dp[i] = dp[a]+1;
                par[i] = a;
            }
        }
    }
    while(!Q.empty()){
        int a = Q.front(); Q.pop_front();
        for (auto &&b : G[a]){
            if(num[b] > num[a]){
                par[b] = a;
            }
        }
    }
    vector<int> dp2(n);
    ll ans = k;
    for (int i = 1; i < n; ++i) {
        int color = k-(min(dp[i], 2)+dp2[par[i]]);
        dp2[par[i]]++;
        if(color < 0) ans = 0;
        else (ans *= color) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8440
a, b, k = gets.split.map(&:to_i)
smaller, larger = a >= b ? [b, a] : [a, b]
count = 0
smaller.downto(1) do |i|
  if smaller % i == 0 && larger % i == 0
    count += 1
    if count == k
      puts i
      break
    end
  end
end


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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    // dp[i][j][4]
    using P = pair<ll,ll>;
    ll r, c, k;
    cin >> r >> c >> k;

    map<P,ll> v;
    while(k--) {
	ll x, y, z;
	cin >> x >> y >> z;
	x--, y--;
	v[{x,y}] = z;
    }

    vector<vector<vector<ll>>> dp(r+1, vector<vector<ll>>(c+1, vector<ll>(4)));

    auto f = [&](ll i, ll j) {
	if(v.count({i-1,j-1})) return v[{i-1,j-1}];
	return 0ll;
    };

    for(ll i=1; i<=r; i++) {
	for(ll j=1; j<=c; j++) {
	    dp[i][j][0] = max({dp[i][j-1][0], dp[i-1][j][3]});
	    dp[i][j][1] = max({dp[i][j-1][1], dp[i][j-1][0] + f(i, j), dp[i-1][j][3] + f(i, j)});
	    dp[i][j][2] = max({dp[i][j-1][2], dp[i][j-1][1] + f(i, j), dp[i-1][j][3] + f(i, j)});
	    dp[i][j][3] = max({dp[i][j-1][3], dp[i][j-1][2] + f(i, j), dp[i-1][j][3] + f(i, j)});

	    dp[i][j][1] = max(dp[i][j][1], dp[i][j][0]);
	    dp[i][j][2] = max(dp[i][j][2], dp[i][j][1]);
	    dp[i][j][3] = max(dp[i][j][3], dp[i][j][2]);
	}
    }
    cout << dp[r][c][3] << endl;
}

Measured memory_bytes: 649188
import math
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        for k in range(j,n+1):
            if(i==j and j==k and i==k):ans+=math.gcd(math.gcd(i,j),k)
            elif(i!=j and j!=k and i!=k):ans+=math.gcd(math.gcd(i,j),k)*6
            else:ans+=math.gcd(math.gcd(i,j),k)*3
print(ans)


Measured memory_bytes: 9196
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,v,g,books[11][2010],n_books[11] = {0},all[2][11][2010],mem,sum,dp[11][2010] = {0};
    scanf("%d%d",&n,&k);
    for(int i = 0; i < n; i++)
    {
        scanf("%d%d",&v,&g);
        books[g][n_books[g]] = v;
        n_books[g]++;
    }
    for(int i = 1; i < 11; i++)sort(books[i],books[i] + n_books[i]);
    for(int i = 1; i < 11; i++)
    {
        mem = 0;
        sum = 0;
        for(int j = n_books[i] - 1; j >= 0; j--)
        {
            sum = sum + books[i][j];
            all[0][i][mem] = n_books[i] - j;//sassuu
            all[1][i][mem] = sum + all[0][i][mem] * (all[0][i][mem] - 1);//urine
            mem++;
        }
    }
    /*for(int i = 1; i < 11; i++)
    {
        for(int j = 0; j < n_books[i]; j++)
        {
            printf("%3d",all[1][i][j]);
        }
        printf("\n");
    }*/
    for(int i = 1; i < 11; i++)
    {
        for(int j = 0; j < n; j++)
        {
            dp[i][j] = dp[i - 1][j];
            for(int l = 1; l <= n_books[i] && j - l >= 0; l++)
            {
                dp[i][j] = max(dp[i][j],dp[i - 1][j - l] + all[1][i][l - 1]);
            }
        }
    }
    /*for(int i = 1; i < 11; i++)
    {
        for(int j = 0; j < n; j++)
        {
            printf("%3d",dp[i][j]);
        }
        printf("\n");
    }*/
    printf("%d\n",dp[10][k]);
}

Measured memory_bytes: 2932
N,K = map(int,input().split())
p = list(map(int,input().split()))

p2 = [(i+1)/2 for i in p]

ans = sum(p2[:K])
tmp = ans
idx = 0
while idx<N-K:
    tmp += p2[idx+K]
    tmp -= p2[idx]
    ans = max(ans,tmp)
    idx += 1

print(ans)
    

Measured memory_bytes: 77448
var
	n,mi,ma,i,a:Longint;
	cnt:array[1..99]of Longint;
	f:Boolean;
begin
	read(n);
	mi:=n;
	for i:=1 to n do begin
		read(a);
		if mi>a then mi:=a;
		if ma<a then ma:=a;
		inc(cnt[a]);
	end;
	f:=true;
	if cnt[mi]-ma mod 2<>1 then f:=false;
	for i:=mi+1 to ma do begin
		if cnt[i]<2 then f:=false;
	end;
	if f and(mi*2>=ma)then writeln('Possible')else writeln('Impossible');
end.

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int vv[4][3][10];
	int b, f, r, v, n;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				vv[i][j][k] = 0;
			}
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		vv[b - 1][f - 1][r - 1] += v;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << " "<<vv[i][j][k];
				if(k==9) cout<< endl;
			}
		}
		if (i != 3) {
			for (int p = 0; p < 20; p++)cout << "#";
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll m[123];

int main(){
    ll N=ii();
    ll K=ii();
    REP(i,0,K){
        ll D=ii();
        REP(j,0,D){
            ll a=ii();
            m[a]=1;
        }
    }
    ll ret=N;
    REP(i,0,123){
        ret-=m[i];
    }
    oie(ret);

    return 0;
}


Measured memory_bytes: 3628
N,M,C = map(int,input().split())
Bs = list(map(int,input().split()))
As_list = []
cnt = 0
for i in range(N):
    As = list(map(int,input().split()))
    sm = 0
    for j in range(M):
        sm += As[j]*Bs[j]
    if sm + C > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    vi b(n),c(n);
    copy(all(a),b.begin());
    copy(all(a),c.begin());
    if(prev_permutation(all(b))){
        rep(i,n)cout<<(i?" ":"")<<b[i];
        cout<<endl;
    }
    rep(i,n)cout<<(i?" ":"")<<a[i];
    cout<<endl;
    if(next_permutation(all(c))){
        rep(i,n)cout<<(i?" ":"")<<c[i];
        cout<<endl;
    }
    return 0;
}


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

bool check(int n)
{
    for (int i = 0; i * i <= n; i++)
    {
        if (i * i == n)
            return true;
    }
    return false;
}

int main()
{
    string a, b;
    cin >> a >> b;
    int x = atoi((a + b).c_str());
    if (check(x))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

int n, a[300005];
lint l[300005], r[300005];

int main(){
	scanf("%d",&n);
	for(int i=1; i<=3*n; i++) scanf("%d",&a[i]);
	priority_queue<int, vector<int>, greater<int> > pq;
	priority_queue<int> pq2;
	lint sum = 0;
	for(int i=1; i<=3*n; i++){
		sum += a[i];
		pq.push(a[i]);
		while(pq.size() > n){
			sum -= pq.top();
			pq.pop();
		}
		l[i] = sum;
	}
	sum = 0;
	for(int i=3*n; i; i--){
		sum += a[i];
		pq2.push(a[i]);
		while(pq2.size() > n){
			sum -= pq2.top();
			pq2.pop();
		}
		r[i] = sum;
	}
	lint ret = -1e18;
	for(int i=n; i<=2*n; i++){
		ret = max(ret, l[i] - r[i+1]);
	}
	cout << ret << endl;
}


Measured memory_bytes: 7032
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Contest.D
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int h = cin.NextInt();
			int w = cin.NextInt();
			int n = cin.NextInt();
			var a = cin.ArrayInt(n);
			var list = new List<int>();
            for (int i = 0; i < n; i++)
            {
				list.AddRange(Enumerable.Repeat(i + 1, a[i]));
            }
            for (int i = 0; i < h; i++)
            {
				var l = list.GetRange(i * w, w);
				if (i % 2 == 1) l.Reverse();
				Console.WriteLine(string.Join(" ", l));
            }

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13280
#include<iostream>
#include<set>
#include<utility>
#include<cstring>

typedef std::pair<int, int> P;

bool used[3][9][9];
int n;
char puzzle[9][9];

// k: 0 -> ver, 1 -> hor, 2 -> sq
int f( int k, int i, int j )
{
	switch( k )
	{
		case 0:
			return j;
		case 1:
			return i;
		case 2:
			return i / 3 * 3 + j / 3;
	}
}

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

	bool fst = true;
	while( n-- )
	{
		memset( used, false, sizeof( used ) );
		
		std::set<int> s[3][9];
		
		for( int i = 0; i != 9; ++i )
		{
			for( int j = 0; j != 9; ++j )
			{
				std::cin >> puzzle[i][j];

				int t = puzzle[i][j] - '1';
				int fl = 0;
				for( int k = 0; k != 3; ++k )
					fl |= (used[k][f(k,i,j)][t] << k);

				for( int k = 0; k != 3; ++k )
					if( fl >> k & 1 )
						s[k][f(k, i, j)].insert( t );
					else
						used[k][f(k,i,j)][t] = true;
			}
		}

		if( !fst )
			std::cout << std::endl;

		for( int i = 0; i != 9; ++i )
		{
			for( int j = 0; j != 9; ++j )
			{
				bool fl = false;
				for( int k = 0; k != 3; ++k )
					fl |= s[k][f(k, i, j)].count( puzzle[i][j] - '1' );

				std::cout << ( fl ? '*' : ' ' ) << puzzle[i][j]; 
			}
			
			std::cout << std::endl;
		}

		fst = false;
	}

	return 0;
}

Measured memory_bytes: 1188
n=int(input())
if(1<=n<=9):
  print(n)
elif(10<=n<=99):
  print(9)
elif(100<=n<=999):
  print(9+n-99)
elif(1000<=n<=9999):
  print(909)
elif(10000<=n<=99999):
  print(909+n-9999)
else:
  print(90909)

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

namespace Atcoder177
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            long[] A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            long wa = 0;
            long[] was = new long[N];

            long ans = 0;

            foreach (long a in A)
            {
                wa += a;
            }
            

            long mod = 1000000007;

            for (long i = 0; i < N - 1; i++)
            {
                if (i == 0)
                {
                    wa -= A[0];
                    was[i] = wa % mod;
                    continue;
                }
                
                wa -= A[i];
                was[i] = wa % mod;
            }

            for (long i = 0; i < N - 1; i++)
            {
                ans += (A[i] * was[i]) % mod;
                ans %= mod;
            }

            Console.WriteLine(ans % mod);
        }
    }
}


Measured memory_bytes: 48984
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int a[32769];
int n;
int main()
{
        rep(i,182)
        {
                rep2(j,i,182)
                {
                        if(i*i+j*j>=32769)break;
                        rep2(k,j,182)
                        {
                                if(i*i+j*j+k*k>=32769)break;
                                rep2(l,k,182)
                                {
                                        if(i*i+j*j+k*k+l*l>=32769)break;
                                        a[i*i+j*j+k*k+l*l]++;
 
                                }
                        }
                }
        }
        while(1)
        {
                cin>>n;
                if(n==0)break;
                cout<<a[n]<<endl;
        }
        return 0;
}

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

int main(){
    string s;
    int x,y;
    cin>>s>>x>>y;
    vector<int>a,b;
    bool isx=1;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='F'){
            c++;
        }else{
            if(isx){
                a.push_back(c);
            }else{
                b.push_back(c);
            }
            c=0;
            isx=(!isx);
        }
    }
    if(s[s.size()-1]=='F'){
        if(isx){
            a.push_back(c);
        }else{
            b.push_back(c);
        }
    }
    const int N=8005;
    bool dpa[N]={1},dpb[N]={1};
    int suma=0,sumb=0;
    for(int i=1;i<a.size();i++){
        suma+=a[i];
        for(int j=suma;j-a[i]>=0;j--){
            if(dpa[j-a[i]])dpa[j]=1;
        }
    }
    for(int i=0;i<b.size();i++){
        sumb+=b[i];
        for(int j=sumb;j-b[i]>=0;j--){
            if(dpb[j-b[i]])dpb[j]=1;
        }
    }
    x=abs(x-a[0]);
    y=abs(y);
    if((suma>=x&&sumb>=y)&&(((suma-x)%2==0&&dpa[(suma-x)/2]))&&(((sumb-y)%2==0&&dpb[(sumb-y)/2]))){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  
  // 逆元計算
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

//二項係数(Combination)
struct Combination {
  vector<mint> fact, ifact;
  Combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int x, y;
  cin >> x >> y;

  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
  } else {
    int n = (2 * y - x) / 3;
    int m = (2 * x - y) / 3;
    if (n < 0 || m < 0) {
      cout << 0 << endl;
    } else {
      Combination c(n + m);
      mint ans = c(n + m, n);
      cout << ans.x << endl;
    }
  }
 
  return 0;
}


Measured memory_bytes: 13800
#include<bits/stdc++.h>
#define    ll           long long
#define    ln           endl
#define    gap          " "
#define    in           cin
#define    out          cout
#define    yes          cout<<"YES"<<endl
#define    no           cout<<"NO"<<endl
#define    new_line     out<<endl;
#define    f(i,x,n)     for(int i=x;i<n;i++)
#define    fr(i,x,n)    for(int i=x;i>n;i--)
#define    vi           vector<int>
#define    vll          vector<ll>
using namespace std;



int main()
{
        ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
ll int a,b,c,d;
cin>>a>>b>>c>>d;
ll int x,y;
vector<ll int>vc;
vc.push_back(a*c);
vc.push_back(a*d);
vc.push_back(b*c);
vc.push_back(b*d);
sort(vc.begin(),vc.end());
cout<<vc[3];

}



Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

vector<int> v[30];

signed main(){
	string S,T;
	cin>>S>>T;
	int N=S.size(),M=T.size();
	set<char> U;
	REP(i,N){
		U.insert(S[i]);
	}
	REP(i,M){
		if(U.find(T[i])==U.end()){
			cout<<-1<<endl;
			return 0;
		}
	}
	REP(i,N){
		v[S[i]-'a'].push_back(i);
	}
	int p=-1;
	int ans=0;
	REP(i,M){
		int c=T[i]-'a';
		int pos=distance(v[c].begin(),lower_bound(v[c].begin(),v[c].end(),p+1));
		if(pos==v[c].size()){
			ans++;
			p=v[c][0];
		}
		else{
			p=v[c][pos];
		}
	}
	cout<<ans*N+p+1<<endl;
	return 0;
}


Measured memory_bytes: 1724
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs():
    ans = [0]*n
    dist = [-1]*n
    que = deque([0])
    dist[0] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in g[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            ans[w] = v + 1
            que.append(w)
    return ans[1:]

n, m = MAP()
g = [[] for i in range(n)]
for i in range(m):
    A, B =MAP()
    g[A-1].append(B-1)
    g[B-1].append(A-1)

print("Yes")
for x in bfs():
    print(x)

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  int mini = sum;
  int sum_sum = 0;
  for(int i = 0; i < n; i++){
    sum_sum +=a[i];
    mini = min(mini,abs(sum_sum - (sum - sum_sum)));
  }
  cout << mini << endl;
}

Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

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

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;


int32_t main()
{

   IOS
   int x,y,z;
   cin>>x>>y>>z;
   cout<<z<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 768
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
int main() {
	double N, x[11];
	string u[11];
	cin >> N;
	double ans = 0;

	for (int i = 1; i <= N; i++) {
		cin >> x[i] >> u[i];
		if (u[i] == "JPY")ans += x[i];
		else ans += x[i] * 380000;
	}

	cout << ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int k,x;

    cin>>k>>x;
    FOR(i,x-k+1,x+k-1){
        if(i!=x+k-1){
            cout<<i<<" ";
        }else{
            cout<<i<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int r0, w0, c, r;
bool d(int x) {
    double y = ((double)r0 + x * r) / w0;
    if(y >= c) return true;
    else return false;
}
 
signed main() {
    while(cin >> r0 >> w0 >> c >> r, r0 || w0 || c || r) {
        int mi = -1, ma = INF;
        while(ma - mi > 1) {
            int mid = (ma + mi) / 2;
            if(d(mid)) ma = mid;
            else mi = mid;
        }
        cout << ma << endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int H,W;
string s[55];
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={-1,1,-1,0,1,-1,0,1};
char cnt(int x,int y){
	int c = 0;
	for(int d=0;d<8;d++){
		int nx = x+dx[d];
		int ny = y+dy[d];
		if(nx<0||ny<0||nx>=H||ny>=W)continue;
		if(s[nx][ny]=='#')c++;
	}
	return (char)('0'+c);
}
int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++)cin >> s[i];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(s[i][j]=='#')printf("#");
			else printf("%c",cnt(i,j));
		}
		printf("\n");
	}
	return 0;
}

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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 2 * N;

int n, m;
int a[N];
LL s[N];
map<int, int> cnt;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i ++ ) s[i] = s[i - 1] + a[i];
	
	cnt[0] = 1;
	LL res = 0;
	for (int i = 1; i <= n; i ++ ) res += cnt[s[i] % m] ++ ;
	printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char **argv)
{
    unsigned int N, C, K;
    std::cin >> N >> C >> K;
    std::vector<int> T(N);
    for(unsigned int i = 0; i < N; i++){
        std::cin >> T.at(i);
    }
    std::sort(T.begin(), T.end());

    unsigned int k = 0;
    int buses = 0;
    while(k < T.size()){
        buses++;
        int bus_start = T.at(k) + K;
        int c = 0;
        for(unsigned int i = 0; i < C && k+i < T.size(); i++){
            if(T.at(k+i) <= bus_start) c++;
        }
        k += c;
    }
    std::cout << buses << std::endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m;
	cin >> n >> m;
	cout << ((n - m) * 100 + m * 1900) * (1 << m) << endl;
	return 0;
}

Measured memory_bytes: 256
# D - Friend Suggestions
class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), self.find(y)
        if x == y:
            return

        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]


def main():
    N, M, K, *ABCD = map(int, open(0).read().split())
    AB, CD = ABCD[:2 * M], ABCD[2 * M:]
    relationships = UnionFind(N, 1)
    friends, blocked = [0] * (N + 1), [0] * (N + 1)
    for a, b in zip(*[iter(AB)] * 2):
        relationships.unite(a, b)
        friends[a] += 1
        friends[b] += 1
    for c, d in zip(*[iter(CD)] * 2):
        if relationships.is_same(c, d):
            blocked[c] += 1
            blocked[d] += 1
    ans = [relationships.get_size(i) - friends[i] - blocked[i] - 1 for i in range(1, N + 1)]
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 47344
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define si set<int>
#define y1 yy
#define debug if(printDebug)
using namespace std;
bool printDebug=false;
int main(){
    //printDebug=true;
    /*freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);//*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);//*/
    int k;
    cin >> k;
    int pos=1;
    int v=7;
    int ans=-1;
    if(k%2!=0){
	    while(pos<=k){
	    	if(v%k!=0){
	    		v=((v*10)+7)%k;
	    		pos++;
	    	}
	    	else{
	    		ans=pos;
	    		break;
	    	}
	    }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;
         
        public class Main { //クラス名はMain
            public static void main(String[] args) {
                //コード
              Scanner sc = new Scanner(System.in);
              int n1 = sc.nextInt();
              int seigen = 0;
              //値の代入
              if (Math.abs(n1) % 2 == 0) {
                //偶数
                seigen = (n1 / 2);
              }
                else {
                //奇数
                  seigen = (n1 / 2);
                  seigen++;
              }
              
              int count = 0;
              for(int i=1;i<seigen;i++) {
                if (n1 - i > 0){
           			count++;
          			}
          		else{
            		// 処理なし
          			}
              }
              System.out.println(count);
        }
        }

Measured memory_bytes: 22996
#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 lcm(int a,int b){return a/gcd(a, b)*b;}

int n, lean = 0;
ll a[100005], ans = 1LL;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    ll p = a[0];
    rep(i, 1, n) {
        if (lean == 0) {
            if (p > a[i]) lean = -1;
            if (p < a[i]) lean = 1;
        } else if ((lean == 1 && p > a[i]) || (lean == -1 && p < a[i])) {
            lean = 0;
            ans++;
        }
        p = a[i];
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
while True:
    n=int(input())
    if n==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    A=max(a)
    B=min(a)
    C=sum(a)
    D=len(a)
    E=C-A-B
    F=D-2
    print(E//F)


Measured memory_bytes: 5596
N, X = map(int, input().split())

if X * 2 == N:
    ans = 3 * X
else:
    ans = 0
    if X * 2 < N:
        LL = N - X
        SS = X
    else:
        LL = X
        SS = N - X
    while True:
        div, mod = divmod(LL, SS)
        ans += 3 * SS * div
        if mod == 0:
            break
        LL = SS
        SS = mod

print(ans)

Measured memory_bytes: 3064
n,a,b=map(int,input().split())
aa=list(map(int,input().split()))
ans=0
for i in range(n-1):
	if (aa[i+1]-aa[i])*a>b:
		ans+=b
	else:
		ans+=(aa[i+1]-aa[i])*a
print(ans)

Measured memory_bytes: 14252
// AtCoder
    // Beginner Contest 137
    // B. Alternating Current
    #include <bits/stdc++.h>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <string> 
    #include <vector>
    #include <numeric>
    using namespace std;
    typedef long long int ll;
    typedef long double ld;
    typedef pair<ll, int> PLI;
    typedef pair<int, int> PII;
    const ll mxsize = 1e5 + 15;
    const ll linf = 1e9;
    const long double inf = 10000000000.0;
    #define fastIO                                                                 \
      ios_base::sync_with_stdio(false);                                            \
      cin.tie(NULL);                                                               \
      cout.tie(NULL);
    const ll mod = 1e9 + 7;
    /******************************************* IMPORTANT CODE SNIPPETS ************************************************/ 
    
    ll pow(ll x, ll n) {
      if (n == 0)
        return 1ll;
      ll temp;
      temp = pow(x, n / 2);
      if (n % 2 == 0)
        return temp * temp;
      else
        return x * temp * temp;
    }

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

    int sum_digit(int val) {
      if (val < 0)
        return -1;
      if (val == 0)
        return 0;
      int ans = 0;
      while (val > 0) {
        ans = ans + val % 10;
        val = val / 10;
      }
      return ans;
    }

    ll count_div(ll l, ll r, ll val) {
      if (l % val == 0)
        return (((r / val) - (l / val)) + 1);
      else
        return ((r / val) - (l / val));
    }

    int powmod(int x, int y, int m) {
      int res = 1;
      // x = x % mod;
      while (y > 0) {
        if (y & 1)
          res = (res * x) % m;
        cout << res << endl;
        y = y / 2;
        cout << x << endl;
        x = (x * x) % m;
      }
      // cout << res << endl;
      return res;
    }
    /******************************************** CODE STARTS FROM HERE *************************************************/ 
    
    int main()
    {
      int k , x;
      cin >> k >> x;
      vector < int > ans;
      for(int i = x - k + 1 ; i <= x + k - 1 ; i++)
      ans.push_back(i);
      for(int i = 0 ; i < ans.size() ; i++)
      cout << ans[i] << " ";
    }

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

int main(){
  long n, k;
  cin >> n >> k;
  long r=n/k;
  if(k%2==1){
    cout << r*r*r;
  }
  else {
    long t=2*n/k-n/k;
    cout << r*r*r+t*t*t;
  }
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    bool isgood = true;
    if (s[0] == s[1]) isgood = false;
    if (s[1] == s[2]) isgood = false;
    if (s[2] == s[3]) isgood = false;
    if (isgood) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void) {
	int n,x,l,cnt=0,y=0,i;
	cin >> n >> x;
	for (i = 1;i <= n;i++) {
		cin >> l;
		y += l;
		if (y > x)
			break;
	}
	cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll a,b,n; cin >> a >> b >> n;
    cout << (a*min(n,b-1))/b << endl;
    return 0;
}


Measured memory_bytes: 3604