akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	int n, m;
	cin >> n >> m;
	map<int, set<int>> g;
	int a, b, h[n];
	for(int i=0;i<n;i++)
		cin >> h[i];
	for(int i=0;i<m;i++) {
		cin >> a >> b;
		g[a-1].insert(b-1);
		g[b-1].insert(a-1);
	}
	int count = 0;
	for(int i=0;i<n;i++) {
		bool ok = true;
		for(auto neighbor: g[i]) {
			if(h[neighbor] >= h[i]) {
				ok = false;
				/* cout << "break "; */
				/* deb(i); */
				break;
			}
		}
		if(ok) {
				/* deb(i); */
				count++;
		}
	}
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 22800
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

used = set()
h = []
heappush(h, (-A[0]-B[0]-C[0], 0, 0, 0))
result = []
used.add((0, 0, 0))

for _ in range(K):
    sum, i, j, k = heappop(h)
    result.append(-sum)
    if i < X-1 and (i+1, j, k) not in used:
        heappush(h, (-A[i+1]-B[j]-C[k], i+1, j, k))
        used.add((i+1, j, k))
    if j < Y-1 and (i, j+1, k) not in used:
        heappush(h, (-A[i]-B[j+1]-C[k], i, j+1, k))
        used.add((i, j+1, k))
    if k < Z-1 and (i, j, k+1) not in used:
        heappush(h, (-A[i]-B[j]-C[k+1], i, j, k+1))
        used.add((i, j, k+1))

for v in result:
    print(v)

Measured memory_bytes: 5104
n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
i = 0
for x in b:
    while i < n and a[i] < x:
        i += 1
    if i < n and a[i] == x:
        i += 1
    else:
        print('NO')
        exit(0)
print('YES')

Measured memory_bytes: 35164
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if i == 0 or i % 2 == 0:
                    if j != W - 1 and j % 2 == 0:
                        print("#", end="")
                    elif j != W - 1 and j % 2 != 0:
                        print(".", end="")
                    elif j == W - 1 and j % 2 == 0:
                        print("#")
                    else:
                        print(".")
                else:
                    if j != W - 1 and j % 2 != 0:
                        print("#", end="")
                    elif j != W - 1 and j % 2 == 0:
                        print(".", end="")
                    elif j == W - 1 and j % 2 != 0:
                        print("#")
                    else:
                        print(".")

        print()



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

bool isEvenVector(vector<int> & vec)
{
  for(int &x : vec) {
    if(x % 2 == 1)
    {
      return false;  //奇数なのでfalse
    }
    x /= 2;
  }
  return true;
}
 
int main(){
  int N;
  int count = 0;
  cin >> N;
  vector<int> inputVec;
  for(int i = 0; i < N; i++)
  {
    int temp;
    cin >>temp;
    inputVec.push_back(temp);
  }
  
  while(true)
  {
    if(false == isEvenVector(inputVec))
    {
      break;
    }
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N, M;
string A[100], B[100];

int main() {
  cin >> N >> M;
  rep(i, 0, N) { cin >> A[i]; }
  rep(i, 0, M) { cin >> B[i]; }
  rep(i, 0, N) {
    rep(j, 0, N) {
      bool ok = true;
      rep(k, 0, M) {
        rep(l, 0, M) {
          if (B[k][l] != A[i + k][j + l]) ok = false;
        }
      }
      if (ok) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}


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

signed main(){
  int A,B;
  cin>>A>>B;
  cout<<A-B+1<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N;

int main() {
  cin >> N;
  ll nn = N;
  ll sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }

  if (nn % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

const int MAXN = 3005;
ll p[MAXN];
ll p_new[MAXN];
const ll mod = 1000000007;

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

    p[1] = 1;
    for (int n = 2; n <= N; n++)
    {
        for (int i = 1; i <= n; i++)
            p_new[i] = 0;
        if (s[n-2] == '>')
        {
            for (int i = 1; i <= n; i++)
            {
                // 1..i
                p_new[1] += p[i];
                p_new[i+1] = (p_new[i+1] - p[i] + mod) % mod;
            }
        }
        else
        {
            for (int i = 1; i <= n; i++)
            {
                // i+1..n
                p_new[i+1] = (p_new[i+1] + p[i]) % mod;
            }
        }
        for (int i = 2; i <= n; i++)
            p_new[i] = (p_new[i] + p_new[i-1]) % mod;
        swap(p, p_new);
    }
    ll ans = 0;
    for (int i = 1; i <= N; i++) ans = (ans + p[i]) % mod;
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
int h, w, n;
ppi bfs(char[1005][1005], pii, char);

int solve(char land[1005][1005], pii start, int n) {
  int res = 0;
  char curr = '0';
  for (int i = 0; i < n; ++i) {
    char target = '0' + i + 1;
    ppi tmp_res = bfs(land, start, target);
    start = tmp_res.first;
    res += tmp_res.second;
  }
  return res;
}

const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

ppi bfs(char land[1005][1005], pii start, char target) {
  int res = 0;
  int to_time[1005][1005];
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) to_time[i][j] = -1;
  to_time[start.first][start.second] = 0;
  if (land[start.first][start.second] == target) 
    return ppi(start, 0);
  queue<pii> qu;
  qu.push(start);
  while (!qu.empty()) {
    pii tmp = qu.front();
    int tmp_time = to_time[tmp.first][tmp.second];
    qu.pop();
    for (int i = 0; i < 4; ++i) {
      int nx = tmp.first + dx[i], ny = tmp.second + dy[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w && land[nx][ny] != 'X' &&
          to_time[nx][ny] == -1) {
        if (land[nx][ny] == target)
          return ppi(pii(nx, ny), tmp_time + 1);
        else {
          to_time[nx][ny] = tmp_time + 1;
          qu.push(pii(nx, ny));
        }
      }
    }  // four directions search
  }
}

int main() {
  char land[1005][1005];
  pii start;
  cin >> h >> w >> n;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      cin >> land[i][j];
      if (land[i][j] == 'S') start = pii(i, j);
    }
  cout << solve(land, start, n) << endl;
}


Measured memory_bytes: 8016
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

int n;

void dfs(string s, char lim) {
  if (s.size() >= n) {
    cout << s << ln;
    return;
  }

  for (char c = 'a'; c <= lim; c++) {
    char next = c == lim ? lim + 1 : lim;
    dfs(s + c, next);
  }

  return;
}

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

  cin >> n;

  dfs("", 'a');

  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
// ver1.7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n,k;
  cin >> n >> k;
  vector<pair<int,int>> a(n);
  int qw,er;
  rep(i,0,n){
    cin >> qw >> er;
    a[i] = make_pair(qw,er);
  }
  sort(ALL(a));
  int now=0;
  rep(i,0,n){
    now += a[i].second;
    if(k<=now) {
      cout << a[i].first;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1920
while 1:
	n = input()
	if n == 0: break
	ans = []
	for i in range(n):
		inp = raw_input().split()
		P,A,B,C,D,E,F,S,M = map(int,inp[1:])
		ans.append([inp[0],(M*F*S-P)*1.0/(A+B+C+(D+E)*M)])
	ans = sorted(sorted(ans), key = lambda x:x[1], reverse = True)
	for k,v in ans: print k
	print "#"

Measured memory_bytes: 4248
#include<iostream>
using namespace std;
int modulo(int a,int b,int c){
    long long x=1,y=a;
    while(b > 0){
        if(b%2 == 1){
            x=(x*y)%c;
        }
        y = (y*y)%c; 
        b /= 2;
    }
    return x%c;
}
long long mulmod(long long a,long long b,long long c){
    long long x = 0,y=a%c;
    while(b > 0){
        if(b%2 == 1){
            x = (x+y)%c;
        }
        y = (y*2)%c;
        b /= 2;
    }
    return x%c;
}
bool Miller(long long p,int iteration){
    if(p<2){
        return false;
    }
    if(p!=2 && p%2==0){
        return false;
    }
    long long s=p-1;
    while(s%2==0){
        s/=2;
    }
    for(int i=0;i<iteration;i++){
        long long a=rand()%(p-1)+1,temp=s;
        long long mod=modulo(a,temp,p);
        while(temp!=p-1 && mod!=1 && mod!=p-1){
            mod=mulmod(mod,mod,p);
            temp *= 2;
        }
        if(mod!=p-1 && temp%2==0){
            return false;
        }
    }
    return true;
}

int main(int argc, char* argv[])
{

    int input ;
    cin>>input;
    if(input==2)cout<<input<<endl;
    else{
    int i = 0;
    
    if(input%2==0)
        i = input+1;
    else i = input;

    for(;i<2*input;i+=2) 
        if(Miller(i,20)) 
            break;
    cout<<i<<endl;
}
    return 0;
}


Measured memory_bytes: 256
n, k =map(int,input().split())
l=list(map(int,input().split()))
l.append(n+l[0])
d=[0 for i in range(k+1)]
 
for i in range(1,k+1):
  d[i]=l[i]-l[i-1]
 
print(sum(d)-max(d))

Measured memory_bytes: 25840
input_line = input().split()
m = int(input_line[0])
t = int(input_line[1])
s = int(input_line[2])
 
time = 0
if ( m % s == 0 ):
    time = m / s
else:
    time = (m / s) + 1
 
if ( int(time) <= t ):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 8948
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashSet;
fn main() {
    input! {
        s: chars,
    };
    let mut map = s.iter().map(|c| *c as u8).collect::<HashSet<_>>();
    let ansu8 = ('a' as u8..'z' as u8 + 1)
        .filter(|c| !map.contains(c))
        .min()
        .unwrap_or(0u8);
    println!(
        "{}",
        if ansu8 == 0u8  {
            "None".to_string()
        } else {
            (ansu8 as char).to_string()
        }
    );
}


Measured memory_bytes: 6396
#include <iostream>

using namespace std;

typedef long long ll;

ll mini(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

void Licz(ll n, ll m, ll* b, ll* c)
{
    if (n % 2 == 0)
    {
        *b = n * m / 2;
        *c = n * m / 2;
    }
    else
    {
        *b = n / 2 * m;
        *c = n / 2 * m + m;
    }
}

ll Ile(ll n, ll m)
{
    ll r = 1000000000000000000;
    ll a, b, c;
    for (ll i = 1; i <= m - 1; ++i)
    {
        ll a = i * n;
        Licz(n, m - i, &b, &c);
        if (b < a)
            swap(a, b);
        if (c < a)
            swap(a, c);
        if (c < b)
            swap(c, b);
        r = mini(r, c - a);
        a = i * n;
        Licz(m - i, n, &b, &c);
        if (b < a)
            swap(a, b);
        if (c < a)
            swap(a, c);
        if (c < b)
            swap(c, b);
        r = mini(r, c - a);
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, m;
    cin >> n >> m;
    cout << mini(Ile(n, m), Ile(m, n));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int n,j;
	cin >> n;
	vector<int> vec;
	for (int i = 0; i < n; ++i) {
		cin >> j;
		vec.emplace_back(j);
	}
	for (int i = n-1; i >= 0; --i) {
		if (i == 0) {
			cout <<vec[i]<< endl;
		}
		else {
			cout << vec[i] << " ";
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "/Users/swad/Desktop/CP/debug.h"
#endif

// const int N = int(1e5) + 10;
const int MOD = int(1e9) + 7;

struct matrix{
	ll mat[100][100];
	int dim;
	matrix(){};
	matrix(int d){
		dim = d;
		for(int i=0;i<dim;i++)
			for(int j=0;j<dim;j++)
				mat[i][j] = 0;
	}
	/// mat = mat * mul
	matrix operator *(const matrix &mul){
		matrix ret = matrix(dim);
		for(int i=0;i<dim;i++){
			for(int j=0;j<dim;j++){
				for(int k=0;k<dim;k++){
					ret.mat[i][j] += (mat[i][k])*(mul.mat[k][j]) ;
					ret.mat[i][j] %= MOD ;
				}
			}
		}
		return ret ;
	}
	matrix operator + (const matrix &add){
		matrix ret = matrix(dim);
		for(int i=0;i<dim;i++){
			for(int j=0;j<dim;j++){
				ret.mat[i][j] = mat[i][j] + add.mat[i][j] ;
				ret.mat[i][j] %= MOD ;
			}
		}
		return ret ;
	}
	matrix operator ^(ll p){
		matrix ret = matrix(dim);
		matrix m = *this ;
		for(int i=0;i<dim;i++) ret.mat[i][i] = 1 ; /// identity matrix
		while(p){
			if( p&1 ) ret = ret * m ;
			m = m * m ;
			p >>= 1 ;
		}
		return ret ;
	}
};

int n;
ll k;

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	cin >> n >> k;
	matrix m = matrix(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%lld", &m.mat[i][j]);
		}
	}
	m = m ^ k;
	ll ans = 0LL;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			(ans += m.mat[i][j]) %= MOD;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[114514];
ll memo[114514];
ll ru[114514];
ll aa[222222];
signed main() {
	ll n, ans = 0;
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)ans += a[i];
	for (int i = 0; i < n; i += 2)memo[i / 2] = a[i];
	for (int i = 1; i < n; i += 2)memo[(n - 1) / 2 + 1 + i / 2] = a[i];
	for (int i = 0; i < n; i += 2)memo[n + i / 2] = a[i];
	for (int i = 0; i <= n + n / 2; i++)ru[i + 1] = ru[i] + memo[i];
	rep(i, n) {
		if (i <= n / 2)aa[i * 2 + 1] = ((ru[i + n / 2 + 1] - ru[i]) - (ans / 2)) * 2;
		else aa[(i - n / 2) * 2] = ((ru[i + n / 2 + 1] - ru[i]) - (ans / 2)) * 2;
	}
	rep(i, n)cout << aa[i + 1] << " ";
	ggr
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

int main(){
    ios::sync_with_stdio(0);
    int x;cin>>x;
    if(x==1)cout<<0;
    else cout<<1;
}



Measured memory_bytes: 3644
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7,MAXL=25;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll x,y,z,t=0;
	cin>>x>>y;
	z=x;
	for(int i=1;;i++){
		z*=2;
		if(z>y)
			return cout<<i,0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k,p,sum=0;
  itn a[1000000];
  cin>>n>>k;
  n-=k;
  if(n==0) cout<<1<<"\n";
  else cout<<n/(k-1)+(n%(k-1)!=0?1:0)+1<<"\n";
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

ll gcd(ll x, ll y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}

ll gcd3(ll x, ll y, ll z) {
    return gcd(gcd(x,y), z);
}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll K;

    cin >> K;

    ll total = 0;
    for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
    for(int c = 1; c <= K; c++){
        total += gcd3(a,b,c);
    }
    }
    }

    cout << total << endl;

}


Measured memory_bytes: 3608
n=gets.to_i
h={}
m=1
n.times do |i|
  s=gets.chomp
  if h.has_key?(s)
    h[s]+=1
    m=h[s] if m<h[s]
  else
    h[s]=1
  end
end
l=[]
h.each do |hh|
  if hh[1]==m
    l << hh[0]
  end
end
puts l.sort


Measured memory_bytes: 40284
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N, x;
	cin >> N >> x;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int n = 0;
	while (1) {
		if (x >= a[n]) {
			x -= a[n];
			n++;
		}
		else {
			break;
		}
		if (n == N && x > 0) {
			n--;
			break;
		}
		else if (n == N && x == 0) {
			break;
		}
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3580
n, k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]

sorted_h = sorted(h)

num = 0
if k >= len(sorted_h):
    print('0')
elif k == 0:
    print(sum(sorted_h))
else:
    del sorted_h[-k:]
    print(sum(sorted_h))



Measured memory_bytes: 26180
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(26, 0);
  REP(i, n) a[s[i]-'a']++;
  bool ok = true;
  REP(i, n) if(a[i] > 1) ok = false;
  if(ok) cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}

Measured memory_bytes: 256
S = list(input())
if S[0] != "A":
    print("WA")
    exit()
else:
    idx = -1
    for i in range(2, len(S) - 1):
        if S[i] == "C":
            if idx == -1:
                idx = i
            else:
                print("WA")
                exit()
    if idx == -1:
        print("WA")
        exit()

    for i in range(len(S)):
        if i == 0 or i == idx:
            continue
        else:
            if S[i].islower() == False:
                print("WA")
                exit()
print("AC")


Measured memory_bytes: 62000
n = int(input())
s_L = []
for _ in range(n):
    s_L.append(input())
m = int(input())
t_L = []
for _ in range(m):
    t_L.append(input())

import collections

posi = collections.Counter(s_L)

ans = {}
for k,v in posi.items():
    for t in t_L:
        if t == k:
            v -= 1
    ans[k] = v


ans = sorted(ans.items(),key=lambda x:x[1],reverse=True)

if ans[0][1] < 0:
    print(0)
else:
    print(ans[0][1])


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

int main(int argc, char **argv)
{
	int n, i, j;
	char *a = (char *)malloc(10000*sizeof(char));
	
	while(scanf("%s", a) != EOF){
		n = strlen(a) - 1;
		i = j = 0;
		while(n >= 2){
			if(a[n] == 'I' && a[n-1] == 'O'){
				if(a[n-2] == 'J'){
					i++;
					n -= 3;
				} else if(a[n-2] == 'I'){
					j++;
					n -= 2;
				} else {
					n -= 3;
				}
			} else {
				n--;
			}
		}
		printf("%d\n%d\n", i, j);
		
		free(a);
		a = (char *)malloc(10000*sizeof(char));
	}
	free(a);
	
	return 0;
}

Measured memory_bytes: 0
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
cnt = [[-1] * w for _ in range(h)]

def bfs():
    queue = deque()
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                queue.append([i, j])
                cnt[i][j] = 0
    while queue:
        i, j = queue.popleft()
        for di, dj in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if 0 <= i + di < h and 0 <= j + dj < w and cnt[i + di][j + dj] == -1:
                queue.append([i + di, j + dj])
                cnt[i + di][j + dj] = cnt[i][j] + 1

bfs()
print(max([max(l) for l in cnt]))

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

int main(void)
{
	int a;
	cin >> a;
	if(a >= 64)
		cout << 64 << endl;
	else if(a >= 32)
		cout << 32 << endl;
	else if(a >= 16)
		cout << 16 << endl;
	else if(a >= 8)
		cout << 8 << endl;
	else if(a >= 4)
		cout << 4 << endl;
	else if(a >= 2)
		cout << 2 << endl;
	else 
		cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int( 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong

signed main(){
    int H,W,n;
    cin >> H >> W >> n;

    
    int dx[3] = {-1,0,1};
    int dy[3] = {-1,0,1};
    map< pair<int,int> , int>  Map;
    REP(i,n){
        int h,w;
        scanf("%lld%lld",&h,&w);
        REP(i,3){
            REP(j,3){
                if( 2 <= h + dx[i] and h + dx[i]<= H-1 and 2 <= w + dy[j] and w + dy[j] <= W -1) Map[ make_pair(h + dx[i],w + dy[j])]++;
            }
        }
    }
    int ans[10] = {};
    itrfor(itr,Map){
        ans[ (*itr).se] ++;
    }
    FOR(i,1,10){
        ans[0] -= ans[i];
    }
    ans[0] += (H-2) * (W-2);
    REP(i,10) cout << ans[i] << endl;
}

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

int main(){
  int N;
  cin>>N;
  
  vector <int> H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  
  int ans=0;
  
  for(int i=0;i<N;i++){
    bool yuri=true;
    for(int j=0;j<i;j++){
      if(H[j]>H[i]){
        yuri=false;
      }
    }
    if(yuri){
      ans++;
    }
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if (e-d) <= k and (e-c) <= k and (e-b) <= k and (e-a) <= k and (d-c) <= k and (d-b) <= k and (d-a) <= k and (c-b) <= k and (c-a) <= k and (b-a) <= k:
  print("Yay!")
else:
  print(":(")


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

int main() {
  long n,m;
  cin >> n >> m;
  vector<vector<long>> ans(m,vector<long>());
  vector<long> p(m);
  vector<long> y(m);
  vector<vector<vector<long>>> a(n,vector<vector<long>>(0));
  for(long i=0;i<m;i++) {
    cin >> p[i] >> y[i];
    a[p[i]-1].push_back({y[i],i});
    ans[i].push_back(p[i]);
  }

  for(long i=0;i<n;i++) {
    if(a[i].size()!=0) sort(a[i].begin(),a[i].end());
    for(long j=0;j<a[i].size();j++) {
      ans[a[i][j][1]].push_back(j+1);
    }
  }

  for(long i=0;i<m;i++) {
    for(long j=0;j<5-floor(log10(ans[i][0]));j++) cout << "0";
    cout << ans[i][0];
    for(long j=0;j<5-floor(log10(ans[i][1]));j++) cout << "0";
    cout << ans[i][1] << endl;
  }
}

Measured memory_bytes: 17280
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long int64;
typedef pair<int64, int64> pll;

const int INF = 0x3f3f3f3f;

const int MAX_N = 12;
const int MAX_M = 12;

int C[MAX_N];
int A[MAX_N][MAX_M];

int lv[MAX_M];
int dfs(int N,int M,int X,int i,int sum){
    if(i == N){
        for (int j = 0; j < M; ++j)
            if(lv[j] < X)    return INF;
        return sum;
    }
    assert(i < N);

    int ret = INF;
    ret = min(dfs(N,M,X,i+1,sum),ret);
    
    for (int j = 0; j < M; ++j)    lv[j] += A[i][j];
    ret = min(dfs(N,M,X,i+1,sum+C[i]),ret);
    for (int j = 0; j < M; ++j)    lv[j] -= A[i][j];

    return ret;
}


int main(){
    int N,M,X;
    scanf("%d%d%d",&N,&M,&X);
    for (int i = 0; i < N; ++i){
        scanf("%d",C+i);
        for (int j = 0; j < M; ++j)
            scanf("%d",A[i]+j);
    }
    int ans = dfs(N,M,X,0,0);
    if(ans == INF)    ans = -1;
    printf("%d\n",ans);
}


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

int H, W;
char buf[410][410];
bool visited[410][410];

const int DI[4] = {1, 0, -1, 0};
const int DJ[4] = {0, 1, 0, -1};

pair<int,int> go(int r, int c) {
  pair<int,int> res(0, 0);
  if(!visited[r][c]) {
    visited[r][c] = true;
    if(buf[r][c] == '#') {
      res.first++;
    } else {
      res.second++;
    }
    REP(d, 4) {
      int nr = r + DI[d];
      int nc = c + DJ[d];
      if(nr >= 0 && nc >= 0 && nr < H && nc < W && buf[r][c] != buf[nr][nc]) {
        pair<int,int> cur = go(nr, nc);
        res.first += cur.first;
        res.second += cur.second;
      }
    }
  }
  return res;
}

int main(void) {
  scanf("%d%d", &H, &W);
  REP(i, H) {
    scanf("%s", buf[i]);
  }
  ll res = 0;
  REP(i, H) REP(j, W) {
    pair<int,int> cur = go(i, j);
    res += cur.first * ll(cur.second);
  }
  cout << res << endl;

  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n + 2];
    int i;
    for (i = 0; i < n; i++)
        cin >> a[i];
    int dp[n + 2] = {0};
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (i = 2; i < n; i++)
        dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]));

    //for (i = 0; i < n; i++)
        //cout << dp[i] << " ";
    cout << dp[n - 1] << "\n";

    return (0);
}

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

#define pb push_back
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

int const N = 3e3 + 7;

string s, t;
int dp[N][N] = {};
int solve(int i, int j)
{
	if (i >= s.size() || j >= t.size())
		return 0;

	if (dp[i][j] != -1)
		return dp[i][j];

	if (s[i] == t[j])
		return dp[i][j] = max(1 + solve(i+1, j+1), max(solve(i+1, j), solve(i, j+1)));
	return dp[i][j] = max(solve(i+1, j), solve(i, j+1));
}

int main()
{
	fastio;

	memset(dp, -1, sizeof(dp));

	cin >> s >> t;
	solve(0, 0);

	
	int i = 0, j = 0;
	while (i < s.size() && j < t.size())
	{
		if (s[i] == t[j])
		{
			cout << s[i];
			i++, j++;
		}

		else (dp[i+1][j] > dp[i][j+1]) ? i++ : j++;
	}
	cout << '\n';

	return 0;
}


Measured memory_bytes: 39432
#include <stdio.h>

int main () {
	
	int i, j, N, a[1000], flag, k, temp;
	int count = 0 ;

	
	scanf ("%d",&N) ;
	for ( i = 0 ; i < N ; i ++ ) {
		scanf("%d", &a[i] ) ;
	}
	
	flag = 1 ;
	while (flag ) {
		flag = 0 ;
		for ( j = N - 1 ; j >= 1 ; j-- ) {
			if (a[j] < a[j-1] ) { 
				temp = a[j] ;
				a[j] = a[j-1] ;
				a[j-1] = temp ;
				flag = 1 ;
				count++ ;
			}
			
		}
		
	}
		for ( k = 0 ; k < N ; k++ ) {
			printf("%d",a[k] ) ;
				if (k != N-1)
					printf(" ");
					else 
					printf("\n");
		}
	printf("%d\n",count ) ;
	
	
	

return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

ll gcd(ll a, ll b)
{
    //cerr << a << " " << b << endl;
    if (a < b)
    {
        ll t = a;
        a = b;
        b = t;
    }
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}

ll calc(ll a, ll b, ll n)
{
    return ((b - b % n) - ((a + ((n - a % n) % n)))) / n + 1;
}

int main(int argc, char const *argv[])
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cerr << gcd(c, d) << endl;

    cerr << calc(a, b, c) << endl;
    cerr << calc(a, b, d) << endl;
    cerr << calc(a, b, c * d / gcd(c, d)) << endl;
    cout << (b - a + 1) - calc(a, b, c) - calc(a, b, d) + calc(a, b, c * d / gcd(c, d)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int N;
V<int> a;
V<int> s;

int main(){
	cin>>N;
	a.resize(N);
	rep(i,N) cin>>a[i];
	if(N%2 == 0){
		int x[2] = {};
		rep(i,N) x[i%2] += a[i];
		if(x[0]<x[1]) swap(x[0],x[1]);
		cout<<x[0]<<" "<<x[1]<<endl;
		return 0;
	}

	s.resize(N+1);
	rep(i,N) s[i+1] += s[i] + (i%2==0 ? a[i] : -a[i]);

	auto can = [&](int X){	//>=X: ok
		int N = ::N/2+1;
		int mn = 0;
		rep1(r,N){
			if(s[r*2-1]-mn >= X){
				chmin(mn,s[r*2]);
				if(r == N) return true;
			}
		}
		return false;
	};

	int ub = 1e9, lb = -1e9;
	while(ub-lb>1){
		int m = (ub+lb)/2;
		if(can(m)) lb = m;
		else ub = m;
	}
	int sm = 0;
	rep(i,N) sm += a[i];
	int sm1 = 0;
	rep(i,N) if(i%2==1) sm1 += a[i];
	int A = sm1 + lb;
	int B = sm - A;
	cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 2560
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();

        HashMap<Integer, TreeSet<Integer>> c = new HashMap<>();
        int[][] d = new int[2][m];
        for (int i = 0; i < m; i++) {
            int t = in.nextInt();
            int u = in.nextInt();
            d[0][i] = t;
            d[1][i] = u;
            TreeSet<Integer> x = c.getOrDefault(t, new TreeSet<>());
            x.add(u);
            c.put(t, x);
        }

        HashMap<Integer, ArrayList<Integer>> h = new HashMap<>();
        for (Map.Entry<Integer, TreeSet<Integer>> e : c.entrySet()) {
            h.put(e.getKey(), new ArrayList<>(e.getValue()));
        }

        for (int i = 0; i < m; i++) {

            ArrayList<Integer> x = h.get(d[0][i]);
            int index = Collections.binarySearch(x, d[1][i]);

            out.printf("%06d%06d\n", d[0][i], index + 1);
        }
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


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

using namespace std;

int n, p, q;
int a[1000000];
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (a[0] < 0 && a[n - 1] > 0) {
    for (int i = 1; i + 1 < n; i++) {
      if (a[i] < 0) {
        //cout << a[n - 1] << " " << a[i] << "\n";
        ans.emplace_back(a[n - 1], a[i]);
        a[n - 1] -= a[i];
      } else {
        //cout << a[0] << " " << a[i] << "\n";
        ans.emplace_back(a[0], a[i]);
        a[0] -= a[i];
      }
    }
    //cout << a[n - 1] << " " << a[0] << "\n";
    ans.emplace_back(a[n - 1], a[0]);
    a[n - 1] -= a[0];
  } else if (a[0] >= 0) {
    for (int i = 1; i + 1 < n; i++) {
      //cout << a[0] << " " << a[i] << "\n";
      ans.emplace_back(a[0], a[i]);
      a[0] -= a[i];
    }
 //   cout << a[n - 1] << " " << a[0] << "\n";
    ans.emplace_back(a[n - 1], a[0]);
    a[n - 1] -= a[0];
  } else {
    for (int i = 0; i + 1 < n; i++) {
      //cout << a[n - 1] << " " << a[i] << "\n";
      ans.emplace_back(a[n - 1], a[i]);
      a[n - 1] -= a[i];
    }
  }
  cout << ans.back().first - ans.back().second << "\n";
  for (auto it: ans) {
    cout << it.first << " " << it.second << "\n";
  }
  return 0;
}

Measured memory_bytes: 3188
#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

class rep {
	const usize f, l;

public:
	class itr {
		friend rep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	rep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
class revrep {
	const usize f, l;

public:
	class itr {
		friend revrep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	revrep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <cstdio>

int main() {
	usize n, q;
	scanf("%zu%zu", &n, &q);
	::std::vector<usize> a(n + 1), b(n + 1);
	for (const auto i : rep(0, n))
		scanf("%zu", &a[i]), b[a[i]] = i;
	usize p, v = n;
	while (q--) {
		scanf("%zu", &p);
		a[v] = p;
		::std::swap(v, b[p]);
	}
	a.erase(a.begin() + v);
	for (const auto i : rep(0, n))
		printf("%zu%c", a[(i + v) % n], " \n"[i + 1 == n]);
	return 0;
}



Measured memory_bytes: 3948
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long ruijyo(ll n, ll k) {
	if (k == 0) {
		return 1;
	}
	ll sum = 1;
	ll i;
	REP(i, 0, k) {
		sum *= n;
		sum %= MOD;
	}
	return sum;
}

int main()
{
	ll  i, j, k, l, m,n, sum, flag, N,  M, K, H, W, B,C,D;
	sum = 0;
	flag = 0;
	cin >> N;
	vector<ll>T(N);
	vector<ll>A(N);
	ll maxt;
	ll maxa;
	maxt = maxa=0;
	REP(i, 0, N) {
		cin >> T[i];
	}
	REP(i, 0, N) {
		cin >> A[i];
		if (T[i] > maxt)
			maxt = T[i];
		if (A[i] > maxa)
			maxa = A[i];
	}
	REP(i, 0, N) {
		if (T[i] == A[i])
			break;

	}
	j = i;
	ll max = A[j];
	if (max != maxa || max != maxt) {
		output("0");
		return 0;
	}
	i = 0;
	ll cc = 0;
	ll ans = 1;
	while (i < j ) {
		if (T[i + 1] == T[i]) {
			cc++;
			i++;
		}
		else {
			ans *= ruijyo(T[i], cc);
			ans %= MOD;
			cc = 0;
			i++;


		}
	}
	ans *= ruijyo(T[i], cc);
	ans %= MOD;
	i = N - 1;
	cc = 0;
	while (i > j+1) {
		if (A[i]==A[i-1]) {
			cc++;
			//output("y)");
		}
		else {
			ans *= ruijyo(A[i], cc);
			//output(ans);
			ans %= MOD;
			cc = 0;


		}
		i--;
	}
	ans *= ruijyo(A[i], cc);
	ans %= MOD;
	output(ans);

	return 0;
	

	
}













Measured memory_bytes: 1792
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;




void main() {
    int N, A, B;
    scan(N, A, B);
    string s = readln.chomp;

    int tot, avs;
    foreach (i ; 0 .. N) {
        bool ok;

        if (s[i] == 'a') {
            if (tot < A + B) {
                ok = true;
            }
        }
        else if (s[i] == 'b') {
            if (tot < A + B && avs < B) {
                ok = true;
            }
        }

        yes(ok);
        if (ok) {
            tot++;
            if (s[i] == 'b') {
                avs++;
            }
        }
    }


}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 2812
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e18
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
ll n,i,j,k;

int main()
{
    fastio;
    ll u,v,a,b;
    cin>>n>>a>>b;
    vector<vector<ll > > adj(n+1,vector<ll >());
    for(i=1;i<n;i++){
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    vector<ll > da(n+1,inf),db(n+1,inf);
    vector<bool > used(n+1,false);
    used[a]=true;
    queue<ll > q;
    q.push(a);
    da[a]=0;
    while(!q.empty()){
        u=q.front(); q.pop();
        for(auto to:adj[u]){
            if(!used[to]){
                used[to]=true;
                da[to]=da[u]+1;
                q.push(to);
            }
        }
    }
    used.assign(n+1,false);
    used[b]=true;
    q.push(b);
    db[b]=0;
    while(!q.empty()){
        u=q.front(); q.pop();
        for(auto to:adj[u]){
            if(!used[to]){
                used[to]=true;
                db[to]=db[u]+1;
                q.push(to);
            }
        }
    }
    vector<pair<ll,ll > > d;
    for(i=1;i<=n;i++) d.pb({db[i],i});
    sort(d.begin(),d.end());
    ll ans=0;
    for(i=0;i<n;i++){
        if(d[i].X>da[d[i].Y])
            ans=max(ans,d[i].X-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 10100
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf = (char *)wmem;
  rd(buf);
  x = buf;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int T[50];
string S[50];
string X;
int main(){
  int i;
  wmem = memarr;
  int res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
      rd(T[Lj4PdHRW]);
    }
  }
  rd(X);
  {
    int e98WHCEY;
    int cTE1_r3A;
    if(N==0){
      cTE1_r3A = 0;
    }
    else{
      cTE1_r3A = T[0];
      for(e98WHCEY=(1);e98WHCEY<(N);e98WHCEY++){
        cTE1_r3A += T[e98WHCEY];
      }
    }
    res =cTE1_r3A;
  }
  for(i=(0);i<(N);i++){
    res -= T[i];
    if(S[i]==X){
      break;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191229-1 [beta]

// --- original code ---
// int N, T[50];
// string S[50], X;
// {
//   int res;
//   rd(N,(S,T)(N),X);
//   res = sum(T(N));
//   rep(i,N){
//     res -= T[i];
//     if(S[i]==X) break;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include<cstdio>
#define _ 0
#define rep(k ,l ,r) for(register int k = l ; k <= r ; ++ k)
using namespace std;
const int maxn = 1e9;
int n,k,s;
int read() {
    char cc = getchar() ; int cn = 0 , flus = 1;
    while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus; cc = getchar();}
    while(cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0' ,cc = getchar();
    return cn * flus;
}
int main()
{
	// scanf("%d%d%d",&n,&k,&s);
    n = read() ,k = read() ,s = read();
	rep(i ,1 ,k) printf("%d ",s);
	if(s < maxn) rep(i ,k + 1 ,n) printf("%d " ,maxn);
	else rep(i ,k + 1 ,n) printf("1 ");
	return 0;
}

Measured memory_bytes: 1280