akhauriyash/Code-Regression huggingface dataset:
while True:
  n=int(input()) #審判の数
  if n==0:#入力終了
   break
  l=[]
 
  s=0
  for i in range(n):
    j=int(input()) #得点
    l.append(j)
    s+=j
  print((s-max(l)-min(l)) //(n-2))


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 100000000000000
#define endl '\n'
ll arr[200005];
bool chk(ll x,ll n,ll k)
{
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ll temp=(ll)(ceil((arr[i]*1.0)/x));
		temp--;
		ans+=temp;
	}
	if(ans>k)
		return false;
	return true;
}
int main()
{
	fastio;
	#ifdef gdb_18
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,k;
	cin>>n>>k;
	ll hi=0;
	for(ll i=1;i<=n;i++)
	{	
		cin>>arr[i];
		hi=max(hi,arr[i]);
	}
	ll lo=1;
	while(lo<hi)
	{
		ll mid=(lo+hi)/2;
		if(chk(mid,n,k))
			hi=mid;
		else
			lo=mid+1;
	}
	cout<<lo<<endl;
	return 0;	
}

Measured memory_bytes: 5064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		String word;
		int count = 0;
		List<String> text = new ArrayList<>();
		final String EOT = "END_OF_TEXT";

		Scanner stdIn = new Scanner(System.in);

		word = stdIn.nextLine();

		for(int i = 0;;i++) {
			String s = stdIn.next();
			if(s.equals(EOT)) {
				break;
			}
			text.add(s);
		}

		for(String s : text) {
//			System.out.println(s + " == " + word + " : " + s.compareToIgnoreCase(word));
			if(s.compareToIgnoreCase(word) == 0) {
				count++;
			}
		}

		System.out.println(count);


		stdIn.close();
	}

}

Measured memory_bytes: 26076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int N, M;

int main () {
  cin >> N;
  map<string, int> c;
  rep(i,N) {
    string s;
    cin >> s;
    c[s]++;
  }

  cin >> M;
  rep(i,M) {
    string s;
    cin >> s;
    c[s]--;
  }

  int ans = 0;
  for(auto p: c) {
    ans = max(ans, p.second);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from itertools import permutations
N=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
s=0
for x in permutations(range(1,N+1)):
    s=s+1
    if list(x)==p:
        a=s
    if list(x)==q:
        b=s
print(abs(a-b))



Measured memory_bytes: 3316
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

int main(){
    int x,n;cin>>x>>n;
    vector<int> p(n);
    rep(i,0,n) cin>>p[i];
    sort(p.begin(),p.end());
    int num = 0;
    int ans = 0;
    while (true){
        int k1 = x+num;
        int k2 = x-num;
        int f2  =true;
        rep(i,0,n){
            if (k2==p[i]){
                f2 = false;
                break;
            }
        }
        if (f2){
            cout<<k2<<endl;
            return 0;
        }
        int f1  = true;
        rep(i,0,n){
            if (k1==p[i]){
                f1 = false;
                break;
            }
        }
        if (f1){
            cout<<k1<<endl;
            return 0;
        }
        num++;
    }
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, h;
    cin >> n >> h;
    int mx = 0;
    int a, b;
    priority_queue<int> t;
    REP(i, n) {
        cin >> a >> b;
        chmax(mx, a);
        t.emplace(b);
    }
    int ans = 0;
    while (h > 0 && !t.empty()) {
        ans++;
        auto s = t.top();
        if (mx <= s) {
            h -= s;
            t.pop();
        } else {
            ans--;
            break;
        }
    }
    if (h > 0) ans += (h + mx - 1) / mx;
    cout << ans << endl;

}


Measured memory_bytes: 892
#include<iostream>
using namespace std;
int A[15];
int L[15];int R[15];
int n;

bool dfs(int i, int j, int k)
{
	
	if(i==10) return true;
	if(A[i] > L[j-1])
	{
		L[j] = A[i];
		if(dfs(++i,++j,k))
			return true;
	}
	if(A[i] > R[k-1])
	{
		R[k] = A[i];
		if(dfs(++i,j,++k))
			return true;	
	}	
	return false;
}
void solve()
{

	if(dfs(0,1,1))
		cout << "YES"<<endl;
	else
		cout <<"NO"<<endl;
}

int main()
{
	
	cin >>n;
	while(n--)
	{
		for(int i =0; i<10; i++)
			cin >> A[i];
		L[0] = R[0] = 0;		
		solve();
	}
}

Measured memory_bytes: 3040
#include<iostream>
using namespace std;
int main(){
  int a,b,c,i;
  cin >> i; 
  for(int n = 0;n < i;n++){
    cin >> a >> b >> c;
    if(a*a == b * b + c * c){
      cout << "YES" << endl;
    } else if(b*b == a * a + c * c){
      cout << "YES" << endl;
    } else if(c*c == b * b + a * a){
      cout << "YES" << endl;
    } else {cout <<"NO" << endl;} 
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N;
  cin >> N;
  ll ans = N-1;
  for (ll i = 1; i * i <= N; i++) {
    if (N%i == 0) {
      ll temp = i-1;
      temp += (N/i) - 1;      
      if (temp < ans) ans = temp;
    }
  }
  cout << ans << '\n';  
  return 0;
}

Measured memory_bytes: 3564
s, t  = map(int, input().split())
u = list(map(int,input().split()))
ln = []
for i in u:
    ln.append((1 + i)/2)

from itertools import accumulate

B = [0] + ln

B = list(accumulate(B)) 
answer = []

for i in range(s-(t-1)):
    answer.append(B[i+t]-B[i])

print(max(answer)) 

Measured memory_bytes: 29892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    string n;
    cin >> n;
    for(int i=0; i<n.length(); i++){
        if(n[i] == '9'){
            n[i] = '1';
        }
        else if(n[i] == '1'){
            n[i] = '9';
        }
    }
    int ans;
    for(int i=0; i<3; i++){
        ans += (n[2-i]-'0')*pow(10,i);
    }
    cout << ans;
    return 0;
}

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

int bfs(int s,vector<vector<int>> &adj,vector<int> &visited){

	queue<int> q ;
	q.push(s) ;

	visited[s]=1 ;

	int size=1 ;

	while(!q.empty()){

		int t=q.front() ;
		q.pop() ;

		for(auto x:adj[t]){
			if(visited[x]==0)
			{
				q.push(x) ;
				visited[x]=1 ;
				size++ ;
			}
		}

	}

	return size ;

}


void solve(){
	
	int n,m ;
	cin>>n>>m ;

	vector<vector<int>> adj(n+1) ;
	
	
	for(int i=0;i<m;i++){
		int l,r ;
		cin>>l>>r;
		//cout<<l<<r ;
			
		adj[l].push_back(r) ;
		adj[r].push_back(l) ;
	
	}

	vector<int> visited(n+1) ;

	int res=0 ;

	for(int i=1;i<=n;i++){

		if(visited[i]==0)
		{
			int answer=bfs(i,adj,visited) ;
			res=max(res,answer) ;		
		}
	
	}		

	cout<<res ;

}
int main(){
	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 15708
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,k = LI()
    e = collections.defaultdict(list)
    t = []
    for _ in range(n-1):
        a,b = LI_()
        e[a].append(b)
        e[b].append(a)
        t.append((a,b))

    r = inf
    q = [0] * n
    k2 = k//2
    if k%2 == 0:
        for i in range(n):
            v = [-1] * n
            v[i] = 0
            q[0] = i
            qi = qe = 0
            while qi <= qe:
                c = q[qi]
                for ni in e[c]:
                    if v[ni] >= 0:
                        continue
                    if v[c] == k2:
                        continue
                    v[ni] = v[c] + 1
                    qe += 1
                    q[qe] = ni
                qi += 1
            tr = n-qe-1
            if r > tr:
                r = tr
    else:
        for i in range(n-1):
            a,b = t[i]
            v = [-1] * n
            v[a] = v[b] = 0
            q[0] = a
            q[1] = b
            qi = 0
            qe = 1
            while qi <= qe:
                c = q[qi]
                for ni in e[c]:
                    if v[ni] >= 0:
                        continue
                    v[ni] = v[c] + 1
                    if v[ni] > k2:
                        continue
                    qe += 1
                    q[qe] = ni
                qi += 1
            tr = n-qe-1
            if r > tr:
                r = tr

    return r

print(main())



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

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  cout << (d - t * s > 0 ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int sum = a*100+b*10+c;
	if(sum%4 == 0) puts("YES");
	else puts("NO");

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int M,i,flag=0,k=0;
    long long int A[200],min;
    min = 10000000000;
    scanf("%d" ,&M);
    for (i=0; i<M; i++) {
        scanf("%lld" ,&A[i]);
        if(A[i]%2!=0) flag=1;
    }
    while(flag==0){
        k++;
        for(i=1; i<M; i++) {
            A[i]/=2;
            if(A[i]%2!=0){
                printf("%d" ,k);
                return 0;
            }
        }
    }
    printf("0");
    return 0;
}


Measured memory_bytes: 1716
a = int(input())
b = list(map(int, input().split()))
b.sort()

count = 0
for c in b:
    for d in b:
        if c >= d:
            continue
        for e in b:
            if d >= e:
                continue

            if c + d > e and d + e > c and e + c > d:
                count += 1
print(count)

Measured memory_bytes: 67868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=500005;
char s[max_n];
int l[max_n],r[max_n];
int main(){
    scanf(" %s",s+1);
    int n=strlen(s+1)+1;
    for(int i=2;i<=n;i++){
        if(s[i-1]=='<')l[i]=l[i-1]+1;
    }
    for(int i=n-1;i>=1;i--){
        if(s[i]=='>')r[i]=r[i+1]+1;
    }
    ll ans=0;
    for(int i=1;i<=n;i++)ans+=max(l[i],r[i]);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4608
#include <stdio.h>

int main(){
    int n,mini=1<<29;
    scanf("%d",&n);
    for (int i=0; i<n; i++){
        int cnt=0;
        int x;
        scanf("%d",&x);
        while (x%2==0) {
            x/=2;
            cnt++;
        }
        if (mini>cnt) mini=cnt;
    }
    printf("%d",mini);
    return 0;
}

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

int main() {
    vector<int> result;
    bool tf = true;
    for (int i = 0; tf; i++) {
        int a, b;
        char op;
        cin >> a >> op >> b;
        if (op == '?') {
            tf = false;
            break;
        }
        switch (op) {
            case '+':
                result.push_back(a+b);
                break;
            case '-':
                result.push_back(a-b);
                break;
            case '*':
                result.push_back(a*b);
                break;
            case '/':
                result.push_back(a/b);
                break;
            default:
                break;
        }
    }
    for (int i = 0; i < result.size(); i++) {
        printf("%d\n", result.at(i));
    }
}


Measured memory_bytes: 3268
#include <iostream>
#include <set>

using namespace std;

int main(void){
    int N;
    cin >> N; cin.ignore();
    
    set<int> nums;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A; cin.ignore();
        
        auto itr = nums.find(A);
        if (itr == nums.end()) {
            nums.insert(A);
        } else {
            nums.erase(A);
        }
    }
    
    cout << nums.size() << endl;
} 


Measured memory_bytes: 4864
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const N = nextInt()
    const a = nextIntArray()
    let sorted = [...a]
    sorted.sort((a,b) => a-b)
    let ans = "";
 
    for (let i = 0; i < N; i++) {
        if (a[i] < sorted[N / 2]) { ans += String(sorted[N / 2]) + "\n" }
        else { ans += String(sorted[N / 2 - 1]) + "\n" }
    }
    console.log(ans)
}
Main()


Measured memory_bytes: 71384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <unordered_set>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>x(m),y(m);
    rep(i,m){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    vector<pii>z(n,pii(1,0));
    z[0] = pii(1,1);
    rep(i,m){
        if(z[x[i]].second==1){
            if(z[x[i]].first==1){
                z[x[i]].second=0;
            }
            z[x[i]].first--;
            z[y[i]].first++;
            z[y[i]].second=1;
        }
        else{
            z[x[i]].first--;
            z[y[i]].first++;
        }
    }
    int ans =0;
    rep(i,n){
        if(z[i].second==1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N, T;
int main() {
    while (cin >> N >> T) {
        int res = 1<<29;
        for (int i = 0; i < N; ++i) {
            int c, t; cin >> c >> t;
            if (t <= T) res = min(res, c);
        }
        if (res < 1<<29) cout << res << endl;
        else cout << "TLE" << endl;
    }
}
















Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    vll a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];
    ll q;
    cin >> q;
    vll b(q), c(q);
    for(ll i = 0; i < q; i++) cin >> b[i] >> c[i];
    map<ll, ll> mp;
    ll ans = 0;
    for(ll i = 0; i < n; i++) {
        mp[a[i]]++;
        ans += a[i];
    }
    vll ansv(q);
    for(ll i = 0; i < q; i++) {
        ll cnt = mp[b[i]];
        ans += (c[i] - b[i]) * cnt;
        ansv[i] = ans;
        mp[c[i]] += mp[b[i]];
        mp[b[i]] = 0;
    }
    for(auto i : ansv) cout << i << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

int main()
{
	int r,c;
	int a[200][200] = {0};
	
	cin >> r >> c;
	
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin >> a[i][j];
			a[i][c] += a[i][j];
			a[r][j] += a[i][j];
		}
		a[r][c] += a[i][c];		
	}
	
	for(int i=0; i<r+1; i++){
		for(int j=0; j<c; j++)
			cout << a[i][j] << ' ';
		cout << a[i][c] << endl;
	}
	
	return 0;
}



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

int main() {
  string s;
  cin >> s;
  int n = s.size(), u = 1, v = 1;
  bool b = false;
  rep(i, n / 2) if(s[i] != s[n - 2 - i]) b = true;
  if(b || s[0] != '1' || s[n - 1] != '0') {
    cout << -1 << endl;
    return 0;
  }
  rep(i, n / 2 + 1) s[n / 2 + 1 + i] = '0';
  reverse(begin(s), end(s));
  rep(i, n - 1) {
    v++;
    cout << u << ' ' << v << '\n';
    if(s[i + 1] == '1') u = v;
  }
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e18;
const int inf=2e9;
const ll MOD=1000000007;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};

int main(){
    int N;cin>>N;
    int info[N];
    rep(i,N)cin>>info[i];
    int now=info[0],count=1;
    rep(i,N){
        if(now>info[i]){
            count++;
            now=info[i];
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
void print(int arr[],int n){
    for(int i=0;i<n;i++){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}
int main(){
        int n,p;
        cin>>n>>p;
        int pieces=(n*3)+p;
        cout<<pieces/2;
    return 0;
    
}

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

int main(void) {
	// in
	int n;
	std::cin >> n;
	std::vector<long long> a(n);
	for(int i = 0; i < n; ++i) std::cin >> a[i];

	// sort
	std::sort(a.begin(), a.end());

	std::vector<long long> b;
	int i_a = 0;
	while(i_a < n-1) {
		if(a[i_a] == a[i_a+1]) {
			b.push_back(a[i_a]);
			i_a += 2;
		}
		else ++i_a;
	}

	int n_b = b.size();
	long long sq = (n_b >= 2 ? b[n_b-1] * b[n_b-2] : 0LL);

	std::cout << sq << std::endl;

	return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;

ll N;
ll cnt = 0;


//再帰的に753数を得る
int saiki(string a)
{
  
  	ll tmp = stol(a);
    if(N < tmp)
    {
        return 0;
    }

    bool flg3 = false;
    bool flg5 = false;
    bool flg7 = false;
    //小さくてかつ7,5,3すべてつかっていたら
    for(int j = 0; j < a.size();j++)
    {
        if(a[j] == '3')flg3 = true;
        if(a[j] == '5')flg5 = true;
        if(a[j] == '7')flg7 = true;
    }

    if(flg3 && flg5 && flg7)cnt++;

    saiki(a + "7");
    saiki(a + "5");
    saiki(a + "3");
    return 0;
}


int main()
{
      // 追加２, 以降 cin の入力元が 'input.txt' になる
 //   std::ifstream in("resource/input.txt");
 //   std::cin.rdbuf(in.rdbuf());

    ll streak,res,iMax,iMin;

    cin >> N;

    saiki("0");

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n,t;
	while(cin >> n && n){
		int v[10] = {0};
		
		for(int i=0;i<n;i++){
			cin >> t;
			v[t]++;
		}
		for(int i=0;i<10;i++){
			if(v[i] == 0){
				cout << "-" << endl;
			}else{
				for(int j=0;j<v[i];j++){
					cout << "*";
				}
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 0
n,W=map(int,input().split())

v1=[]
v2=[]
v3=[]
v4=[]

w,v=map(int,input().split())
v1.append(v)
w1=w

for _ in range(n-1):
    w,v=map(int,input().split())
    if w1==w:
        v1.append(v)
    elif w1+1==w:
        v2.append(v)
    elif w1+2==w:
        v3.append(v)
    elif w1+3==w:
        v4.append(v)

v1.sort(reverse=True)
v2.sort(reverse=True)
v3.sort(reverse=True)
v4.sort(reverse=True)

v=[v1,v2,v3,v4]

sumv=[[] for _ in range(4)]

for i,item in enumerate(v):
    tmp=[0]
    tmpv=0
    for j in item:
        tmpv+=j
        tmp.append(tmpv)
    sumv[i]=tmp

ans=0
#print(sumv)
for num1 in range(len(sumv[0])):
    for num2 in range(len(sumv[1])):
        for num3 in range(len(sumv[2])):
            for num4 in range(len(sumv[3])):

                tmpans=0
                tmpwait=0
                if sumv[0][num1]!=0:
                    tmpans+=sumv[0][num1]
                    tmpwait+=(num1)*(w1)
                if sumv[1][num2]!=0:
                    tmpans+=sumv[1][num2]
                    tmpwait+=(num2)*(w1+1)
                if sumv[2][num3]!=0:
                    tmpans+=sumv[2][num3]
                    tmpwait+=(num3)*(w1+2)
                if sumv[3][num4]!=0:
                    tmpans+=sumv[3][num4]
                    tmpwait+=(num4)*(w1+3)

                if tmpwait<=W:
                    ans=max(ans,tmpans)

print(ans)




            

        


Measured memory_bytes: 74564
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    HL = list(map(int, sys.stdin.readline().split()))

    for i in range(N - 1, 0, -1):
        diff = HL[i - 1] - HL[i]
        if diff > 1:
            print("No")
            exit()
        elif diff == 1:
            HL[i - 1] -= 1
        else:
            continue

    print("Yes")

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

int main(void){
  int p,q,r; cin >> p >> q >> r;
  cout << min(p+q,min(p+r,q+r)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll N ; cin >> N ;
	for(ll h=1;h<=3500;h++){
		for(ll n=1;n<=3500;n++){
			if(4*h*n-N*h-N*n!=0&&N*h*n%(4*h*n-N*h-N*n)==0&&N*h*n/(4*h*n-N*h-N*n)>0){
				cout << h << " " << n << " " << N*h*n/(4*h*n-N*h-N*n) << endl ;
				return 0 ;
			}
		}
	}
	cout << '?' << endl ;
}


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

typedef long long ll;

ll gcd(ll a, ll b){
    return b == 0 ? a : gcd(b, a%b);
}

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

    ll x;
    cin >> x;
    ll ans = abs(start-x);

    for(int i = 1; i < n; i++){
        cin >> x;
        ll tmp = abs(start - x);
        if(tmp == 0)    continue;
        ans = gcd(ans, tmp);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define getarray(a,n)  for(int i=0;i<n;i++) cin>>a[i]
#define ll long long 
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vi vector<int>
#define w(t) int t;cin>>t;while(t--)
using namespace std;

int main()
{
    fast
    string a,b;
    cin>>a>>b;
    ll cnt=0;
    for(int i=0;i<a.length();i++)
    {
    	if(a[i]!=b[i])
    	{
    		cnt++;
    	}
    }
    cout<<cnt;
    return 0;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int> freq[n];
    map<vector<int>, int> wtf;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        freq[i].resize(26);
        for(char c : s) {
            freq[i][c - 'a']++;
        }
        ans += wtf[freq[i]];
        wtf[freq[i]]++;
    }
    cout << ans << "\n";
}


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

int N, A, B, C;
int l[8];

int dfs(int k, int a, int b, int c) {
    if (k == N) {
        if (a == 0 || b == 0 || c == 0) {
            return 1000000000;
        }
        return abs(A - a) + abs(B - b) + abs(C - c);
    }

    int res = 100000000;
    res = min(res, dfs(k + 1, a + l[k], b , c) + (a > 0 ? 10 : 0));
    res = min(res, dfs(k + 1, a, b + l[k] , c) + (b > 0 ? 10 : 0));
    res = min(res, dfs(k + 1, a, b , c + l[k]) + (c > 0 ? 10 : 0));
    res = min(res, dfs(k + 1, a, b, c));
    return res;
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++)
        cin >> l[i];
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}

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

bou_half = sum(List)/2

bou_sum = 0
for i in List:
    bou_sum += i
    if bou_sum == bou_half:
        print(0)
        exit()
    if bou_sum > bou_half:
        if bou_sum - bou_half < bou_half - bou_sum + i: # 中心が右より
            print(int((bou_sum - bou_half) // 0.5))
            exit()
        else: 
            print(int((bou_half - bou_sum +i) // 0.5))
            exit()


Measured memory_bytes: 88912
N , K = map(int, input().split())
l = list(map(int, input().split()))
ll = sorted(l)
res = 0
if N == K :
    res = sum(ll)
elif K==1 : 
    res = ll[0]
else:
    for i in range (K):
        res += ll[i]
print(res)

Measured memory_bytes: 9264
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

  int k, n;
  int l[50];

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

  sort(l, l + n);

  int ans = 0;
  for(int i = 0; i < k; i++)
    ans += l[n - 1 - i];

  printf("%d\n", ans);

  return 0;
}


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

int main(){
  int n,ans=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    if(i%2!=0){
      ans++;
    }
  }
  cout<<fixed<<setprecision(20)<<(double)ans/n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
bool complare(char a, char b){
	return a > b;
}
int main(){
	char s[100];
	char t[100];
	cin >> s >> t;
	int lens = strlen(s);
	int lent = strlen(t);
	sort(s, s + lens);
	sort(t, t + lent, complare);
	if (strcmp(s, t) < 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

{
    int number[30],i, j, a;
            for (i=0; i<5; ++i)
        scanf("%d",&number[i]);
            for (i=0; i<5; ++i)
                {
                    for (j=i+1; j<5; ++j)
                        {
                            if (number[i]<number[j])
                                {
                                    a=number[i];
                
                                    number[i]=number[j];
                
                                    number[j]=a;
                                }
                        }
                }
                    for (i=0; i<5; ++i)
                        {
                            printf("%d",number[i]);
                            if(i==4)
                                printf("\n");
                            else
                                printf(" ");
                        }
    
    return 0;
}

Measured memory_bytes: 1028
n = int(input())
h = [int(i) for i in input().split()]

flg = True
for i in range(n-1):
    if h[n-1-i] + 1 < h[n-2-i]:
        flg = False
        break
    
    if h[n-1-i] < h[n-2-i]:
        h[n-2-i] -= 1

if flg:
    print("Yes")
else:
    print("No")


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

    //long long
    using ll = long long;

    // pair<int, int>
    using PII = pair<int, int>;

    //最大値、mod
    const int MOD = 1000000007;
    const int INF = 1000000000;
    const long long LINF = 1e18;

    //出力系
    #define print(x) cout << x << endl
    #define prints(x) cout << fixed << setprecision(10) << x << endl
    #define printc(x) cout << setw(2) << setfill('0') << x << endl;
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数 
    unsigned gcd(unsigned a, unsigned b) {
      if(a < b) return gcd(b, a);
      unsigned r;
      while ((r=a%b)) {
        a = b;
        b = r;
      }
      return b;
    }

    // 最小公倍数
    unsigned lcm(unsigned a, unsigned b){
        return a / gcd(a, b) * b; 
    }

    // a = max(a, b), a = min(a, b)
    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; }

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









int main(){
  int N;
  cin >> N;
  int a = 0;
  int b = 0;
  int ab = 0;
  int ans = 0;
  vector<string>S(N);
  REP(i, N){
    cin >> S.at(i);
    int len = S.at(i).length();
    if(S.at(i).at(0) == 'B' && S.at(i).at(len - 1) == 'A') ab++;
    else if(S.at(i).at(0) == 'B') b++;
    else if(S.at(i).at(len - 1) == 'A') a++;
    for(int j = 0; j < len - 1; j++){
      if(S.at(i).at(j) == 'A' && S.at(i).at(j + 1) == 'B') ans++;
    }
  }
if(a + b == 0) ans +=max(0, ab - 1); 
else ans += ab + min(a, b);
print(ans);

}

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

using ll = long long;
static const ll MOD = 1e9 + 7;

// 組合せを素数で割った値を求める
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  
  COMinit();
  
  ll ans = 0;
  
  for(int i = b; i <= w; i++){
    ans += COM((h - a - 1) + i, i) * COM((a - 1) + (w - i - 1), a - 1);
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 12160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

string s;

int main() {
    ios::sync_with_stdio(false);
    cin>>s;
     if(s=="ABC") puts("ARC");
     else puts("ABC");
    return 0;
}

Measured memory_bytes: 3632
using System;

class Program {
  static void Main() {
    string n = Console.ReadLine();
    if ((n[0]==n[1]&&n[1]==n[2])||(n[1] == n[2] && n[2] == n[3])) {
      Console.WriteLine("Yes");
    } else {
      Console.WriteLine("No");
    }
  }
}

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

vector<long long> Power10Rev = {1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1};

int numlunlun2(int start, int numdigits){
    if((start < 0)||(start > 9))return 0;
    if(numdigits <= 0)return 0;
    if(numdigits == 1)return 1;
    return numlunlun2(start-1, numdigits-1)+numlunlun2(start, numdigits-1)+numlunlun2(start+1, numdigits-1);
}

int numlunlun(long long upper){
    //including upper
    int res = 0;
    bool calculated = false;
    int prvdigit;
    for(int i=0; i<10; i++){
        if(upper >= Power10Rev[i]){
            int curdigit = (upper/Power10Rev[i])%10;
            if(!calculated){
                for(int j=1; j<curdigit; j++)res += numlunlun2(j, 10-i);
                for(int j=1; j<10; j++){
                    for(int k=9-i; k>0; k--)res += numlunlun2(j, k);
                }
            }else{
                for(int j=prvdigit-1; j<curdigit; j++)res+=numlunlun2(j, 10-i);
            }
            if(i<9){
                int nxtdigit = (upper/Power10Rev[i+1])%10;
                if(nxtdigit > curdigit + 1){
                    res += numlunlun2(curdigit, 10-i);
                    break;
                }else if(nxtdigit < curdigit - 1){
                    break;
                }else{
                    calculated = true;
                    prvdigit = curdigit;
                }
            }else{
                res += 1;
            }
        }
    }
    return res;
}

int main(void){
    int K;
    cin >> K;
    long long Nupper = 3234566667LL;
    long long Nlower = 0LL;
    long long res = (Nupper + Nlower)/2;
    while(Nupper - Nlower > 1){
        if(numlunlun(res) >= K){
            Nupper = res;
        }else{
            Nlower = res;
        }
        res = (Nupper + Nlower)/2;
    }

    cout << Nupper << endl;

    return 0;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = read().decode('utf8').split()
print('YES' if A == B[::-1] and B == A[::-1] else 'NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	vector<int>v(n);
	REP(i,n) cin>>v[i];
	int ans=0;
	REP(i,n){
		if(v[i]!=i+1) ans++;
	}
	if(ans<=2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        print(B[N//2] - A[N//2] + 1)
    else:
        print((B[N//2] + B[N//2-1]) - (A[N//2] + A[N//2-1]) + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 90964
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int calc(int h, int w) {
  int res = INF;
  FOR(i,1,h) {
    int A = i*w;
    int B = ((h - i) / 2) * w;
    int C = h * w - A - B;
    if (C > 0) CHMIN(res, max({A,B,C}) - min({A,B,C}));
    B = (h - i) * (w / 2);
    C = h * w - A - B;
    if (C > 0) CHMIN(res, max({A,B,C}) - min({A,B,C}));
  }
  return res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int H,W;
  cin >> H >> W;
  cout << min(calc(H,W),calc(W,H)) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NIL -1
#define Length 500005
typedef struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
} Tree;
Tree *root = NULL;
void insert(int key){
  Tree *c = (Tree*)malloc(sizeof(Tree));
  c -> key = key;
  Tree *x, *y;
  x = root;
  y = NULL;
  while(x != NULL){
    y = x;
    if(c -> key < x -> key)
      x = x -> l;
    else
      x = x -> r;
  }
  c -> p = y;
  c -> l = NULL;
  c -> r = NULL;
  if(y == NULL){
    root = c;
  }else if(c -> key < y -> key){
    y -> l = c;
  }else{
    y -> r = c;
  }

}
void printInorder(Tree *u){
  if(u == NULL)
    return;
  printInorder(u -> l);
  printf(" %d", u -> key);
  printInorder(u -> r);
}
void printPreorder(Tree *u){
  if(u == NULL)
    return ;
  printf(" %d", u -> key);
  printPreorder(u -> l);
  printPreorder(u -> r);
}
int main(){
  char line[100];
  int n;
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d", &n);
  char *str_ptr;
  int key;
  for(int i = 0; i < n; ++i){
    fgets(line, sizeof(line), stdin);
   
    if(strcmp(line, "print") == 0 || strcmp(line, "print\n") == 0){
      printInorder(root);
      printf("\n");
      printPreorder(root);
      printf("\n");
    }else{
      str_ptr = strtok(line, " ");
      if(strcmp(str_ptr, "insert") == 0){
        str_ptr = strtok(NULL, " ");
        sscanf(str_ptr, "%d", &key);
        insert(key);
      } 
    }
  } 
 
  return 0;
}



Measured memory_bytes: 25172
function main()
  
  (H,W) = map(x -> parse(BigInt,x), split(readline()))
  
  ans = 0
  
  if H == 1 || W == 1
  	ans = 1
  elseif H % 2 == 0
    ans += W*div(H,2)
  else
    ans += W*div(H,2)
    ans += ceil(Int,W/2)
  end
  
  println(ans)
  
end

main()

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

class Program
{
    static bool isPrime(long a)
    {
        if (a <= 1) return false;
        for (long i = 2; i <= (long)Math.Sqrt(a); i++)
        {
            if (a % i == 0) return false;
        }
        return true;
    }
    public static void Main(string[] args)
    {
        long n = long.Parse(Console.ReadLine());
        long[] a = new long[n];
        for (long i = 0; i < n; i++) a[i] = long.Parse(Console.ReadLine());
        int res = 0;
        for (int i = 0; i < n; i++) res = (isPrime(a[i]))? res + 1: res;
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 15968
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();

        var checkList = input.Split(' ').ToList().ConvertAll(x => int.Parse(x));

        if (checkList.Sum() == 17)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }

        Console.ReadLine();
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	vector<string> v;
	int N, M;
	cin >> N;
	map<string, int> s;
	for (int i = 0; i < N; ++i) {
		string x;
		cin >> x;
		++s[x];
		v.push_back(x);
	}
	cin >> M;
	map<string, int> t;
	for (int i = 0; i < M; ++i) {
		string x;
		cin >> x;
		++t[x];
		v.push_back(x);
	}

	int ans = 0;
	for (auto &x : v) {
		ans = max(ans, s[x] - t[x]);		
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define M 1000000000
#define ll long long
int m, n, r, x, y, t;
char c;
int a[1005];
int s[201][201];
int l[201][201];
ll dp[1005][205];
int main() {
    while ((~scanf("%d %d", &n, &m)) && m && n) {
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                if (i == j) s[i][j] = l[i][j] = 0;
                else s[i][j] = l[i][j] = M;
        for (int i = 0; i < m; ++i) {
            scanf("%d %d %d %c", &x, &y, &t, &c);
            if (c == 'L') l[x][y] = l[y][x] = min(l[x][y], t);
            else s[x][y] = s[y][x] = min(s[x][y], t);
        }
        for (int k = 1; k <= n; ++k)
            for (int i = 1; i <= n; ++i)
                for (int j = 1; j <= n; ++j) {
                    s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
                    l[i][j] = min(l[i][j], l[i][k] + l[k][j]);
                }
        scanf("%d", &r);
        for (int i = 0; i < r; ++i) scanf("%d", &a[i]);
        for (int i = 0; i < r; ++i) for (int j = 1; j <= n; ++j) dp[i][j] = M;
        for (int i = 1; i <= n; ++i) dp[0][i] = s[i][a[0]] + l[i][a[0]];
        for (int i = 1; i < r; ++i) {
            for (int j = 1; j <= n; ++j) {
                for (int k = 1; k <= n; ++k) {
                    if (j != k) dp[i][k] = min(dp[i][k], dp[i - 1][j] + l[a[i - 1]][j] + s[j][k] + l[k][a[i]]);
                    else dp[i][j] = min(dp[i][j], dp[i - 1][j] + l[a[i - 1]][a[i]]);
                }
                //printf("%d ",dp[i][j]);
            }//printf("\n");
        }
        ll ans = M;
        for (int i = 1; i <= n; ++i) ans = min(ans, dp[r - 1][i]);
        printf("%d\n", ans);
    }
    return 0;
}



Measured memory_bytes: 4628
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
using ll = long long;
 
int n, i, j;
string s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> s;
	
	ll r = count(begin(s), end(s), 'R');
	ll g = count(begin(s), end(s), 'G');
	ll b = count(begin(s), end(s), 'B');
	
	ll res = r * g * b;
	for (int j = 1; j < n; ++j) {
        for (int i = 0; i < j; ++i) {
			int k = 2 * j - i;
			if (k < n) res -= s[i] != s[j] and s[j] != s[k] and s[k] != s[i]; 
		}
	}
	
	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 3660