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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

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

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b, d;
	ll c;
	//char c;
	ll h, w;
	ll k;
	string s, t;
	//ll s, t;
	ll l_ans = 0;
	string s_ans = "NG";

	cin >> x;
	
	if (x == 0) l_ans = 1;
	else l_ans = 0;

	cout << l_ans << "\n";

	return;
}


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

	solve_abc_a();

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define fast            ios_base::sync_with_stdio(false)
#define mems(x, y)      memset(x, y, sizeof x)
#define pii             pair < int, int >
#define prec(x)         << fixed << setprecision(x)
#define itf             it->first
#define its             it->second
#define it(x)           it = x.begin(); it != x.end(); it++
#define pq_max(x)       priority_queue < x >
#define pq_min(x)       priority_queue < x, vector < x >, greater < x > >
#define ll              long long
#define nl              << "\n"
#define spc             << " "
#define pb              push_back
#define inf             0x3f3f3f3f
#define PI              3.14159265358979323846
#define E               2.71828182845904523536
#define gamma           0.5772156649
#define EPS             1e-9
#define toint(st, x)    stringstream ss(st); ss >> x
// =======Debug========//
#define watch(x)        cout << (#x) spc << x nl
//int fx[] = {1, -1, 0, 0};
//int fy[] = {0, 0, 1, -1};
const int mod=1e9+7;
const int mxn=1e5+9;
int n, w;
int weight[mxn];
ll value[mxn];
ll dp[105][mxn];
bool vis[105][mxn];
ll func(int i, ll ww)
{
    if(i >= n)          return 0;
    if(vis[i][ww])      return dp[i][ww];
    vis[i][ww] = 1;
    ll t1 = 0, t2 = 0;
    if(ww + weight[i] <= w)      t1 = value[i] + func(i + 1, ww + weight[i]);
    t2 = func(i + 1, ww);

    return dp[i][ww] = max(t1, t2);
}
int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    cin >> n >> w;
    for(int i = 0; i < n; i++)      cin >> weight[i] >> value[i];
    ll ans = func(0, 0);
    cout << ans nl;
    return 0;
}


Measured memory_bytes: 89856
N = int(input())
a = [int(i) for i in input().split()]

from operator import mul
from functools import reduce

even_list = list(filter(lambda x:x%2==0, a))

if len(even_list) == 0:
    print(0)
else:

    count = 0

    for m in even_list:
    
        while True:
            m = m / 2
            count += 1
    
            if m % 2 == 1:
                break

    print(count)



Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
#define vvatagashi_is cin
signed main(){
    // beautiful code starts here....
    //written by "the god of coder",who is vvataarne
    int vvataarne_is_redcoder_as_known_as_tourist;
    cin >> vvataarne_is_redcoder_as_known_as_tourist;
    vector<int>vvataarne_house(vvataarne_is_redcoder_as_known_as_tourist);
    for(auto &pro:vvataarne_house){
        vvatagashi_is >> pro;
    }
    int Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything = 0;
    for(auto &vvatagashi : vvataarne_house){
        while(vvatagashi%2 == 0){
            Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything++;
            vvatagashi /=2;
        }
    }
    cout <<Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];
  ll ans = 0;
  for(int i = 1; i < n ;++i){
    ll walk = (x[i] - x[i - 1]) * a;
    ans += min(walk, b);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>p;
struct edge { int to, cost; };

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
bool f = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";

int main() {
	int n, a, b, c;
	std::string s, t;
	std::cin >> a;
	std::cout << a / 3 << std::endl;
	}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for n in range(N):
    if A[n]>=B[n]:
        ans += B[n]
    elif A[n+1]>=B[n]-A[n]:
        ans += B[n]
        A[n+1] -= B[n] - A[n]
    else:
        ans += A[n] + A[n+1]
        A[n+1] = 0
        
print(ans)

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

int main(void) {
    int n, a[100], ans = INT_MAX;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = -100; i <= 100; i++) {
        int cost = 0;
        for (int j = 0; j < n; j++) cost += (a[j] - i) * (a[j] - i);
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


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

typedef long long ll;

string s;
int n;
ll ans=0;

void rec(int v,ll sum,ll c){
  if(v==n-1){
    ll d=c*10+(s[v]-'0');
    ans+=sum+d;
  }
  else {
    ll d=c*10+(s[v]-'0');
    rec(v+1,sum,d);
    rec(v+1,sum+d,0);
  }
}

int main()
{
  cin>>s;
  n=s.length();

  rec(0,0,0);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = []
for i in range(N):
    s = list(input().strip())
    s_list = [int(k) for k in s]
    S.append(s_list)

count_max = 0
for i in range(N):
    flag = [-1]*N
    q = deque([i])
    flag[i] = 0
    count = 0
    while(q):
        count += 1
        for k in range(len(q)):
            v = q.popleft()
            for j in range(len(S[v])):
                if S[v][j] == 1 and flag[j] == -1:
                    flag[j] = count
                    q.append(j)
                elif S[v][j] == 1:
                    if flag[j]%2 != count%2:
                        print(-1)
                        sys.exit()
    count_max = max(count, count_max)
print(count_max)
        


Measured memory_bytes: 43356
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

int n, all;
vector<int> a;
vector<int> v;
vector<int> ps;

void init() {
	ps.resize(v.size() + 1);
	for (int i = 0; i < (int)v.size(); i++) {
		ps[i + 1] = ps[i] + v[i];
	}
}

int sm(int l, int r) {
	r++;
	if (l >= r) return 0;
	return ps[r] - ps[l];
}

int proc(int l, int r, int dir) {
	//0-l
	//1-r
	int c = (r - l);
	int t = n - c;
	if (t == 0) return 0;
	int ans = 0;
	if (!dir) {
		dir ^= (t % 2);
		int rl = (l - (t + 1) / 2);
		int rr = (r + t / 2);
		ans = sm(rl, l - 1) + sm(r + 1, rr);
		ans *= 2;
		if (!dir) ans -= v[rr];
		else ans -= v[rl];
		ans += v[r];
	} else {
		dir ^= (t % 2);
		int rl = (l - t / 2);
		int rr = (r + (t + 1) / 2);
		ans = sm(rl, l - 1) + sm(r + 1, rr);
		ans *= 2;
		if (!dir) ans -= v[rr];
		else ans -= v[rl];
		ans += v[l];
	}
	return ans;
}

int sr() {
	int l = n;
	int r = n;
	int c = 0;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		c = v[i + n];
		ans = max(ans, c + proc(l, r, 0));
		r++;
	}
	return ans;
}

int sl() {
	int l = n;
	int r = n;
	int c = 0;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		c = v[n - i];
		ans = max(ans, c + proc(l, r, 1));
		l--;
	}
	return ans; 
}


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

	cin >> all >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		v.push_back(all - a[i]);
	}    
	a.push_back(0);
	v.push_back(0);
	for (int i = 0; i < n; i++) {
		a.push_back(a[i]);
		v.push_back(a[i]);
	}
	init();
	cout << max(sl(), sr()) << endl;
}


Measured memory_bytes: 11728
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int n;

	cin >> n;

	cout << n / 3 << endl;












	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


bool dfs(vector<vector<char> > v,int i,int j,int h,int w){
	if(j-1>=0&&v[i][j-1]=='#')return true;
	else if(i+1<h&&v[i+1][j]=='#')return true;
	else if(i-1>=0&&v[i-1][j]=='#')return true;
	else if(j+1<w&&v[i][j+1]=='#')return true;
	else {
//		cout<<i<<" "<<j<<" "<<v[i][j-1]<<" "<<v[i-1][j]<<" "<<v[i][j+1]<<endl;
		return false;
	}
}

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int h,w,i,j;
	string s;
	char c;
	bool ch=true,sh=false;;
	cin>>h>>w;
	vector<vector<char> > v(h,vector<char>());
	for(i=0;i<h;i++){
		cin>>s;
		for(j=0;j<w;j++){
			v[i].push_back(s[j]);
		}
	}
//	for(i=0;i<h;i++){
//		for(j=0;j<w;j++){
//			cout<<v[i][j];
//		}
//		cout<<endl;
//	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(v[i][j]=='#'){
				if(!dfs(v,i,j,h,w))ch=false;
			}
		}
	}
	if(ch)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
num = tuple(num)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
  
lcd = dict()
for i in num:
  j = factorization(i)
  for x,y in j:
    if not x in lcd.keys():
      lcd[x] = y
    else:
      lcd[x] = max(lcd[x],y)

lc = 1
for i,j in lcd.items():
  lc *= pow(i,j,mod)
  
ans =0
for i in range(n):
  ans += lc*pow(num[i], mod-2, mod)
  ans %= mod
print(ans)

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

using namespace std;

typedef long long ll;

const int MAXN = 105;
const int MAXW = 1e5 + 5;

int n, W;
int w[MAXN], v[MAXN];
ll dp[MAXN][MAXW];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> W;
  for (int i = 0; i < n; ++i) {
    cin >> w[i] >> v[i];
  }
  for (int i = w[0]; i < MAXW; ++i) {
    dp[0][i] = v[0];
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < MAXW; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (j - w[i] >= 0) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
      }
    }
  }
  cout << dp[n - 1][W] << endl;
  return 0;
}



Measured memory_bytes: 81696
#include<bits/stdc++.h>
#define register rg
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
typedef long long ll;
char a[1000001];
int main() {
	cin>>a;
	int c=0,ans=0,ans1=0;
	for(int i=0; i<strlen(a); i++) {
		if(a[i]-'0'!=c)
			ans++;
		c^=1;
	}
	c=1;
	for(int i=0; i<strlen(a); i++) {
		if(a[i]-'0'!=c)
			ans1++;
		c^=1;
	}
	printf("%lld\n",min(ans1,ans));
	//file("a");
	return 0;
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    string S, T;
    cin >> S >> T;
    bool x = false;
    int y = S.size();
    for (int i = 0; i < y; i++)
    {
        bool z = true;
        for (int j = 0; j < y; j++)
        {
            if (S[(i + j) % y] != T[j])
                z = false;
        }
        if(z)
            x = true;
    }
    cout << (x ? "Yes" : "No");
}

Measured memory_bytes: 256
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    ls = [0] * (n + 1)
    tm = 0
    for i, v in enumerate(a):
        ls[i + 1] = (((1 + v) * v) // 2) / v
    ls = list(itertools.accumulate(ls))
    for i in range(k, n + 1):
        tm = max(tm, ls[i] - ls[i-k])
    print(tm)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 74952
N = int(input())
p = list(map(int,input().split()))

sw = []
for i in range(N-1):
  if p[i]>p[i+1]:
    sw.append(i)

if len(sw)==0:
  print('YES')
  
if len(sw)==1:
  if (sw[0]>0 and p[sw[0]-1]>p[sw[0]+1]) or (sw[0]<N-2 and p[sw[0]]>p[sw[0]+2]):
    print('NO')
  else:
    print('YES')
if len(sw)==2:
  if (sw[0]>0 and p[sw[0]-1]>p[sw[1]+1]) or (sw[1]<N-2 and p[sw[0]]>p[sw[1]+2]):
    print('NO')
  else:
    print('YES')
if len(sw)>2:
  print('NO')
  


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
    long int R, D, x[11];
    int i;

    scanf("%ld %ld %ld", &R, &D, &x[0]);

    for(i=0; i<10; i++){
        x[i+1] = R*x[i] - D;
        printf("%ld\n", x[i+1]);
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int n,w;
vector< vector<int> > dp(101, vector<int>(10001,-1) );
vector<pair<int,int> > c(0);

int search(int i,int j){
  if( dp[i][j]> -1 ) return dp[i][j];
  int ans;
  if(i==n){
    ans=0;
  }
  else if( c[i].second > j ){
    ans = search(i+1,j);
  }
  else{
    ans = max(search(i+1,j) , search(i+1,j-c[i].second)+c[i].first );
  }
  dp[i][j]=ans;
  return ans;
}

int main(void){

  cin>>n;
  cin>>w;

  for(int i=0;i<n;i++){
    int x,y;
    cin>>x;
    cin>>y;
    c.push_back(make_pair(x,y));
  }

  cout << search(0,w) << endl;


  return 0;
}



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

int main(){
  long a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  if((abs(w-v))*t >= abs(b-a) && v>w)cout << "YES" << endl;
  else cout << "NO\n";
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    string a, b;
    cin >> a >> b;
    vector<int> c(1), d(1);
    for(int i = 0; i < a.size(); i++){
        c.push_back((a[i] == 'A'? 1:2));
    }
    for(int i = 0; i < b.size(); i++){
        d.push_back((b[i] == 'A'? 1:2));
    }
    partial_sum(begin(c), end(c), begin(c));
    partial_sum(begin(d), end(d), begin(d));
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int w, x, y, z;
        cin >> w >> x >> y >> z;
        int p1 = (c[x] - c[w - 1]) % 3;
        int p2 = (d[z] - d[y - 1]) % 3;
        cout << (p1 == p2? "YES":"NO") << endl;
    }
    return 0;
}


Measured memory_bytes: 1788
def leap? year
    result = false
    result = true if year % 4 == 0
    result = false if year % 100 == 0
    result = true if year % 400 == 0
    return result
end

def days year, month, day
    n_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    sum = 0
    1.upto(year-1){|y| sum += (leap? y) ? 366 : 365}
    1.upto(month-1){|m|
        sum += n_days[m-1]
        sum += 1 if leap?(year) && m == 2
    }
    1.upto(day){|d| sum += 1}
    return sum
end

while true
    y1,m1,d1,y2,m2,d2 = gets.chomp.split.map(&:to_i)
    break if [y1,m1,d1,y2,m2,d2].any?{|x| x < 0}
    puts days(y2, m2, d2) - days(y1, m1, d1)
end


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

int main()
{
    string S;
    cin >> S;
    string vals[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

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

            if(S == vals[i]) {
                printf("%d", 7-i);
            }
        }
        return 0;
    }





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
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;
}
long long dp[200010];
  
int main()
{
  int N;
  cin >> N;
  vector<int> vecsix;
  vector<int> vecnine;
  int x = 6;
  while(x<=N){
    vecsix.push_back(x);
    x*=6;
  }
  int y = 9;
  while(y<=N){
    vecnine.push_back(y);
    y*=9;
  }

  REP(i,100010){
    dp[i]=INF;
  }
  dp[0]=0;
  dp[1]=1;
  REP(i,N){
    for(auto p:vecsix){
      chmin(dp[i+p],dp[i]+1);
    }
    for(auto p:vecnine){
      chmin(dp[i+p],dp[i]+1);
    }
    chmin(dp[i+1],dp[i]+1);
  }

  cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int ia, ib, ps;

void read(void)
{
    scanf("%d %d", &ia, &ib);
}

void exec(void)
{
    ps = (ia > 0) ? 1 : ((ib < 0) ? 2 * ((ib - ia) % 2) - 1 : 0);
}

void print(void)
{
    printf("%s\n", ps < 0 ? "Negative" : (ps > 0 ? "Positive" : "Zero"));
}

void repl(void)
{
    read();
    exec();
    print();
}

int main(void)
{
    repl();
    return 0;
}


Measured memory_bytes: 128
S = [i for i in input()]
T = [i for i in input()]
size_s = len(S)
size_t = len(T)
kouho = []
if size_t > size_s :
    print("UNRESTORABLE")
else :
    for i in range(size_s-size_t+1):
        p = [i for i in S]
        for j in range(size_t):
            if S[i+j] == T[j] or S[i+j] == "?" :
                continue   
            else :
                break 
        else :
            for j in range(size_s):
                if S[j] == "?" :
                    p[j] = "a"
            for j in range(size_t):
                p[i+j] = T[j]
            kouho.append("".join(p))

    if len(kouho) == 0 :
        print("UNRESTORABLE")
    else:
        kouho.sort()
        print(kouho[0],end = " ")


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

int main(void){

    int n, m;
    cin >> n >> m;
    vector<vector<int>> data(m);
    for(int i=0; i<m; i++) {
        int k;
        cin >> k;
        vector<int> temp(k);
        for(int j=0; j<k; j++) cin >> temp[j];
        data[i] = temp;
    }
    
    vector<int> p(m);
    for(int i=0; i<m; i++) {
        cin >> p[i];
    }
    
    int result = 0;
    for(unsigned int i=0; i<(1<<n); i++) {
        bool isOK = true;
        for(int j=0; j<m; j++) {
            int count = 0;
            for(int k=0; k<data[j].size(); k++) {
                if((i>>(data[j][k]-1)&0x01) == 0x01) {
                    count++;
                }
            }
            if(count%2!=p[j]) {
                isOK = false;
            }
        }
        if(isOK) result++;
    }
    
    cout << result << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N, Y;
  cin >> N >> Y;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      int k = N - i - j;
      if (i * 10000 + j * 5000 + k * 1000 == Y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;

  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

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


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_A = 11;
const int MAX_N = 2e2 + 10;

int A, B, Nr[MAX_A][MAX_A];


const int ITER = 100;
int N = 2*ITER + 2;
vector<pi> Ed[MAX_N];
int Ans[ITER+1][ITER+1];
int main() {
	cin >> A >> B;
	for(int i=1; i<=A; i++) for(int j=1; j<=B; j++) scanf("%d", &Nr[i][j]);
	for(int i=1; i<=ITER; i++) Ed[i].emplace_back(i+1, 'X'+1000);
	for(int i=ITER+2; i<N; i++) Ed[i].emplace_back(i+1, 'Y'+1000);
	
	for(int i=0; i<=ITER; i++) for(int j=0; j<=ITER; j++) {
		int val = 0;
		for(int a=1; a<=A; a++) for(int b=1; b<=B; b++)
			val = max(Nr[a][b] - a*i - b*j, val);
		Ans[i][j] = val;
		//printf("%d %d : %d\n", i, j, val);
		if(val >= 0 && val <= 100)
			Ed[i+1].emplace_back(N-j, val);
	}

	for(int a=1; a<=A; a++) for(int b=1; b<=B; b++) {
		int now = INF;
		for(int i=0; i<=ITER; i++) for(int j=0; j<=ITER; j++) {
			int val = Ans[i][j]; 
			if(val >= 0 && val <= 100) now = min(now, val + a*i + b*j);
		}
		if(now != Nr[a][b]) return puts("Impossible") < 0;
	}
	puts("Possible");
	int M = 0; 
	for(int i=1; i<=N; i++) M += SZ(Ed[i]);
	printf("%d %d\n", N, M);
	for(int v=1; v<=N; v++) {
		for(auto &val : Ed[v]) {
			int w, c; tie(w, c) = val;
			if(c >= 1000) printf("%d %d %c\n", v, w, c - 1000);
			else printf("%d %d %d\n", v, w, c);
		}
	}
	printf("%d %d\n", 1, N);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int a, b;
    cin >> a >> b;
    string U; cin >> U;
    if(S == U) a--;
    else b--;
    cout << a << " " << b << endl;

    return 0;
}


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


#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;


const int MAX = 1000000;
  
int block;
  
struct Query {
    int L, R, index, result;
};
  
bool compare(Query x, Query y) {
    if (x.L / block != y.L / block)
        return x.L / block < y.L / block;
  
    return x.R < y.R;
}
  
bool compare1(Query x, Query y) {
    return x.index < y.index;
}
  
void queryResults(int a[], int n, Query q[], int m) {
    block = (int)sqrt(n);
  
    sort(q, q + m, compare);
  
    int currL = 0, currR = 0;
    int curr_Diff_elements = 0;
  
    int freq[MAX] = { 0 };
  
    for (int i = 0; i < m; i++) {
          
        int L = q[i].L, R = q[i].R;
  
        while (currL < L) {
              
            freq[a[currL]]--;
            if (freq[a[currL]] == 0)
                curr_Diff_elements--;
              
            currL++;
        }
  
        while (currL > L) {
            freq[a[currL - 1]]++;
  
            if (freq[a[currL - 1]] == 1)
                curr_Diff_elements++;
              
            currL--;
        }
        while (currR <= R) {
            freq[a[currR]]++;
  
            if (freq[a[currR]] == 1)
                curr_Diff_elements++;
              
            currR++;
        }
  
        while (currR > R + 1) {
  
            freq[a[currR - 1]]--;
  
            if (freq[a[currR - 1]] == 0)
                curr_Diff_elements--;
              
            currR--;
        }
        q[i].result = curr_Diff_elements;
    }
}
  
void printResults(Query q[], int m) {
    sort(q, q + m, compare1);
    for (int i = 0; i < m; i++) {
        cout << q[i].result << endl;
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    int colors[n];
    Query queries[q];
    for (int i=0; i<n; i++) {
        cin >> colors[i];
    }
    
    for (int i=0; i<q; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        Query &query=queries[i];
        query.L=l;
        query.R=r;
        query.index=i;
    }
    
    queryResults(colors, n, queries, q);
    printResults(queries, q);
}

int main() {
    FAST_INPUT;
    
    solve();
    
    return 0;
}


Measured memory_bytes: 17432
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
// xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,いくつ)
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
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 (b<a) { a=b; return 1; } return 0; }

int main(){
  int n,k; cin >> n >> k;
  vi cnt(n);
  set<int> st;
  rep(i,n){
    int a; cin >> a; a--;
    cnt[a]++;
    st.insert(a);
  }
  int ans = 0;
  if(k < st.size()){
    sort(all(cnt));
    int p = 0;
    while(cnt[p] == 0) p++;
    rep(i,st.size()-k){
      ans += cnt[p];
      p++;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 10368
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-10
#define PB push_back
#define fi first
#define se second
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
typedef pair<int,int> Pii;
typedef vector<int> vi;
bool PRIME[1000001];
void Prime(){ 
    PRIME[0]=PRIME[1]=true; 
    for(int i=2;i*i <= 1000000 ;i++){ 
        if(PRIME[i]==false){ 
            for(int j=i*i ; j<=1000000 ; j+=i){ 
                PRIME[j] = true; 
            } 
        } 
    } 
    return; 
}
int main(){
	Prime();
    int n,x;
    while(scanf("%d%d",&n,&x),n){
        int goods[32]={0};
		int dp[1000001]={0};
		int ans = -1;
        rep(i,n){
            scanf("%d",&goods[i]);
        }
        sort(goods,goods+n);
		rep(i,n){
			reps(j,goods[i],x+1){
				if(dp[j] < dp[j-goods[i]]+goods[i]){
					dp[j] = dp[j-goods[i]]+goods[i];
					if(!PRIME[dp[j]])ans = max(ans,dp[j]);
				}
			}
		}
		ans == -1 ? puts("NA") : printf("%d\n",ans);
	}
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 085 B / Link: http://abc085.contest.atcoder.jp/tasks/abc085_b  ----- */


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

	LL N; 
	cin >> N;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	SORT(a), UNIQ(a);
	
	LL ans = SZ(a);
	
	
	cout << (ans) << "\n";

	return 0;
}


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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

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

	vi p(a);
	for(int &i: p) cin>> i;
	vi q(b);
	for(int &i: q) cin>> i;
	vi r(c);
	for(int &i: r) cin>> i;

	sort(all(p), greater<int>());
	sort(all(q), greater<int>());
	sort(all(r), greater<int>());

	int ans = 0;
	priority_queue<int, vi, greater<int>> pq;

	for(int i = 0; i<x; ++i){
		ans += p[i];
		pq.push(p[i]);
	}
	for(int i = 0; i<y; ++i){
		ans += q[i];
		pq.push(q[i]);
	}
	for(int i: r){
		if(pq.size() == 0) break;

		if(pq.top() < i){
			ans -= pq.top();
			ans += i;
			pq.pop();
		}
	}
	cout<< ans << endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}


Measured memory_bytes: 7612
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
typedef long long ll;
#define equ(a,b) ((fabs((a)-(b)))<(eps))
#define more(a,b) (((a)-(b))>(eps))
#define less(a,b) (((a)-(b))<(-eps))
#define inf 0x3f3f3f3f

int main(){
    long double a,b;
    cin>>a>>b;
    ll ans=a*b;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3784
use proconio::input;

fn main() {
    input! {
        n: usize,
        w: i64,
        v: [(i64, usize); n]
    };
    let mut dp = [w+1; 100001];
    dp[0] = 0;
    for &p in &v {
        for i in (p.1..=100000).rev() {
            dp[i] = dp[i].min(dp[i-p.1] + p.0);
        }
    }
    for i in (0..=100000).rev() {
        if dp[i] <= w {
            println!("{}", i);
            break;
        }
    }
}


Measured memory_bytes: 2956
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef pair<int,int> P;
const int INF = 1000000000;

int main(){
	int i,a,b,c,d,n;
	scanf("%d",&n);
	rep(i,n){
		int scr,x,y,z,w; 
		scanf("%d%d%d%d",&a,&b,&c,&d);
		scr = (a*c+b*d)*((c>=5&&d>=2)?0.8:1);
		
		if(c>=5&&d<2)scr = min(scr,(int)((a*c+b*2)*0.8));
		if(c<5&&d>=2)scr = min(scr,(int)((a*5+b*d)*0.8));
		if(c<5&&d<2)scr = min(scr,(int)((a*5+b*2)*0.8));
		
		/*
		if(c>=5&&d<2)scr = (scr<=(int)(a*c+b*2)*0.8)?scr:(int)(a*c+b*2)*0.8);
		if(c<5&&d>=2)scr = (scr<=(int)(a*5+b*d)*0.8)?scr:(int)(a*5+b*d)*0.8);
		scr = (scr<=(int)(a*5+b*2)*0.8)?scr:(int)(a*5+b*2)*0.8);*/
		
		
	printf("%d\n",scr);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <cstdio>
#include <cctype>
#include <cstdlib>
using namespace std;

void print(int n){
    int board[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            board[i][j] = 0;
        }
    }
    board[n/2+1][n/2] = 1;
    int x = n/2+2, y = n/2+1;
    for(int i = 2; i <= n*n; i++){
        while( true ){
            if( x >= n ){
                x = 0;
            }else if( y >= n ){
                y = 0;
            }else if( y < 0 ){
                y = n-1;
            }else if( board[x][y] ){
                x++;
                y--;
            }else{
                board[x][y] = i;
                break;
            }
        }
        x++;y++;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            printf("%4d", board[i][j]);
        }
        puts("");
    }
}

int main(){
    int n;
    while( scanf("%d", &n), n ){
        print( n );
    }
    return 0;
}

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

int main()
{
    int t,c=0, b, ans=123456789;
    cin >> t;
    int arr[t+1];
    for(int i=0; i<t; i++)
    {
        cin >> b;
        if(b%2 == 1)return cout<<"0"<<endl, 0;
        while(b%2 == 0)c++, b/=2;
        ans=min(c, ans);
        c=0;
    }
   
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000;
#define PI 3.14159265
int main()
{
    fastio;
    int h,w,k;
    cin>>h>>w>>k;
    string s[h];
    for(int i=0;i<h;i++)
        cin>>s[i];
    int ans = INT_MAX;
    for(int i=0;i<(1<<(h-1));i++)
    {
        map<int,int>mp;
        int cur = 0;
        for(int r=0;r<h;r++)
        {
            mp[r] = cur;
            if((1<<r)&i)cur++;
            //trace3(i,r,mp[r]);
        }
        int cnt[h] = {0};
        int total = cur;
        int sta=0;
        for(int c=0;c<w;)
        {
            bool f = true;
            for(int r=0;r<h;r++)
            {
                if(s[r][c]=='1')
                    cnt[mp[r]]++;
                if(cnt[mp[r]]>k)
                    f = false;
            }
            if(f)
                c++;
            else
            {
                if(sta==c)
                {
                    total = INT_MAX;
                    break;
                }
                for(int r=0;r<h;r++)
                    cnt[r] = 0;
                total++;
                sta = c;
            }
            //trace2(c,total);
        }
        ans = min(ans,total);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 

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

int main(void)
{
    int n=0;
    int ans=0;
    std::cin >> n;
    std::vector<int> d;
    rep(i,n){int t; cin>>t;d.push_back(t) ;}
    sort(d.begin(),d.end());
    ans=d[n/2]-d[n/2-1];
    std::cout << ((ans>0)?ans:0) << std::endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) for(int i=0;i<(c).size();i++)
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).begin();i++)
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> pi;

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

int n;

int buftoI(char buf[6][6])
{
	int y,x;
	rep(i,n)rep(j,n)if(buf[i][j]=='@')y=i,x=j;
	
	int ret=(y<<3)+x;
	rep(i,n)rep(j,n)ret*=2,ret+=(buf[i][j]=='#');
	return ret;
}
pi ItoBuf(int s,char buf[6][6])
{
	for(int i=n-1;i>=0;i--)for(int j=n-1;j>=0;j--)
	{
		int t=s&1;
		buf[i][j]=t?'#':'.';
		s/=2;
	}
	int x=s&7,y=s>>3;
	buf[y][x]='@';
	return mp(y,x);
}
void moveTime(char buf[6][6])
{
	char tmp[6][6];
	
	rep(i,n)rep(j,n)
	{
		int cnt=0;
		rep(d,8)
		{
			int ny=i+dy[d],nx=j+dx[d];
			if(ny<0||nx<0||ny>=n||nx>=n)continue;
			if(buf[ny][nx]!='.')cnt++;
		}
		if(buf[i][j]=='#')
		{
			if(cnt==2||cnt==3)tmp[i][j]='#';
			else tmp[i][j]='.';
		}
		else if(buf[i][j]=='.')
		{
			if(cnt==3)tmp[i][j]='#';
			else tmp[i][j]='.';
		}
		else tmp[i][j]='@';
	}
	
	rep(i,n)rep(j,n)buf[i][j]=tmp[i][j];
}

int main()
{

	while(cin>>n,n)
	{
		char buf[6][6];
		rep(i,n)cin>>buf[i];
		//BFS
		int ans=-1,cur=buftoI(buf);
		queue<pi> Q;
		Q.push(mp(0,cur));
		set<int> V;
		V.insert(cur);
		while(!Q.empty())
		{
			int step=Q.front().first;
			cur=Q.front().second;
			Q.pop();
			
			if((cur&((1<<n*n)-1))==0)
			{
				ans=step;break;
			}
			
			pi p=ItoBuf(cur,buf);
			int y=p.first,x=p.second;
			
			rep(d,8)
			{
				int ny=y+dy[d],nx=x+dx[d];
				if(ny<0||nx<0||ny>=n||nx>=n)continue;
				if(buf[ny][nx]!='.')continue;
				
				char nxtbuf[6][6];
				rep(i,n)rep(j,n)nxtbuf[i][j]=buf[i][j];		
				nxtbuf[ny][nx]='@',nxtbuf[y][x]='.';
				moveTime(nxtbuf);
				int nxt=buftoI(nxtbuf);
				
				if(V.count(nxt))continue;
				V.insert(nxt);
				Q.push(mp(step+1,nxt));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
	ll n;
	cin >> n;

	ll ans = (n + 1) * n / 2 - n;
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))

X_sorted = sorted(X)
first_half_median = X_sorted[N // 2 - 1]
last_half_median = X_sorted[N // 2]

for i in range(N):
    if X[i] <= first_half_median:
        print(last_half_median)
    else:
        print(first_half_median)

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> L(n), R(n);
    for (int i = 0; i < n; i++) {
        cin >> L[i] >> R[i];
    }
    int maxL_idx = 0, minR_idx = 0;
    for (int i = 0; i < n; i++) {
        if (L[maxL_idx] < L[i] || (L[i] == L[maxL_idx] && R[i] < R[maxL_idx])) {
            maxL_idx = i;
        }

        if (R[minR_idx] > R[i] || (R[i] == R[minR_idx] && L[i] > L[minR_idx])) {
            minR_idx = i;
        }
    }

    ll ans = max(R[minR_idx] - L[maxL_idx] + 1, 0LL);
    {
        ll tmp = 0;
        for (int i = 0; i < n; i++) {
            if (i == minR_idx || i == maxL_idx) continue;
            tmp = max(tmp, R[i] - L[i] + 1);
        }
        ans += tmp;
    }

    if (minR_idx == maxL_idx) {
        cout << ans << "\n";
        return 0;
    }

    ll L1 = L[minR_idx], R1 = R[minR_idx], L2 = L[maxL_idx], R2 = R[maxL_idx];
    vector<ll> d1(n), d2(n);
    vector<int> ids(n);
    for (int i = 0; i < n; i++) {
        ids[i] = i;
        ll nex_L1 = max(L1, L[i]);
        ll nex_R1 = min(R1, R[i]);
        d1[i] = max(R1 - L1 + 1, 0LL) - max(nex_R1 - nex_L1 + 1, 0LL);

        ll nex_L2 = max(L2, L[i]);
        ll nex_R2 = min(R2, R[i]);
        d2[i] = max(R2 - L2 + 1, 0LL) - max(nex_R2 - nex_L2 + 1, 0LL);
    }
    sort(ids.begin(), ids.end(), [&](const int i1, const int i2){
        if (d1[i1] != d1[i2]) return d1[i1] < d1[i2];
        return d2[i1] > d2[i2];
    });

    vector<ll> dd1(n, 0), dd2(n, 0);
    for (int ii = 0; ii < n; ii++) {
        int i = ids[ii];
        dd1[ii] = d1[i];
        if (ii > 0) dd1[ii] = max(dd1[ii], dd1[ii-1]);
    }

    for (int ii = n - 1; ii >= 0; ii--) {
        int i = ids[ii];
        dd2[ii] = d2[i];
        if (ii < n - 1) dd2[ii] = max(dd2[ii], dd2[ii + 1]);
    }

    ll sum = max(R1 - L1 + 1, 0LL) + max(R2 - L2 + 1, 0LL);
    ll ans2 = max(sum - dd1[n-1], sum - dd2[0]);
    for (int i = 0; i < n - 1; i++) {
        ans2 = max(ans2, sum - dd1[i] - dd2[i + 1]);
    }
    ans = max(ans, ans2);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5376
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int N  =sc.nextInt();
        int [] List = new int[N];
        for(int i=0;i<N;i++) List[i]=sc.nextInt();
        Arrays.sort(List);
        int num=0;
        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(List[i]+List[j]>List[k])num++;
                    else break;
                }
            }
        }
        System.out.println(num);
    }
}

Measured memory_bytes: 27572
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <stack>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#define mst(a,b) memset(a,b,sizeof(a))
#define din(a) scanf("%d",&a);
#define lfin(a) scanf("%lf",&a);

using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const double E=exp(1.0);
const double eps=1e-9;
const int mod=1e7;
const int M=1e6;

typedef pair<int,int>P;
vector<P>vec[M];
ll d[M];
/*
  d[j] 是去 j 的距离；
  vector [x] 含义 ： 表示去往 x 的一个 2 数据集合（ 通向城市，其距离） 
*/
/*
  dfs（a,b）： 通往 a 所有可能的地方，其终点是b
       搜索能去 a 的所有路径中： 
	   如果没到终点，{ 继续 dfs ,就更新去 a 步数（答案）}  
*/
/*
void dfs(int x,int y){
	int i,k=vec[x].size();
	for(i=0;i<k;i++){
		P s=vec[x][i];
		if(s.first!=y){
			d[s.first]=d[x]+s.second;
		
			dfs(s.first,x);
		}
	}
}*/
void dfs(int x,int y){
	for(int i=0;i<vec[x].size();i++) {
		P temp=vec[x][i];
		if(temp.first!=y){
			d[temp.first]=d[x]+temp.second;
			dfs(temp.first,x); 
		}
	} 
} 





int main() {
	int n,i;
	din(n);
	for(i=0;i<n-1;i++) {
		int a,b,c;
		din(a);din(b);din(c);
		// 去 a 的 b 点的距离是 c 
		vec[a].push_back(P(b,c));
		// 去 b 的 a 点的距离是 c 
		vec[b].push_back(P(a,c));
	}
	int  m,k;
	din(m);din(k);
	d[k]=0;
	// 搜能去往 k 的地方，其终点位置是 k 
	dfs(k,k);
	for(i=0 ;i<m ;i++) {
		int a,b;
		din(a);din(b);
		printf("%lld\n",d[a]+d[b]);
	}
	return 0;
}

Measured memory_bytes: 37120
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	vector<char> ss;
	cin >> s;
	for (auto ch : s) {
		if (ch == 'B') {
			if (!ss.empty()) ss.resize(ss.size() - 1);
		}
		else ss.push_back(ch);
	}

	for (auto ch : ss) cout << ch;
	cout << "\n";

	return 0;
}


Measured memory_bytes: 504
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion


//ABC  115-C Chrismas Eve

int main(void) {
	int        i, n, k;
	int        h[100001];

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

	qsort(h, n, sizeof(int), i_asort);

	int min = 1000000001, tmp;
	for (i = 0; i <= n - k; i++) {
		min = ((h[i + k - 1] - h[i]) < min) ?
			(h[i + k - 1] - h[i]) : min;
	//	min = _min(tmp, min);
	}

	printf("\n%d\n", min);
	return 0;
}


Measured memory_bytes: 2728