akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;
typedef long long ll;
double *dp;


void swap(int* a, int* b)
{
	int t = *a;
	*a = *b;
	*b = t;
}

int partition(int array[],int array2[], int l, int r) {
	int pivot = array[r];
	int i = (l - 1);

	for (int j = l; j <= r - 1; j++) {
		if (array[j] <= pivot) {
			i++;
			swap(&array[i], &array[j]);
			swap(&array2[i], &array2[j]);
		}
	}
	swap(&array[i + 1], &array[r]);
	swap(&array2[i + 1], &array2[r]);
	return (i + 1);
}

void quickSort(int array[], int array2[],int l, int r) {
	if (l < r) {
		int pivot = partition(array,array2, l, r);
		quickSort(array,array2, l, pivot - 1);
		quickSort(array,array2, pivot + 1, r);
	}
}



void solve(){
	
	int  N;
	int *A,*B;
	cin >> N;
	A = new int[N];
	B = new int[N];
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		B[i] = i+1;
	}
	quickSort(A, B, 0, N - 1);
	for (int i = 0;i < N;i++)cout << B[i] << " ";
	
}


int main() {
	solve();

}

Measured memory_bytes: 1536
import sys
input = sys.stdin.readline
import itertools

"""
A -> BB -> AAAA -> A とできるので、操作は可逆。
全部 A, AA, AAA のどれかにできる
A の個数 + 2 * (B の個数) mod 3が等しいことと同値
"""

convert = {'A':1, 'B':2}
S = [convert[x] for x in input().rstrip()]
T = [convert[x] for x in input().rstrip()]

Scum = [0] + list(itertools.accumulate(S))
Tcum = [0] + list(itertools.accumulate(T))

Q = int(input())
answer = []
for _ in range(Q):
    a,b,c,d = map(int,input().split())
    x = Scum[b] - Scum[a-1]
    y = Tcum[d] - Tcum[c-1]
    answer.append('YES' if x % 3 == y % 3 else 'NO')

print('\n'.join(answer))

Measured memory_bytes: 14336
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		String s = in.next();
		int[] count = new int[n+1];
		for(int i=0;i<n-1;i++) {
			count[i+1] += count[i];
			if(s.charAt(i)=='A' && s.charAt(i+1)=='C') {
				count[i+1]++;
			}
		}
		for(int i=0;i<q;i++) {
			int l = in.nextInt();
			int r = in.nextInt();
			System.out.println(count[r-1]-count[l-1]);
		}
		in.close();

	}

}

Measured memory_bytes: 66996
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,i,O[100000] = {},E[100000] = {};scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);a--;
    if(i%2==0) O[a]++;
    else E[a]++;
  }
  if(max_element(O,O+100000)-O != max_element(E,E+100000)-E){
    printf("%d\n",n-*max_element(O,O+100000)-*max_element(E,E+100000));
    return 0;
  }
  sort(O,O+100000,greater<int>());
  sort(E,E+100000,greater<int>());
  printf("%d\n",n-O[0]-max(O[1],E[1]));
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int a[1010], b[1010], c[1010];

int d[110][110];

bool check(int idx) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d[i][a[idx]] + d[b[idx]][j] + c[idx] == d[i][j] ||
                d[i][b[idx]] + d[a[idx]][j] + c[idx] == d[i][j])
                return false;
        }
    }
    return true;
}

void warshall_floyd() {
    for (int k = 0; k < n; k++)
	for (int i = 0; i < n; i++)
	    for (int j = 0; j < n; j++)
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int solve() {
    for (int i = 0; i < n; i++) {
        fill_n(d[i], n, inf);
        d[i][i] = 0;
    }
    for (int i = 0; i < m; i++) {
        d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    }
    warshall_floyd();

    int res = 0;
    for (int i = 0; i < m; i++) {
        res += check(i);
    }
    return res;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 384
def main(n):
    c=[[0]*10 for _ in range(10)]
    for k in range(1,n+1):
        n=str(k)
        i = int(n[0])
        j = int(n[-1])
        c[i][j] += 1
    ans =0
    for i in range(10):
        for j in range(10):
            ans+=c[i][j]*c[j][i]
    print(ans)
             
if __name__=='__main__':
    main(int(input()))

Measured memory_bytes: 3064
#include <iostream>
#include <stdint.h>

using namespace std;

int32_t main()
{
  char e;

  cin >> e;
  if(e == 'a' || e == 'i' || e == 'u' || e == 'e' || e == 'o'){
    cout << "vowel" << endl;
  } else{
    cout << "consonant" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
const int MAXN = 1e5 + 5;

int main()
{
	zapp;
	ll n, i = 1;
	cin >> n;
	vl a;
	ll num = 0;
	a.pb(0);
	while (num < 1000000000000001)
	{
		num += pow(26, i);
		i++;
		a.pb(num);
	}

	ll len;
	for (i = 0; i < a.size() - 1; i++)
	{
		if (n > a[i] && n <= a[i + 1])
		{
			len = i + 1;
		}
	}

	string ans = "";

	for (i = 0; i < len; i++)
	{
		ll rem = (n - 1) % 26;
		ans.pb('a' + rem);
		n -= rem;
		n /= 26;
	}

	reverse(ans.begin(), ans.end());

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 4064
_n, m = gets.split.map(&:to_i)
# [](l,r)
cards = Array.new(m) { gets.split.map(&:to_i) }

# (l,r)
l, r = cards.reduce do |c0, c1|
  l0, r0 = c0
  l1, r1 = c1
  [[l0, l1].max, [r0, r1].min]
end
p((l..r).size)


Measured memory_bytes: 9596
#include <stdio.h>

int main()
{
  int i;
  int j;
  int sum;
  int a[3][3] = {0};
  int check[3][3] = {0};
  int b;
  
  i = -1;
  while (++i < 3)
    scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);

  while (scanf("%d", &b) != EOF)
  {
	i = -1;
    while (++i < 3)
    {
      j = -1;
      while (++j < 3)
      {
    	if (a[i][j] == b)
          check[i][j] = 1;
      }
    }
  }

  // 横方向
  i = 0;
  while (i < 3)
  {
    j = 0;
    sum = 0;
  	while (j < 3)
    {
      sum += check[i][j];
      j++;
    }
    if (sum == 3)
    {
      printf("Yes");
      return (0);
    }
    i++;
  }
  
  // 縦方向
  j = 0;
  while (j < 3)
  {
    i = 0;
    sum = 0;
  	while (i < 3)
    {
      sum += check[i][j];
      i++;
    }
    if (sum == 3)
    {
      printf("Yes");
      return (0);
    }
    j++;
  }
  
// 斜め方向 右上から左下
  sum = 0;
  i = 0;
  while (i < 3)
  {
    sum += check[i][i];
    i++;
  }
  if (sum == 3)
  {
    printf("Yes");
    return (0);
  }

  
// 斜め方向 右上から左下
  sum = 0;
  i = 0;
  while (i < 3)
  {
    sum += check[2 - i][i];
    i++;
  }
  if (sum == 3)
  {
    printf("Yes");
    return (0);
  }
  
  printf("No");
  return (0); 
}


Measured memory_bytes: 128
#include <stdio.h>

int sumDigits(int n) {
  int s = 0;
  while (1) {
    if (n / 10 == 0) {
      s += n;
      break;
    }
    s += n % 10;
    n = n / 10;
  }
  return s;
}

int main() {
  // your code here...
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);

  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int r = sumDigits(i);
    if (a <= r && r <= b) {
      sum += i;
    }
  }

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

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  string a,b;
  cin >> a >> b;
  for(int i = 0; i < a.size(); ++i)
  {
    cout << a[i] << b[i];
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define fastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define scan(a) scanf("%d", &a)
#define scanll(a) scanf("%lld", &a)
#define scanD(a) scanf("%lf", &a)
#define print(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printD(a) printf("%lf\n", a)
#define printTwo(a) printf("%.2lf\n", a);
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

/* ----------------------------------------------------------------------------------- */

int arr[5];

void solve() {
	string str;
	cin >> str;
	if(str == "AC") {
		arr[1]++;
	} else if(str == "WA") {
		arr[2]++;
	} else if(str == "TLE") {
		arr[3]++;
	} else {
		arr[4]++;
	}
}

int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif

	// solve();

	__test {
		solve();
	}

	printf("AC x %d\n", arr[1]);
	printf("WA x %d\n", arr[2]);
	printf("TLE x %d\n", arr[3]);
	printf("RE x %d\n", arr[4]);

	showTime;
	return 0;
}




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

int main() {
  
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  
  string word = "";
  for (int i = 0; i < S.size(); i++) {
    word += S.at(i);
    if (word == "maerd") word = "";
    else if (word == "remaerd") word = "";
    else if (word == "esare") word = "";
    else if (word == "resare") word = "";
  }
  
  if (word == "") cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    vector<int> a(n);

    for (auto i = 0; i < n; i++)
    {
        int ti, ai;
        cin >> ti >> ai;
        t[i] = ti;
        a[i] = ai;
    }

    long long anst = t[0];
    long long ansa = a[0];

    for (auto i = 1; i < n; i++)
    {
        long long x = max((anst + t[i] - 1) / t[i], (ansa + a[i] - 1) / a[i]);
        anst = t[i] * x;
        ansa = a[i] * x;
    }

    cout << anst + ansa << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        String s = br.readLine();
        String t = br.readLine();
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i < s.length(); i++){
            if(i + t.length() > s.length()) continue;
            int count = 0;
            for(int j = 0; j < t.length(); j++){
                if(s.charAt(i+j) != t.charAt(j)){
                    count++;
                }
            }
            ans = Math.min(ans, count);
        }
        sb.append(ans);
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


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

int main() {
    int N, AC = 0, WA = 0, TLE = 0, RE = 0;
    string S;
    cin >> N;
    while (N--) {
        cin >> S;
        if (S == "AC") AC++;
        else if (S == "WA") WA++;
        else if (S == "TLE") TLE++;
        else RE++;
    }
    cout << "AC x " << AC << endl << "WA x " << WA << endl << "TLE x " << TLE << endl << "RE x " << RE << endl;
    return 0;
}


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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)
#define sz(s) ((int) (s).size())

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    int k;
    cin >> k;
    cout << a[k - 1];
    return 0;
}

Measured memory_bytes: 256
N = int(input())
R = []
for i in range(N):
	X,L = map(int,input().split())
	R.append((X+L,X-L))
R.sort()
ans = 0
right = None
for x in R:
	l,r = x[1], x[0]
	if right == None:
		ans += 1
		right = r
	else:
		if l >= right:
			ans += 1
			right = r

print(ans)

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

int main(){
    unsigned long long n; cin >> n;
    if (n == 1){
        cout << 0 << endl;
    } else {
        cout << setprecision(100000) << (n * (n - 1)) / 2 << endl;
    }
    return 0;
}

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

using namespace std;
int main(){
    long long n,au,sum=0; cin>> n;
    au=n;
    while(au){
        sum+=au%10;
        au/=10;
    }
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int n, a, b;
int fact[300005];
long long k;
const int MOD = 998244353;
inline int invmod(int x){
    int p = MOD - 2, aux = x, ans = 1;
    for(int i = 0; (1 << i) <= p ; ++i){
        if((1 << i) & p) ans = (1LL * ans * aux) % MOD;
        aux = (1LL * aux * aux) % MOD;
    }
    return ans;
}
inline int comb(int n, int k){
    int ans = fact[n];
    int c1 = invmod(fact[n - k]);
    int c2 = invmod(fact[k]);
    ans = (1LL * ans * c1) % MOD;
    ans = (1LL * ans * c2) % MOD;
    return ans;
}
int main()
{
    scanf("%d%d%d%lld", &n, &a, &b, &k);
    fact[0] = fact[1] = 1;
    for(int i = 2; i <= n ; ++i)
        fact[i] = (1LL * fact[i - 1] * i) % MOD;

    int Sol = 0;
    for(int t = 0; t <= n ; ++t){
        int i = t;
        long long k2 = k - 1LL * i * a;
        if(k2 < 0) break ;
        if(k2 % b) continue ;
        long long j = k2 / b;
        if(j > n) continue ;
        Sol = (Sol + (1LL * comb(n, i) * comb(n, j)) % MOD) % MOD;
    }
    printf("%d", Sol);
    return 0;
}


Measured memory_bytes: 1408
local s=io.read():gsub("BC","D")
local counter=0
local answer=0
for i=1,#s do
    if s:byte(i)==65 then
        counter=counter+1
    elseif s:byte(i)==68 then
        answer=answer+counter
    else
        counter=0
    end
end
print(answer)

Measured memory_bytes: 3008
s = input()
n = len(s)
ans = [0]*n
i = 0
while i < n:
    cntr = 0
    cntl = 0
    while s[i] == 'R':
        cntr += 1
        i += 1
    irl = i-1
    while s[i] == 'L':
        cntl += 1
        i += 1
        if i >= n:
            break
    if (cntr + cntl)%2 == 0:
        ans[irl] = (cntr+cntl)//2
        ans[irl+1] = (cntr+cntl)//2
    elif cntr % 2 != 0:
        ans[irl] = (cntr+cntl+1)//2
        ans[irl+1] = (cntr+cntl-1)//2
    else:
        ans[irl] = (cntr+cntl-1)//2
        ans[irl+1] = (cntr+cntl+1)//2
print(*ans)
        

Measured memory_bytes: 49596
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int a, b, c, d;

int main() {
    string s;
    cin >> s;
    a = s.at(0) - '0'; b = s.at(1) - '0'; c = s.at(2) - '0'; d = s.at(3) - '0';
    bool flg = false;
    int op1, op2, op3;
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < 2; ++j) {
            for(int k = 0; k < 2; ++k) {
                int ans = a;
                if(i == 0) ans += b;
                else ans -= b;
                if(j == 0) ans += c;
                else ans -= c;
                if(k == 0) ans += d;
                else ans -= d;
                if(ans == 7) {
                    flg = true;
                    op1 = i; op2 = j; op3 = k;
                }
            }
        }
    }

    cout << a;
    if(op1 == 0) cout << '+';
    else cout << '-';
    cout << b;
    if(op2 == 0) cout << '+';
    else cout << '-';
    cout << c;
    if(op3 == 0) cout << '+';
    else cout << '-';
    cout << d << "=7" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#define inf 1000000000

using namespace std;

int N;
vector<int> G[100005];
int dist1[100005], dist2[100005];

void bfs(int dist[], int s)
{
	for(int i = 1; i <= N; i++) dist[i] = inf;
	dist[s] = 0;
	queue<int> Q;
	Q.push(s);
	
	int v;
	while(Q.size()){
		v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i]] < inf) continue;
			dist[G[v][i]] = dist[v] + 1;
			Q.push(G[v][i]);
		}
	}
}

int main(void)
{
	cin >> N;
	int a, b;
	for(int i = 1; i <= N-1; i++){
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	bfs(dist1, 1);
	bfs(dist2, N);
	
	int cnt = 0;
	for(int i = 1; i <= N; i++){
		if(dist1[i] <= dist2[i]) cnt++;
	}
	if(cnt > N-cnt) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
	
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

ll c[21];
ll t[21][50001];

int main() {
    
    ll n,m;
    ll inf = mop;
    cin >> n >> m;
    for (ll i=1;i<=m;i++){
        cin >> c[i];
    }
    for (ll i=0;i<=m;i++){
        for (ll j=0;j<=n;j++){
            if (i==0){
                t[i][j] = inf;
            }else if(j==0){
                t[i][j] = 0;
            }else{
                ll pre,post;
                pre = t[i-1][j];
                if(j-c[i]>=0){
                    post = t[i][j-c[i]] + 1;
                    t[i][j] = min(pre, post);
                }else{
                    t[i][j] = pre;
                }

            }
        }
    }
    
    cout << t[m][n] << endl;

}





Measured memory_bytes: 11296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
class uft{
private:
	int p[200010],r[200010];
public:
	int find(int x){
		if(x==p[x])return x;
		return p[x]=find(p[x]);
	}
	uft(int n){
		rep(i,n+1){
			p[i]=i;
			r[i]=1;
		}
	}
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(r[x]<r[y])p[x]=y;
		else{
			p[y]=x;
			if(x==y)r[y]++;
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
};
int n,k,l,p,q;
map<P,int>mp;
signed main(){
	cin>>n>>k>>l;
	uft a(n),b(n);
	rep(i,k){
		cin>>p>>q;
		a.unite(p,q);
	}
	rep(i,l){
		cin>>p>>q;
		b.unite(p,q);
	}
	for(int i=1;i<=n;i++){
		mp[{a.find(i),b.find(i)}]++;
	}
	cout<<mp[{a.find(1),b.find(1)}];
	for(int i=2;i<=n;i++){
		cout<<" "<<mp[{a.find(i),b.find(i)}];
	}
	cout<<endl;
    return 0;
}

Measured memory_bytes: 18176
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef vector<vector<char>> field_t;
typedef long long ll;
typedef pair<int, int> point_t;

int main()
{
	ll N,i,j,k,K;
    cin >> N;
	K=0;
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			for(k=1;k<=N;k++){
				K+=gcd(gcd(i,j),k);
			};
		}
	}
	cout <<K<< endl;
	return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <typeinfo>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;



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

	string num = a + b;

	int n = atoi(num.c_str());
	int nn = sqrt(n);

	if (nn * nn == n) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

int ans;

int main(){
  int n, l;
  cin >> n >> l;
  
  ans = n*(2*l+n-1)/2;
  if(l > 0) ans -= l;
  else if(l < 1-n) ans -= (l+n-1);
    
  cout << ans << endl;
}

Measured memory_bytes: 256
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    String s;
    std::cin >> s;

    String prev = "";
    Int ans = 0, i = 0;
    while (i < s.length()) {
        if (s.substr(i, 1) == prev) {
            if (i == s.length() - 1) {
                break;
            } else {
                prev = s.substr(i, 2);
                i += 2;
                ++ans;
            }
        } else {
            prev = s.substr(i, 1);
            i += 1;
            ++ans;
        }
    }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

Polygon reflect(Line l,Polygon p){
  FOR(i,0,p.size())p[i]=reflect(l,p[i]);
  return p;
}

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return 1;
  if(cross(a,b)<-eps)return -1;
  if(dot(a,b)<-eps)return 2;
  if(a.norm()<b.norm())return -2;
  return 0;
}

bool intersect(Line l,Segment s){
  if(ccw(l.p1,l.p2,s.p1)*ccw(l.p1,l.p2,s.p2)<0)return true;
  return false;
}

int n;
Point s;
bool used[10]={};

int check(vector<Segment> vs){
  FOR(i,1,vs.size()){
    FOR(j,0,i){
      if(intersect(Line(s,vs[j].p1),vs[i]))continue;
      if(intersect(Line(s,vs[j].p2),vs[i]))continue;
      if(intersect(Line(s,vs[i].p1),vs[j]))continue;
      if(intersect(Line(s,vs[i].p2),vs[j]))continue;
      return 0;
    }
  }
  return 1;
}

int rec(Polygon p,vector<Segment> vs){
  if(vs.size()==n)return check(vs);
  int res = 0;
  FOR(i,0,n){
    if(used[i])continue;
    used[i]=true;
    Segment e(p[i],p[(i+1)%n]);
    vs.pb(e);
    res+=rec(reflect(e,p),vs);
    vs.pop_back();
    used[i]=false;
  }
  return res;
}

int main()
{
  while(cin>>n && n){
    Polygon p;
    vector<Segment> vs;
    cin>>s.x>>s.y;
    FOR(i,0,n){
      int x,y;
      cin>>x>>y;
      p.pb(Point(x,y));
    }
    cout<<rec(p,vs)<<endl;
  }
  return 0;
}

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

const int NM_MAX = 51;
int n_road[NM_MAX] = {};

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        n_road[a]++;
        n_road[b]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << n_road[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, K);
    i64 a = 0;
    rep(i, 0, 1100000) {
        a = (a * 10) + 7;
        a %= K;
        if (a == 0) {
            print(i + 1);
            return 0;
        }
    }

    print(-1);

    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int S = a * b;
        int L = 2 * (a + b);
        System.out.println(S + " " + L);
    }
}


Measured memory_bytes: 26128
#include<stdio.h>

int n, A[20];

bool exhaustiveSearch(int i, int m) {
  if ( m == 0 ) return true;
  if ( i >= n ) return false;
  return exhaustiveSearch(i + 1, m) || exhaustiveSearch(i + 1, m - A[i]);
}

int main() {
  int q, m;

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

  scanf("%d", &q);

  for ( int i = 0; i < q; i++ ) {
    scanf("%d", &m);
    if (exhaustiveSearch(0, m)) printf("yes\n");
    else printf("no\n");
  }
}



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

int main()
{
	int a, b;
	cin >> a >> b;

	if (a < b) {
		cout << "a < b\n";
	} else if (a > b) {
		cout << "a > b\n";
	} else {
		cout << "a == b\n";
	}

	return 0;
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> X){
  ll ans=INF;
  REP(101){
    ll tmp=0;
    For(j,N){
      tmp+=(X[j]-i)*(X[j]-i);
    }
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> X(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
    }
    solve(N, std::move(X));
    return 0;
}


Measured memory_bytes: 256
io = STDIN
n,m=io.gets.split.map(&:to_i)
ac={}
wa=Hash.new{|h,k|h[k]=0}
m.times do
  pr,s=io.gets.split
  if s=="AC"
    ac[pr]=1
  else
    wa[pr]+=1 if ac[pr]==nil
  end
end
wacnt=0
wa.each do |pr,i|
  wacnt+=wa[pr] if ac[pr]==1
end
puts "#{ac.size} #{wacnt}"


Measured memory_bytes: 15228
#include <stdio.h>
int main(void){
    int n;
    scanf("%d\n",&n);
    int h[101];
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    h[n]=0;
    
    int cou=0;
    int len=n;
    while(len){
        if(h[0]==0){
            for(int i=0;i<len-1;i++){
                h[i]=h[i+1];
            }
            len--;
        }else{
            int j=0;
            while(h[j]!=0){
                h[j]--;
                j++;
            }
            cou++;
        }
        
    }
    printf("%d\n",cou);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = input()

SUM=[0]*(N+1)#iより西のWの数
SUM2=[0]*(N+1)#iより西のEの数
for i in range(N):
    if A[i]=="W":
        SUM[i+1] = SUM[i]+1
        SUM2[i+1] = SUM2[i]
    else:
        SUM2[i+1] = SUM2[i]+1
        SUM[i+1] = SUM[i]
    
SUM3 = [SUM[i]+(SUM2[-1]-SUM2[i+1]) for i in range(N)]
print(min(SUM3))

Measured memory_bytes: 29688
#include<stdio.h>
int main() {
	int n, x,result=0, a[106] = {},memo,min;
	scanf("%d%d", &n, &x);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (int i = 0; i < n; i++) {
		min = 1000000001;
		for (int j = 0; j < n; j++) {
			if (min > a[j]) {
				min = a[j];
				memo = j;
			}
		}
		if (min <= x) {
			x = x - min;
			result++;
			a[memo] = 1000000001;
		}
		else { break; }
	}
	if (result==n&&x!=0)result--;
	printf("%d", result);
}

Measured memory_bytes: 128
hoge = input().split()
W = int(hoge[0])
H = int(hoge[1])
x = int(hoge[2])
y = int(hoge[3])

ans1 = W*H/2

if W/2 == x and H/2 == y:
  ans2 = 1
else:
  ans2 = 0

print(ans1,ans2)

Measured memory_bytes: 3060
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			a.begin(), a.end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define	MAX_QWORD		((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N, K;
	cin >> N >> K;

	ll ans = 0;
	for (int div = K + 1; div <= N; div++) {
		int floorVal = FloorN(N, div);
		int num = ((floorVal / div) * (div - K));
		if (floorVal < N) {
			int startVal = max(floorVal + 1, floorVal + K);
			num += max(0, (N - startVal + 1));
		}
		ans += num;
	}

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



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

struct Kruskal {
  Kruskal() {}
  Kruskal(int n) {
    init(n);
  }

  struct UnionFind {
    vector<int> p, r;

    UnionFind() {}
    UnionFind(int size) {
      init(size);
    }

    void init(int size) {
      p.resize(size);
      r.resize(size);
      for (int i = 0; i < size; ++i) {
        p[i] = i;
        r[i] = 1;
      }
    }

    int root(int x) {
      if (p[x] == x)
        return x;
      else
        return p[x] = root(p[x]);
    }

    void unite(int x, int y) {
      x = root(x);
      y = root(y);

      if (x == y) return;

      if (r[x] > r[y]) swap(x, y);
      r[x] += r[y];
      p[y] = x;
    }

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

  struct edges {
    edges() {}
    edges(int u, int v, int64_t cost) : u(u), v(v), cost(cost) {}
    bool operator<(const edges &e) const {
      return cost < e.cost;
    }

    int u, v;
    int64_t cost;
  };

  struct edge {
    edge() {}
    edge(int to, int64_t cost) : to(to), cost(cost) {}

    int to;
    int64_t cost;
  };

  vector<edges> E;
  vector<vector<edge>> G;

  void init(int n) {
    G.resize(n + 1);
  }

  void add(int u, int v, int64_t cost) {
    // cerr << u << " <-" << cost << "-> " << v << endl;
    E.push_back(edges(u, v, cost));
  }

  void make_graph(edges e) {
    G[e.u].push_back(edge(e.v, e.cost));
    G[e.v].push_back(edge(e.u, e.cost));
  }

  int64_t kruskal(int n) {
    int64_t res = 0;
    UnionFind uf(n + 1);

    sort(E.begin(), E.end());
    for (auto &e : E) {
      if (!uf.same(e.u, e.v)) {
        res += e.cost;
        uf.unite(e.u, e.v);
        make_graph(e);
      }
    }

    return res;
  }

  int64_t kruskal() {
    return kruskal(G.size());
  }
};

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

  vector<pair<pair<int, int>, int>> a, b;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;

    a.push_back(make_pair(make_pair(x, y), i));
    b.push_back(make_pair(make_pair(y, x), i));
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  Kruskal G(n);
  for (int i = 1; i < n; ++i) {
    G.add(a[i - 1].second, a[i].second, abs(a[i].first.first - a[i - 1].first.first));
    G.add(b[i - 1].second, b[i].second, abs(b[i].first.first - b[i - 1].first.first));
  }

  cout << G.kruskal() << endl;
}


Measured memory_bytes: 15012
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m,i,j,a,b;
   cin>>n>>m;
   vector<int>v[n+1];
   for(i = 0;i < m;i++)
   {
       cin>>a>>b;
       v[a].push_back(b);
       v[b].push_back(a);
   }
   for(i = 1;i <= n;i++)
    cout<<v[i].size()<<endl;
    return 0;
}


Measured memory_bytes: 256
S=input()
ref="AKIHABARA"
rema=lambda s: "".join([c for c in s if c != 'A'])
def split_a(s):
    i=0
    arr=[]
    while i<len(s):
        j=i
        while j<len(s) and s[j]=='A':
            j+=1
        arr.append(j-i)
        i=j+1
    return arr
if len(S)>len(ref) or rema(ref) != rema(S):
    print("NO")
elif any([s>r for r,s in zip(split_a(ref), split_a(S))]):
    print("NO")
else:
    print("YES")


Measured memory_bytes: 38256
import math


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors


N = int(input())
divisors = make_divisors(N)

cnt = 0
for d in divisors:
    if d == 1:
        continue

    if N < d:
        break

    if is_prime(d):
        dd = d
        while True:
            if N < dd:
                break
            if N % dd == 0:
                N //= dd
                cnt += 1
                dd *= d
            else:
                break
print(cnt)


Measured memory_bytes: 9476
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<int> A(M);
    rep(i,M) cin >> A[i];

    int odd = 0;
    rep(i,M) {
        if (A[i]&1) odd++;
    }
    if (odd > 2) {
        cout << "Impossible" << ln;
        return 0;
    }
    vector<int> a;
    if (odd >= 1) {
        rep(i,M) {
            if (A[i]&1) {
                a.emplace_back(A[i]);
                break;
            }
        }
    }
    rep(i,M) {
        if (~A[i]&1) a.emplace_back(A[i]);
    }
    if (odd == 2) {
        for (int i = M-1; i >= 0; i--) {
            if (A[i]&1) {
                a.emplace_back(A[i]);
                break;
            }
        }
    }
    for (auto i : a) cout << i << " ";
    cout << ln;
    vector<int> b;
    rep(i,M) {
        if (i==0) {
            if (a[i]-1>0) b.emplace_back(a[i]-1);
        } else if (i==M-1) {
            b.emplace_back(a[i]+1);
        } else {
            b.emplace_back(a[i]);
        }
    }
    if (M==1) b.emplace_back(1);
    cout << b.size() << ln;
    for (auto i : b) cout << i << " ";
    cout << ln;
}


Measured memory_bytes: 3676
X = 0
Y = 0
while True :
  try :
    a, b, c = map(int, input().split(","))
    if(c ** 2 == a ** 2 + b ** 2) :
      X += 1
    elif(a == b) :
      Y += 1
    else :
      pass
  except :
    print(X)
    print(Y)
    break


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    string ans="Heisei";
    string mon = s.substr(5, 6);
    if(stoi(mon)>4){
        ans = "TBD";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define     debug       printf("\n<<CameHere<<\n")
#define     mem(x,y)    memset(x, y, sizeof(x))
#define     all(qz)     qz.begin(),qz.end()
#define     rall(qz)    qz.rbegin(),qz.rend()
#define     inf         LLONG_MIN
#define     INF         LLONG_MAX
#define     mod         1000000007
#define     Sqr(x)      ((x)*(x))
#define     ll          long long
#define     mk          make_pair
#define     pb          push_back
#define     pi          acos(-1.0)
#define     cos(a)      cos(a*pi/180)
#define     sin(a)      sin(a*pi/180)
#define     tan(a)      tan(a*pi/180)

ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/
ll ar[8][8];
ll n,m,k;

ll fn(ll x,ll y){
    ll br[8][8];
    for(ll i=0;i<8;i++){
        for(ll j=0;j<8;j++){
            br[i][j]=ar[i][j];
        }
    }
    for(ll i=0;i<7;i++){
        ll xx=(1<<i)&x;
        if(xx!=0){
            for(ll j=1;j<=m;j++){
                br[n-i][j]=0;
            }
        }
    }
    for(ll i=0;i<7;i++){
        ll xx=(1<<i)&y;
        if(xx!=0){
            for(ll j=1;j<=n;j++){
                br[j][m-i]=0;
            }
        }
    }
    ll cnt=0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(br[i][j]==1) cnt++;
        }
    }
    //cout<<x<<" "<<y<<" "<<cnt<<endl;
    return cnt;
}

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

    //ll n,m,k;
    cin>>n>>m>>k;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            char ch;
            cin>>ch;
            if(ch=='#'){
                ar[i][j]=1;
            }
        }
    }
    ll rr=pow(2,n);
    ll cc=pow(2,m);
    //cout<<rr<<" "<<cc<<endl;
    ll ans=0;
    for(ll i=0;i<rr;i++){
        for(ll j=0;j<cc;j++){
            if(fn(i,j)==k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



















Measured memory_bytes: 4064
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  s.append(list(map(int, input().split())))
  
sdictlist = []
sdictlistsorted = []
for i in range(D):
  onedict = {}
  for j in range(26):
    onedict[j] = s[i][j]
  sdictlist.append(onedict)
  onesorteddict = sorted(onedict.items(), key=lambda x:x[1], reverse=True)
  sdictlistsorted.append(onesorteddict)

lenpastmax = 21 #26まで設定できる
#26 -> 145419
#25 -> 18657778
#24 -> 40796238
#23
pastlist = []
for i in range(D):
  j = 0
  while(sdictlistsorted[i][j][0] in pastlist):
    j += 1
  print(sdictlistsorted[i][j][0]+1)
  pastlist.append(sdictlistsorted[i][j][0])
  if(len(pastlist)==lenpastmax):
    pastlist.pop(0)


Measured memory_bytes: 10448