akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  string s;
  cin>>s;
  if(s[0]==s[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int L,R;
int main (){
    cin >> L >> R;
    long long int up = min( R-L,2019);
    long long int ans = ((L % 2019) * ((L+1)%2019) % 2019);
    for(long long int i=L;i<=(L+up);i++) {
        for(long long int j=i;j<=(L+up);j++) {
            if(i==j) continue;
            long long int a = (i % 2019);
            long long int b = (j % 2019);
            ans = min( a*b % 2019 , ans % 2019);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// abc152_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int a,b;
  cin>>a>>b;
  if (a>b){
    rep(i,a){
      cout<<b;
    }
  } else {
    rep(i,b){
      cout<<a;
    }
  }
  cout<<endl;
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int ret = min(N * A, B);
  cout << ret << endl;
  return 0;
}



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

int main()
{
	int N, K;
	cin >> N >> K;
	map<int, int> mp;
	for( int i = 0; i < N; i++ ) {
		int A;
		cin >> A;
		mp[A]++;
	}

	vector<int> num;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		num.push_back( it->second );
	}
	sort( num.begin(), num.end() );
	int ans = 0;
	while( num.size() > K ) {
		ans += num[0];
		num.erase( num.begin() );
	}

	cout << ans << endl;
}


Measured memory_bytes: 13592
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,i,temp=0,max1=0,max2=0; cin>>n;
    vector <int> v;
    for(i=0;i<n;i++){
        int k; cin>>k; v.push_back(k);
    }
    int maxElementIndex = max_element(v.begin(),v.end()) - v.begin();
    temp=maxElementIndex;
    max1=v[maxElementIndex];
    v[maxElementIndex]=0;
    maxElementIndex = max_element(v.begin(),v.end()) - v.begin();
    max2=v[maxElementIndex];
    for(i=0;i<n;i++){
        if(i==temp) cout<<max2<<"\n";
        else cout<<max1<<"\n";
    }
}

Measured memory_bytes: 2548
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const double PI = acos(-1.0);

ll lcm(ll a, ll b)
{
	ll res = 1;
	for(ll i = 31622; i >= 2; i--) {
		if(a % i == 0 && b % i == 0) {
			res *= i;
			a /= i;
			b /= i;
		}
	}
	return res * a * b;
}

int main()
{
	ll a, b, c, d, l;
	cin >> a >> b >> c >> d;

	a--;
	l = lcm(c, d);
	ll res = b - (b / c + b / d - b / l);
	res -= a - (a / c + a / d - a / l);
	cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
n, k, q = map(int, input().split())
quiz = [int(input()) for i in range(q)]
point = [k-q]*n
for i in quiz:
  point[i-1] += 1
[print("Yes") if i > 0 else print("No") for i in point]
'''
1. あらかじめ全員のポイントを Q 減らしておく (つまり，開始時点のポイントは K − Q)．
2. Q 回の正解それぞれに対して，正解者のポイントを 1 増やす．

リストの中身すべてに計算すると「リスト要素」＊「ループ回数」の計算量になる
'''

Measured memory_bytes: 11368
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S, T;
	cin >> S >> T;
	int ans = 0;
	REP(i, 3) {
		if (S[i] == T[i])ans++;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()

{

    int N,ans=0;

    cin >> N;

    int k;

    for (int i = 1; i <= N; i++)

    {

        cin >> k;

        if (k % 2 == 1 && i % 2 == 1)

        {

            ans++;

        }

    }

    cout << ans;

    return 0;

}

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

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

int N;

int main() {
  cin >> N;

  int t = 0;
  ll ans = 10000000;
  ll i = 0;
  while (i <= N) {
    int count = 0;
    t = N - i;

    while (t > 0) {
      int cc = t % 9;
      t /= 9;
      count += cc;
    }

    int tt = i;
    while (tt > 0) {
      int cc = tt % 6;
      tt /= 6;
      count += cc;
    }

    ++i;

    if (ans > count) ans = count;
  }

  cout << ans << endl;
}


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

int main(){
    int n,r;
    cin>>n>>r;
    int ans;
    ans = n>=10 ? r:r+100*(10-n);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 998244353;
const long double PI = acos(-1);
const long long N = 4e5+1;
 
typedef long long ll;
typedef long double ld;

ll t[4*N], lazy[4*N];

void build(ll a[], ll v, ll tl, ll tr)
{
    if(tl == tr)
        t[v] = a[tl];
    else
    {
        ll tm = (tl + tr) >> 1;
        build(a, v * 2, tl, tm);
        build(a, v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2], t[v * 2 + 1]);
    }
}
void push(ll v)
{
    t[v * 2] = (t[v*2] + lazy[v]) % MOD;
    lazy[v * 2] = (lazy[v * 2] +lazy[v])%MOD;
    t[v * 2 + 1] = (t[v * 2 + 1] + lazy[v])%MOD;
    lazy[v * 2 + 1] =( lazy[v * 2 + 1]+lazy[v]) % MOD;
    lazy[v] = 0;
}

void update(ll v, ll tl, ll tr, ll l, ll r, ll val)
{
    if(l > r)
        return;
    if(l == tl && r == tr)
    {
        t[v] = (t[v] + val)% MOD;
        lazy[v] = (lazy[v] + val) % MOD;
    }
    else
    {
        push(v);
        ll tm=(tl+tr)>>1;
        update(v*2, tl, tm, l, min(r, tm), val);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, val);
        t[v]=min(t[v*2], t[v*2+1]);
    }
}

ll query(ll v, ll tl, ll tr, ll l, ll r)
{
    if(l>r)
        return INT_MAX;
    if(l<=tl && tr<=r)
    {
        return t[v];
    }
    push(v);
    ll tm=(tl+tr)>>1;
    return min(query(v*2, tl, tm, l, min(r, tm)), 
            query(v*2+1, tm+1, tr, max(l, tm+1),r));
}
void test_case()
{
	ll n, k;
	cin >> n >> k;
	vector<pair<ll,ll>> v(k+1);
	for(int i = 1; i <= k; i++)
	{
		cin >> v[i].first >> v[i].second;
	}
	ll nn = 2 * n + 1;
	ll a[nn] = {0};
	build(a, 1, 0, nn-1);
	update(1, 0, nn-1, 1, 1, 1);
	for(int i = 1; i < n; i++)
	{
		ll z = query(1, 0, nn-1, i, i);
		// cout << z << " ";
		if(!z)
			continue;
		for(int j = 1; j <= k; j++)
		{
			// cout << v[j].first << ' ' << v[j].second << '\n';
			update(1, 0, nn-1, i + v[j].first, i+v[j].second, z);
		}
	}
	ll z = query(1, 0, nn-1, n, n);
	cout << z<< '\n';
	
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


Measured memory_bytes: 23088
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define N 505

using namespace std;
typedef pair<int,int> Pair;
typedef long long ll;

const long double Pi = 3.14159265358979323846l;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = mul(res, x);
		x = mul(x, x), y >>= 1;
	} return res;
}

template <class T> inline T	input() {
	T x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T &y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T &y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

long long sum, a[N][N];
long long n, m, h, w;

int main() {
	read(n, m, h, w);
	for (int i = h; i <= n; i += h)
		for (int j = w; j <= m; j += w)
			a[i][j] = - 4000ll * (h * w - 1) - 1, sum += a[i][j];

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (!a[i][j]) a[i][j] = 4000, sum += 4000;

	if (sum <= 0) return puts("No"), 0;
	puts("Yes");
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < m; ++j) printf("%lld ", a[i][j]);
		printf("%lld\n", a[i][m]);
	}
	return 0;
}


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

using namespace std;

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

  for (int i = 1; i < 10; i ++) {
    for (int j = 1; j < 10; j ++) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

bool c[110][110];

int main() {
    int A, B;
    cin >> A >> B;

    int n = 100;
    int s = n / 2;
    --A, --B;
    rep(i, s) rep(j, n) c[i][j] = 1;
    for (int i = 0; i < s - 1; i += 2) {
        for (int j = 0; j < n; j += 2) {
            if (A) {
                c[i][j] = 0;
                --A;
            }
        }
    }
    for (int i = s + 1; i < n; i += 2) {
        for (int j = 0; j < n; j += 2) {
            if (B) {
                c[i][j] = 1;
                --B;
            }
        }
    }
    puts("100 100");
    rep(i, n) {
        rep(j, n) { printf("%c", c[i][j] ? '#' : '.'); }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1e5 + 10;
int a[maxN];
int n;
int ans[maxN];
vector < int > g[maxN];
void dfs(int v, int p) {
    vector < int > all;
    for (int to : g[v]) {
        dfs(to, v);
        all.emplace_back(ans[to]);
    }
    sort(all.begin(), all.end());
    ans[v] = all.size();
    for (int i = 0; i < all.size(); i++) {
        ans[v] = max(ans[v], all[i] + ((int)all.size() - i));
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int par;
        cin >> par;
        g[par].emplace_back(i);
    }
    dfs(1, -1);
    cout << ans[1];
    return 0;
}

Measured memory_bytes: 13952
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

void st()
{
    cout<<"setwise coprime";
}
 
void pr()
{
     cout<<"pairwise coprime";
}

void no()
{
    cout<<"not coprime";
}
bool primechk[1000007];
map<long long,long long> mp;

int main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL);
    long long n,i,x,cnt,j,bb=0;
    //preprocess(1000004);
    cin>>n;
    long long arr[n+5];
    for(i=0;i<n;i++){cin>>arr[i];}
    for(i=0;i<n;i++)
    {
        x=arr[i];
        for(j=2;j*j<=x;j++)
        {
            if(x%j==0)
            {
                mp[j]++;
                if(mp[j]==n){no();return 0;}
                else if(mp[j]>1){bb=1;}
                while(x%j==0){x/=j;}
            }
        }
        if(x>=2){mp[x]++;if(mp[x]==n){no();return 0;}else if(mp[x]>1){bb=1;}}
    }
     if(bb){st();}
    else{pr();}
    return 0;
}

Measured memory_bytes: 16248
#include <string>
#include <iostream>
#include <unordered_set>

int main(void) {
	int N = 0;
	char c = ' ';
	bool fail = 0;
	std::cin >> N;
	std::string str;
	std::unordered_set<std::string> myset;

	for (int i = 0; i < N; i++) {
		std::cin >> str;
		char t_c = str[0];
		if (c != t_c && i != 0) {
			std::cout << "No";
			fail = 1;
			break;
		}
		if (myset.find(str) != myset.end()) {
          std::cout << "No";
			fail = 1;
			break;
		} else {
			myset.insert(str);
		}
		c = str[str.length() - 1];
	}
	if (!fail)
		std::cout << "Yes";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n > k) cout << k*x+(n-k)*y;
    else cout << n*x;
    cout << "\n";
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N,A,B;
    cin >> N >> A >> B;
    string str;
    cin >> str;
    int ca = 0, cb = 0;
    for(int i=0; i<str.size(); i++) {
        if(ca+cb >= A+B) {
            cout<<"No" << endl;
            continue;
        }
        if(str[i] == 'c'){
            cout << "No" << endl;
        }else if(str[i] == 'b') {
            if(ca+cb < A+B && cb < B){
                cout << "Yes" << endl;
                cb++;
            }
            else cout << "No" << endl;
        }else {
            if(ca+cb < A+B){
                cout<<"Yes" << endl;
                ca++;
            }
            else cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

int main() {
  int N, M;
  cin >> N >> M;
  //u:1から定期便1つで行ける島, v:Nから〃
  vector<int> u, v;

  REP(i, M){
    int a,b;
    cin >> a >> b;
    if(a == 1) u.push_back(b);
    if(b == N) v.push_back(a);
  }

  sort(ALL(v));

  REP(i, u.size()){
    auto j = lower_bound(ALL(v), u[i]);
    if(j != v.end() && *j == u[i]){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;
long long modinv(long long a, long long m=MOD) {long long b = m, u = 1, v = 0;while (b) {    long long t = a / b;    a -= t * b; swap(a, b);    u -= t * v; swap(u, v);}u %= m; if (u < 0) u += m;return u;}
//MODの割り算の際にa/＝b;をa *= modinv(b,MOD);とする。
int gcd(int a, int b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}
 

 const int ma = 1000000000;
int main(){
    int N,M;cin >> N >> M;
    int j =1;
    int ans = 1;
    ll se = M/N;
    ll ser = N*se;
    for(int i=se;i>=1;i--){
        ll tmp  = M - ser;
        ser -= N;
        // cout << ser << endl;
        if(tmp%i==0){
            cout << i << endl;
            break;     
        }
    }

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

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

#define ll long long 
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

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


	ll n; cin >> n;
	ll change = ceil(n / 1000.0) * 1000;
	cout << change - n;
	return 0;
}

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

const int MOD = 1000000007;
long long dp[1100000], sum[1100000];

int main () {
    long long n; cin >> n;
    dp[0] = 1; sum[1] = 1;
    dp[1] = 1; sum[2] = 2;
    for (long long i = 2; i < n; ++i) {
        dp[i] = (dp[i-1] + sum[i-2]) % MOD;
        sum[i+1] = sum[i] + dp[i];
    }
    long long res = 0;
    for (long long i = 0; i < n; ++i) {
        if (i <= n-3) res += dp[i] * (n * (n-2) % MOD+i+3) % MOD;
        else if (i == n-2) res += dp[i] * n % MOD * (n-1) % MOD;
        else if (i == n-1) res += dp[i] * n % MOD;
        res %= MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 16640
n=int(input())
code=input()
fump=[code[i:i+1] for i in range(0,len(code))]
jump=[]
k=0
l=0
for i in range(n):
    if fump[i]=='(':
        jump.append('(')
        k+=1
    elif k>l:
        jump.append(')')
        l+=1
    else:
        jump.append(')')
        jump.insert(0,'(')
        k+=1
        l+=1
while k>l:
    jump.append(')')
    l+=1
for z in range(len(jump)):
    print(jump[z],end='')
        


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


int main() {
  string s;cin >> s;
  int n = (s.size()-1)/2;
  int ans=0;
  rep(i,n+1){
    if(s[i]!=s[s.size()-1-i])ans++;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
#ifdef MY
    freopen("input.txt","r",stdin);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #define endl '\n';
#endif
    cin>>n;
    if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)
        cout<<"hon";
    else if(n%10==3)
        cout<<"bon";
    else
        cout<<"pon";
}


Measured memory_bytes: 3652
import itertools as it
def main() :
    N = int(input())
    S_list = [input() for s in range(N)]
    dic_counts = {"M" : 0, "A" : 0, "R" : 0, "C" : 0, "H" : 0}
    li = ["M","A","R","C","H"]
    combi = list(it.combinations(li,3))

    for s in S_list :
        for key in dic_counts.keys() :
            if (s[0] == key) :
                dic_counts[key] += 1

    sum = 0
    for item in combi :
        sum += dic_counts[item[0]] * dic_counts[item[1]] * dic_counts[item[2]]
    
    print(sum)


main()

# memo
# M1 A1 R1 C1
# M2       C2
# M3
# 
# M,A,R -> 3 * 1 * 1
# M,A,C -> 3 * 1 * 2
# A,R,C -> 1 * 1 * 2



Measured memory_bytes: 9772
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int chk[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, q, i, tot = 0, b, c;
    cin >> n;
    vector<int> ar(n);
    for(i = 0; i < n; i++){
        cin >> ar[i];
        chk[ar[i]]++;
        tot += ar[i];
    }
    cin >> q;
    while(q--){
        cin >> b >> c;
        tot += chk[b]*(c-b);
        chk[c] += chk[b];
        chk[b] = 0;
        cout << tot << nl;
    }
}

Measured memory_bytes: 4192
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    int H, W; cin >> H >> W;
    int N; cin >> N;
    int a[N+1]; for (int i = 1; i <= N; ++i) cin >> a[i];

    int ans[H][W];
    int i = 1;
    for (int h = 0; h < H; ++h) {
        if (h % 2 == 0) {
            for (int w = 0; w < W; ++w) {
                ans[h][w] = i;
                --a[i];
                if (a[i] == 0) ++i;
            }
        } else {
            for (int w = W - 1; w >= 0; --w) {
                ans[h][w] = i;
                --a[i];
                if (a[i] == 0) ++i;
            }
        }
    }

    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W - 1; ++w) {
            cout << ans[h][w] << " ";
        }
        cout << ans[h][W-1] << endl;
    }


    return 0;
}





Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

ll D = 365;
vec c(26);
mat s(D, vec(26));
vec last(26, 0);


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

    cin >> D;
    Rep (i, 26) {
        cin >> c[i];
    }
    Rep (i, D) {
        Rep (j, 26) {
            cin >> s[i][j];
        }
    }

    ll tmp = 0;
    Rep (i, D) {
        ll score = tmp;
        ll ans = 0;
        ll best = tmp;
        Rep (j, 26) {
            score += s[i][j];
            Rep (k, 26) {
                if (k != j) score -= c[k] * (i+1-last[k]);   
            }
            if (score > best) {
                ans = j;
                best = score;
            }
            score -= s[i][j];         
        }

        last[ans] = i+1;
        cout << ans+1 << endl;
    }
}

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;

int main(){
    char s[3]; int ans = 0;
    for(int i = 0; i < 3; i++){
        cin >> s[i];
        if(s[i] == '1') ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int x,a;
	cin >> x>>a;
	if(x<a){
		cout<<0;
	}else{
		cout<<10;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	int n;
	cin>>n;
	int ans = INF;
	for(int i=0;9*i<=n;i++){
		int nine = i;
		int memo = 0;
		while(nine > 0){
			memo += nine%9;
			nine /= 9;
		}
		int nn = n;
		nn -= 9*i;
		while(nn > 0){
			memo += nn%6;
			nn /= 6;
		}
		ans = min(ans,memo);
	}

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


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

ll a[100005];
ll b[100005];

int main() {
	int n;
	scanf("%d", &n);
	for (int i=0 ; i<n ; i++) {
		scanf("%lld%lld", a+i, b+i);
	}
	ll off = 0;
	ll sol = 0;
	for (int i=n-1 ; i>=0 ; i--) {
		a[i] += off;
		ll add = (b[i] - a[i]%b[i]) % b[i];
		off += add;
		sol += add;
	}
	printf("%lld\n", sol);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n,k,a[N];
LL s[N],t[N];
unordered_map<int,int>vis;
int main() {
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i],s[i]=s[i-1]+a[i],s[i]=(s[i]+k)%k;
    LL ans=0;
    vis[0]=1;
    int l=0;
    for(int i=1;i<=n;i++){
        while(i-l>=k){
            vis[(s[l]-l%k+3ll*k)%k]--;
            l++;
        }
        ans+=vis[(s[i]-i%k+3ll*k)%k];
        vis[(s[i]-i%k+3ll*k)%k]++;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 10824
#include <stdio.h>

int main(void){
	char c_num[11];
	int num[10] , i , j;
	while(scanf("%s" , c_num)!=EOF){
		for(i=0;i<10;i++) num[i] = c_num[i] - '0';
		for(i=9;i>0;i--){
			for(j=0;j<i;j++){
				if(num[j] + num[j+1] >= 10) num[j] = num[j] +num[j+1] - 10;
				else num[j] += num[j+1];
			}
		}
		printf("%d\n" , num[0]);
	}
	return 0;
}

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

using namespace std;

static std::string keyence{"keyence"};

bool solve(const std::string& s) {
  if (s.find(keyence) != std::string::npos) {
    return true;
  }
  int const eraseSize = s.size() - keyence.size();
  if (!eraseSize) {
    return false;
  }
  for (int i = 0; i < s.size() - eraseSize; ++i) {
    std::string ss = s;
    ss.erase(ss.begin() + i, ss.begin() + i + eraseSize);
    if (ss == keyence) {
      return true;
    }
  }
  return false;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s;
  std::cin >> s;
  std::cout << (solve(s) ? "YES" : "NO") << std::endl;
  return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;


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

	string S, T;
	cin >> S >> T;
	int ans = 0;
	rep(i, 0, SZ(S))
	{
		if (S[i] != T[i])ans++;
	}

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

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int N; 
int C[10010] = {}; 
vector<int> E[10010];
bool F[10010]; 
int S[10010]; 
void dfs(int s, int &count){
	F[s] = true; 
	S[s] = count; 
	count ++; 
	for(int i = 0; i < E[s].size(); i++){
		if(F[E[s].at(i)]) continue; 
		dfs(E[s].at(i), count); 
	}
}
int main(){
	cin >> N; 
	for(int i = 0; i < N-1; i++){
		int a, b; cin >> a >> b; 
		a--; b--; 
		E[a].push_back(b); E[b].push_back(a); 
	}
	int ans = 0; 
	for(int i = 0; i < N; i++){
		cin >> C[i]; 
	}
	sort(C, C+N, greater<int>()); 
	for(int i = 1; i < N; i++){
		ans += C[i]; 
	}
	cout << ans << endl; 
	int count = 0; 
	dfs(0, count); 
	for(int i = 0; i < N; i++){
		cout << C[S[i]] << " "; 
	}
	cout << endl; 
}

Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static boolean[][] graph;
    public static void main(String[] ans) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        graph = new boolean[N][N];
        for (int i = 0; i < N; i++) {
            Arrays.fill(graph[i], false);
        }

        for (int i = 0; i < M; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            graph[a-1][b-1] = true;
            graph[b-1][a-1] = true;
        }
        boolean[] visited = new boolean[N];
        Arrays.fill(visited, false);
        visited[0] = true;
        System.out.println(dfs(0, N,visited ));
    }

    private static int dfs(int currentNode, int N, boolean[] visited) {
        boolean allVisited = true;
        for (int i = 0; i < N; i++) {
            if (!visited[i]) {
                allVisited = false;
            }
        }
        if (allVisited) {
            return 1;
        }

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if(!graph[currentNode][i]) {
                continue;
            }

            if(visited[i]) {
                continue;
            }
            visited[i] = true;
            ans += dfs(i, N, Arrays.copyOf(visited, visited.length));
            visited[i] = false;
        }

        return ans;
    }
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int e = c - (d - b);
    int f = d + (c - a);
    int g = e - (f - d);
    int h = f + (e - c);
    cout << e << ' ' << f << ' ' << g << ' ' << h << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7
#define num 111111

typedef long long ll;
int p1[num], p2[num];
vector<int> a, b;

int main()
{
  int n, m1 = 1, m2 = 1, tmp;

  cin>>n;
  REP(i,n/2) {
    cin>>tmp;
    p1[tmp]++;
    cin>>tmp;
    p2[tmp]++;
  }

  REP(i,num) {
    if (p1[i] > m1) {
      a.clear();
      a.push_back(i);
      m1 = p1[i];
    } else if (p1[i] == m1) {
      a.push_back(i);
    }

    if (p2[i] > m2) {
      b.clear();
      b.push_back(i);
      m2 = p2[i];
    } else if (p2[i] == m2) {
      b.push_back(i);
    }
  }

  if (a.size() > 2 || b.size() > 2) {
    cout<<n - m1 - m2<<endl;
  } else if (a[0] != b[0]) {
    cout<<n - m1 - m2<<endl;
  } else {
    sort(p1, p1+num);
    sort(p2, p2+num);
    int r = max(m1 + p2[num-2], m2 + p1[num-2]);
    cout<<n-r<<endl;
  }

  return 0;
}

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

int main(){
  int hen[3];
  int cnt=0;
  int d=0;
  int e=0;
  
  while(1)
    {
      for(int i=0;i < 3;i++)
	{
	  cin >> hen[i];
	}
      sort(hen,hen+3);

      int judge = pow(hen[0],2) + pow(hen[1],2);
      int most = pow(hen[2],2);
      
      if(hen[0]+hen[1] > hen[2] && hen[1]+hen[2] > hen[0] && hen[2]+hen[0] > hen[1])
	{
	  if(judge < most)
	    {
	      d++;
	    }
	  else if(judge > most)
	    {
	      e++;
	    }
	  else if(judge == most)
	    {
	      cnt++;
	    }
	}
      else
	{
	  break;
	}
    }
  cout << cnt+e+d << " " << cnt << " " << e << " " << d << endl;
  return 0;
}



Measured memory_bytes: 3104
import java.io.*;
import java.util.*;
 
public class Main {
	static final Reader in = new Reader();
	static final long M=(long)1e9+7;
	
	public static void main(String[] args) {
		int n=in.nextInt();
		long[] ps = new long[n+1];
		long nf=1;
		for(int i=1; i<=n; ++i) {
			ps[i]=(ps[i-1]+in.nextInt())%M;
			nf=nf*i%M;
		}
		long ans=nf*ps[n]%M, s=0;
		for(int i=1; i<=n-1; ++i) {
			s=(s+ps[n-i]-ps[i]+M)%M;
			ans=(ans+nf*modI((long)(i+1)*(i>=n-1?1:i+2), M)%M*2*s+nf*modI(i+1, M)%M*(ps[i]+ps[n]-ps[n-i]+M))%M;
		}
		System.out.println(ans);
	}
	
	static long modI(long a, long m) {
		return (a%=m)<=1?1:(1-modI(m%a, a)*m)/a+m;
	}
	
	static class Reader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while(st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 36212
"""
クラスカルのアルゴリズム
"""

class UnionFindTree:
  def __init__(self, n: int):
    self.__parent = [i for i in range(n)]
    self.__rank = [0 for i in range(n)]

  def unite(self, x, y) -> None:
    self.__link(self.__find_set(x), self.__find_set(y))

  def same(self, x, y) -> bool:
    return self.__find_set(x) == self.__find_set(y)

  def __find_set(self, x):
    if x != self.__parent[x]:
      self.__parent[x] = self.__find_set(self.__parent[x])
    return self.__parent[x]

  def __link(self, x, y):
    if self.__rank[x] < self.__rank[y]:
      self.__parent[x] = y
    else:
      if self.__rank[x] == self.__rank[y]:
        self.__rank[x] += 1
      self.__parent[y] = x


class Edge:
  def __init__(self, src, dst, weight):
    self.src = src
    self.dst = dst
    self.weight = weight


V, E = map(int, input().split())
INF = 10**10
edges = [Edge(*map(int, input().split())) for i in range(E)]
edges.sort(key=lambda e: e.weight)
total_cost = 0
t = UnionFindTree(V)

for e in edges:
  if not t.same(e.src, e.dst):
    t.unite(e.src, e.dst)
    total_cost += e.weight

print(total_cost)



Measured memory_bytes: 33900
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

char solve2( char c, int a ) {
    char answer = c - 'a';
    // cout << c << endl;
    // cout << c << ',' << a << endl;
    for ( int i = 0; i < a; i++ ) {
        answer = ( answer + 1 ) % 26;
    }
    // cout << (char)( answer + 'a' ) << endl;
    // cout << (char)( answer + 'a' ) << endl;
    return ( answer + 'a' );
}

string solve( string input, int a, int b ) {
    input[a-1] = solve2( input[a-1], b );
    return input;
}

int main() {
    int n;
    while ( cin >> n && n ) {
        string input;
        cin >> input;
        
        int A[n], B[n];
        for ( int i = 0; i < n; i++ ) {
            cin >> A[i] >> B[i];
            A[i]--;
            B[i]--;
        }
        
        for ( int i = n-1; i >= 0; i-- ) {
            int a = A[i];
            int b = B[i];
            swap( input[a], input[b] );
            input[a] = solve2( input[a], abs( a - b ) );
            input[b] = solve2( input[b], abs( a - b ) );
        }
        
        cout << input << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  
  for(int i=0;i<N;i++) cin >> d[i];
  int set = N;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(d[i]==d[j]){
        set--;
        break;
      }
    }
  }
  
  cout << set << endl;
}


Measured memory_bytes: 256
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			




k = input1() 
a,b=input2()
flag=False
for i in range(a,b+1):
	if i % k==0:
		flag=True
		break

if flag:
	print("OK")
else:
	print("NG")













Measured memory_bytes: 27124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M ;
    int A[M] ,B[M];
  for ( int i=0 ; i < M ;i++){
    cin >> A[i] >> B[i] ;
  }
  int road[N] ;
  for ( int i=0 ; i<N ; i++ ){
    road[i]=0;
  }
  for ( int i=0 ; i < M ; i++){
    road[A[i]-1]++;
    road[B[i]-1]++;
  }
  for ( int i=0 ; i< N ; i++){
    cout << road[i] << endl;
  }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int cnt[200];

pii pp[200];

char s[200];

void solve(){
	int n, k;
	scanf("%d%d", &n, &k);
	REP(i, 0, n){
		scanf("%s", &s[0]);
		cnt[s[0]]++;
	}
	int ans = 0;
	REPN(i, 'A', 'Z'){
		pp[i - 'A'] = mp(cnt[i], i);
	}
	while(1){
		sort(pp, pp + 26);
		reverse(pp, pp + 26);
		if (pp[k - 1]._1 == 0){
			break;
		}
		REP(i, 0, k){
			pp[i]._1--;
		}
		ans++;
	}
	printf("%d\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
struct P : IComparable<P>
{
	public readonly int H, Power;
	public P(int h, int p) {H = h; Power = p; }
	public int CompareTo(P p) => End.CompareTo(p.End);
	public int End => H + Power;
}
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const long INF = 2011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Console.WriteLine(Solve());
		Out.Flush();
	}
	int Solve()
	{
		var N = F();
		var ps = new List<P>();
		for (int i = 0; i < N; i++)
		{
			var I = G();
			ps.Add(new P(I[0], I[1]));
		}
		ps.Sort();
		// dp[i, j] = [0, i) の人から j 人積むときの高さの最小値 (無理なら INF)
		var dp = new long[N + 1][];
		dp[0] = new long[1];
		for (var i = 0; i < N; i++)
		{
			dp[i + 1] = new long[i + 2];
			for (var j = 1; j <= i + 1; j++)
			{
				var skip = j < i + 1 ? dp[i][j] : INF;
				if (dp[i][j - 1] <= ps[i].H) dp[i + 1][j] = Min(skip, dp[i][j - 1] + ps[i].Power);
				else dp[i + 1][j] = skip;
			}
		}
		var m = 0;
		for (var j = 1; j <= N; j++) if (dp[N][j] < INF) m = j;
		return m;
	}
}


Measured memory_bytes: 127668
#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define LL long long
#define pb push_back
#define PB pop_back
#define PF pop_front
#define F first
#define S second
#define inrow(vec)    for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
#define incoloum(vec) for(int i=0;i<vec.size();i++)cout<<vec[i]<<endl;

const double PI=3.1415926;
const int KL=1e6;
const LL mod=1e9+7;


using namespace std;

LL q,x,y,z,n,m,p[KL],mn=1e9,mx=-1e9,ans;
string t;
vector <LL> vec;
set <int> s;
map <int,int> M;


LL pw(LL u,LL v)
{
    if(v==0)return 1;
    ans=pw(u,v/2)%mod;
    ans=(ans*ans)%mod;
    if(v%2==1)ans=(ans*u)%mod;
    return ans%mod;

}
LL division_m(LL u,LL v)
{
    LL ret=pw(v,mod-2);
    ret=(ret*u)%mod;
    return ret%mod;
}

int main()
{
    scl(n);scl(x);scl(y);
    m=pw(2,n);
    m=(m-1+mod)%mod;
    LL sum=1,sum1=1;
    for(LL i=0;i<=x-1;i++)
    {
        sum=(sum*(n-i))%mod;
        sum1=(sum1*(i+1))%mod;
    }
    m=(m-division_m(sum,sum1)+mod)%mod;
    sum=1;sum1=1;
    for(LL i=0;i<=y-1;i++)
    {
        sum=(sum*(n-i))%mod;
        sum1=(sum1*(i+1))%mod;
    }
    m=(m-division_m(sum,sum1)+mod)%mod;

    cout<<m<<endl;


    return 0;
}


Measured memory_bytes: 256