akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();
            final int K = fs.nextInt();
            final int X = fs.nextInt();
            final int Y = fs.nextInt();

            System.out.println(K < N ? X * K + Y * (N - K) : X * N);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

#define lli long long int

int main() {
	lli n, ans = LLONG_MAX;
	cin >> n;
    int raiz = sqrt(n), is = 1;
	for(lli i = 1; i <= raiz; i++) {
		if(n % i == 0) {
			ans = min(ans, (i-1) + ((n/i)-1));
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    
    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    
    long long initial_distance = abs(b - a);
    if(v == w || v < w){
        cout << "NO" << endl;
        return 0;
    }
    
    double time_needed = (double)initial_distance/(v - w);
    if(time_needed <= t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#ifdef LOCAL
    freopen("input.in" , "r" , stdin);
#endif
    int n , m;
    cin >> n >> m;

    vector<int> adj[m + 1];
    for (int i = 1 ;i <= n ;i++) {
        int time , reward;
        cin >> time >> reward;
        if (time <= m)
            adj[time].push_back(reward);
    }

    int ans = 0;

    priority_queue<int> pq;
    for (int i = 1 ;i <= m ;i++) {
        for (int x : adj[i])
            pq.push(x);

        if (pq.size()) {
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans;
}


Measured memory_bytes: 8864
#include <iostream>
#include <vector>
#include <memory.h>
using namespace std;

vector<vector<int>> edge;
int visited[200010];
bool cycle[200010];
int grundy[200010];
vector<int> cyc;

bool dfs(int i) {
	visited[i] = 1;
	for (int u: edge[i]) {
		if (visited[u] == 0) cycle[i] |= dfs(u);
		else if (visited[u] == 1) cycle[i] = 1;
	}
	visited[i] = 2;
	if (cycle[i]) cyc.push_back(i);
	return cycle[i];
}

int find_grundy(int i) {
	if (grundy[i] != -1) return grundy[i];
	int mask = 0;
	for (int u: edge[i]) {
		mask |= (1 << find_grundy(u));
	}
	return grundy[i] = __builtin_ctz(~mask);
}

int grundy_single_init(int i) {
	int mask = 0;
	for (int u: edge[i]) {
		if (!cycle[u]) mask |= (1 << grundy[u]);
	}
	return mask;
}

int grundy_single(int i) {
	int mask = 0;
	for (int u: edge[i]) {
		mask |= (1 << grundy[u]);
	}
	return __builtin_ctz(~mask);
}

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

	int n, t;
	cin >> n;

	edge.resize(n);
	memset(grundy, -1, sizeof(grundy));
	for (int i = 0; i < n; ++i) {
		cin >> t;
		t--;
		edge[t].push_back(i);
	}

	for (int i = 0; i < n; ++i) {
		if (!visited[i]) dfs(i);
	}

	for (int i = 0; i < n; ++i) {
		if (!cycle[i] && grundy[i] == -1) find_grundy(i);
	}

	int start = grundy_single_init(cyc[0]);
	int low = __builtin_ctz(~start);
	grundy[cyc[0]] = low;
	start |= (1 << low);
	for (int i = 1; i < cyc.size(); ++i) {
		grundy[cyc[i]] = grundy_single(cyc[i]);
	}
	if (grundy_single(cyc[0]) == grundy[cyc[0]]) {
		cout << "POSSIBLE";
		return 0;
	}
		
	grundy[cyc[0]] = __builtin_ctz(~start);
	for (int i = 1; i < cyc.size(); ++i) {
		grundy[cyc[i]] = grundy_single(cyc[i]);
	}
	if (grundy_single(cyc[0]) == grundy[cyc[0]]) {
		cout << "POSSIBLE";
	}
	else cout << "IMPOSSIBLE";
}

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

using namespace std;


int main(int argc, char* argv[])
{
	int n;
	cin >> n;
	vector<int> b;
	b.resize(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> b[i];
	}

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

	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;


int main(){
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
        x[i]-=a;
    }
    vector<map<int,ll> > mpv(n+1);
    mpv[0][0]=1;
    for(int i=1;i<=n;i++){
        for(auto p:mpv[i-1]){
            int key=p.first;
            ll num=p.second;
            mpv[i][key+x[i-1]]+=num;
            mpv[i][key]+=num;
        }
    }
    cout<<mpv[n][0]-1<<endl;
    
}


Measured memory_bytes: 4516
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) {
		cin >> A.at(i);
	}
	ll p = 1;
	rep(i, 100005) {
		p = A.at(p - 1);
		if (p == 2) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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 all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int n;
	cin >> n;
	vi x(n),y;
	rep(i,n) cin >> x[i];
	y = x; sort(all(y));
	int ave1 = y[n/2-1],ave2 = y[n/2];
	for(int i = 0; i < n; i++){
		if(x[i] < ave1) cout << ave2 << endl;
		else if(x[i] > ave2) cout << ave1 << endl;
		else if(x[i] == ave1) cout << ave2 << endl;
		else cout << ave1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
N = int(input())
S = [str(input()) for i in range(N)]
S_head = []
for i in S:
    S_head.append(i[:1])
M_num = S_head.count("M")
A_num = S_head.count("A")
R_num = S_head.count("R")
C_num = S_head.count("C")
H_num = S_head.count("H")
ans = M_num*A_num*R_num + M_num*A_num*C_num + M_num*A_num*H_num +\
      M_num*R_num*C_num + M_num*R_num*H_num + M_num*C_num*H_num +\
      A_num*R_num*C_num + A_num*R_num*H_num + A_num*C_num*H_num +\
      R_num*C_num*H_num
print(ans)

Measured memory_bytes: 10520
n = int(input())
A = list(map(int, input().split()))
cnt = 0
s = 0
m = 10 ** 9
for ai in A:
    if ai <= 0:
        cnt = cnt + 1
        ai *= (-1)
    s += ai
    if m > ai:
        m = ai
if cnt % 2 == 0:
    for a in A:
        ans = s
else:
    ans = s - 2*m
print(ans)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n;
    cin >> n;
    vector<long long> ds;
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ds.push_back(i);
            if (n / i != i) {
                ds.push_back(n / i);
            }
        }
    }
    long long best_dist = n-1;
    for (auto d : ds) {
        best_dist = min(best_dist, d + n/d - 2);
    }
    cout << best_dist << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int answer = 0;
		int city_number = sc.nextInt();
		int start = sc.nextInt();
		if (city_number == 1) {
			System.out.println(Math.abs(sc.nextInt() - start));
			return;
		}

		for (int i = 0; i < city_number - 1; i++) {
			//System.out.println(answer);
			if (i == 0) {
				answer = gcd(Math.abs(sc.nextInt() - start), Math.abs(sc.nextInt() - start));
				continue;
			}
			answer = gcd(answer, Math.abs(sc.nextInt() - start));
		}
		System.out.println(answer);
	}

	private static int gcd(int a, int b) {
		//大小関係チェック
		if (b > a) {
			int tmp2 = 0;
			tmp2 = b;
			b = a;
			a = tmp2;
		}

		//ユークリッドの互除法
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}
}


Measured memory_bytes: 47980
#include <bits/stdc++.h>
 
//g++ -std=c++11
//g++ -std=c++1z 

using namespace std;

typedef long long ll;
const long long INF = 1e18+10;

int main() {
 
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
 
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int aux = -1;
    while(a>0 && c>0) {
    	if(aux == -1)
    		c-=b;
    	else
    		a-=d;
    	aux*=-1;
    }

    if(c <= 0)
    	cout << "Yes" << endl;
    else
    	cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(val) cerr << "Value " << #val << " : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ld epsilon = 10e-9;
const ll nax = 0;
ll s, c;
	
int main(void){
	IOS
	cin >> s >> c;
	ll ans;
	if(c>2*s){
		ans=(c+2*s)/4;
	}
	else{
		ans=min(c/2, s);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t>vec(N);
    for (int i=0; i < N; i++){
        cin >> vec.at(i);
    }

    int64_t count = 0;
    for (int i=0; i < N; i++) {
        int index = i + 1;
        if (vec[i] == index) {
            if (index == N) {
                int64_t tmp = vec[i];
                vec[i] = vec[i - 1];
                vec[i - 1] = tmp;
            }
            else
            {
                int64_t tmp = vec[i];
                vec[i] = vec[i + 1];
                vec[i + 1] = tmp;
            }
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

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

using namespace std;

bool prime[1000001];
int ans[1000001];

void erat()
{

    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i < 1000001; i++) {
        prime[i] = true;
    }

    for (int i = 2; i < 500001; i++) {
        if (prime[i]) {
            for (int j = 2; j*i < 1000001; j++) {
                prime[i*j] = false;
            }
        }
    }
}

void solve()
{
    ans[0] = 0;
    for (int i = 1; i < 1000001; i++) {
        ans[i] = 1;
    }
    for (int i = 7; i < 1000001; i++) {
        if (prime[i]) {
            for (int j = 2; i*j < 1000001; j++) {
                ans[i*j] = 0;
            }
            ans[i] = 0;
        }
    }
    for (int i = 1; i < 1000001; i++) {
        ans[i] += ans[i-1];
    }
}

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

    erat();
    solve();

    while (m) {
        cin >> n;
        cout << ans[n] - ans[m-1] << endl;
        cin >> m;
    }
    return 0;
}

Measured memory_bytes: 6044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    char S;
    cin >> S;
    if(S < 'a'){
        cout << 'A' << "\n";
    }else{
        cout << 'a' << "\n";
    }
}

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

int main(){
	int X, Y, ans = 0;
	scanf("%d%d", &X, &Y);
	if(X <= 3){
		ans += (4 - X) * 100000;
	}
	if(Y <= 3){
		ans += (4 - Y) * 100000;
	}
	if(X == 1 && Y == 1){
		ans += 400000;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if (H==0 and W==0):
        break
    for i in range(H):
        for j in range(W):
            if (H==0 and W==0):
                break
            elif(i==0):
                print("#", end="")
            elif(j==0):
                print("#", end="")
            elif(j==W-1):
                print("#", end="")
            elif(i==H-1):
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N, K, C;
  string S;
  cin >> N >> K >> C;
  cin >> S;
  vector<int> vv;
  int p = S.size() - 1;
  int count = 0;
  while(p >= 0) {
    if(S[p] == 'o') {
      vv.push_back(p);
      count++;
      if(count == K) break;
      p = p - C - 1;
      continue;
    }
    p--;
  }

  vector<int> v;
  rep(i, vv.size()) {
    v.push_back(vv[vv.size()-1-i]);
  }

  // vector<int> v2;
  // int ind = 0;
  // count = 0;
  // while(ind < S.size()) {
  //   if(S[ind] == 'o') {
  //     v2.push_back(ind);
  //     count++;
  //     if(count == K) break;
  //     ind -= 4;
  //     continue;
  //   }
  //   ind--;
  // }

  // rep(i, K) {
  //   if(v[i] == v2[i]) {
  //     cout << i+1 << endl;
  //   }
  // }

  v.push_back(0);


  int start = 0;
  int end = v[0];
  int cnt = 0;
  int ns = 0;
  int ne = v[0];
  do {
    start = ns;
    end = ne;
    bool f = false;
    for(int i = start; i < end; i++) {
      if(S[i] == 'o') {
        cnt++;
        ns = i + C + 1;
        ne = v[cnt];
        f = true;
        break;
      }
    }
    if(!f) {
      cout << end + 1 << endl;
      cnt++;
      ns = end + C + 1;
      ne = v[cnt];
    }
  } while(cnt < v.size()-1);
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    map<string, bool> m;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (!m[s]) ans++;
        m[s] = 1;
    }
    cout << ans << "\n";
}


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

using namespace std;
#define ll long long
deque<ll>s , f, d , k;

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i<n; i++){
        int p; cin >> p;
        s.push_back(p);
    }
    sort(s.begin(),s.end());
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    f.push_back(s[0]);f.push_back(s[n-1]);
    s.pop_back();s.pop_front();
    while(s.size()>0){
        ll num = f.front();
        ll num2 = f.back();
        int sz = s.size();
        ll k = s[0];
        ll k2 = s[sz-1];
        ll nm = abs(k-num);
        ll nm2 = abs(k-num2);
        ll nm3 = abs(k2-num);
        ll nm4 = abs(k2-num2);
        vector<ll>v;
        v.push_back(nm);v.push_back(nm2);v.push_back(nm3);v.push_back(nm4);
        sort(v.begin(),v.end());
        ll p = v[3];
        if(p == nm){
            f.push_front(k);
            s.pop_front();
        }
        else if(p==nm2){
            f.push_back(k);
            s.pop_front();
        }
        else if(p==nm3){
            f.push_front(k2);
            s.pop_back();
        }
        else{
            f.push_back(k2);
            s.pop_back();
        }
    }
    ll ans = 0;
    for(int i = 0; i<n-1; i++)ans += abs(f[i]-f[i+1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
int main(){
  int N;
  cin>>N;
  vector<vector<int>> A(2,vector<int>(N));
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    A[0][i] = a;
    A[1][i] = -b;
  }
  vector<P> C(N);
  for(int i=0;i<N;i++)
    C[i] = {A[0][i] - A[1][i],i};
  sort(C.begin(),C.end(),greater<P>());
  ll ans = 0;
  for(int i=0;i<N;i++)
    ans += A[i%2][C[i].second];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2552
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

a = readints()
a[0], a[1] = a[1], a[0]
a[0], a[2] = a[2], a[0]
for i in range(len(a)):
    print(int(a[i]), end=' ')


Measured memory_bytes: 3832
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val a = Array(n) { 0 }
    val b = Array(n) { 0L }

    for (i in 0 until n) {
        a[i] = sc.nextInt()
        b[i] = sc.nextLong()
    }

    val numbers = possibleNumbers(k)
    var best = -1L

    for (number in numbers) {
        best = Math.max(best, solve(number, a, b))
    }
    println(best)

}

fun solve(num: Int, a: Array<Int>, b: Array<Long>): Long {
    var sum = 0L
    for (i in 0 until a.size) {
        if (num or a[i] == num) {
            sum += b[i]
        }
    }
    return sum
}

fun possibleNumbers(k: Int): List<Int> {
    val list = mutableListOf<Int>()
    list.add(k)

    var x = k
    for (bit in 0..31) {
        if (x shr bit and 1 == 1) {
            list.add(x xor (1 shl bit))
        }
        x = x or (1 shl bit)
    }

    list.add(0)
    return list
}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}




Measured memory_bytes: 52184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll solve(int n, ll x){
    if(n==0)  return 1;
    ll len = (1LL<<(n+2)) - 3;
    ll num = (1LL<<(n+1)) -1;
    ll cent = num ;
   // cout<<cent<<endl;
    ll len2 = (1LL<<(n+1)) - 3;
    if(x==1) return 0;
    else if(x<cent) return solve(n-1,x-1);
    else if(x==cent) return solve(n-1,len2)+1;
    else if(len> x&&x<len) return solve(n-1,len2) + 1 + solve(n-1, x-cent); 
    else if(len ==x ) return 2*solve(n-1,len2) + 1; 
    else return num;
}
int main(void){
    int n; cin>>n;
    ll x; cin>>x;
    
    cout<< solve(n,x) <<endl;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int gcd(int a, int b){
  if(a < b){
    int tmp = a;
    a = b;
    b = tmp;
  }
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}

int main(){
  string S;
  cin >> S;
  ll ans = 0;
  int cnt = 0;
  REPR(i, S.length()-1){
    if(S[i] == 'B'){
      ans += S.length()-i-1-cnt;
      cnt++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-07-24 12:45:36
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , A[MAXN] , dp[MAXN] , prv[MAXN];

vector<ll> solve(vector<ll> vec){
    vector<ll> ans;
    int cnt = 0;
    while(n > 1){
        //cnt++;
        //if(cnt > 20)    break;
        //cout << SZ(vec) << sep << n << endl;
        //cout.flush();
        if(vec.back() != n){
            ans.push_back(n); n--;
            //cout << "1" << endl;
            continue;
        }
        if(vec[0] != 1){
            ans.push_back(1); n--;
            for(int i = 0 ; i < SZ(vec) ; i++)  vec[i]--;
            //cout << "2" << endl;
            continue;
        }
        if(vec[SZ(vec) - 2] == n - 2){
            ans.push_back(n - 1); n -= 2; vec.pop_back();
            //cout << "3" << endl;
            continue;
        }
        ans.push_back(n - 2); n -= 2; vec.pop_back(); vec.push_back(n);
        //cout << "4" << endl;
    }
    //cout << "==========\n";
    return ans;
}

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

    cin >> n;
    for(int i = 2 ; i <= n + 1 ; i++)   cin >> A[i];
    for(int i = 2 ; i <= n + 1 ; i++){
        dp[i] = -INF;
        for(int j = 0 ; j < i ; j++){
            if(i % 2 == j % 2){
                if(dp[j] + A[i] > dp[i])    dp[i] = dp[j] + A[i] , prv[i] = j;
            }
        }
    }
    ll x = 2;
    for(int i = 2 ; i <= n + 1 ; i++)   if(dp[x] < dp[i]) x = i;
    cout << dp[x] << endl;
    vector<ll> res;
    while(x >= 2){
        res.push_back(x - 1);
        x = prv[x];
    }
    reverse(all(res));
    //for(int i : res)    cout << i << endl;
    //return 0;
    vector<ll> ans = solve(res);
    cout << SZ(ans) << endl;
    for(int i : ans)    cout << i << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;


int main(){
    double r;
    cin >> r;
    cout << 6.28*r << endl;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


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

Measured memory_bytes: 3628
x, y = map(int, input().split())
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
if A.count(x) * A.count(y) + B.count(x) * B.count(y):
    print("Yes")
else: print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
int findMaxGCD(int arr[], int n) 
{ 
	// Calculating MAX in array 
	int high = 0; 
	for (int i = 0; i < n; i++) 
		high = max(high, arr[i]); 

	// Maintaining count array 
	int count[high + 1] = {0}; 
	for (int i = 0; i < n; i++) 
		count[arr[i]]++; 

	// Variable to store the 
	// multiples of a number 
	int counter = 0; 

	// Iterating from MAX to 1 
	// GCD is always between 
	// MAX and 1. The first 
	// GCD found will be the 
	// highest as we are 
	// decrementing the potential 
	// GCD 
	for (int i = high; i >= 1; i--) 
	{ 
		int j = i; 
	counter = 0; 
	
		// Iterating from current 
		// potential GCD 
		// till it is less than 
		// MAX 
		while (j <= high) 
		{ 
			// A multiple found 

			if(count[j] >=2) 
			return j; 

		else if (count[j] == 1)		 
				counter++;		 

			// Incrementing potential 
			// GCD by itself 
			// To check i, 2i, 3i.... 
			j += i; 

			// 2 multiples found, 
			// max GCD found 
			if (counter == 2)		 
				return i; 
		} 
	} 
} 

// Driver code 
int main() 
{ 
	int n,g=0;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i],g=__gcd(g,arr[i]);
	int x=findMaxGCD(arr, n); 
	if(x==1) {
	    cout<<"pairwise coprime";
	} else if (g==1) {
	    cout<<"setwise coprime";
	} else {
	    cout<<"not coprime";
	}

	return 0; 
} 


Measured memory_bytes: 11376
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N;

int main(){
	cin >> N;

	int s = N%2?N:N+1;
	vector<pair<int, int>> ans, cmp;
	for(int u=1; u<=N/2; u++){
		cmp.push_back({u, s-u});
	}
	if(N%2){
		cmp.push_back({0, N});
	}
	for(int i=0; i<cmp.size(); i++){
		auto next = cmp[(i+1)%cmp.size()];
		if(cmp[i].first>0&&next.first>0){
			ans.push_back({cmp[i].first, next.first});
		}
		if(cmp[i].first>0){
			ans.push_back({cmp[i].first, next.second});
		}
		if(next.first>0){
			ans.push_back({cmp[i].second, next.first});
		}
		ans.push_back({cmp[i].second, next.second});
	}

	for(auto &p: ans){
		if(p.first > p.second) swap(p.first, p.second);
	}
	sort(ans.begin(), ans.end());
	auto last = unique(ans.begin(), ans.end());
	ans.resize(last-ans.begin());

	cout << ans.size() << endl;
	for(auto p: ans){
		cout << p.first << " " << p.second << endl;
	}

	return 0;
}


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

int main()
{
  int b,a;
  cin >> a;
  cin >> b;
  if((a*b)%2==0)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> p(N);
    REP(i,N)p[i] = in();
    int count = 0;
    REP(i,N)if(p[i] != i+1)count++;
    cout << (count > 2 ? "NO" : "YES") << "\n";
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

import org.omg.Messaging.SyncScopeHelper;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new ABC106().doIt();
	}
	class ABC106{
		void doIt(){
			int N = sc.nextInt();
			int M = sc.nextInt();
			int Q = sc.nextInt();
			int station[][] = new int[N+10][N+10];
			int cnt[][] = new int[N+10][N+10];
			for(int i = 0;i < M;i++) {
				int L = sc.nextInt();
				int R = sc.nextInt();
				station[L][R]++;
			}
			for(int i = N + 1;i >= 0;i--) {
				for(int j = 0;j < N+1;j++) {
					station[i][j] = station[i][j] + station[i+1][j];
				}
			}
			for(int i = N + 1;i >= 0;i--) {
				for(int j = 0;j < N+1;j++) {
					station[i][j+1] = station[i][j+1] + station[i][j];
				}
			}
			for(int i = 0;i < Q;i++) {
				int qs = sc.nextInt();
				int qg = sc.nextInt();
				System.out.println(station[qs][qg]);
			}
		}
	}
}


Measured memory_bytes: 165840
mod = 10**9+7
n,m = map(int,input().split())
fac = [1]*(m+1)
for i in range(1,m):
    fac[i+1] = fac[i] * (i+1) % mod
def inv(x):
    return pow(x,mod-2,mod)
def cmb(n,k,mod):
    return fac[n]*inv(fac[k])*inv(fac[n-k])
def per(n,k,mod):
    return fac[n]*inv(fac[n-k])
ans = 0
for k in range(n+1):
    ans += cmb(n,k,mod)*(-1)**k*per(m,k,mod)*per(m-k,n-k,mod)**2
    ans %= mod
print(ans)

Measured memory_bytes: 92184
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int main()
{
  int n;
  cin >> n;
  
  // 各マスに行くためのコストを格納する
  vector<int> dp(n);
  
  vector<int> h(n);
  for (int i = 0; i < n; i ++)
    cin >> h.at(i);
  
  // 1マス目は0
  dp.at(0) = 0;
  
  // 2マス目には最初のマスから行くパターンのみ
  dp.at(1) = abs(h.at(1) - h.at(0));
  
  // 3マス目以降
  for (int i = 2; i < n; i ++)
  {
    // 1マス前から移動したときの最小コストを求める
    int step1 = dp[i - 1] + abs(h.at(i) - h.at(i - 1));
    
    // 2マス前から移動したときの最小コストを求める
    int step2 = dp[i - 2] + abs(h.at(i) - h.at(i - 2));
    
    // step1, step2の最小値を求めることでi+1マス目の最小コストを求められる
    dp.at(i) = min(step1, step2);
  }
  
  // Nマス目に到達するための最小コストを出力
  cout << dp.at(n - 1) << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    COMinit();
    string S;
    ll K;
    cin >> S >> K;
    ll ans = 0, N = S.size();
    ans += COM(N-1, K) * pow(9, K);
    ans += ((S[0]-'0') - 1) * COM(N-1, K-1) * pow(9, K-1);

    if(K == 1) {
        ans++;
        cout << ans << endl;
        return 0;
    }

    string T = "";
    T += S[0];
    rep(i, N-1) T += '0';

    if(K == 2) {
        for(ll i = 1; i < N; i++) {
            string U = T;
            for(char x = '1'; x <= '9'; x++){
                U[i] = x;
                if(U <= S) ans++;
            }
        }
        cout << ans << endl;
        return 0;
    }

    for(ll i = 1; i < N; i++) {
        for(ll j = i+1; j < N; j++) {
            string U = T;
            for(char x = '1'; x <= '9'; x++) for(ll y = '1'; y <= '9'; y++) {
                U[i] = x, U[j] = y;
                if(U <= S) ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 12160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		char[] cs = s.toCharArray();
		int cnt = 0;

		if (String.valueOf(cs[a]).equals("-")) {
			for (int i = 0; i < a; i++) {
				if (Character.isDigit(cs[i])) {
					cnt++;
				}
			}
			for (int i = (a + 1); i <= (a + b); i++) {
				if (Character.isDigit(cs[i])) {
					cnt++;
				}
			}
			if (cnt == (a + b)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int x,y,z;
int main(){
    cin>>x>>y>>z;
    for(int i=1;i<=1000;i++){
        if(i*x%y==z){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
int n,a;
int main() {
	n=_; string s;
	cin>>s;
	for( int i=0;i<n;i++ )
		if(s[i]=='R') a++;
		else a--;
	puts(a>0?"Yes":"No");
}

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

int intAbs(int x){
	if(x<0) return x*-1;
	return x;
}

int solve(int pos,int N,int DP[],int stones[],int K=2){
	if(DP[pos]!=INF) return DP[pos];
	int ret=INF;
	if(pos>N) return INF;
	if(N==(pos+1)) return 0; 
	for(int i=1;i<=K;i++){
		if(i+pos<N){
			ret=min(ret,solve(pos+i,N,DP,stones)+intAbs(stones[pos+i]-stones[pos]));
//			cout<<pos<<","<<ret<<endl;
		}
	}
	return DP[pos]=ret;
}

int main(){
	int N;
	cin>>N;
	int bestValue[N]={};
	int stones[N];
	for(int i=0;i<N;i++){
		cin>>stones[i];
		bestValue[i]=INF;
	}
	cout<<solve(0,N,bestValue,stones)<<"\n";
	return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);

    if((A==5 && B==5 && C==7) || (A==5 && B==7 && C==5) || (A==7 && B==5 && C==5))
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int n, a[MAXN], b[3], c;

signed main()
{
    for(int i = 0; i < 3; i++){
        cin >> a[i];
    }
    b[0] = abs(a[0] - a[1]);
    b[1] = abs(a[0] - a[2]);
    b[2] = abs(a[1] - a[2]);
    sort(b, b + 3);
    printf("%lld\n", b[0] + b[1]);


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;
//const static CELL  = -1;
 
ll digsum(ll n) {
    ll res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}
 
int main(){
    ll N, N_; cin >> N; N_ = N;
    ll N_SUM = digsum(N);
    ll dig = 0;
    while(N_ != 0) {
        dig++;
        N_ /= 10;
    }
    ll d = N / pow(10, dig-1);
    ll ans = 9*(dig-1);
    ans += d-1;
    cout << max(ans, N_SUM) << endl;
 
 
 
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF 100000000
using namespace std;

struct edge { long v, c, h, r; };

struct state {
  long n, p, c, t;
  bool operator<(const state s) const {
    return c > s.c;
  }
};

long N, M, H, K, S, T, P;
vector<edge> E[500];
long a, b, c, h, r;
long l[500], d[500], k[500][500];
long dp1[500], dp2[500][500][30];

int main(void) {
  while(cin >> N >> M >> H >> K, N || M || H || K) {
    REP(i, 0, N) E[i].clear();
    REP(i, 0, M) {
      cin >> a >> b >> c >> h >> r; a--; b--; r--;
      E[a].push_back((edge) { b, c, h, r });
      E[b].push_back((edge) { a, c, h, r });
    }
    cin >> S >> T >> P; S--; T--;
    REP(i, 0, P) {
      cin >> l[i] >> d[i];
      REP(j, 0, l[i]) {
        cin >> k[i][j];
        k[i][j]--;
      }
    }

    REP(i, 0, 1 << K) dp1[i] = INF;
    dp1[0] = 0;
    REP(i, 0, 1 << K) {
      REP(j, 0, P) {
        long s = 0;
        REP(m, 0, l[j]) s |= (1 << k[j][m]);
        dp1[i | s] = min(dp1[i | s], dp1[i] + d[j]);
      }
    }

    priority_queue<state> q;
    REP(i, 0, N) REP(j, 0, 1 << K) if(dp1[j] < INF) q.push((state) { S, j, dp1[j], 0 });
    REP(i, 0, N) REP(j, 0, 1 << K) REP(m, 0, 30) dp2[i][j][m] = INF;

    long ans = -1;
    while(q.size()) {
      state c = q.top();
      q.pop();

      if(c.n == T) {
        ans = c.c;
        break;
      }

      if(dp2[c.n][c.p][c.t] <= c.c) continue;
      dp2[c.n][c.p][c.t] = c.c;

      REP(i, 0, E[c.n].size()) {
        long nn = E[c.n][i].v;
        long np = c.p;
        long nc = (c.p & (1 << E[c.n][i].r)) ? c.c : c.c + E[c.n][i].c;
        long nt = c.t + E[c.n][i].h;
        if(nt <= H && dp2[nn][np][nt] > nc) q.push((state) { nn, np, nc, nt });
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 17860
import scala.collection.mutable.ListBuffer

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val Vs, Es = sc.nextInt()
    val E = Array.fill[Boolean](Vs, Vs)(false)
    (0 until Es) foreach { _ =>
      val u, v = sc.nextInt()
      E(u)(v) = true
    }
    val visited = new Array[Boolean](Vs)

    val topologicalSorted = new ListBuffer[Int]()
    // 全ての頂点からスタートし, uから繋がっている全てのvについて探索, 帰ってくるタイミングで
    def dfs(u: Int): Unit =
      if (!visited(u)) { // 訪れていない時
        visited(u) = true // 訪れた.
        (0 until Vs) foreach { v => // 全ての頂点について
          if (E(u)(v)) { // 辺が繋がっているv
            dfs(v) // vについてdfs
          } // 辺が繋がっていない頂点には移動しない.
        }
        topologicalSorted.prepend(u)
      } // 訪れているなら何もしない.

    (0 until Vs) foreach dfs

    topologicalSorted.foreach(println)
  }
}



Measured memory_bytes: 216760
#include<stdio.h>

int main(void)
{
    int n;
    scanf("%d",&n);
    
    char s[3][100];
    for(int i=0;i<3;i++){
        scanf("%s",s[i]);
        //printf("%s\n",s[i]);
        
    }
    
    int count=0;
    for(int i=0;i<n;i++){
        int tm=0;
        if(s[0][i]!=s[1][i])tm++;
        if(s[0][i]!=s[2][i])tm++;
        if(s[1][i]!=s[2][i])tm++;
        if(tm)count+=tm-1;
    }
    
    printf("%d\n",count);
    
    return 0;
}

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

int main() {
	string in_st;
	int i,size, n;
	bool atoz[26] = { false };
	cin >> in_st;
	size = in_st.size();
	char a;
	for (i = 0; i < size; i++) {
		atoz[in_st[i] - 'a'] = true;
	}

	for (i = 0; i < 26; i++) {
		if (atoz[i] == false) {
			cout << (char)('a' + i) << endl;
			return 0;
		}
	}

	cout << "None" << endl;


}

Measured memory_bytes: 512
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(str,input().split())
c = [int(b[i]) for i in range(n)]
d = [[a[i],c[i],i+1] for i in range(n)]
d.sort(key = lambda x:x[0])
cnt = 0
d[0].append(0)
for i in range(1,n):
    if d[i][0] != d[i-1][0]:
        cnt += 1
    d[i].append(cnt)
d.sort(key = lambda x:x[3]*10**3-x[1])
for i in range(n):
    print(d[i][2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - w + 1) * (n - h + 1) << endl;
}

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

using namespace std;

typedef long long int ll;

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

  int n, a, b;
  cin >> n >> a >> b;
  vector < int > h(n);
  for(int i = 0; i < n; i++) cin >> h[i];

  sort(h.begin(), h.end());

  int lo = 0, hi = 1e9 + 5;
  ll ans = LLONG_MAX;
  while(lo <= hi){
    ll mid = (hi - lo) / 2 + lo;
    ll c = mid * b;
    ll req = 0;
    for(int i = 0; i < n; i++){
      if(h[i] > c){
        req += (h[i] - c + a - 1 - b) / (a - b);
      }
    }

    if(req <= mid){
      hi = mid - 1;
      ans = min(ans, mid);
    }else{
      lo = mid + 1;
    }
  }

  cout << ans << '\n';
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
    string S;
    cin >> S;
    int stock[26];
    const int a = int('a');
    REP(i,26){
        stock[i]=1;
    }
    REP(i,S.length()){
        stock[int(S[i])-a]--;
    }
    bool flag;
    string ans;
    REP(i,26){
        if(stock[i]==1){
            ans = S + char(a+i);
            flag = false;
            break;
        }else{
            flag = true;
        }
    }
    if(flag){
        for(int i=S.length()-1;i>=0;--i){
            stock[int(S[i])-a]++;
            REP(j,26){
                if(j>int(S[i])-a){
                    if(stock[j]==1){
                        ans = S.substr(0,i) + char(a+j);
                        flag = false;
                        break;
                    }
                }
            }
            if(!flag){
                break;
            }
        }
    }
    if(flag){
        cout << -1;
    }else{
        cout << ans;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int n,bobNum = 0,aliceNum = 0;
	cin >> n;
	vector<int>a(n);
	for (int& x : a)cin >> x;
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		(i % 2 == 0 ? bobNum += a[i] : aliceNum += a[i]);
	}
	cout << abs(bobNum - aliceNum) << endl;
} 


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N;
  while(cin >> N&&N){
    int arr[N];
    for(int i=0;i<N;i++)cin>>arr[i];
    for(int i=0;i<N;i++){
      int j;
      for(j=i+1;j<N;j++){
        if(arr[j-1]+1!=arr[j]) break;
      }
      if(i)cout<<" ";cout<<arr[i];
      if(j>i+1){
        cout<<'-'<<arr[j-1];
        i=j-1;
      }
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$sum = 0;
$len = $b - $a + 1;
if($a % 2 == 1){$sum^=$a;$len--;}
if($b % 2 == 0){$sum^=$b;$len--;}
if(floor($len / 2) % 2 == 1)$sum^=1;
echo $sum;


Measured memory_bytes: 4604
#include<stdio.h>
int main()
{
	int n,a,min=-1,sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(a<min||min==-1)
		{
			min=a;
			sum++;
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

int b[25000],c[25000];

    int main(){
      int n;
      cin >> n;
      int a[2][n];
      rep(i,2){
       rep(j,n){
        cin >> a[i][j]; 
       }
      }
      ll ans=0;
      rep(i,n){
        ll score=0;
        rep(j,i+1)score+=a[0][j];
        for(int j=i;j<n;j++)score+=a[1][j];
        ans=max(ans,score);
      }
      cout << ans << endl;
      return 0;}

Measured memory_bytes: 256
open System

[<EntryPoint>]
let main argv =

    let S = Console.ReadLine().ToCharArray() |> Array.toList
    let T = Console.ReadLine().ToCharArray() |> Array.toList

    let mutable count = 0
    let mutable current = 0
    List.iter (fun x -> if x = T.Item(current) then 
                            count <- count + 1
                        current <- current + 1) S

    printfn "%d" count

    0


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

int solve(int N, int M, int Q, int maximum, vector<int> &current,
          const vector<int> &a, const vector<int> &b, const vector<int> &c,
          const vector<int> &d) {
  if ((int)current.size() == N) {
    int score = 0;
    for (int i = 0; i < Q; i++) {
      if (current[b[i]] - current[a[i]] == c[i]) {
        score += d[i];
      }
    }
    return score;
  }
  int ans = -1;
  for (int i = maximum; i <= M; i++) {
    vector<int> current_copy(current);
    current_copy.push_back(i);
    ans = max(ans, solve(N, M, Q, i, current_copy, a, b, c, d));
  }
  return ans;
}

int main(void) {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  vector<int> current;
  cout << solve(N, M, Q, 1, current, a, b, c, d) << endl;

  return 0;
}

Measured memory_bytes: 3628