akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, l; cin >> n >> l;
	VE a(n);
	rep(i, n) {
		a[i] = l + i;
	}
	int sum = 0;
	rep(i, n) {
		sum += a[i];
	}
	int now = INF;
	int ans = 0;
	rep(i, n) {
		if (now > abs(a[i])) {
			now = abs(a[i]); ans = sum - a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

ll fact(ll n,ll r)
{
	r = min(r,n-r);
	ll p = 1,q = 1;
	while(r)
	{
		p *= n;
		q *= r;
		--n,--r;
		ll j = __gcd(p,q);
		p/= j;
		q/= j;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a,b;
	cin>>n>>a>>b;
	ll v[n];
	long double h=0.0;
	ll ans = 0;
	for(int i = 0;i<n; i++)
		cin>>v[i];
	sort(v,v+n, greater<ll>());
	for(int i = 0;i<a ; i++)
		ans += v[i];
	ll ways=0;
	h = (double)ans/a;
	int g = count(v,v+n,v[a-1]);
	int h2 = count(v,v+a,v[a-1]);
	if(v[0]==v[a-1])
	for(int i = h2; i<=min(g,b); i++)
		ways += fact(g,i);
	else
		ways += fact(g,h2);
	cout<<fixed<<setprecision(6)<<h<<endl;
	cout<<ways<<endl;
	return 0;
}

Measured memory_bytes: 256
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  ll n;
  cin >> n;
  ll ans = n * (n + 1) * (n + 2) / 6;
  rep(i, n - 1)
  {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    if (a > b)
      swap(a, b);
    ll t = (a + 1) * (n - b);
    ans -= t;
  }
  cout << ans << "\n";
}

int main()
{
  init_main();
  solve();
}

Measured memory_bytes: 3652
// to format a document: ctrl + K -> ctrl + D

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;

int main() {
    int N, K;
    cin >> N >> K;

    int ans;
    if (N % K == 0)
        ans = 0;
    else
        ans = 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

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

  int32_t N;
  cin >> N;
  int32_t sum = 0;
  vector<int32_t> X(N);
  for (auto& x : X) {
    cin >> x;
    sum += x;
  }
  int32_t c = sum / N;
  int32_t res = 0;
  for (auto x : X) {
    res += (c - x) * (c - x);
  }
  int32_t res2 = 0;
  c++;
  for (auto x : X) {
    res2 += (c - x) * (c - x);
  }
  cout << min(res, res2) << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
C1 = Counter(v1)
C2 = Counter(v2)
if C1.most_common(1)[0][0]!=C2.most_common(1)[0][0]: 
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(1)[0][1]))
elif C1.most_common(1)[0][1]==C2.most_common(1)[0][1]==n//2:
  print(n//2)
elif C1.most_common(1)==C2.most_common(1) and C1.most_common(2)[1][1] >= C2.most_common(2)[1][1]:
  print((n//2-C1.most_common(2)[1][1])+(n//2-C2.most_common(1)[0][1]))
else:
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(2)[1][1]))
 

Measured memory_bytes: 64900
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        System.out.println(dfs(n, new Integer[n + 1]));
    }

    private static int dfs(int target, Integer[] dp) {
        if (target == 0) {
            return 0;
        }
        if (dp[target] != null) {
            return dp[target];
        }
        int maxNine = 1, maxSix = 1;
        while (maxNine * 9 <= target) {
            maxNine *= 9;
        }
        while (maxSix * 6 <= target) {
            maxSix *= 6;
        }
        return Math.min(1 + dfs(target - maxNine, dp), 1 + dfs(target - maxSix, dp));
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 33496
#include<stdio.h>
int main(){
    int a,i,b[100];
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d",&b[i]);
    }
    for(i=a-1;i>=0;i--){
        printf("%d",b[i]);
        if(i!=0){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
N = int(input())
listh = list(map(int, input().split()))
#print(listh)
lista = [0]
count = 0
for n in range(1,N):
    if listh[n] > listh[n-1]:
        count = 0
        lista.append(count)
    else:
        count = count + 1
        lista.append(count) 
#print(lista)        
print(max(lista))      
        

Measured memory_bytes: 14224
N = int(input())
T = [0]
X = [0]
Y = [0]
for a in range(N + 1):
    if a == N:
        break
    L = input().split()
    T.append(int(L[0]))
    X.append(int(L[1]))
    Y.append(int(L[2]))
    if abs(X[a + 1] - X[a]) + abs(Y[a + 1] - Y[a]) <= T[a + 1] - T[a] and (abs(X[a + 1] - X[a]) + abs(Y[a + 1] - Y[a])) % 2 == (T[a + 1] - T[a]) % 2:
        pass
    else:
        break
if a == N:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 11816
#include <iostream>

using namespace std;

int n, cnt[7], in, d[7], i;

main(){
  while(cin >> n){
    for(i=0;i<7;i++) cnt[i] = d[i] = 0;
    for(i=0;i<n;i++){
      cin >> in;
      if(in/10 == in%10) d[in/10] = 1;
      else{
        cnt[in/10]++;
        cnt[in%10]++;
      }
    }
    int f = 1, t = 0;
    for(i=0;i<7;i++){
      if(d[i] && !cnt[i] && n > 1) f = 0;
      if(cnt[i]&1) t++;
    }
    if(t > 2) f = 0;
    cout << (f ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

char buf[110];

int main(void) {
  ll K;
  cin >> buf >> K;
  int len = strlen(buf);
  int res = 1;
  REP(i, min((ll)len, K)) {
    if(buf[i] != '1') {
      res = buf[i] - '0';
      break;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	int L,A,B,C,D;
	
	cin>>L>>A>>B>>C>>D;
	
	for(;L>=0;L--){
		A-=C;
		B-=D;
		if(A<=0&&B<=0)
			break;
	}
	
	cout<<L-1<<endl;

}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  deque<int> ans;
  vector<int> vis(n, 0);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    if (i == 0) {
      ans.push_back(u);
      ans.push_back(v);
      vis[u] = vis[v] = 1;
    }
    g[u].push_back(v);
    g[v].push_back(u);
  }
  while (true) {
    bool ok = true;
    int end = ans.front();
    for (int nbr : g[end]) {
      if (vis[nbr]) continue;
      ok = false;
      vis[nbr] = 1;
      ans.push_front(nbr);
      break;
    }
    end = ans.back();
    for (int nbr : g[end]) {
      if (vis[nbr]) continue;
      ok = false;
      vis[nbr] = 1;
      ans.push_back(nbr);
      break;
    }
    if (ok) break;
  }
  cout << (int) ans.size() << endl;
  for (int i = 0; i < (int) ans.size(); i++) {
    if (i > 0) cout << " ";
    cout << ans[i] + 1;
  }
  cout << endl;
  return 0;	
}

Measured memory_bytes: 7168
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;

typedef pair<int, int> P;
const int MN = 1010;

vector<int> data[MN][2];
vector<P> g[MN];
int used[MN];
int u;
bool f;
void dfs(int id, int p, int x) {
    if (used[p] != -1) {
        if (used[p] != x) f = true;
        return;
    }
    used[p] = x;
    data[id][x].push_back(p);
    for (P pp: g[p]) {
        int d, dp;
        tie(d, dp) = pp;
        dfs(id, d, (x+dp)%2);
    }
}

bool useddp[MN][MN];
int dp[MN][MN];
int calc(int i, int d) {
    if (d < 0) return 0;
    if (i == u) {
        if (d == 0) return 1;
        return 0;
    }
    if (useddp[i][d]) return dp[i][d];
    useddp[i][d] = true;
    int res = 0;
    res += calc(i+1, d-(int)data[i][0].size());
    res += calc(i+1, d-(int)data[i][1].size());
    res = min(res, 2);
    return dp[i][d] = res;
}

bool solve() {
    for (int i = 0; i < MN; i++) {
        g[i].clear();
        data[i][0].clear();
        data[i][1].clear();
    }
    memset(used, -1, sizeof(used));
    memset(useddp, 0, sizeof(useddp));
    f = false;
    u = 0;

    int n, a, b, c;
    cin >> n >> a >> b;
    c = a+b;
    if (!n && !a && !b) return false;
    for (int i = 0; i < n; i++) {
        int x, y; string s;
        cin >> x >> y >> s; x--; y--;
        if (s == "yes") {
            g[x].push_back(P(y, 0));
            g[y].push_back(P(x, 0));
        } else {
            g[x].push_back(P(y, 1));
            g[y].push_back(P(x, 1));
        }
    }
    for (int i = 0; i < c; i++) {
        if (used[i] != -1) continue;
        dfs(u, i, 0);
        u++;
    }
    if (f) {
        cout << "no" << endl;
        return true;
    }

    if (calc(0, a) != 1) {
        cout << "no" << endl;
        return true;
    }
    int num = a;
    vector<int> result;
    for (int i = 0; i < u; i++) {
        if (calc(i+1, num-(int)data[i][0].size())) {
            for (int x: data[i][0]) {
                result.push_back(x+1);
            }
            num -= data[i][0].size();
        } else {
            for (int x: data[i][1]) {
                result.push_back(x+1);
            }
            num -= data[i][1].size();
        }
    }
    sort(result.begin(), result.end());
    for (int d: result) {
        cout << d << endl;
    }
    cout << "end" << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e13;

struct Node {
    char type;
    vector<Node> child;
    Node(char _type) {
        type = _type;
    }
    void trav(string ind) {
        cout << ind << type << endl;
        for(Node node : child)
            node.trav(ind + " ");
    }
    int need0() {
        if(type == '&') {
            return min(child[0].need1() + child[1].need0(), child[0].need0());
        } else if(type == '|') {
            return child[0].need0() + child[1].need0();
        } else {
            return 1;
        }
    }
    int need1() {
        if(type == '|') {
            return min(child[0].need0() + child[1].need1(), child[0].need1());
        } else if(type == '&') {
            return child[0].need1() + child[1].need1();
        } else {
            return 1;
        }
    }
};

int main() {
    string S;
    cin >> S;
    stack<char> st;
    vector<Node> nodes;
    for(int i = 0; i < S.size(); ++i) {
        char c = S[i];
        if(c == '&') {
            while(!st.empty() && st.top() == '&') {
                nodes.push_back(Node('&'));
                st.pop();
            }
            st.push('&');
        } else if(c == '|') {
            while(!st.empty() && st.top() != '(') {
                nodes.push_back(Node(st.top()));
                st.pop();
            }
            st.push('|');
        } else if(c == '?') {
            nodes.push_back(Node(c));
        } else if(c == '(') {
            st.push('(');
        } else {
            while(!st.empty() && st.top() != '(') {
                nodes.push_back(Node(st.top()));
                st.pop();
            }
            st.pop();
        }
    }
    while(!st.empty()) {
        nodes.push_back(Node(st.top()));
        st.pop();
    }
    stack<Node> nst;
    for(int i = 0; i < nodes.size(); ++i) {
        Node node = nodes[i];
        if(node.type == '?') {
            nst.push(node);
        } else if(node.type == '&') {
            Node n2 = nst.top();
            nst.pop();
            Node n1 = nst.top();
            nst.pop();
            node.child.push_back(n1);
            node.child.push_back(n2);
            nst.push(node);
        } else {
            Node n2 = nst.top();
            nst.pop();
            Node n1 = nst.top();
            nst.pop();
            node.child.push_back(n1);
            node.child.push_back(n2);
            nst.push(node);
        }
    }
    Node root = nst.top();
    cout << root.need0() << " " << root.need1() << endl;
    return 0;
}


Measured memory_bytes: 24384
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
    
    int N;
    cin >> N;
    
    int sum=0 ;
    int a=1,b=1 ;
    int x,y,z;
    while (b <= N){
        b *= 10;
        x = N/a;
        y = N/b;
        z = x*a - y*b;
        sum += z/a;
        
        /*
        cout << b << endl;
        cout << x << endl;
        cout << y << endl;
        cout << z << endl;
        */
        
        a *= 10;
    }
    
    if( N%sum == 0 ){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" <<endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  ll n,k,m=0;
  cin>>n>>k;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=min(k,n);i>0;i--){
    for(int j=0;j<=i;j++){
      ll c=0;
      priority_queue<ll> p;
      ll l=j,r=i-j;
      for(int s=0;s<l;s++){
        c+=a[s];
        p.push(-a[s]);
      }
      for(int s=n-1;s>=n-r;s--){
        c+=a[s];
        p.push(-a[s]);
      }
      for(int t=0;t<k-i;t++){
        if(!p.empty()){
          if(p.top()>=0){
            c-=-p.top();      p.pop();
       }
      }
      }
      m=max(c,m);
    }
  }
  cout<<m;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	for (;;) {
		int x, y; cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x > y) swap(x, y);
		cout << x << ' ' << y << endl;
	}
}

Measured memory_bytes: 1160
#include <string>
#include <iostream>
using namespace std;
int main()
{
   int occurrences = 0;
   int n;
   string s;
   cin>> n;
   cin>>s;
   string::size_type pos = 0;
   string target = "ABC";
   while ((pos = s.find(target, pos )) != std::string::npos) {
          ++ occurrences;
          pos += target.length();
   }
   cout << occurrences << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string S;
  int ans=0;
  cin >> S;
  for(int i=1; i<S.length(); i++){
    if(S[i-1] == S[i]){
      ans++;
      if(S[i] == '0') S[i] = '1';
      else S[i] = '0';
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int num[] = new int[n];
        for(int i = 0; i < n; i++){
            num[i] = sc.nextInt();
        }
        for(int i = n - 1; i >= 0; i -= 2){
        	System.out.print(num[i] + " ");
        }
        for(int i = n % 2; i < n; i += 2){
        	System.out.print(num[i] + " ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 61856
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		int[] x = new int[5];

		for (int i = 0; i < 5; i++) {
			x[i] = scan.nextInt();
		}

		//WK変数

		//演算
		int result = 1;

		for (int num : x) {

			if (num == 0) {
				break;
			}
			result++;
		}
		;

		//結果出力
		System.out.println(result);
	}
}

Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;

int main(void) {
	int n, k; cin >> n >> k;
	vector<int> dislike(10);
	for (int i = 0; i < k; i++) {
		int a; cin >> a;
		dislike[a]++; //嫌いな数字の添え字に1を立てる
	}

	int ans = n;
	while (true) {
		bool flag = true;
		int tmp = ans;
		while (tmp != 0) {
			// 嫌いな数字が含まれているかチェックする
			if (dislike[tmp % 10] == 1) {
				flag = false;
				break;
			}
			tmp /= 10;
		}

		if (flag) {
			cout << ans << endl;
			break;
		}
		ans++;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll s[110000];
bool ok;
ll ans;
ll m, n, k, q;


//セグ木
double dat[2560000];
ll sz;

void init(ll n) {
	sz = 1;
	while (sz < n)sz *= 2;
	REP(i, sz * 2 - 1) dat[i] = 1; //初期値
}

void update(ll k, double a) { //場所(0-indexed), 値
	k += sz - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = dat[k * 2 + 1] * dat[k * 2 + 2]; //更新
	}
}

double query(ll a, ll b, ll k, ll l, ll r) { //[a, b) 呼ぶとき (a, b, 0, 0, sz)
	if (r <= a or b <= l)return 1;
	if (a <= l and r <= b)return dat[k];
	double v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
	double v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return v1 * v2; //戻り値
}


int main() {
	cin >> n;
	vector<ll> t(n);
	init(110000);
	REP(i, n) {
		double a;
		cin >> t[i] >> a;
		update(i, (double)(10 - a) / 10);
	}
	t.push_back(INF);
	ll q;
	cin >> q;
	REP(i, q) {
		ll a, b;
		cin >> a >> b;
		ll i1 = lower_bound(ALL(t), a) - t.begin();
		ll i2 = lower_bound(ALL(t), b) - t.begin();
		cout << fixed << setprecision(10) << (double)1000000000 * query(i1, i2, 0, 0, sz) << endl;
	}
}




Measured memory_bytes: 6688
#include <iostream>

int main()
{
	int N, M = 0;
	std::cin >> N >> M;

	int answer = 0;
	for (int i = 0; i < M; ++i)
	{
		int temp = 0;
		std::cin >> temp;
		answer += temp;
	}

	if (N - answer < 0)
	{
		std::cout << -1 << "\n";
	}
	else
	{
		std::cout << N - answer << "\n";
	}

	return 0;
}

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

using namespace std;

using int64 = long long;
const int64 LINF = 1LL << 60;
const int INF = 1 << 30;

int V, E, K;
int64 g[31][150][150];

int main() {
  fill_n(**g, 31 * 150 * 150, -LINF);

  cin >> V >> E >> K;
  for(int i = 0; i < V; i++) {
    g[0][i][i] = 0;
  }
  for(int i = 0; i < E; i++) {
    int a, b;
    int64 c;
    cin >> a >> b >> c;
    g[0][a][b] = max(g[0][a][b], c);
  }

  for(int i = 0; i < 30; i++) {
    for(int j = 0; j < V; j++) {
      for(int k = 0; k < V; k++) {
        for(int l = 0; l < V; l++) {
          g[i + 1][k][l] = max(g[i + 1][k][l], g[i][k][j] + g[i][j][l]);
        }
      }
    }
  }


  auto check = [&](int bit) {
    vector< int64 > dp(V);
    for(int k = 30; k >= 0; k--) {
      if((bit >> k) & 1) {
        vector< int64 > dp2(V);
        for(int i = 0; i < V; i++) {
          for(int j = 0; j < V; j++) {
            dp2[j] = max(dp2[j], dp[i] + g[k][i][j]);
          }
        }
        dp.swap(dp2);
      }
    }
    return *max_element(begin(dp), end(dp)) >= K;
  };

  int ok = INF, ng = 0;
  while(ok - ng > 1) {
    int mid = (ok + ng) / 2;
    if(check(mid)) ok = mid;
    else ng = mid;
  }

  if(ok == INF) {
    cout << -1 << endl;
  } else {
    cout << ok << endl;

    if(ok <= 100) {
      int64 dp[101][150] = {{}}, pv[101][150];
      for(int i = 0; i < ok; i++) {
        for(int j = 0; j < V; j++) {
          for(int k = 0; k < V; k++) {
            if(dp[i][j] + g[0][j][k] > dp[i + 1][k]) {
              dp[i + 1][k] = dp[i][j] + g[0][j][k];
              pv[i + 1][k] = j;
            }
          }
        }
      }
      int high = 00;
      for(int i = 0; i < V; i++) {
        if(dp[ok][i] >= dp[ok][high]) high = i;
      }
      vector< int > route;
      for(int i = ok; i >= 0; i--) {
        route.push_back(high);
        high = pv[i][high];
      }
      reverse(begin(route), end(route));
      for(int i = 0; i < route.size(); i++) {
        if(i) cout << " ";
        cout << route[i];
      }
      cout << endl;
    }
  }
}



Measured memory_bytes: 8864
#include <bits/stdc++.h>
#define INF 1000000000000000
#define int long long

using namespace std;

int n=0,k=0;
int h[301];
int dp[301][301];

signed main()
{
	cin >> n >> k;
	for (int i=0; i<n; i++)
	{
		cin >> h[i];		
	}
	if (k==n)
	{
		cout << 0;
		return 0;
	}
	for (int j=0; j<n; j++)
	{
		dp[1][j] = h[j];	
	}
	for (int i=2; i<=n-k; i++)
		for (int j=0; j<n; j++)
			dp[i][j] = INF;
	for (int i=2; i<=n-k; i++)
	{
		for (int j=0; j<n; j++)
		{
			for (int k=j+1; k<n; k++)
			{
				dp[i][j] = min(dp[i][j], dp[i-1][k]+max(0ll, h[k]-h[j])+h[j]-h[k]);	
			}	
		}		
	}
	int Min = INF;		
	/*for (int i=1; i<=n-k; i++)
	{
		for (int j=0; j<n; j++)
		{
			cout << dp[i][j] << ' ';	
		}
		cout << endl;
	}
	cout << endl;*/
	for (int j=0; j<n; j++)
	{
		Min = min(Min, dp[n-k][j]);
	}
	cout << Min;
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
//-------------------------------------------------------------------------------

ld a,b,x;

void input_var(){
    cin >> a >> b >> x;
}
//-------------------------------------------------------------------------------

signed main(){
    cout << fixed << setprecision(10);
    input_var();
    ld ans = 0;
    ld s = x / a;
    if(s >= a * b / 2)ans = atan2(((a * b - s) * 2 / a),a) / (2 * PI) * 360;
    else ans = atan2(b,s * 2 / b) / (2 * PI) * 360;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
char s[3333],t[3333];p[3333][3333];i,j,l;A(a){i--&&l--?(a=s[i])-t[l]?A(p[i+1][l+1]-p[i][l+1]?i++:l++):putchar(a,A()):0;}main(){gets(s);for(l=strlen(gets(t));j<l?:(j=0,++i<strlen(s));j++)p[i+1][j+1]=s[i]-t[j]?fmax(p[i+1][j],p[i][j+1]):p[i][j]+1;A();}

Measured memory_bytes: 41216
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define P pair
#define M 998244353
#define fr(i,n) for(int i=0;i<n;i++)
#define M2 1000000007
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
#define Take_n ll n; cin>>n;
using namespace std;
 
int main()
{
	int n,m,j,i;
	cin>>n>>m;
	string s[n];
	for(i=0;i<n;i++)
	cin>>s[i];
	ll dp[n][m];
	dp[0][0]=1;
	for(i=1;i<m;i++)
	{
		if(s[0][i]=='.')
		dp[0][i]=dp[0][i-1];
		else
		dp[0][i]=0;
	}
	for(i=1;i<n;i++)
	{
		if(s[i][0]=='.')
		dp[i][0]=dp[i-1][0];
		else
		dp[i][0]=0;
	}
	for(i=1;i<n;i++)
	{
		for(j=1;j<m;j++)
		{
			if(s[i][j]=='.')
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%M2;
			else
			dp[i][j]=0;
		}
	}
	
	cout<<dp[n-1][m-1];
    return 0;
}

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

ll power (ll base , ll pow){
	if (pow == 0){
		return 1;
	}
	ll temp = power(base , pow/2);
	if (pow % 2 == 1){
		return temp * temp * base;
	} else {
		return temp * temp;
	}
}

int main(){
	ll x;
	cin >> x;

	bool done = false;
	for(ll i = -125 ; i <126 ; i++){
		for(ll j = -125 ; j <126 ; j++){
			ll a = power(i , 5);
			ll b = power(j , 5);

			ll temp = a - b;
			if (temp == x){
				cout << i << " " << j << endl;
				done = true;
				break;
			}
		}
		if (done){break;}
	}

	return 0;
}


Measured memory_bytes: 3596
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

int n=26;
int v[26];

int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  string s, ans="";
  cin >> s;

  REP(i, s.size()) v[s[i]-'a']++;
  
  //REP(i, n) cout << v[i] << endl;  
  int tmp = 0, idx = 0;
  REP(i, n) if(v[i] == 1) tmp++;
  
  if(tmp == n){
    bool ok = false;
    while(!s.empty() && !ok){
      int back = s.back() - 'a';
      s.erase(s.end()-1);
      v[back] = 0;
      for(int i=back+1; i<n; i++){
	if(!v[i]){
	  s += i+'a';
	  ok = true;
	  break;
	}
      }
    }
    ans = s;
    /*
    REP(i, n) {
      if(s[i] == 'z') {
	idx = i;
	break;
      }
    }
    if(idx == 0){cout << -1 << endl; return 0;}
    else idx--;
    REP(i, idx){
      ans += s[i];
    }
    ans += s[idx]+1;
    */
  }
  else{
    char moji;
    REP(i, n) if(v[i] != 1){moji='a'+i; break;}
    ans += s+moji;    
  }
  if(ans.empty()) cout << -1 << endl;
  else cout << ans << endl;
  
  
  return 0;
}


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

using namespace std;

long f1(string S, long K){
    long ans = 0;
    int i = 0;
    int cnt=0;
    while(i < S.length()){
        auto u = S[i];
        cnt=0;
        int j;
        for(j=i; j<S.length(); ++j){
            if(u == S[j]){
                cnt++;
            }else{
                break;
            }
        }
        ans += cnt/2;
        i=j;
    }
    ans*=K;

    if(S[0] == S[S.length()-1] && cnt%2==1){
        ans+=K-1;
    }

    return ans;
}

long f2(string S, long K){
    long ans = 0;
    int i = S.length()-1;
    int cnt=0;
    while(i >= 0){
        auto u = S[i];
        cnt=0;
        int j;
        for(j=i; j>=0; --j){
            if(u == S[j]){
                cnt++;
            }else{
                break;
            }
        }
        ans += cnt/2;
        i=j;
    }
    ans*=K;

    if(S[0] == S[S.length()-1] && cnt%2==1){
        ans+=K-1;
    }

    return ans;
}

int main(){
    string S;
    long K;
    cin>>S>>K;
    bool flag = true;
    for(int i=0; i<S.length(); ++i){
        if(S[0] != S[i]){
            flag = false;
            break;
        }
    }
    if(flag==true){
        cout<<S.length()*K/2<<endl;
        return 0;
    }

    if(K==1){
        long ans = 0;
        int i = 0;
        int cnt=0;
        while(i < S.length()){
            auto u = S[i];
            cnt=0;
            int j;
            for(j=i; j<S.length(); ++j){
                if(u == S[j]){
                    cnt++;
                }else{
                    break;
                }
            }
            ans += cnt/2;
            i=j;
        }
        cout<<ans<<endl;
        return 0;
    }

    long ans1 = f1(S, K);
    long ans2 = f2(S, K);
    cout<<min(ans1, ans2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
    
    int k,a,b;
    int flag = 0;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);

    for(int i=a; i<=b; i++){
        if(i%k==0){
          flag = 1;  
        }
    }
    if(flag == 1){
        printf("OK\n");
    } else {
        printf("NG\n");
    }
        return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
#define fo(i,a) for(i = 0;i < a;i++)
using namespace std;
int main(void)
{
	int n,m,a[1000]={0},b,c=0,p=0,i;
	
	cin >> n >> m ;
	fo(i,m){
		cin >> a[i] >> b ;
	}
	sort(a,a + m,greater<int>()) ;
	fo(i,m){
		if(a[i] >= n){
				p++ ;
			}
		else if(a[i] < n && p < m - 1){
			c += n - a[i] ;
			p++ ;
		}
	}
	cout << c << endl ;
	
	return 0 ;
}



Measured memory_bytes: 3160
def main():
  N, M, X = map(int, input().split())
  a = list(map(int, input().split()))
  
  i = 0
  while i < M:
    if a[i] > X:
      break
    i += 1
  print(min(i, M - i))

if __name__ == "__main__":
  main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

map<long long,int> prime_factor(long long n){
    map<long long,int> mp;
    for(int i = 2; (long long)i * i <= n; i++){
        while(n % i == 0){
            mp[i]++;
            n /= i;
        }
    }
    if(n != 1) mp[n]++;
    return mp;
}

signed main(){
    ll a,b;
    cin >> a >> b;
    map<ll, int> mp = prime_factor(a);
    int ans = 1;
    for(auto i : mp){
        if(b % i.first == 0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n; cin>>n;
  vector<int> x(n);
  rep(i, n) cin>>x[i];

  ll res=1e18;
  for (int p=0; p<101; p++) {
    ll tmp=0;
    rep(j, n) {
      tmp+=(p-x[j])*(p-x[j]);
    }
    res=min(res, tmp);
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int num[200];
	int N;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> num[i];
	}
	int cnt = 0;
	bool flg = true;

	do
	{
		for (int i = 0; i < N; i++)
		{
			if (num[i] % 2 == 0) {
				num[i] /= 2;
			}
			else {
				flg = false;
				break;
			}
		}
		if(flg)cnt++;
	} while (flg);
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

class UnionFind {
public:
  vector<int> par, rank; // parent(negative := its root and abs-value is its size), depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;  // already belong to same tree
    if(rank[x] < rank[y]){  // y becomes parent node
      par[y] += par[x];
      par[x] = y;
    } else {  // x becomes parent node
      par[x] += par[y];
      par[y] = x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int size(int x){ return -par[find(x)]; }
};

int main(){
  int n,m;
  cin>>n>>m;
  using P = pair<pair<long,int>,pair<int,int>>;
  // cost, id, s, t
  vector<P> vec(m);
  vector<long> costs(m);
  rep(i,m){
    int s,d,c;
    cin>>s>>d>>c;
    s--;d--;
    vec[i] = P{{c,i},{s,d}};
    costs[i] = c;
  }

  sort(all(vec));

  vector<bool> used(m,false);

  auto mst = [&](int nouse){
    UnionFind uf(n);
    long ret = 0;
    for(auto p : vec){
      int s = p.se.fi, t = p.se.se;
      if(uf.same(s,t)) continue;
      if(p.fi.se == nouse) continue;
      uf.unite(s,t);
      ret += p.fi.fi;
      used[p.fi.se] = true;
    }
    if(uf.size(0)!=n) return 123456789456789L;
    return ret;
  };

  vector<int> cand;
  int cost = mst(-1);

  rep(i,m) if(used[i]) cand.pb(i);

  int a = 0; long b = 0;
  for(auto i : cand){
    long r = mst(i);
    if(r>cost){
      a++;
      b += costs[i];
    }
  }
  cout << a << " " << b << endl;

  return 0;
}

Measured memory_bytes: 4432
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    int  X,N,dN_array[128]={-1},minimal_itg=101,minimal_abs=101,tmp;

    cin >> X >> N;
    
    if(N==0){
        minimal_itg = X;
    }else{
        for(int i=0;i<N;i++){
            cin >> tmp;
            dN_array[tmp]=1;
        }
        for(int j=-50;j<=201;j++){
            if(j<=0){
                if(abs(X-j)<minimal_abs){
                    minimal_abs =abs(X-j);
                    minimal_itg = j;
                }
            }else if(dN_array[j]!=1){
                if(abs(X-j)<minimal_abs){
                    minimal_abs =abs(X-j);
                    minimal_itg = j;
                }
            }
        }
    }
    cout << minimal_itg << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <vector>
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

long long int N, K;
long long int x[100010], y[100010], col[100010];

const long long int MAXK = 2005;
long long int black[MAXK + 5][MAXK + 5], white[MAXK + 5][MAXK + 5];

long long int getSum(long long int arr[][MAXK + 5], int sx, int sy, int gx, int gy) {
    long long int ret = 0; // gx++; gy++;
    ret += arr[sx][sy];
    ret += arr[gx][gy];

    ret -= arr[sx][gy];
    ret -= arr[gx][sy];
    return ret;
}

int main() {
    cin >> N >> K;
    for(int i=0; i<N; i++) {
        char c;
        cin >> x[i] >> y[i] >> c;
        x[i] %= (2*K);
        y[i] %= (2*K);
        col[i] = (c == 'W' ? 1 : 0);

        if(col[i]) white[ x[i]+1 ][ y[i]+1 ]++;
        else       black[ x[i]+1 ][ y[i]+1 ]++;
    }

    for(int i=0; i<MAXK; i++) {
        for(int j=0; j<MAXK; j++) {
            white[i][j+1] += white[i][j];
            black[i][j+1] += black[i][j];
            // fprintf(stderr, "i = %d, j = %d\n", i, j);
        }
    }
    for(int j=0; j<MAXK; j++) {
        for(int i=0; i<MAXK; i++) {
            white[i+1][j] += white[i][j];
            black[i+1][j] += black[i][j];
        }
    }

    // 黒四角の左上を固定
    long long int ans = 0;
    for(int i=0; i<=K; i++) {
        for(int j=0; j<=K; j++) {
            long long int sum = 0;
            sum += getSum(black, 0  , 0  , i  , j  );
            sum += getSum(black, i+K, 0  , 2*K, j  );
            sum += getSum(black, i  , j  , i+K, j+K);
            sum += getSum(black, 0  , j+K, i  , 2*K);
            sum += getSum(black, i+K, j+K, 2*K, 2*K);

            sum += getSum(white, 0  , j  , i  , j+K);
            sum += getSum(white, i  , 0  , i+K, j  );
            sum += getSum(white, i+K, j  , 2*K, j+K);
            sum += getSum(white, i  , j+K, i+K, 2*K);

            ans = max({ans, sum, N - sum});
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()



int main()
{
  int N, t=0;

  cin >> N;

  vector<string> s(N);
  vector<string> l;

  rep(i, N)
  {
    cin >> s[i];

  }

  set<string> st;


  rep(i, N)
  {
    st.insert(s[i]);
  }

  

  cout << st.size() << endl;



}


Measured memory_bytes: 25064
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#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;
  cout << s.substr(0,s.size()-8) << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools
L,R = map(int,input().split())
if (L+2019) < R:
  R = L+2019

ans_list=[]
for v in itertools.combinations(range(L,R+1),2):
  buf1 = v[0]%2019
  buf2 = v[1]%2019
  ans_list.append((buf1*buf2)%2019)
print(min(ans_list))

Measured memory_bytes: 75568
x = [1 for i in range(10 ** 6 + 1)]
x[0] = x[1] = 0
for i in range(10 ** 6 + 1):
  if x[i] == 1:
    for j in range(i * 2, 10 ** 6 + 1, i):
      x[j] = 0
while 0 == 0:
  try:
    n = int(input())
    c = 0
    for i in range(n + 1):
      c += x[i]
    print(c)
  except EOFError:
    break



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



int main() 
{
  ll N; cin>>N;
  vector<ll> A(N+1,0);
  rep(i,N)
  {
    cin>>A.at(i+1);
  }
  /*rep(i,N+1)
  {
    if(i!=0) {cout<<" ";}
    cout<<A.at(i);
    if(i==N) {cout<<endl;}
  }*/ 
  ll all=0;
  rep(i,N+1)
  {
    if(i==N) {all+=abs(A.at(0)-A.at(N)); continue;}
    all+=abs(A.at(i+1)-A.at(i));
  }
  //cout<<all<<endl;
  for(ll i=1;i<=N;i++)
  {
    if(i==N) 
    {
      cout<<all-(abs(A.at(N)-A.at(N-1))+abs(A.at(N)-A.at(0)))+abs(A.at(0)-A.at(N-1))<<endl;
      continue;
    }
    cout<<all-(abs(A.at(i)-A.at(i-1))+abs(A.at(i)-A.at(i+1)))+abs(A.at(i-1)-A.at(i+1))<<endl;
  }
          
  
  return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A; REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl
#define rsort(p, q) sort(p, q, greater<int>());

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

ull 
ryuka(ull n)
{
  ull L0 = 2, L1 = 1, L2 = 3;

  if (n == 0) return L0;
  if (n == 1) return L1;
  if (n == 2) return L2;
  
  n -= 1;
  while (0 < n) {
    L2 = L1 + L0;
    L0 = L1;
    L1 = L2;
    n--;
  }
  return L2;
}

int
main()
{
  CIN(N);
  ANS(ryuka(N));

  return 0;
}


Measured memory_bytes: 256