akhauriyash/Code-Regression huggingface dataset:
/* ALDS1_2_B: Selection Sort - http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B 
Selection Sort
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

SelectionSort(A)
1 for i = 0 to A.length-1
2     mini = i
3     for j = i to A.length-1
4         if A[j] < A[mini]
5             mini = j
6     swap A[i] and A[mini]
Note that, indices for array elements are based on 0-origin.

Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.

Input
The first line of the input includes an integer N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by space characters.

Output
The output consists of 2 lines.

In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.

In the second line, please print the number of swap operations.

Constraints
1 ≤ N ≤ 100

Sample Input 1
6
5 6 4 2 1 3
Sample Output 1
1 2 3 4 5 6
4

Sample Input 2
6
5 2 4 6 1 3
Sample Output 2
1 2 3 4 5 6
3
*/

use std::io::*;

pub trait SSort {
    fn selection_sort(&mut self) -> i32;
}
impl SSort for Vec<i32> {
    fn selection_sort(&mut self) -> i32 {
        let n = self.len();     // Length of the vector.
        let mut no_swaps = 0;
        for i in 0..n {
            // Minimum i: idx of the minimum element of unsorted array.
            let mut mini = i;       
            for j in i..n {
                if self[j] < self[mini] {
                    mini = j;
                }
            }
            if i != mini {
                self.swap(i,mini);
                no_swaps += 1;
            }
        }
        no_swaps
    }
}

fn main() {
    let stdin = stdin();
    let mut lines = stdin.lock().lines().map(|l| l.unwrap());

    let _: i32 = lines.next().unwrap().parse().unwrap();

    let mut seq: Vec<i32> = lines.next().unwrap()
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();                     // Sequence to be sorted.

    let no_swaps = seq.selection_sort();
    let mut ans = array_to_str(&seq);
    ans.push_str(&format!("\n{}", no_swaps));
    println!("{}", ans);
}

// ------------------------------------------------------------------
// Auxiliary methods.
fn array_to_str(arr: &Vec<i32>) -> String {
    // Converts a numerical array to a string for output purposes.
    let mut ans = String::new();
    for a in arr {
        ans.push_str(&format!("{} ", *a));
    }
    return ans.trim().to_string();
}



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

int64_t gcd(int64_t a, int64_t b){
    if (b > a) return gcd(b, a);

    if(a % b == 0){
        return b;
    } else {
        return gcd(b, a % b);
    }
}

int64_t lcm(int64_t a, int64_t b){
    return a/gcd(a,b)*b;
}

int pow_of_2(int64_t n){
  int res = 0;
  while(n % 2 == 0){
    n /= 2; res++;
  }
  return res;
}

int main(){
  int64_t N, M;
  vector<int64_t> a(100010);
 
  cin >> N >> M;
  for(int i=0; i<N; i++){
    int64_t tmp; cin >> tmp;
    a[i] = tmp/2;
  }
 
  int t = pow_of_2(a[0]);
  for(int i=0; i<N; i++){
    if(pow_of_2(a[i]) != t){
      cout << 0 << endl; return 0;
    }
    a[i] >>= t;
  }
  M >>= t;

  int64_t l = 1;
  for(int i=0; i<N; i++){
    l = lcm(l, a[i]);
    if(l > M){
      cout << 0 << endl; return 0;
    } 
  }
 
  cout << (M+l)/(2*l) << endl;
}

Measured memory_bytes: 1024
def grid1(lines):
    mod = 10 ** 9 + 7
    
    w = len(lines[0])
    cur = [0] * w
    nxt = [0] * w
    cur[0] = 1

    for line in lines:
        nxt[-1] = 0
        for i in range(w):
            if line[i] == "#":
                nxt[i] = 0
            else:
                nxt[i] = (cur[i] + nxt[i - 1]) % mod
        cur, nxt = nxt, cur

    return cur[-1]


def main():
    h, w = [int(x) for x in input().split()]
    lines = [None] * h
    for i in range(h):
        lines[i] = input()

    return grid1(lines)


print(main())


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int q;
bool p[100001];
int sum[100001];

int main() {
    cin >> q;
    for (int i = 2; i <= 100000; i++) {
        bool ok = true;
        for (int j = 2; j*j <= i; j++) {
            if (i%j == 0) {
                ok = false;
                break;
            }
        }
        p[i] = ok;
    }
    for (int i = 1; i <= 100000; i++) {
        sum[i] += sum[i-1];
        if (i%2==0) continue;
        if (p[i] && p[(i+1)/2]) {
            sum[i]++;
        }
    }
    rep(i,q) {
        int l, r;
        cin >> l >> r;
        cout << sum[r]-sum[l-1] << endl;
    }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;


ll mpow(ll x, ll n, ll mod){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

// nCa
ll combination(ll n, ll a, ll mod) {
    ll X = 1;
    for (ll i = n - a + 1; i <= n; i++) {
        X = (X * i) % mod;
    }
    ll Y = 1;
    for (ll i = 1; i <= a; i++) {
        Y = (Y * i) % mod;
    }

    ll iY = mpow(Y, mod - 2, mod);
    return X * iY % mod;
}


void Main()
{
    ll n, K;
    cin >> n >> K;

    ll mod = 7LL + 1e9;
    repi (i, K + 1) {
        ll res = combination(K - 1, i - 1, mod) * combination(n - K + 1, i, mod);
        res %= mod;
        put(res);
    }
}
signed main(){ Main();return 0;}

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

#ifdef RUBICK
#include "dbg.h"
#endif

using namespace std;
using namespace __gnu_pbds;

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

typedef long long ll;

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

    if (abs(x - a) < abs(x - b))
        puts("A");
    else
        puts("B");

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stack>
#include<queue>
#include<string>
#include<deque>
#include<set>
#include<vector>
#include<map>
#define ll long long
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
    int a[100005];
    int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];	
	 } 
	 int ans=0;
	 for(int i=1;i<=n-1;i++)
	 {
	 	if(a[i]==i)
	 	{
	 	swap(a[i],a[i+1]);
		 ans++;	
		 }
		 
	 	
	 }
	 if(a[n]==n)
	 ans++;
	 cout<<ans<<endl; 
		return 0;
 } 


Measured memory_bytes: 3908
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int n, t,a=0,b,ans=0;
	cin >> n >> t;
	rep(i, n) {
		cin >> b;
		ans += min(b + t - a, t);
		a = b + t;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>

#define NMAX 2000001
#define AMAX 10000

using namespace std;

void counting_sort(unsigned short* A, unsigned short* B, int n, int k)
{
    int C[k + 1];
    for (int i = 0; i <= k; i++) C[i] = 0;
    for (int i = 0; i < n; i++) C[A[i]]++;
    for (int i = 1; i <= k; i++) C[i] += C[i - 1];
    for (int i = n - 1; i >= 0; i--)
    {
        B[C[A[i]] - 1] = A[i];
        C[A[i]]--;
    }
}

int main()
{
    int n;
    cin >> n;
    unsigned short A[n];
    unsigned short B[n];
    for (int i = 0; i < n; i++) cin >> A[i];
    counting_sort(A, B, n, NMAX);
    for (int i = 0; i < n - 1; i++) cout << B[i] << " ";
    cout << B[n - 1] << "\n";
    return 0;
}


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

int main() {
  int n,k;
  string s;
  cin >> n >> k >> s;
  if(s.at(k - 1) == 'A'){
    s.at(k - 1) = 'a';
  }else if(s.at(k - 1) == 'B'){
    s.at(k - 1) = 'b';
  }else if(s.at(k - 1) == 'C'){
    s.at(k - 1) = 'c';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int s, d, m;
	while(cin >> s >> d >> m){
		int num = 0;
		vector<int> w;
		vector<int> p;
		vector<P> idx;
		rep(i, s){
			int k;
			cin >> k;
			idx.push_back(MP(num, num+k-1));
			num += k;
			rep(j, k){
				int we, pr;
				cin >> we >> pr;
				w.push_back(we);
				p.push_back(pr);
			}
		}


		vector<int> ww;
		vector<int> pp;
		rep(i, d){
			int f;
			cin >> f;
			for(int j = idx[f].first; j <= idx[f].second; j++){
				ww.push_back(w[j]);
				pp.push_back(p[j]);
			}
		}

		int n = ww.size();
		vector<vector<int> > dp(n+1, vector<int>(301, -1));
		dp[0][0] = 0;
		rep(i, n){
			rep(j, 301){
				if(dp[i][j] == -1) continue;
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
				if(j+pp[i] > 300) continue;
				dp[i+1][j+pp[i]] = max(dp[i+1][j+pp[i]], dp[i][j] + ww[i]);
			}
		}
		int answ = 0;
		int ansp = 0;
		rep(i, m+1){
			if(answ < dp[n][i]){
				answ = dp[n][i];
				ansp = i;
			}
		}
		cout << answ << ' ' << ansp << endl;
	}

	return 0;
}

Measured memory_bytes: 4504
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
15 6
1 2 7 8 12 50

output:
2
"""

import sys


def solve():
    rec[0] = 0
    for i in range(all_coins):
        for j in range(coins[i], money + 1):
            rec[j] = min(rec[j], rec[j - coins[i]] + 1)

    return rec


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    money, all_coins = map(int, _input[0].split())
    coins = list(map(int, _input[1].split()))
    # assert len(coins) == c_num
    rec = [float('inf')] * (money + 1)
    ans = solve()
    print(ans.pop())

Measured memory_bytes: 9488
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <ios>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX = 100001;

class C {
	int N, M;
	vector<vector<int>> byPrefectureYears;
	vector<int> years;
	vector<int> prefs;

public:
	void solve()
	{
		for (int i{ 0 }; i < MAX; i++)
			sort(byPrefectureYears[i].begin(), byPrefectureYears[i].end());

		ostringstream oss;

		for (int i{ 0 }; i < M; i++)
		{
			oss.str("");
			oss << setfill('0') << right << setw(6) << prefs[i];
			oss << setfill('0') << right << setw(6) << (1 + (lower_bound(byPrefectureYears[prefs[i]].begin(), byPrefectureYears[prefs[i]].end(), years[i]) - byPrefectureYears[prefs[i]].begin()));
			cout << oss.str() << endl;
		}

	}

	C()
	{
		cin >> N >> M;
		years.resize(M);
		prefs.resize(M);
		byPrefectureYears.resize(MAX);

		for (int i{ 0 }; i < M; i++)
		{
			cin >> prefs[i] >> years[i];
			byPrefectureYears[prefs[i]].push_back(years[i]);
		}	
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 7808
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int r = sc.nextInt();
        if (n >= 10) {
            System.out.println(r);
        } else {
            System.out.println(r + 100 * (10 - n));
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset
 
using namespace std;
 
typedef long long Lint;
typedef pair<Lint,Lint> ii;
typedef pair<int,char> ic;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;
 
const int maxn = 1020;
const int maxm = 10000020;
const int MOd = 998244353;

int a;
string s, s2;

void solve() {
	scanf("%d",&a);
	Lint ans = 0, tot = 0;
	for(int i=0,j;i<a;i++) {
		scanf("%d",&j);
		ans += tot*j;
		tot += j;
		tot %= (1000000000+7);
		ans %= (1000000000+7);
	}
	cout << ans << endl;
}
 
int main() {
	int n = 1;
	// scanf("%d",&n);
	while( n-- ) solve();
 
	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,a[1001],sum=0;
	cin>>n;
	for(i=1;i<=n*2;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+2*n+1);
	for(i=1;i<=2*n;i++)
	{
		if(i%2==1)
		{
			sum=sum+a[i];
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
fbcnt = 0
fwcnt = 0

for i in range(len(S)):
    val = S[i]
    if i%2==0:
        if val == '1':
            fbcnt += 1
        else:
            fwcnt += 1
    else:
        if val == '1':
            fwcnt += 1
        else:
            fbcnt += 1
print(min(fbcnt, fwcnt))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

 ll gcd(ll a,ll b){ 
    if(b == 0) return a;
    return gcd(b,a%b); 
 }

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	int n;
	cin >> n;
	ll ans=1;
	REP(i, n) {
		ll t;
		cin >> t;
		ans = lcm(ans, t);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	long long int n,m;
	long long int i,j,k;
	cin>>n;
	for(i=0;i<100005;i++){
		if(i*i>n){
			m=i-1;
			break;
		}
	}
	for(i=m;i>0;i--){
		if(n%i==0){
			m=n/i;
			break;
		}
	}
	for(i=0,j=1;i<11;i++,j*=10){
		if(m<j){
			m=i;
			break;
		}
	}
	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>

using namespace std;



int main() {
    

    
    int h, w;
    vector<string> f;
    cin >> h >> w;
    
    vector<vector<int>> v1(h, vector<int>(w, 0));
    vector<vector<int>> v2(h, vector<int>(w, 0));
    
    for (int i = 0; i < h; ++i)
    {
        string s;
        cin >> s;
        f.push_back(s);
    }
    
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (f[i][j] == '.')
            {
                if (j != 0)
                {
                    v1[i][j] = v1[i][j - 1] + 1;
                }
                else
                {
                    v1[i][j] = 1;
                }
            }
        }
        for (int j = 0; j < w; ++j)
        {
            if (f[i][w - 1 - j] == '.')
            {
                if (j != 0)
                {
                    v1[i][w - 1 - j] = max(v1[i][w - 1 - j], v1[i][w - j]);
                }
            }
        }
    }
    
    for (int i = 0; i < w; ++i)
    {
        for (int j = 0; j < h; ++j)
        {
            if (f[j][i] == '.')
            {
                if (j != 0)
                {
                    v2[j][i] = v2[j - 1][i] + 1;
                }
                else
                {
                    v2[j][i] = 1;
                }
            }
        }
        for (int j = 0; j < h; ++j)
        {
            if (f[h - 1 - j][i] == '.')
            {
                if (j != 0)
                {
                    v2[h - 1 - j][i] = max(v2[h - 1 - j][i], v2[h - j][i]);
                }
            }
        }
    }
    int ret = 0;
    
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            ret = max(ret, v1[i][j] + v2[i][j] - 1);
        }
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define vint vector<int>
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define pb() push_back()
#define mod 100000007
#define elif else if
#define str string
//main
signed main(){
  int N,M,O,Q,count=0,count2=0,count3=0;
  double D=0;
  int c='A'-'a';
  //char C;
  str S,T;
  cin>>N>>M>>O;
  vint A(O);
  vint P(N);
  rep(0,N)P[i]=M;
  rep(0,O)cin>>A[i];
  rep(0,O)P[A[i]-1]+=1;
  rep(0,N)P[i]>O?cout<<"Yes"<<endl:cout<<"No"<<endl;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
int main(void)
{
	ll a[5];
	for(int i=0;i<5;i++) cin>>a[i];
	for(int i=0;i<5;i++)
	{
		if(a[i]==0)
		{
			cout<<i+1;
			return 0;
		}
	}
}

Measured memory_bytes: 3640
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long n = sc.nextLong();
StringBuilder sb = new StringBuilder();

while(n-->0){
    sb.append((char)('a'+n%26));
    n/=26;
}sb.reverse();
System.out.println(sb.toString());

        sc.close();
    }
}

Measured memory_bytes: 35696
#include <iostream>
#include <string.h>

using namespace std;

static const int MAX = 36;

class card {
public:
	char name[2];
	int value;
};

void bubbleSort(card* p, int n);
void selectionSort(card* p, int n);

int main() {
	int n,i,flag;
	card A[MAX], B[MAX];

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> A[i].name;
		A[i].value = A[i].name[1] - '0';
		B[i] = A[i];
	}

	bubbleSort(A, n);
	cout << "Stable" << endl;

	selectionSort(B, n);

	flag = 0;
	for (i = 0; i < n; i++) {
		if (strncmp(A[i].name, B[i].name, 2) == 0)
			continue;
		else {
			flag = 1;
			break;
		}
	}

	if (flag == 0)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	return 0;
}

void bubbleSort(card* p, int n) {
	int i, j;
	card temp;

	//bubble sort
	for (i = 0; i < n; i++) {
		for (j = n - 1; j > i; j--) {
			if (p[j].value < p[j - 1].value) {
				temp = p[j - 1];
				p[j - 1] = p[j];
				p[j]= temp;
			}
		}
	}

	//print array
	cout << p[0].name;
	for (i = 1; i < n; i++)
		cout << ' ' << p[i].name;
	cout << endl;
}

//selectionSort
void selectionSort(card* p, int n) {
	int i,j,min,max, idx;
	card temp, A[MAX];

	//selection sort
	for (i = 0; i < n; i++) {
		min = p[i].value;
		idx = i;
		for (j = i + 1; j < n; j++) {
			if (min > p[j].value) {
				min = p[j].value;
				idx = j;
			}
		}
		if (i != idx) {
			temp = p[i];
			p[i] = p[idx];
			p[idx] = temp;
		}
	}

	//print array
	cout << p[0].name;
	for (i = 1; i < n; i++)
		cout << ' ' << p[i].name;
	cout << endl;
}

Measured memory_bytes: 3096
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int A = 0;
    int B = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &A, &B);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    ans = (A - 1)*(B - 1);
    
    if(1 == 0){
      /* 真の場合の処理 */
      
    }else{
      /* 偽の場合の処理 */
      
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    printf("%d", ans); // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}






Measured memory_bytes: 128
import bisect

def fun():
    a = sorted(list(map(int,input().split())))
    b = sorted(list(map(int,input().split())))
    c = sorted(list(map(int,input().split())))
    ans = 0
    for k in b:
        pos1 = bisect.bisect_left(a,k)
        pos2 = bisect.bisect_right(c,k)
        ans += (pos1*(n-pos2))
    print(ans)
if __name__ == "__main__":
    n = int(input())
    fun()


Measured memory_bytes: 22720
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
#define PI (acos(-1.0))
#define Abs(a) (((a)<0) ? (-(a)) :(a) )
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=((n)-1);i>=0;i--)
#define rrep(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define Pii pair<int,int>
#define PB push_back
#define Size(x) ((int)(x.size()))
using namespace std;
typedef long long mint;
typedef unsigned long long umint;
int getD(mint num)
{
    stringstream ss;
    ss << num;
    return ss.str().size();
}
int main()
{
    //freopen("in.txt","r",stdin);
    mint n;
    cin>> n;
    int ans;
    for(mint i = 1; i*i <= n; i++)
    {
        if(n % i == 0)
        {
            //cout << n / i << endl;
            ans = getD(n / i);
        }
    }
    cout << ans << endl;
    return 0;
}




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

int main() {
    int n, a, b, q; cin >> n >> a >> b >> q;
    vector<int> x(a);
    vector<char> c(a);
    for(int i = 0; i < a; ++i) {
        cin >> x[i] >> c[i];
    }
    vector<int> y(b), h(b);
    for(int i = 0; i < b; ++i) {
        cin >> y[i] >> h[i];
    }

    auto find_left_most_pos = [&] (int p) {
        while(true) {
            const int i = upper_bound(begin(y), end(y), p) - begin(y) - 1;
            if(i < 0 || h[i] == 0) break;
            p -= ((p - y[i]) / (y[i] - h[i]) + 1) * (y[i] - h[i]);
        }
        return p;
    };
    map<int, char> ans;
    for(int i = 0; i < a; ++i) {
        ans[find_left_most_pos(x[i])] = c[i];
    }

    while(q--) {
        int z; cin >> z;
        z = find_left_most_pos(z);
        cout << (ans.count(z) ? ans[z] : '?');
    }
    cout << endl;
}



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

int main()
{
    int n, k, l[50];
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    sort(l, l + n);
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += l[n - k + i];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;
    double t,a; cin>>t>>a;
    vector <double> h(n+1);
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    vector <double> kionsa(n+1);
    for(int i=1;i<=n;i++){
        kionsa[i]=abs(t-h[i]*0.006-a);
        //if(kion[i]<-273.15) kion[i]=273.15;
    }
    double min=kionsa[1];
    int x=1;
    for(int i=1;i<=n;i++){
        if(min>kionsa[i]) {min=kionsa[i]; x=i;}
    }
        cout<<x<<endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

int main(){

    ios :: sync_with_stdio(false);
    int N, p[100005];
    cin >> N;
    FOR(i,N) cin >> p[i];
    bool ok = 0;

    int ans = 0;
    FOR(i, N){
        if(p[i] == i){
            if(ok) ok = 0;
            else {
                ans++;
                ok = 1;
            }
        }
        else ok = 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a<=k){
  cout << "Yay!" << endl;
  }
  else{
  cout << ":(" << endl;
  }
}
    

Measured memory_bytes: 256
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007    //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

// debug
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG2(x, y) cout << #x << ": " << x << " " << #y << ": " << y << endl
#define DEBUG_VEC(v)   \
  cout << #v << ":";   \
  REP(i, v.size())     \
  cout << " " << v[i]; \
  cout << endl
#define DEBUG_ARR(v, n) \
  cout << #v << ":";    \
  REP(i, n)             \
  cout << " " << v[i];  \
  cout << endl

typedef pair< ll, ll > P;

P f(ll x)
{
  ll en = x % 10;
  ll st = 0;
  while (x)
  {
    st = x;
    x /= 10;
  }
  return P(st, en);
}

signed main()
{
  ll N;
  cin >> N;
  map< P, ll > freq;

  FOR(i, 1, N)
  {
    // Bのst/enを求める
    P p = f(i);
    freq[p]++;
  }

  ll ans = 0;
  FOR(i, 1, N)
  {
    // Aのst/enを逆にしたen/stがどれだけあるか調べる
    P p = f(i);
    P q(p.second, p.first);
    ans += freq[q];
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll long long
#define MOD 1000000007
#define pll             pair<ll,ll>
#define pii             pair<int,int> 
#define mp(a,b)         make_pair(a,b)
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define vb 				vector<bool>
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define FOR(i,a,b) 		for(ll i = a; i <= b ; i++)
#define forn(i,n) 		for(ll i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			ll t;cin>>t;while(t--)
 
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF				INT_MAX
#define INFL			LLONG_MAX
#define max1(x,y) (x)>(y)?(x):(y)
#define ss second
#define ff first
#define MAXN 100001
vector<vector<ll> > adj(MAXN);
bool visited[MAXN]={0};
ll dist[MAXN]={0};
vector<ll> order;
ll n;
void topologicalSortUtil(int v,stack<int> &Stack) 
{ 
    visited[v] = true; 
    for (ll i=0;i<adj[v].size();i++) 
        if (!visited[adj[v][i]]) 
            topologicalSortUtil(adj[v][i], Stack); 
      Stack.push(v); 
} 
void topologicalSort() 
{ 
    stack<int> Stack; 
    FOR(i,1,n) 
      if (visited[i] == false) 
        topologicalSortUtil(i,Stack); 
  
    // Print contents of stack 

    while (Stack.empty() == false) 
    { 
        order.pb(Stack.top()); 
        Stack.pop(); 
    } 
} 

int main(){
    fast
    ll m;
    cin>>n>>m;
    vector<vector<ll> > parent(n+1);
    forn(i,m){
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        parent[b].pb(a);
        //dist[b]=max(dist[b],1+dist[a]);
    }
    topologicalSort();
    forn(i,n){
        if(parent[order[i]].size()==0)
        continue;
        forn(j,parent[order[i]].size())
        dist[order[i]]=max(dist[order[i]],1+dist[parent[order[i]][j]]);
    }
    ll ans=0;
    FOR(i,1,n){
        //cout<<dist[i]<<" ";
        ans=max(ans,dist[i]); 
    }
    //cout<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15352
#include <stdio.h>
#include <iostream>
#include <string>

int main(void) {
	int a = 0;
	int b = 0;
	int c = 0;
	std::cin >> a >> b >> c;

	char* str = "";
	if (a < b && b < c) {
		str = "Yes";
	}
	else {
		str = "No";
	}

	printf("%s\n", str);

	return 0;
}


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

int main() {
    int N, s, v;
    cin >> N;
    string S;
    cin >> S;
    deque<int> r, w;
    r.emplace_back(-1);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            r.emplace_back(i);
        } else {
            w.emplace_front(i);
        }
    }
    w.emplace_front(N);

    int c = 0;
    while (true) {
        s = r.back();
        v = w.back();
        r.pop_back();
        w.pop_back();
        // cout << s << " " << v << endl;
        if (s <= v) {
            cout << c << endl;
            return 0;
        }
        c++;
    }
}


Measured memory_bytes: 4464
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e9 +7
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
#define prm 998244353
#define endl '\n'
using namespace std;

int main()
{
    fastio; 
    ll T=1;
    //cin>>T; 
    while(T--)
    {
    	string s;
    	cin>>s;
    	ll n=s.size();
    	ll sum=0;
    	for(ll i=0;i<n;i++)sum+=(s[i]-'0');
    	//sum=0;
    	if(sum%9==0)cout<<"Yes";
    	else cout<<"No";
    	
    }
}



Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000


int main(){
	int A,B;
	cin>>A>>B;
	if((A+B)%2==1){
		cout<<"IMPOSSIBLE"<<endl;
	}
	else{
		cout<<(A+B)/2<<endl;
	}
	
	

	
	return 0;
}




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

int main()
{
	int i,n;
	cin>>n;
	for(i=0;i<n;i++)
	{
		int a[3];
		cin>>a[0]>>a[1]>>a[2];
		sort(a,a+3);
		if(a[2]*a[2] == a[0]*a[0] + a[1]*a[1])
		{
			cout<<"YES"<<endl;
		} else				
			cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
    double a,b;
    scanf("%lf %lf",&a,&b);
    if(a>b)printf("GREATER\n");
    else if(a<b)printf("LESS\n");
    else printf("EQUAL\n");
    return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,k=MI()
    print(min(n%k,k-n%k))

main()

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<ios>
#include<cmath>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<assert.h>
#include<bitset>
#include<tuple>
#include<climits>
#include<deque>
#include<utility>
#include<unordered_map>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<ext/pb_ds/assoc_container.hpp>
#include<chrono>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int a,b;cin>>a>>b;
    cout<<max3(a+b,a-b,a*b);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<utility>//swap(数値交換)
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define rt "\n"
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())

int main(){
	int a, b;
	cin >> a >> b;
	if (500 * a >= b)cout << "Yes" << rt;
	else cout << "No" << rt;
	return 0;
}

// abc : 141 , aoj : ITP1_6_D
//sort, abs, swap, reverse, max, min
//__gcd, substring, erase, push_back,stoll、stoi

Measured memory_bytes: 256
def solve(S):
    cnt0 = 0
    cnt1 = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == '1':
                cnt1 += 1
            else:
                cnt0 += 1
        else:
            if S[i] == '1':
                cnt0 += 1
            else:
                cnt1 += 1
    return min(cnt0, cnt1)


S = input()
print(solve(S))

Measured memory_bytes: 3188
import java.util.Scanner;

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

        int N = sc.nextInt();
        int paperNum = 0;

        paperNum += N / 2;

        if (N % 2 == 1) {
            paperNum++;
        }

        System.out.println(paperNum);
    }
}

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

int main(){
  string s, t, d;
  int a=3;
  cin >> s;
  reverse(s.begin(),s.end());
  d = s;
  while(s.size()>0){
    if(s[0]=='r' || s[1]=='e'){
      if(s[2]=='m'){
        t+="remaerd";
        s.erase(0, 7);
      }else if(s[2]=='s'){
        t+="resare";
        s.erase(0, 6);
      }else{
        break;
      }
    }else if(s[0]=='e'){
      if(s[1]=='s'){
        t+="esare";
        s.erase(0, 5);
      }
    }else if(s[0]=='m'){
      if(s[1]=='a'){
        t+="maerd";
        s.erase(0, 5);
      }
    }
  }
  cout << (t==d?"YES":"NO") << endl;
  return 0;
}


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

int main(){

  for(int i=1;;i++){
    int x;
    cin>>x;
  if(x == 0 ) break;
  cout<<"Case "<<i<<": "<<x<<endl;
  }

 return 0;
}


Measured memory_bytes: 3080
#include<vector>
#include<cmath>
#include<complex>
#include<iostream>
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<float.h>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int


ll solve(ll a, ll b){
	if (a < b) swap(a,b);
	if (a%b==0) return (a/b*2-1)*b;
	ll ret = a/b * 2*b;
	return ret + solve(a%b, b);
}

int main(void){
	ll N, X;
	cin >> N >> X;
	cout << N + solve(N-X, X) << endl;
	return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> ls(N, -1);
    int ans = 0;
    int a ,b;
    for(int i=0; i<M; i++){
        cin >> a >> b;
        ls.at(b-1) = max(ls.at(b-1), a-1);
    }
    int ps = -1;
    for(int i=0; i<N; i++){
        if(ls.at(i)==-1){
            continue;
        }
        if(ls.at(i)>=ps){
            ans += 1;
            ps = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

int main(int argc, char **argv) {
    int a, b;
    cin >> a >> b;
    int ans = max(a+b, a-b);
    ans = max(ans, a*b);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline

def make_modinv_list(n, mod=10**9+7):
    inv_list = [0]*(n+1)
    inv_list[1] = 1
    for i in range(2, n+1):
        inv_list[i] = (mod - mod//i * inv_list[mod%i] % mod)
    return inv_list

mod = 998244353
N = int(readline())
A = list(map(int, readline().split()))
C = max(A) + 1
inv_list = make_modinv_list(C, mod)
h = [0] * C
for x in A:
    h[x] = (h[x] + x) % mod
for i in range(1, C):
    for j in range(i*2, C, i):
        h[i] = (h[i] + h[j]) % mod
g = [0] * C
for i in range(1, C):
    g[i] = h[i] * h[i] % mod
for i in range(C-1, 0, -1):
    for j in range(i*2, C, i):
        g[i] = (g[i] - g[j]) % mod
ans = 0
for i in range(1, C):
    ans = (ans + g[i] * inv_list[i]) % mod
ans -= sum(A)
print(ans * inv_list[2] % mod)    


Measured memory_bytes: 81028
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  ll a[N],b[N];
  for(int i=0;i<N;i++) cin >> a[i];
  for(int i=0;i<N;i++) cin >> b[i];

  ll suma = 0LL;
  ll sumb = 0LL;
  for(int i=0;i<N;i++){
    suma += a[i];
    sumb += b[i];
  }

  ll ope = sumb - suma; //操作回数
  if(ope < 0LL){
    cout << "No" << endl;
    return 0;
  }

  ll opea = 0LL;
  ll opeb = 0LL;
  for(int i=0;i<N;i++){
    if(a[i] > b[i]) opeb += a[i] - b[i];
    else if(a[i] < b[i]){
      ll tmp = b[i] - a[i];
      if(tmp % 2 == 0) opea += tmp / 2;
      else {
        opeb += 1;
        opea += (tmp + 1) / 2;
      }
    }
  }

  if(opea <= ope && opeb <= ope){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int X, N;
int p[128];

int main(void) {
	int i;
	if (scanf("%d%d", &X, &N) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d" ,&p[i]) != 1) return 1;
	}
	for (i = 0; ; i++) {
		int t;
		for (t = X - i; t <= X + i; t += i == 0 ? 1 : i * 2) {
			int ok = 1;
			int j;
			for (j = 0; j < N; j++) {
				if (p[j] == t) ok = 0;
			}
			if (ok) {
				printf("%d\n", t);
				return 0;
			}
		}
	}
}


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

int main(){
    ll n,ans;
    cin >> n;
    if(n%2==0)ans = n/2;
    else ans = n/2+1;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	// "os"
	"fmt"
	"strconv"
)

func main() {
	var aa,bb string
	fmt.Scanf("%s %s", &aa, &bb)

	var result string
	if aa > bb {
		num, _ := strconv.Atoi(aa)
		// fmt.Fprintf(os.Stderr, "%v\n", num)
		for ii:=0;ii<num;ii++ {
			result += bb
		}
	} else {
		num, _ := strconv.Atoi(bb)
		// fmt.Fprintf(os.Stderr, "%v\n", num)
		for ii:=0;ii<num;ii++ {
			result += aa
		}
	}
	fmt.Printf("%s\n", result)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;

ll modpow(ll x, ll n){
	ll r=1;
	while(n){
		if(n&1) r=r*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return r;
}

int main(){
  ll n;cin>>n;
  vll d(n),dis(n,0);
  rep(i,0,n){
    cin>>d[i];
    dis[d[i]]++;
  }
  if(dis[0]!=1||d[0]!=0){
    cout<<0<<endl;return 0;
  }
  
  sort(d.begin(),d.end());
  ll ans=1;
  rep(i,1,d[n-1]+1){
    if(dis[i]==0){
      cout<<0<<endl;return 0;
    }
    ans*=modpow(dis[i-1],dis[i]);
    ans%=MOD;
  }
  cout<<ans%MOD<<endl;
}




Measured memory_bytes: 4836
#include "bits/stdc++.h"
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int inf=100000;

vll par(inf),myrank(inf);
//par[i]=iならiは根（はじめは全て根）
void init(ll n){
  REP(i,n){
    par[i]=i;myrank[i]=0;
  }
  return;
}
//xの根
ll root(ll x){
  return (par[x]==x)?x:par[x]=root(par[x]);
}
//xが根の木とyが根の木を繋げる
void unite(ll x,ll y){
  x=root(x);y=root(y);
  if(x==y){return;}
  if(myrank[x]<myrank[y]){par[x]=y;}
  else{par[y]=x;}
  if(myrank[x]==myrank[y]){myrank[x]++;}
}
//根が同じかどうか
bool same(ll x,ll y){
  return root(x)==root(y);
}


int main(){
  ll n,q;
  cin>>n>>q;
  init(n);
  REP(i,q){
    ll p,a,b;
    cin>>p>>a>>b;
    if(p==0){
      unite(a,b);
    }
    else{
      if(same(a,b)){cout<<1<<endl;}
      else{cout<<0<<endl;}
    }
  }
}



Measured memory_bytes: 4248
import sys
input = sys.stdin.readline
from itertools import accumulate

def merge(x, y):
  D = sorted([dp[x][0], dp[x][1], dp[y][0], dp[y][1]], reverse=True)
  return (D[0], D[1])
  
n = int(input())
A = tuple(map(int, input().split()))
dp = [(a, 0) for a in A]
for j in range(n):
  for i in range(1<<n):
    if i & (1<<j):
      dp[i] = merge(i, i & ~(1<<j))
L = tuple(accumulate((sum(d) for d in dp), max))
print(*L[1:], sep="\n")

Measured memory_bytes: 186376
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    vector<int> abc(3);
    cin>> abc[0] >> abc[1] >> abc[2];
    int ans = 0;
    while(1) {
        sort(abc.begin(), abc.end());
        if ( abc[0] == abc[1] && abc[0] == abc[2] ) {
            cout << ans << endl;
            return 0;
        }
        if ( abc[0] + 2 <= abc[2] ) {
            ++ans;
            abc[0] += 2;
            continue;
        }
        else {
            ++abc[0];
            ++abc[1];
            ++ans;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import math

class SieveOfEratosthenes:
    def __init__(self, V):
        self.is_prime = [True] * (V + 1)
        self.primes = []
        for i in range(2, V + 1):
            if self.is_prime[i]:
                self.primes.append(i)
                for j in range(i * i, V + 1, i):
                    self.is_prime[j] = False
    
    def factorize(self, x):
        assert x > 1
        result = []
        for p in self.primes:
            exp = 0
            while x % p == 0:
                exp += 1
                x = x // p
            if exp > 0:
                result.append((p, exp))
            if p * p > x:
                break
        if x > 1:
            result.append((x, 1))
        return result


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

    if all(a == 1 for a in A):
        return 'pairwise coprime'

    gcd_all = 0
    for a in A:
        gcd_all = math.gcd(gcd_all, a)

    if gcd_all > 1:
        return 'not coprime'
    
    sieve = SieveOfEratosthenes(max(A))
    used_primes = set()
    for a in A:
        if a != 1:
            factors = sieve.factorize(a)
            for (p, e) in factors:
                if p in used_primes:
                    return 'setwise coprime'
                used_primes.add(p)
    
    return 'pairwise coprime'

print(solve())

Measured memory_bytes: 134724
function getLineByParam( param ){
  var ret;
  for ( var i=0; i<param[0].length; i++ ) {
    if ( "\n" == param[0].charAt( i ) ) {
      ret = param[0].slice( 0, i );
      param[0] = param[0].slice( ret.length+1 );
      return ret;
    }
  }
  ret = param[0];
  param[0]="";
  return ret;
}

function countBomb( S, i, j ){
  if ( '#' === S[i][j] ) return '#';
  var cnt = 0;
  if ( 0 < i ) {
    if ( 0 < j && '#' === S[i-1][j-1] ) cnt++;
    if ( '#' === S[i-1][j] ) cnt++;
    if ( S[i].length - 1 > j && '#' === S[i-1][j+1] ) cnt++;
  }
  if ( 0 < j && '#' === S[i][j-1] ) cnt++;
  if ( S[i].length - 1 > j && '#' === S[i][j+1] ) cnt++;
  if ( S.length - 1 > i ) {
    if ( 0 < j && '#' === S[i+1][j-1] ) cnt++;
    if ( '#' === S[i+1][j] ) cnt++;
    if ( S[i].length - 1 > j && '#' === S[i+1][j+1] ) cnt++;
  }
  return cnt;
}

function Main(input) {
  input = [input];
  var tmp = getLineByParam(input).split(" ");
  var H = parseInt( tmp[0] );
  var W = parseInt( tmp[1] );
  var S = [];
  for ( var i=0; i<H; i++ ) {
    S[i] = [];
    tmp = getLineByParam(input).split("");
    for ( var j=0; j<W; j++ ) {
      S[i][j] = tmp[j];
    }
  }

  for ( var i=0; i<H; i++ ) {
    for ( var j=0; j<W; j++ ) {
      S[i][j] = countBomb( S, i, j );
    }
    console.log( S[i].join("") );
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500