akhauriyash/Code-Regression huggingface dataset:
"""基本方針：500円で両替出来るだけして、端数を5円に変換する。
"""
import math
X = int(input())
ans = 0
#以後はXを減算していく
#500円玉両替処理
ans += math.floor(X / 500) * 1000
X -= math.floor(X / 500) * 500
#5円玉両替処理
ans += math.floor(X / 5) * 5
X -= math.floor(X / 5) * 5

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define MAXN 200005
#define INT_SIZE 32
#define debug cout<<"we are debugging"<<endl;
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
const ll MAX = 1000005;
ll fac[MAX], finv[MAX], inv[MAX];
void cmbinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i=2;i<MAX;i++) {
		fac[i] = fac[i-1]*i%MOD;
		inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i] = finv[i-1]*inv[i]%MOD;
	}
}
ll cmb(ll n, ll k) {
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main()
{
     fast;
     cmbinit();
    ll n;
    cin>>n;
    ll ans=fast_expo(10,n);
    ans%=MOD;
    ll val=0,ans1;
    for(ll i=1;i<=n;i++)
    {
         ans1=((cmb(n,i))%MOD*(fast_expo(8,n-i))%MOD)%MOD;
         val=(val+ans1)%MOD;
         val%=MOD;
    }
    for(ll i=1;i<=n;i++)
    {
         ans1=((cmb(n,i))%MOD*(fast_expo(8,n-i))%MOD)%MOD;
         val=(val+ans1)%MOD;
         val%=MOD;
    }
    ll ans3=fast_expo(8,n)%MOD;
    val=(val+ans3)%MOD;
    cout<<(ans-val+MOD)%MOD;
}


Measured memory_bytes: 27052
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ll a[100005],b[100005];

vector<pll> v;

int main()
{ios_base::sync_with_stdio(false);
ll n,h,ans=0;
cin>>n>>h;
rep(i,0,n-1)
{
	cin>>a[i]>>b[i];
	v.pb(mp(a[i],1));
	v.pb(mp(b[i],0));
}
sort(all(v));
reverse(all(v));
int sz=v.size();
rep(i,0,sz-1)
{
	if(v[i].ss==0)
	{
		h-=v[i].ff;
		ans++;
		if(h<=0)break;
	}
	else
	{
		ll x=v[i].ff;
		ans+=(h+x-1)/x;
		break;
	}
}
ol(ans);
return 0;
}



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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  string s;
  cin>>n>>s;
  
  auto u = unique(s.begin(), s.end());
  s.erase(u, s.end());
  
  cout<<s.length();
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
void solve(){
	int n;
	cin>>n;
	cout<<(n+n*n+n*n*n)<<'\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tt;
    tt=1;
    while(tt--)
        solve();
    return 0;
}


Measured memory_bytes: 3652
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();

		sc.close();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < N; i++) {
			sb.append(S.charAt(i));
			sb.append(T.charAt(i));
		}

		out.println(sb.toString());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct RH{
    string S;
    const int p=1000000007;
    vector<int>po[2];
    const int M=2;
    const int mod[2]={1000000009,1000000021};
    vector<int>H[2];

    RH(string s){
        S=s;
        rep(k,M){
            H[k]=vector<int>(S.size()+1);
            po[k]=vector<int>(S.size()+1);
            po[k][0]=1;
            rep(i,S.size()){
                H[k][i+1]=(H[k][i]*p+S[i])%mod[k];
                po[k][i+1]=po[k][i]*p%mod[k];
            }
        }
    }

    vector<int>getH(int l,int r){
        vector<int>res;
        rep(k,M){
            res.pb((H[k][r]-H[k][l]*po[k][r-l]%mod[k]+mod[k])%mod[k]);
        }
        return res;
    }
};

typedef unsigned long long ull;

int N;
string S;

signed main(){
    /*
    for(int i=1000000009+1;;i++){
        bool ok=true;
        for(int j=2;j*j<=i;j++)if(i%j==0)ok=false;
        if(ok){
            cout<<i<<endl;
            break;
        }
    }*/
    cin>>N;
    cin>>S;

    string uku=S;
    reverse(all(uku));
    uku=S+"*"+uku;

    RH rh(uku);
    for(int i=2;i<=S.size();i++){
        bool ok=true;
        for(int j=2*(i-1);j<S.size();j+=2*(i-1)){
            int L=min(2*(i-1),N-j);
            if(rh.getH(0,L)!=rh.getH(j,j+L))ok=false;
        }


        int L=min(i-1,N-(i-1));
        if(rh.getH(i-1,i-1+L)!=rh.getH(N+1+N-i,N+1+N-i+L))ok=false;

        if(ok){
            cout<<i<<endl;return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 99592
#include <stdio.h>
int main(void){
    // Your code here!
    long N, A, B;
    
    scanf("%ld %ld %ld", &N, &A, &B);
    
    if((B-A)%2 == 0){
        printf("%ld", (B-A)/2);
        return 0;
    }
    
    if((B-1)<(N-A)){
        printf("%ld", (A+B-1)/2);
    }else{
        printf("%ld", N-(A+B-1)/2);
    }
}


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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

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

int main()
{

	//ifstream cin("input.txt");
	//freopen("output.txt", "w", stdout);

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	map<ll, vector<int> > pos;
	pos[0].pb(-1);
	for (int i = 0; i < n; ++i) {
		pos[a[i]].pb(i);
	}

	vector<ll> ans(n);

	ll cnt = 0;
	map<ll, vector<int> >::iterator it = --pos.end();
	int x = n;
	while (true) {
		x = min(x, it->second[0]);
		if (x == -1) {
			break;
		}
		cnt += sz(it->second);
		map<ll, vector<int> >::iterator prev = it;
		--prev;
		ll val = it->first - prev->first;
		ans[x] += val * cnt;
		--it;
	}

	for (int i = 0; i < n; ++i) {
		cout << ans[i] << '\n';
	}

}


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

bool ok=0;
int n,k;
int a[200005];
int l[200005];

bool maxn[200005];
bool minn[200005];
deque<int> que;

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        if(a[i]>a[i-1]||i==1)
            l[i]=l[i-1]+1;
        else l[i]=1;
    }

    for(int i=1;i<=n;i++){
        while(!que.empty()&&que.front()<=i-k)que.pop_front();
        while(!que.empty()&&a[que.front()]<a[i])que.pop_front();
        if(que.empty())maxn[i]=1;
        que.push_back(i);
    }
    while(!que.empty())que.pop_back();
    for(int i=n;i>=1;i--){
        while(!que.empty()&&que.front()>=i+k)que.pop_front();
        while(!que.empty()&&a[que.front()]>a[i]){
            que.pop_front();
        }
        if(que.empty())minn[i]=1;
        que.push_back(i);
    }

   // for(int i=1;i<=n;i++)
   // {
   //     cout<<minn[i]<<" "<<maxn[i]<<" "<<l[i]<<endl;
   // }

    int ans=1;
    if(l[k]==k)ok=1;
    for(int i=k+1;i<=n;i++)
    {
        if(l[i]>=k){if(!ok){ok=1;ans++;}continue;}
        if(minn[i-k]&&maxn[i])continue;
     //   cout<<" "<<i<<endl;
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2432
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String S = scan.next();
        char[] d = S.toCharArray();
        List<Integer> red = new ArrayList<>();
        red.add(-1);
        List<Integer> green = new ArrayList<>();
        green.add(-1);
        List<Integer> blue = new ArrayList<>();
        blue.add(-1);
        for (int i = 0; i < d.length; i++) {
            if (d[i] == 'R') {
                red.add(i);
                continue;
            }
            if (d[i] == 'G') {
                green.add(i);
                continue;
            }
            if (d[i] == 'B') {
                blue.add(i);
                continue;
            }
        }
        red.add(N);
        green.add(N);
        blue.add(N);
        long ans = 0;
        int red_len = red.size();
        int green_len = green.size();
        int blue_len = blue.size();
        ans += count(N, red, green, blue);
        ans += count(N, blue, green, red);
        ans += count(N, green, red, blue);
        ans += count(N, blue, red, green);
        ans += count(N, green, blue, red);
        ans += count(N, red, blue, green);
        System.out.println(ans);
    }

    private long count(int N, List<Integer> red, List<Integer> green, List<Integer> blue) {
        int red_len = red.size();
        int blue_len = blue.size();
        long ans = 0;
        for (int g : green) {
            if (g == -1 || g == N) {
                continue;
            }
            int right_most_red = Collections.binarySearch(red, g);
            right_most_red = (0 <= right_most_red) ? right_most_red: ~right_most_red;
            if (right_most_red == red_len - 1) {
                right_most_red -= 1;
            }
            while (g <= red.get(right_most_red)) {
                right_most_red -= 1;
            }
            if (right_most_red == 0) {
                continue;
            }
            int left_most_blue = Collections.binarySearch(blue, g);
            left_most_blue = (0 <= left_most_blue) ? left_most_blue : ~left_most_blue;
            if ( left_most_blue == blue_len - 1) {
                continue;
            }
            HashSet<Integer> rc = new HashSet<>();
            for (int i = 1; i <= right_most_red; i++) {
                rc.add(g - red.get(i));
            }
            long red_size = rc.size();
            HashSet<Integer> bc = new HashSet<>();
            for (int i = left_most_blue; i < blue_len - 1; i++) {
                bc.add(blue.get(i) - g);
            }
            long blue_size = bc.size();
            for (int x : bc) {
                rc.remove(x);
            }
            long common = red_size - rc.size();
            ans += red_size * blue_size - common;
        }
        return ans;
    }
}


Measured memory_bytes: 55148
/*
先手肯定跑到离后手最远的地方。

直接以后手为根建立就可以了。 
*/

#include <cstdio>
#include <algorithm>

const int MAXN = 100000 + 10;

int n, p1, p2;
int pre[MAXN << 1], to[MAXN << 1], head[MAXN], wcnt;
int dep[MAXN], maxdep[MAXN], fa[MAXN];

inline void addedge(int u, int v) {
	wcnt++;
	pre[wcnt] = head[u];
	head[u] = wcnt;
	to[wcnt] = v;
}
inline void add2edge(int u, int v) {
	addedge(u, v);
	addedge(v, u);
}

void dfs(int u) {
	int i;
	
	maxdep[u] = dep[u];
	for(i=head[u]; i; i=pre[i]) {
		if(!dep[to[i]]) {
			fa[to[i]] = u;
			dep[to[i]] = dep[u] + 1;
			dfs(to[i]);
			maxdep[u] = std::max(maxdep[u], maxdep[to[i]]);
		}
	}
}

int main() {
	int i, u, v, t;
	int ans = 0;
	
	scanf("%d %d %d", &n, &p1, &p2);
	for(i=1; i<n; i++) {
		scanf("%d %d", &u, &v);
		add2edge(u, v);
	}
	
	dep[p2] = 1;
	dfs(p2);
	t = (dep[p1] - dep[p2]) / 2;
	for(i = 0; i <= t; i++) {
		ans = std::max(ans, maxdep[p1]);
		p1 = fa[p1];
	}
	printf("%d\n", ans - 2);
	return 0;
}

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

using namespace std;

int main() {
	vector<int> h(3);
	cin >> h[0] >> h[1] >> h[2];
	sort(h.begin(), h.end());
	if(h[0] == 5 && h[1] == 5 && h[2] == 7)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


Measured memory_bytes: 3624
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    M = sum(A)
    table = set()
    i = 1
    while i * i <= M:
        if M % i == 0:
            table.add(i)
            table.add(M // i)
        i += 1

    res = 1
    for p in table:
        B = list(map(lambda x: x%p, A))
        B.sort()
        
        forward = [0]*N
        forward[0] = B[0]
        for j in range(1,N):
            forward[j] = forward[j-1] + B[j]
        
        back = [0]*N
        if B[j] != 0:
            back[N-1] = p - B[j]
        for j in reversed(range(N-1)):
            if B[j] == 0:
                back[j] = back[j+1]
            else:
                back[j] = back[j+1] + p - B[j]
        
        for j in range(N-1):
            if forward[j] == back[j+1] and forward[j] <= K:
                res = max(res, p)
    
    print(res)
        

if __name__ == '__main__':
    main()

Measured memory_bytes: 68712
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const int MAXN = 5000;
const int MOD = 1000000007;
const int INF = 2000000000;
const double PI = 3.14159265358979;
const int dir_4r[] = { -1, 1, 0, 0 };
const int dir_4c[] = { 0, 0, -1, 1 };
const int dir_8r[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int dir_8c[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() 
{
	string str;
	while (cin >> str)
		cout << str[0] << str.length() - 2 << str[str.length() - 1] << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	int cnt=0;
	while(1){
		char c=getchar();
		if(c==10)break;
		if(cnt^=1)putchar(c);
	}
}

Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp.split.map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split.map(&:to_i)

count = 0

t.each do |value|
  left = 0
  right = n

  while (left < right) do
    mid = (left + right) / 2
    if s[mid] == value
      count += 1
      break
    elsif s[mid] > value
      right = mid
    elsif s[mid] < value
      left = mid + 1
    end
  end
end

puts count


Measured memory_bytes: 15640
N = int(input())
D = list(map(int,input().split()))
Semi = 0
i = 0
D.sort()
while i != N//2:
    Semi = D[i]
    i += 1
if len([el for el in D if el > Semi]) != N//2:
    print(0)
else:
    print(min([el for el in D if el > Semi])-Semi)

Measured memory_bytes: 14392
#include <iostream>
#include <cstdio> 


using namespace std;

int main() {
	int x;
	

	int i = 1;
	while (1) {
		cin >> x;
		if (x==0) break;

		printf("Case %d: %d\n", i, x);
		i++;
	}


	return 0;
}



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

int main (){
    int A, B, C = 0;
    cin >> A >> B;
    for (int i = A; i <= B; i++){
        
        if (i / 10000 == i % 10){
            if (i / 1000 % 10 == i % 100 / 10){
                C ++;
            }
        }
    }
    cout << C << endl;
}


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

int main() {
  int sum = 0, N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);
  sort(p.begin(), p.end());
  for (int i = 0; i < K; i++)
    sum += p.at(i);
  cout << sum << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    bool f = true;
    if(n % 2) f = false;
    rep(i, 0, n / 2) if(s[i] != s[n / 2 + i]) f = false;
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main{
	public static void main(String args[]) throws IOException{
		Scanner bf = new Scanner(System.in);
		long[] list = new long[31];
		list[0] = 1;
		list[1] = 1;
		list[2] = 2;
		list[3] = 4;
		for(int i=4; i<31; i++){
			list[i] = list[i-1]+list[i-2]+list[i-3];
		}
		for(int i=0; i<31; i++){
			list[i] = (list[i]-list[i]%10)/10+1;
			list[i] = (list[i]-list[i]%365)/365+1;
		}
		while(true){
			int N = bf.nextInt();
			if(N==0) break;
			System.out.println(list[N]);
		}
	}
}

Measured memory_bytes: 17188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());

    bool res = true;
    for (int i = 0; i < N - 1; i++)
    {
        if (A.at(i) == A.at(i + 1))
        {
            res = false;
            break;
        }
    }
    if (res)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  string s;cin >> s;
  map<int,int> mm;
  LL ans = 0;
  int lst = 0;
  mm[0]++;
  reverse(ALL(s));
  int mul = 1;
  for(auto it:s){
    lst += mul*(it-'0');
    lst %= 2019;
    ans += mm[lst];
    mm[lst]++;
    // cout << lst << endl;
    mul *= 10;
    mul %= 2019;
  }
  cout << ans << endl; 
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  if ((S[0] == S [1] && S[2] == S[3] && S[0] != S[2]) || (S[0] == S [2] && S[1] == S[3] && S[0] != S[3]) || (S[0] == S [3] && S[1] == S[2] && S[0] != S[2]))
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}


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

int main()
{
    int n, a, b, c, x;

    while( cin >> n >> a >> b >> c >> x )
    {
        if( n + a + b + c + x == 0 )
            break;

        int d[n];
        for( int i = 0; i < n; i++ )
            cin >> d[i];
        
        int target = 0, cnt = 0;
        while( target != n && cnt <= 10000 )
        {
            if( x == d[target] )
            {
                target++;
                if( target == n )
                    break;
            }
            x = ( a * x +  b ) % c;
            cnt++;
        }
        if( cnt > 10000 )
            cout << -1 << endl;
        else
            cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3000
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    int dx = c-a,dy = d-b;
    cout<<c-dy<<" "<<d+dx<<" "<<a-dy<<" "<<b+dx;
}



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

using namespace std;

#define ALL(a) (a).begin(), (a).end()
typedef long long ll;

int main() {
		int N, M;
		cin >> N >> M;
		vector<int> d[100001];

		int p[M], y[M];
		for (int i = 0; i < M; i++) {
				cin >> p[i] >> y[i];
				d[p[i]].push_back(y[i]);
		}

		for (int i = 0; i < 100001; i++) {
				sort(ALL(d[i]));
		}

		for (int i = 0; i < M; i++) {
				int lastDigit = lower_bound(ALL(d[p[i]]), y[i]) - d[p[i]].begin() + 1;
				printf("%06d%06d\n", p[i], lastDigit);
		}
		return 0;
}


Measured memory_bytes: 7808
#include <vector>
#include <iostream>
#include <limits>
#include <queue>
#include <utility>

using namespace std;


struct edge {
    int src;
    int dst;
    int weight;

    edge(int src, int dst, int w) : src(src), dst(dst), weight(w) {}
};

bool operator < (const edge &a, const edge &b) {
  return a.weight > b.weight;
}


int main() {
    int v, e, r;
    cin >> v >> e >> r;

    vector<vector<edge>> G(v);
    for (int i = 0; i < e; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s].emplace_back(s, t, d);
    }

    // Dijkstra's algorithm (with pritority queue)
    auto INF = numeric_limits<int>::max();
    vector<int> d(v, INF);
    vector<bool> visited(v, false);
    priority_queue<edge> Q;

    Q.emplace(-1, r, 0);
    d[r] = 0;
    while (!Q.empty()) {
        auto e = Q.top(); Q.pop();
        visited[e.dst] = true;
        if (d[e.dst] < e.weight)
            continue;

        for (auto& x : G[e.dst]) {
            if (visited[x.dst])
                continue;
            int w = x.weight + d[e.dst];
            if (w < d[x.dst]) {
                d[x.dst] = w;
                Q.emplace(e.dst, x.dst, w);
            }
        }
    }

    for (int i = 0; i < v; ++i) {
        if (d[i] != INF) {
            cout << d[i] << endl;
        } else {
            cout << "INF" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 16048
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    repr(i,1,n){
        if(a[i] < a[i-1]){
            ans += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  for(int i = 0; i < 500000; i++){
    double res = i * 1.08;
    if((int)res == n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
#define non __builtin_popcount
#define ml map<ll, ll> 
#define ms map<string , ll> 
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	
	string s;
	ll m,x,y, my=0, ym=0;
	cin>>s;
	x= (s[0]-'0')*10 + (s[1]-'0');
	y= (s[2]-'0')*10 + (s[3]-'0');
/*	if(x<13)
	{
	    
	    
	}*/
	if(x<13 && y<13 && x>0 && y>0)
	cout<<"AMBIGUOUS";
	else if(x<13 && x>0)
	cout<<"MMYY";
	else if(y<13 && y>0)
	cout<<"YYMM";
	else
	cout<<"NA";
	
    return 0;
}























Measured memory_bytes: 256
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Sun Apr  1 19:07:52 2018
//
package main

import (
	"fmt"
)

var N int
var A []int

func main() {
	fmt.Scan(&N)

	A = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	count := 0
	for i := range A {
		if A[i]%2 == 1 {
			count++
		}
	}

	if count%2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

void printdq(deque<char> dq, int rev)
{
	int i;
	if(rev == 0)
	{

		for(auto it=dq.begin(); it!=dq.end(); it++)
			cout << *it;

		// for(i=0; i<dq.size(); i++)
		// 	cout << dq.front() << " ";
		// dq.pop_front();
	}
	else
	{
		reverse(dq.begin(), dq.end());
		for(auto it=dq.begin(); it!=dq.end(); it++)
			cout << *it;
	}
	cout << "\n";
}

int main()
{
	string s;
	cin >> s;
	deque<char> dq;
	for(int i=0; i<s.size(); i++)
	{
		dq.push_back(s[i]);
	}
	int i, j, k, x, y, q;
	cin >> q;
	int rev=0;
	while(q--)
	{
		int f, t;
		char c;
		cin >> t;


		if(t == 1)
			rev = rev^1;
		else
		{
			cin >> f >> c;
			if(f == 1 && rev == 0)
			{
				// printdq(dq, rev);
				// cout << "AA";
				dq.push_front(c);
				// printdq(dq, rev);
			}
			else if(f == 2 && rev == 0)
			{
				// cout << "BB";
				dq.push_back(c);
			}
			else if(f == 1 && rev == 1)
			{
				// cout << "DD";
				dq.push_back(c);
			}
			else
			{
				// cout << "EE";
				dq.push_front(c);
			}
		}

		

		
	}
	printdq(dq, rev);

}

Measured memory_bytes: 1280
#include<stdio.h>
#include<math.h>

#define P 10000
#define UNDEFINED -1

int CheckPrime(int v);	//v????´???°??????1????????????
int GetPrime(int n);	//n??????????´???°????????????
int PRIME[P];			//?´???°?????????

int main(){
	int v = 0;
	int N = 0;
	scanf("%d", &N);
	int num = 0;

	for( int i = 0; i < P; i++ ){
		PRIME[i] = UNDEFINED;
	}

	for( int i = 0; i < N; i++ ){
		scanf("%d", &v);
		num += CheckPrime(v);
	}

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

	return 0;
}

int CheckPrime(int v){
	for( int i = 0; i < P; i++ ){
		if( PRIME[i] == UNDEFINED ){
			PRIME[i] = GetPrime(i);
		}
		if( v == PRIME[i] ){
			return 1;
		}
		if( v % PRIME[i] == 0){
			return 0;
		}
		if( sqrt(v) + 1 < PRIME[i] ){
			return 1;
		}
	}
	return 1;
}

int GetPrime(int n){
	if( n > P ){
		printf("E\n");
	}
	if( n == 0 ){
		PRIME[0] = 2;
		return 2;
	}
	if( n == 1 ){
		PRIME[1] = 3;
		return 3;
	}
	if( PRIME[n-1] == UNDEFINED ){
		PRIME[n-1] = GetPrime(n-1);
	}

	int v = PRIME[n-1] + 2;

	for( int i = 0; i < n; i++){
		if( v % PRIME[i] == 0 ){
			i = 0;
			v += 2;
		}
		if( sqrt(v) + 1 < PRIME[i] ){
			break;
		}
	}
	PRIME[n] = v;
	return v;
}

Measured memory_bytes: 1064
#include <stdio.h>

int main(void)
{
	int i, j, k, x, n,kekka;
	while (1)
	{
		scanf("%d %d", &n, &x);
		kekka = 0;

		if (n == 0 && x == 0)
		{
			break;
		}
		else
		{
			for (i = 1; i < n-1; i++)
			{
				for (j = i+1; j < n; j++)
				{
					for (k = j+1; k < n+1; k++)
					{
						if ((i + j + k) == x)
						{
							//printf("%d", (i + j + k));
							kekka++;
						}
					}
				}
			}
		}
		printf("%d\n", kekka);
	}

	
	return 0;
}


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

int main() {
    int S;
    int h, m, s;
    cin >> S;
    s = S % 60;
    m = ((S - s) % 3600) / 60;
    h = (S - m - s) / 3600;
    cout << h << ':' << m << ':' << s << endl;
    return 0;
}



Measured memory_bytes: 3100
A, B = map(int, input().split())
N = B - A + 1
pn, ans = 0, 0

def p(pn):
  if pn % 2 == 0: return 0
  else: return 1

if A % 2 == 0:
  pn = N // 2
  if B % 2 == 0:
    ans = p(pn) ^ B
  else:
    ans = p(pn)
else:
  pn = (N - 1) // 2
  if B % 2 == 0:
    ans = A ^ p(pn) ^ B
  else:
    ans = A ^ p(pn)

print(ans)

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

double max_value(int* v, int size) {
    double max_v = (double)(v[0] + v[1]) / 2;
    for (int i = 2; i < size; i++) {
        max_v = (max_v + v[i]) / 2;
    }
    return max_v;
}

int main() {
    int N;
    cin >> N;
    int* v;
    v = new int[N];
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    sort(v, v + N);
    cout << max_value(v, N) << endl;
}

Measured memory_bytes: 256
/* C */

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    
    if(n >= m){
    	cout << 0 << endl;
    }else{
	    int* x = new int[m];
    	int* dif = new int[m - 1];

	    for(int i = 0; i < m; i++){
    		cin >> x[i];
	    }
    	
	    sort(x, x+m);

	    for(int j = 0; j < m - 1; j++){
    		dif[j] = x[j + 1] - x[j];
    	}

	    sort(dif, dif + m - 1);

	    int sum = 0;

	    for(int k = 0; k < m - n; k++){
    		sum += dif[k];
	    }

	    cout << sum << endl;

	}
	
}

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

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<int,pair<int,ll> > pii;
typedef vector<int> vi;

#define f first
#define s second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<(n); i++)
#define Forn(i, n) for(register int i=1; i<=(n); i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int ex_gcd(int a, int b, int&x, int&y, int mod=1e9+7)
{
    if(!a)
    {
        x=0, y=1;
        return b;
    }
    int d=ex_gcd(b%a, a, y, x);
    x=(x-1LL*b/a*y%mod)%mod;
    return d;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=1e5+5;

int N, cnt, vis[MAX], A[MAX], B[MAX];
pi tot[MAX<<1];
ll ret, ans1, ans2;

int main()
{
    N=in();
    forn(i, N) A[i]=in(), ans1+=A[i],
               B[i]=in(), ans2+=B[i],
               tot[i*2]=mp(A[i], i), 
               tot[i*2+1]=mp(B[i], i);
    sort(tot, tot+N*2);
    forn(i, N) ret+=tot[i].f;
    forn(i, N)
    {
        if(vis[tot[i].s])
        {
            printf("%lld\n", ret);
            return 0;
        }
        vis[tot[i].s]=1;
    }
    //get 0 0  and  1 1
    ll tt=min(ans1, ans2), tv;
    if(tot[N-1].s!=tot[N].s)
        tv=tot[N].f;
    else tv=min(tot[N+1].f, tot[N-1].f-tot[N-2].f+tot[N].f);
    printf("%lld\n", min(tt, tv+ret-tot[N-1].f));
    return 0;
}

Measured memory_bytes: 2944
N = int(input())
A = list(map(int, input().split()))

D = [[0] * 2 for _ in range(N)]

for i in range(N):
  D[i] = [i, A[i]]

D.sort(key = lambda x: x[1], reverse = True)

DP = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
  n, x = D[i]
  t = i + 1
  for j in range(t + 1):
    l = j
    r = t - j
    rr = N - 1 - r
    if l != 0:
      DP[l][r] = DP[l - 1][r] + abs(n - l + 1) * x
    if r != 0:
      DP[l][r] = max(DP[l][r], DP[l][r - 1] + abs(rr + 1 - n) * x)

ans = 0
for i in range(N + 1):
  ans = max(ans, DP[i][N - i])
print(ans)


Measured memory_bytes: 106188
#include <stdio.h>

int main(){
	int x, y;
	
	while(scanf("%d %d", &x, &y) != EOF){
		int tmp, m, n;
		
		if(x > y){
			m = x;
			n = y;
		}else{
			m = y;
			n = x;
		}
		
		while(n != 0){
			tmp = n;
			n   = m % n;
			m   = tmp;
		}
		
		printf("%d %d\n", m, x / m * y);
	}

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	int n;
	int f = 0;
	string s, t;
	cin >> n;
	cin >> s;

	if (n % 2 == 1)
		cout << "No";
	else
	{
		for (int i = 0;i < n / 2;i++)
		{
			if (s[i] != s[n / 2 + i])
				f = 1;
		}
		if (f == 0)
			cout << "Yes";
		else
			cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
x = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
else:
    sum = 1
    f = True
    for a in A:
        sum *= a
        if sum > 10**18:
            print(-1)
            f = False
            break
    if f:
        print(sum)

Measured memory_bytes: 21652
import Control.Monad (replicateM)

main :: IO ()
main = do
  (n:ns) <- map (read :: String -> Integer) <$> getNLine_ 6
  print $ ans n ns

ans :: Integer -> [Integer] -> Integer
ans n ns = let m = minimum ns in if n `mod` m == 0 then 4 + n `div` m else 5 + n `div` m

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine

Measured memory_bytes: 508
#include<stdio.h>
int main()
{
    int a,b;
    char c;
    scanf("%d %c %d",&a,&c,&b);
    if(c=='+')
    {
        printf("%d\n",a+b);
    }
    else
    {
        printf("%d\n",a-b);
    }
    return 0;
}


Measured memory_bytes: 128
from collections import deque


def main():
    from collections import deque
    H, W = (int(i) for i in input().split())
    Ch, Cw = (int(i)-1 for i in input().split())
    Dh, Dw = (int(i)-1 for i in input().split())
    A = [input() for i in range(H)]
    V = [[-1]*W for i in range(H)]  # V[h][w]を頂点iとする
    d = ((1, 0), (0, 1), (-1, 0), (0, -1))

    def bfs_2d(sy, sx, v):
        que = deque()
        V[sy][sx] = v
        que.append((sy, sx))
        while que:
            uh, uw = que.popleft()
            for dy, dx in d:
                next_h = uh + dy
                next_w = uw + dx
                if not(0 <= next_h < H and 0 <= next_w < W):
                    continue
                if V[next_h][next_w] != -1:
                    continue
                if A[next_h][next_w] == '#':
                    continue
                V[next_h][next_w] = v
                que.append((next_h, next_w))

    # グループ分け
    vertex = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" or V[h][w] != -1:
                continue
            bfs_2d(h, w, vertex)
            vertex += 1

    # グラフを作成、全てのマスで5*5の範囲を走査
    G = [[] for _ in range(vertex)]
    used = [set() for _ in range(vertex)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                continue
            for dh in range(-2, 3):
                for dw in range(-2, 3):
                    if h + dh < 0 or H <= h + dh or w + dw < 0 or W <= w + dw:
                        continue
                    if A[h+dh][w+dw] == "#":
                        continue
                    if V[h][w] == V[h+dh][w+dw]:
                        continue
                    if V[h+dh][w+dw] in used[V[h][w]]:
                        continue
                    G[V[h][w]].append((V[h+dh][w+dw]))
                    used[V[h][w]].add((V[h+dh][w+dw]))

    # for h in range(H):
    #     print(V[h])

    # for i in range(vertex):
    #     print(G[i])

    # スタートからゴールまでbfsして最短距離を求める
    s = V[Ch][Cw]
    g = V[Dh][Dw]
    que = deque([0])

    dist = [-1 for _ in range(vertex)]
    par = [-1]*vertex
    que = deque()
    dist[s] = 0
    que.append(s)
    while que:
        u = que.popleft()
        for v in G[u]:
            if par[v] != -1:
                continue
            par[v] = u
            dist[v] = dist[u] + 1
            que.append(v)

    print(dist[g])


if __name__ == '__main__':
    main()


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  vector<string> ans(0);
  map<int, double> sumScore;
  sumScore[K] = 0.0;
  for (int i=0; i<K; i++) {
    sumScore[K] += log(A[i]);
  }
  for (int i=K; i<N; i++) {
    sumScore[i+1] = sumScore[i] - log(A[i-K]) + log(A[i]);
    if (sumScore[i+1] > sumScore[i]) ans.emplace_back("Yes");
    else ans.emplace_back("No");
  }
  for (string a : ans) {
    cout << a << endl;
  }
}


Measured memory_bytes: 23216
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(n+1), y(m+1);
    cin >> x[0] >> y[0];
    for(int i=1; i<=n; ++i)
        cin >> x[i];
    for(int i=1; i<=m; ++i)
        cin >> y[i];

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if(x.back() < y.front())
        cout << "No War" << endl;
    else
        cout << "War" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <string>
#include <cstring>
#define REP(i,n) for(int i=0;i<n;i++)
using Int = long long;
using namespace std;
// http://www.prefield.com/algorithm/container/union_find.html
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main()
{
    int N, K, L; cin >> N >> K >> L;
    UnionFind road(N), rail(N);
    REP(i, K) {
        int p, q; cin >> p >> q;
        p--, q--;
        road.unionSet(p, q);
    }
    REP(i, L) {
        int r, s; cin >> r >> s;
        r--, s--;
        rail.unionSet(r, s);
    }
    map<Int, int> cnt;
    REP(i, N) {
        cnt[(Int)road.root(i) * N + rail.root(i)]++;
    }
    REP(i, N) {
        cout << cnt[(Int)road.root(i) * N + rail.root(i)] << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 13568
// Library
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

// TYPEDEFS
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

// CONSTANTS
#define SZA 0
#define SZB 0

// MACRO
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
#define ABS(X) (((X) > 0)? (X) : -(X))
#define YN(X) ((X)? "Yes" : "No")
#define SWAP(T, X, Y) {T t; t = X; X = Y; Y = t;}

#define F first
#define S second
#define PB push_back
#define MP make_pair


// Global Tables

//ull gPreProcess[SZA][SZB];

// Functions

void Print2DVector(vector<vector<int>>& v)
{
    ull i, j; 
    for(i = 0; i < v.size(); i++)
    {
        for(j = 0; j < v[i].size(); j++)
        {
            cout << v[i][j];
            if(j == v[i].size()-1)
            {
                cout << endl;
            }
            else
            {
                cout << " ";
            }
        }
    }
}

void PrintVector(vi& v)
{
    ull i;
    for(i = 0; i < v.size(); i++)
    {
        cout << v[i];
        if(i == v.size()-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PrintArr(int* a, ull N)
{
    ull i;
    for(i = 0; i < N; i++)
    {
        cout << a[i];
        if(i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PreProcessTables()
{
    ull i, j;
    for(i = 0; i < SZA; i++)
    {
        for(j = 0; j < SZB; j++)
        {
            break;
        }
        break;
    }
}

void TC(int t)
{
    long long N;
    cin >> N;
    long long val, max_val = 0;
    int A[1000001]{0};
    for(long long i = 0; i < N; i++)
    {
        cin >> val;
        A[val]++;
        max_val = max(max_val, val);
    }
    long long mx = 1, cnt;
    bool sieve[1000001]{false};
    for(long long i = 2; i < max_val+1; i++)
    {
        if(!sieve[i])
        {
            cnt = 0;
            for(long long j = i; j < max_val+1; j += i)
            {
                sieve[j] = true;
                if(A[j])
                {
                    cnt += A[j];
                }
            }
            if(cnt > 0)
            {
                mx = max(mx, cnt);
            }
        }
    }
    if(mx == 1)
    {
        cout << "pairwise coprime" << endl;
    }
    else if(mx == N)
    {
        cout << "not coprime" << endl;
    }
    else
    {
        cout << "setwise coprime" << endl;
    }
}   

// Main

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

    int T = 1, t;
    for(t = 1; t <= T; t++)
    {
        TC(t);
    }
    return 0;
}


Measured memory_bytes: 8548
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007
int acs(const void* a, const void* b) { return *(int*)a - *(int*)b; } // 1,2,3,4
int des(const void* a, const void* b) { return *(int*)b - *(int*)a; } // 8,7,6,5
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
//snippet
#define N 100009

int main() {
	int h, w, k, masu[7][7]={0};
	LL ans = 0;
	char s[7];
	scanf("%d%d%d", &h, &w, &k);
	rep(i, h) {
		scanf("%s", s);
		rep(j, w) {
			if (s[j]=='#')masu[i][j] = 1;
		}
	}



	rep(allh, 1<<h)rep(allw, 1<<w) {
		int tmp = 0, masur[7][7] = { 0 };
		rep(i, h)if (allh & (1 << i)) {
			rep(j, w)masur[i][j]++;
		}
		rep(j, w)if (allw & (1 << j)) {
			rep(i, h)masur[i][j]++;
		}
		/*rep(i, h) {
			rep(j, w)printf("%d", masur[i][j]);
			printf("\n");
		}*/
		rep(i, h)rep(j, w)if (masu[i][j] == 1 && masur[i][j] == 0)tmp++;
		if (tmp == k) {
			ans++;
			//printf("*\n");
		}
	}
	printf("%lld", ans);



	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
signed main() {
    int A, B, K;
    cin >> A >> B >> K;
    cout << max((int)0, A - K) << ' ' << max((int)0, B - max((int)0, K - A)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    int n, t, ci, ti, cmin = 1001;
    cin >> n >> t;
    for (int i = 0; i < n; i++)
    {
        cin >> ci >> ti;
        if ((ti <= t) && (ci <= cmin))
        {
            cmin = ci;
        }
    }
    if (cmin == 1001)
    {
        cout << "TLE";
    }
    else
    {
        cout << cmin;
    }
    return 0;
}


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

int main() {
	int high[10];
	for(int i=0;i<10;i++){
		cin>>high[i];
	}
	sort(high,high+10);
	for(int i=9;i>=7;i--){
		cout<<high[i]<<endl;
	}
	return 0;
}

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

int main(){
  long n, m, l, minus;
  cin >> n;
  m = 0;
  vector<long> vec(n);
  l = n / 2;
  if(n == (n / 2) * 2) minus = 1;
  else minus = -1;
  rep(i, n){
    l += minus * i;
    cin >> vec[l];
    minus *= -1;
  }
  rep(i, n){
    if(i == 0) cout << vec[i];
    else cout << " " << vec[i];
  }
  cout << endl;
}

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

using namespace std;

typedef long long ll;

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

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

bool parse(int &pos, const string S) {
    if (S[pos] == '$') {
        return true;
    }

    if (S[pos] == 'm') {
        pos++;

        if (!parse(pos, S)) {
            return false;
        }

        if (S[pos] != 'e') {
            return false;
        }
        pos++;

        if (!parse(pos, S)) {
            return false;
        }

        if (S[pos] != 'w') {
            return false;
        }
        pos++;

        return true;
    } else {
        return true;
    }
}

int main(void) {
    string S;
    cin >> S;

    // Add sentinel
    S = S + "$";

    int pos = 0;
    if (parse(pos, S) && pos == (int) S.size() - 1) {
        cout << "Cat" << endl;
    } else {
        cout << "Rabbit" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define N_MAX 100001
typedef pair<int,int> P;
 
int main(){
  int N,R,L;
  int d,t,x;
  int time[N_MAX]={0};
  int score[N_MAX]={0};
  cin >> N >> R >> L;
  priority_queue<P> que;
  for(int i=1;i<=N;i++){
    que.push(P(0,N-i));
  }
  int now = 0;
  for(int j=0;j<R;j++){
    cin >> d >> t >> x;
    P p1 = que.top();
    while(score[N-p1.second] != p1.first){
      que.pop();
      p1 = que.top();
    }
    time[N-p1.second] += t - now;
    now = t;
    score[d] += x;
    que.push(P(score[d],N-d));
  }
  P p1 = que.top();
  while(score[N-p1.second] != p1.first){
    que.pop();
    p1 = que.top();
  }
  time[N-p1.second] += L - now;
  priority_queue<P> que2;
  for(int i=1;i<=N;i++){
    que2.push(P(time[i],N-i));
  }
  p1 = que2.top();
  cout << N - p1.second << endl;
}

Measured memory_bytes: 11952