akhauriyash/Code-Regression huggingface dataset:
//解説AC　これが天才以外お断りパズルか……
//手元で試すのは大事
//ケースを考えて、手で書くことの大切さを知れた。
#include <bits/stdc++.h>

using namespace std;

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

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    vii ans(h,vi(w,0));
    rep(i,b){
        rep(j,a){
            ans[i][j]=1;
        }
    }
    REP(i,b,h){
        REP(j,a,w){
            ans[i][j]=1;
        }
    }
    rep(i,h){
        rep(j,w){
            cout<<ans[i][j];
        }
        cout<<endl;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 7584
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
q = int(input())

sm = 0
cnt = defaultdict(int)
for i in a:
    sm += i
    cnt[i] += 1

for _ in range(q):
    b, c = list(map(int, input().split()))
    if b in cnt:
        sm -= cnt[b] * b
        sm += cnt[b] * c

        cnt[c] += cnt[b]
        del cnt[b]
    print(sm)

Measured memory_bytes: 94700
#include <stdio.h>

int main (void){

	int x[3000]={0};
	int y[3000]={0};
	int s;
	int i,j;
	
	
	for(i=0;i<3000;i++){
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0 && y[i]==0){
			break;
		}
	}
	
	for(j=0;j<i;j++){
		if(x[j]>=y[j]){
			s = x[j];
			x[j] = y[j];
			y[j] = s;
		}
		printf("%d %d\n",x[j],y[j]);
	}
	return 0;
}

Measured memory_bytes: 628
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut a: Vec<i64> = s.map(|a| a.parse().unwrap()).collect();
	a.sort();
	let mut cum = vec![0; n + 1];
	let mut pnum = vec![0; *a.last().unwrap() as usize * 2 + 1];
	for (i, a) in a.iter().rev().enumerate() {
		cum[i + 1] = cum[i] + *a;
		pnum[*a as usize] += 1;
	}
	for i in (0..pnum.len() - 1).rev() {
		pnum[i] += pnum[i + 1];
	}
	let mut l = 2;
	let mut r = a.last().unwrap() * 2 + 1;
	'a: while r - l > 1 {
		let mid = l + (r - l) / 2;
		let mut cnt = 0;
		for a in a.iter().rev() {
			cnt += pnum[std::cmp::max(0, mid - *a) as usize];
			if cnt >= m {
				l = mid;
				continue 'a;
			}
		}
		r = mid;
	}
	let (lsum, lcnt) = a.iter().fold((0, 0), |r, a| {
		let c = pnum[std::cmp::max(0, l - *a) as usize];
		(r.0 + c as i64 * *a + cum[c], r.1 + c)
	});
	let ans = lsum - (lcnt - m) as i64 * l;
	println!("{}", ans);
}


Measured memory_bytes: 10492
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))

def bs(t,s,e):

    while e-s > 1:
        #print(s,e)
        m = (s+e)//2
        if S[m] <= t:
            s = m
        else:
            e = m
    if S[s] == t or S[e] == t:
        return True
    else:
        return False

ans = 0
for t in T:
    if bs(t,0,n-1):
        ans += 1
print(ans)


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

#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define str string
#define vint vector<int>
#define vvint vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vool vector<bool>
#define vtr vector<str>
#define vvtr vector<vector<str>>
#define pb() pushback
#define elif else if
#define all(x) x.begin(),x.end()

main(){
    int N,X,b,H=0,W=0,count=0,count2=0;
    double d,D;
    int C='A'-'a';
    char op;
    str S,T;
    cin>>N>>X>>S;
    S[X-1]-=C;
    cout<<S<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//コピペするとこ



//-------------------------------------------------


int main()
{
  int n ;
  cin >> n ;
  vector<pair<int,int>> vec(n) ;
  
  REP(i,n){
    int a, b ;
    cin >> a >> b ;
    vec.at(i) = MP(a,b) ;
  }
  
  double sum = 0 ;
  double ans ;
  
  REP(i,n-1){
    FOR(j,i+1,n){
      sum += sqrt((vec.at(i).FI-vec.at(j).FI)*(vec.at(i).FI-vec.at(j).FI)+(vec.at(i).SE-vec.at(j).SE)*(vec.at(i).SE-vec.at(j).SE)) ;
    }
  }
  
  double aa = n*(n-1)/2 ;
  double bb = n-1 ;
  
  ans = sum/aa*bb ;
  
  
  
  cout << SP(10) << ans <<endl;
  

  return 0 ;
}




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

int main(){
    long long N,M,K;
    cin >> N >> M>>K;
    long long A_sub, B_sub;
    long long A[N+1],B[M+1];
    long long i,j;
    A[0]=0;
    B[0]=0;
    for(i=1; i<=N; i++){
        cin >> A_sub;
        A[i]=A[i-1]+A_sub;
    }
    for(i=1; i<=M; i++){
        cin >> B_sub;
        B[i]=B[i-1]+B_sub;
    }
    long long ans=0;
    j=M;
    for(i=1; i<=N; i++){
        while(A[i]+B[j]>K){
            j--;
            if(j<0) break;
        }
        if(j<0) break;
        ans = max(ans,i+j);
    }
    i=N;
    for(j=1; j<=M; j++){
        while(A[i]+B[j]>K){
            i--;
            if(i<0) break;
        }
        if(i<0) break;
        ans = max(ans,i+j);
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	int dp[n+1][3];
	for (int i = 0; i < n+1; ++i)
		for (int j = 0; j < 3; ++j)
			dp[i][j] = 0;
	for(int i = 0; i < n; ++i){
		dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[i];
		dp[i+1][1] = max(dp[i][2], dp[i][0]) + b[i];
		dp[i+1][2] = max(dp[i][0], dp[i][1]) + c[i];
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
	return 0;
}

Measured memory_bytes: 2560
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [D] = string_to_int(inputs[0])
    if D == 22:
        return "Christmas Eve Eve Eve"
    if D == 23:
        return "Christmas Eve Eve"
    if D == 24:
        return "Christmas Eve"
    if D == 25:
        return "Christmas"
    return ""


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


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

int main() {
	int s, w;
	cin >> s >> w;
	string ans = "safe";
	if(w >= s) ans = "unsafe";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <cstdio>

using namespace std;
int i;
long long k,x,y,a[54];
int main()
{
    scanf ("%lld", &k);
    x=(1LL)*k/50;
    y=(1LL)*k%50;
    for (i=1;i<=50;i++)
        a[i]=(0LL)+49+x;
    for (i=1;i<=y;i++)
        a[i]=(0LL)+a[i]+1;
    for (i=(y+1);i<=50;i++)
        a[i]=(0LL)+a[i]-y;
    printf ("%d\n", 50);
    for (i=1;i<=50;i++)
        printf ("%lld ", a[i]);
    printf ("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 100010

int main(){
	IOS;
	tihs;

	ll n;cin>>n;
	n=n%10;
	if(n==2 or n==4 or n==5 or n==7 or n==9)cout<<"hon";
	else if(n==3)cout<<"bon";
	else cout<<"pon";


	return 0;
}

Measured memory_bytes: 3612
<?php
// 入力
$s = trim(fgets(STDIN));

$n = strlen($s);

// 答え出力用配列に0格納
$ans = array_fill(0, $n, 0);

// 計算
$top = 0;
while($top < $n) {
    if ($s[$top] === 'R') $next = 'L';
    else $next = 'R';

    $next_top = strpos($s, $next, $top);

    if (!$next_top) $next_top = $n;

    $cnt = $next_top - $top;

    if ($s[$top] === 'R') {
        $x0 = $top + $cnt - 1;
        $x1 = $x0 + 1;
    } else {
        $x0 = $top;
        $x1 = $x0 - 1;
    }
    $ans[$x0] += ceil($cnt / 2);
    $ans[$x1] += floor($cnt / 2);

    $top = $next_top;
}

// 出力
echo implode(' ', $ans).PHP_EOL;

Measured memory_bytes: 35576
#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
typedef pair<int, int> P;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    map<P, int> mp;
    P c1[100010], c2[100010];
    rep(i, m) {
        cin >> c1[i].first >> c1[i].second;
        c2[i] = c1[i];
    }
    sort(c2, c2 + m);
    int k = 1;
    rep(i, m) {
        if(i > 0 && c2[i].first != c2[i - 1].first) k = 1;
        mp[c2[i]] = k++;
    }
    rep(i, m) {
        cout << setfill('0') << right << setw(6) << c1[i].first; 
        cout << setfill('0') << right << setw(6) << mp[c1[i]] << endl;
    }


    return 0;
}


Measured memory_bytes: 11392
#include<stdio.h>
int main()
{
    int days,ans = 0;
    int dp[1100][8] = {0};
    char sign;
    scanf("%d",&days);
    for(int i = 0; i < 4; i++)dp[0][i] = -1;
    for(int i = 0; i < days; i++)
    {
        dp[i][0] = -1;
        scanf(" %c",&sign);
        if(sign == 'J')
        {
            dp[i][1] = -1;dp[i][2] = -1;dp[i][3] = -1;
        }
        if(sign == 'O')
        {
            dp[i][1] = -1;dp[i][4] = -1;dp[i][5] = -1;
        }
        if(sign == 'I')
        {
            dp[i][2] = -1;dp[i][4] = -1;dp[i][6] = -1;
        }
    }
    for(int i = 0; i < days; i++)
        for(int j = 0; j < 8; j++)
        {
            if(dp[i][j] == -1)dp[i][j] = 0;
            else if(i == 0)dp[i][j] = 1;
            else if(j == 1)
                dp[i][j] = (dp[i - 1][1] + dp[i - 1][3] + dp[i - 1][5] + dp[i - 1][7]) % 10007;
            else if(j == 2)
                dp[i][j] = (dp[i - 1][2] + dp[i - 1][3] + dp[i - 1][6] + dp[i - 1][7]) % 10007;
            else if(j == 3)
                dp[i][j] = (dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3] + dp[i - 1][5] + dp[i - 1][6] + dp[i - 1][7]) % 10007;
            else if(j == 4)
                dp[i][j] = (dp[i - 1][4] + dp[i - 1][5] + dp[i - 1][6] + dp[i - 1][7]) % 10007;
            else if(j == 5)
                dp[i][j] = (dp[i - 1][1] + dp[i - 1][3] + dp[i - 1][4] + dp[i - 1][5] + dp[i - 1][6] + dp[i - 1][7]) % 10007;
            else if(j == 6)
                dp[i][j] = (dp[i - 1][2] + dp[i - 1][3] + dp[i - 1][4] + dp[i - 1][5] + dp[i - 1][6] + dp[i - 1][7]) % 10007;
            else if(j == 7)
                dp[i][j] = (dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3] + dp[i - 1][4] + dp[i - 1][5] + dp[i - 1][6] + dp[i - 1][7]) % 10007;
        }/*for(int i = 0; i < 8; i++)
    {
        for(int j = 0; j < days; j++)
        {
            printf("%2d",dp[j][i]);
        }
        printf("\n");
    }*/
    for(int i = 0; i < 8; i++)
        ans = ans + dp[days - 1][i];
    printf("%d\n",ans % 10007);
    return 0;
}

Measured memory_bytes: 2792
var readline = require('readline')
var reader = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

var lines = [];
reader.on('line', function(line) {
  lines.push(line);
});

reader.on('close', function() {
  var words = lines[0].split(' ');
  var N = Number(words[0]), M = Number(words[1]);
  var A = [];
  var B = [1];

  for(var i=0; i<N; ++i) A.push(true);

  for(var i=0; i<M; ++i) A[Number(lines[i+1])-1] = false;

  var mod = 1000000007;

  if(!A[0]) { B.push(0); }
  else { B.push(1); }

  for(var i=1; i<N; ++i) {
    if(!A[i]) { B.push(0); continue; }
    B.push((B[B.length-2]+B[B.length-1])%mod);
  }

  console.log(B[B.length-1]);

});

Measured memory_bytes: 26720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int main(){
  int N;
  cin >> N ;
  int num = 0;
  for(int i=1;i<=N;i++){
    int a; cin >> a;
    if(a==num+1) num++;
  }
  if(num==0) cout << -1 << endl;
  else cout << N-num << endl;
}

Measured memory_bytes: 3628
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
import collections
from heapq import *
#RRR...WWW...にしたい
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
S=[list(input()) for _ in range(H)]
#print(S)
dp=[[float("inf") for _ in range(W)] for _ in range(H)]
st=[Ch-1,Cw-1]
d2=deque()
d = deque()
d2=deque()
d.append(st)
cnt=0
dp[Ch-1][Cw-1]=0
while True:
    while len(d)>0:
        x,y=d.popleft()
        d2.append([x,y])
        #print(dp[x][y],dp[x+1][y],dp[x][y+1])
        if x!=0:
            if S[x-1][y]==".":
                if dp[x-1][y]>dp[x][y]:
                    dp[x - 1][y]=dp[x][y]
                    d.append([x-1,y])
        if x!=H-1:
            if S[x+1][y]==".":
                if dp[x+1][y]>dp[x][y]:
                    dp[x + 1][y]=dp[x][y]
                    d.append([x+1,y])
        if y!=0:
            if S[x][y-1]==".":
                if dp[x][y-1]>dp[x][y]:
                    dp[x][y-1]=dp[x][y]
                    d.append([x,y-1])
        if y!=W-1:
            if S[x][y+1]==".":
                if dp[x][y+1]>dp[x][y]:
                    dp[x][y+1]=dp[x][y]
                    d.append([x,y+1])
        #print(dp,d,d2)
        #input()
    while len(d2)>0:
        x,y=d2.popleft()
        for i in range(max(0,x-2),min(x+3,H)):
            for j in range(max(0,y-2),min(y+3,W)):
                if S[i][j]==".":
                    if dp[i][j] > dp[x][y]+1:
                        dp[i][j]=dp[x][y]+1
                        d.append([i,j])
    #print(dp)
    #input()
    cnt=cnt+1
    if len(d)==0:
        break
if dp[Dh-1][Dw-1]==float("inf"):
    print(-1)
else:
    print(dp[Dh-1][Dw-1])


Measured memory_bytes: 155108
import math

N=int(input())
n = N**0.5

if n % 1 == 0:
  print(math.floor(2* n -2))
else:
  n = int(round(n, 0))
  while N % n != 0 :
    n = n - 1
  b = N / n
  print(math.floor(n + b -2))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    string S;
    cin >> S;
    static const long long N = S.size();
    static const long long mod = 2019;
    vector<long long> num(N); // 各桁の数字(左から0番目, 1番目, ...)
    for (long long i = 0; i < N; ++i)
    {
        num[i] = S[i] - '0';
    }
    vector<long long> t(N + 1, 0);
    vector<long long> cnt(mod, 0);
    cnt[0] = 1;
    long long dig = 1;
    for (long long i = N - 1; i >= 0; --i)
    {
        t[i] = t[i + 1] + num[i] * dig;
        t[i] = (t[i] + mod) % mod;
        ++cnt[t[i]];
        dig *= 10;
        dig = (dig + mod) % mod;
    }
    long long ans = 0;
    for (long long c : cnt)
    {
        ans += c * (c - 1LL)/2LL;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    ll n;
    cin >> n;
    map<ll, ll> m;
    ll sum = 0;
    rep (i, n) {
        ll p;
        cin >> p;
        m[p]++;
        sum += p;
    }
    int q;
    cin >> q;
    rep (i, q) {
        ll b, c;
        cin >> b >> c;
        int d = m[b];
        sum -= d * b;
        sum += d * c;
        m[b] = 0;
        m[c] += d;
        cout << sum << endl;
    }
}




Measured memory_bytes: 9588
#include<map>
#include<set>
#include<cmath>
#include<regex>
#include<queue>
#include<stack>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>

#pragma warning(disable:4996)
using namespace std;

constexpr int MAXN = 100005;

int N;
int A;
int B;
int var[MAXN];

int main() {
	scanf("%d%d%d", &N, &A, &B);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &var[i]);
	}
	long long tempAns = 0;
	for (int i = 2; i <= N; ++i) {
		long long dis = (long long)(var[i] - var[i - 1]) * A;
		tempAns = tempAns + min(dis, (long long)B);
	}
	printf("%lld\n", tempAns);
	return 0;
}

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

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

    // solve
    int a[26] = {0};
    for (int i = 0; i < S.length(); ++i) {
        a[S[i] - 'a']++;
    }
    bool flag = false;
    for (int i = 0; i < 26; ++i) {
        if (a[i] >= 2) flag = true;
    }

    // output
    cout << (flag ? "no" : "yes") << endl;

    return 0;
}


Measured memory_bytes: 764
#![allow(unused_imports)]pub mod pcl{pub mod stdin{use std::io::prelude::*;use std::io::stdin;use std::str::FromStr;pub fn read_line()->String{let mut s=String::new();stdin().read_line(&mut s).unwrap();s.trim().to_string()}pub fn read<T:FromStr>()->T{read_from(stdin())}pub fn read_token()->String{read_token_from(stdin())}pub fn read_ascii()->char{read_ascii_from(stdin())}pub fn read_from<R:Read,T:FromStr>(read:R)->T{read_token_from(read).parse().unwrap_or_else(|_|panic!("failed to parse a value"))}pub fn read_token_from<R:Read>(read:R)->String{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).take_while(|x|!x.is_whitespace()).collect()}pub fn read_ascii_from<R:Read>(read:R)->char{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).next().expect("failed to get a next character")}}}
use pcl::stdin::*;
fn main() {
    let n: usize = read();
    println!("{}", (n + 1) / 2);
}



Measured memory_bytes: 4352
#!/usr/bin/env python3
import sys


def solve(N: int):
    n = N % 10
    if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
        print("hon")
    elif n == 0 or n == 1 or n == 6 or n == 8:
        print("pon")
    else:
        print("bon")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61740
#include<cstdio>
#define pritnf printf
#define scnaf scanf
#define retrun return
#define sizoef sizeof
#define inl inline
#define br break
#define con continue
#define mst(a,b) memset(a,b,sizeof(a))
#define fora(x,a,b) for(re nti (x)=(a);(x)<=(b);++(x))
#define forb(x,a,b) for(re nit (x)=(a);(x)>=(b);--(x))
#define re register
#define stt struct
#define infa (0x3f3f3f3f)
#define infb (0x7fffffff)
#define infd (0x7f)
#define abss(x) ((x)>(0)?(x):(-1)*(x))
#define maxx(a,b) ((a)>(b)?(a):(b))
#define minn(a,b) ((a)<(b)?(a):(b))
#define pf(_) ((_)*(_))
#define in(a) freopen("D:/""/in"a".in","r",stdin)
#define out(a) freopen("D:/""/out"a".out","w",stdout)
typedef long long ll;
typedef int itn,nti,tin,tni,nit;
using namespace std;
const nit maxa=10004;
const nit maxb=1e2;
const nit maxc=5;

char x;
tni n,dq=0,ans=0;

tin main()
{
	//in("1");
	//
	scanf("%d\n",&n);
	fora(i,1,n)
	{
		x=getchar();
		if(x=='I')
		{
			++dq;
		}
		else if(x=='D')
		{
			--dq;
		}
		//
		if(dq>ans)
		{
			ans=dq;
		}
	}
	//
	pritnf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)             \
    do {                         \
        cout << #args << " -> "; \
        err(args);               \
    } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
    std::cout << a << ' ';
    err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &... args) {
    for (auto &v : arg)
        std::cout << v << ' ';
    err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII   = pair<int, int>;

// Global Const Variable
const int64 INF  = 0x3f3f3f3f3f3f3f3f;
const int MOD  = 1000000007;
const int MAXN = 200005;
const int MAXL = 1000;

int v[MAXN], w[MAXN], dp[MAXN][MAXL];

void run() {
    int x,y;
    cin >> x >> y;
    int b = y-2*x;
    if((b&1) || b<0 || b>2*x) cout << "No" << endl;
    else cout << "Yes" << endl;
}

// Debug Input Redirection
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    run();
}

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

double dp[3003][3003], p[3003], q[3003];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lf", &p[i]);
		q[i] = 1 - p[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0] * q[i];
		dp[i][i] = dp[i - 1][i - 1] * p[i];
		for (int j = 1; j < i; j++) {
			dp[i][j] = dp[i - 1][j] * q[i] + dp[i - 1][j - 1] * p[i];
		}
	}
    double ans = 0;
    for (int i = n/2 + 1; i<=n; i++){
        ans += dp[n][i];
    }
    printf("%.10lf", ans);
}

Measured memory_bytes: 68992
/* ex3_2
  bonbonc */

#include<stdio.h>

int main(void){

	int number;

	
	scanf("%d",&number);
	number%=10;		/*1の位を取り出す*/
	switch (number){	/*場合分け*/
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			printf("hon\n");
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			printf("pon\n");
			break;
		case 3:
			printf("bon\n");
			break;
	}
	
	return 0;
}

Measured memory_bytes: 1620
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        //input
        int n = Integer.parseInt(br.readLine());
        int[][] point = new int[n][2];
        double[][] dis = new double[n][n];

        //init
        for(int i = 0; i < n; i++){
          Arrays.fill(dis[i], -1);
        }

        // for algorithm
        double tmp = 0.0;
        double result = 0.0;
        int count = 0;
        double div = (double)2/n;

        for(int i = 0; i < n; i++){
          String[] str = br.readLine().split(" ");
          point[i][0] = Integer.parseInt(str[0]);
          point[i][1] = Integer.parseInt(str[1]);
        }

        for(int i = 0; i < n; i++){
          for(int j = i + 1; j < n; j++){
            tmp = Math.pow((double)(point[i][0]-point[j][0]), 2.0) + Math.pow((double)(point[i][1]-point[j][1]), 2.0);
            dis[i][j] = Math.sqrt(tmp);
          }
        }

        // algorithm
        for(int i = 0; i < n; i++){
          for(int j = 0; j < n; j++){
            if(dis[i][j] == -1.0){
              continue;
            }else{
               result += dis[i][j];
               count++;
            }
          }
        }
        
        System.out.println(result * div);
        
      }
    }
}

Measured memory_bytes: 23124
import java.util.*;
class Main{
  public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	int K = stdIn.nextInt();
    int X = stdIn.nextInt();
    for(int i=X-K+1;i<X+K;i++){
      System.out.print(i+" ");
    }
    System.out.println("");
  }
}

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// ????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		// ??£?¨?
		String line = "";
		char temp;
		// 26???????????¨?????????
		int[] array = new int[26];
		while (sc.hasNext()) {
			// ??±????????????
			line = sc.nextLine();
			// ??¨???????????????????°??????????????????????
			String lower = line.toLowerCase();
			// System.out.println(lower);
			// ?????????char ??????
			for (int i = 0; i < lower.length(); i++) {
				temp = lower.charAt(i);
				// System.out.println(temp);
				// ??\?????????????????¨a?????¢???????????????????????°?????§??????
				// if(Character.isLetter('a')){
				if ('a' <= temp && temp <= 'z') {
					array[temp - 'a']++;
				}
			}
		}
		for (int i = 0; i < array.length; i++) {
			System.out.println((char) ('a' + i) + " : " + array[i]);
		}
	}
}

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

int main() {
    string s, t, ans;
    int mlen;

    cin >> s;
    cin >> t;

    int dp[t.size() + 1][s.size() + 1];

    for (int j = 0; j < t.size() + 1; j++) {
        for (int i = 0; i < s.size() + 1; i++) {
            dp[j][i] = 0;
        }
    }

    for (int j = 1; j < t.size() + 1; j++) {
        for (int i = 1;i < s.size() + 1; i++) {
            if (s[i - 1] == t[j - 1]) {
                dp[j][i] = dp[j - 1][i - 1] + 1;
                dp[j][i] = max(dp[j][i], dp[j - 1][i]);
                dp[j][i] = max(dp[j][i], dp[j][i - 1]);
            }
            else{
                dp[j][i] = max(dp[j - 1][i], dp[j][i - 1]);
            }
        }
    }    

    ans = "";
    int i = s.size();
    int j = t.size();
    mlen = dp[j][i];

    while (mlen > 0) {
        while (dp[j][i - 1] == dp[j][i]) {
            i--;
        }
        
        while (dp[j - 1][i] == dp[j][i]) {
            j--;
        }

        ans += s[i - 1];
        i--;
        j--;
        mlen--;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;





    // for (int j = 1; j < t.size() + 1; j++) {
    //     for (int i = left; i < s.size() + 1; i++) {
    //         if (dp[j][i] > mlen) {
    //             ans += s[i - 1];
    //             // cout << ans << endl;
    //             mlen = dp[j][i];
    //             left = i;
    //             cout << left << endl;
    //         }
    //     }
    // }
    // cout << ans << endl;

    // for (int j = 0; j < t.size() + 1; j++) {
    //     for (int i = 0; i < s.size() + 1; i++) {
    //         cout << i << "," << j << " " << dp[j][i] << endl;
    //     }
    // }
}



Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  Int dp[20][4][2][2][10];
  memset(dp,-1,sizeof(dp));
  function<Int(Int,Int,Int,Int,Int)> dfs=
    [&](Int pos,Int st,Int ok,Int lim,Int pre){
    if(pos==n) return ok;
    Int &res=dp[pos][st][ok][lim][pre];
    if(~res) return res;
    res=0;
    for(Int i=0;i<=(lim?s[pos]-'0':9);i++){
      Int nlim=lim&&(i==s[pos]-'0');
      if(st==0&&i==5){
	res+=dfs(pos+1,1,ok,nlim,i);
      }else if(st==1&&i==1){
	res+=dfs(pos+1,2,ok,nlim,i);
      }else if(st==2){
	res+=dfs(pos+1,3,ok,nlim,i);
      }else if(st==3){
	if(i==3) res+=dfs(pos+1,0,1,nlim,i);
	else if(pre==5&&i==1) res+=dfs(pos+1,2,ok,nlim,i);
	else res+=dfs(pos+1,i==5,ok,nlim,i);
      }else res+=dfs(pos+1,i==5,ok,nlim,i);
    }
    //cout<<pos<<" "<<st<<" "<<ok<<" "<<lim<<" "<<pre<<":"<<res<<endl;
    return res;
  };
  cout<<dfs(0,0,0,1,0)<<endl;
  return 0;
}



Measured memory_bytes: 3232
n,m=gets.chomp.split(" ").map(&:to_i);
arr = []
n.times do 
  arr.push(2)
end
m.times do 
  arr.push(1)
end
ans = 0
arr.each_with_index do |num,i|
  j = i
  while j < arr.size - 1
    if (num + arr[j + 1]).even?
      ans += 1
    end
    j += 1
  end
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

typedef vector<pair<int, int>> FACTORS;

class Sieve {
public:
    Sieve(int size) : sieve(size+1) {
        sieve[0] = -1;
        sieve[1] = -1;
        for (int i = 2; i <= size; ++i) {
            if (!sieve[i]) {
                sieve[i] = i;
                for (LL j = (LL) i * i; j <= (LL) size; j += i) {
                    if (!sieve[j]) {
                        sieve[j] = i;
                    }
                }
            }
        }
    }

    bool isPrime(int x) {
        return (sieve[x] == x);
    }

    void getFactors(int x, vector<int>& out) {
        while (1 < x) {
            int f = sieve[x];
            out.push_back(f);
            x /= f;
        }
    }

    void factorize(int x, FACTORS& factors) {
        vector<int> fs;
        getFactors(x, fs);
        if (!fs.empty()) {
            factors.push_back({fs[0], 0});            
            for (int f: fs) {
                if (factors.back().first != f) {
                    factors.push_back({f, 0});        
                }
                ++factors.back().second;
            }
        }
    }

private:
    vector<int> sieve;
};

template<typename T>
T gcd(T a, T b) 
{
    if (b < a) { //! make sure a <= b
        T tmp = b;
        b = a;
        a = tmp;
    }

    T r = b % a;
    while (r) {
        b = a;
        a = r;
        r = b % a;
    }

    return a;
}

//! return lcm of a and b
template<typename T>
T lcm(T a, T b) 
{
    return a * b / gcd<T>(a, b);
}

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

    Sieve sv(1000001);

    int allGcd = -1;
    map<int, int> allLcmFactors;
    map<int, int> allProFactors;
    int N;
    cin >> N;
    rep(i, N) {
        int A;
        cin >> A;

        if (allGcd < 0) {
            allGcd = A;
        } else if (1 < allGcd) {
            allGcd = gcd(allGcd, A);
        }

        FACTORS fs;
        sv.factorize(A, fs);
        for (auto f: fs) {
            allLcmFactors[f.first] = max(allLcmFactors[f.first], f.second);
            allProFactors[f.first] += f.second;
        }
    }

    if (allGcd == 1) {
        bool pairwiseCoprime = true;
        for (auto it: allLcmFactors) {
            if (allLcmFactors[it.first] != allProFactors[it.first]) {
                pairwiseCoprime = false;
                break;
            }
        }
        if (pairwiseCoprime) {
            cout << "pairwise coprime" << endl;
        } else {
            cout << "setwise coprime" << endl;
        }
    } else {
        cout << "not coprime" << endl;
    }

    return 0;
}


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

int main() {
  IN(ll, N);
  vector<ll> A(N);
  ll mod = 1000000007;
  REP(i, N) {
    IN(ll, tmp);
    tmp %= mod;
    A.at(i) = tmp;
  }

  ll ans = 0;
  ll sum = A.at(N - 1);
  for (int i = N - 2; i >= 0; --i) {
    ans += sum * A.at(i);
    ans %= mod;
    sum += A.at(i);
    sum %= mod;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  string n;
  cin >> n;
  for (int i = 0; i < n.size(); i++) {
    if (n.at(i) == '1') {
      n.at(i) = '9';
    }
    else if (n.at(i) == '9') {
      n.at(i) = '1';
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
ans = 0
for a, b in ab_list:
    if b >= m:
        print(ans + a * m)
        exit()
    else:
        ans += a * b
        m -= b


Measured memory_bytes: 29792
import java.util.*;
import java.math.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int i,n,x[]=new int[10004];
		BigInteger tmp,ans,y[]=new BigInteger[10004];

		while(true){
			n = scan.nextInt();
			if(n == 0) break;

			for(i=0;i<n;i++) x[i] = scan.nextInt();
			Arrays.sort(x,0,n);
			tmp = new BigInteger("0");
			ans = new BigInteger("0");
			for(i=0;i<n;i++){
				y[i] = new BigInteger(Integer.toString(x[i]));
			}
			for(i=0;i<n-1;i++){
				tmp = tmp.add(y[i]);
				ans = ans.add(tmp);
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 13000
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define fi first
#define se second
#define pp pop_back
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define rep(x, a, b) for(int x=a; x<=b; x++)
#define drp(x, a, b) for(int x=a; x>=b; x--)
typedef long long ll;
const int N=500500;
priority_queue<int> q;
int n, k, a[N], p[N], tree[N], tag[N<<2], d[N];
pair<int, int> mn[N<<2];
ll read(){
	ll x=0; char ch=getchar();
	while(ch<'0' || ch>'9') ch=getchar();
	while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0', ch=getchar();
	return x;
}
void write(ll x){
	if(x<10)
	{
		putchar(x+'0');
		return;
	}
	write(x/10);
	putchar(x%10+'0');
}
void update(int x, int v){
	for(; x<=n; x+=x&-x) tree[x]+=v;
}
int query(int x){
	int ret=0;
	for(; x; x-=x&-x) ret+=tree[x];
	return ret;
}
void build(int rt, int l, int r){
	if(l==r)
	{
		mn[rt]=mp(d[l], -l);
		return;
	}
	build(rt<<1, l, mid);
	build(rt<<1|1, mid+1, r);
	mn[rt]=min(mn[rt<<1], mn[rt<<1|1]);
}
void down(int rt){
	mn[rt<<1].fi-=tag[rt]; tag[rt<<1]+=tag[rt];
	mn[rt<<1|1].fi-=tag[rt]; tag[rt<<1|1]+=tag[rt];
	tag[rt]=0;
}
void update(int rt, int l, int r, int p){
	if(l==r)
	{
		mn[rt]=mp(1e9, -l);
		return;
	}
	down(rt);
	if(p<=mid) update(rt<<1, l, mid, p);
	else update(rt<<1|1, mid+1, r, p);
	mn[rt]=min(mn[rt<<1], mn[rt<<1|1]);
}
void modify(int rt, int l, int r, int L, int R){
	if(l>=L && r<=R)
	{
		mn[rt].fi--;
		tag[rt]++;
		return;
	}
	down(rt);
	if(L<=mid) modify(rt<<1, l, mid, L, R);
	if(R>mid) modify(rt<<1|1, mid+1, r, L, R);
	mn[rt]=min(mn[rt<<1], mn[rt<<1|1]);
}
int main(){
	scanf("%d%d", &n, &k);
	rep(i, 1, n) scanf("%d", a+i), p[a[i]]=i;
	drp(i, n, 1)
	{
		d[p[i]]=query(min(p[i]+k-1, n))-query(max(p[i]-k+1, 1)-1);
		update(p[i], 1);
	}
	rep(i, 1, n) if(!d[i]) q.push(i), d[i]=1e9;
	build(1, 1, n);
	memset(a, 0, sizeof a);
	rep(i, 1, n)
	{
		int u=q.top(); q.pop();
		a[u]=n-i+1;
		modify(1, 1, n, max(u-k+1, 1), min(u+k-1, n));
		while(!mn[1].fi)
		{
			q.push(-mn[1].se);
			update(1, 1, n, -mn[1].se);
		}
	}
	rep(i, 1, n) printf("%d\n", a[i]);
}

Measured memory_bytes: 30704
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//


int s[20][20];

int main() {

    int N, M; cin >> N >> M;
    vector<int> k(M);
    rep(i,M) {
        cin >> k[i];
        rep(j,k[i]) cin >> s[i][j];
    }
    vector<int> p(M);
    rep(i,M) cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1<<N); ++bit) {
        bool flag = true;
        for (int i = 0; i < M; ++i) {
            int sum = 0;
            for (int j = 0; j < k[i]; ++j) {
                if (bit & (1<<(s[i][j]-1))) ++sum;
            }
            if (sum % 2 != p[i]) flag = false; 
        }
        if (flag) ++ans;
    }

    out(ans);

    return 0;
}






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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string s; cin >> s;
    int n = s.length();

    for (char c = 'a'; c <= 'z'; c++) {
        bool flag = true;
        for (int i = 0; i < n; i++) {
            if (s[i] == c) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M,X,j,z;
    cin>>N>>M>>X;
    j=0;
    z=0;
    vector<int>a(M);
    for(int i=0;i<M;i++){
        cin>>a.at(i);
    }
    for(int i=0;i<M;i++){
        if(a.at(i)<X){
            j++;
        }
        else if(a.at(i)==X){
            z++;
        }
        else{
            break;
        }
    }
    if(z==0){
        if(M-j>M/2){
            cout<<j<<endl;
        }
        else{
            cout<<M-j<<endl;
        }
    }
    else{
        if(M-j>(M-1)/2){
            cout<<j<<endl;
        }
        else{
            cout<<M-j<<endl;
        }
    }

}

Measured memory_bytes: 256
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A = str(input())
B = str(input())
ans = [str(i) for i in range(1,4)]

ans.remove(A)
ans.remove(B)
print(ans[0])


Measured memory_bytes: 10664
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int X[7]={0,-1,0,1,-1,0,1};
int Y[7]={0,-1,-1,0,0,1,1};

bool in(int h,int w,int size){
  if(h<0 || w<0 || size<=h || h<w)return false;
  return true;
}

int Search(vector<vector<int> > V,int h,int w,int c){
  int res=0; 
  bool B[11][11]={};
  V[h][w]=c;
  for(int k=0;k<7;k++){
    queue<pair<pair<int,int>,int> > Q;
    int a=h+Y[k],b=w+X[k];
    bool flag=true;
    int count=1;
    if(!in(a,b,V.size()))continue;
    if(B[a][b])continue;
    Q.push(make_pair(make_pair(a,b),V[a][b]));
    B[a][b]=true;

    while(!Q.empty()){
      pair<pair<int,int>,int> u=Q.front();
      Q.pop();
      for(int k=1;k<7;k++){
	int c=u.f.f+Y[k],d=u.f.s+X[k];
	if(!in(c,d,V.size()))continue;
	if(V[c][d]==0)flag=false;
	if(B[c][d])continue;
	if(V[c][d]!=u.s)continue;
	count++;
	B[c][d]=true;
	Q.push(make_pair(make_pair(c,d),u.s));
      }
    }
    if(flag && V[a][b]!=0){
      if(k==0)res-=count;
      else res+=count;
    }
  }
  return res;
}
int main()
{
  vector<vector<int> > V;
  int n,c,a;

  while(1){
    cin>>n>>c;
    if(n+c==0)break;
    V.clear();
    V.resize(n);
    for(int i=0;i<n;i++){
      for(int j=0;j<i+1;j++){
	cin>>a;
	V[i].push_back(a);
      }
    }
    int ans=-10000000;
    for(int i=0;i<n;i++){
      for(int j=0;j<i+1;j++){
	if(V[i][j]==0){
	  ans=max(Search(V,i,j,c),ans);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
while t = gets
	t = t.split.map &:to_f
	ax = [t[0],t[2]].sort
	bx = [t[4],t[6]].sort
	ay = [t[1],t[3]].sort
	by = [t[5],t[7]].sort
	if bx[0].between?(ax[0], ax[1]) || bx[1].between?(ax[0], ax[1])
		if by[0].between?(ay[0], ay[1]) || by[1].between?(ay[0], ay[1])
			puts "YES"
		elsif ay[0].between?(by[0], by[1])
			puts "YES"
		else
			puts "NO"
		end
	elsif ax[0].between?(bx[0], bx[1])
		if by[0].between?(ay[0], ay[1]) || by[1].between?(ay[0], ay[1])
			puts "YES"
		elsif ay[0].between?(by[0], by[1])
			puts "YES"
		else
			puts "NO"
		end
	else
		puts "NO"
	end
end

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

int main() {
  int N;
  cin >> N;
  map<string, int> mp;

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    mp[s]++;
  }

  cout << mp.size() << endl;
}

Measured memory_bytes: 19120
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    int ant[5];
    ant[0] = a;
    ant[1] = b;
    ant[2] = c;
    ant[3] = d;
    ant[4] = e;

    bool flag = true;

    for (int i = 0; i < 5; ++i)
    {
        for (int j = i + 1; j < 5; ++j)
        {
            //            cout << ant[j] << " " << ant[i] << endl;
            if (ant[j] - ant[i] > k)
            {
                flag = false;
                break;
            }
        }
    }

    if (flag)
    {
        cout << "Yay!" << endl;
    }

    else
    {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc162/tasks/abc162_d
// math
import std.conv;
import std.stdio;
import std.string;

void main() {
    int n = readln.chomp.to!int;
    string s = readln.chomp;

    long[char] rgb;
    rgb['R'] = 0L;
    rgb['G'] = 0L;
    rgb['B'] = 0L;

    foreach(ch; s)
        rgb[ch] += 1L;

    long first = rgb['R']*rgb['G']*rgb['B'];

    if(first == 0L) {
        "0".writeln;
        return;
    }

    long not_second = 0L;

    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            int k = 2*j - i;

            if(k > n-1)
                continue;

            if(s[i] == s[j] || s[i] == s[k] || s[j] == s[k])
                continue;

            not_second += 1L;
        }
    }

    writefln("%s", first-not_second);
}



Measured memory_bytes: 2804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int n, c=0, ans=0, f[100005];
pair<int, int> x[100005], y[100005];
pair<int, pair<int, int> > a[200010];

int find(int x) {
    return f[x] != x ? f[x] = find(f[x]) : x;
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> x[i].first >> y[i].first;
        x[i].second = y[i].second = i;
        f[i] = i;
    }

    sort(x, x+n);
    sort(y, y+n);

    for (int i = 1; i < n; i++) {
        a[c++] = make_pair(x[i].first - x[i-1].first, make_pair(x[i].second, x[i-1].second));
        a[c++] = make_pair(y[i].first - y[i-1].first, make_pair(y[i].second, y[i-1].second));
    }

    sort(a, a+c);

    for (int i = 0; i < c; i++) {
        if (find(a[i].second.first) != find(a[i].second.second)) {
            f[find(a[i].second.first)] = find(a[i].second.second);
            ans += a[i].first;
        }
    }

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

Measured memory_bytes: 4480
while 1:
    n, m = map(int, raw_input().split())
    if not n or not m:
        break
    wantList = [0] * m
    for i in range(n):
        place = map(int, raw_input().split())
        for i, want in enumerate(place):
            if want:
                wantList[i] += 1
    ret = sorted(range(m), key=lambda k: wantList[k], reverse=True)
    ret = map(lambda x: x + 1, ret)
    print reduce(lambda a, b: str(a) + " " + str(b), ret)

Measured memory_bytes: 4360
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
 
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        String relation;
 
        if(a > b){
            relation = ">";
        }else if(a < b){
            relation = "<";
        }else{
            relation = "==";
        }
 
        System.out.printf("a %s b\n", relation);
    }
}


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int n;
string s;

int main(){
  cin >> n >> s;
  int r=0,b=0;
  rep(i,n){
    if(s[i]=='R')r++;
    else b++;
  }
  if(r>b)cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main() {
  int A, B,C,D;
  string op;
  cin >> A >>B>>C>>D;

if(A+B>C+D){
  cout<<"Left"<<endl;
}
  else if(A+B==C+D)
    cout<<"Balanced" ;
  else
    cout<<"Right";
}

Measured memory_bytes: 384
import heapq
n, m = [int(i) for i in input().split()]
ab = []
for _ in range(n):
    a, b = [int(i) for i in input().split()]
    ab.append([a, -b])
ab.sort()
j = 0
ans=0
h = []
for i in range(1, m + 1):
    while j<n and ab[j][0] <= i:
        heapq.heappush(h, ab[j][1])
        j += 1
    if h:
        ans += heapq.heappop(h)
print(-ans)


Measured memory_bytes: 20776