akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <cmath>
#include <cstdlib>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

using namespace std;

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

    int d,g;
    cin >> d >> g;
    g /= 100;
    
    vector<int> cs(d), ps(d), nt(d);
    for(int i = 0; i < d; ++i)
    {
        cin >> ps[i] >> cs[i];
        cs[i] /= 100;
    }
       
    struct stat_t {
        int score;
        int numtask;
    };
    
    const auto calc_numtask = [&](const int comp_a)
    {
        stat_t ret = {0, 0};
        int maxrank = -1;
        for(int i = 0; i < d; ++i)
        {
            if(comp_a & (1 << i))
            {
                ret.score += (i+1) * ps[i] + cs[i];
                ret.numtask += ps[i];
            }
            else
            {
                maxrank = i;
            }
        }
        if(maxrank >= 0)
        {
            for(int i = 0; i < ps[maxrank] && ret.score < g; ++i)
            {
                ret.numtask += 1;
                ret.score += maxrank + 1;
            }
        }
        return ret;
    };
    
    int min_numtask = numeric_limits<int>::max();
    
    for(int comp_a = 0; comp_a < (1<<d); ++comp_a)
    {
        const auto stat = calc_numtask(comp_a);
        if(stat.score >= g)
        {
            min_numtask = min(min_numtask, stat.numtask);
        }
    }
    
    cout << min_numtask << '\n';

    return 0;
}


Measured memory_bytes: 384
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

#include<bits/stdc++.h>
using namespace std;

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    jj             " "
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }

const   int  N   =   2e6+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;

int main() {ikarus_101

    ll n,m,i,j,k,x;

    cin>>n>>k>>x;
    cout << min(n * k , x) << nn;







    return 0;
}


Measured memory_bytes: 3624
n = int(input())
a = list(map(int, input().split()))
b = a.copy()

for i, k in enumerate(a):
    if i % 2 == 0:
        b[n // 2 + (i + 1) // 2] = k
    else:
        b[n // 2 - (i + 1) // 2] = k

if n % 2 == 1:
    print(' '.join([str(k) for k in b[::-1]]))
else:
    print(' '.join([str(k) for k in b]))

Measured memory_bytes: 30404
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
A=b-a
B=c-a
C=d-a
D=e-a
F=c-b
G=d-b
H=d-c
I=e-b
J=e-c
K=e-d
if k>=A and k>=B and k>=A and k>=C and k>=D and k>=F and k>=G and k>=H and k>=I and k>=J and k>=K:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3188
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> p(N);
    rep(0, i, N)
    {
        cin >> p.at(i);
    }

    sort(all(p));
    ll ans = 0;
    rep(0, i, K)
    {
        ans += p.at(i);
    }
    cout << ans << endl;
}

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

int main(){

  string S;
  cin >> S;
  int Rnum=0;
  int Lnum=0;
  int ans[100001];

  For(i,100001) ans[i] = 0;

  for(int i=0; i<S.size(); i++){
    if(S[i]=='R') Rnum++;
    if(S[i]=='L') {
      int j=i;
      while(S[j]=='L'){
        Lnum++;
        j++;
      }
      if((Rnum+Lnum)%2==0){
        ans[i-1] = (Rnum+Lnum)/2;
        ans[i] = (Rnum+Lnum)/2;
      }else if(Rnum%2!=0){
        ans[i-1] = (Rnum+Lnum+1)/2;
        ans[i] = (Rnum+Lnum-1)/2;
      }else{
        ans[i-1] = (Rnum+Lnum-1)/2;
        ans[i] = (Rnum+Lnum+1)/2;
      }
      i=j-1;
      Rnum=0;
      Lnum=0;
    }
  }

  For(i,S.size()-1) cout << ans[i] << " ";
  cout << ans[S.size()-1] << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N, M;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;
    int dist = N - 1;
    for(int i = 1; i <= M; i++){
        if(dist * 2 <= N && dist * 2 + 4 > N && !(N & 1)) dist--;
        cout << i << " " << i + dist << endl;
        dist -= 2;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define rep(i,a,b) for(int i = a;i < b; ++i)
using namespace std;

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

bool is_prime(int x){
	for(int i = 2;i *i <= x; ++i){
		if(x % i == 0)return false;
	}
	return true;
}

int main(){
	cin.tie(0);	
	cout.tie(0);	
	ios_base::sync_with_stdio(0);
	int x;
	cin >> x;
	while(!is_prime(x)){
		++x;
	}
	cout << x << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  REP(i, n) {
    REP(j, m) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }

  set<int> used;
  int usedc = 0;
  int ans = n + 1;
  while (usedc < m) {
    int count[m] = {};
    REP(i, n) {
      REP(j, m) {
        if (used.find(a[i][j]) == used.end()) {
          count[a[i][j]]++;
          break;
        }
      }
    }

    int maxi = -1;
    int tmp = 0;
    REP(i, m) {
      if (count[i] > tmp) {
        tmp = count[i];
        maxi = i;
      }
    }
    used.insert(maxi);
    usedc++;
    ans = min(tmp, ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
int cost[11][11];
#define INF 1e9

using namespace std;

int main(void){
	int n,a,b,d;
	int cmax;
	int t,rmin,tmin;
	while(cin >> n,n){
		tmin=INF;
		cmax=0;
		for(int i=0;i<11;i++)
				for(int j=0;j<11;j++)
					cost[i][j]=INF;
					
		for(int i=0;i<11;i++)
			cost[i][i]=0;
			
		for(int i=0;i<n;i++){
			cin >> a >> b >> d;
			if(cmax<a)
				cmax=a;
			if(cmax<b)
				cmax=b;
			cost[a][b]=cost[b][a]=d;
		}
		for(int k=0;k<=cmax;k++)
			for(int i=0;i<=cmax;i++)
				for(int j=0;j<=cmax;j++)
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
		
		for(int i=0;i<=cmax;i++){
			t=0;
			for(int j=0;j<=cmax;j++)
					t+=cost[i][j];
			if(t<tmin)
				tmin=t,rmin=i;
		}
		cout << rmin << ' ' << tmin << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

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

    ll A[N];    
    REP(i, N){
        cin >> A[i];
    }

    sort(A, A+N);

    ll res = gcd(A[0], A[1]);
    FOR(i, 2, N-1){
        res = gcd(res, A[i]);
        if(res == 1){
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    if( a % 2 || b % 2 || c % 2 ) cout << 0 << endl;
    else if( a == b && b == c ) cout << -1 << endl;
    else {
        int cnt = 0;
        while( !( a % 2 ) && !( b % 2 ) && !( c % 2 ) ) {
            int tmpa, tmpb, tmpc;
            tmpa = b / 2 + c / 2;
            tmpb = a / 2 + c / 2;
            tmpc = a / 2 + b / 2;
            ++cnt;
            a = tmpa; b = tmpb; c = tmpc;

        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,q;
vector<int>edge[100005];
struct segtree{
	int seg[(1<<18)],lazy[(1<<18)];
	void init(){ memset(seg,0,sizeof(seg)); memset(lazy,0,sizeof(lazy));}
	int update(int a,int b,int k,int l,int r,int x){
		if(r<a || b<l) return seg[k];
		else if(a<=l && r<=b){
			seg[k] = max(seg[k],x);
			lazy[k] = max(lazy[k],x);
			return seg[k];
		}
		if(lazy[k]){
			for(int q=1;q<=2;q++){
				seg[k*2+q] = max(seg[k*2+q],lazy[k]);
				lazy[k*2+q] = max(lazy[k*2+q],lazy[k]);
			}
			lazy[k] = 0;
		}
		seg[k] = max(update(a,b,k*2+1,l,(l+r)/2,x),update(a,b,k*2+2,(l+r)/2+1,r,x));
	}
	int query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return -1;
		else if(a<=l && r<=b){
			return seg[k];
		}
		if(lazy[k]){
			for(int q=1;q<=2;q++){
				seg[k*2+q] = max(seg[k*2+q],lazy[k]);
				lazy[k*2+q] = max(lazy[k*2+q],lazy[k]);
			}
			lazy[k] = 0;
		}
		return max(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2+1,r));
	}
}seg;

int beg[100005],en[100005],id,vv[100005];
void dfs(int v,int u){
	vv[id] = v;
	beg[v] = id++;
	for(int i=0;i<edge[v].size();i++){
		dfs(edge[v][i],v);
	}
	en[v] = id-1;
}
int main(){
	while(1){
	    id = 0;
		scanf("%d%d",&n,&q);
		if(n == 0) return 0;
		ll ans = 0;
		for(int i=1;i<=n;i++) edge[i].clear();
		for(int i=2;i<=n;i++){
			int a; scanf("%d",&a);
			edge[a].push_back(i);
		}
		seg.init();
		dfs(1,-1);
		for(int i=0;i<q;i++){
			char ch; int v; scanf(" %c %d",&ch,&v);
			if(ch == 'Q'){
				int val = seg.query(beg[v],beg[v],0,0,(1<<17)-1);
				ans += vv[val];
			}
			else{
				seg.update(beg[v],en[v],0,0,(1<<17)-1,beg[v]);
			}
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 17020
n,a,b = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort()
t = a-b
r = 10**9+5
l = 0

while r-l > 1:
    m = (r+l)//2
    mi = m*b
    count = 0
    for i in h:
        if i > mi:
            count += (i-mi+t-1)//t
    if count <= m:
        r = m
    else:
        l = m
print(r)

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

int main(){
   int N;
   cin >>N;
   int a=0;
   int sum=0;
   
   vector<int>vec(N);
   for(int i=0; i<N; i++){
   cin>>vec.at(i);
   //cout<<vec.at(i);
   }

   for(int i=0; i<N; ){
   sum+=1; 
   //cout<<i;
   a=vec.at(i);
   //cout<<a;
       if(vec.at(i)==2){
       cout<<sum<<endl;//☆
       break;
        }
    else 
    i=a-1;
    //cout<<i<<endl;
         if(sum>N){
         cout<<-1<<endl;//☆
         break;
         }
  }
}//m

/*
33424
1
032
2
243
3
32☆3
*/
/*
2が押せないとき
3412
032
210
032
210
032
-1
*/

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"YES"<<endl;
	exit(0);
}
 
void No(){
	cout<<"NO"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n, m; cin >> n >> m;
    map<int, int> mp;
    rep(i, m) {
        int a, b; cin >> a >> b;
        mp[a] ++; mp[b] ++;
    }
    for(auto p: mp) {
        if(p.sc % 2 == 1) {
            No();
        }
    }
    Yes();
	return 0;
}

Measured memory_bytes: 4984
S = input()
st = set(['A', 'G', 'C', 'T'])
ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        string = S[i:j+1]
        if not string:
            continue
        flag = True
        for char in string:
            if char not in st:
                flag = False
        if flag:
            ans = max(ans, len(string))
print(ans)

Measured memory_bytes: 3064
h,w,k=map(int,input().split())
s=[list(map(int,list(input()))) for _ in range(h)]
def func(catyoko):
  cattate=0
  past=[0]*10
  for wi in range(w):
    now=[0]*10
    for i in range(1,len(catyoko)):
      for j in range(catyoko[i-1],catyoko[i]):
        now[i-1]+=s[j][wi]
    if max([past[i]+now[i] for i in range(10)])>k:
      if max(now)>k:
        return -10
      else:
        cattate+=1
      past=[nowi for nowi in now]
    else:
      for i in range(10):
        past[i]+=now[i]
  return cattate+len(catyoko)-2

# 横方向の割り方は2^(h-1)通りある。h<=10なので横方向の割り方は全探索する。
# 縦方向の割り方は貪欲法
ans=h+w
for i in range(2**(h-1)):
  catyoko=[0]
  for j in range(h-1):
    if ((i>>j) & 1):#立っているビットのところで処理が走る
      catyoko.append(j+1)
  catyoko.append(h)
  a=func(catyoko)
  #print(a,catyoko)
  if a>=0:
    ans=min(ans,a)
print(ans)


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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


using state = tuple<ll, ll, ll>;


const int limit = 100010;
ll a[limit], b[limit], c[limit];

auto abcmp = [](int i, int j)->bool{
	const ll vi = b[i] - a[i];
	const ll vj = b[j] - a[j];
	return vi <  vj;
};

ll acmax[limit];
ll bcmax[limit];

int main(void) {
	int x, y, z;
	cin >> x >> y >> z;
	const int all = x + y + z;

	rep(i, all) cin >> a[i] >> b[i] >> c[i];

	vector<int> idx(all);
	iota(begin(idx), end(idx), 0);
	sort(begin(idx), end(idx), abcmp);

	{
		priority_queue<ll> pq;
		rep(i, x) {
			acmax[0] += a[idx[i]];
			pq.push(c[idx[i]] - a[idx[i]]);
		}

		rep(i, z) {
			pq.push(c[idx[x + i]] - a[idx[x + i]]);
			acmax[i + 1] = acmax[i] + a[idx[x + i]] + pq.top();
			pq.pop();
		}
	}

	reverse(begin(idx), end(idx));

	{
		priority_queue<ll> pq;
		rep(i, y) {
			bcmax[0] += b[idx[i]];
			pq.push(c[idx[i]] - b[idx[i]]);
		}

		rep(i, z) {
			pq.push(c[idx[y + i]] - b[idx[y + i]]);
			bcmax[i + 1] = bcmax[i] + b[idx[y + i]] + pq.top();
			pq.pop();
		}
	}

	ll ans = 0LL;
	rep(k, z + 1) chmax(ans, acmax[k] + bcmax[z - k]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4344
import java.awt.geom.*;
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		int dataset = sc.nextInt();
		while(dataset-- > 0){
			String s = sc.next();
			int cap = 4000;
			char [] c = new char[cap];
			Arrays.fill(c, '*');
			int pos = cap / 2;
			int len = s.length();
			for(int i = 0; i < len;){
				char nowc = s.charAt(i);
				if(Character.isLetter(nowc)){
					c[pos] = nowc;
					i++;
				}
				else if(nowc == '-'){
					pos++;
					i = i + 2;
				}
				else{
					pos--;
					i = i + 2;
				}
			}
			String ans = new String(c).replaceAll("\\*+", "");
			System.out.println(ans);
		}
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 22148
import string

count = {x: 0 for x in string.ascii_lowercase}
lines = ""

while True:
    try:
        lines += input().lower()
    except EOFError:
        break

for c in lines:
    if 'a' <= c <= 'z':
        count[c] += 1

for key in string.ascii_lowercase:
    print("{0} : {1}".format(key, count[key]))

Measured memory_bytes: 8004
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#define INF 0x3f3f3f3f
#define maxn 105000
#define maxnn 6000
#define juzheng 300
#define line cout << "-------------------------" << endl;
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define fill_(a,b,n) fill(a,a + n,b)
#define esp 1e-9
 
#define ri(n) scanf("%d",&n)
#define ri2(a,b) scanf("%d %d",&a,&b)
#define ri3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define rd(n) scanf("%lf",&n)
#define rd2(a,b) scanf("%lf %lf",&a,&b)
#define rd3(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define rl(n) scanf("%lld",&n)
#define rl2(a,b) scanf("%lld %lld",&a,&b)
#define rl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define rui(n) scanf("%u",&n)
#define rui2(a,b) scanf("%u %u",&a,&b)
#define rui3(a,b,c) scanf("%u %u %u",&a,&b,&c)
#define rs(str) scanf("%s",str)
#define pr(n) cout << n << endl
#define ll long long
#define int64 __int64
#define ui unsigned int

using namespace std;

const ll mod = 1e9 + 7;

//Date:2018-8-11
//Author：HarryBlackCat

ll sum[maxn],n,m;
map<ll,ll> mapp; 

void init(){
	mem(sum,0);
	mapp.clear();
	mapp[0] = 1;
}

int main() {
	//cin.sync_with_stdio(false);//降低cin，cout时间
	while(~rl2(n,m)){
		init();
		
		ll x;
		for(int i = 1;i <= n;i++){
			rl(x);
			sum[i] = (sum[i - 1] + x) % m;
			mapp[sum[i]]++;
		}
		
		map<ll,ll>::iterator iter;
		ll ans = 0;
		for(iter = mapp.begin();iter != mapp.end();iter++){
			ll temp = iter->second;
			ans += (temp - 1) * temp / 2;
		} 
		
		pr(ans);
	}
	return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A<6){
    cout << 0 << endl;
  }
  else if(5<A&&A<13){
    cout << B/2 << endl;
  }
  else{
    cout << B << endl;
  }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> t(n+1);
    vector<pair<int,int>> p(n+1);
    t[0] = 0;
    p[0] = {0,0};
    for(int i = 1; i < n+1; i++){
        cin >> t[i];
        int a,b;
        cin >> a >> b;
        p[i] = {a,b};
    }
    for(int i = 0; i < n; i++){
        int cost = abs(p[i].first-p[i+1].first)+abs(p[i].second-p[i+1].second);
        if((cost < (t[i+1]-t[i]) && (cost-t[i]+t[i+1])%2 == 1) || cost > t[i+1]-t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
#define par pair<pair<int,int>, int>
#define f first
#define s second

int n, a[405];
long long mem[405][405],cum[405];

long long dp(int start=1, int end=n)
{
    if(start == end) return 0;
    long long &ret =mem[start][end];
    if(~ret) return ret;
    ret = OO;
    for(int i=start; i<end; i++)
    {
        ret = min(ret,1ll* dp(start, i)+dp(i+1, end)+(cum[i]-cum[start-1])+(cum[end]-cum[i]));
    }
    return ret;
}

int main()
{
    memset(mem, -1, sizeof mem);
    scanf("%d",&n);
    for(int i=1; i<=n ;i++)scanf("%d",a+i);
    for(int i=1; i<=n ;i++)cum[i] = cum[i-1]+a[i];
    printf("%lld",dp());
    return 0;
}

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

const int maxn = 500, mod = 1e9 + 7;
int n, X, fact[maxn + 3], finv[maxn + 3], c[maxn + 3], f[maxn + 3][maxn + 3][maxn + 3], p[maxn + 3][maxn + 3];

int qpow(int a, int b) {
	if (a <= maxn && b <= maxn && p[a][b]) return p[a][b];
	int c = 1, d = a, e = b;
	for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) c = 1ll * a * c % mod;
	if (d <= maxn && e <= maxn) p[d][e] = c;
	return c;
}

void prework(int n) {
	fact[0] = 1;
	for (int i = 1; i <= n; i++) fact[i] = 1ll * fact[i - 1] * i % mod;
	finv[n] = qpow(fact[n], mod - 2);
	for (int i = n; i; i--) finv[i - 1] = 1ll * finv[i] * i % mod;
}

int C(int n, int m) {
	if (n < 0 || m < 0 || m > n) return 0;
	return 1ll * fact[n] * finv[m] % mod * finv[n - m] % mod;
}

int main() {
	scanf("%d %d", &n, &X);
	prework(X);
	for (int i = 1, x; i <= n; i++) {
		scanf("%d", &x), c[x]++;
	}
	f[X + 1][0][0] = 1;
	for (int i = X; i; i--) {
		for (int j = 0; j <= X; j++) {
			for (int k = i * j; k <= X; k++) {
				for (int l = 0; l <= j && l * i <= k; l++) {
					f[i][j][k] = (f[i][j][k] + 1ll * f[i + 1][j - l][k - l * i] * finv[l]) % mod;
				}
				f[i][j][k] = 1ll * f[i][j][k] * qpow(k - (i - 1) * j, c[i]) % mod;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= X; i++) {
		for (int j = 0; j <= X; j++) {
			ans = (ans + 1ll * f[1][i][j] * fact[i] % mod * ((X - j) & 1 ? mod - 1 : 1) % mod * C(X - j + 1, i)) % mod;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

int main(void)
{
	long long k, n;
	cin >> k >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		if (i == 0)
			ans[i] = a[n-1]-a[0];
		else {
			ans[i] = k - (a[i]-a[i-1]);
		}
	}
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
	return 0;
}


Measured memory_bytes: 1792
n,k = map(int,input().split())
h = []
for i in range(n):
    hi = int(input())
    h.append(hi)
h.sort()

min = 10**100
for i in range(n-k+1):
    if min > h[k+i-1]-h[i]:
        min = h[k+i-1]-h[i]

print(min)


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

const int MOD = 1e9 + 7;
int mul(int a, int b) {
	return (long long) a * b % MOD;
}
int my_pow(int a, int b) {
	int r = 1;
	while(b) {
		if(b % 2) {
			r = mul(r, a);
		}
		a = mul(a, a);
		b /= 2;
	}
	return r;
}
int my_inv(int a) {
	return my_pow(a, MOD  - 2);
}

void sub_self(int& a, int b) {
	a -= b;
	if(a < 0) {
		a += MOD;
	}
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> fac(2 * n + 1);
	fac[0] = 1;
	for(int i = 1; i <= 2 * n; i++) {
		fac[i] = mul(fac[i-1], i);
	}
	
	// if(n >= 5) cerr << "fac[5] = " << fac[5] << endl;
	
	auto binomial = [&](int a, int b) {
		if(a < b) {
			return 0;
		}
		return mul(fac[a], my_inv(mul(fac[b], fac[a-b])));
	};
	
	vector<int> a(n);
	for(int& x : a) {
		cin >> x;
	}
	sort(a.begin(), a.end());
	// 2 5 6 7 9 11
	   // 1
	int answer = 0;
	for(int i = 0; i < n - 1; i++) {
		int diff = (a[i+1] - a[i]) % MOD;
		int ways = binomial(n, k);
		sub_self(ways, binomial(i + 1, k));
		sub_self(ways, binomial(n - i - 1, k));
		answer = (answer + mul(diff, ways)) % MOD;
	}
	cout << answer << endl;
}


Measured memory_bytes: 1408
def factorial(n)
  n = 0 if n.nil?
  th = 10**9+7
  (1..n).inject { |f, i| (f *  i) % th}
end

th = 10**9+7
n,m = gets.split.map(&:to_i)

if (n-m).abs > 1
  puts "0"
  exit
end
if n == m
  puts (factorial(n) * factorial(m) * 2) % th
else
  puts (factorial(n) * factorial(m)) % th
end

Measured memory_bytes: 14268
#include <stdio.h>

int main()
{
    long long n,m,ans = 0;
    scanf("%lld %lld",&n,&m);

    if(m >= n * 2)
    {
        ans = n + (m - n * 2) / 4;
    }
    else
    {
        ans = m / 2;
    }
    
    printf("%lld",ans);
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var rates = new Dictionary<string, decimal>();
        rates.Add("JPY", 1);
        rates.Add("BTC", 380000);

        decimal sum = 0;
        for (int i = 0; i < N; i++)
        {
            var inputs = Console.ReadLine().Split(' ');
            var amount = decimal.Parse(inputs[0]);
            var unit = inputs[1];
            sum += amount * rates[unit];
        }
        Console.WriteLine(sum);
    }
}



Measured memory_bytes: 13152
# -*- coding: utf-8 -*-

import sys
import numpy as np

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

N, K = MAP()
A = LIST()

def check(omit):
    # 部分和DP
    dp = np.zeros(K, dtype=np.bool)
    prev = np.zeros(K, dtype=np.bool)
    dp[0] = prev[0] = 1
    for i in range(N):
        # まとめて遷移
        if i != omit and A[i] < K:
            prev[A[i]:] |= dp[:K-A[i]]
        dp = prev.copy()
    # 今回の値A[omit]を足してKに到達できるような部分和があれば、これは必要
    for j in range(max(0, K-A[omit]), K):
        if dp[j]:
            return True
    # なければ不要
    return False

A.sort()
print(bisearch_min(-1, N, check))


Measured memory_bytes: 12608
#include <bits/stdc++.h>
#ifdef CHECK_

std::vector<int> graph[2048];
int n, k;

void load() {
  n = get<int>();
  k = get<int>();
  for(int i = 1; i < n; ++i) {
    auto s = get<int>();
    auto t = get<int>();
    graph[s].push_back(t);
    graph[t].push_back(s);
  }
}

int memo[2048][2048];
bool term[2048];

void dfs2(int prev, int id, int rem) {
  if( rem == 0 ) term[id] = true;
  for(int next : graph[id]) {
    if( next == prev ) continue;
    dfs2(id, next, rem - 1);
  }
}


int dfs(int prev, int id, int rem) {
  if( rem < 0 ) return 0;
  if( rem == 0 ) return 1;
  int res = 1;
  for(int next : graph[id]) {
    if( next == prev ) continue;
    res += dfs(id, next, rem - 1);
  }
  return res;
}

int main() {
  load();
  int res = (1 << 28);
  for(int i = 1; i <= n; ++i) {
    dfs2(-1, i, k);
  }
  if( k % 2 == 0 ) {
    for(int i = 1; i <= n; ++i) {
      int m = (int)graph[i].size();
      if( m < 2 ) continue;
      int temp = 1;
      for(int j = 0; j < m; ++j) {
        auto x = dfs(i, graph[i][j] , k / 2 - 1);
        temp += x;
      }
      res = std::min(res, n - temp);
    }
  }
  else {
    for(int i = 1; i <= n; ++i) {
      for(int j : graph[i]) {
        if( i < j ) continue;
        int temp = 2;
        for(int next : graph[i]) {
          if( next == j ) continue;
          temp += dfs(i, next, k / 2 - 1);
        }
        for(int next : graph[j]) {
          if( next == i ) continue;
          temp += dfs(j, next, k / 2 - 1);
        }
        res = std::min(res, n - temp);
      }
    }
  }
  put(res);
  
  return 0;
}

#else

template<typename T>
T get() { return 0; }
template<>
int get() { int x; scanf("%d", &x); return x; }
template<>
long get() { long x; scanf("%ld", &x); return x; }

template<typename T>
void put(T x) {}
template<>
void put(int x) { printf("%d\n", x); }
template<>
void put(long x) { printf("%ld\n", x); }


#define CHECK_
#include __FILE__
#endif



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, m; std::cin >> n >> m;
  ll ans = 0;
  for (ll i = 1; i * i <= m; i++) {
    if (m % i) continue;
    if (n * i <= m) chmax(ans, i);
    if (n * (m / i) <= m) chmax(ans, m / i);
  }
  std::cout << ans << "\n";
}


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

int main()
{
    int n, k;
    int cnt = 0;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        int temp;
        cin >> temp;
        if (temp >= k) cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
//encoding:utf-8
#include <iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる
#include<math.h>
#include<vector>
#include<algorithm> //sort とかにいる

#define ll long long
using namespace std;
int inf = INFINITY;

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int all_path = 0;
  int position = 0;
  for(int i=0;i<n;i++){
    all_path += abs(position-a[i]);
    position = a[i];
  }
  all_path += abs(position);

  for(int i=0;i<n;i++){
    int ans = all_path;
    int pre_position,after_position;
    if(i==0){
      pre_position = 0;
    }
    else{
      pre_position = a[i-1];
    }
    if(i==n-1){
      after_position = 0;
    }
    else{
      after_position = a[i+1];
    }
    // cout<<pre_position<<a[i]<<after_position<<endl;
    if((pre_position<=a[i]&&a[i]<=after_position)||(pre_position>=a[i]&&a[i]>=after_position)){
    }
    else{
      ans -= abs(a[i]-pre_position)+abs(after_position-a[i]);
      ans += abs(pre_position-after_position);
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
char str[300005];
int main() {
	int n;
	scanf("%d%s", &n, str);
	int r = 0, g = 0, b = 0, rg = 0, rb = 0, gb = 0;
	ll ans = 1;
	const ll MOD = 998244353;
	auto mul = [&](int x) {
		ans = ans * x % MOD;
	};
	for (int i = 0; i < 3 * n; ++i) {
		if (str[i] == 'R') {
			if (gb > 0) mul(gb--);
			else if (g > 0) {
				++rg;
				mul(g--);
			} else if (b > 0) {
				++rb;
				mul(b--);
			} else {
				++r;
			}
		} else if (str[i] == 'G') {
			if (rb > 0) mul(rb--);
			else if (r > 0) {
				++rg;
				mul(r--);
			} else if (b > 0) {
				++gb;
				mul(b--);
			} else {
				++g;
			}
		} else if (str[i] == 'B') {
			if (rg > 0) mul(rg--);
			else if (r > 0) {
				++rb;
				mul(r--);
			} else if (g > 0) {
				++gb;
				mul(g--);
			} else {
				++b;
			}
		}
	}
	for (int i = 2; i <= n; ++i) mul(i);
	printf("%lld\n", ans);
}


Measured memory_bytes: 512
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] str = new String[n];
        for(int i = 0; i<n; i++) {
            char[] chars = sc.next().toCharArray();
            Arrays.sort(chars);
            str[i] = new String(chars);
        }
        Arrays.sort(str);
        //for(String s: str) System.out.println(s);
        long cnt = 1;
        long ans = 0;
        String pres = str[0];
        for(int i = 1; i<n; i++) {
            String s = str[i];
            if(pres.equals(s)) {
                cnt++;
            }else {
                ans += cnt*(cnt-1)/2;
                cnt=1;
            }
            pres = s;
        }
        //System.out.println(cnt);
        ans += cnt*(cnt-1)/2;

        System.out.println(ans);

    }
}

Measured memory_bytes: 51828
nm = input().split(" ")

#偶数になるのは偶偶or奇奇

n = int(nm[0])
m = int(nm[1])

#偶偶の場合の数
Even = n * (n-1)/2

#奇数の場合の数
Odd = m * (m-1)/2

#組み合わせの合計
print(int(Even + Odd))


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

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

    long long h, w;
    cin >> h >> w;

    long long mini = 1e9;
    for(long long i = 1; i < h; i++){
        long long a = i * w;
        long long b = (h - i) / 2 * w;
        long long c = h * w - a - b;
        mini = min(mini, max(a, max(b, c)) - min(a, min(b, c)));
        
        b = (w / 2) * (h - i);
        c = h * w - a - b;
        mini = min(mini, max(a, max(b, c)) - min(a, min(b, c)));
    }

    for(long long i = 1; i < w; i++){
        long long a = i * h;
        long long b = (w - i) / 2 * h;
        long long c = h * w - a - b;
        mini = min(mini, max(a, max(b, c)) - min(a, min(b, c)));

        b = (h / 2) * (w - i);
        c = h * w - a - b;
        mini = min(mini, max(a, max(b, c)) - min(a, min(b, c)));
    }

    cout << mini << endl;

    return 0;
}

Measured memory_bytes: 256
X, N = gets.split.map(&:to_i)
P = gets.split.map(&:to_i)

a = 100000
b = 100000
(0..101).each do |x|
    if !P.include?(x) && (as = (x - X).abs) < b then
        b = as
        a = x
    end
end

puts a


Measured memory_bytes: 14388
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    String op = sc.next();
    int B = sc.nextInt();
    if (op.equals("+")) System.out.println(A+B);
    if (op.equals("-")) System.out.println(A-B);
  }
}

Measured memory_bytes: 22740
#!/usr/bin/python3
#coding: utf-8

N = int(input())

p = 10**9 + 7

ret = pow(10, N, p)
ret -= pow(9, N, p)
ret -= pow(9, N, p)
ret += pow(8, N, p)

ret = (ret + p) % p

print(ret)

Measured memory_bytes: 9100
#include <stdio.h>
int main(){

 int W, H, x, y, r;
 scanf ("%d%d%d%d%d", &W, &H, &x, &y, &r);
 if ( 0 + r <= x && x <= W - r && 0 + r <= y && y <= H - r ) {
   printf("Yes\n");
 } else {
   printf("No\n");
 }
  return 0;

}



Measured memory_bytes: 2128
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i+100*j+50*k==X:
        ans+=1
print(ans)


Measured memory_bytes: 3060
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    for j in range(len(A)-1):
        print(A[j],end=" ")
    print(A[-1])


Measured memory_bytes: 5976
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

// 同じ数の整数がN+1個以上あると無理
// そうでないならうまくできそう
// 構築方法わからｎ、、

const int MAX_N = 200010;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    repeat(i, N) cin >> A[i];
    repeat(i, N) cin >> B[i];
    vector<int> cntA(N + 1, 0), cntB(N + 1, 0);

    repeat(i, N) {
        ++cntA[A[i]], ++cntB[B[i]];
    }
    repeat(i, N + 1) {
        if (cntA[i] + cntB[i] > N) {
            cout << "No" << endl;
            return 0;
        }
    }

    // https://scrapbox.io/procon-kirokuyou/ABC178_F_-_Contrast_(600)
    // とにかくスワップする
    // AとBがかぶっているところがM個あるなら、そのなかで違う組同士でBiをスワップする
    // と、M-2個になる。その要領で、M-4, M-6, ..., 1個と減らして最後は
    // 例外処理で減らす
    int R = 0, L = 0;
    repeat(i, N) {
        if (A[i] != B[i]) continue;
        setmax(R, i + 1);
        while (R < N) {
            // A[R] == B[R] かつ B[i] != B[R]なRを探す
            if (A[R] == B[R] && B[i] != B[R]) break;
            ++R;
        }
        if (R < N) {
            swap(B[i], B[R]);
        } else {
            while (L < N) {
                if (A[i] != B[L] && A[L] != B[i]) {
                    swap(B[i], B[L]);
                    ++L;
                    break;
                }
                ++L;
            }
        }
    }

    cout << "Yes" << endl;
    repeat(i, N) cout << B[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 6428
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

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

    string s;
    cin >> s;

    if(SZ(s) == 2){
        cout << s << endl;
        return 0;
    }
    reverse(ALL(s));
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
cout<<fixed<<setprecision(10);

int A,B;
  cin >> A >> B;
  if(A>=13) cout << B<< endl;
  else if (A>=6) cout <<B/2<<endl;
  else cout << 0 <<endl;
	
}

Measured memory_bytes: 256
n = input()
a = list(map(int, input().split()))
max = 10**9
for i in a:
    c = 0
    if i % 2 == 0:
        while i % 2 == 0:
            i = i/2
            c += 1
    if c < max:
        max = c
        
print(max)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 100050;

int n, m, fa[N], p[N];

int Find(int x) { return fa[x] == 0 ? x : fa[x] = Find(fa[x]); }
void Union(int x, int y) { if ((x = Find(x)) != (y = Find(y))) fa[x] = y; }

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  for (int i = 1, x, y; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    Union(x, y);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans += (Find(i) == Find(p[i]));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 896
sx, sy, tx, ty = map(int, input().split())

dy = tx - sx
dx = ty - sy

ans = ''

ans += 'U' * dx
ans += 'R' * dy
ans += 'D' * dx
ans += 'L' * dy
ans += 'L'
ans += 'U' * (dx + 1)
ans += 'R' * (dy + 1)
ans += 'D'
ans += 'R'
ans += 'D' * (dx + 1)
ans += 'L' * (dy + 1)
ans += 'U'

print(ans)

Measured memory_bytes: 61792
#include <stdio.h>

int main(void){
	int a;
	int b;
	int add;
	int sub;
	int mul;
	int max;
	char buf[128];
	fgets(buf, 127, stdin);
	sscanf(buf,"%d %d", &a, &b);
	add = a + b;
	sub = a - b;
	mul = a * b;
	if(add > sub && add > mul){
		max = add;
	} else if(sub > add && sub > mul){
		max = sub;
	} else if(mul > add && mul > sub){
		max = mul;
	}
	printf("%d\n", max);
}

Measured memory_bytes: 128
# 単一始点最短経路 Single source shortest path I

INFTY = 2000000000

n = int(input())
M = [[INFTY for i in range(n)] for i in range(n)]
for i in range(n):
    dat = [int(i) for i in input().split()]
    for j in range(1, dat[1] + 1):
        M[dat[0]][dat[2 * j]] = dat[2 * j + 1]

col = [-1 for i in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]

d[0] = 0

while True:
    mincost = INFTY
    for i in range(n):
        if col[i] != 1 and d[i] < mincost:
            mincost = d[i]
            u = i
    
    if mincost == INFTY:
        break
    
    col[u] = 1
    
    for v in range(n):
        if col[v] != 1 and M[u][v] != -1:
            if d[u] + M[u][v] < d[v]:
                d[v] = d[u] + M[u][v]
                p[v] = u
                col[v] = 0

for i in range(n):
    print(i, d[i])




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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

class UnionFind {
    public:
        vector<int> rank, p, size;

        UnionFind() {}
        UnionFind(int s) {
            rank.resize(s, 0);
            p.resize(s, 0);
            size.resize(s, 0);
            rep (i, s) init(i);
        }

        void init(int x) {
            p[x] = x;
            rank[x] = 0;
            size[x] = 1;
        }

        bool isSame(int x, int y) {
            return root(x) == root(y);
        }

        void unite(int x, int y) {
            if (isSame(x, y)) return;
            link(root(x), root(y));
        }

        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
                size[x] += size[y];
            } else {
                p[x] = y;
                size[y] += size[x];
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }

        int root(int x) {
            if (x != p[x]) {
                p[x] = root(p[x]);
            }
            return p[x];
        }

        int getSize(int x) {
            return size[root(x)];
        }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    UnionFind uf = UnionFind(n);
    vector<int> p(n);
    rep (i, n) {
        cin >> p[i];
        p[i]--;
    }
    rep (i, m) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        uf.unite(x, y);
    }
    int res = 0;
    rep (i, n) if (uf.isSame(i, p[i])) res++;
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 1792
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

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

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

ll pow(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    return (x % mod) * pow(x, y-1, mod) % mod;
}

const static ll A = 71;

bool isPrime(ll p) {
    if (p == 2) {
        return true;
    }
    if (pow(A, p-1, p) == 1) {
        RANGE(i, 2, min(p, (ll)sqrt(p)+1)) {
            if (p % i == 0) {
                return false;
            }
        }
        return true;
    }
    return false;
}

int run(istream& in, ostream& out) {
    ll N;
    in >> N;

    ll ans = 0;
    RANGE(c, N, min(N+1000, 100003LL)) {
        if(isPrime(c)) {
            ans = c;
            break;
        }
    }
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 3328