akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll Mod = 1e9 + 7;
const int Maxn = 2e5 + 10;
const ll Inf = 1e17;

vector<pll> G[Maxn];
ll a[Maxn], par[Maxn];

ll get(ll u){
	if(par[u] == u) return u;
	return par[u] = get(par[u]);
}
ll ans = 0;
void merge(ll u, ll v, ll w){
	//cerr << u << " " << v << '\n';
	u = get(u); v = get(v);
	if(u == v) return ;
	ans += w;
	par[u] = v;
	//cerr << "?!?!? " << u << ' ' << v << ' ' << w << '\n';
}

pll mn[Maxn], mn2[Maxn];

void add(ll u, pll nw){
	//if(nw.S == 0) cerr << nw.F << " " << nw.S << " done!\n";
	
	if(nw.S == mn[u].S){
		mn[u].F = min(mn[u].F, nw.F);
		return ;
	}
	if(nw.S == mn2[u].S){
		mn2[u].F = min(mn2[u].F, nw.F);
		if(mn2[u] < mn[u]) swap(mn2[u], mn[u]);
		return ;
	}
	if(mn[u] > nw){
		mn2[u] = mn[u];
		mn[u] = nw;
	} else mn2[u] = min(mn2[u], nw);
}
pll plu(pll nw, ll x){
	return {nw.F + x, nw.S};
}

void DFS(ll u, ll p){
	ll adj, w;
	add(u, {a[u], par[u]});
	//cerr << "!!!! " << par[u] << '\n';
	for(auto e : G[u]){
		adj = e.F; w = e.S;
		if(adj == p) continue;
		DFS(adj, u);
		add(u, plu(mn[adj], w));
		add(u, plu(mn2[adj], w));
	}
}
pll res[Maxn];
void DFS2(ll u, ll p){
	ll adj, w;
	for(auto e : G[u]){
		adj = e.F; w = e.S;
		if(adj == p) continue;
		add(adj, plu(mn[u], w));
		add(adj, plu(mn2[u], w));
		DFS2(adj, u);
	}
	if(mn[u].S != par[u])
		res[par[u]] = min(res[par[u]], plu(mn[u], a[u]));
	if(mn2[u].S != par[u])
		res[par[u]] = min(res[par[u]], plu(mn2[u], a[u]));
}

vector< pair<ll, pll> > E;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	
	for(int i = 1; i <= n; i++) cin >> a[i];
	ll u, v, w;
	for(int i = 1; i < n; i++){
		cin >> u >> v >> w;
		G[u].pb({v, w});
		G[v].pb({u, w});
	}
	iota(par, par + Maxn, 0);
	for(int it = 0; it < 20; it++){
		
		for(int j = 1; j < Maxn; j++){
			par[j] = get(j);
			mn[j] = {Inf + Inf, j};
			mn2[j] = {Inf + Inf, j};
			res[j] = {Inf, j};
		}
		E.clear();
		
		DFS(1, -1);
		DFS2(1, -1);
		E.clear();
		for(int i = 1; i <= n; i++){
			if(get(i) == i){
				
				E.pb({res[i].F, {res[i].S, i}});
			}
		}
		sort(E.begin(), E.end());
		for(auto ed : E) merge(ed.S.F, ed.S.S, ed.F);	
	
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 48624
MOD = int(1e9 + 7)

def fact(n):
    ret = 1
    for i in range(n):
        ret = (ret * (i + 1)) % MOD
    return ret

N, M = map(int, input().split())

if N == M:
    ans = 2 * (fact(N) ** 2)
elif abs(N - M) == 1:
    ans = fact(N) * fact(M)
else:
    ans = 0
ans %= MOD

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX = 1e5;
const int MV = 1e5;
ll MA = -INF , MI = INF , ANS;

bool arr[120][15];
int p[120][120] , cnt[120];

void print( int msk )
{
	for(int i=9 ; i>=0 ; i--)
	{
		if( ( msk >> i ) & 1 )
			cout << 1;
		else
			cout << 0;
	}
	return;
}
int32_t main()
{
	IO;
	int n;
	cin >> n;

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

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

	for(int msk = 1 ; msk < 1024 ; msk++)
	{
		ANS = 0;
	//	cerr << msk << " || \n";
	//	print( msk );
	//	cerr << "\n";

		for(int i=0 ; i<n ; i++)
			cnt[i] = 0;

		for(int i=0 ; i<10 ; i++)
		{
			if( ( msk >> i ) & 1 )
			{
			//	cerr << i << ": ";
				for(int k=0 ; k<n ; k++)
				{
					if( arr[k][i] )
						cnt[k]++ ;//, cerr << k<<" ";
				}
				//cerr <<"\n";
			}
		}
//		cerr << "\n";

		for(int k=0 ; k<n ; k++)
			ANS += p[k][ cnt[k] ];
		
		MA = max( MA , ANS );
	}
	
	cout << MA << "\n";
	return 0;
}

Measured memory_bytes: 256
//not answered

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  
  vector<string> w(n);
  REP(i, n)
    cin >> w[i];
  
  map<string, int> wordmap;
  wordmap[w[0]]++;
  REP1(i, n){
    if(wordmap[w[i]] == 0 &&
       w[i-1][w[i-1].size()-1] == w[i][0])
      wordmap[w[i]]++;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            bool tmp = true;
            int a = X - 1;
            while (tmp)
            {
                a += 1;
                tmp = hantei(a);
            }
            Console.WriteLine(a);
        }

        static bool hantei(int x)
        {
            bool flag = false;
            for(int i = 2; i < x; i++)
            {
                if(x % i == 0)
                {
                    flag = true;
                    break;
                }
            }
            return flag;
        }
       
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */
/*
      static long func(long n)
      {
          long d = 0;
          for (long i = 0; i < 10; i++)
          {
              if (n / longPow(10, i) == 0)
              {
                  d = i;
                  break;
              }
          }
          long ret = A * n + B * d;
          return ret;
      }
      static long longPow(long a, long n)
      {
          long b = 1;
          for (long i = 0; i < n; i++) b = b * a;
          return b;
      }
      */


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

using namespace std;

int main() {
  int N,a,b,c;
  cin >> N;
  
  a=N/100; 
  b=(N-a*100)/10;
  c=(N-a*100-b*10);
  

  if (c == 2 || c==4 || c==5 || c==7 || c==9) {
    cout << "hon" << endl;
  }
  

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


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), [](char a, char b) { return a > b; });
    string ans = "No";
    if (s < t)
        ans = "Yes";
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll a[110][3], b[3];
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
    if (a[i][2] >= 1) {
      for (int j = 0; j < 3; j++) {
        b[j] = a[i][j];
      }
    }
  }
  ll cx, cy, h;
  for (ll i = 0; i <= 100; i++) {
    for (ll j = 0; j <= 100; j++) {
      bool flag = true;
      ll tmp1 = b[2] + llabs(b[0] - i) + llabs(b[1] - j);
      for (ll k = 0; k < n; k++) {
        ll tmp2 = tmp1 - llabs(a[k][0] - i) - llabs(a[k][1] - j);
        tmp2 = max(tmp2, 0LL);
        if (tmp2 != a[k][2]) {
          flag = false;
        }
      }
      if (flag) {
        cx = i;
        cy = j;
        h = tmp1;
      }
    }
  }
  cout << cx << " " << cy << " " << h << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class T> inline std::istream& operator >> (std::istream& is, std::vector<T>& v) { for (T& x : v) { is >> x; }return is; }
	template<class T> inline std::ostream& operator << (std::ostream& os, const std::vector<T>& v) {
		for (auto itr = v.begin(); itr != v.end();) { os << (*itr) << ((++itr != v.end()) ? " " : ""); }
		return os;
	}
	template<class V, typename T>inline void fill(V& v, const T& val) { v = val; }
	template<class V, typename T>inline void fill(std::vector<V>& v, const T& val) { for (V& x : v) { fill(x, val); } }
	template<class V, typename H>inline void resize(std::vector<V>& v, const H h) { v.resize(h); }
	template<class V, typename H, typename... T>inline void resize(std::vector<V>& v, const H& h, const T& ... t) { v.resize(h); for (auto& x : v) { resize(x, t...); } }
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }

	void solve() {
		IOS;
		int h1, m1, h2, m2, k;
		cin >> h1 >> m1 >> h2 >>  m2 >> k;
		int t1, t2;
		t1 = h1 * 60 + m1;
		t2 = h2 * 60 + m2;
		int res = t2 - t1 - k;
		put(res);
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}


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

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

    vector<ll> p(a);
    rep (i, a)
        cin >> p[i];

    vector<ll> q(b);
    rep (i, b)
        cin >> q[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());

    vector<ll> ans;
    rep (i, x)
        ans.push_back(p[i]);
    rep (i, y)
        ans.push_back(q[i]);
    rep (i, c)
    {
        ll r;
        cin >> r;
        ans.push_back(r);
    }

    sort(ans.begin(), ans.end(), greater<ll>());
    cout << accumulate(ans.begin(), ans.begin() + x + y, 0LL) << endl;
    return 0;
}

Measured memory_bytes: 9024
/*Lower_Rating*/
/*AGC 036 Roadwork*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;

#define LL long long
#define MAXN 200000
#define MAXM 800000
#define MAXK 17
#define MOD 998244353
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 2000000000
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int x,int y){return (x+y>=MOD)?x+y-MOD:x+y;}
int dec(int x,int y){return (x-y<0)?x-y+MOD:x-y;}
int mul(int x,int y){return 1LL*x*y%MOD;}

int n,m;
struct node{
    int s,t,x;
}p[MAXN+5];
priority_queue<Pr> Q;
bool cmp(node s1,node s2){
    return s1.s<s2.s;
}
int main()
{
    n=read(),m=read();
    for(int i=1;i<=n;i++){
        p[i]=(node){read(),read(),read()};
        p[i].s-=p[i].x,p[i].t-=p[i].x;
    }
    sort(p+1,p+n+1,cmp);
    int np=1;
    for(int i=1;i<=m;i++){
        int t=read();
        while(np<=n&&p[np].s<=t)
        Q.push(Pr(-p[np].x,np)),np++;
        while(!Q.empty()&&p[Q.top().Y].t<=t)
        Q.pop();
        if(Q.empty())printf("-1\n");
        else printf("%d\n",-Q.top().X);
    }
}


Measured memory_bytes: 5232
#include<iostream>
#include <string>
#include<vector>

using namespace std;

int main(){

	char a, b;
	cin >> a >> b;
	if( a == 'H'){
		cout << b << endl;
	}
	else{
		if( b == 'H'){
			cout << 'D' << endl;
		}
		else{
			cout << 'H'<< endl;
		}
	}

	return 0;

}

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

int main(){
	int n, m;	cin >> n >> m;
  	vector<int> s(m);
    vector<char> c(m); // 正しい
//	vector<int> c(m); // 間違い
  	for(int i = 0; i < m; i++){
    	cin >> s.at(i) >> c.at(i);
    	if(s.at(i) == 1 && c.at(i) == '0' && n != 1){ //正しい
//        if(s.at(i) == 1 && c.at(i) == '0' && n != 1){ // 間違い
        	cout << -1 << endl;
          	return 0;
        }
    }
  	
  	
  	for(int i = 0; i < m; i++){
    	for(int j = 0; j < m; j++){
        	if(i != j && s.at(i) == s.at(j) && c.at(i) != c.at(j)){
            	cout << -1 << endl;
              	return 0;
            }
        }
    }

	int nm = 0;
  	for(int i = 0; i <= 1000; i++){
    	string st = to_string(i);
      	bool fct = true;
      	if(st.size() == n){
      		for(int j = 0; j < m; j++){
  				if( c.at(j) != st.at(s.at(j)-1)) fct = false;
//          		cout << fct << endl;
        	}
        }
      	else fct = false;
      	
      	if(fct){nm = i;	break;}
   }
	  	cout << nm << endl;
}

// 間違いの理由
//文字列に変換して比較するところをint型の c と
//char型の i　を比較していた
//そのため、for文中のif文でずっと fct = false に
//なってしまったため、for文のサイクル終了まで
//nm に数字が代入されることがなかった


Measured memory_bytes: 256
from collections import deque
S= deque(input())
Q = int(input())
ba = 1
for i in range(Q):
    Query =list(map(str,input().split()))
    Query0 = Query[0]
    if Query[0] == '1':
        ba *= -1
    else:
        if Query[1] == '1' and ba ==1:
            S.appendleft(Query[2])
        elif Query[1] == '1' and ba ==-1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==-1:
            S.appendleft(Query[2])
if ba == -1:
    S.reverse()
mojieru = ''.join(S)
print(mojieru)

Measured memory_bytes: 14064
#include <bits/stdc++.h>
#define maxn 112345
#define inf 0x3f3f3f3f
using namespace std;

int n,k;
int h[maxn];
int d[maxn];
int main(){
	cin >> n >> k;

	for(int i = 0; i < n; ++i){
		scanf("%d",&h[i]);
	}

	for (int i = 0; i < n-2; ++i)
		d[i] = inf;

	d[n-1] = 0;
	d[n-2] = abs(h[n-1]-h[n-2]);
	for (int i = n-3; i >= 0; --i)
		for (int j = i+1; j <= i+k; ++j){		
			if(j>=n)
				break;
			d[i] = min(d[i],abs(h[i]-h[j])+d[j]);
		}	
	

	//for (int i = 0; i < n; ++i)
	//	cout << d[i] << " ";

	cout << d[0] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e11;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	map<int, int>m;
	rep(i, N) {
		int A;
		cin >> A;
		m[A]++;
	}
	int l1 = 0, l2 = 0;
	for (auto i : m) {
		if (i.second >= 4) {
			l1 = l2 = i.first;
		}
		else if (i.second >= 2) {
			if (l1 < l2)chmax(l1, i.first);
			else chmax(l2, i.first);
		}
	}
	int ans = l1 * l2;
	cout << ans << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int n;
int a[maxn];
map<int,int>m;
int ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	reverse(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		if(m[a[i]]>0) m[a[i]]--,ans++;
		else{
			int tmp=(1<<(32-__builtin_clz(a[i])));
		//	cout<<tmp<<endl;
			m[tmp-a[i]]++;
		} 
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 19712
def swap(A, i, j):
    temp = A[i]
    A[i] = A[j]
    A[j] = temp

def selection(A):
    N = len(A)
    count = 0
    for i in range(N):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if (min_j != i):
            swap(A, i, min_j)
            count += 1
    print(" ".join(map(str, A)))
    print(count)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    selection(A)



Measured memory_bytes: 5600
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		String s = in.next();
		int len = s.length(), n = len - 1;
		char[] buf = s.toCharArray();
		int[] a = new int[len];
		long ans = 0, tmp, sum;

		if (len == 1) {
			out.println(s);
			return ;
		}

		for (int i=0; i<len; ++i)
			a[i] = buf[i] - '0';

		int mst = 1<<n;

		for (int st=0; st<mst; ++st) {
			sum = 0;
			tmp = a[0];
			for (int j=0; j<n; ++j) {
				if ((st & (1<<j)) == 0) {
					// consecutive
					tmp = 10 * tmp + a[j+1];
				} else {
					// there is '+'
			//		out.print(tmp + "+");
					sum += tmp;
					tmp = a[j+1];
				}
			}
			sum += tmp;
			//out.println(tmp + " = " + sum);
			ans += sum;
		}

		out.println(ans);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

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

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

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


Measured memory_bytes: 21332
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	cin >> n;
	vvi mass(n, vi(n));
	REP(i, n)
		REP(j, n)
		cin >> mass[i][j];
	ll ans = 0;
	REP(i,n-1)
		FOR(j,i+1,n) {
		ans += min(mass[i][j], mass[j][i]);
	}
	cout << ans << endl;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

int x, y, z, k;
vector<ll>a(1000,0), b(1000,0), c(1000,0);
int main(){
	cin >> x >> y >> z >> k;
	rep(i,0,x)cin >> a[i];
	rep(i,0,y)cin >> b[i];
	rep(i,0,z)cin >> c[i];

	vector<ll>tmp;
	for(int i = 0; i < x; i++){
		for(int j = 0; j < y; j++){
			tmp.push_back(a[i]+b[j]);
		}
	}
	sort(rall(tmp));
	vector<ll>tmp2;
	for(int i = 0; i < min(k, (int)tmp.size()); i++){
		tmp2.push_back(tmp[i]);
	}
	vector<ll>ans;
	for(int i = 0; i < tmp2.size(); i++){
		for(int j = 0; j < z; j++){
			ans.push_back(tmp2[i]+c[j]);
		}
	}
	sort(rall(ans));
	for(int i = 0; i < k; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

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

string keta(int a){
  string s=to_string(a);
  int l=s.size();
  if(l == 1){
    return "00000"+s;
  }
  if(l == 2){
    return "0000"+s;
  }
  if(l == 3){
    return "000"+s;
  }
  if(l == 4){
    return "00"+s;
  }
  if(l == 5){
    return "0"+s;
  }
  if(l == 6){
    return s;
  }
}

int main(){
  int N,M;
  cin >>N>>M;
  map<long long int,int> Z;
  for(int i=0;i<M;i++){
    int a,b;
    cin >>a>>b;
    long long int d=a*10000000000+b;
    Z[d] = i;
  }
  vector<string> ans(M);
  int c=0;
  long long int u,uf,t;
  for(auto itr = Z.begin();itr != Z.end();itr++){
    c++;
    t=itr->first;
    u=t/10000000000;
    if(u != uf) c=1;
    ans.at(itr -> second) = keta(u)+keta(c);
    uf = u;
  }
  for(int i=0;i<M;i++){
    cout << ans.at(i)<<endl;
  }
}

Measured memory_bytes: 13184
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
for i in a:
    l[i]+=1

ans=0
for i in range(n+1):
    ans+=l[i]*(l[i]-1)//2

for i in a:
    print(ans-l[i]*(l[i]-1)//2+(l[i]-1)*(l[i]-2)//2)

Measured memory_bytes: 25716
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int ans = 0;
        if (x < a) {

        } else {
            ans = 10;
        }
        System.out.println(ans);
        sc.close();
    }
}


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

const int h_mv[4] = {0,  0, 1, -1};
const int w_mv[4] = {1, -1, 0,  0};

char s[52][52];

int main(void) {
  int H, W;
  cin >> H >> W;
  
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> s[i][j];
    }
  }
  
  for (int i = 1; i <= H; i++) {
    s[i][0] = s[i][W+1] = '.';
  }
  for (int j = 1; j <= W; j++) {
    s[0][j] = s[H+1][j] = '.';
  }

  bool ans = true;
  for (int i = 1; i <= H && ans; i++) {
    for (int j = 1; j <= W && ans; j++) {
      if (s[i][j]=='#') {
        bool next_black = false;
        for (int k = 0; k < 4; k++) {
          if (s[i+h_mv[k]][j+w_mv[k]]=='#') {
            next_black = true;
            break;
          }
        }
        if (!next_black) {
          ans = false;
        }
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main()
{
  ll N;
  scanf("%lld",&N);
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    scanf("%lld",&A[i]);
  }
  double sum = 0;
  for (int i=0; i<N; i++) {
    sum += 1.0/A[i];
  }
  printf("%.6f\n", 1.0/sum);

  return 0;
}


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

int main(){
    vector<bool> nonp(1000001, 0);
    for(int i = 2; i < 1000001; i++){
        if(nonp[i]) continue;
        for(int j = i+i; j < 1000001; j += i)   nonp[j] = true;
    }
    int a, b;
    while(cin >> a >> b, a+b){
        int x = 1<<30, y = 1<<30;
        for(int i = a; i >= 2; i--){
            if(a%i == 0 && !nonp[i]){
                if(x == 1<<30)  x = i;
                else            x -= i;
            }
        }
        for(int i = b; i >= 2; i--){
            if(b%i == 0 && !nonp[i]){
                if(y == 1<<30)  y = i;
                else            y -= i;
            }
        }
        cout << (x > y ? "a" : "b") << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
N = int(input())
A = [int(n) for n in input().split()]
cnt = 0
for i in range(N):
    min_x = A[i]
    exchange = "no"
    for j in range(i+1, N):
        if min_x > A[j]:
            min_x = A[j]
            index = j
            exchange = "ok"
    if exchange == "ok":
        A[index] = A[i]
        A[i] = min_x
        cnt += 1
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=" ")
print(cnt)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

struct UnionFind{
    vector<int> d;
    UnionFind(int n=0):d(n,-1){}
    int root(int x){
        if(d[x]<0)return x;
        return d[x]=root(d[x]);
    }
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x]+=d[y];
        d[y]=x;
        return true;
    }
    bool same(int x,int y){return root(x)==root(y);}
    int usize(int x){return -d[root(x)];}
};

int main(){
    ll n,m;cin >>n>>m;
    UnionFind uni(n);
    vector<ll>p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < m; ++i) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        uni.unite(x, y);
    }
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        if(uni.same(p[i],i))ans++;
    }
    cout <<ans <<endl;
    return 0;
}



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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0): x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }
  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};

Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }

const double DINF = 1e20;
int n;
Point ps[2][1010],tmp[1010];

inline double getDist(Point p){ return sqrt(p.x*p.x+p.y*p.y); }

bool comp_arg(const double &a,const double &b) { return !equals(fabs(a),fabs(b)) && fabs(a) < fabs(b); }

void compute(){
  Point grv[2] = {Point(),Point()};
  rep(i,2) rep(j,n) grv[i] = grv[i] + ps[i][j];
  rep(i,2) grv[i] = grv[i] / (double)n;
  rep(i,2) rep(j,n) ps[i][j] = ps[i][j] - grv[i];
  sort(ps[0],ps[0]+n);
  sort(ps[1],ps[1]+n);

  vector<double> arg_buf;
  rep(i,n) rep(j,n) {
    double dist[2] = { getDist(ps[0][i]), getDist(ps[1][j]) };
    if( !equals(dist[0],dist[1]) ) continue;
    double arg = atan2(ps[0][i].y,ps[0][i].x) - atan2(ps[1][j].y,ps[1][j].x);
    arg_buf.push_back(arg);
  }

  sort(arg_buf.begin(),arg_buf.end(),comp_arg);
  arg_buf.erase(unique(arg_buf.begin(),arg_buf.end()),arg_buf.end());

  rep(i,(int)arg_buf.size()){
    double arg = arg_buf[i];
    rep(j,n) tmp[j] = rotate(ps[1][j],arg);
    sort(tmp,tmp+n);
    bool failed = false;
    rep(j,n) if( !( tmp[j] == ps[0][j] ) ) { failed = true; break; }
    if( !failed ) { printf("%.11lf\n",fabs(arg)); break; }
  }

}

int main(){
  while( cin >> n, n ){
    rep(i,2) rep(j,n) cin >> ps[i][j].x >> ps[i][j].y;
    compute();
  }
  return 0;
}

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

long count(int N,long X);
vector<long> P,All;
long ans=0;
int main()
{
	int N,i;
	long X,ans;
	cin>>N>>X;
	P.push_back(1);
	All.push_back(1);
	for(i=1;i<=N;i++){
		All.push_back(2*All.at(i-1)+3);
		P.push_back(2*P.at(i-1)+1);
		//printf("%d %ld %ld\n",i,P.at(i),All.at(i));
	}
	ans=count(N,X);
	cout <<ans;
	return 0;
}

long count(int N,long X){
	//printf("\n%d %ld",N,X);
	if(N==0){
		return 1;
	}else if(X==1){
		return 0;
	}else if(X==((All.at(N)+1)/2)){
		return P.at(N-1)+1;
	}else if(X==All.at(N)){
		return 2*P.at(N-1)+1;
	}else if(X<((All.at(N)+1)/2)){
		return count(N-1,X-1);
	}else if(X>((All.at(N)+1)/2)){
		return (count(N-1,X-(All.at(N)+1)/2)+P.at(N-1)+1);
	}
}


Measured memory_bytes: 256
fn main(){
    let n = read_lineT::<usize>();
    let mut v = read_vec::<i32>();
    
    let q = partition(&mut v, 0, n - 1);
    
    for i in 0..n {
      if i != 0 { print!(" "); }
      if i == q { print!("["); }
      print!("{}", v[i]);
      if i == q { print!("]"); }
    }
    println!("");
}

fn read_lineT<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn partition(A: &mut Vec<i32>, p: usize, r: usize) -> usize {
    let x     = A[r];
    let mut i = p - 1;
    for j in p..r {
        if A[j] <= x {
          i = i + 1;
          let temp = A[i];
          A[i] = A[j];
          A[j] = temp;
        }
    }
    let temp = A[i + 1];
    A[i + 1] = A[r];
    A[r] = temp;
    i + 1
}


Measured memory_bytes: 5040
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

const int DAT_SIZE=(1<<18)-1;

int data[DAT_SIZE], datb[DAT_SIZE];

void add(int a, int b, int x, int k, int l, int r){
	if(a<=l && r<=b){
		data[k]+=x;
	}else if(l<b && a<r){
		datb[k]+=(min(b, r)-max(a, l))*x;
		add(a, b, x, k*2+1, l, (l+r)/2);
		add(a, b, x, k*2+2, (l+r)/2, r);
	}
}

int sum(int a, int b, int k, int l, int r){
	if(b<=l || r<=a){
		return 0;
	}else if(a<=l && r<=b){
		return data[k]*(r-l)+datb[k];
	}else{
		int res=(min(b, r)-max(a, l))*data[k];
		res+=sum(a, b, k*2+1, l, (l+r)/2);
		res+=sum(a, b, k*2+2, (l+r)/2, r);
		return res;
	}
}

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	printf("%d\n", n);
	multimap<int, int> dl;
	for(int i=0; i<n; i++){
		int r, l, d;
		scanf("%d %d", &l, &r);
		d=r-l;
		dl.insert(make_pair(d, l));
	}
	int d0=0, count=0;
	auto itr=dl.begin();
	for(int d=0; d<=m-2; d++){
		while(itr->first==d){
			int l=itr->second;
			add(l, l+d+1, 1, 0, 0, m+1);
			count++;
			itr++;
		}
		int k=m/(d+2);
		int s=sum(0, k*(d+2)+1, 0, 0, m+1);
		for(int i=1; i<=k; i++){
			s-=sum((i-1)*(d+2)+1, i*(d+2), 0, 0, m+1);
		}
		printf("%d\n", n-count+s);
	}
	return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <numeric>

constexpr int Mod = 1e9 + 7;

struct UnionFind {
	std::vector<int> parent;
	int size = 0;

	int root(int x) {
		return (parent[x] == x ? x : parent[x] = root(parent[x]));
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y)
			return;

		--size;
		parent[y] = x;
	}

	void reset(int n) {
		parent.resize(n);
		size = n;
		std::iota(parent.begin(), parent.end(), 0);
	}
};

int pow2[100001];

int main() {
	pow2[0] = 1;
	for (int i = 1; i < 100001; ++i)
		pow2[i] = (2 * pow2[i - 1]) % Mod;

	int n, m;
	UnionFind uf;
	while (true) {
		std::cin >> n >> m;
		if (n == 0 && m == 0)
			break;

		uf.reset(n);
		
		for (int i = 0; i < m; ++i) {
			int a, b;
			std::cin >> a >> b;
			--a, --b;

			uf.unite(a, b);
		}

		int ans = pow2[uf.size];
		if (uf.size != n)
			ans = (ans + 1) % Mod;

		std::cout << ans << std::endl;
	}
}


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

int main() {
    string str;
    while(cin >> str && str != "-") {
        int m, h;
        cin >> m;
        for(int i = 1; i <= m; i++) {
            cin >> h;
            str = str.substr(h) + str.substr(0, h);
        }
        cout << str << endl;
    }
    return 0;
}


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

long long knapSack(int W, long long wt[], long long val[], int n)
{
   int i, w;
   long long K[n+1][W+1];


   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }


   return K[n][W];
}
int main()
{
    int i,j,k,l,we,n;

    cin>>n>>we;
    long long v[n],wi[n];
    for(i=0;i<n;i++)
    {
        cin>>wi[i]>>v[i];
    }
   long long ans = knapSack(we,wi,v,n);
   cout<<ans<<endl;

}


Measured memory_bytes: 79104
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n, color[MAX];
vector<int> G[MAX];

void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	while(!S.empty()) {
		int u = S.top();
		S.pop();
		for(int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if(color[v] == NIL) {
			color[v] = c;
			S.push(v);
			}
		}
	}
}

void assignColor() {
	int id = 1;
	for(int i = 0; i < n; i++) color[i] = NIL;
	for(int u = 0; u < n; u++) {
		if(color[u] == NIL) dfs(u, ++id);
	}
}

int main() {
    int s, t, m,q;
	cin >> n >> m;
	
	for(int i = 0; i < m; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	
	assignColor();
    
	cin >> q;
	
	for(int i = 0; i < q; i++) {
		cin >> s >> t;
		if(color[s] == color[t]) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}	
	
	return 0;	
}

Measured memory_bytes: 8964
h, w = 100, 100
ans = [[0] * w for i in range(h)]
a, b = map(lambda x: int(x) - 1, input().split())
table = [['.' if i % 2 == 0 else '#' for i in range(w)] for j in range(h)]
for i in range(w):
    table[0][i] = '.'
    table[99][i] = '#'

for i in range(0, 98, 2):
    for j in reversed(range(1, 98, 2)):
        if a == 0:
            break
        table[j][i] = '#'
        a -= 1
    else:
        continue
    break

for i in reversed(range(1, 100, 2)):
    for j in range(2, 99, 2):
        if b == 0:
            break
        table[j][i] = '.'
        b -= 1
    else:
        continue
    break

print(h, w)
print('\n'.join([''.join(t) for t in table]))


Measured memory_bytes: 3316
n=int(input())
N=10**4+1
lst=[0]*N
s=0
for i in range(1,10**2+1):
    for j in range(1,10**2+1):
        for k in range(1,10**2+1):
            s=i**2+j**2+k**2+i*j+j*k+k*i
            if s<10**4+1:
                lst[s]+=1
for i in range(1,n+1):
    print(lst[i])



Measured memory_bytes: 9080
def main():
    h = int(input())
    w = int(input())
    n = int(input())
    if h <= w:
        high = w
    else:
        high = h
    for i in range(1, n+1):
        if high * i >= n:
            print(i)
            return


if __name__ == "__main__":
    main()



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
int H, W, c; cin >> H >> W;
string S[H+2], T[H]; S[0]=string(W+2,'.'); S[H+1]=string(W+2,'.');
for(int i=1; i<=H; i++){ cin >> S[i]; S[i]='.'+S[i]+'.'; }

for(int h=1; h<=H; h++){ for(int w=1; w<=W; w++){
if(S[h][w]=='.'){
   c=0;
   if(S[h-1][w-1]=='#'){ c++; }
   if(S[h-1][w]=='#'){ c++; }
   if(S[h-1][w+1]=='#'){ c++; }
   if(S[h][w-1]=='#'){ c++; }
   if(S[h][w+1]=='#'){ c++; }
   if(S[h+1][w-1]=='#'){ c++; }
   if(S[h+1][w]=='#'){ c++; }
   if(S[h+1][w+1]=='#'){ c++; }
   T[h-1]+=('0'+c);
}
else{T[h-1]+='#';}
} }

for(int i=0; i<H; i++){ cout << (T[i]+"\n"); }
}

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

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

  vector<int> number1(N);
  for(int i=0; i<N ; i++){
    cin >> number1.at(i);
  }
   vector<int> number2(N);
  for(int i=0; i<N ; i++){
    number2.at(i) = number1.at(i);
  }
  sort(number1.begin(),number1.end());
  reverse(number1.begin(),number1.end());
  
  for(int i=0; i<N ; i++){
    if(number2.at(i) == number1.at(0)){
      cout << number1.at(1) << endl;
    }
    else cout << number1.at(0) << endl;
  }
}

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

using namespace std;

const int N = 2e5 + 5;
int n, k, arr[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> k >> n;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }

    int fmin = 1e9 + 7;
    for(int i = 1; i <= n; i++){
        int ans;
        if(i == 1){
            ans = arr[n] - arr[i];
        } else {
            ans = arr[i - 1] + k - arr[i];
        }
        fmin = min(fmin, ans);
    }
    cout << fmin << '\n';
    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
  
  int flag=1;
  ll sum=0;
  int flag1=0;
  ll tot=0;
  int ans=0;
  map<int,int>mp;
  vi v;
  set<char>st;
  set<char>st2;
  set<char>st3;
  string s;
  sci(n);
  cin>>s;
  rep(i,0,n-1)
  {
    st3.insert(s[i]);
  }
   for(auto it=st3.begin();it!=st3.end();it++)
      {
       // cout<<*it<<endl;
      }
  int max=0;
  for(int i=0;i<n;i++)
  {
    st.clear();st2.clear();
    for(int j=0;j<=i;j++)
      {st.insert(s[j]);}
       for(int j=i+1;j<=n-1;j++)
      {st2.insert(s[j]);}
      int ans=0;
      for(auto it=st.begin();it!=st.end();it++)
      {
        
        if(st2.count(*it)>0) 
        {
          ans++;
        }
      }
      if(ans>max) max=ans;
      //cout<<st.size()<<" "<<st2.size()<<endl;
  }
  cout<<max;

  
    return 0;
}

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


int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<long,long>> A(N);
    for( int i = 0; i < N; ++i ){
        long a, b;
        cin >> a >> b;
        A[i] = make_pair( a, b );
    }


    long ans = 0;
    long num_drink = 0;
    sort( A.begin(), A.end() );
    for( int i = 0; i < N; ++i ){
        if( num_drink + A[i].second >= M ){
            ans += A[i].first * (M - num_drink);
            break;
        }else{
            num_drink += A[i].second;
            ans += A[i].first * A[i].second;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		rep(i,n)cin>>in[i];
		int co=0;
		rep(i,n)rep(j,n-i-1)if(in[j]>in[j+1]){
			co++;
			swap(in[j],in[j+1]);
		}
		cout<<co<<endl;
	}
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;



int main(void) {
	char b;
	cin >> b;
	if (b == 'A')cout << 'T' << endl;
	else if (b == 'T')cout << 'A' << endl;
	else if (b == 'C')cout << 'G' << endl;
	else cout << 'C' << endl;
}

Measured memory_bytes: 256
s=str(input())
n=len(s)

l_f=s[0:(n-1)//2]
l_e=s[((n+3)//2)-1:n]

def pala(s):
  pr=s[::-1]
  if s==pr:
    return True
  else:
    return False

if pala(s) and pala(l_f) and pala(l_e):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  long long K;
  cin >> S >> K;
  char ans='1';
  int a=S.size();
  if(K<a) a=K; 
  for(int i=0; i<a; i++){
//    cout << "i:"<<i<<" S[i]:"<<S[i]<<endl;
    if(S[i]!='1'){
      ans=S[i];
      break;
    }
  }
  cout << ans-'0' << endl;
}

Measured memory_bytes: 256
#include<iostream>

#include <string>

using namespace std;



int main(){

	int A, B, C, D;
	bool win= true;

	cin >> A>>B >>C >> D;
	
	while(A>0 && B>0){
		C-=B;
		if(C<=0){
			cout <<"Yes" <<"\n";
 		  	break;
		}
		A-=D;
		if(A<=0){
			cout <<"No" <<"\n";
			break;
		}
			
	}



}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>

using namespace std;

string s;int c,f;

int main()
{
    cin>>s;
    for(int i=0;i<s.size();i++)
        if(s[i]=='S')f++;
        else if(f>0){f--;c+=2;}
    cout<<s.size()-c<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll ans = INF;
  for (int i = -100; i <= 100; i++) {
    ll cost = 0;
    for (int j = 0; j < N; j++) {
      cost += (a[j] - i) * (a[j] - i);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

using namespace std;

int main() {
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  int over = 0;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'c') {
      cout << "No" << endl;
    }
    if(s[i] == 'a') {
      if(cnt < a + b) {
        cnt++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
    if(s[i] == 'b') {
      if(cnt < a + b && over < b) {
        over++; cnt++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#define rep(i, n) for(int i;i<n;i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main(void){
    int n;
    cin>>n;
    int p[n];
    rep(i, n){
        cin>>p[i];
    }
    int cnt=0;
    rep(i,n){
        if (p[i]!=i+1){
            cnt++;
        }
    }
    if (cnt<=2){
        cout<<"YES"<<endl;
    }
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
// ABC081A - 

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	string S;
	cin >> S;

	int ans = 0;

	for (int i = 0; i < 3; i++) {
		if (S[i] == '1') {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};


int main() {
    string s,t; cin >> s >> t;
    int ss = sz(s);
    int ts = sz(t);
    int cnt = 10000;
    rep(i,ss-ts+1) {
        int tmp = 0;
        rep(j,ts) {
            if (s[i+j] != t[j]) {
                tmp++;
            }
        }
        chmin(cnt,tmp);
    }
    cout << cnt << endl;
}    

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

int main() {
  ll n,k;
  cin>>n>>k;
  ll p = n%k;
  ll q = k-p;
  ll ans  =  min(p,q);
  cout << ans << endl;
}



Measured memory_bytes: 256
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);

    if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29660
#include<iostream>
#include<math.h>
using namespace std;
class Xcubic{
public:
  int cal(int x){
    int res=(int)pow(x,3);
    return res;
  }
};
int main(){
  int x;
  cin>>x;
  Xcubic xcubic;
  cout<<xcubic.cal(x)<<endl;
  return 0;
}

Measured memory_bytes: 1200
S=input()
A=[chr(ord('a') + i) for i in range(26)]
if S=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  if len(S)<26:
    for i in A:
      if str(i) not in S:
        print(S+str(i))
        exit()
  else:
    for i in range(24,-1,-1):
      for j in range(25,i,-1):
        if S[i] < S[j]:
          print(S[:i]+S[j])
          exit()

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

signed main(){
  int N; cin >> N;
  vector<int> vec;
  int sum = 0, i = 1;
  while(sum <= N){
    vec.push_back(i);
    sum += i;
    i++;
  }
  for(int i = 0; i < vec.size(); i++){
    if(vec[i] != sum - N) cout << vec[i] << endl;
  }
}

Measured memory_bytes: 384