akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	string s, t; cin >> s >> t;
	int n = s.size();
	const int M = 26;
	vvi jeng(M);
	for (int i = 0; i < n; i++) {
		int u = s[i] - 'a';
		jeng[u].push_back(i);
	}
	ll ans = -1;
	for (char c : t) {
		int u = c - 'a';
		if (jeng[u].empty()) return cout << -1 << endl, 0;
		ans++;
		int lo = ans % n;
		auto it = lower_bound(jeng[u].begin(), jeng[u].end(), lo);
		if (it != jeng[u].end()) {
			int hi = *it;
			ans += hi - lo;
		} else {
			ans += n - lo;
			ans += jeng[u].front();
		}
	}
	cout << ans + 1 << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 1228
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

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


int bfs(int start, vector<int>& d, vector<vector<int>>& g) {
	d[start] = 0;
	int last = -1;
	queue<int> q;
	q.push(start);
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		last = cur;
		for (int next : g[cur]) {
			if (d[next] != -1) continue;
			d[next] = d[cur] + 1;
			q.push(next);
		}
	}
	return last;
}
vector<bool> isprime;

void eratos(int n) {
	isprime.resize(n + 1);
	for (int i = 0; i <= n; i++) {
		isprime[i] = true;
	}
	isprime[0] = false;
	isprime[1] = false;
	for (int i = 2; i * i <= n; i++) {
		if (isprime[i]) {
			int j = i + i;
			while (j <= n) {
				isprime[j] = false;
				j = j + i;
			}
		}
	}
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
	eratos(1000000);
    int n, m, s, t; scanf("%d %d %d %d", &n, &m, &s, &t); s--; t--;
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int u, v; scanf("%d %d", &u, &v);
		u--; v--;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	{
		vector<int> v1; for (auto e : g[s]) v1.emplace_back(e);
		vector<int> v2; for (auto e : g[t]) v2.emplace_back(e);
		sort(v2.begin(), v2.end());
		for (auto e : v1) {
			if (binary_search(v2.begin(), v2.end(), e)) {
				puts("2");
				return 0;
			}
		}
	}
	vector<int> pr; for (int i = 3; i < 1000000; i += 2) if (isprime[i]) pr.emplace_back(i);
	vector<int> ds(n, -1), dt(n, -1); bfs(s, ds, g); bfs(t, dt, g);
	if (ds[t] % 2 == 1) {
		int res = *lower_bound(pr.begin(), pr.end(), ds[t]);
		printf("%d\n", res);
	}
	else {
		int res = inf;
		for (int i = 0; i < n; i++) {
			int d = ds[i];
			for (auto e : g[i]) {
				if ((dt[e] + d + 1) & 1) {
					chmin(res, *lower_bound(pr.begin(), pr.end(), dt[e] + d + 1));
				}
			}
		}
		if (res == inf) puts("-1");
		else printf("%d\n", res);
	}
    return 0;
}


Measured memory_bytes: 9748
import numpy as np
from collections import Counter

n = int(input())
A = list(map(int,input().split()))

cnt = Counter(A)

b = np.array([0]*(max(A)+1))

A.sort()
ans = 0
for a in A:
    if cnt[a] == 1 and not b[a]:
        ans += 1
    b[a::a] = 1

print(ans)

Measured memory_bytes: 63720
// Problem : A - Plural Form
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
#define 	ll		    long long
#define 	rep(i,a,n)  for(int i=a;i<n;i++)
#define		rof(i,a,n)	for(int i=a;i>=n;i--)
#define 	MOD 		1000000007
#define 	ff 			first
#define 	ss 			second
#define 	pb 			push_back
#define 	all(x) 		(x).begin(),(x).end()
#define 	dg(x)		cerr << x << endl;
#define 	endl		"\n"


using namespace std;
const int N = 1e5 + 5;
ll ar[N];

void solve(){
	string str;
	cin >> str;
	
	int ln = str.length();
	if(str[ln -1] == 's')
		str += "es";
	else
		str += 's';
	cout << str;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 3652
// 2011/08/21 Tazoe

#include <iostream>
#include <string>
#include <queue>
#include <map>
using namespace std;

struct state{
	string seg;
	int tim;
};

int main()
{
	while(true){
		struct state wrm;
		cin >> wrm.seg;
		if(wrm.seg=="0")
			break;
		wrm.tim = 0;

		queue<struct state> que;
		que.push(wrm);

		map<string, bool> memo;

		while(true){
			if(que.empty()){
				cout << "NA" << endl;
				break;
			}

			wrm = que.front();
			que.pop();

			if(memo[wrm.seg])
				continue;
			else
				memo[wrm.seg] = true;

			bool flg = true;
			for(int i=1; i<wrm.seg.size(); i++)
				if(wrm.seg[i]!=wrm.seg[0]){
					flg = false;
					break;
				}
			if(flg){
				cout << wrm.tim << endl;
				break;
			}

			struct state tmp;
			for(int i=0; i<wrm.seg.size()-1; i++)
				if(wrm.seg[i]==wrm.seg[i+1])
					continue;
				else if(wrm.seg[i]!='r'&&wrm.seg[i+1]!='r'){
					tmp.seg = wrm.seg;
					tmp.seg[i] = tmp.seg[i+1] = 'r';
					tmp.tim = wrm.tim+1;
					que.push(tmp);
				}
				else if(wrm.seg[i]!='g'&&wrm.seg[i+1]!='g'){
					tmp.seg = wrm.seg;
					tmp.seg[i] = tmp.seg[i+1] = 'g';
					tmp.tim = wrm.tim+1;
					que.push(tmp);
				}
				else if(wrm.seg[i]!='b'&&wrm.seg[i+1]!='b'){
					tmp.seg = wrm.seg;
					tmp.seg[i] = tmp.seg[i+1] = 'b';
					tmp.tim = wrm.tim+1;
					que.push(tmp);
				}
		}
	}

	return 0;
}

Measured memory_bytes: 1896
#include <stdio.h>

void p(int *array, int n){
    int i;
    for (i = 0; i < n; i++) {
        if (i != 0) putchar(' ');
        printf("%d", array[i]);
    }
    putchar('\n');
}

int main(){
    int r, c, sheet[1000][1000] = {{0}}, i, j;
    scanf("%d%d", &r, &c);
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            scanf("%d", &sheet[i][j]);
        }
    }
    
    for (i = 0;i < r;i++){
        for (j = 0;j < c;j++){
            sheet[i][c] += sheet[i][j];
            sheet[r][j] += sheet[i][j];
        }
    }
    
    for (i = 0;i < c;i++) sheet[r][c] += sheet[r][i];
    
    for (i = 0;i <= r ;i++) p(sheet[i], c + 1);
    
    return 0;
}

Measured memory_bytes: 4516
# ABC170C

x, n = map(int, input().split())

if n == 0:
    p = set([])
else:
    p = list(map(int, input().split()))
a = list(set(range(201)) - set(p))
abs_diff = [abs(i - x) for i in a]
min_abs_diff = min(abs_diff)
for i, j in zip(a, abs_diff):
    if j == min_abs_diff:
        print(i)
        break


Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	int sum = 0;
	for (int i = 0; i < s.size(); i++)
	{
		int u = s[i] - '0';
		sum += u;
	}
	if (sum % 9 == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}



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

int main(){
 int n;
 cin >>n;
 int h[n+1];
 vector<int>cost(n+1); 
 rep(i,n){
 cin >>h[i+1];
 }
  
 cost[2]= abs(h[2]-h[1]);
 for(int i=3;i<=n;i++){
 	cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2])); 	
 }
 cout<<cost[n]<<endl;
}

Measured memory_bytes: 1024
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

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

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

INF=Float::INFINITY

N,K=get_i
V=get_i
R=min(N,K)
ans=-INF
(R+1).times do|a|
    (R-a+1).times do|b|
      val=[]
      a.times do|i|
          val<< V[i] 
      end 
      (N-1).downto(N-b) do|i|
          val<< V[i]
      end
      val.sort!
      res=0
      k=K-(a+b)
      val.each do|v|
          if v<0 and k>0
              k-=1
          else
              res+=v
          end
      end
      ans=max(ans,res)
    end
end
puts ans

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	int zeros=0;
	int base=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	//cout << "input finished!" << endl;
	while(true){
		sort(a,a+n);
		base=zeros;
		for(int i=1+zeros;i<n;i++){
			a[i]=a[i]%a[base];
			if(a[i]==0){
				zeros++;
			}
		}
		if(n-1==zeros){
			sort(a,a+n);
			cout << a[zeros] << endl;
			return 0;
		}
	}
}



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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()

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

const long long INF = 1LL << 60;

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

    int x = -1, y = -1, z = -1;

    rep(i, N + 1) {
        rep(j, N - i + 1) {
            int k = N - i - j;
            if (10000 * i + 5000 * j + 1000 * k == Y) {
                x = i;
                y = j;
                z = k;
                break;
            }
        }
        if (x != -1) {
            break;
        }
    }

    cout << x << " " << y << " " << z << endl;
    return 0;
}

Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, a, func=max, one=-10 ** 18):
        self.logn = (len(a) - 1).bit_length()
        self.n = 1 << self.logn
        self.func = func
        self.one = one

        self.b = [self.one] * (2 * self.n - 1)
        for i, j in enumerate(a):
            self.b[i + self.n - 1] = j
        for i in reversed(range(self.n - 1)):
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_item(self, i):
        return self.b[i + self.n - 1]

    def update(self, index, x):
        i = index + self.n - 1
        self.b[i] = x
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def update_func(self, index, x):
        i = index + self.n - 1
        self.b[i] = self.func(self.b[i], x)
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_segment(self, l, r):
        l += self.n
        r += self.n
        s = self.one
        t = self.one
        while l < r:
            if l & 1:
                s = self.func(s, self.b[l - 1])
                l += 1
            if r & 1:
                r -= 1
                t = self.func(self.b[r - 1], t)
            l >>= 1
            r >>= 1
        return self.func(s, t)


n,k = map(int, input().split())
seg = SegmentTree([0]*(400000))
for _ in range(n):
    a = int(input())
    ma = seg.get_segment(max(0, a-k), min(400000,a+k+1))
    seg.update_func(a,ma+1)
print(seg.get_segment(0, 400000))


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


int main() {

    string s;
    cin >> s;
    set<char> st;
    for (int i = 0; i < s.length(); ++i) {
        if (st.count(s[i]) == 0) {
            st.insert(s[i]);
        } else { 
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        int a[]=new int[3];
        a[0]=sc.nextInt();
        a[1]=sc.nextInt();
        a[2]=sc.nextInt();
        Arrays.sort(a);
        if((a[0]==a[1]&&a[1]!=a[2])||(a[0]!=a[1]&&a[1]==a[2]))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


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

const int INF = 100000000;

int n;
int cnt = 0;
int ans = 0;
int main() {
    cin >> n;
    for(int i=1;i<=n;i+=2){
        cnt = 0;
        for(int j=1;j<=i;++j){
            if(i%j==0)cnt++;
        }
        if(cnt==8){
            // cout <<"ikutu:" <<i << endl;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
	long long p=0,q=0;
    long long n=0,k=0;
	cin >> n >> k;
	vector<bool> a(n,false);
	vector<long long> b(n,0);
	long long count=k,genzaiti=1;
	bool kikkake=false;
	
	for(int i=0;i<n;i++)
	{
		cin >> b.at(i);
	}
	while(kikkake==false)
	{ if(count==0)
		{
			goto FIN;
		}  
      if(a.at(genzaiti-1)==false)
		{a.at(genzaiti-1)=true;
		}
		else
		{
			kikkake=true;
			break;
		}
		genzaiti=b.at(genzaiti-1);
		count--;
		
	}
	p=genzaiti;
	while(kikkake==true)
	{
      if(count==0)
		{
			goto FIN;
		}
		genzaiti=b.at(genzaiti-1);
		count--;
		q++;
		
		if(p==genzaiti)
		{
			kikkake=false;
		}
	}
	count=count%q;
	while(kikkake==false)
	{   if(count<=0)
		{
			goto FIN;
		}
		genzaiti=b.at(genzaiti-1);
		count--;
		
	}
	
	
	
	
	FIN:
  cout << genzaiti;
}


Measured memory_bytes: 4840
N,M=map(int,input().split(" "))
count=0

nokori=[0]*(M+1)
  
for i in range(0,N):

  kk=list(map(int,input().split(" "))) 
  K=kk[0]
  del kk[0]
  
  for j in kk:
    nokori[j]+=1
    
  #print(nokori)
  
for ii in nokori:
  count+=(ii==N)
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF (1LL << 60)
typedef long long LL;
using namespace std;

int main() {
	int n;	cin >> n;
	vector<vector<int>> luck(n + 1, vector<int>(3));
	for (int i = 1; i < n + 1; i++) {
		cin >> luck[i][0] >> luck[i][1] >> luck[i][2];
	}

	vector<vector<LL>> dp(n + 1, vector<LL>(3, -INF));
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {	//i日の行動
			for (int k = 0; k < 3; k++) {	//i+1日目の行動
				if (j == k)	continue;
				dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + luck[i + 1][k]);
			}
		}
	}
	cout << *max_element(dp[n].begin(), dp[n].end());
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll n, W;
ll weight[110], value[110];

ll dp[110][100010];

int main() {
	int i,w;
	cin >> n >> W;
	for (i = 0; i < n; ++i) cin >> weight[i] >> value[i];
	for(w=0;w<=W;w++) dp[0][w] = 0;
	for(i=0;i<n;i++) {
		for(w=0;w<=W;w++) {
			if(weight[i] <= w) dp[i+1][w] = max(dp[i][w],dp[i][w-weight[i]]+value[i]);
			else dp[i+1][w] = dp[i][w];
		}
	}
	cout << dp[n][W] << endl;
}

Measured memory_bytes: 80128
import java.util.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int x = Integer.valueOf(sc.next());
            int y = Integer.valueOf(sc.next());
            int z = Integer.valueOf(sc.next());

            System.out.println(z + " " + x + " " + y);            
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int>> min_heap;

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

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

const int maxn = 1e5 + 5;
int A, B, M;
int a[maxn], b[maxn];


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int mina = 1e9;
    int minb = 1e9;
    cin >> A >> B >> M;
    for (int i = 1; i <= A; i++) {
        cin >> a[i];
        mina = min(mina, a[i]);
    }
    for (int i = 1; i <= B; i++) {
        cin >> b[i];
        minb = min(minb, b[i]);
    }
    int ans = mina + minb;
    for (int i = 1; i <= M; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, a[x] + b[y] - c);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

	class C {
		double time;
		int w,dis;
		ArrayList<Integer> list;
		public C(double time, int w, int dis, ArrayList<Integer> list) {
			this.time = time;
			this.w = w;
			this.dis = dis;
			this.list = list;
		}
		@Override
		public String toString() {
			return "C [time=" + time + ", w=" + w + ", dis=" + dis + ", list="
					+ list + "]";
		}
	}

	private double calc(int dis, int w){
		double ans = (double)dis / (2000.0 / (70 + w * 20));
		return ans;
	}

	private void doit() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int len = 1 << n;
		int [] numlist = new int[n];
		int [] dislist = new int[n];
		int [] wlist = new int[n];
		C [][] dp = new C[n][len];
		for(int i=0; i < n; i++){
			numlist[i] = sc.nextInt();
			dislist[i] = sc.nextInt();
			wlist[i] = sc.nextInt();
			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(numlist[i]);
			dp[i][1 << i] = new C(0.0,wlist[i],dislist[i],list);
		}
		for(int i = 1 ; i < len; i++) {

			for(int j = 0; (1 << j) < len; j++){
				if((i & (1 << j)) == 0){
					int nextnum = i | (1 << j);
					C min = null;
					for(int k = 0; k < n ; k++){
						if(dp[k][i] == null){
							continue;
						}
						if(min == null){
							min = dp[k][i];
						}
						double mintime = min.time + calc(Math.abs(min.dis - dislist[j]), min.w);
						double nowtime = dp[k][i].time + calc(Math.abs(dp[k][i].dis - dislist[j]), dp[k][i].w);
						if(mintime > nowtime){
							min = dp[k][i];
						}
					}
					ArrayList<Integer> nextlist = new ArrayList<Integer>();
					nextlist.addAll(min.list);
					nextlist.add(numlist[j]);
					double nexttime = min.time + calc(Math.abs(min.dis - dislist[j]), min.w);
					int nextw = min.w + wlist[j];
					int nextdis = dislist[j];
					dp[j][nextnum] = new C(nexttime, nextw, nextdis, nextlist);
				}
			}
		}

		//print
		C ans = null;
		for(int i =0; i < n;i++){
			if(ans == null){
				ans = dp[i][len-1];
			}

			if(ans.time > dp[i][len-1].time){
				ans = dp[i][len-1];
			}
		}
		for(int i = 0; i < ans.list.size() - 1;i++){
			System.out.print(ans.list.get(i) + " ");
		}
		System.out.println(ans.list.get(n - 1));

		//debug
//		for(int i = 1; i < len; i++){
//			for(int j = 0; j < n; j++){
//				if(dp[j][i] == null){
//					System.out.println("null");
//				}
//				else{
//					System.out.println(dp[j][i].toString() + " ");
//				}
//
//			}
//			System.out.println();
//		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();

	}

}

Measured memory_bytes: 43000
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;






signed main() {
	speed;
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],ans;
set<int>s;
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //freopen("milkvisits.in","r",stdin);
    //freopen("milkvisits.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        s.insert(a[i]);
        int x=*s.begin();
        if(x>=a[i])ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 10368
def min2(a,b)
    return a>b ? b : a
end
def max2(a,b)
    return a<b ? b : a
end

def get_dist(xx,yy)
    score = 0
    for x,y in xx.zip(yy)
        score += (y-x)**2
    end
    return score
end

def is_nomal(v)
    l = 0
    r = v

    if  v ==1 
         return true
    end

    while r - l > 1
        center = (r+l)/2
        center2 = center**2

        if center2 == v
            return true
        elsif center2 > v
            r = center
        else
            l = center
        end
    

    end

    return false

end

N = gets.to_i

Xlist = (1..N).map{|i| gets.split.map{|j| j.to_i}}
count =0
for i in 0...N-1
    for j in i+1...N

        if is_nomal(get_dist(Xlist[i],Xlist[j]))
            count +=1
        end

    end
end
puts count

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

#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
typedef long long ll;

int a, b, x;

signed main() {
	cin >> a >> b >> x;
	cout << (a<=x && x<=a+b ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    vector<int> ans(N - 1);
    vector<set<pair<int, int>>> edge(N);
    for(int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].insert({b, i});
        edge[b].insert({a, i});
    }
    queue<pair<int, int>> q;
    q.push({0, -1});
    while(q.size()) {
        int a, c;
        tie(a, c) = q.front(); q.pop();
        int c_ = 0;
        for(auto x : edge[a]) {
            int b, i;
            tie(b, i) = x;
            edge[b].erase({a, i});
            if(c_ == c) c_++;
            q.push({b, c_});
            ans[i] = c_ + 1;
            c_++;
        }
    }
    int K = *max_element(WHOLE(ans));
    cout << K << endl;
    for(int i = 0; i < N - 1; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 14976
import math

Q = int(input())
ls = []
rs = []

for i in range(Q):
    [l, r] = input().split() 
    ls.append(int(l))
    rs.append(int(r))

rmax = max(rs)

is_prime = [1]*(rmax+1)
is_prime[0] = 0
is_prime[1] = 0

i = 1

while i < math.sqrt(rmax):
    i += 1
    if is_prime[i] == 1:
        for j in range(i*2, rmax, i):
            is_prime[j] = 0

like2017 = [0]*(rmax+1)

for i in range(1, rmax+1, 2):
    if is_prime[i] == 1 and is_prime[int((i+1)/2)] == 1:
        like2017[i] = 1
        
cumul = [0]*(rmax+1)
for i in range(1, rmax+1):
    cumul[i] = cumul[i-1] + like2017[i]

for i in range(Q):
    print(cumul[rs[i]] - cumul[ls[i]-1])


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

int main(){
  int N;
  cin >> N;
  vector<int> c(N);
  for(int i = 0; i < N; i++){
    cin >> c.at(i);
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    if(i > 0){
      if(c.at(i-1) == c.at(i)){
        c.at(i) = 0;
        count++;
      }
    }
  }
  cout << count << endl;

}

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

using namespace std;

#define N 1000000

char str[N + 2];
long long sum_d[N + 2];
long long sum_m[N + 2];
long long sum_dm[N + 2];

long long query_d(int l, int r){
	return sum_d[r] - sum_d[l - 1];
}

long long query_m(int l, int r){
	return sum_m[r] - sum_m[l - 1];
}

int main(){
	int n, q, k, i;
	long long ans;

	scanf("%d", &n);
	scanf(" %s", str + 1);

	for (i = 1; i <= n; i++){
		sum_d[i] = sum_d[i - 1] + (str[i] == 'D');
		sum_m[i] = sum_m[i - 1] + (str[i] == 'M');
		sum_dm[i] = sum_dm[i - 1] + (str[i] == 'M' ? sum_d[i] : 0);
	}

	scanf("%d", &q);

	while (q--){
		scanf("%d", &k);
		ans = 0;

		for (i = 1; i <= n; i++){
			if (i <= k){
				if (str[i] == 'C'){
					ans += sum_dm[i];
				}
			}
			else{
				if (str[i] == 'C'){
					ans += sum_dm[i] - sum_dm[i - k] - query_d(1, i - k) * query_m(i - k + 1, i - 1);
				}
			}
		}

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

	return 0;
}

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

int main() {
    int k, s;
    cin >> k >> s;
    int ans=0;
    for (int i=0;i<=k;i++)
    {
        for (int j=0;j<=k;j++)
        {
            if (s-i-j>=0&&s-i-j<=k)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int len, n;
	int[] a;

	void run(){
		for(;sc.hasNext();){
			String[] ss=sc.nextLine().split(" ");
			len=Integer.parseInt(ss[0]);
			n=ss.length-1;
			a=new int[n];
			for(int i=0; i<n; i++){
				a[i]=Integer.parseInt(ss[i+1]);
			}
			solve();
		}
	}

	void solve(){
		double[][] dp=new double[1<<n][n];
		for(int j=0; j<1<<n; j++){
			fill(dp[j], INF);
		}
		for(int i=0; i<n; i++){
			dp[1<<i][i]=2*a[i];
		}
		for(int s=1; s<1<<n; s++){
			for(int j=0; j<n; j++){
				if((s>>j&1)==0){
					continue;
				}
				for(int i=0; i<n; i++){
					if((s>>i&1)==0){
						dp[s|1<<i][i]=min(dp[s|1<<i][i],
								dp[s][j]+2*sqrt(a[j]*a[i])-a[j]+a[i]);
					}
				}
			}
			// debug(s,dp[s]);
		}
		double min=INF;
		for(int i=0; i<n; i++){
			min=min(min, dp[(1<<n)-1][i]);
		}
		println(min<len+EPS?"OK":"NA");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

using ll = long long;
using namespace std;

int main() {
    int t1, t2;
    ll a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll d1 = t1 * (a1 - b1);
    ll d2 = d1 + t2 * (a2 - b2);
    if ((d1 > 0 && d2 > 0) || (d1 < 0 && d2 < 0)) {
        cout << 0 << endl;
    } else if (d1 == 0 || d2 == 0) {
        cout << "infinity" << endl;
    } else {
        ll count = abs(d1) / abs(d2) + 1;
        if (abs(d1) % abs(d2)) {
            cout << 2 * count - 1 << endl;
        } else {
            cout << 2 * count - 2 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
        a[i] *= 2;
    }

    ll x = 0;
    rep(i, n) x = a[i] - x;
    x /= 2;

    rep(i, n){
        cout << x << endl;
        x = a[i] - x;
    }
    return 0; 
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int P[100000];
int low[100000];
int high[100000];

void search(int pos, int prev, const vector<vector<int>>& g){
	low[pos] = high[pos] = (P[pos] != -1 ? P[pos] : -1);
	for(int next : g[pos]){
		if(next == prev) continue;
		search(next, pos, g);
		if(low[next] == -2 && high[next] == -2){
			low[pos] = high[pos] = -2;
			return;
		} else if(!(low[next] == -1 && high[next] ==-1)){
			if(low[pos] == -1){
				low[pos] = low[next]-1;
				high[pos] = high[next]+1;
			} else {
				if(abs(low[pos]+low[next])%2 != 1){
					low[pos] = high[pos] = -2;
					return;
				}
				low[pos] = max(low[pos], low[next]-1);
				high[pos] = min(high[pos], high[next]+1);
				if(high[pos] < low[pos]){
					low[pos] = high[pos] = -2;
					return;
				}
			}
		}
	}
}

void search2(int pos, int prev, const vector<vector<int>>& g){
	for(int next : g[pos]){
		if(next == prev) continue;
		if(low[next] == -1 && high[next] == -1){
			low[next] = low[pos] - 1;
			high[next] = high[pos] + 1;
		} else {
			low[next] = max(low[next], low[pos]-1);
			high[next] = max(high[next], high[pos]+1);
		}
		search2(next, pos, g);
	}
}

int main(){
	int N;
	while(cin >> N){
		vector<vector<int>> g(N);
		for(int i=0;i<N-1;i++){
			int A, B; cin >> A >> B;
			--A; --B;
			g[A].push_back(B);
			g[B].push_back(A);
		}
		int K; cin >> K;
		memset(P, -1, sizeof(P));
		int start;
		for(int i=0;i<K;i++){
			int V; cin >> V;
			cin >> P[V-1];
			start = V-1;
		}
		search(start, -1, g);
		if(low[start] == -2 && high[start] == -2){
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
			search2(start, -1, g);
			for(int i=0;i<N;i++) cout << low[i] << endl;
		}
	}
}



Measured memory_bytes: 15360
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

	int a, b;
	cin >> a >> b;

	if (a + b == 15)
		COUT("+");
	else if (a * b == 15)
		COUT("*");
	else
		COUT("x");


	return 0;
}


Measured memory_bytes: 256
import os
import sys
from math import gcd

import numpy as np


def solve(inp):
    n = inp[0]
    aaa = inp[1:]

    g = 0
    for i in range(n):
        g = gcd(g, aaa[i])
    if g != 1:
        return -1

    PRIMES = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
              107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223,
              227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347,
              349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
              467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
              613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743,
              751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883,
              887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997)

    one_count = (aaa == 1).sum()
    val = set(aaa)
    if len(val) + max(0, one_count - 1) < n:
        return 0

    for p in PRIMES:
        multiple_count = 0
        for a in val:
            b = a
            if b % p == 0:
                multiple_count += 1
                b //= p
                while b % p == 0:
                    b //= p
                if b == 1:
                    val.remove(a)
                else:
                    if b in val:
                        return 0
                    val.remove(a)
                    val.add(b)

        if multiple_count > 1:
            return 0

    return 1


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(['setwise coprime', 'pairwise coprime', 'not coprime'][ans])


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

int main() {
    int n;
    cin >> n;
    int t[n];
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    int m;
    cin >> m;
    int p[m], x[m];
    for (int i = 0; i < m; i++) {
        cin >> p[i] >> x[i];
    }
    for (int i = 0; i < m; i++) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
            if (j == p[i]-1) ans += x[i];
            else ans += t[j];
        }
        cout << ans << endl;
    }
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  vector<int> cnt;
  int n = a[0];
  int c = 1;
  for (int i = 1; i < N; i++) {
    if (n == a[i]) {
      c++;
    } else {
      cnt.push_back(c);
      n = a[i];
      c = 1;
    }
  }
  cnt.push_back(c);

  int ans = 0;
  for (int i = 0; i < cnt.size(); i++) {
    ans += cnt[i] / 2;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int N, M;
    cin >> N >> M;
    priority_queue<P,vector<P>, greater<P> > queue;
    for(size_t i = 0; i < N; i++)
    {
        ll a, b;
        cin >> a >> b;
        queue.push(P(a, b));
    }
    ll price = 0;
    while(M>0){
        P cheapest = queue.top();
        if(cheapest.second > M) {
            price += ll(cheapest.first * M);
            M = 0;
        }
        else {
            price += ll(cheapest.first * cheapest.second);
            M -= cheapest.second;
            queue.pop();
        }
    }
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define mp make_pair
int main(void)
{
	int n, m;
	while (cin >> n >> m, n && m){
		vector <int> taro, hanako;
		int tmp, tsum = 0, hsum = 0;
		for (int i = 0; i < n; i++){
			cin >> tmp;
			taro.push_back(tmp);
			tsum += taro[i];
		}
		for (int i = 0; i < m; i++){
			cin >> tmp;
			hanako.push_back(tmp);
			hsum += hanako[i];
		}
		int mi = 210000000;
		int ret1, ret2;
		for (int i = 0; i < n; i++){
			//cout << "*";
			for (int j = 0; j < m; j++){
				if (tsum - taro[i] + hanako[j] == hsum - hanako[j] + taro[i]){
					if (tsum - taro[i] + hanako[j] < mi){
						mi = tsum - taro[i] + hanako[j];
						ret1 = taro[i];
						ret2 = hanako[j];
					}
				}
			}
		}//puts("");
		if (mi == 210000000) cout << "-1" << endl;
		else cout << ret1 << " " << ret2 << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>

using namespace std;

struct SccKosaraju {
    int n;
    vector<vector<int>> g;
    vector<vector<int>> rg;
    vector<bool> visited;
    vector<int> sccno;
    int sccCount = 0;
    vector<int> s;
    
    
    SccKosaraju(int n): n(n) {
        g.assign(n, vector<int>());
        rg.assign(n, vector<int>());
        visited.assign(n, false);

        sccno.assign(n, -1);
    }
    
    void addEdge(int from, int to) {
        g[from].push_back(to);
        rg[to].push_back(from);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (!visited[i]) {
                dfs1(i);
            }
        }
        
        for (int i = n - 1; i >= 0; i--) {
            if (sccno[s[i]] == -1) {
                sccCount++;
                dfs2(s[i]);
            }
        }
    } 
    
    bool sameScc(int u, int v) {
        return sccno[u] == sccno[v];
    }
    
    void dfs1(int u) {
        visited[u] = true;
        for (int v : g[u]) {
            if (!visited[v]) {
                dfs1(v);
            }
        }
        s.push_back(u);
    } 
    
    void dfs2(int u) {
        sccno[u] = sccCount;
        for (int v : rg[u]) {
            if (sccno[v] == -1) {
                dfs2(v);
            }
        }
    }   
};

int main() {
    int n, m;
    cin >> n >> m;
    SccKosaraju scc(n);
    
    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to;
        scc.addEdge(from, to);
    }
 
    scc.solve();
    
//    for (int i = 0; i < n; i++) {
//        cout << i << " " << scc.sccno[i] << endl;
//    }
    
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        int u, v;
        cin >> u >> v;
        cout << (scc.sameScc(u, v)? 1 : 0) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    deque<char> que;
    bool flag=false;
    rep(i,s.size()){
        if(!flag && s[i]=='R') continue;
        que.push_back(s[i]);
        flag=true;
    }
    while(!que.empty()){
        if(que.back()=='W'){
            que.pop_back();
        }else{
            break;
        }
    }
    ll R=0,W=0;
    rep(i,que.size()){
        if(que[i]=='R') R++;
        else W++;
    }
    ll ans=min(R,W);
    ll cnt=0;
    rep(i,n){
        if(i<R && que[i]=='W')  cnt++;
    }
    chmin(ans,cnt);
    cout<<ans<<endl;
}

Measured memory_bytes: 3832
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define f(x,y,x1,y1,x2,y2) (y2-y1)*(x-x1)-(x2-x1)*(y-y1) 


int determine(double px,double py,double x1,double y1,double x2,double y2,double x3,double y3) /*pが
(x1,y1)と(x2,y2)結ぶ直線に関して同じ側にいれば1,そうでなければ-1*/
{
  if((f(px,py,x1,y1,x2,y2)>0&&f(x3,y3,x1,y1,x2,y2)>0) || (f(px,py,x1,y1,x2,y2)<0&&f(x3,y3,x1,y1,x2,y2)<0))
    return 1;
  else
    return -1;
}

int main(void)
{
  double px,py,x1,x2,x3,y1,y2,y3;
  
  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&px,&py)!=EOF){
    if(determine(px,py,x1,y1,x2,y2,x3,y3)==1 && determine(px,py,x2,y2,x3,y3,x1,y1)==1 && 
       determine(px,py,x3,y3,x1,y1,x2,y2)==1)
      printf("YES\n");
    else 
      printf("NO\n");
  }
  
  
  return 0;
}

Measured memory_bytes: 612
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let mut ai: Vec<u32> = (0..n).map(|_| read()).collect();
    ai.sort_by(|a, b| a.partial_cmp(b).unwrap());
    ai.reverse();
    let mut a_sum: u32 = 0;
    let mut b_sum: u32 = 0;
    for (i, n) in ai.into_iter().enumerate() {
        if i % 2 == 0 {
            a_sum += n
        } else {
            b_sum += n
        }
    }
    println!("{}", a_sum - b_sum);
}


Measured memory_bytes: 4352
import java.util.*;

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

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    int count;
        
    count = A;
    A = B;
    B = count;
    
    count = A;
    A = C;
    C = count;
    
    System.out.println(A + " " + B + " " + C);
  }
}


Measured memory_bytes: 22228
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define INF 10000000
#define MOD (long long)1e+9+7

typedef long long ll;
typedef pair<ll, ll> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z


int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

void solve(void){
    ll n;
    cin >> n;
    ll ans = 1;
    rep(n, i) {
        ans *= i+1;
        ans %= MOD;
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 256