akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for(int i = (s); i < (e); i++)
#define FOE(i, s, e) for(int i = (s); i <= (e); i++)
#define FOD(i, s, e) for(int i = (s); i >= (e); i--)
#define ll long long

int n, p[20005], A[20005], B[20005];

int main ()
{
	scanf("%d", &n);
	FOR(i, 0, n) scanf("%d", &p[i]);
	
	FOE(i, 1, n) A[i] = i * n - n + 1;
	FOE(i, 1, n) B[i] = A[n - i + 1];
	
	FOE(i, 1, n) A[p[i - 1]] += i - 1;
	FOE(i, 1, n) printf("%d ", A[i]); printf("\n");
	FOE(i, 1, n) printf("%d ", B[i]); printf("\n");
	
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;




int main(void)
{
	pair<int , int> now , input;
	int ans = 0;
	int N , H , W;
	
	cin >> W >> H >> N;
	cin >> now.second >> now.first;

	for (int i = 0; i < N - 1; i++)
	{
		// yを縦とする
		cin >> input.second >> input.first;

		// 両方正の値or両方負の値
		if ((now.first - input.first > 0 && now.second - input.second > 0) ||
			(now.first  - input.first < 0 && now.second - input.second < 0))
		{
			// 斜めに移動できる = 遠いほうと同じ歩数となる (abs : 絶対値⇒距離だから)
			ans += max(abs(now.first - input.first) , abs(now.second - input.second));
		}
		else
		{
			ans += abs(now.first - input.first) + abs(now.second - input.second);
		}
		// 現在値を移動
		now = input;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;

#define m(a, b) memset(a, b, sizeof(a))
#define py(b, a) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & (-x))

const int maxn = 1e5 + 10;
const int inf = 1e9;
typedef long long LL;
typedef pair<int, int> PII;
struct point{
	int x, y;
}num[maxn];
int n, m;
bool cmp(point a, point b){
	if(a.x == b.x) return a.y < b.y;
	else return a.x < b.x;
}
int main(){
	int ans = 0;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m ; i ++)
		scanf("%d %d", &num[i].x, &num[i].y);
	sort(num + 1, num + 1 + m, cmp);
	int pos = 0;
	for(int i = 1; i <= m ; i++){
//		cout << pos << endl;
		if(pos > num[i].y && num[i].x < pos)
			pos = num[i].y;
		else if(num[i].x >= pos){
			pos = num[i].y;
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <numeric>

using namespace std;

int main(void){
 long int A, B;
  cin >> A >> B;
 long int tmp;

 long int a = A;
 long int b = B;
 long int r;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  
  cout << A*B/b << endl;
  
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1), b(n);
    REP(i, n+1) cin >> a[i];
    REP(i, n) cin >> b[i];

    ll ans = 0;

    for(int i = 0; i < n; ++i){
        int tmp = min(a[i], b[i]);
        ans += tmp;
        a[i] -= tmp;
        b[i] -= tmp;
        tmp = min(a[i+1], b[i]);
        ans += tmp;
        a[i+1] -=tmp;
        b[i] -= tmp;
    }

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


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		long min = 1000000, max = -1000000, sum = 0;
		for (int i = 0; i < n; i ++) {
			long a = scanner.nextLong();
			min = Math.min(min, a);
			max = Math.max(max, a);
			sum += a;
		}
		
		scanner.close();
		
		System.out.println(min + " " + max + " " + sum);
	}

}



Measured memory_bytes: 42548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=2005;
const int mod=1e9+7;
int a[max_n];
int b[max_n];
int n,k;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[j]>a[i])b[i]++;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        int x=0;
        for(int j=1;j<i;j++)if(a[j]>a[i])x++;
        int d=b[i];
        ans+=1ll*x*k%mod+1ll*k*(k-1)/2%mod*d%mod;
        ans%=mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a[4][13], n, m, i, j;
	char ch, d;
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			a[i][j] = 0;
		}
	}

	scanf("%d",&n);
	for (int h = 1; h <= n; h++) { //所持しているトランプを出力する
		getchar();
		scanf("%c %d",&ch,&m);
		if (ch == 'S') a[0][m] = 1;
		else if (ch == 'H') a[1][m] = 1;
		else if (ch == 'C') a[2][m] = 1;
		else if (ch == 'D') a[3][m] = 1;
	}
	
	for (j = 1; j <= 13; j++) {
		if (a[0][j] != 1) printf("S %d\n", j);
	}
	for (j = 1; j <= 13; j++) {
		if (a[1][j] != 1) printf("H %d\n", j);
	}
	for (j = 1; j <= 13; j++) {
		if (a[2][j] != 1) printf("C %d\n", j);
	}
	for (j = 1; j <= 13; j++) {
		if (a[3][j] != 1) printf("D %d\n", j);
	}
	return 0;
}


Measured memory_bytes: 2052
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 8/3/2019

*/

#include <bits/stdc++.h>
using namespace std;
#define time cout << "\ntime: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}





int main(void){
	Boost();
	int n;
	cin >>n;
	int M[n][3];
	for(int i=0 ;i<n ;i++)
		for(int j=0 ; j<3 ;j++)
			cin >>M[i][j];

    for(int i=n-2 ; i>=0 ;i--){
    	for(int j=0;j<3 ;j++){
    		int x=M[i][j];
    		for(int k=0 ;k<3 ;k++){
    			if(k==j)
    				continue;
    			M[i][j]=max(M[i+1][k]+x,M[i][j]);
    		}
    	}
    }


    cout<< max({M[0][0],M[0][1],M[0][2]});
   return 0;
}


Measured memory_bytes: 1408
s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']

while len(s) > 0:
    for word in words:
        flg = False

        if s.endswith(word):
            s = s[:(len(s) - len(word))]
            flg = True
            break

    if not flg:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
A,B,K=map(int,input().split())
for i in range(K):
    if i%2==0:
        if A%2==0:
            B+=A//2
            A//=2
        else:
            B+=(A-1)//2
            A=(A-1)//2
    else:
        if B%2==0:
            A+=B//2
            B//=2
        else:
            A+=(B-1)//2
            B=(B-1)//2
print(A,B)           

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,c,d;
    string s,t;

    cin >> a >> b;//>> c >> d;
    //cin >> s >> t;
    cout << (a-1) * (b-1);

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f;

int n,m,k;

int main(){
    n=read();m=read();k=read();
    bool ok=0;
    for(int i=0;i<=n;i++){
    	for(int j=0;j<=m;j++){
    		if(i*m-i*j+(n-i)*j==k)ok=1;
    	}
    }
    if(ok)printf("Yes");else printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};



signed main() {
	char c;
	char bo[6] = "aiueo";
	scanf("%c", &c);
	REP(i, 6) {
		if (c == bo[i]) {
			printf("vowel\n");
			return 0;
		}
	}
	printf("consonant\n");
	return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	int ans = 0;
	rep(i, n){
		if(s[i] == 'A' && i + 2 < n){
			if(s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
		}
	}

	cout << ans;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int byk=0;
  for(int i=0;i<s.length();i++){
 	byk+=(s[i]-'0');
  }
  if(byk%9==0)puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void){
    int n,m;
    cin >> n >> m;
    priority_queue<int> pq;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        pq.push(a);
    }

    for(int i=0;i<m;i++){
        int value = pq.top(); pq.pop();
        pq.push(value/2);
    }

    ll ans = 0;
    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>

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

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

int main() {
  int r;
  cin >> r;
  if(r < 1200) {
    cout << "ABC" << endl;
  } else if(r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] a = new char[h][w];
        for (int i = 0 ; i < h ; i++) {
            a[i] = sc.next().toCharArray();
        }
        for (int i = 0 ; i < w + 2 ; i++) {
            System.out.print('#');
        }
        System.out.print("\n");
        for (int i = 0 ; i < h ; i++) {
            System.out.print('#');
            for (int j = 0 ; j < w ; j++) {
                System.out.print(a[i][j]);
            }
            System.out.print('#');
            System.out.print("\n");
        }
        for (int i = 0 ; i < w + 2 ; i++) {
            System.out.print('#');
        }
        System.out.print("\n");
    }

}

Measured memory_bytes: 23764
N, M = map(int, input().split())

W = [1] * (N + 1)
W[1] = 0
R = [0] * (N + 1)
R[1] = 1
cnt = [1] * (N + 1)

for _ in range(M):
    fr, to = map(int, input().split())
    cnt[fr] -= 1
    cnt[to] += 1

    if R[fr] == 1 and W[fr] >= 1:
        R[to] = 1
        W[to] += 1

    if R[fr] == 1 and W[fr] == 0:
        R[fr] = 0
        R[to] = 1

    if R[fr] == 0 and W[fr] >= 1:
        W[fr] -= 1
        W[to] += 1

    if cnt[fr] == 0:
        W[fr] = 0
        R[fr] = 0

ans = len([0 for r in R if r >= 1])
print(ans)


Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int arr[N] , n , val[N];
vector<int> v;
int main(){
    cin >> n;
    for(int i = 1 ; i <= n ;i++)
        cin >> arr[i];
    for(int i = n ; i >= 1 ; i--){
        int sum = 0;
        for(int j = i ; j <= n ; j+= i)sum += val[j];
        if(sum % 2 != arr[i]){
            v.push_back(i);
            val[i]++;
        }
    }
    cout << v.size() << endl;
    for(int i = 0 ; i < v.size() ; i++)cout << v[i] << " ";
    return 0;
}

Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

template <class T>inline bool chmin(T &a, const T b){
    if(a > b){a = b; return true;}
    return false;
}

template <class T>inline bool chmax(T &a, const T b){
    if(a < b){a = b; return true;}
    return false;
}


int main(){
    int N, W; cin >> N >> W;
    vector<pair<int, int>> a(N);
    rep(i, N){
        int w, v; cin >> w >> v;
        a[i] = make_pair(w, v);
    }
    vector<vector<ll>> dp(N + 1,vector<ll>(W + 1, -1));//i個目を詰めた時のj以下の最大値
    rep(i, W + 1) dp[0][i]  = 0;
    rep(i, N){
        rep(j, W + 1){
            if(j - a[i].first >= 0){
                dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i].first] + a[i].second);
            }else{
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    cout << dp[N][W] << endl;
}

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

int main() {
    int h, w;
    while(1) {
	cin >> h >> w;
	if(h==0 && w==0) {
	    break;
	}
	for(int i=0; i<h; i++) {
	    for(int j=0; j<w; j++) {
		if((i+j) % 2 == 0) {
		    cout << "#";
		} else {
		    cout << ".";
		}
	    }
	    cout << endl;
	}
	cout << endl;
    }
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) (__gcd(a, b))
#define LCM(a, b) ((a)/GCD(a,b)*(b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 450555;
const int M = 1125;

char c[M][M], b[M][M];
void solve() {
    int n,m,k;
    cin >> n >> m >> k;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> c[i][j];
        }
    }

    int ans = 0;
    for (int mask1 = 0; mask1 < (1 << n); mask1++){
        for (int mask2 = 0; mask2 < (1 << m); mask2++){
            for (int i = 0; i < n; i++){
                for (int j = 0; j < m; j++){
                    b[i][j] = c[i][j];
                }
            }
            VI X, Y;
            for (int i = 0; i < n; i++){
                if (mask1 & (1 << i)) X.PB(i);
            }
            for (int i = 0; i < m; i++){
                if (mask2 & (1 << i)) Y.PB(i);
            }
            for (int i : X){
                for (int j = 0; j < m; j++){
                    b[i][j] = 'r';
                }
            }
            for (int j : Y){
                for (int i = 0; i < n; i++){
                    b[i][j] = 'r';
                }
            }
            int z = 0;
            for (int i = 0; i < n; i++){
                for (int j = 0; j < m; j++){
                    if (b[i][j] == '#') z++;
                }
            }
            if (z == k) ans++;
        }
    }

    cout << ans;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

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

int main() {
	int N, K; cin >> N >> K;
	
	int ans = 0, x;
	for( int i = 0; i < N; i++ ){
		cin >> x;
		ans += 2*min(K-x,x);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    ll ans=0;
    cin>>n;
    string s;
    cin>>s;
    ll pre[n+2][4];
    memset(pre,0,sizeof pre);
    rep(i,0,sz(s)){
        if(s[i]=='R'){
            pre[i+1][1]++;
        }
        if(s[i]=='G'){
            pre[i+1][2]++;
        }
        if(s[i]=='B'){
            pre[i+1][3]++;
        }
        rep(j,1,4){
            pre[i+1][j]+=pre[i][j];
        }
    }
    // cout<<pre[n+1][3]<<endl;
    rep(i,0,n){
        rep(j,i+1,n){
            if(s[i]==s[j])continue;
            if(j+j-i<n && s[j+j-i]!=s[i] && s[j+j-i]!=s[j])ans--;
            bool is1=0,is2=0,is3=0;
            if(s[i]=='R' || s[j]=='R') is1 = 1;
            if(s[i]=='G' || s[j]=='G') is2 = 1;
            if(s[i]=='B' || s[j]=='B') is3 = 1;
            if(!is1){
                ans+=pre[n][1]-pre[j+1][1];
            }
            if(!is2){
                ans+=pre[n][2]-pre[j+1][2];
            }
            if(!is3){
                ans+=pre[n][3]-pre[j+1][3];
            }
        }
    }
    cout<<ans<<'\n';
    return 0;   
}   

Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int age = sc.nextInt();
		int money = sc.nextInt();
		
		if(age>=13) {
			System.out.println(money);
			
		}else if(age>=6 && age<=12) {
			System.out.println(money/2);
		}else {
			System.out.println(0);
		}
		
	}
}


Measured memory_bytes: 23124
N,K = map(int,input().split())
lr = list(input())

cnt = 0
for i in range(len(lr)-1):
    if lr[i] == "R":
        if lr[i+1] == "R":
            cnt+=1

for i in range(len(lr)-1,0,-1):
#     print(i)
    if lr[i] == "L":
        if lr[i-1]=="L":
            cnt+= 1
            
cnt += 2*K
print(min(N-1,cnt))

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

int main(){
  int n;ll ans = 0;cin >> n;
  vector<int> a(n);rep(i,n){cin >> a[i];ans += a[i]-1;}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int a,b,t; cin>>a>>b>>t;
    cout<<t/a*b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

const ll MXN=100005;
vector<edge> G[MXN];
vector<bool> B(MXN,false);
vl ans(MXN);

void bfs(ll x,ll d){
  B[x]=true;
  ans[x]=d;
  ll k=G[x].size();
  rep(i,k){
    if(B[G[x][i].to]==false){
      bfs(G[x][i].to,G[x][i].cost+d);
    }
  }
}

  
int main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
  ll N;
  cin >> N;
  rep(i,N-1){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  ll Q,K;
  cin >> Q >> K;
  K--;
  bfs(K,0);
  rep(i,Q){
    ll x,y;
    cin >> x >> y;
    x--;y--;
    cout << ans[x]+ans[y] << endl;
  }
}

Measured memory_bytes: 14336
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    ll n=in();
    vector<ll>d(n);REP(i,n)d[i]=in();sort(ALL(d));
    cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 1152
#include<stdio.h>
int main() {
	int W,H,x,y,r,buff;
	scanf("%d %d %d %d %d", &H, &W, &x,&y,&r);
	if (x - r >= 0 && y - r >= 0 && x + r <= H && y + r <= W)printf("Yes\n");
	else printf("No\n");
}


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

int N, M, A[100], sum;

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    sort(A, A + N);
    puts(A[N-M] * 4 * M >= sum ? "Yes" : "No");
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
      	int k = sc.nextInt();
		
      if(k == 1){
            System.out.println(0);   
      }else{
        	System.out.println(n - k); 
      }
 
 
    }
}

Measured memory_bytes: 35796
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

m1,d1 = inp
m2,d2 = inp
puts (m1 == m2)? 0 : 1



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int ans = n/2;
    if(n%2==0) ans--;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		sc.close();

		StringBuffer sb = new StringBuffer(input);
		String reverse = sb.reverse().toString();

		if (input.equals(reverse)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 22736
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));

	Vec b(n);
	ll l = 0, r = n-1;
	rep(i, n){
		if(i%2){
			b[i] = a[l];
			l++;
		}else{
			b[i] = a[r];
			r--;
		}
	}
	ll ans1 = 0, mini1 = LINF;
	repn(i, n-1){
		mini1 = min(mini1, abs(b[i]-b[i-1]));
		ans1 += abs(b[i]-b[i-1]);
	}
	if(mini1 < abs(b[n-1]-b[0])) ans1 += abs(b[n-1]-b[0])-mini1;
	l = 0, r = n-1;
	rep(i, n){
		if(i%2){
			b[i] = a[r];
			r--;
		}else{
			b[i] = a[l];
			l++;
		}
	}
	ll ans2 = 0, mini2 = LINF;
	repn(i, n-1){
		mini2 = min(mini2, abs(b[i]-b[i-1]));
		ans2 += abs(b[i]-b[i-1]);
	}
	if(mini2 < abs(b[n-1]-b[0])) ans2 += abs(b[n-1]-b[0])-mini2;
	co(max(ans1, ans2));

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)

//小文字=大文字+32

int main() {
	string s;
	cin >> s;
	ll ans=0;
	rep(i, s.size()) {
		ans += ctoi(s[i]);
	
	}
	if (ans % 9 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}



}
	



Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int x,a,b;
  cin >> x >> a >> b;
  cout << (x-a)%b << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = ("0 " + Console.ReadLine()).Split().Select(int.Parse).ToArray();
        for (int i = 1; i <= n; i++)
        {
            Console.Write($"node {i}: key = {a[i]}, ");
            if (i != 1) Console.Write($"parent key = {a[i / 2]}, ");
            if (i * 2 <= n) Console.Write($"left key = {a[i * 2]}, ");
            if (i * 2 + 1 <= n) Console.Write($"right key = {a[i * 2 + 1]}, ");
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 18428
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  S=input()
  T=input()
  if S==T:
    print("No")
    return
  if S in T:
    print("Yes")
    return
  s=list(S)
  t=list(T)
  
  s.sort()
  t.sort(reverse=True)
  if s==t:
    print("No")
    return
  
#  if(len(s)<len(t)):
#    print("Yes")
#    return
  for i in range(min(len(s),len(t))):
    if ord(s[i])>ord(t[i]):
      print("No")
      return
    elif ord(s[i])<ord(t[i]):
      print("Yes")
      return
  print("No")
  return
main()

Measured memory_bytes: 9148
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val inputList = readLine()!!.split(" ").map { it.toInt() }
    //val lcm = inputList.reduce { a, b -> lcm(a, b) }
    //println(lcm)

    val sum = inputList.sum()

    println(sum - N)
}

Measured memory_bytes: 39636
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int N, K;
  int A[200000] = {0};
  int B[200000] = {0};
  cin >> N >> K;
  for (int i = 0; i < N; i++) 
    cin >> A[i];
  sort(A, A+N);
  int j = 0;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == A[i+1])
      count++;
    else {
      B[j] = count + 1;
      count = 0; j++;
    }
  }
  sort(B, B+j);
  int minority = 0;
  for (int i = 0; i < j-K; i++)
    minority += B[i];
  cout << minority << endl;
  return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

using pii = pair<int, int>;

int N;
vector<int> A, B;
vector<pii> C;

signed main() {
  cin >> N;
  A.resize(N);
  B.resize(N);
  rep (i, N) {
    cin >> A[i] >> B[i];
    C.push_back({A[i] + B[i], i});
  }
  sort(all(C));
  reverse(all(C));

  int tSum = 0, aSum = 0;
  rep (i, N) {
    if (i % 2 == 0) {
      tSum += A[C[i].second];
    } else {
      aSum += B[C[i].second];
    }
  }

  cout << tSum - aSum << endl;

  return 0;
}

Measured memory_bytes: 3956
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();

    int h[] = new int[n];

    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    Arrays.sort(h);

    int min = Integer.MAX_VALUE;
    for (int i = 0; i < n - k + 1; i++) {
      min = Math.min(h[i + k - 1] - h[i], min);
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 50636
#![allow(warnings)]
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  // 入力
  let (n, k) = {
    let tmp: Vec<usize> = read_vec();
    (tmp[0], tmp[1])
  };
  let mut p: Vec<f64> = read_vec();

  // p について累積和を計算

  let mut p_ev: Vec<f64> = Vec::new();
  let mut p_ruiseki: Vec<u64> = Vec::new();

  for i in &p {
    p_ev.push((i+1.0)/2.0);
  }

  let mut p_ev_ruiseki : Vec<f64> = Vec::new();

  p_ev_ruiseki.push(0.0);

  for i in 1..p_ev.len()+1 {
    let tmp = p_ev[i-1] + p_ev_ruiseki[i-1];
    p_ev_ruiseki.push(tmp);
  }

  let mut ans = 0.0;
  for i in 0..n-k+1 {
    let tmp = p_ev_ruiseki[i+k] - p_ev_ruiseki[i];
    if tmp > ans { ans = tmp; }
  }
  println!("{}", ans);
}


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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

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

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((b / a) > c)
    {
        cout << c << endl;
    }
    else
    {
        cout << b / a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define REL
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

int n;
ll D, A, ch[200010];
pair <ll, ll> a[200010];

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("threesum.in", "r", stdin);
	//freopen("threesum.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> D >> A;
	for (int i = 0; i < n; i++)
		cin >> a[i].first >> a[i].second;
	sort(a, a + n);
	ll add = 0, ans = 0;
	for (int i = 0; i < n; i++)
	{
		add -= ch[i];
		ll need = a[i].second - add;
		ll vist = (need + A - 1) / A;
		if (need <= 0)
			vist = 0;
		ans += vist;
		int pos = upper_bound(a, a + n, mp(ll(a[i].first + 2 * D), ll(1e9 + 10))) - a;
		ch[pos] += vist * A;
		add += vist * A;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main(){
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    long long int res;
    res = a*c;
    res = max(res, a*d);
    res = max(res, b*c);
    res = max(res, b*d);
    cout << res << endl;
}

Measured memory_bytes: 3632
/*
参考にしたもの

Tにできるものはアーベル群(足し算と引き算ができる代数系)
unitは単位元

Union-Find.cpp
https://qiita.com/drken/items/cce6fc5c579051e64fab
*/

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;

template<typename T>
struct WeightedUnionFind{
    T unit;
    vector<int> par;
    vector<int> es;
    vector<T> ws;
    WeightedUnionFind(int N,T unit) : par(N,-1),es(N,0),ws(N,unit),unit(unit) {}
    
    //初期化
    void init(int N){
        par.assign(N,-1);
        es.assign(N,0);
        ws.assign(N,unit);
    }
    //rootを探す
    int find(int x){
        if(par[x]<0) return x;
        else{
            int r=find(par[x]); //先に圧縮
            ws[x]+=ws[par[x]];
            return par[x]=r;
        } 
    }
    //集合の要素数
    int usize(int x) {return -par[find(x)];}
    //集合の辺の数
    int esize(int x) {return es[find(x)];}
    //xのrootを0にしたときの重さ 最初に圧縮する
    T weight(int x){find(x); return ws[x];}
    //y-x
    //これをやる前にsameで同じ集合にあるかを確認する
    T diff(int x,int y){return weight(y)-weight(x);}

    //weight(y)-weight(x)となるようにmergeする
    //xとyがすでに繋がっていたらfalseを返す weightはそのまま
    bool unite(int x,int y,T w){
        w+=weight(x); w-=weight(y);
        x=find(x);
        y=find(y);
        es[x]++;
        if(x==y) return false;

        if(usize(x)<usize(y)) swap(x,y),w=-w;
        par[x]+=par[y];
        es[x]+=es[y];
        par[y]=x;
        ws[y]=w;
        return true;
    }

    bool same(int x,int y) {return find(x)==find(y);}

};

signed main(void){
    int n,q;
    cin>>n>>q;
    WeightedUnionFind<ll> uf(n,0LL);
    while(q--){
        int a;
        cin>>a;
        if(a==0){
            int x,y,z;
            cin>>x>>y>>z;
            uf.unite(x,y,z);
        }else{
            int x,y;
            cin>>x>>y;
            if(uf.same(x,y)) cout<<uf.diff(x,y)<<endl;
            else cout<<"?"<<endl;
        }
    }
}


Measured memory_bytes: 4432
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll M = 1e9+7;
const ll INF = 1e18;

ll n, ans;
ll a[110000];
priority_queue<P, vector<P>, greater<P> > pq;

int main() {
  cin >> n;

  for (ll i = 0; i < n; i++) {
    ll x, l;
    cin >> x >> l;
    pq.push(P(x+l, x-l));
  }
  
  ans = n;
  ll now = -INF;
  while (!pq.empty()) {
    P p = pq.top();
    pq.pop();
    ll l = p.second;
    ll r = p.first;
    if (l < now) {
      ans--;
      continue;
    }
    now = r;
  }

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

Measured memory_bytes: 2420
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    val s1 = Array(a, {b.toString()}).joinToString("")
    val s2 = Array(b, {a.toString()}).joinToString("")
    println(if (s1 < s2) s1 else s2)
}

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



int main()
{
	int t[100100];
    int n;
    cin >> n;
    int i = 1;
    while(n --)
    {
        cin >> t[i];
        i ++;
    }
    int m;
    cin >> m;
    while(m --)
    {
        int p, x;
        cin >> p >> x;
        int c;
        c = t[p];
        t[p] = x;
        int sum = 0;
        for(int j = 1; j < i; j ++)
        {
            sum += t[j];
        }
        cout << sum <<endl;
        t[p] = c;
    }
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<functional> //sortのgreater
#include<iostream>
#include <math.h>
#include<numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include<string> //文字列
#include<vector>

#define rep(i,n) for (int i = 0; i < n; i++)
#define REP(i,n) for(int i=1;i<=n;i++)

using namespace std;
typedef long long ll;

int main()
{
    // Input
    int n, k;
    cin >> n >> k;

    vector<bool> havecandy(n, false);

    rep(i, k) {
        int d;
        cin >> d;

        rep(j, d) {
            int a;
            cin >> a;

            havecandy[a - 1] = true;
        }
    }
    cout << count(havecandy.begin(), havecandy.end(), false);
    return 0;
}


Measured memory_bytes: 3224
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

long long i,j,k,N,M,X,C[12],A[12][12],Y,fact[12],ans,sum[12],temp,n;

int main()
{
  cin>>N>>M>>X;
  
  for(i=0;i<N;i++)
  {
    cin>>C[i];
    for(j=0;j<M;j++)
    {
      cin>>A[i][j];
    }
  }
  Y=1;
  for(i=0;i<N;i++)
  {
    fact[i]=Y;
    Y*=2;
  }
  ans=10000000;
  for(k=0;k<Y;k++)
  {
    temp=0;
    for(j=0;j<M;j++)
    {
      sum[j]=0;
    }
    for(i=0;i<N;i++)
    {
      if((k&fact[i])!=0)
      {
        temp+=C[i];
        for(j=0;j<M;j++)
        {
          sum[j]+=A[i][j];
        }
      }
    }
    n=0;

    for(j=0;j<M;j++)
    {
      if(sum[j]<X) n=1;
    }
    if(n==0)    ans=min(ans,temp);
    
    
  }
  
  if(ans==10000000) cout<<"-1";
  else cout <<ans;
  
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

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

  LL ans = 0;
  string S;
  cin >> S;

  int len = S.length();

  string bw;
  FOR(i, 0, len) {
    if (i % 2) {
      bw.push_back('1');
    } else {
      bw.push_back('0');
    }
  }

  string wb;
  FOR(i, 0, len) {
    if (i % 2) {
      wb.push_back('0');
    } else {
      wb.push_back('1');
    }
  }

  LL temp = 0;
  FOR(i, 0, len) {
    if (S[i] != bw[i]) {
      temp++;
    }
  }
  FOR(i, 0, len) {
    if (S[i] != wb[i]) {
      ans++;
    }
  }

  ans = min(ans, temp);
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 720
#include <stdio.h>

int main(void){
	int a, b, c, s;
	scanf("%d %d %d", &a, &b, &c);
	if((a >= b) && (a >= c))
		s = a*10 + b + c;
	else if((b >= a)&&(b >= c))
		s = b*10 + a + c;
	else
		s = c*10 + a + b;

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

	return 0;
}


Measured memory_bytes: 128
from collections import deque
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
count = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for i in range(Q):
    p, x = map(int, input().split())
    count[p-1]+=x
q = deque([0])
flag = [False]*N
while q:
    v = q.pop()
    flag[v] = True
    for e in G[v]:
        if flag[e]:
            continue
        count[e]+=count[v]
        q.append(e)
print(*count)

Measured memory_bytes: 105236
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int n,m;
int a[50],b[50];
bool graph[50][50];
bool visited[50];

void dfs(int v) {
    visited[v] = true;
    REP(i,n) {
        if (!graph[v][i] || visited[i]) continue;
        dfs(i);
    }
}

int main() {
    cin>>n>>m;
    REP(i,m) {
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
        graph[a[i]][b[i]]=true;
        graph[b[i]][a[i]]=true;
    }
    int ans = 0;
    REP(i,m) {
        REP(j,n) visited[j] = false;
        graph[a[i]][b[i]]=false;
        graph[b[i]][a[i]]=false;
        dfs(0);
        bool flag = false;
        REP(j,n) if (!visited[j] && ++ans) break;
        graph[a[i]][b[i]]=true;
        graph[b[i]][a[i]]=true;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <forward_list>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// sanitize: shift + f11
// debug: shift + f9

unsigned long long int computeVal(vector<long long> & vals, vector<vector<long long>> map) {
    ll tot = 0;

    for(auto & e : map) {
        if(vals[e[1]] - vals[e[0]] == e[2])
            tot += e[3];
    }

    return tot;
}

long long maxVal(ll n, ll m, ll s, ll prevVal, vector<long long> & vals, vector<vector<long long>> map) {
    if(s > n) {
        return computeVal(vals, map);
    }

    ll maxValue = 0;
    for(ll i = prevVal; i <= m; ++i) {
        vals[s] = i;
        maxValue =  max(maxValue, maxVal(n, m, s+1, i, vals, map));
    }

    return maxValue;
}

int main()
{
    ll N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<long long>> qi;

    R1(Q) {
        ll ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        qi.push_back({ai, bi, ci, di});
    }

    vector<long long> vals(N+1);
    cout << maxVal(N, M, 1, 1, vals, qi) << endl;
}

Measured memory_bytes: 3676