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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

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

int T[10000];
int DPL[10000][5005], DPR[10000][5005];

int main() {
  int N,K;
  scanf("%d%d", &N, &K);
  REP(i,N) scanf("%d", &T[i]);
  DPL[0][0] = 1;
  REP(i,N-1)REP(j,5005)if(DPL[i][j]) {
    DPL[i+1][j] = 1;
    DPL[i+1][min(5000,j+T[i])] = 1;
  }
  DPR[N-1][0] = 1;
  FORD(i,N,1) REP(j,5005) if (DPR[i][j]) {
    DPR[i-1][j] = 1;
    DPR[i-1][min(5000,j+T[i])] = 1;
  }

  int result = 0;
  REP(i,N) {
    if (T[i] >= K) continue;

    FOR(j,1,5005) DPR[i][j] += DPR[i][j-1];
    int A = K - T[i], B = K - 1;

    // printf("%d %d %d\n", i, A, B);
    // REP(j,K+1) printf("%d %d %d %d\n", i, j, DPL[i][j], DPR[i][j]);
    bool necessary = false;
    FOR(j,A,B+1) if (DPL[i][j]) necessary = true;
    REP(l,A) if (DPL[i][l]) {
      if (DPR[i][B-l] > DPR[i][A-l-1]) {
        necessary = true;
      }
    }
    if (!necessary) ++result;
  }

  printf("%d\n", result);
}


Measured memory_bytes: 198912
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <climits>
using namespace std;


int main(){
    long long a, b;
    cin >> a >> b;
    cout << 98 << ' ' << 99 << endl;
    a--, b--;
    for(int i = 0; i < 49; ++i){
        for(int j = 0; j < 99; ++j){
            if(!(i % 2) || !(j % 2) || !b){
                cout << '.';
            }
            else{
                cout << '#';
                b--;
            }
        }
        cout <<endl;
    }

    for(int i = 0; i < 49; ++i){
        for(int j = 0; j < 99; ++j){
            if(!(i % 2) || !(j % 2) || !a){
                cout << '#';
            }
            else{
                cout << '.';
                a--;
            }
        }
        cout <<endl;
    }
    
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second
ll dp[1001][20001]; 

int main(){
    ll h,n;
    cin >> h >> n;
    ll a[n] = {},b[n] = {};
    rep(i,0,n){
        cin >> a[i] >> b[i];
    }

    
    rep(i,0,n){
        rep(j,1,20001){
            dp[i][j] = LINF;
        }
    }

    rep(i,0,n){
        rep(j,0,20001){
            if(a[i] <= j) dp[i+1][j] = min(dp[i+1][j-a[i]] + b[i], dp[i][j]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    
    ll ans = LINF;
    rep(i,h,20001){
        ans = min(ans,dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 160060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1000010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll x, y;
    cin >> x >> y;

    if((x+y)%3 != 0) {
        out(0);
        re0;
    }

    ll m = (x+y)/3;
    if(x < m || 2*m < x) {
        out(0);
        re0;
    }

    init();

    out(Comb(m, x-m));    
    re0;
}

Measured memory_bytes: 23680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] monsterArr = new int[n+1];
		int[] heroArr = new int[n];
		
		for(int i = 0; i < n+1;i++) {
			monsterArr[i] = sc.nextInt();
		}
		for(int i = 0; i < n;i++) {
			heroArr[i] = sc.nextInt();
		}
		
		sc.close();
		
		long ans = 0;
		for(int i = 0; i < n; i++) {
			int numOfMonster = monsterArr[i];
			int capableBeat = heroArr[i];
			if(numOfMonster >= capableBeat) {
				ans += capableBeat;
			}else {
				capableBeat -= numOfMonster;
				ans += numOfMonster;
				int nextMonster = monsterArr[i+1];
				if(nextMonster >= capableBeat) {
					ans += capableBeat;
					monsterArr[i + 1] -= capableBeat;
				}else {
					ans += nextMonster;
					monsterArr[i + 1] = 0;
				}
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 64604
#include "bits/stdc++.h"
using namespace std;

vector<int> g[101010];
int used[101010];
bool can;

void dfs(int v, int prev, int color) {
        used[v] = color;
        for (auto u : g[v]) if (u != prev) {
                if (used[u] == -1) {
                        dfs(u, v, 1 - color);
                } else if (used[u] != 1 - color) {
                        can = true;
                }
        }
}

int main() {
        int n, m;
        cin >> n >> m;
        for (int i = 0; i < m; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        memset(used, -1, sizeof used);
        dfs(0, -1, 0);
        if (can) {
                long long ans = (long long) n * (n - 1) / 2;
                cout << ans - m << endl;
        } else {
                int black = 0;
                for (int i = 0; i < n; i ++) {
                        black += used[i];
                }
                long long ans = (long long) black * (n - black);
                cout << ans - m << endl;
        }
        return 0;
}



Measured memory_bytes: 7040
using System;
using System.Collections.Generic;
using System.Linq;

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

            int[] l = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();

            List<int> ll = l.Where((x, y) => y % 2 == 0).ToList();

            Console.WriteLine(ll.Sum());






        }
    }
}


Measured memory_bytes: 11476
#include<iostream>

using namespace std;

int main() {
  int a, b;
  string c;
  cin >> a >> b;
  if(a < b) {
    c = '<';
  }
  else if(a > b) {
    c = '>';
  }
  else 
    c = "==";
  cout << "a " << c << " b" << endl;

  return 0;
}



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

int main()
{
	int n;
	cin >> n;
	int sum = 0, top = 0;
	for(auto i = 0; i < n; ++i){
		int p;
		cin >> p;
		sum += p;
		top = max(top, p);
	}
	cout << sum - top / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
def flip(c):
    if c == '0':
        return '1'
    else:
        return '0'

def main():
    S = input()

    # 黒白...
    count1 = 0
    target = '0'
    for s in S:
        if s != target:
            count1 += 1
        target = flip(target)

    # 白黒...
    count2 = 0
    target = '1'
    for s in S:
        if s != target:
            count2 += 1
        target = flip(target)

    print(min(count1, count2))

main()

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String str = br.readLine();

		calc(str);
	}

	public static void calc(String str) {
		String[] result = str.split(" ");

		int num1 = Integer.parseInt(result[0]);
		int num2 = Integer.parseInt(result[1]);

		if (num1 < num2) {
			System.out.println("a < b");
		} else if (num1 > num2) {
			System.out.println("a > b");
		} else if (num1 == num2) {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 24228
X,Y,A,B,C = map(int,input().split())

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
r.sort()

p.reverse()
q.reverse()
r.reverse()

qi = 0
ri = 0

lis = [0]

for i in range(B+C):

    if (qi == Y or qi == B) and ri==C:
        lis.append(float("-inf"))
    elif qi == Y or qi == B:
        lis.append(lis[-1] + r[ri])
        ri += 1
    elif ri == C:
        lis.append(lis[-1] + q[qi])
        qi += 1
    elif q[qi] > r[ri]:
        lis.append(lis[-1] + q[qi])
        qi += 1
    else:
        lis.append(lis[-1] + r[ri])
        ri += 1

#print (lis)
ans = 0

n = 0
for i in range(X+1):

    if i != 0:
        n += p[i-1]

    if len(lis) > X+Y-i:
        ans = max(ans , n + lis[X+Y-i])

print (ans)

    



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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


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

  cout << (n + n*n + n*n*n) << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
#define LN 30

int a[upperlimit+1],b[upperlimit+1];
int temp1[upperlimit+1],temp2[upperlimit+1];
int n;
int query(int i,int j){
    int l,r,mid;
    int ret=0;

    l=1;r=n;
    while(r-l>1){
        mid=(l+r)>>1;
        if(temp2[mid]>=i)r=mid;
        else l=mid;
    }
    while(l<=n && temp2[l]<i)l++;
    ret=(1-l);
    l=1;r=n;
    while(r-l>1){
        mid=(l+r)>>1;
        if(temp2[mid]<=j)l=mid;
        else r=mid;
    }
    while(r>=1 && temp2[r]>j)r--;
    ret+=r;
    // for(l=1;l<=n;l++)if(temp2[l]>=i && temp2[l]<=j)ret++;
    return max(0,ret);
}
int main()
{
    int i,j,k,answer=0,l,r;
    sd(n);
    for(i=1;i<=n;i++)sd(a[i]);
    for(i=1;i<=n;i++)sd(b[i]);


    for(k=0;k<=LN;k++){
        for(i=1;i<=n;i++){
            temp1[i]=(a[i]&((1<<(k+1))-1));
            temp2[i]=(b[i]&((1<<(k+1))-1));
        }
        sort(temp2+1,temp2+n+1);
        ll tot=0;

        for(i=1;i<=n;i++){
            int bit=(temp1[i]>>k);
            if(bit){
                l=0;
                r=(1<<(k+1))-1-temp1[i];
                tot+=query(l,r);
                l=r+1+(1<<k);
                r=(1<<(k+1))-1;
                tot+=query(l,r);
            }
            else{
                l=(1<<k)-temp1[i];
                r=(1<<(k+1))-1-temp1[i];
                tot+=query(l,r);
            }
        }

        if(tot&1)answer|=(1<<k);
    }

    pdn(answer);
    return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int t,x;
    cin>>t>>x;
    printf("%.8lf\n",(double)t/x);
    return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>

using namespace std;
#define int long long
constexpr int mod = 1000000007;

#define LOADVECTOR(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;

struct Box {
	int amount = 1;
	bool red = false;
};

signed main() {
	ios::sync_with_stdio(false);
	LOAD(int, N);
	LOAD(int, M);
	std::vector<int>x(M), y(M);
	std::vector<Box> boxes(N);
	boxes[0].red = true;
	for (int nnn = 0; nnn < M; ++nnn) {
		cin >> x[nnn]; --(x[nnn]);
		cin >> y[nnn]; --(y[nnn]);
	}
	for (int m = 0; m < M; ++m) {
		boxes[y[m]].red |= boxes[x[m]].red;
		boxes[y[m]].amount++;
		boxes[x[m]].amount--;
		if (boxes[x[m]].amount == 0) {
			boxes[x[m]].red = false;
		}
	}
	int res = 0;
	for (int n = 0; n < N; ++n) {
		if (boxes[n].red)++res;
	}
	cout << res << endl;
	return 0;
}
#endif


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define int long long int
#define frwd(i,a,b,j) for(int i=a;i<b;i+=j)
#define rev(i,a,b,j) for(int i=a;i>=b;i-=j)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define tr(container, it) \
for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int > > 
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define INF LLONG_MAX
#define mod 1000000007
using namespace std;
void solve()
{
	int n;
	cin>>n;
	int a[n];
	frwd(i,0,n,1) cin>>a[i];
	vector<int > dp(n+1);
	dp[1]=0;
	dp[2]=abs(a[1]-a[0]);
	frwd(i,3,n+1,1)
	{
		dp[i]=min(dp[i-2]+abs(a[i-1]-a[i-3]),dp[i-1]+abs(a[i-1]-a[i-2]));
	}
	cout<<dp[n];
}
signed main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	int t;
	//cin>>t;
	t=1;	
	while(t--)
	{
		solve();
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = [int(e) for e in input().split()]

def selection_sort(A, N):
    steps = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[minj] > A[j]:
                minj = j
        if i != minj:
            steps += 1
        A[minj], A[i] = A[i], A[minj]

    for e in A[:-1]:
        print(e, end=' ')
    print(A[-1])
    print(steps)
    return A

selection_sort(A, N)


Measured memory_bytes: 5616
N = int(input())
F = [list(map(str,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
INF = 10**12

ans = -INF
for i in range(1,2**10):
    cnt = [0]*N
    res = 0
    bs = format(i,"b")
    bs = bs.zfill(10)
    for j in range(N):
        fs = "".join(F[j])
        for k in range(10):
                cnt[j] += int(fs[k])*int(bs[k])
    for l in range(N):
        res += P[l][cnt[l]]
    if res > ans:
        ans = res
print(ans)

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

int main(){
    int n, t;
    cin >> n >> t;
    vector<pair<int,int>> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(),v.end());
    for(int i = 0; i < n; i++){
        if(v[i].second <= t){
            cout << v[i].first << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int to, T cost) {
        emplace_back(to, cost);
    }

    int size() {
        return n;
    }
};


int main() {

    int N,M;

    cin >> N >> M;

    vi V(3);

    REP(i,3)V[i] = 0;

    bool flag = true;

    REP(i,M){
        int a,b;
        cin >> a >> b;

        if((V[a-1]!=0 && V[a-1] != b) || (N>1 && a == 1 && b == 0)){
          flag = false;
        }
         V[a-1] = b;
    }

    int ans = 0;

    REP(i,N){
       if(N>1 && i == 0 && V[i] == 0){
           ans = 1;
           continue;
       }
       ans = ans * 10 + V[i];
    }


    if(!flag){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
  int n,A[100],mini,count=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  
  for(int i=0;i<n-1;i++){
    mini=i;
    for(int j=i+1;j<n;j++){
      if(A[j]<A[mini])mini=j;
    }
    
    if(i!=mini){
      count++;
      swap(A[i],A[mini]);
    }
  }
  
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<A[i]; 
  }
  cout<<endl<<count<<endl;

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793116
#define mod 1e9+7
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int main() {
  off;
  int t;
  //cin>>t;
  t=1;
  while(t--){  
    int n;
    cin>>n;
    int a[n],c=0,min1=INT_MAX;
    for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<0)
              ++c;
          min1=min(min1,abs(a[i]));
        }
    long long sum=0;
    for(int i=0;i<n;i++)
       sum+=abs(a[i]);
     if(c%2==0)
       {
          cout<<sum<<'\n';
       }
     else
       {
          cout<<sum-2*min1<<'\n';
       }    

  }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main() {
    // your code goes here
    int n;
    cin >> n;
    int arr[n]; 
    for(int i=0; i<n; i++){
        cin >> arr[i];
    }
     
    for(int i=0; i<n-1 ;i++){
            cout << arr[i] << " ";
        }
        cout << arr[n-1] << endl;
     
    for(int i=1; i<=n-1; i++){
        int v = arr[i];
        int j = i-1;
         
        while(j >=0 && arr[j]>v){
            arr[j+1] = arr[j];
            j--;
        }
        arr[j+1] = v;


        for(int i=0; i<n-1 ;i++){
            cout << arr[i] << " ";
        }
        cout << arr[n-1] << endl;
    }
     
     
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

int main() {
	string s;
	int K;
	cin >> s;
	cin >> K;
	
	for(int i=0; i<s.size(); i++) {
		if(s[i] == 'a') {
			continue;
		}
		int diff = 'z' - s[i] + 1; 
		if(diff <= K) {
			K -= diff;
			s[i] = 'a';
		}
		
	}
	int N = s.size();
	s[N-1] = 'a' + ((int)(s[s.size()-1] - 'a') +  K   ) % 26;
	
	
	cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 512
function rl()
   local r = {}
   for word in io.read():gmatch("%S+") do
      table.insert(r, tonumber(word))
   end
   return r
end

function ru()
   return unpack(rl())
end

function pu(x, ...)
   if x then
      io.write(x, ' ')
      return pu(...)
   else
      io.write('\n')
   end
end

H, W, K = ru()
c = {}
for i = 1, H do
   c[i] = {}
   for j = 1, W do
      c[i][j] = io.read(1)
   end
   io.read()
end

function line(i)
   if i > H then
      return col(1)
   else
      local save = {}
      for j = 1, W do
	 save[j] = c[i][j]
	 c[i][j] = 'x'
      end
      local r = line(i + 1)
      for j = 1, W do
	 c[i][j] = save[j]
      end
      return r + line(i + 1)
   end
end

function col(j)
   if j > W then
      local count = 0
      for i = 1, H do
	 for j = 1, W do
	    if c[i][j] == '#' then
	       count = count + 1
	    end
	 end
      end
      return count == K and 1 or 0
   else
      local save = {}
      for i = 1, H do
	 save[i] = c[i][j]
	 c[i][j] = 'x'
      end
      local r = col(j + 1)
      for i = 1, H do
	 c[i][j] = save[i]
      end
      return r + col(j + 1)
   end
end

pu(line(1))


Measured memory_bytes: 2584
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let n = Int(readLine()!)!

    // 自分にとってプラスで相手にとってマイナス
    let dishes = (0..<n).map { i -> (Int, Int) in 
        let ab = readWords { Int($0)! }
        let a = ab[0]
        let b = ab[1]
        return (a, b)
    }.sorted { $0.0 + $0.1 > $1.0 + $1.1 }

    var t = 0
    var a = 0
    for (i, dish) in dishes.enumerated() {
        if i % 2 == 0 {
            t += dish.0
        } else {
            a += dish.1
        }
    }

    print(t - a)
}
main()

Measured memory_bytes: 16964
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };

vector<ll>to[10101010];
vector<ll>ans(1010101);
vector<bool>visited(1010101);

void dfs(ll v, ll pv) {
	visited[v] = true;
	if (v != 0)ans[v] += ans[pv];
	for (auto nv : to[v]) {
		if (visited[nv] == false)dfs(nv, v);
	}
}

//long longしか使わない
int main() {
	ll n, q;
	cin >> n >> q;
	vector<ll>a(n - 1), b(n - 1);
	rep(i, n - 1) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		to[a[i]].push_back(b[i]);
		to[b[i]].push_back(a[i]);
	}
	vector<ll>p(q), x(q);
	rep(i, q) {
		cin >> p[i] >> x[i];
		p[i]--;
		ans[p[i]] += x[i];
	}
	dfs(0, 0);
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int n, b, f, r, v;
    int building[5][4][11] = {};

    cin >> n;
    rep(i, n)
    {
        cin >> b >> f >> r >> v;
        building[b][f][r] += v;
    }
    for (int i = 1; i <= 4; i++)
    {
        for (int j = 1; j <= 3; j++)
        {
            for (int k = 1; k <= 10; k++)
            {
                cout << " ";
                cout << building[i][j][k];
            }
            cout << endl;
        }
        if (i != 4)
        {
            cout << "####################" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3084
N, K = map(int, input().split())
MAX = 10 ** 9 + 7
 
res = 0
 
def calc_sum(l, r):
  return ((l+r) * (r-l+1)) // 2
 
for i in range(K, N+2):
  low = calc_sum(0,i-1)
  high = calc_sum(N-i+1,N)
  res = (res + (high-low+1)) % MAX
 
print(res)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vs = V<string>;
using vd = V<double>; using vvi = V< V<int> >; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ins(S);
  ll ans = 0;
  ll b = 0;
  rep(i , sz(S)){
    if(S[i] == 'B') b++;
    else ans += b;
  }
  out(ans);
}

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

using namespace std;
#define ll long long

const ll MOD = (ll)1e9 + 7LL;
const int MAXN = 1005;

int n, m;
string g[MAXN];
ll dp[MAXN][MAXN];

bool out (int i, int j) { return (i >= n) || (j >= m) || (g[i][j] == '#'); }

ll solve (int i, int j) {

    if (i == n - 1 && j == m - 1) return 1LL;
    if (out (i, j)) return 0LL;

    ll &p = dp[i][j];
    if (p != -1) return p;

    return p = solve (i + 1, j) % MOD + solve (i, j + 1) % MOD ;
}


int main () {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> m;

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

    memset (dp, -1LL, sizeof dp);

    cout << solve (0, 0) % MOD << '\n';


    return 0;
}


Measured memory_bytes: 9344
//B - Collecting Balls (Easy Version) 2017/09/16
#include <iostream>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
using namespace std;

int main(int argc , char *argv[]){
    int n , k , x;
    cin >> n >> k;
    int min=0;
    rep(i, n){
        cin >> x;
        if(abs(0-x)>=abs(x-k)) min+=2*abs(x-k);
        else min+=2*abs(0-x);
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

LL gcd(LL x, LL y)
{
	return (y==0)?x:gcd(y,x%y);
}

int n;
LL a[1048];
LL g,g1;

int main ()
{
	cin>>n;
	int i;
	for (i=1;i<=n;i++) cin>>a[i];
	g=a[1];
	LL ans=a[1];
	for (i=2;i<=n;i++)
	{
		g=gcd(ans,a[i]);
		ans=ans*(a[i]/g);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	int n; cin >> n;
	cout << n * n*n << endl;
	return  0;
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        int count = 0;
        int ans = 0;

        while(ans <= x){
            ans = nbOfPplSit(count, y, z);
            count++;
        }

        System.out.println(count-2);
    }

    int nbOfPplSit(int num, int y, int z){
        return num * y + (num+1)*z;
    }

}

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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  deque<char> dq(ALL(s));
  bool rev = false;
  REP(i,n) {
    int com;
    cin >> com;
    if(com == 1) {
      rev = !rev;
      continue;
    }
    int HeadOrTail;
    cin >> HeadOrTail;
    char c;
    cin >> c;
    if(HeadOrTail == 1) {
      if(rev) dq.push_back(c);
      else dq.push_front(c);
    } else {
      if(rev) dq.push_front(c);
      else dq.push_back(c);
    }
  }
  if(rev) {
    REPR(i,dq.size()-1) cout << dq[i];
  } else {
    REP(i,dq.size()) cout << dq[i];
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 896
n = int(input())
S = [a for a in range(1,14)]
H = [b for b in range(1,14)]
C = [c for c in range(1,14)]
D = [d for d in range(1,14)]
for i in range(n):
    mark,num = input().split()
    if mark == "S":
        S.remove(int(num))
    elif mark == "H":
        H.remove(int(num))
    elif mark == "C":
        C.remove(int(num))
    elif mark == "D":
        D.remove(int(num))
for s in S:
    print("S {}".format(s))
for h in H:
    print("H {}".format(h))
for c in C:
    print("C {}".format(c))
for d in D:
    print("D {}".format(d))


Measured memory_bytes: 5596
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;

void main()
{
  int m = readln.chomp.split.back.to!int;
  string s = readln.chomp;
  int l = 0, r = 1;
  // bool[string] set;
  bool[ulong[2]] set;
  auto hasher = new RollingHash(s);
  foreach (i; 0..m) {
    string v = readln;
    auto f = function(char c, ref int w) {
      if (c == '+') {
        ++w;
      } else {
        --w;
      }
    };
    if (v[0] == 'L') {
      f(v[1], l);
    } else {
      f(v[1], r);
    }
    set[hasher.substr(l, r)] = true;
    // set[s[l..r]] = true;
  }
  writeln = set.length;
}

class RollingHash {
  enum long MOD1 = 1_000_000_007;
  enum long MOD2 = 1_000_000_009;
  enum long B1 = 1_009;
  enum long B2 = 1_007;

  ulong[] b1s, b2s;
  ulong[] array1;
  ulong[] array2;
  this(string s) {
    array1 ~= 0;
    array2 ~= 0;
    b1s ~= 1;
    b2s ~= 1;
    foreach (c; s) {
      array1 ~= ((array1.back + ulong(c)) * B1) % MOD1;
      array2 ~= ((array2.back + ulong(c)) * B2) % MOD2;
      b1s ~= (b1s.back * B1) % MOD1;
      b2s ~= (b2s.back * B2) % MOD2;
    }
  }
  ulong[2] substr(uint l, uint r)
  {
    ulong h1 = (array1[r] - ((b1s[r - l] * array1[l]) % MOD1) + MOD1) % MOD1;
    ulong h2 = (array2[r] - ((b2s[r - l] * array2[l]) % MOD2) + MOD2) % MOD2;
    return [h1, h2];
  }
}

Measured memory_bytes: 42528
# coding: utf-8
# Your code here!

N=int(input())
X=list(map(int,input().split()))
X.sort()

sig=0
for i in range(N):
    sig+=X[i]

sig_2=0
for i in range(N):
    sig_2+=X[i]**2

min=10**10
med=X[0]
while True:
    sum=N*med**2-2*med*sig+sig_2

    if sum<min:
        min=sum
        prev=sum
        med+=1
    else:
        break

print(prev)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5;
struct Element
{
    int u,v,opt;
} p[N+3];
int fa[N+3];
int n,q,c; ll m;

int find(int u) {return fa[u]==u?u:fa[u]=find(fa[u]);}

int main()
{
    scanf("%d%lld%d",&n,&m,&q);
    for(int i=1; i<=n; i++) fa[i] = i;
    for(int i=1; i<=q; i++)
    {
        scanf("%d%d%d",&p[i].u,&p[i].v,&p[i].opt); p[i].u++; p[i].v++;
        if(p[i].opt==0)
        {
            int uu = find(p[i].u),vv = find(p[i].v);
            if(uu!=vv) {fa[uu] = vv;}
        }
    }
    int huan = 0; c = 0;
    for(int i=1; i<=n; i++) {if(i==find(i)) c++;}
    for(int i=1; i<=q; i++){
        if(p[i].opt==1){
            huan++;
            int uu = find(p[i].u),vv = find(p[i].v);
            if(uu==vv) {puts("No"); return 0;}
        }
    }
    ll l = huan?max(3ll,(ll)c):c-1ll,r = 1ll*c*(c-1ll)/2ll;
    if(m-(n-c)>=l && m-(n-c)<=r) {puts("Yes");}
    else {puts("No");}
    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#define ll long long
using namespace std;
const ll N = 1e6 + 5;
int main(){
	int x, a, b;
	cin >> x >> a >> b;
	int dd = x - a;
	cout << dd % b << endl;
}

Measured memory_bytes: 256
bus = "0123456789543210123456789"
rbus = "543210"
for i in xrange(input()):
    s, t = raw_input().split()
    if t<s<'6':
        left = rbus.find(s, 0)
        right = rbus.find(t, left)
        print " ".join(rbus[left:right+1])
    else:
        left = bus.find(s, 0)
        right = bus.find(t, left)
        print " ".join(bus[left:right+1])

Measured memory_bytes: 4216
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
typedef long long ll;
using namespace std;

struct disjoint_sets {
    vector<int> xs;
    disjoint_sets() = default;
    explicit disjoint_sets(size_t n) : xs(n, -1) {}
    bool is_root(int i) { return xs[i] < 0; }
    int find_root(int i) { return is_root(i) ? i : (xs[i] = find_root(xs[i])); }
    int set_size(int i) { return - xs[find_root(i)]; }
    int union_sets(int i, int j) {
        i = find_root(i); j = find_root(j);
        if (i != j) {
            if (set_size(i) < set_size(j)) swap(i,j);
            xs[i] += xs[j];
            xs[j] = i;
        }
        return i;
    }
    bool is_same(int i, int j) { return find_root(i) == find_root(j); }
};

struct query_t {
    int a, b, c;
    bool is_once;
};
bool operator < (query_t const & x, query_t const & y) {
    return make_tuple(- x.c, x.a, x.b) < make_tuple(- y.c, y.a, y.b);
}
int main() {
    int n, queries; cin >> n >> queries;
    priority_queue<query_t> que;
    repeat (i,queries) {
        int a, b, c; cin >> a >> b >> c;
        que.push({ a,  b,      c,    true });
        que.push({ a, (a+1)%n, c+1, false });
        que.push({ b, (b+1)%n, c+2, false });
    }
    ll acc = 0;
    disjoint_sets sets(n);
    vector<bool> used(n);
    while (sets.set_size(0) != n and not que.empty()) {
        query_t q = que.top(); que.pop();
        if (not q.is_once) {
            if (used[q.a]) continue; // without push
            used[q.a] = true;
            que.push({ (q.a+1)%n, (q.b+1)%n, q.c+2 });
        }
        if (not sets.is_same(q.a, q.b)) {
            sets.union_sets(q.a, q.b);
            acc += q.c;
        }
    }
    cout << acc << endl;
    return 0;
}


Measured memory_bytes: 16744
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a, b,c,d, q, w;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	q = a * b, w = c * d;
	if (q > w)
	{
		printf("%d", q);
	}
	else printf("%d", w);
	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include <iostream>

using namespace std;

long long int N, d[101] = {}, ans = 0;
bool flag[101] = {};

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> d[i];
		if (!flag[d[i]])ans++;
		flag[d[i]] = true;
	}
	cout << ans << endl;
	return 0;
}

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

struct Unionfind{
  vector<int> d;
  Unionfind(int n): d(n,-1){}
  int root(int x){
    if(d[x]<0) return x;
    return d[x]=root(d[x]);
  }
  bool unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y) return false;
    if(d[x]>d[y]) swap(x,y);
    d[x]+=d[y];
    d[y]=x;
    return true;
  }
  bool same(int x,int y){return root(x)==root(y);}
  int size(int x){return -d[root(x)];}
};

int deg[100005];
vector<int> to[1000005];

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  Unionfind uf(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  for(int i=0;i<k;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  for(int i=0;i<n;i++){
    int ans=uf.size(i)-1-deg[i];
    for(int u:to[i]){
      if(uf.same(i,u)) ans--;
    }
    printf("%d%c",ans,i==n-1?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 30272
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
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);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    double N;cin >> N;
    rep1(h, 3500) {
        rep1(n, 3500) {
            double k = (N*h*n)/(4*h*n-N*(h+n));
            // if(k>0)cout << k << endl;
            // cout << 4*h*n-N*h-N*n << endl;
            if((k==(int)(k)&&k>0)) {
                cout << h << ' ' << n << ' ' << (int)(k) << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3704
import sys
from collections import deque
from functools import reduce
import copy


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    N = len(nums)
    for i in range(N):
        nums[i] -= (i+1)
    nums.sort()
    total = reduce(lambda x, y: x + y, nums, 0)
    half = N // 2
    sub = nums[half]
    total = reduce(lambda acc, x: acc + abs(x - sub), nums, 0)
    return total


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int A, B, C;
    cin >> A >> B >> C;

    int d = A % B, sum = 0;
    for(int i = 0; i < B; i++)
    {
        sum += d;
        sum %= B;
        if(sum==C){
            puts("YES");
            return 0;
        }
    }
    puts("NO");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int D;
  	cin>>D;
  	if(D==25) cout<<"Christmas"<<endl;
    if(D==24) cout<<"Christmas Eve"<<endl;
    if(D==23) cout<<"Christmas Eve Eve"<<endl;
    if(D==22) cout<<"Christmas Eve Eve Eve"<<endl;
}
  

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
rate = [0]*9
ans = 0

for i in range(n):
    if 1 <= l[i] <= 399:
        rate[0] += 1
    elif 400 <= l[i] <= 799:
        rate[1] += 1
    elif 800 <= l[i] <= 1199:
        rate[2] += 1
    elif 1200 <= l[i] <= 1599:
        rate[3] += 1
    elif 1600 <= l[i] <= 1999:
        rate[4] += 1
    elif 2000 <= l[i] <= 2399:
        rate[5] += 1
    elif 2400 <= l[i] <= 2799:
        rate[6] += 1
    elif 2800 <= l[i] <= 3199:
        rate[7] += 1
    else:
        rate[8] += 1

for i in range(8):
    if rate[i] != 0:
        ans += 1

if ans == 0:
    print("1", rate[8])
elif rate[8] != 0:
    print(ans, ans+rate[8])
else:
    print(ans, ans)

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

int main(){
    int n,k=0;cin>>n;
    for(int i=0;n-4*i>=0;i++){
        if((n-4*i)%7==0){
            k++;
            break;
        }
    }
    if(k==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
	long long unsigned int a, b, r, gcd, lcm, x, y;
	while(cin >> a >> b){
		r = 1; x = a; y = b;
		while(r != 0){
			r = x % y;
			x = y;
			y = r;
		}
		gcd = x;
		lcm = a * b / gcd;

		cout << gcd << ' ' << lcm << endl;
	}
}

Measured memory_bytes: 1152