akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int n, m, q;
int *a, *b, *c, *d;
int x[15];

ll dfs(int i, int k) {
    if (i == n) {
        ll sum = 0;
        for (int j = 0; j < q; j++) {
            if (x[b[j]]-x[a[j]] == c[j])
                sum += d[j];
        }
        return sum;
    }

    ll ans = 0;
    for (int j = k; j <= m; j++) {
        x[i] = j;
        ans = max(dfs(i+1, j), ans);
    }
    return ans;
}

int main() {
    cin >> n >> m >> q;
    a = new int[q], b = new int[q], c = new int[q], d = new int[q];
    for (int i = 0; i < q; i++) {
        int A, B;
        cin >> A >> B >> c[i] >> d[i];
        a[i] = A-1, b[i] = B-1;
    }

    cout << dfs(0, 1) << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int n;
    cin >> n;
    //int dd1,dd2;
    //bool flag =false;

    vi dd1(n),dd2(n);
    rep(i,n){
        cin >> dd1[i] >> dd2[i];
    }

    rep(i,n-2){
        //cout << i <<" " <<i+2<< endl;
        if(dd1[i]== dd2[i] && dd1[i+1] == dd2[i+1] && dd1[i+2] == dd2[i+2]){
            cout << "Yes" << endl;
            return 0; 
        }
    }
    cout << "No" << endl;

    // rep(i,n){
    //     cin >> d1 >> d2;
    //     if(d1 == d2){
    //         cnt++;
    //     }else{
    //         if(cnt >= 3){
    //             flag = true;
    //         }
    //         cnt = 0;
    //     }
    // }

    // if(flag)cout << "Yes" << endl;
    // else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3632
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}


//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll H, N; cin >> H >> N;
	vector<ll> a(N); rep(i, N) cin >> a[i];

	ll sum = 0;
	rep(i, N) sum += a[i];

	if (sum < H) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
string s;
sc2(n,s);
if(n<3200)pr("red");
else pr(s);

	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rep2(i,n) for(int i = 0;i <= (n);i++)

int main(void){
    int a[3][3];
    int n;
    rep(i,3){
        rep(j,3)cin >> a[i][j];
    }
    cin >> n;
    int b[n];
    rep(i,n)cin >> b[i];
    rep(i,n){
        rep(j,3){
            rep(k,3)if(b[i] == a[j][k])a[j][k] = 0;
        }
    }
    bool check = false;
    rep(i,3){
        int c = 0;
        rep(j,3){
            c += a[i][j];
            //cout << a[i][j];
        }
        //cout << endl;
        if(c == 0)check = true;
    }
    rep(i,3){
        int c = 0;
        rep(j,3)c += a[j][i];
        if(c == 0)check = true;
    }
    if(a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0)check = true;
    if(a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0)check = true;
    if(check)cout << "Yes";
    else cout << "No";

}

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

int main(){
    ll N;
    string S;
    cin >> S;
    N = S.size();
    ll cnt = 0;
    ll l = 0;
    ll r = N-1;
    while(l <= r){
        if(S[l] != S[r]){
            if(S[l] == 'x'){
                cnt++;
                l++;

            }else if(S[r] == 'x'){
                cnt++;
                r--;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }else{
            l++;
            r--;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
n = int(input())
A = list(map(int, input().split()))
flag = 1
count = 0

while flag:
    flag = 0
    for i in reversed(range(n-1)):
        if A[i] > A[i+1]:
            a = A[i]
            A[i] = A[i+1]
            A[i+1] = a
            flag = 1
            count += 1
print(' '.join(map(str, A)))
print(count)


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

#define o(output) cout << output << endl
#define priolity_queue pq
#define push p
#define top t

using namespace std;

string s;
int a,b,c,d;
char A,B;
map<char,int> mp;

int main(){
  cin>>a>> b>>c>>d;
  min(b,d)-max(a,c)>=0?o(min(b,d)-max(a,c)):o(0);}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Edge():
    def __init__(self,t,f,r,ca,co):
        self.to = t
        self.fron = f
        self.rev = r
        self.cap = ca
        self.cost = co

class MinCostFlow():
    size = 0
    graph = []

    def __init__(self, s):
        self.size = s
        self.graph = [[] for _ in range(s)]

    def add_edge(self, f, t, ca, co):
        self.graph[f].append(Edge(t, f, len(self.graph[t]), ca, co))
        self.graph[t].append(Edge(f, t, len(self.graph[f])-1, 0, -co))

    def min_path(self, s, t):
        dist = [inf] * self.size
        route = [None] * self.size
        que = collections.deque()
        inq = [False] * self.size
        dist[s] = 0
        que.append(s)
        inq[s] = True
        while que:
            u = que.popleft()
            inq[u] = False
            for e in self.graph[u]:
                if e.cap == 0:
                    continue
                v = e.to
                if dist[v] > dist[u] + e.cost:
                    dist[v] = dist[u] + e.cost
                    route[v] = e
                    if not inq[v]:
                        que.append(v)
                        inq[v] = True

        if dist[t] == inf:
            return inf

        flow = inf
        v = t
        while v != s:
            e = route[v]
            if flow > e.cap:
                flow = e.cap
            v = e.fron

        c = 0
        v = t
        while v != s:
            e = route[v]
            e.cap -= flow
            self.graph[e.to][e.rev].cap += flow
            c += e.cost * flow
            v = e.fron

        return dist[t]

    def calc_min_cost_flow(self, s, t, flow):
        total_cost = 0
        for i in range(flow):
            c = self.min_path(s, t)
            if c == inf:
                return c
            total_cost += c

        return total_cost

def main():
    n = I()
    mcf = MinCostFlow(4096)
    s = 4094
    t = 4095
    for i in range(n):
        mcf.add_edge(s, i, 1, 0)
        mcf.add_edge(i, 4093, 1, 0)

    a = []
    b = []
    ss = set()
    for _ in range(n):
        ai,bi = LI()
        a.append(ai)
        b.append(bi)
        ss.add(ai)
        ss.add(bi)
    d = {}
    for i,v in zip(range(len(ss)), sorted(ss)):
        d[v] = i + n
        mcf.add_edge(i+n, t, 1, 0)
    mcf.add_edge(4093, t, inf, 0)
    for i in range(n):
        mcf.add_edge(i, d[a[i]], 1, -b[i])
        mcf.add_edge(i, d[b[i]], 1, -a[i])
    res = mcf.calc_min_cost_flow(s, t, n)
    return -res


print(main())



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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long

int d[305][305];
int flgs[305][305];

int main(){
    int n; cin>>n;
    rep(i,n) rep(j,n) cin>>d[i][j];

    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(d[i][j]>d[i][k]+d[k][j]){
                    cout<<-1<<endl;
                    return 0;
                }
                if(d[i][j]==d[i][k]+d[k][j] && d[i][k] && d[k][j]) flgs[i][j]=true;
            }
        }
    }
    ll ans=0;
    rep(i,n) for(int j=i+1;j<n;j++){
        if(!flgs[i][j]) ans+=d[i][j];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
argN,argK = list(map(int,input().split()))
argS = input()

if argK == 1:
  ans = argS[0].lower() + argS[1:argN]
elif argK == argN:
  ans = argS[:argK-1] + argS[argK-1].lower()
else:
  ans = argS[:argK-1] + argS[argK-1].lower() + argS[argK:argN]

print(ans)

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

int main(){
    int N;
    cin >> N;
    vector<pair<int,int>> A(N);
    rep(i,N) cin >> A[i].first;
    rep(i,N) A[i].second = i + 1;
    
    sort(A.begin(), A.end());
    rep(i,N) cout << A[i].second << ' ';
    cout << endl;

    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<cstring>

#define ll unsigned long long int

using namespace std;

ll dp[51][51][2501];
ll v[51];

ll a;

ll ways(ll n, ll cnt, ll sum) {

	if(n == 0) {

		if(cnt == 0)return 0;

		if(sum % cnt) return 0;

		if(sum/cnt != a) return 0;

		return 1;
	}

	if(dp[n][cnt][sum] != -1) return dp[n][cnt][sum];

	return dp[n][cnt][sum] = ways(n-1,cnt + 1, sum + v[n-1]) + ways(n-1,cnt, sum);
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll n; cin >> n >> a;
	memset(dp,-1,sizeof(dp));

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

	ways(n,0,0);

	cout << dp[n][0][0] << '\n';

	return 0;
}

Measured memory_bytes: 51580
function Main(input) {
    input = input.split("\n").map(Number);
    var max = 0;
    input.forEach(function(val){
        if(max<(10-((val-0.1)%10))-0.1) max = 10-((val-0.1)%10)-0.1;
    });
    var sum = 0;
        input.forEach(function(val){
            sum += Math.ceil(val/10)*10;
    });
    console.log(sum-max);
}Main(require("fs").readFileSync("/dev/stdin","utf8").trim());


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
int N, ptr, res;
int A[100000];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);

  sort(A, A + N);

  while (ptr < N) {
    int cc = A[ptr], f = 0;
    // 一致するところのみ、数え上げる
    while (ptr < N && A[ptr] == cc) {
      f++;
      ptr++;
    }
    res += f % 2;
  }

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


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  int b=a.at(0)-1 ,cnt=0;
  while(cnt < n){
    cnt++;
    if(b == 1)
      break;
    b = a.at(b)-1;
  }
  if(cnt < n)
    cout << cnt << endl;
  else
    cout << -1 << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b,k,i,p,q;	//4 8 3
	scanf("%d%d%d",&a,&b,&k);
	p = min(a+k-1, b);
	q = max(p+1, b-k+1);
	for(i=a;i<=p;i++)
		printf("%d\n",i);
	for(i=q;i<=b;i++)
		printf("%d\n",i);
	return 0;
}


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

int main(){
    int X;
    cin >> X;
    vector<int> vec(4);
    vec[0] = X / 1000;
    X -= 1000 * vec[0];
    vec[1] = X / 100;
    X -= 100 * vec[1];
    vec[2] = X / 10;
    X -= 10 * vec[2];
    vec[3] = X;
    if  (vec[0] + vec[1] + vec[2] + vec[3] == 7) cout << vec[0] << "+" << vec[1] << "+" << vec[2] << "+" << vec[3] << "=7" << endl;
    else if (vec[0] + vec[1] + vec[2] - vec[3] == 7) cout << vec[0] << "+" << vec[1] << "+" << vec[2] << "-" << vec[3] << "=7" << endl;
    else if (vec[0] + vec[1] - vec[2] + vec[3] == 7) cout << vec[0] << "+" << vec[1] << "-" << vec[2] << "+" << vec[3] << "=7" << endl;
    else if (vec[0] + vec[1] - vec[2] - vec[3] == 7) cout << vec[0] << "+" << vec[1] << "-" << vec[2] << "-" << vec[3] << "=7" << endl;
    else if (vec[0] - vec[1] + vec[2] + vec[3] == 7) cout << vec[0] << "-" << vec[1] << "+" << vec[2] << "+" << vec[3] << "=7" << endl;
    else if (vec[0] - vec[1] + vec[2] - vec[3] == 7) cout << vec[0] << "-" << vec[1] << "+" << vec[2] << "-" << vec[3] << "=7" << endl;
    else if (vec[0] - vec[1] - vec[2] + vec[3] == 7) cout << vec[0] << "-" << vec[1] << "-" << vec[2] << "+" << vec[3] << "=7" << endl;
    else if (vec[0] - vec[1] - vec[2] - vec[3] == 7) cout << vec[0] << "-" << vec[1] << "-" << vec[2] << "-" << vec[3] << "=7" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int sx,sy,tx,ty;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);

	for(int i = 0; i < ty-sy; i++){
		printf("U");
	}
	for(int i = 0; i < tx-sx; i++){

		printf("R");
	}
	for(int i = 0; i < ty-sy; i++){

		printf("D");
	}
	for(int i = 0; i < tx-sx; i++){

		printf("L");
	}
	printf("L");

	for(int i = 0; i < ty-sy+1; i++){

		printf("U");
	}
	for(int i = 0; i < tx-sx+1; i++){

		printf("R");
	}
	printf("D");
	printf("R");

	for(int i = 0; i < ty-sy+1; i++){

		printf("D");
	}
	for(int i = 0; i < tx-sx+1; i++){

		printf("L");
	}
	printf("U\n");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

void no_cost_graphmake(ll E,mat &G){
  rep(i,E){
    ll a,b;
    cin >> a >> b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);//有向なら消す
  }
}
ll W=0,B=0;
bool nibugraph(mat &G,ll n){
  vec A(n,0);
  rep(j,n){
    if(A.at(j)==0){
      A.at(j)=1;
      W++;
      queue<ll> Q;
      Q.push(j);
      while(!Q.empty()){
        ll a=Q.front();
        Q.pop();
        rep(i,(ll)G.at(a).size()){
          if(A.at(G.at(a).at(i))==0){
            A.at(G.at(a).at(i))=3-A.at(a);
            if(A.at(G.at(a).at(i))==1){
              W++;
            }else{
              B++;
            }
            Q.push(G.at(a).at(i));
          }else if(A.at(G.at(a).at(i))==A.at(a)){
            return false;
          }
        }
      }
    }
  }
  return true;
}

int main(){
  ll N,M;
  cin >> N >> M;
  mat G(N);
  no_cost_graphmake(M,G);
  if(nibugraph(G,N)){
    cout << W*B-M << endl;
  }else{
    cout << (N*(N-1))/2-M << endl;
  }
}


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

int main()
{
  int k;
  string s;
  cin >> k;
  cin >> s;
  if (k < s.size())
  {
    cout << s.substr(0, k) << "..."
         << "\n";
  }
  else
  {
    cout << s << "\n";
  }
}

Measured memory_bytes: 3628
def cmb_mod(n, r, mod):
    x, y = 1, 1
    for i in range(r):
        x = (x * (n - i)) % mod
        y = (y * (i + 1)) % mod
    return (x * pow(y, mod - 2, mod)) % mod

n, a, b = map(int, input().split())

mod = 10**9 + 7
all_case = pow(2, n, mod) - 1

print((all_case - cmb_mod(n, a, mod) - cmb_mod(n, b, mod)) % mod)

Measured memory_bytes: 3064
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll n;
	string s;
	cin >> n >> s;


	ll con1 = 0;
	ll con2 = 0;
	ll ans1 = 0;
	ll ans2 = 0;

	REP(i, n) {
		if (s[i] == ')') {
			if (con1 > 0) {
				con1--;
			}
			else {
				ans1++;
			}
		}
		else {
			con1++;
		}
	}
	if (con1 > 0) ans2 = con1;

	cout << string(ans1, '(') + s + string(ans2, ')') << endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << 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 debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	string s;
 	cin >> s;
 	ll ans = 0;
 	for (ll i = 0; i < sz(s); i++) {
 		ll temp = s[i] - '0';
 		ans = (ans + temp) % 9;
 	}   
 	if (ans == 0) {
 		cout << "Yes" << endl;
 	}
 	else {
 		cout << "No" << endl;
 	}
 	return 0;
}

Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();

		if(Math.abs(x-a) < Math.abs(x-b)){
			System.out.println("A");
		}else{
			System.out.println("B");
		}

		scan.close();
	}
}


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

int main() {
  int A, B;
  int SUM = 0, count = 0;
  cin >> A >> B;
  
  if(B != 1){
    while(SUM < (B - A)) {
      SUM += A - 1;
      count++;      
    }
    count++;
  }
  else {
    count =0;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  int four=0,two=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(a%4==0) four++;
    else if(a%2==0) two++;
  }
  bool ans=false;
  if(n%2==0){
    if(four*2+two>=n) ans=true;
  }
  else{
    if(four*2+two>=n-1) ans=true;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;
int main() {
  int n,m,x,bef,aft,ans;cin >> n >> m >> x;
  bef = 0;
  aft = 0;
  vector<int> a(m);
  for(int i=0;i<m;i++){
    cin >> a[i];
  }
  for(int j=0;j<m;j++){
    if(a[j]<x){
      bef++;
    }else{
      aft++;
    }
  }
  ans = min(bef,aft);

  cout << ans << endl;
}  

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

int a, b, c, ans;

int main() {
  cin >> a >> b >> c;
  ans = max({a, b, c});
  if(a == ans)
    cout << "A" << endl;
  else if(b == ans)
    cout << "B" << endl;
  else
    cout << "C" << endl;

  return 0;
}


Measured memory_bytes: 3076
/*
	嘘解法のはずだが、落ちるケースが見つからないコード
*/

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1000000000;

char c[2][101];
int tm;
int vistime[16384];
int backto[16384];
int memo[16384];
bool via[12345];
vector<int> G[2][101];
int tmtable[12345];

int compresspath(int st){
	if(backto[st] != INF && tmtable[backto[st]] != st){
		backto[st] = min(backto[st], compresspath(tmtable[backto[st]]));
	}
	return backto[st];
}

int dfs(int va, int vb, int prvgt, int &retlp){
	int st = va << 7 | vb;

	retlp = backto[st];

	if(vistime[st] == -1){
		vistime[st] = tm;
		tmtable[tm] = st;
		++tm;
		via[vistime[st]] = true;
		
		int ret = 0;
		int loop;
		
		if(c[0][va] == c[1][vb]){
			for(int i = 0; i < G[0][va].size(); ++i){
				for(int j = 0; j < G[1][vb].size(); ++j){
					int a = G[0][va][i], b = G[1][vb][j];
					ret = max(ret, dfs(a, b, vistime[st], loop));
					retlp = min(retlp, loop);
				}
			}
			++ret;
		}
		else{
			for(int i = 0; i < G[0][va].size(); ++i){
				for(int j = 0; j < G[1][vb].size(); ++j){
					int a = G[0][va][i], b = G[1][vb][j];
					ret = max(ret, dfs(a, b, prvgt, loop));
					retlp = min(retlp, loop);
				}
			}

			for(int i = 0; i < G[0][va].size(); ++i){
				ret = max(ret, dfs(G[0][va][i], vb, prvgt, loop));
				retlp = min(retlp, loop);
			}
			
			for(int j = 0; j < G[1][vb].size(); ++j){
				ret = max(ret, dfs(va, G[1][vb][j], prvgt, loop));
				retlp = min(retlp, loop);
			}
		}

		memo[st] = ret;
		backto[st] = retlp;

		via[vistime[st]] = false;
	}
	else{
		if(memo[st] == -1){
			retlp = min(retlp, vistime[st]);
		}

		if(retlp != INF && via[retlp]){
			if(retlp <= prvgt){
				throw 1;
			}
			return 0;
		}
	}

	int t = compresspath(st);
	if(t != INF){
		memo[st] = max(memo[st], memo[tmtable[t]]);
	}

	return memo[st];
}


int main() try{
	fill(vistime, vistime + 16384, -1);
	fill(memo, memo + 16384, -1);
	fill(backto, backto + 16384, INF);

	int n[2], m, a, b, r;
	for(int i = 0; i < 2; ++i){
		scanf("%d%d", &n[i], &m);
		
		for(int j = 1; j <= n[i]; ++j){
			scanf(" %c", &c[i][j]);
		}
		for(int j = 0; j < m; ++j){
			scanf("%d%d", &a, &b);
			G[i][a].push_back(b);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n[0]; ++i){
		for(int j = 1; j <= n[1]; ++j){
			if(c[0][i] == c[1][j] && vistime[i << 7 | j] == -1){
				ans = max(ans, dfs(i, j, tm, r));
			}
		}
	}
	
	printf("%d\n", ans);
}catch(...){
	puts("-1");
}

Measured memory_bytes: 1392
#include<bits/stdc++.h>
using namespace std;
long long a,k;
vector<int>v;
int main()
{
    scanf("%d",&a);
    for(int s=0;s<a;s++)
    {
       	scanf("%d",&k);
        if((s+a+1)%2)v.push_back(k);
        else v.insert(v.begin(),k);
    }
    for(int s=0;s<a;s++)cout<<v[s]<<" ";
}

Measured memory_bytes: 3060
# encoding:utf-8
from functools import reduce

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	n = int(input())
	nums = [int(input()) for _ in range(n)]

	out = reduce(lcm, nums)
	print(out)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3572
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#endif

#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;

int main() {
	fastIO;
	int ar[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	cout << ar[k - 1];
	return 0;
}

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

typedef long long ll;
typedef complex<double> Vec;

ll N;
vector<ll> H;

bool solve() {
  for (ll i = N - 2; i >= 0; --i) {
    if (H[i] > H[i + 1]) {
      --H[i];
      if (H[i] > H[i + 1]) return false;
    }
  }
  return true;
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll h;
    cin >> h;
    H.push_back(h);
  }
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

int main() {
  ll a, b;
  string op;
  cin >> a >> op >>  b;

  if (op == "+") {
    cout << (a + b) << endl;
  } else {
    cout << (a - b) << endl;
  }

}

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

using namespace std;

int main(){
	double a,b,l,co,s,h;
	
	cin>>a>>b>>co;
	
	s=(a*b*sin(co/(180/3.14159265)))/2;
	
	l=a*a+b*b-2*a*b*cos(co/(180/3.14159265));
	l=sqrt(l);
	l+=a+b;
	h=2*s/a;
	
	printf("%8lf\n",s);
	printf("%8lf\n",l);
	printf("%8lf\n",h);
}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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 Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
  int much(int a){
  vector<int> e(a);
  rep(i,a)
  e[i]=find(i);
  sort(all(e)); 
  e.erase(unique(all(e)),e.end());
  return e.size();
  }
};
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<int> d(b),e(b),f(c),g(c);
  rep(i,b)
    cin>>d[i]>>e[i];
  rep(i,c)
    cin>>f[i]>>g[i];
  Union l(a);
  vector<int> n(a,0),m(a,0);
  rep(i,b){
    l.unite(d[i]-1,e[i]-1);
    n[d[i]-1]++;
    n[e[i]-1]++;
    }
  rep(i,c){
  if(l.same(f[i]-1,g[i]-1)){
    m[f[i]-1]++;
    m[g[i]-1]++;
    }
  }
  rep(i,a){
    cout<<l.Size(i)-n[i]-1-m[i]<<' ';
  }
}

Measured memory_bytes: 6272
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

// UnionFind 構造体 for tree
type UnionFind struct {
	par []int
}

/*コンストラクタ*/
func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}
func (u UnionFind) unite(x int, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}

var mod int = 1000000007

type pair struct {
	fi int
	se int
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	m := iScan()
	a := make([]int, m)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = iScan()
		b[i] = iScan()
		a[i]--
		b[i]--
	}
	ans := 0
	for i := 0; i < m; i++ {
		u1 := newUnionFind(n)
		for j := 0; j < m; j++ {
			if i != j {
				u1.unite(a[j], b[j])
			} else {
				continue
			}
		}
		if u1.size(0) != n {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1800
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

template<class T> ll upper(T n,T m){return (n+m-1)/m;};
template<class T> ll rounding(T n){return (long double)n+0.5;};

template<class T> bool inG(T x,T n){return 0<=x && 0<n;}
template<class T> bool outG(T x,T n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int a,b;
  cin>>a>>b;

  cout<<b*qp(b-1,a-1);

  return 0;

}


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

const int MAX = 100000;
int main() {
	static int N, M, X[MAX];
	cin >> N >> M;
	for (int i = 0;i < M;++ i) cin >> X[i];
	sort(X, X+M);
	for (int i = 0;i < M - 1;++ i) X[i] = X[i + 1] - X[i];
	sort(X, X+M-1);
	int ans = 0;
	for (int i = 0;i < M - N;++ i) ans += X[i];
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まずソートすると見通しが良くなる
ある区間をコマが動くときは、必ずその区間の左側にコマを置くとしても最適になるので問題はない
更に、それは貪欲に隣接点との差が小さいほうから選んでも問題はない
よって差についてソートして、小さいほうからmax(0, M-N)個の和が答え
*/

Measured memory_bytes: 640
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <bitset>
#include <cassert>

using namespace std;

const int SIZE = 1 << 17;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0, sign = 1;
    char ch = Advance();
    while (!isdigit(ch) && ch != '-')
        ch = Advance();
    if (ch == '-') {
        sign = -1;
        ch = Advance();
    }
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer * sign;
}

char ReadCh() {
    char ch = Advance();
    while (!isalpha(ch))
        ch = Advance();
    return ch;
}

const int MAXN = 100000;

int dad[1 + MAXN];
int cost[1 + MAXN];
queue<int> Queue;
vector<int> g[1 + MAXN];

void Initialize(int n) {
    for (int i = 1; i <= n; i++)
        dad[i] = i;
}

int FindDad(int node) {
    if (dad[node] == node)
        return node;
    return dad[node] = FindDad(dad[node]);
}

bool Join(int a, int b) {
    a = FindDad(a);
    b = FindDad(b);
    if (a == b)
        return false;
    if (rand() % 2)
        dad[a] = b;
    else
        dad[b] = a;
    return true;
}

vector<int> v;

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    srand(time(0));
    int n = Read(), m = Read();
    for (int i = 1; i <= n; i++)
        cost[i] = Read();
    Initialize(n);
    for (int i = 1; i <= m; i++) {
        int a = Read() + 1, b = Read() + 1;
        Join(a, b);
    }
    for (int i = 1; i <= n; i++)
        g[FindDad(i)].push_back(cost[i]);
    long long answer = 0;
    int components = 0;
    for (int i = 1; i <= n; i++)
        if (dad[i] == i) {
            sort(g[i].begin(), g[i].end());
            components++;
            answer += g[i][0];
            for (int j = 1; j < g[i].size(); j++)
                v.push_back(g[i][j]);
        }
    sort(v.begin(), v.end());
    if (components == 1) {
        printf("0\n");
        return 0;
    }
    int need = 2 * (components - 1) - components;
    if (v.size() < need) {
        printf("Impossible\n");
        return 0;
    }
    for (int i = 0; i < need; i++)
        answer += v[i];
    printf("%lld\n", answer);
    return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <string>

using namespace std;

int main(){
  int a, b;
  string S;
  cin >> a >> b;
  char Sa='0'+a;
  char Sb='0'+b;
  if(a<=b){
    for(int i=0; i<b; i++) cout << Sa;
  }
  else{
    for(int i=0; i<a; i++) cout << Sb;
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

w, a, b = gets.split(' ').map!(&:to_i)

if a > b
  near = b
  far = a
else
  near = a
  far = b
end

ans = if (near + w) >= far
        0
      else
        (far - (near + w)).abs
      end

puts ans


Measured memory_bytes: 1788
n,*a=map(int,open(0))
d={}
for i in a[:n]:d[i]=0
for i in a[n:]:d[i]=1
a,c=1,0
for i in sorted(d):
  if((c>0)!=d[i])*c:a=a*abs(c)%(10**9+7)
  c+=d[i]or-1
print(a)

Measured memory_bytes: 30076
#include <cstdio>
#define max 102
#define f(ss, nn) for(int i = ss;i < nn;i++)
#define p(x) printf("%s\n", x)

struct trip{
	int p;int s;
};

int Sort(struct trip a[max], int left, int mid, int right){
	struct trip l[max/2+2], r[max/2+2];
	int ln = 0, rn = 0;
	for(int i = left;i < mid;i++)l[i-left] = a[i];
	for(int i = mid;i < right;i++)r[i-mid] = a[i];
	for(int i = left;i < right;i++){
		if((l[ln].p >= r[rn].p && ln < mid - left) || rn >= right - mid)a[i] = l[ln++];
		else a[i] = r[rn++];
	}
	return 0;
}

int MergeSort(struct trip a[max], int left, int right){
	if(left + 1 >= right)return 0;
	int mid = (left + right) / 2;
	MergeSort(a, left, mid);
	MergeSort(a, mid, right);
	Sort(a, left, mid, right);
	return 0;
}

int main(){
	int n, m, a[1002][max];
	struct trip b[max];
	//int i;n = 10;
	
	/*f(5, n)p("fuck");
	for(int i = 5;i < n;i++)printf("fuck\n");*/
	
	while(scanf("%d %d", &n, &m) && n != 0 && m != 0){
		for(int i = 0;i < m;i++)b[i].p = 0, b[i].s = i + 1;
		for(int i = 0;i < n;i++)
			for(int j = 0;j < m;j++)scanf("%d", &a[i][j]);
		for(int i = 0;i < m;i++)
			for(int j = 0;j < n;j++)b[i].p += a[j][i];
		//for(int i = 0;i < m;i++)printf("%d ", b[i].s);
		MergeSort(b, 0, m);
		//printf("   m == %d\n", m);
		for(int i = 0;i < m - 1;i++)printf("%d ", b[i].s);
		printf("%d\n", b[m - 1].s);
	}
	return 0;
}

/*
4 6
 1 0 1 0 1 1
1 1 0 1 0 0
 1 1 1 0 0 0
 1 0 1 0 1 0
*/

Measured memory_bytes: 2968
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll a; cin >> a;
    if(a == 1){
        put("Hello World");
    }else{
      cin >> a;
        ll b; cin >>b;
        put(a + b);
    }
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int W = sc.nextInt();
    int H = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
    if (r <= x && x <= W - r && r <= y && y <= H - r) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 26360
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int L = in.nextInt();
            int sumFlavor = n * L + n * (n - 1) / 2;
            int minDf = Integer.MAX_VALUE;
            int ans = -1;
            for (int i = 0; i < n; i++) {
                int curFlavor = L + i;
                int restFlavor = sumFlavor - curFlavor;
                int df = Math.abs(sumFlavor - restFlavor);
                if (df < minDf) {
                    minDf = df;
                    ans = restFlavor;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <set>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(void){
  int a,b;
  cin>>a>>b;
  cout<<((a*b)%2?"Odd":"Even" )<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>


#define MAX 1000000

int main()
{
	int n,a, i,p=2, flag = 1;
	int num_cnt[MAX] = {0,0,1};
	
	for (a = 3; a < MAX; a++)
	{
		for (i = 2; i <= sqrt(a); i++)
		{
			if (a%i == 0)
			{
				flag = 0;
				break;
			}
		}
		if (flag)
		{
			num_cnt[a] = num_cnt[p] + 1;
			p = a;
		}
		else
		{
			flag = 1;
			num_cnt[a] = num_cnt[p];
		}
	}
	
	while (scanf("%d", &n) != EOF)
	{
		if (n >= 1 && n <= 999999)
		{
			printf("%d\n", num_cnt[n]);
		}
	}

	
	return 0;
}


Measured memory_bytes: 4512
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    D = in_nl()
    mod = 998244353

    if D[0] != 0:
        print(0)
        exit()

    for i in range(1, N):
        if D[i] == 0:
            print(0)
            exit()

    count = [0] * N
    for i in range(N):
        count[D[i]] += 1

    zero = N + 1
    non_zero = -1
    for i in range(N):
        if count[i] == 0:
            zero = min(zero, i)
        else:
            non_zero = max(non_zero, i)

    if zero < non_zero:
        print(0)
        exit()

    ans = 1
    for i in range(1, N):
        if count[i] == 0:
            break
        else:
            ans *= count[i - 1] ** count[i]
            ans %= mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18312
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
#define PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	long double a, b, h, m;
	cin >> a>>b>>h>>m;
	long double dm = 360 * m / 60;
	long double dh = 360 * h / 12 + (360 / 12) * (m / 60);
	long double dd = abs(dm - dh);
	//cout << dd << " \n";
	long double ans;
	if (dd != 0){
		if (dd > 180){
			dd = 360 - dd;
		}
		ans= sqrt(a*a + b*b - 2 * a*b*cos(dd * PI / 180.0));
	}
	else ans = abs(a - b);


	cout <<setprecision(24)<< ans;

	//system("pause");
	return 0;
}

Measured memory_bytes: 3612