akhauriyash/Code-Regression huggingface dataset:
// Last Change: 08/26/2019 21:44:01.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> AB(N);
  ll sumB = 0;
  for (ll i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    AB[i] = a + b;
    sumB -= b;
  }
  sort(AB.begin(), AB.end(), greater<ll>());

  for (ll i = 0; i < N; i += 2) {
    sumB += AB[i];
  }
  cout << sumB << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		int i, max = -2147483646, currentmin, size, differ;
		List<Integer> numbers = new ArrayList<Integer>();

		Scanner in = new Scanner(System.in);
		
		size = Integer.parseInt(in.nextLine());
		for(i = 0; i < size; i++) numbers.add(Integer.parseInt(in.nextLine()));
		
		currentmin = numbers.get(0);
		for(i = 1; i < size; i++){
			differ = numbers.get(i) - currentmin;
			if(numbers.get(i) < currentmin) currentmin = numbers.get(i);
			if(differ > max) max = differ;
		}
		System.out.println(max);

	}
}

Measured memory_bytes: 176312
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

void init()
{
}

void solve()
{
	int h, w, k;
	cin >> h >> w >> k;

	vector<string> c;
	rep(i, h)
	{
		string s;
		cin >> s;
		c.push_back(s);
	}

	int ans = 0;

	rep(i, (1 << h))
	{
		rep(j, (1 << w))
		{
			int cnt = 0;
			rep(y, h)
			{
				rep(x, w)
				{
					if ((i & (1 << y)) == 0)
					{
						continue;
					}
					if ((j & (1 << x)) == 0)
					{
						continue;
					}

					if (c[y][x] == '#')
					{
						cnt++;
					}
				}
			}

			if (cnt == k)
			{
				ans++;
			}
		}
	}

	cout << ans << endl;
}

int main()
{
	init();
	solve();
}


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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N - 1));
    rep(i, N) {
        rep(j, N - 1) {
            cin >> A[i][j];
            A[i][j]--;
        }
        reverse(all(A[i]));
    }

    int days = 0;
    vector<P> q;
    auto check = [&](int i) {
        if (A[i].size() == 0) return;
        int j = A[i].back();
        if (A[j].size() == 0) return;
        if (A[j].back() == i) {
            P p(i,j);
            if (p.second < p.first) swap(p.first, p.second);
            q.push_back(p);
        }
    };
    rep(i, N) { check(i); }
    while (q.size() > 0) {
        sort(all(q));
        q.erase(unique(all(q)), q.end());
        days++;
        vector<P> prevQ;
        swap(prevQ, q);
        for (P p : prevQ) {
            int i = p.first, j = p.second;
            A[i].pop_back();
            A[j].pop_back();
            check(i);
            check(j);
        }
    }

    rep(i, N) {
        if (A[i].size() != 0) {
            puts("-1");
            return 0;
        }
    }
    cout << days << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    
    // 普通にaピザをx枚、bピザをy枚買った場合の金額
    ll ans = a*x + b*y;

    // ABピザ2枚を組み合わせて少ない方を満たす場合
    if(x > y) chmin(ans, 2*y*c + (x-y)*a);
    else if(x < y) chmin(ans, 2*x*c + (y-x)*b);

    // 全部ABピザ2枚の組み合わせで作る場合
    chmin(ans, max(x, y)*2*c);

    // 出力
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
int main()
{
	int n,i,j,t,m,a[10],b[10],q=1,w=1,e=1;
	cin>>n>>m;
	if(n==1&&m==0) {
		cout<<0;return 0;
	}
		if(n==2&&m==0) {
		cout<<10;return 0;
	}
	if(n==3&&m==0) {
		cout<<100;return 0;
	}
	for(i=1;i<=m;i++)
	{
		cin>>a[i]>>b[i];
		if(b[i]==0&&a[i]==1&&n>1) {
			cout<<-1;return 0;
		} 
		
	}
	for(j=1;j<=m;j++)
	{
		for(i=j+1;i<=m;i++)
		{
			if(i!=j&&a[j]==a[i]&&b[j]!=b[i]) {
				cout<<-1;return 0;
			} 
		}
	}
	for(i=1;i<=m;i++)
	if(n==1&&a[i]==1&&b[i]==0)
		{
			cout<<0;return 0;
		}
  if(n==3)
  {	for(i=1;i<=m;i++)
  		{
  			if(a[i]==1) {
				q=0;cout<<b[i]; break;
			}
		  }
		
		if(q) cout<<1;
			
for(i=1;i<=m;i++)
		{
			
			if(a[i]==2) {
				cout<<b[i];w=0;break;
			}
		}
		if(w) cout<<0;
for(i=1;i<=m;i++)
		{
			if(a[i]==3) {
				cout<<b[i];e=0;break;
			}
		}
	if(e) cout<<0;
  }
  else if(n==2)
  {
  		for(i=1;i<=m;i++)
		{
				if(a[i]==1) {
				q=0;cout<<b[i];break;
			}
		}
		
		if(q) cout<<1;
for(i=1;i<=m;i++)
		{
			if(a[i]==2) {
				cout<<b[i];w=0;break;
			}
		}
		if(w) cout<<0;

  }
   else if(n==1){
   	for(i=1;i<=m;i++)
		{
			if(a[i]==1) {
				q=0;cout<<b[i];break;
			}
		}
		if(q) cout<<1;
   }
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int base = (int) 1e9+7;
const int maxn = (int) 1e5 + 5;
#define x first
#define y second
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
int n, m;
pii a[maxn];
pip c[maxn];
bool fre[maxn];
bool mycmp1(pip u, pip v) {
	return u.y.x < v.y.x;
}
bool mycmp2(pip u, pip v) {
	return u.y.y < v.y.y;
}
int ABS(int x) { return x>0?x:-x;}
vector<int> ds[maxn];
int d[maxn];
int main() {
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i].x >> a[i].y;	
		c[i].x = i;
		c[i].y = a[i];
	}
	sort(c+1, c + 1 + n, mycmp1);
	for(int i = 2; i <= n; ++i) {
		int u = c[i].x, v = c[i-1].x;
		ds[u].push_back(v);
		ds[v].push_back(u);
	}
	sort(c+1, c + 1 + n, mycmp2);
	for(int i = 2; i <= n; ++i) {
		int u = c[i].x, v = c[i-1].x;
		ds[u].push_back(v);
		ds[v].push_back(u);
	}
	priority_queue< pii, vector<pii>, greater<pii> > q;
	q.push(pii(0, 1));
	for(int i = 1; i <= n; ++i) d[i] = base;
	d[1] = 0;
	while (!q.empty()) {
		pii p = q.top(); q.pop();
		int u = p.y, ts = p.x;
		fre[u] = 1;
		for(int i = 0; i < ds[u].size(); ++i) {
			int v = ds[u][i], ts1 = min(ABS(a[u].x-a[v].x), ABS(a[u].y-a[v].y));
			if (!fre[v] && d[v] > ts1) {
				d[v] = ts1;
				q.push(pii(ts1, v));
				//cout << v << " " << ts1 << endl;
			}
		}
	}
	long long ans = 0;
	for(int i = 1; i <= n; ++i) {
		ans += d[i];
		//cout << d[i] << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9336
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1
ans = 0
for k, v in dic.items():
    if k < v:
        ans += v - k
    elif v < k:
        ans += v

print(ans)


Measured memory_bytes: 18676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int , int>
#define fast ios_base::sync_with_stdio(0)
#define mx 100005
#define inf 100000000000000000LL
ll arr[mx], dp[mx];
int n, k;
ll solve(int pos)
{
    if(pos==n) return 0;
    ll&ret = dp[pos];
    if(dp[pos]!=-1) return ret;
    ret = inf;
    for(int i=1; i<=k; i++){
        int nxt = pos+i;
        if(nxt>n) break;
        ret = min(ret, llabs(arr[pos] - arr[nxt]) + solve(nxt));
    }
    return ret;
}
int main()
{
    //fast;
    while(scanf("%d%d",&n,&k)){
        for(int i=1; i<=n; i++)
            scanf("%lld",&arr[i]);
        memset(dp, -1, sizeof dp);
        printf("%lld\n", solve(1));
        return 0;
    }
}



Measured memory_bytes: 6528
a, b, c, x, y = map(int, input().split())

if a + b >= 2*c:
    price = 2 * c * min(x, y)
else:
    price = (a + b)*min(x, y)

if x > y:
    price += min(a, 2*c)*(x-y)
else:
    price += min(b, 2*c)*(y-x)

print(price)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(v) v.begin(),v.end()
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     return gcd(b,a%b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   ll n;
   cin>>n;
   ll ar[n];
   for(int i=0;i<n;i++)
    cin>>ar[i];
   sort(ar,ar+n);
   ll su=0;
   for(int i=0;i<n-1;i++)
    su+=ar[i];
   su-=ar[n-1];
   if(su>0)cout<<"Yes\n";
   else cout<<"No\n";
   return 0;

}


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

int n;

int isPrime(int a){
	if(a <= 1) return 0;
	if(a == 2) return 1;
	for(int i = 2; i * i <= a; i++){
		if(a % i == 0) return 0;
	}
	return 1;
}

int main(){
	while(cin >> n){
		int cnt = 0;
		for(int i = 1; i <= n; i++){
			if(isPrime(i) && isPrime(n - i + 1)) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=998244353;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    vector<pll>x(n);
    rep(i,n){
        ll a;cin>>a;
        a--;
        x[i]=mp(a,i+1);
    }
    sort(all(x));
    vector<ll>a(n*n);
    ll j=0;
    ll now=0;
    vector<ll>used(n+1);
    bool f=1;
    rep(i,n*n){
        if(x[now].first==i){
            if(used[x[now].second]<x[now].second-1)f=0;
            used[x[now].second]++;
            a[i]=x[now].second;
            now++;
            continue;
        }else{
            while(j<n&&used[x[j].second]>=x[j].second-1){
                j++;
            }
            if(j==n)continue;
            used[x[j].second]++;
            a[i]=x[j].second;
        }
    }
    now=0;
    j=0;
    rep(i,n*n){
        if(a[i])continue;
        while(used[x[j].second]==n){
            j++;
        }
        a[i]=x[j].second;
        used[a[i]]++;
    }
    rep(i,n+1)used[i]=0;
    rep(i,n*n){
        used[a[i]]++;
        if(x[now].first==i){
            if(used[a[i]]!=a[i])f=0;
            now++;
        }
    }
    if(!f){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    rep(i,n*n){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 5332
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int nax=5e5+1;
vector<int> cnt(nax);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   int n,q;
   cin>>n>>q;
   vector<int> a(n);
   for(int i=0;i<n;i++) cin>>a[i];
   vector<pair<pair<int,int>,int>> vec(q);
   for(int i=0;i<q;i++)
   {
       cin>> vec[i].first.first>>vec[i].first.second;
       vec[i].first.first--;
       vec[i].first.second--;
       vec[i].second=i;

   }
   int blk=sqrt(n);
   sort(vec.begin(),vec.end(),[&](pair<pair<int,int>,int> x,pair<pair<int,int>,int> y){
      
       if((x.first.first/blk)!=(y.first.first/blk)) return (x.first.first/blk)<(y.first.first/blk);
       else return x.first.second<y.first.second;
       
   });
   int l=0,r=-1;
   vector<int> an(q);
   int ans=0;
   auto add=[&](int id){
       cnt[a[id]]++;
       if(cnt[a[id]]==1) ans++;
   };

   auto sub=[&](int id){
       cnt[a[id]]--;
       if(cnt[a[id]]==0) ans--;
   };

   for(int i=0;i<q;i++)
   {
       while(r<vec[i].first.second)
       {
           r++;
           add(r);
       }
        while(l<vec[i].first.first)
       {
           
           sub(l);
           l++;

       }
       while(r>vec[i].first.second)
       {
           sub(r);
           r--;
       }
      
       while(l>vec[i].first.first)
       {
           l--;
           add(l);
           

       }
      //if(l==r) ans--;
      an[vec[i].second]=ans;
       //cout<<ans<<endl;

   }
   for(auto it : an) cout<<it<<"\n";;
}


Measured memory_bytes: 15524
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> gr[1919];
int x[1919];
string out="POSSIBLE";
pint dfs(int v){
	//cout<<v<<endl;
	if(gr[v].size()==0) return mp(x[v],0);
	
bool dp[2][5140];
	memset(dp,false,sizeof(dp));dp[0][0]=true;
	int sum=0,n=gr[v].size(),ma=-1;
	vector<pint> p;
	rep(i,n){
		pint P=dfs(gr[v][i]);
		sum+=P.fi+P.se;
		assert(sum<=5000*1000);
		//cout<<v<<' '<<gr[v][i]<<' '<<P.fi<<' '<<P.se<<endl;
		p.pb(P);
	}
	rep(j,n){
		int now=j%2,ne=1-now;
		memset(dp[ne],false,sizeof(dp[ne]));
		rep(i,x[v]+1){
			if(!dp[now][i]) continue;
			if(i+p[j].fi<=x[v]) dp[ne][i+p[j].fi]=true;
			if(i+p[j].se<=x[v]) dp[ne][i+p[j].se]=true;
		}
	}
	rep(i,x[v]+1){
		if(dp[n%2][i]) ma=i;
	}
	if(ma<0){
		out="IMPOSSIBLE";
		return mp(0,0);
	}
	//cout<<v<<' '<<x[v]<<' '<<sum-ma<<endl;
	return mp(x[v],sum-ma);
}
int main()
{
	int n,p;
	cin>>n;
	rep(i,n-1){
		cin>>p;p--;gr[p].pb(i+1);
	}
	rep(i,n) cin>>x[i];
	dfs(0);
	cout<<out<<endl;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,l,r;
  while(cin>>n>>l>>r,n+l+r){
    vi A(n);
    for(auto &a:A)cin>>a;
    ll ans=0;
    for(int i=l;i<=r;i++){
      bool fl=true;
      for(int j=0;j<n;j++){
	if(i%A[j] == 0){
	  fl = false;
	  if(j%2==0)ans++;
	  break;
	}
      }
      if(fl){
	if(n%2==0)
	  ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <iostream>
#include <set>
#include <vector>
#include <map>
using namespace std;

int main() {

  std::map<int, int> mp; 
  set<int> st;

  string com = "start";

  while (com != "end") {
    cin >> com;

    if (com == "insert") {
      int num;
      cin >> num;
      st.insert(num);
      mp[num] += 1;

    } else if (com == "extract") {
      auto itr = st.end();
      --itr;
      std::cout << *itr << "\n";
      mp[*itr] -= 1;
      if (mp[*itr] == 0) {
        auto c = st.erase(itr);
      }
    }
  }
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define bug(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long int ll;

int main(){
    ll h,w,s,s1,s2,s3,smax,smin,Ti=1e18;
    cin>>h>>w;
    s=h*w;
    if(s%3==0){
        cout<<0<<endl;
        return 0;
    }
    for(ll i=1;i<=w-1;i++){
        s1=i*h;
        s2=(h/2)*(w-i);
        s3=((h+1)/2)*(w-i);
        smax=max(s1,max(s2,s3));
        smin=min(s1,min(s2,s3));
        Ti=min(smax-smin,Ti);
    }
    for(ll i=1;i<=h-1;i++){
        s1=i*w;
        s2=(w/2)*(h-i);
        s3=((w+1)/2)*(h-i);
        smax=max(s1,max(s2,s3));
        smin=min(s1,min(s2,s3));
        Ti=min(smax-smin,Ti);
    }
    s1=(h/3+1)*w;
    s2=(h/3)*w;
    Ti=min(s1-s2,Ti);
    s1=h*(w/3+1);
    s2=h*(w/3);
    Ti=min(Ti,s1-s2);
    cout<<Ti<<endl;
	return 0;
}


Measured memory_bytes: 256
//fifer a tak luboin
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mp make_pair
#define pb push_back
#define s second
#define f first
#define endl "\n"

// using namespace __gnu_pbds;
using namespace std;
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

const ll inf = 1e14;
const double eps = 1e-10;                                     
const double pi = acos(-1.0);
const ll mod = 1000000007;
const int N = 100100;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    unordered_map <int, int> cnt;
    for (int i = 0; i < 3; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }

    for (auto it: cnt) {
        if (cnt[it.f] == 2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;  
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> field(H);
  for(int i=0; i<H; i++){
    cin >> field[i];
  }
  int ans = inf;
  for(int bit=0; bit<(1<<(H-1)); bit++){
    vector<int> ord(H,0);
    int cnt_H = 0;
    for(int i=0; i<H-1; i++){
      if(bit & (1<<i)){
        ord[i+1] = ord[i]+1;
        cnt_H++;
      }else{
        ord[i+1] = ord[i];
      }
    }
    bool can = true;
    int cnt_W = 0;
    vector<int> sum(cnt_H+1,0);
    for(int j=0; j<W; j++){
      bool ok = true;
      vector<int> one(cnt_H+1,0);
      for(int i=0; i<H; i++){
        one[ord[i]] += field[i][j] - '0';
        sum[ord[i]] += field[i][j] - '0';
        if(one[ord[i]] > K) can = false;
        if(sum[ord[i]] > K) ok = false;
      }
      if(!ok){
        cnt_W++;
        sum = one;
      }
    }
    if(can){
      chmin(ans,cnt_H+cnt_W);
    }
  }
  cout << ans << endl;
  return 0;
}

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

template <typename T>
class SegmentTree {
	const int n;
	const T id;
	function<T(T, T)> merge;
	vector<T> data;
public:
	SegmentTree(int n_, T id_, function<T(T, T)> merge_) :
		n(1 << (int)ceil(log2(n_))), id(id_), merge(merge_), data(n * 2, id) {}
	void Init(const vector<T>& data_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	void Update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int l, int r) {
		l += n; r += n + 1;
		T res1 = id, res2 = id;
		while (l < r) {
			if (l & 1) res1 = merge(res1, data[l++]);
			if (r & 1) res2 = merge(data[--r], res2);
			l >>= 1; r >>= 1;
		}
		return merge(res1, res2);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	int n, q, com, x, y;
	cin >> n >> q;
	SegmentTree<int> st(n, INT_MAX, [](int l, int r) { return min(l, r); });
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.Find(x, y));
		}
		else {
			st.Update(x, y);
		}
	}
	return 0;
}

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

bool comp(p a, p b) {
  return a.first > b.first;
}

int main(void) {
  ll N, M; cin >> N >> M;
  vector<p> A(N);
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    A.at(i) = make_pair(a, 1);
  }
  for (ll i = 0; i < M; i++) {
    ll B, C; cin >> B >> C;
    A.push_back(make_pair(C, B));
  }
  sort(A.begin(), A.end(), comp);

  ll a = 0;
  ll i = 0;
  while (N >= A.at(i).second) {
    a += A.at(i).first * A.at(i).second;
    N -= A.at(i).second;
    i++;
  }
  a += A.at(i).first * N;
  cout << a << endl;

  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int odd = 0;
    for (int i = 1; i <= n; ++i) {
        if (i%2 != 0) odd++;
    }
    double ans = (double)odd/n;
    printf("%.10f", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define inf 1e17
#define MAX_SIZE 1000005 

void pr(int arr[], int size) 
{ for (ll i=0; i < size; i++) {printf("%d ", arr[i]); }cout << endl;}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  ll n , a , b;
  cin >> n >> a >> b;
  ll x = b/n;
  ll y = a/n;
  if(x - y > 0){
      cout << "OK" << endl;
  }
  else{
     if(b%n == 0 || a%n == 0){
         cout << "OK";
     }
     else{
     cout << "NG" << endl;
     }
  }
  
    
  return 0;
}


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

ll a,b,c,n,m;
ll ans=100000000000;

string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin>>n;
  vector<int> v(n);
  rep(i,n-1){
    int t;
    cin>>t;
    v[t-1]++;
  }
  rep(i,n)cout<<v[i]<<endl;

  return 0;
}



Measured memory_bytes: 3964
from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]

tree = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(X):
    tree[a].append((b, i))
    tree[b].append((a, i))

color = [0] * (N - 1)
nodes = [set() for _ in range(N + 1)]
visited = [False] * (N + 1)

q = deque([1])
visited[1] = True
while q:
    u = q.popleft()
    c = 1
    for v, i in tree[u]:
        if visited[v]:
            continue

        while c in nodes[v] or c in nodes[u]:
            c += 1
        color[i] = c
        nodes[u].add(c)
        nodes[v].add(c)
        visited[v] = True
        q.append(v)

print(max(len(v) for v in tree))
print(*color, sep="\n")


Measured memory_bytes: 141180
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  string str = S;
  int count = 0;
  for (int i = 0; i < N - 2; i++){
    int j = i + 1;
    int k = j + 1;
        if(str.at(i) == 'A' && str.at(j) == 'B' && str.at(k) == 'C'){
          count ++;
        }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 636
#include<iostream>
#include<cstdio>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	int max = 1 << 31;
	int min = 1 << 30;
    long long	int sum = 0;
	int key = 0;
	for (int i = 0; i < n; i++) {
		cin >> key;
		sum += key;
		if (min > key) {
			min = key;
		}
		if (max < key) {
			max = key;
		}
	}
	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = Integer.parseInt(sc.next());
			int i, L = 0, R = 0;
			int[] a = new int[5001];
			if(n == 0) {
				break;
			}
			for(i = 0; i < n; i++) {
				a[i] = Integer.parseInt(sc.next());
			}
			L = R = a[0];
			for(i=1; i<n; i++){
				if( L >= R ) ; else L = R;
				if( R + a[i] < a[i] ) R = a[i]; else R = R + a[i];
			}
			if( L > R) {
				System.out.println(L);
			}else {
				System.out.println(R);
			}
		}
		sc.close();


	}

}



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

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	int L = Integer.parseInt(scan.next());
	String[] S = new String[N];
	for (int i = 0; i < N; i++) {
	    S[i] = scan.next();
	}

	Arrays.sort(S);
	for (int i = 0; i < N; i++) {
	    System.out.print(S[i]);
	}
	System.out.println();
	scan.close();
    }
}


Measured memory_bytes: 22100
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

constexpr int INF = 1000000000;/* 1e+9a */
constexpr int MODULO = 1000000007;

typedef int64_t ll;

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

ll div(ll k){
    ll i = 0;
    while(k % 2 == 0) {k /= 2; i++;}
    return i;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll sum = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        ll tmp;
        std::cin >> tmp;
        sum += div(tmp);
    }
    cout << sum << '\n';

}


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

int main(){
	ll x, y;
	cin >> x >> y;

	ll ans = 1e18;
	if (x < y) {
		ans = min(ans, y - x);
	}
	if (-x <= y) {
		ans = min(ans, y + x + 1);
	}
	if (x <= -y) {
		ans = min(ans, -y - x + 1);
	}
	if (-x <= -y) {
		ans = min(ans, -y + x + 2);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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;
}

ll M = 1000000007;

void solve()
{
	int n;
	cin>>n;
	//int mn=1e9+1;
	priority_queue<int>a;
	vector<int>b(n);
	rep(i,n){
		cin>>b[i];
	}
	sort(all(b),greater<int>());
	rep(i,n){
		if(!i){
			a.push(b[i]);
		}else{
			a.push(b[i]);
			a.push(b[i]);
		}
	}
	ll sum=0;
	rep(i,n-1){
		sum+=a.top();
		a.pop();

	}
	cout<<sum<<endl;
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 6112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        int index = -1;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) != '1') {
                index = i;
                break;
            }
        }
        if (index == -1) {
            System.out.println(1);
        } else {
            if (index > K - 1) {
                System.out.println(1);
            } else {
                System.out.println(String.valueOf(S.charAt(index)));
            }
        }
        sc.close();
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;

int main() {
  string num;
  cin >> num;
  char digit = num.back();

  if ( digit == '0' || digit == '1' || digit == '6' || digit == '8') {
    cout << "pon" << endl;
    return 0;
  }
  else if ( digit == '3' ) {
    cout << "bon" << endl;
    return 0;
  }
  else {
    cout << "hon" << endl;
    return 0;
  }
}

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


int main() {
    int N;
    cin >> N;
    if (N == 1 || N == 2 || N == 4) {
        cout << 4 << endl;
    }
    else {
        int i = 1;
        while(true) {
            if (N%2 == 1) {
                N = 3*N + 1;
            }
            else {
                N /= 2;
            }
            i++;
            if (N == 4) {
                cout << i + 3 << endl;
                break;
            }
        }
    }
    
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s;
	cin >> s;
	if(s[0]=='7' || s[1]=='7' || s[2]=='7') cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

mint choose(ll a,ll b)
{
    mint x=1,y=1;
    rep(i,b){
        x*=a-i;
        y*=i+1;
    }
    return x/y;
}
int main()
{
    ll x, y;
    cin >> x >> y;
    ll a, b;
    if ((2 * x - y) % 3 != 0)
    {
        cout << 0 << endl;
    }
  else if (2 * x - y < 0)
    {
        cout << 0 << endl;
    }
    else
    {
        b = (2 * x - y) / 3;
        a = x - 2 * b;
        a+= b;
        mint j;//初期化をしないといけない。
          j+=choose(a,b);
        cout <<j.x <<endl;
    }
}

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

int main() {
	int k;
	cin >> k;
	string s;
	cin >> s;
	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s.at(i);
		}
		cout << "..." << endl;
	}
}

Measured memory_bytes: 3628
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 100;

char s[Maxn + 5];
int K;
pair<int,int> t;

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%s %d", s + 1, &K);
	int len = strlen(s + 1);
	ll ans1 = 0, ans2 = 0;
	for(int i = 1; i <= len;) {
		int j = i;
		while(j < len && s[j + 1] == s[i])
			j++;
		if(i == 1 && j == len) {
			printf("%lld\n", 1LL * K * len / 2);
			return 0;
		}
		if(i == 1) t = make_pair(i, j);
		else if(j == len) {
			if(s[1] == s[len]) {
				if(((j - i + 1) & 1) && ((t.second - t.first + 1) & 1))
					ans2 = K - 1;
			}
		}
		ans1 += 1LL * (j - i + 1) / 2;
		i = j + 1;
	}
	ans1 *= K;
	printf("%lld\n", ans1 + ans2);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	        
		long x = sc.nextLong();
		
		long sum_500 = x/500;
		long sum_5 = (x%500)/5;	
		
		System.out.println(sum_500*1000+sum_5*5);
	}
}


Measured memory_bytes: 22996
import sys
s = input()

if s[0] != 'A':
    print("WA") 
    sys.exit()
if s[2:-1].count("C")!=1:
    print("WA")
    sys.exit()

# Aが頭にあってCは一つしかない
for i,c in enumerate(s):
    if i != 0 and i!=s[2:-1].index("C")+2:
        if ord(c) <= 90:
            print("WA")
            sys.exit()

print("AC")



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll ans=0;
    ll n;
    cin>>n;
    if(n==0 || n%2!=0)
    {
        cout<<0<<endl;
    }
    else
    {
        for (ll i = 10; i <= n; i*=5)
        {
            ans+=n/i;
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> P, Q, v, v2;
    for(int i = 0; i < N; i++){
        int t;
        cin >> t;
        P.push_back(t);
    }
    for(int i = 0; i < N; i++){
        int t;
        cin >> t;
        Q.push_back(t);
    }
    
    for(int i = 0; i < N; i++){
        v.push_back(i + 1);
        v2.push_back(i + 1);
    }
    int a = 1, b = 1;
    
    do{
        if(v == P) break;
        a++;
    }while(next_permutation(v.begin(), v.end()));
    
    do{
        if(v2 == Q) break;
        b++;
    }while(next_permutation(v2.begin(), v2.end()));

    cout << abs(a - b) << "\n";
    return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
   string s;
   cin >> s;
   map<char, int> m;
   for (char c: s) {
      m[c]++;
   }

   for (auto x : m) {
      if (x.second >= 3) {
         puts("Yes");
         return 0;
      } else {
         puts("No");
         return 0;
      }
   }

   return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0 for i in range(10000)]
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            w = (x+y+z)**2-z*x-z*y-x*y
            if w <= 10000:
                a[w-1] += 1
for i in range(n):
    print(a[i])

Measured memory_bytes: 9364
def main():
  import sys
  n=int(input())
  a=tuple(map(int,sys.stdin.readline().split()))
  b=[None]*n
  i=1
  for index in a:
    b[index-1]=i
    i+=1
  print(" ".join(map(str,b)))
if __name__=="__main__":
  main()

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

int N;
string S;

string solve() {
    REP (i, S.size()) S[i] = (S[i] - 'A' + N) % 26 + 'A';
    return S;
}

int main() {
    cin >> N >> S;
    cout << solve() << endl;
}

Measured memory_bytes: 256
n, x, y = gets.chomp.split(" ").map(&:to_i)
INF = 1000000001
x -= 1
y -= 1
ans = Array.new(n, 0)
 
def push(v, d)
  return if @arr[v] != INF
  @arr[v] = d
  @que.push(v)
end
 
(n).times do |i|
  @arr = Array.new(n, INF)
  @que = []
  push(i, 0)
  while !@que.empty? do
    v = @que.shift
    d = @arr[v]
    push(v-1, d+1) if v-1 >= 0 
    push(v+1, d+1) if v+1 < n
    push(y, d+1) if v == x 
    push(x, d+1) if v == y 
  end
  @arr.each  {|v| ans[v] += 1}
end
ans.map!{|i| i/2}
1.upto(n-1) {|i| puts ans[i]}

Measured memory_bytes: 26748
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	ll N;
	cin>>N;
	eFOR(i,1,3500){
		eFOR(j,1,3500){
			if(-N*(i+j)+4*i*j==0)continue;
			if(i*j*N%(-1*N*(i+j)+4*i*j)==0 && i*j*N/(-1*N*(i+j)+4*i*j)>0){
				cout<<i<<" "<<j<<" "<<i*j*N/(-1*N*(i+j)+4*i*j)<<endl;
				return 0;
			}
			//cout<<1/h + 1/i + 1/j<<endl;
			//if(4/N==1/h + 1/i + 1/j)
		}
	}
	
	return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

bool solve(int N, vi& a) {
    vi st(2,0);
    rep(i,N){
        st[a[i] % 2]++;
    }
    return !(st[1] % 2);
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << (solve(N,a) ? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050
ll dp[50][1<<20];
vector<ll> change(int x){
    vector <ll> v;
    int count=0;
    while(x){
        count++;
        if(x%2){v.pb(count);count=0;}
        x/=2;
    }
    return v;
}
int change2(vector<ll> v){
    ll now=1;
    ll ans=0;
    for(auto e:v){
        rep(i,e)now*=2;
        ans+=now/2;
    }
    return ans;
}
bool judge[N];
ll pw[50];
main(){
    ll n=in();
    ll x[3];
    rep(i,3)x[i]=in();
    int sum=x[0]+x[1]+x[2];
    swap(x[0],x[2]);
    vector<pair<vector<ll>,ll>> v;
    vector<ll> vvv;
    v.pb({vvv,1ll});
    ll ans=0;
    pw[0]=1;
    rep(i,20)pw[i+1]=pw[i]*2;
    dp[0][0]=1;
    vector<ll> tmp={2,3};
    rep(i,1<<sum){
        vector<ll> s=change(i);
        int state=0;
        int now[3]={};
        rep(kk,s.size()){
            if(state==3)break;
            if(now[state]+s[kk]<x[state])now[state]+=s[kk];
            else if(now[state]+s[kk]==x[state])state++;
            else {state=-1;break;}
        }
        judge[i]=(state==3?1:0);
    }
    rep(i,n){
        rep(k,1<<sum){
            if(dp[i][k]==0)continue;
            rep2(j,1,7){
                vector<ll> s(1,j);
                ll next=(k*pw[j]+pw[j-1])%pw[sum];
                if(!judge[next])
                dp[i+1][next]=(dp[i][k]+dp[i+1][next])%MOD;
            }
            dp[i+1][0]=(dp[i+1][0]+dp[i][k]*3)%MOD;
        }
    }
    ll p=1;
    rep(i,n){
        p=p*10ll%MOD;
    }
    rep(i,1<<sum){
        p=(p-dp[n][i]+MOD)%MOD;
    }
    cout<<p<<endl;
}


Measured memory_bytes: 149888
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <algorithm>

using namespace std;

int main() {
	int n,ans=0;
	cin >> n;
	vector<int> L(n);


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

	sort(L.begin(), L.end());
	
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
            
				if (L[i] + L[j] > L[k]){
                  ans++;
                }
				else{
                  break;
                }
			}
		}
	}
			
	cout << ans<< endl;

}



Measured memory_bytes: 256