akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
    while(1){
        LL n; cin >> n;
        if(n == 0) break;
        vector<LL> s(n,0);
        REP(i,n){
            cin >> s[i];
        }
        sort(s.begin(),s.end());
        LL sum = 0;
        FOR(i,1,n-1){
            sum += s[i];
        }
        cout << sum/(n-2) << endl;

    }

}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    //ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("../input.txt","r",stdin);
    int N;
    cin >> N;
    set<int> A;
    for (int i = 0; i < N; ++i) {
        int input;
        cin >> input;
        if(A.count(input) == 0) A.insert(input);
        else{
            cout << "NO" << "\n";
            return 0;
        }
    }
    cout << "YES" << "\n";
}


Measured memory_bytes: 13012
N,M = (int(x) for x in input().split())

ab_arr = []
for _ in range(N):
    A,B = (int(x) for x in input().split())
    ab_arr.append((A,B))

ab_arr.sort(key=lambda x:x[0])

nd = 0
ncost = 0
for A,B in ab_arr:
    if nd+B >= M:
        ncost += (M-nd)*A
        break
    nd += B
    ncost += B*A

print(ncost)



Measured memory_bytes: 18120
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll GCD(ll a, ll b){
  if (a > b) swap(a, b);
  while (a % b != 0) a %= b, swap(a, b);
  return b;
}

ll LCM(ll a, ll b){
  ll G = GCD(a, b);
  return a / G * b;
}

int N;
ll M, A[int(1e5 + 5)], cnt[int(1e5 + 5)];

int Count(){
  for (int i = 0; i < N; i++){
    ll now = A[i];
    while (now % 2 == 0){
      now /= 2; cnt[i]++;
    }
  }
  return 0;
}

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

  Count();
  for (int i = 1; i < N; i++){
    if (cnt[i] != cnt[i - 1]){
      cout << 0 << endl; return 0;
    }
  }

  ll now = 1;
  for (int i = 0; i < N; i++){
    now = LCM(now, A[i]);
    if (now > M){
      cout << 0 << endl; return 0;
    }
  }

  ll ans = M / now - M / (2 * now);
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 5312
while True:
	n = input()
	if n == 0: 
		break
	item = {}
	for n in range(n):
		name, cost = raw_input().split()
		item[name] = int(cost)
	for i in range(input()):
		recipe = raw_input().split()
		cost = sum(item[name] if name in item else 0 for name in recipe[2:])
		item[recipe[0]] = min(cost, item[recipe[0]])
	print item[raw_input()]

Measured memory_bytes: 4232
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = Integer.parseInt(sc.next() + sc.next() + sc.next());
		System.out.println(a % 4 == 0 ? "YES" : "NO");
	}
}


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long arr[n+1];
    arr[0]=0;
    for(long long i=1;i<=n;i++)
    {
        cin>>arr[i];
        arr[i]+=arr[i-1];
    }
    long long dp[n+1][n+1];
    for(long long i=0;i<=n;i++)
    {
        for(long long j=0;j<=n;j++)
        dp[i][j]=0;
    }
    for(long long r=2;r<=n;r++)
    {
        for(long long l=r-1;l>=0;l--)
        {
            dp[l][r]=LONG_MAX;
            for(long long k=l;k<r;k++)
            dp[l][r]=min(dp[l][r],arr[r]-arr[l-1]+dp[l][k]+dp[k+1][r]);
        }
    }
    cout<<dp[1][n]<<"\n";
    return 0;
}

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



int main() {
    int n;
    cin >> n;
    int prev = -1e9;
    bool ok = true;
    vector<int> h(n);
    rep(i,n) cin >> h.at(i);
    for (int i = n-1; 1 <= i; --i) {
        if (h.at(i) >= h.at(i-1)) continue;
        h.at(i-1)--;
        if (h.at(i) < h.at(i-1)) ok = false;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3700
#include<stdio.h>
#define N 2000001
int B[N], C[N];

void countingSort(int A[], int B[], int k, int num){
  int i, j;

  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=1;j<=num;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=num;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=num;i++){
    printf("%d", B[i]);
    if(i!=num) printf(" ");
  }
  printf("\n");
}

int main(){
  int A[N];
  int i,j,n,k=0;
  scanf("%d", &n);
  for(i=1;i<=n;i++){
    scanf("%d", &A[i]);
    if(k < A[i]) k=A[i];
  }
  countingSort(A, B, k, n);
  return 0;
}



Measured memory_bytes: 17384
n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = Array.new(n + 1, 0)
n.times do |i|
  c[i + 1] = c[i] + a[i]
end
d = Array.new(m + 1, 0)
m.times do |i|
  d[i + 1] = d[i] + b[i]
end
cnt = 0
bn = m
0.upto(n) do |i|
  break if c[i] > k
  while d[bn] > k - c[i]
    bn -= 1
  end
  cnt = i + bn if cnt < i + bn
end
puts cnt

Measured memory_bytes: 44856
N, M = map(int, input().split())
if N % 2 == 0:
    for i in range(min(M, N // 4)):
        print(i + 1, N - i)
    if M > N // 4:
        for i in range(N // 4, M):
            print(i + 1, N - i - 1)
else:
    for i in range(M):
        print(i + 1, N - i)

Measured memory_bytes: 9308
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (200000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // solve
  long ans = 0;
  int bs[20] = {}, l = 0, r = 0;
  for (int k = 0; k < 20; k++) {
    if (as[0] & (1 << k)) {
      bs[k]++;
    }
  }
  while (r < N) {
    // assume [l, r] satisfies the condition at this point
    int is_satisfied = 1;
    // keep moving r until the condition becomes unsatisfied
    for (r = r + 1; r < N; r++) {
      // add as[r] to bs
      for (int k = 0; k < 20; k++) {
        if (as[r] & (1 << k)) {
          bs[k]++;
          if (bs[k] > 1) {
            is_satisfied = 0;
          }
        }
      }
      // stop if condition becomes unsatisfied
      if (!is_satisfied) {
        break;
      }
    }
    // at this point, [l, r - 1] satisfies the condition, but [l, r] doesn't
    // the number of ranges where the left end is l ([l, r'])
    // that satisfy the condition is r - l
    // printf("l = %d, r = %d\n", l, r);
    // for (int k = 0; k < 20; k++) {
    //   printf("%2d ", bs[k]);
    // }
    // printf("\n");
    // finish if r == N
    if (r == N) {
      r = N - 1;
      const long m = r - l + 1;
      ans += m * (m + 1) / 2;
      // printf("ans = %ld\n", ans);
      break;
    }

    // keep moving l until the condition becomes satisfied again
    for (; !is_satisfied && l < r; l++) {
      // remove as[l] from bs
      for (int k = 0; k < 20; k++) {
        if (as[l] & (1 << k)) {
          bs[k]--;
        }
      }
      // count ranges where the left end is l
      ans += r - l;
      // check whether the condition is satisfied again
      is_satisfied = 1;
      for (int k = 0; k < 20; k++) {
        if (bs[k] > 1) {
          is_satisfied = 0;
          break;
        }
      }
    }

    // printf("l = %d, r = %d\n", l, r);
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return(0);
}

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

int main() {
    ll r, g, b, n;
    cin >> r >> g >> b >> n;

    ll ans = 0;
    rep(i, n+1) {
        rep(j, n+1) {
            ll x = n - (r*i + g*j);
            if(0 <= x && x%b == 0) {
                ans++;
            }
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
const int MaxN = 1e5+5;
int n;
int a[MaxN],t;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	while(~scanf("%d",&n)){
		memset(a,0,sizeof(a));
		for(int i = 0;i<n;i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n,cmp);
		long long sum = 1;
		for(int i = 1;i<n;i++){
			if(a[i]==a[i-1]){
				sum = sum*a[i];
				i++;
				t++;
			}
			if(t==2)
				break;
		}
		if(sum==1&&t!=2)
			sum = 0;
		printf("%lld\n",sum);
	}
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def main():
    X, Y, Z, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = []
    for a in A:
        for b in B:
            ans.append(a + b)

    ans_s = sorted(ans, reverse=True)

    ans2 = []
    for a in ans_s[:3000]:
        for c in C:
            ans2.append(a + c)

    ans2_s = sorted(ans2, reverse=True)

    for i in range(K):
        print(ans2_s[i])


if __name__ == '__main__':
    main()



Measured memory_bytes: 138892
int main(int argc, const char * argv[]) {
    // insert code here...
    int a, b;
    char op;
    for(;;){
        scanf("%d %c %d",&a, &op, &b);
        switch (op) {
            case '+':
                printf("%d\n", a+b);
                break;
                
            case '-':
                printf("%d\n", a-b);
                break;
                
            case '/':
                printf("%d\n", a/b);
                break;
                
            case '*':
                printf("%d\n", a*b);
                break;
                
            default:
                break;
        }
        if(op == '?') break;
    }
    return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long x[] = new long[n], y[] = new long[n];
		
		for(int i=0;i<n;i++){
			x[i] = sc.nextLong();
			y[i] = sc.nextLong();
		}
		
		long parity = Math.abs((x[0] + y[0]) % 2);
		
		boolean f = true;
		for(int i=1;i<n;i++){
			if(Math.abs((x[i]+y[i])%2) != parity)
				f = false;
		}
		
		if(f){
			long a[];
			
			if(parity==0){
				a = new long[32];
				a[0] = 1;
				a[1] = 1;
				for(int i=2;i<32;i++){
					a[i] = a[i-1] * 2;
				}
			}
			else{
				a = new long[31];
				a[0]=1;
				for(int i=1;i<31;i++){
					a[i] = a[i-1] * 2;
				}
			}
			
			System.out.println(a.length);
			
			for(int i=a.length-1;i>=0;i--){
				System.out.print(i==0 ? a[i]:a[i]+" ");
			}
			
			System.out.println();
			
			for(int i=0;i<n;i++){
				long total = (1L << 30) -1;
				if(parity==0)
					total += 1;
				
				for(int j=a.length-1;j>=0;j--){
					if(Math.abs(x[i]-a[j]) + Math.abs(y[i]) <= total){
						x[i] -= a[j];
						System.out.print("R");
					}
					else if(Math.abs(x[i]+a[j]) + Math.abs(y[i]) <= total){
						x[i] += a[j];
						System.out.print("L");
					}
					else if(Math.abs(x[i]) + Math.abs(y[i]-a[j]) <= total){
						y[i] -= a[j];
						System.out.print("U");
					}
					else{
						y[i] += a[j];
						System.out.print("D");
					}
					total>>=1;
				}
				
				System.out.println();
			}
			
		}
		else{
			System.out.println(-1);
		}
	}

}


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

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

ll mod = (ll)(1e9+7);

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }

  ll ans = 0;
  rep(i,n-1){
    sum -= a[i];
    ll tmp = sum%mod;
    tmp *= a[i];
    tmp %= mod;
    ans += tmp;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4836
def abc144b():
    n = int(input())

    start = 1
    end = 9
    flag = False

    # シンプルな全探索
    for i in range(start, end + 1):
        for j in range(start, end + 1):
            if n == i * j:
                flag = True
                break

    if flag:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    abc144b()

Measured memory_bytes: 61696
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+1):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Measured memory_bytes: 3644
import java.util.Scanner;

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

        while(true){
            int n = sc.nextInt();
            int s = sc.nextInt();
            if(n==0 && s==0) break;
            int ans = 0;
            for(int i = 0; i < (1<<10); i++){
                int sum = 0;
                int f = 0;
                for(int j = 0; j < 10; j++){
                    if((1 & i >> j) == 1) {
                        sum += j;
                        f++;
                    }
                }
                if(sum == s&&f == n) ans++;
            }

            System.out.println(ans);
        }

        sc.close();
    }
}


Measured memory_bytes: 26332
#include<iostream>
using namespace std;
int main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	for (int i = 0; i < X; ++i) {
		if (i*Y + (i + 1)*Z > X) {
			cout << i - 1 << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    S[5] = ' ';
    S[13] = ' ';
    S[19] = ' ';
    cout << S << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define X first
#define Y second
using namespace std;
enum STATE{NON, NORMAL, LOOP};

struct node{
	node():state(NON), pos(pair<int, int>(-1, -1)){}
	STATE state;
	pair<int, int> pos;
};

STATE stateChange(STATE current){
	switch(current){
	case NON:
		current = NORMAL;
		break;
	case NORMAL:
		current = LOOP;
		break;
	case LOOP:
		break;
	default:
		break;
	}
	return current;
}

void clear(vector<vector<node> > &pos){
	for(int i = 0; i < pos.size(); i++){
		for(int j = 0; j < pos[i].size(); j++){
			if(pos[i][j].state!=LOOP) pos[i][j].state = NON;
		}
	}
}

int main(){
	int n;
	while(cin >> n && n != 0){
		vector<vector<node> > pos(n, vector<node>(n, node()));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> pos[i][j].pos.X>> pos[i][j].pos.Y;
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				bool f = false;
				int x=j, y=i;
				while(pos[y][x].state!=LOOP){
					pos[y][x].state = stateChange(pos[y][x].state);
					if(pos[y][x].state==LOOP) f = true;
					int tmpx=x, tmpy=y;
					x = pos[tmpy][tmpx].pos.X;
					y = pos[tmpy][tmpx].pos.Y;
				}
				if(f) count++;
				clear(pos);
			}
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1320
N = int(input())
b = [list(map(int,input().split())) for i in range(N)]
txy = [[0,0,0]] + b
ans = "Yes"
for i in range(N):
    dt = txy[i+1][0]-txy[i][0]
    dx = abs(txy[i+1][1]-txy[i][1])
    dy = abs(txy[i+1][2]-txy[i][2])
    if dt < dx + dy or dt%2 != (dx + dy)%2:
        ans ="No"
print(ans)

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

vector<int> arr[200005];
int vals[200005];
void push(int node, int parent) {
  for(int i = 0; i < arr[node].size(); i++) {
    if(arr[node][i]  == parent) continue;
    vals[arr[node][i]] += vals[node];
    push(arr[node][i],node);
  }
}



int main() {
  int n, q; cin >> n >> q;
  for(int i = 0; i < n-1; i++) {
    int r, p; cin >> r >> p; arr[r].push_back(p);
    arr[p].push_back(r);
  }
  for(int i = 0; i < q; i++) {
    int node, value;cin >> node >> value;
    vals[node] += value;
  }

  push(1, 0);
  for(int i = 1; i <= n; i++) {
    cout << vals[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 26624
while True:
    m,f,r=map(int,input().split())
    if m==f==r==-1: break
    ret = 'F'
    score = m + f
    if -1 in (m,f): pass
    elif score >= 80: ret = 'A'
    elif score >= 65: ret = 'B'
    elif score >= 50: ret = 'C'
    elif score >= 30: 
        ret = 'D'
        if r >= 50:ret = 'C'
    print(ret)

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

using namespace std;

const int N_MAX = 200002;

int n, k, c;

string s;

int dp[N_MAX];
int prefdp[N_MAX];

int mi[N_MAX];

int cnt[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k >> c;
    cin >> s;
    s = " " + s;
    for(int i = 1; i <= n; i++)
    {
        prefdp[i] = prefdp[i - 1];
        if(s[i] == 'x')
            continue;
        dp[i] = prefdp[max(0, i - c - 1)] + 1;
        prefdp[i] = max(prefdp[i], dp[i]);
    }
    if(k < prefdp[n])
        return 0;
    for(int i = 1; i <= n; i++)
        mi[i] = prefdp[n];
    for(int i = n; i >= 1; i--)
    {
        if(i < n)
            mi[i] = min(mi[i], mi[i + 1]);
        if(s[i] == 'x')
            continue;
        if(dp[i] >= mi[i])
        {
            cnt[dp[i]]++;
            mi[max(0, i - c - 1)] = min(mi[max(0, i - c - 1)], dp[i] - 1);
        }
    }
    for(int i = 1; i <= n; i++)
        if(dp[i] >= mi[i] && cnt[dp[i]] == 1)
            cout << i << "\n";
    return 0;
}


Measured memory_bytes: 4944
da = list(map(int,input().split()))
oka = 0
o = 0
p = 0
l = 0
k = 0
if da[3] <= da[4]:
  oka = da[3]
  o = da[4]
  p = da[4]-da[3]
  l = 1
  k = 0
elif da[4] <= da[3]:
  oka = da[4]
  o = da[3]
  p = da[3]-da[4]
  l = 0
  k = 1
if (da[0]*da[3] + da[1]*da[4]) >= (da[2]*o*2 + da[k]*p):
  if da[3] <= da[4]:
    print(da[2]*da[4]*2)
  else:
    print(da[2]*da[3]*2)
elif (da[0]*da[3] + da[1]*da[4]) >= (da[2]*oka*2 + da[l]*p):
  if da[3] <= da[4]:
    print(da[2]*da[3]*2 + da[1]*(da[4]-da[3]))
  else:
    print(da[2]*da[4]*2 + da[0]*(da[3]-da[4]))
else:
  print(da[0] * da[3] + da[1] * da[4])

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

	int main(){
		int a,b,c,count=3;
		cin>>a>>b>>c;

		if(a==b){
			count--;
			if(a==c){
				count--;
			}
		}
		else if(a==c){
			count--;
		}
		else if(b==c){
			count--;
		}
		cout<<count<<endl;
		rewind(stdin);
		getchar();
		return 0;
	}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct{
  int parent;
  int left;
  int right;
}Tree;

Tree t[100000];
int num,dep[100000],hei[100000];

void print(int);
void setDep(int,int);
int setHei(int);
int getSib(int);

int main(){
  int v,k,l,r,c,i,root = 0;

  scanf("%d",&num);
  for(i = 0; i< num; i++){
    t[i].parent = -1;
    t[i].left = -1;
    t[i].right = -1;
  }

  for(i = 0; i< num; i++){
    scanf("%d %d %d",&v,&l,&r);
  
    t[v].left = l;
    t[v].right = r;

    if(l != -1)t[l].parent = v;
    if(r != -1)t[r].parent = v;
  }

  for(i = 0; i < num; i++){
    if(t[i].parent == -1)root = i;
  }

  setDep(root,0);
  setHei(root);

  for(i = 0; i< num; i++)print(i);
  return 0;
}


void print(int u){
  
  int i,c;
  printf("node %d: parent = %d, sibling = %d, ",u,t[u].parent,getSib(u));
  int degree = 0;
  if(t[u].left != -1)degree++;
  if(t[u].right != -1)degree++;
  printf("degree = %d, depth = %d, height = %d, ",degree,dep[u],hei[u]);
    
  if(t[u].parent == -1)printf("root\n");
  else if(t[u].left == -1 && t[u].right == -1)printf("leaf\n");
  else printf("internal node\n");
}


void setDep(int u,int p){

  if(u == -1)return;
  dep[u] = p;
  setDep(t[u].right,p+1);
  setDep(t[u].left,p+1);


}


int setHei(int u){
  int h1 = 0,h2 = 0,h;

  if(t[u].left != -1){
    h1 = setHei(t[u].left)+1;
  }
  if(t[u].right != -1){
    h2 = setHei(t[u].right)+1;
  }
  if(h1 > h2)hei[u] =h1;
  else hei[u] = h2;

  return hei[u];
}

int getSib(int u){

  if(t[u].parent == -1)return -1;
  if(t[t[u].parent].left != u && t[t[u].parent].left != -1) return t[t[u].parent].left;
  if(t[t[u].parent].right != u && t[t[u].parent].right != -1) return t[t[u].parent].right;
  
  return -1;
}

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

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

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)




ll mod = 998244353;
ll n,a,b,k;


/*
使い方
Nとmodをセットする
はじめにinitを呼ぶ
*/

ll N;
ll fact[1000002];
ll invf[1000002];

ll f(ll a, ll x){
  ll res = 1;
  a %= mod;
  while(x > 0){
    if(x&1) res = res * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return res;
}

ll inv(ll x){
  return f(x, mod-2);
}

void init(){
  fact[0] = invf[0] = 1;
  FOR(i,1,N){
    fact[i] = i * fact[i-1] % mod;
    invf[i] = inv(fact[i]);
  }
}

ll P(ll n, ll r){
  return fact[n] * invf[n-r] % mod;
}

ll C(ll n, ll r){
  return P(n, r) * invf[r] % mod;
}

ll x,y;

ll cnt = 0;

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


int main(){
  cin >> n>>a>>b>>k;
  N = n +2;
  init();
  for(ll x = 0; x <= n; x++){
    if((k-a*x) % b != 0) continue;
    y = (k-a*x)/b;
    if(y>n) continue;
    if(y<0) break;
    cnt = (cnt+C(n,x)*C(n,y)) % mod;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

lint mod=1e9+7;

int main()
{
	lint N,M;
	lint S[2010]={};
	lint T[2010]={};

	cin >> N >> M;
	for(int i=1;i<=N;i++)
		cin >> S[i];
	for(int i=1;i<=M;i++)
		cin >> T[i];

	lint dp[2010][2010]={};
	lint sum[2010][2010]={};
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=M;j++)
		{
			if(S[i]==T[j])
				dp[i][j]+=sum[i-1][j-1]+1;
			
			dp[i][j]%=mod;
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j];
			sum[i][j]=(sum[i][j]+mod)%mod;
		}
	}

	cout << (1+sum[N][M])%mod << endl;
	return 0;
}



Measured memory_bytes: 63360
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	N--
	fmt.Println((N * (1 + N)) / 2)
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double
#define P 1000000007

using namespace std;


ll power(ll a,ll n,ll p)
{
	ll ans = 1;
	while(n)
	{
		if(n&1) ans = (ans*a)%p;
		n >>=1;
		a = (a*a)%p;
	}
	return ans;
}

ll fact(ll n , ll r , ll p)
{
	ll ans = 1;
	for(ll i=n;i>r;i--)
		ans = (ans*i)%p;
	return ans;
}

ll ncr(ll n,ll r , ll p)
{
	if(r>n/2) r = n-r;
	ll num = fact(n,n-r,p);
	ll den = fact(r,1,p);
	ll inv_d = power(den,p-2,p);
	//cout<<"num "<<num<<" den "<<den<<" inv_d "<<inv_d<<endl;

	return (num*inv_d)%p;
}

int main()
{
	fio
	int TC;
	// cin>>TC;
	TC=1;
	while(TC--)
	{
		ll n,a,b;
		cin>>n>>a>>b;
		//cout<<(P + power(2,n,P)-ncr(n,b,P)-ncr(n,a,P)-1)%P<<endl;
		ll res = power(2,n,P)-1;
		ll rej = (ncr(n,b,P)+ncr(n,a,P))%P;
		rej = P-rej;
		res = (res +rej)%P;
		cout<<res<<endl;
					
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int		str_cmp(const void *s1, const void *s2)
{
	return strcmp(*(char **)s1, *(char **)s2);
}

int main()
{
	int N;
	scanf("%d", &N);
	char str[N][11];
	int p[N];
	char **sort;
	sort = (char**)malloc(sizeof(char*) * N);
	int i = 0;
	int len;
	while (i < N)
	{
		scanf("%s", str[i]);
		scanf("%d", &p[i]);
		len = strlen(str[i]);
		sort[i] = (char*)malloc(sizeof(char) * (len + 1));
		strcpy(sort[i], str[i]);
		i++;
	}
	qsort(sort, N, sizeof *sort, str_cmp);
	i = 0;
	int j;
	int max = -1;
	int index;
	while (i < N)
	{
		j = 0;
		max  = -1;
		while (j < N)
		{
			if (strcmp(sort[i], str[j]) == 0)
			{
				if (p[j] > max)
				{
					max = p[j];
					index = j;
				}
			}
			j++;
		}
		p[index] = -1;
		printf("%d\n", index + 1);
		i++;
	}
	return (0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
vector<int>v[200010];
int n,i,j,x,y,a[200001],q,nod,val;
bool viz[200001];
void df(int nod)
{
    int i;
    viz[nod]=1;
    for(i=0;i<v[nod].size();i++)
        if(!viz[v[nod][i]])
        {
            a[v[nod][i]]+=a[nod];
            df(v[nod][i]);
        }
}
int main()
{
    cin>>n>>q;
    for(i=1;i<n;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(i=1;i<=q;i++)
    {
        cin>>nod>>val;
        a[nod]+=val;
    }
    df(1);
    for(i=1;i<=n;i++)
        cout<<a[i]<<' ';

    return 0;
}


Measured memory_bytes: 23680
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int [] binary_heap = new int[n];
		for (int i = 0; i < n; i++) {
			binary_heap[i] = in.nextInt();
		}
		in.close();
		
		int lk = 0;
		int rk = 0;

		for (int i =0; i < n; i++) {
			if (i == 0) {
				int key = binary_heap[i];
				int node = i+1;
				if (n > 1) {
					lk = binary_heap[1];
				}
				if (n > 2) {
					rk = binary_heap[2];
				}
				
				if (lk == 0 && rk == 0) {
					System.out.println("node " + node + ": key = " + key + ", ");
				}else if (lk == 0) {
					System.out.println("node " + node + ": key = " + key + ", right key = " + rk + ", ");
				}else if (rk == 0) {
					System.out.println("node " + node + ": key = " + key + ", left key = " + lk + ", ");
				}else {
					System.out.println("node " + node + ": key = " + key + ", left key = " + lk + ", right key = " + rk + ", ");
				}
				lk = 0;
				rk = 0;
			
			}else {
				int node = i + 1;
				int key = binary_heap[node - 1];
				int pk = binary_heap[(int)Math.floor(node/2.) - 1];
				if (node * 2 <= n) {
					lk = binary_heap[2 * node - 1];
				}
				if (node * 2 + 1 <= n) {
					rk = binary_heap[2 * node];
				}
				
				if (lk == 0 && rk == 0) {
					System.out.println("node " + node + ": key = " + key + ", parent key = " + pk + ", ");
				}else if(lk == 0) {
					System.out.println("node " + node + ": key = " + key + ", parent key = " + pk + ", right key = " + rk + ", ");
				}else if(rk == 0) {
					System.out.println("node " + node + ": key = " + key + ", parent key = " + pk + ", left key = " + lk + ", ");
				}else {
					System.out.println("node " + node + ": key = " + key + ", parent key = " + pk + ", left key = " + lk + ", right key = " + rk + ", ");
				}
				lk = 0;
				rk = 0;
			}
		}
	}
}



Measured memory_bytes: 27840
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 21-Jun-2020 18:22:16
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

int a[N];
int cnt[N];

int solve() {
    int n; Int(n);
    FOR (i, 1, n) Int(a[i]);

    long long sum = 0;
    FOR (i, 1, n) {
        ++cnt[a[i]];
        sum += a[i];
    }

    int q; Int(q);
    FOR (i, 1, q) {
        int b, c; Int(b, c);
        sum -= 1LL * b * cnt[b];
        sum += 1ll * c * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;

        printf("%lld\n", sum);
    }

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0;
    // Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

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


int main(){
  
  int N;
  cin >> N;
  
  vector<int> a(110);  
  for(int i = 0; i < N; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int alice = 0;
  int bob = 0;
  
  for(int i = 0; i < N; i++){
    
    if(i % 2 == 0){
      alice += a.at(i);
    }    
    else{
      bob += a.at(i);
    }
  }
  
  cout << alice - bob << endl;
}
    
  

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

int main()
{
	int n, m;
	cin >> n >> m;
	static int mat[100][100];
	static int b[100];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			int v;
			cin >> v;
			mat[i][j] = v;
		}
	}
	for (int i = 0; i < m; ++i) {
		int v;
		cin >> v;
		b[i] = v;
	}
	for (int i = 0; i < n; ++i) {
		int sum = 0;
		for (int j = 0; j < m; ++j) {
			sum += mat[i][j] * b[j];
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
 
void qsort(int a[],int left,int right){
     
    int p=(left+right)/2;
    int pivot=a[p];
    int i,temp;
    if(left<right){
        p=left;
        pivot=a[p];
        for(i=left+1;i<=right;i++){
            if(a[i]<pivot){
                p++;
                temp=a[i];a[i]=a[p];a[p]=temp;//swap
            }
        }
        temp=a[left];a[left]=a[p];a[p]=temp;//swap
        qsort(a,left,p-1);
        qsort(a,p+1,right);
    }
 
}
 
int search(int key,int a[],int n){
    int i;
    for(i=0;i<n;i++){
        if(key==a[i])return i;
    }
     
    return i;
}
 
int isVisited(int v[],int n){
    int i;
    for(i=0;i<n;i++){
        if(v[i]!=1)return -1;
    }
    return 1;
}
     
int min(int a,int b){
    if(a<b)return a;
    return b;
}
 
 
int main(void){
    int n,i,j,minW,cost=0,w;
    int a[1000],b[1000],v[1000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
        v[i]=0;
    }
    qsort(b,0,n-1);
     
    for(i=0;i<n;i++){    
        int x=i;
        int sum=0;
        int count=0;
        minW=10000;
        while(v[x]==0){
            v[x]=1;
            sum+=a[x];
            count++;
            if(minW>a[x])minW=a[x];
            x=search(a[x],b,n);
        }
        if(count<2)continue;
         
        cost+=min(b[0]*(count+1)+sum+minW,sum+(count-2)*minW);
        if(isVisited(v,n)==1)break;
    }
     
    printf("%d\n",cost);
    return 0;
}


Measured memory_bytes: 2768
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, m = map(int, input().split())
F = [[] for _ in range(n)]
for _ in range(m):
  x, y, z = map(int, input().split())
  x -= 1
  y -= 1
  F[x].append(y)
  F[y].append(x)
seen = [False]*n
def dfs(v):
  seen[v] = True
  for nv in F[v]:
    if seen[nv]:
      continue
    dfs(nv)
ans = 0
for v in range(n):
  if not seen[v]:
    ans += 1
    dfs(v)
print(ans)

Measured memory_bytes: 104700
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a,b,k;
  cin >> a >>b >>k ;
  int64_t c=a+b;//フロー回避
  if(k>=c){
    cout<<0<<" "<<0<<endl;//ごちそうさま
  }
  else if(a<k&&k<c){
    cout<<0<<" "<<b-(k-a)<<endl;//青木残
  }
  else if(a>=k){
    cout<<a-k<<" "<<b<<endl;//高橋残
  }
}


Measured memory_bytes: 256
N = input()
flag = True
for i in range(1, len(N)):
    if N[i] != '9':
        flag = False
        break

if flag:
    print(int(N[0]) + 9 * (len(N) - 1))
else:
    print(int(N[0]) - 1 + 9 * (len(N) - 1))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int n;
vector<string> ans;

void solve(int i,string s,char mx){
    if(i==n){
        ans.push_back(s);
        return;
    }
    for(char c='a';c<=mx+1;++c){
        s[i]=c;
        if(mx+1==c)solve(i+1,s,mx+1);
        else solve(i+1,s,mx);
    }
}

int main(){
    cin>>n;
    string s={};
    rep(i,n)s+='a';
    solve(1,s,'a');
    for(auto str:ans){
        cout<<str<<endl;
    }
}


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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


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

int main(int argc, char* argv[]) {
  int N, X;
  cin >> N >> X;

  vector<int> L(N);
  rep(i, N) cin >> L[i];

  int D   = 0;
  int cnt = 1;
  for (int i = 1; i <= N; i++) {
    D = D + L[i - 1];
    if (D <= X) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 888
use std::io::Write;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let mut l = 0;
    let mut r = 0;
    for i in 0..n {
        l += (k + i) + (k + n + i);
        r += k + 2 * n + i;
    }
    if l > r {
        println!("-1");
        return;
    }
    assert!(2 * k <= n + 1);
    let mut ans = vec![];
    let mut i = n / 2;
    let mut p = 3 * n - 1;
    let mut q = 2 * n - 1;
    while i < n {
        ans.push((k + i, k + q, k + p));
        p -= 1;
        q -= 2;
        i += 1;
    }
    let mut x = 0;
    let mut y = 2 * n - 2;
    while p >= 2 * n {
        ans.push((k + x, k + y, k + p));
        p -= 1;
        y -= 2;
        x += 1;
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for (a, b, c) in ans {
        writeln!(out, "{} {} {}", a, b, c).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 11640
/*input
4 10 1 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}


int main()
{
	IOS;
	int n,m,h,w;
	cin>>n>>m>>h>>w;
	if(n%h==0&&m%w==0){
		cout<<"No\n";
		return 0;
	}
	cout<<"Yes\n";
	if(n%h){
		REP(i,n) REP(j,m){
			if((i+1)%h==0){
				cout<<-n*(h-1)-1;
			}
			else cout<<n;
			cout<<" \n"[j==m-1];
		}
	}
	else{
		REP(i,n) REP(j,m){
			if((j+1)%w==0){
				cout<<-m*(w-1)-1;
			}
			else cout<<m;
			cout<<" \n"[j==m-1];
		}
	}
	return 0;
}


Measured memory_bytes: 1408
import std.conv, std.stdio, std.algorithm, std.string, std.range, std.math;

void main() {
  readln;
  const l  = readln.split.map!(to!int).array.sort!"a<b".array;
  
  const n = l.length;
  int ans;
  
  auto ls = l.assumeSorted;
  foreach_reverse (long mid; 0..n) foreach_reverse (long low; 0..mid) {
    ans += ls.lowerBound(l[mid]+l[low]).length - 1 - mid;
  }
  
  ans.writeln;
}

Measured memory_bytes: 380
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef double D;
const ll inf=(1ll<<62);
const ll mod=1e9+7;
const int MX=3e5+9;
int n,m,x,y,w,vis[MX],dis[MX],ok[MX],f[MX];
vector<pair<int,int> >v[MX];
vector<int>pars;
void dfs(int x,int d){
    if(dis[x]!=-1){
        if(dis[x]!=d){
            puts("No");
            exit(0);
        }
    }
    dis[x]=d;
    if(vis[x]==2)return;
    if(vis[x]==1){
        puts("No");
        exit(0);
    }
    vis[x]=1;
    for(auto pp:v[x]){
        dfs(pp.first,d+pp.second);
    }
    vis[x]=2;
}
int main(){
    memset(dis,-1,sizeof(dis));
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&x,&y,&w);
        v[x].push_back({y,w});
        f[y]=1;
        ok[x]=ok[y]=1;
    }
    for(int i=1;i<=n;i++){
        if(!ok[i])continue;
        if(!f[i])pars.push_back(i);
    }
    for(auto pp:pars)dfs(pp,0);
    for(int i=1;i<=n;i++){
        if(vis[i]||!ok[i])continue;
        dfs(i,0);
    }
    puts("Yes");
}


Measured memory_bytes: 18944
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  int x,y,z;
  x = A + B;
  y = A - B;
  z = A * B;
  int g;
  g = max({x,y,z});
  cout << g << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
N,M = (int(x) for x in input().split())
keta_num_str = [ (input().split()) for i in range(M) ]

#各桁をキー、数字を値の辞書にする
suuji = ""
num_str_dic = defaultdict(set)
kotae_dic ={ str(i):"0" for i in range(1,N +1) } #　各桁に初期値”０”を入力。
if 1< N:
    kotae_dic["1"] = "1" # 2桁以上の時は左の桁は最低１
for i in keta_num_str:   
    num_str_dic[i[0]].add(i[1])


for i,v in num_str_dic.items():
    if 1 < len(v) : # 一つの桁に複数の値がある時はエラー
        kotae_dic ={}
        break
    
    else:
        kotae_dic[i] = list(v)[0]

# 表示
import math
if kotae_dic == {}: # 一つの桁に複数の値の時        
    print(-1)
else:
    kotae_dic_sorted = sorted(kotae_dic.items(),key=lambda x:int(x[0]))
    kotae_str = "".join( [i[1] for i in kotae_dic_sorted ] ) # 辞書の値を連結
    kotae_int =int(kotae_str)
    if kotae_int == 0 and 1< N: # "00"などはエラー、"0"はOK
        print(-1)
    elif kotae_int == 0 and N == 1:
        print("0")
    elif 10**(N-1) > kotae_int or kotae_int >= 10** N: # 桁があってない＝一番左の桁が”０”はエラー
        print(-1)
  
  #  elif 1000 <= kotae_int: # 答えが１０００以上はエラー
   #     print(-1)

    else:
        print(kotae_int)

Measured memory_bytes: 3316
N = int(input())
k = 1
n = 0
while n < N:
    n += k
    k += 1
if n!=N:
    print('No')
    exit()
print('Yes')
print(k)
ans = [[] for _ in range(k)]
v = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(v)
        ans[j].append(v)
        v += 1
for row in ans:
    print(*([len(row)] + row))

Measured memory_bytes: 14140
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    vs = LI()
    vs = sorted(vs)
    ans = 0
    for i in range(n):
        if i == 0:
            ans += vs[i]
        else:
            ans = (ans + vs[i]) /2
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  long long int *A = (long long int *)a;
  long long int *B = (long long int *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int main(void){
    long long int n, m, i, ans=0;
    scanf("%lld %lld", &n, &m);
    long long int x[m];
    for(i=0; i<m; i++) scanf("%lld", &x[i]);
    qsort(x, sizeof(x) / sizeof(long long int), sizeof(long long int), asc);
    long long int sa[m-1];
    for(i=0; i<m-1; i++) sa[i] = x[i+1] - x[i];
    qsort(sa, sizeof(sa) / sizeof(long long int), sizeof(long long int), asc);
    for(i=0; i<m-n; i++) ans += sa[i];
    printf("%lld", ans);
}

Measured memory_bytes: 2540
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    string s;
    cin >> s;
    vector<int> a(26,0);
    rep(i,s.size()){
        a[s[i]-'a']++;
    }
    if(s.size()<26){
        rep(i,26){
            if(a[i]) continue;
            else{
                cout << s << char('a'+i) << endl;
                return 0;
            }
        }
    }
    else{
        rrep(i,s.size()-1){
            if(s[i+1]<s[i]){
                continue;
            }
            else{
                int ans = INF;
                for(int j = i+1; j<s.size(); j++){
                    if(s[i]<s[j]){
                        chmin(ans,s[j]-0);
                    }
                }
                rep(j,i){
                    cout << s[j];
                }
                cout << char(ans) << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256