akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MAX_N 111111
typedef long long int ll;
int W,H;int N;
ll A[MAX_N];ll B[MAX_N];
int main()
{
	scanf("%d%d%d",&W,&H,&N);
	for(int i=0;i<N;i++){
		scanf("%lld%lld",&A[i],&B[i]);
	}
	if(N&1){
		int n=N/2;ll x,y;vector<ll>X,Y;
		for(int i=0;i<N;i++){
			X.pb(A[i]);
			Y.pb(B[i]);
		}
		sort(X.begin(),X.end());
		sort(Y.begin(),Y.end());
		x=X[n];y=Y[n];
		ll ans=0;
		ll M=0;
		for(int i=0;i<N;i++){
			M=max(M,abs(x-A[i])+abs(y-B[i]));
			ans+=abs(x-A[i]);ans+=abs(y-B[i]);
		}
		printf("%lld\n%lld %lld\n",2*ans-M,x,y);
	}
	else{
		int n=(N-1)/2;ll x[2],y[2];vector<ll>X,Y;
		for(int i=0;i<N;i++){
			X.pb(A[i]);
			Y.pb(B[i]);
		}
		sort(X.begin(),X.end());
		sort(Y.begin(),Y.end());
		for(int i=0;i<2;i++){
			x[i]=X[n+i];y[i]=Y[n+i];
		}
		ll ans[4]={0};
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				ll M=0;
				for(int i=0;i<N;i++){
					M=max(abs(x[j]-A[i])+abs(y[k]-B[i]),M);
					ans[j*2+k]+=abs(x[j]-A[i]);ans[j*2+k]+=abs(y[k]-B[i]);
				}
				ans[j*2+k]*=2;
				ans[j*2+k]-=M;
			}
		}
		ll C=min(min(ans[0],ans[1]),min(ans[2],ans[3]));
		printf("%lld\n",C);
		for(int i=0;i<4;i++){
			//printf("ans[%d]=%lld\n",i,ans[i]);
			if(C==ans[i]){
				printf("%lld %lld\n",x[i/2],y[i%2]);
				break;
			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 6332
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPLL(i, n) for(ll i = 0;i < (n);++i)

#define endl "\n"
#define pb push_back
#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, K; cin >> n >> K;
	ll x[50], y[50], ans = 5000000000000000000;
	vector<ll> xary, yary;
	REP(i, n){
		cin >> x[i] >> y[i];
		xary.pb(x[i]); yary.pb(y[i]);
	}
	sort(ALL(xary)); sort(ALL(yary));
	REP(i, n){
		for (int j = i+1; j < n; j++) {
			REP(k, n){
				for (int l = k+1; l < n; l++) {
					ll left=xary[i], right=xary[j], down=yary[k], up=yary[l];
					int cnt = 0;
					REP(m, n){
						if(x[m]>=left && x[m]<=right && y[m]>=down && y[m]<=up) cnt++;
					}
					if(cnt >= K){
						if((right-left)*(up-down) < ans) cerr << cnt << endl;
						ans = min(ans, (right-left)*(up-down));
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;
int n,k,a[100005];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	int sum=0;
	for(int i=n;i>=n-k+1;i--)
	sum+=a[i];
	cout<<sum<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=0;
	if(a==0&&b==0)
	{
		cout<<"0"<<endl;
		return 0;
	 } 
	ll m=n%(a+b);
	if(m>=a)
	{
		ans=a;
	}
	else
	{
		ans=m;
	}
	cout<<n/(a+b)*a+ans<<endl;
	return 0;
}

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

 
int main(){
 int N;
 cin>>N;
 if(N>=400)if(N<600)cout<<8<<endl;
 if(N>=600)if(N<800)cout<<7<<endl;
 if(N>=800)if(N<1000)cout<<6<<endl;
 if(N>=1000)if(N<1200)cout<<5<<endl;
 if(N>=1200)if(N<1400)cout<<4<<endl;
 if(N>=1400)if(N<1600)cout<<3<<endl;
 if(N>=1600)if(N<1800)cout<<2<<endl;
 if(N>=1800)if(N<2000)cout<<1<<endl;
 
}
	

Measured memory_bytes: 3632
# coding: utf-8
L,R = map(int, input().split())
mod_min=2020

if R-L>2018:
    mod_min=0
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            tmp = (i*j)%2019
            if tmp<mod_min:
                mod_min=tmp
print(mod_min)

Measured memory_bytes: 3060
import math

(a, b, C) = [int(i) for i in input().split()]

cs = math.radians(C)

c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(cs))

h = b * math.sin(cs)
S = a * h / 2
L = a + b + c

[print(format(i, '6f')) for i in [S, L, h]]

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

typedef long long ll;

// nの最大値+1
const ll MAX = 100001;
const ll MOD = 1000000007;

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

// 二項係数計算
ll 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() {
    COMinit();
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    
    ll s_max = 0;
    ll s_min = 0;
    for (int i = k-1; i < n; i++) {
        s_max = (s_max + a[i] * COM(i, k-1) % MOD) % MOD;
        s_min = (s_min + a[n-(i+1)] * COM(i, k-1) % MOD) % MOD;
    }

    ll ans = (s_max - s_min) % MOD;
    if (ans < 0)
        cout << MOD - ans << endl;
    else
        cout << ans << endl;
}

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

int main(){
	string str;
	int n;
	getline( cin, str );
	sscanf( str.c_str(), "%d", &n );

	for( int i=0; i<n; i++ ){
		getline( cin, str );
		unsigned int pos = 0;
		pos = str.find( "Hoshino", pos );
		while( pos != string::npos ){
			str.replace( pos, 7, "Hoshina" );
			pos = str.find( "Hoshino", pos );
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <valarray>
#include <algorithm>
using namespace std;
int main(){
  int n,m,border;
  bool flag=true;
  cin>>n>>m;
  valarray<int>a(n);
  for(auto&i :a){
    cin>>i;
  }
  border=a.sum();
  sort(begin(a),end(a),greater<>());
  for(int i=0;i<m;i++){
    if(border>a[i]*4*m){
      flag=false;
    }
  }
  if(!flag){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 256
<?php

    $N = intval(trim(fgets(STDIN)));
    
    $A = array_map('intval',explode(" ",trim(fgets(STDIN))));
    $B = array_map('intval',explode(" ",trim(fgets(STDIN))));
    $C = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    array_unshift($A,0);
    array_unshift($B,0);
    array_unshift($C,0);
    
    // var_dump($A)
    $sum=0;
    //ボーナスを考えない場合
    for($i=1;$i<=$N;$i++){
        $sum += $B[$A[$i]];
        
        if(!empty($memory)){
            if($memory+1 == $A[$i]){
                $sum+=$C[$memory];
            }
        }
        
        $memory = $A[$i];
    }
    echo $sum;
?>

Measured memory_bytes: 16268
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,
        q:usize,
        c:[Usize1;n],
        mut lr:[(Usize1,Usize1);q],
    };
    let mut bt = BIT::<SUM>::new(n + 111);
    let mut ql = vec![vec![]; n + 5];
    let mut qid = vec![vec![]; q + 5];
    for (i, &(l, r)) in lr.iter().enumerate() {
        ql[r].push(l);
        qid[r].push(i as usize);
    }

    let mut lst = vec![!0; n + 1];
    let mut anss = vec![0; q + 1];
    for i in 0..n {
        if lst[c[i]] != !0 {
            bt.add(lst[c[i]], &(-1));
        }
        bt.add(i, &1);
        lst[c[i]] = i;
        for j in 0usize..qid[i].len() as usize {
            anss[qid[i][j]] = bt.sum(i)
                - if ql[i][j] > 0 {
                    bt.sum(ql[i][j] - 1)
                } else {
                    0
                };
        }
    }

    for i in 0..q {
        println!("{}", anss[i]);
    }
}

pub trait Monoid {
    type T: Clone;
    fn id() -> Self::T;
    fn op(a: &Self::T, b: &Self::T) -> Self::T;
}
pub struct SUM {}
impl Monoid for SUM {
    type T = i64;
    fn id() -> Self::T {
        0
    }
    fn op(a: &Self::T, b: &Self::T) -> Self::T {
        *a + *b
    }
}
/// Generic Binary Indexed Tree
pub struct BIT<M: Monoid> {
    buf: Vec<M::T>,
}
impl<M: Monoid> BIT<M> {
    pub fn new(n: usize) -> Self {
        Self {
            buf: vec![M::id(); n + 10000],
        }
    }
    pub fn sum(&self, i: usize) -> M::T {
        let mut i = i + 100;
        if i == 0 || i == 1 {
            return M::id();
        }
        let mut s = M::id();
        while i > 0 {
            s = M::op(&s, &self.buf[i]);
            i -= 1 << i.trailing_zeros();
        }
        return s;
    }
    pub fn add(&mut self, i: usize, x: &M::T) {
        let mut i = i + 100;
        while i < self.buf.len() {
            let t = &mut self.buf[i];
            *t = M::op(&t, x);
            i += 1 << i.trailing_zeros();
        }
    }
}


Measured memory_bytes: 80448
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
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; }
using namespace std;

const int mod = 1000000007;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n,k; cin>>n>>k;
    int m=floor(sqrt(n));

    vector<int> cnt(m*2);
    rep(i,m)cnt[i]=1;
    rep(i,m)cnt[i+m]=min<int>(n/(m-i),n)-max<int>(n/(m-i+1),m);

    vector<vector<int>> dp(k+1,vector<int>(m*2,0));
    dp[0][0]=1;

    rep(i,k){
        int sum=0;
        rep(j,m*2){
            sum+=dp[i][j]; sum%=mod;
            dp[i+1][m*2-j-1]=sum*cnt[m*2-j-1]%mod;
        }
    }

    int ans=0;
    rep(i,m*2)ans=(ans+dp[k][i])%mod;
    cout<<ans<<endl;

}

Measured memory_bytes: 51328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

int H, W;

vector< vector<char> > fi(1010, vector<char>(1010, '#'));
vector< vector<ll> > dp(1010, vector<ll>(1010, 0));

const int d1[4] = {0,1,0,-1};
const int d2[4] = {1,0,-1,0};



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

    cin >> H >> W;
    for(int i=1; i<=H; ++i) for(int j=1; j<=W; ++j) cin >> fi[i][j];

    dp[1][1] = 1;
    for(int i=1; i<=H; ++i){
        for(int j=1; j<=W; ++j){
            if(fi[i][j] == '#') continue;
            dp[i][j] += dp[i-1][j] + dp[i][j-1];
            chmod(dp[i][j]);
        }
    }

    cout << dp[H][W] << endl;

    // for(int i=1; i<=H; ++i){
    //     for(int j=1; j<=W; ++j){
    //         printf("%5lld", dp[i][j]);
    //     }
    //     cout << endl;
    // }

	return 0;
}


Measured memory_bytes: 9344
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n,k; cin >> n >> k;
  ll ans=0;
  for(ll i=k;i<=n+1;i++){
    ans+=(n-i+1)*i+1;
    ans%=mod;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int max_x=W, min_x=0, max_y=H, min_y=0;

    for (int i=0; i<N; i++){
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1){
            if (x > min_x){
                min_x = x;
            }
        }else if (a == 2){
            if (x < max_x){
                max_x = x;
            }
        }else if (a == 3){
            if (y > min_y){
                min_y = y;
            }
        }else if (a == 4){
            if (y < max_y){
                max_y = y;
            }
        }
    }
    if (min_x < max_x && min_y < max_y){
        cout << (max_x - min_x)*(max_y - min_y) << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

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

struct Node
{
	int Parent;
	int RightSibling;
	int LeftChild;
	int Depth;
	
	Node()
	{
	    Parent = -1;
	    RightSibling = -1;
	    LeftChild = -1;
	    Depth = -1;
	}
};

Node tree[100007];

void Run(int N)
{
	int t = tree[N].LeftChild;
	
	while(t != -1)
	{		
		tree[t].Depth = tree[N].Depth + 1;
		Run(t);
		t = tree[t].RightSibling;
	}
}

int main()
{
	int N, ID, K, C;
	cin >> N;
	
	for(int i = 0; i < N; ++i)
	{
		tree[i] = Node();
	}
	
	for(int i = 0; i < N; ++i)
	{
		cin >> ID >> K;
		for(int j = 0, child; j < K; ++j)
		{
			cin >> C;
						
			if(j == 0)
			{
				tree[ID].LeftChild = C;		
			}
			else
			{
				tree[child].RightSibling = C;
			}
			
			tree[C].Parent = ID;
			child = C;
		}
	}
	
	for(int i = 0; i < N; ++i)
	{
		if(tree[i].Parent == -1)
		{
			tree[i].Depth = 0;
			Run(i);
		}
	}
	
	for(int i = 0; i < N; ++i)
	{
		cout << "node " << i << ": parent = " << tree[i].Parent << ", depth = " << tree[i].Depth << ", ";
		
		if(tree[i].Parent == -1)
		{
			cout << "root";
		}
		else if(tree[i].LeftChild == -1)
		{
			cout << "leaf";
		}
		else
		{
			cout << "internal node";
		}
		
		cout << ", [";
		int t = tree[i].LeftChild;
		bool is_first = true;
		while(t != -1)
		{
			if(!is_first)
			{
				cout << ", ";
			}
			
			cout << t;
			t = tree[t].RightSibling;
			is_first = false;
		}
		cout << "]" << endl;
	}

    return 0;
}



Measured memory_bytes: 4640
s = input()
my1 = int(s[0:2])
my2 = int(s[2:])
my1t = False
my2t = False
if my1 >= 13 or my1 == 0:
    my1t = True
if my2 >= 13 or my2 == 0:
    my2t = True
if my1t == True and my2t == False:
    print('YYMM')
elif my1t == False and my2t == True:
    print('MMYY')
elif my1t == False and my2t == False:
    print('AMBIGUOUS')
else:
    print('NA')


Measured memory_bytes: 3060
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1); m],
    }
    if m % 2 == 1 {
        println!("-1");
        return;
    }
    let mut g = vec![vec![]; n];
    for (a, b) in e {
        g[a].push(b);
        g[b].push(a);
    }
    let mut parent = vec![n; n];
    let mut q = vec![];
    let mut back = vec![];
    let root = 0;
    parent[root] = root;
    let mut stack = vec![root];
    while let Some(v) = stack.pop() {
        q.push(v);
        for &u in g[v].iter() {
            if parent[u] == n {
                parent[u] = v;
                stack.push(u);
            } else if u != parent[v] {
                back.push((std::cmp::min(u, v), std::cmp::max(u, v)));
            }
        }
    }
    back.sort();
    back.dedup();
    assert!(back.len() == m - n + 1);
    let mut deg = vec![0; n];
    for &(a, _) in back.iter() {
        deg[a] += 1;
    }
    let mut ans = back;
    for &v in q.iter().rev() {
        if v == root {
            assert!(deg[v] % 2 == 0);
        } else {
            let p = parent[v];
            if deg[v] % 2 == 0 {
                deg[p] += 1;
                ans.push((p, v));
            } else {
                deg[v] += 1;
                ans.push((v, p));
            }
        }
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for (a, b) in ans {
        writeln!(out, "{} {}", a + 1, b + 1).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 21884
#include <bits/stdc++.h>
using namespace std;
long long s[365][26]; 
int main() {
  int d;
  cin >>d;
  //int d=365;
  vector<int>c(26);
  vector<int>last(26,0);
  //vector<int>hinichi(26,0);
  long long wa=0;
  for(int i=0;i<26;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<d;i++){
    for(int j=0;j<26;j++){
      cin>>s[i][j];
    }
  }
  vector<int>t(d);
  for(int i=0;i<d;i++)cin>>t[i];
  long long kotae=0;
  int hinichi=0;
  long long hikukazu=0;
  for(int i=0;i<d;i++){
    long long atai=0;
    /*for(int j=0;j<26;j++){
      if(atai<s[i][j]){
        atai=s[i][j];
        hinichi=j;
      }
    }
    hikukazu+=wa-c[hinichi]*(i+1-last[hinichi]);
    last[hinichi]=i+1;*/
    atai=s[i][t[i]-1];
    hikukazu+=wa-c[t[i]-1]*(i+1-last[t[i]-1]);
    last[t[i]-1]=i+1;
    kotae+=atai-hikukazu;
    //cout<<wa<<" "<<c[hinichi]<<" "<<hikukazu<<" "<<s[i][hinichi]<<endl;
    //cout<<wa<<" "<<c[t[i]-1]<<" "<<hikukazu<<" "<<s[i][t[i]-1]<<endl;
    cout<<kotae<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 3608
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

count = 0
for i in range(n):
    ret = 0
    for j in range(m):
        ret += a[i][j] * b[j]
    ret += c
    if ret > 0:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	int n;
	cin >> n;
	vector<int> v(3);

	v[0] = n / 100;
	v[1] = (n % 100) / 10;
	v[2] = (n % 10);

	if (v[0] == v[2])cout << "Yes" << endl;
	else cout << "No" << endl;

    return 0;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    set<char> s;
    rep(i, n) {
        char c; cin >> c;
        s.insert(c);
    }
    if (s.size() == 3) {
        cout << "Three" << endl;
    }
    else {
        cout << "Four" << endl;
    }
}


Measured memory_bytes: 256
#include "stdio.h"
int main(int argc, char const *argv[])
{
	int n,i,j,taro_p=0,hanako_p=0;
	char taro[101],hanako[101];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",taro); scanf("%s",hanako);
		for(j=0;;j++){
			if(taro[j] > hanako[j]){
				taro_p = taro_p + 3;
				break;
			}
			else if(taro[j] < hanako[j]){
				hanako_p = hanako_p + 3;
				break;
			}
			else if(taro[j] == hanako[j] && taro[j+1] == '\0' && hanako[j+1] == '\0'){
				hanako_p = hanako_p + 1;
				taro_p = taro_p + 1;
				break;

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


Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define mp make_pair
#define ins insert
#define sz size
#define whoami(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); whi(_it, args); }

void whi(istream_iterator<string> it) { cerr<<"\n"; }

template<typename T, typename... Args>
void whi(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<" "<<a<<" "; whi(++it, args...); }

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;
const ll INF = 4e18;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int a,b;
	cin>>a>>b;
	cout<<(a*b)<<"\n";
	return;
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int INF=1e9;

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

    int N; cin>>N;
    vector<vector<int>> dist(N,vector<int>(N,INF));
    for(int i=0;i<N;i++) dist[i][i]=0;
    for(int i=0;i<N;i++){
        int u,k; cin>>u>>k;
        while(k--){
            int v,c; cin>>v>>c;
            chmin(dist[u][v],c);
        }
    }
    for(int k=0;k<N;k++) for(int i=0;i<N;i++) for(int j=0;j<N;j++){
        chmin(dist[i][j],dist[i][k]+dist[k][j]);
    }
    for(int i=0;i<N;i++){
        cout<<i<<' '<<dist[0][i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3156
// This question is quite tough for me. I am not able to get it.
// Can Anyone Help me
// https://atcoder.jp/contests/dp/tasks/dp_s
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll MOD=1e9+7;
ll dp[10001][101][2];
ll solve(string& k,int D,int pos,int d,bool tight){
	if(dp[pos][d][tight]!=-1)
		return dp[pos][d][tight];
	int ub=(tight)?(k[pos]-'0'):9;
	if(pos==k.length()-1){
		ll ans=0;
		for(int x=0;x<=ub;++x)
			if(x%D==d)
				ans++;
		return ans;
	}
	ll ans=0;
	for(int x=0;x<=ub;x++){
		ans=(ans+solve(k,D,pos+1,(D+d-x%D)%D,tight && (x==ub)))%MOD;
	}
	return dp[pos][d][tight]=ans;
}

int main(){
	int D=0;string k;
	cin>>k>>D;
	memset(dp,-1,sizeof(dp));
	cout<<(MOD+solve(k,D,0,0,1)-1)%MOD<<'\n';
	return 0;
}

Measured memory_bytes: 17152
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)
			break;
		vector<int> date[30];
		vector<set<int>> dat(n);
		for (int i = 0; i < n; i++) {
			int m;
			cin >> m;
			for (int j = 0; j < m; j++) {
				int f;
				cin >> f;
				f--;
				date[f].push_back(i);
			}
		}
		for (int i = 0; i < n; i++)
			dat[i].insert(i);
		int ret = 0;
		while (ret < 30) {
			for (int i = 0; i < date[ret].size(); i++) {
				int from = date[ret][i];
				for (int j = 0; j < date[ret].size(); j++) {
					int to = date[ret][j];
					for (int it : dat[from])
						dat[to].insert(it);
				}
			}
			bool end = false;
			for (int i = 0; i < n; i++) {
				if (dat[i].size() == n) {
					end = true;
					break;
				}
			}
			if (end)
				break;
			ret++;
		}
		cout << (ret == 30 ? -1 : ret + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
fn g(x: f64, xy: &[(f64, f64)]) -> f64 {
    let mut left: f64 = 0.0;
    let mut right: f64 = 1000.0;
    let f = |qx: f64, qy: f64| -> f64 {
        let mut result = 0.0;

        for &(px, py) in xy.iter() {
            let dx = qx - px;
            let dy = qy - py;
            let d = (dx * dx + dy * dy).sqrt();
            if result < d {
                result = d;
            }
        }
        result
    };
    for i in 0..100 {
        let m1: f64 = (left * 2.0 + right) / 3.0;
        let m2: f64 = (left + 2.0 * right) / 3.0;
        if f(x, m1) > f(x, m2) {
            left = m1;
        } else {
            right = m2;
        }
    }
    f(x, left)
}
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let xy: Vec<(f64, f64)> = (0..n)
        .map(|_| {
            let x: f64 = sc.read();
            let y: f64 = sc.read();
            (x, y)
        })
        .collect();
    let mut left = 0.0;
    let mut right = 1000.0;
    for i in 0..100 {
        let m1 = (left * 2.0 + right) / 3.0;
        let m2 = (left + 2.0 * right) / 3.0;
        if g(m1, &xy) > g(m2, &xy) {
            left = m1;
        } else {
            right = m2;
        }
    }
    println!("{}", g(left, &xy));
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
n = input()
a = [input() for i in range(int(n))]
b = [0] * 4

for i in range(int(n)):
    if(a[i] == "AC"):
        b[0] += 1
    elif(a[i] == "WA"):
        b[1] += 1
    elif(a[i] == "TLE"):
        b[2] += 1
    elif(a[i] == "RE"):
        b[3] += 1

print("AC x ", b[0])
print("WA x ", b[1])
print("TLE x ", b[2])
print("RE x ", b[3])

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

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

void solve() {
    int N; cin >> N;
    double ans = ((N + 2 - 1) / 2)/ (double) N;
    cout << fixed << setprecision(15) << ans << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int k; cin>>k;
    long long int ans=0;
    for(int i=1;i<=k;i++)
    for(int j=1;j<=k;j++)
    for(int m=1;m<=k;m++)
      ans+=(gcd(gcd(i,j),m));
    cout<<ans<<endl;  
}    

Measured memory_bytes: 3616
#include <stdio.h>

int main(){
  int i,j,k,m,n;
  int o[100],omx;
  while(scanf("%d %d\n",&n,&m)){
    if(m==0 && n==0) break;
    for(i=0;i<m;i++) o[i]=0; omx=0; k=0;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
        o[j]+=getchar()-'0';
        getchar();
        if(o[j]>omx) omx=o[j];
      }
    }
    for(i=omx;i>=0;i--){
      for(j=0;j<m;j++){
        if(o[j]==i){
          if(k==1) printf(" ");
          printf("%d",j+1);
          k=1;
        }
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 612
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

M = []
P = []

for i in range(N):
    tmp = A[i] - B[i]
    if tmp < 0:
        M.append(tmp)
    else:
        P.append(tmp)

ms = sum(M)
if ms == 0:
    print(0)
    exit(0)

P.sort(reverse=True)

count = 0
for pi in P:
    count += 1
    ms += pi
    if ms >= 0:
        break
else:
    print(-1)
    exit(0)

print(count + len(M))

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

int main(){
  int N;
  cin >> N;
  set<int> col;
  col.insert(N);
  int fn = N;
  for(int i = 2; i < 100000; i++){
    if(fn % 2 == 0) fn = fn / 2;
    else fn = 3 * fn + 1;
    
    if (col.count(fn)) {
      cout << i << endl;
      break;
    }
    else col.insert(fn);
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
const int maxn=200010;
int n,a[maxn],pl[maxn],q[maxn],st[2][maxn][25];

struct node
{
	int t,l,r;
};
bool operator <(node a,node b) {return a.t>b.t;}
priority_queue <node> h;

int rmq(int f,int l,int r)
{
	int k=(int)(log(r-l+1)/log(2));
	//cout<<"rmq:"<<f<<' '<<l<<' '<<r<<' '<<k<<' '<<min(st[f][l][k],st[f][r-(1<<k)+1][k])<<endl;
	return min(st[f][l][k],st[f][r-(1<<k)+1][k]);
}
int main()
{
	scanf("%d",&n);
	memset(st,0x3f,sizeof(st));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pl[a[i]]=i;
		st[i&1][i][0]=a[i];
	}
	for(int k=1;(1<<k)<=n;k++)
	{
		for(int i=1;i<=n-(1<<k)+1;i++)
			for(int f=0;f<=1;f++)
				st[f][i][k]=min(st[f][i][k-1],st[f][i+(1<<(k-1))][k-1]);
	}			
	/*for(int f=0;f<=1;f++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int k=0;(1<<k)<=n;k++)
				cout<<st[f][i][k]<<' ';
			cout<<endl;
		}
		cout<<endl;
	}*/				
	h.push((node){rmq(1,1,n),1,n});
	for(int i=1;i<=n/2;i++)	
	{	
		node w=h.top();
		h.pop();
		//cout<<i<<' '<<w.t<<' '<<w.l<<' '<<w.r<<endl;
		int f=pl[w.t]&1,ano=rmq(f^1,pl[w.t]+1,w.r);
		q[2*i-1]=w.t;q[2*i]=ano;
		//cout<<f<<' '<<ano<<endl;
		if(pl[w.t]>w.l) h.push((node){rmq(f,w.l,pl[w.t]-1),w.l,pl[w.t]-1});
		if(pl[ano]-1>pl[w.t]+1) h.push((node){rmq(f^1,pl[w.t]+1,pl[ano]-1),pl[w.t]+1,pl[ano]-1});
		if(w.r>pl[ano]) h.push((node){rmq(f,pl[ano]+1,w.r),pl[ano]+1,w.r});
	}
	for(int i=1;i<=n;i++)
		printf("%d ",q[i]);
	return 0;
}
/*8
4 6 3 2 8 5 7 1*/

Measured memory_bytes: 43512
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
 
const int N = 2e5 + 7;

int a[N];
 
int32_t main() {
		int n, k; cin >> k >> n;
		for(int i = 1; i <= n; i++) cin >> a[i];
	//	sort(a + 1, a + n + 1, greater <int> ());

		int ans = 0;
		for(int i = 1; i <= n; i++) ans += a[i];

		if(ans >= k) cout << "Yes" << endl;
		else 		 cout << "No" << endl;
}

Measured memory_bytes: 1024
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

const int N = 305;
const long long mod = 1e9 + 7;

int dp[N][N][N];
int ck[N][2][4];
int n, m;

bool ok(int a, int b, int c){
	int at = max({a, b, c});
	for(int j = 0; j <= 1; ++j){
		for(int i = 1; i <= 3; ++i){
			if(ck[at][j][i] == 0) continue;
			int cnt = 0;
			cnt += (a >= ck[at][j][i]);
			cnt += (b >= ck[at][j][i]);
			cnt += (c >= ck[at][j][i]);
			if(cnt != i) return false;
		}
	}
	return true;
}

int recur(int l1, int l2, int l3){
	int at = max({l1, l2, l3}) + 1;
	if(at == n + 1) return 1;
	if(dp[l1][l2][l3] != -1) return dp[l1][l2][l3];
	long long ret = 0;
	if(ok(at, l2, l3)) ret += recur(at, l2, l3);
	if(ok(l1, at, l3)) ret += recur(l1, at, l3);
	if(ok(l1, l2, at)) ret += recur(l1, l2, at);
	return dp[l1][l2][l3] = ret % mod;
}

int main(){
	int l, r, x;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; ++i){
		scanf("%d %d %d", &l, &r, &x);
		if(ck[r][0][x] == 0){
			ck[r][0][x] = l; 
			ck[r][1][x] = l;
		}
		else{ 
			ck[r][0][x] = min(ck[r][0][x], l);
			ck[r][1][x] = max(ck[r][1][x], l);
		}
	}
	memset(dp, -1, sizeof(dp));
	printf("%d\n", recur(0, 0, 0));
	return 0;
}



Measured memory_bytes: 111232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    string S;
    cin >> S;
    if(S.size() % 2==0){
        rep(i,S.size()/2){
            if(!(S.at(i*2) == 'h' && S.at(i*2 + 1)=='i')){
                cout << "No" << endl;
                return 0;
            }
        }
    }else{
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc111_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            var dic1 = new Dictionary<int,int>();
            var dic2 = new Dictionary<int,int>();

            for (int i = 1; i < n; i+=2){
                if(dic1.ContainsKey(input[i-1])) dic1[input[i-1]]++;
                else dic1[input[i-1]] = 1;

                if(dic2.ContainsKey(input[i])) dic2[input[i]]++;
                else dic2[input[i]] = 1;
            }

            Array.Sort(input);
            if(input[0] == input[n-1]){
                WriteLine(n/2);
            }else{
                var tmp1 = dic1.OrderBy((x) => x.Value).OrderByDescending((x) => x.Value).ToList();
                var tmp2 = dic2.OrderBy((x) => x.Value).OrderByDescending((x) => x.Value).ToList();

                if(tmp1[0].Key == tmp2[0].Key){
                    var a = n-tmp1[1].Value-tmp2[0].Value;
                    var b = n-tmp1[0].Value-tmp2[1].Value;
                    WriteLine(Min(a,b));
                }else{
                    WriteLine(n-tmp1[0].Value-tmp2[0].Value);
                }
            }
        }
    }
}

Measured memory_bytes: 28128
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
    while(cin>>N,N){
       vector<string>v;
       REP(i,N){
           string s;
           cin>>s;
           v.push_back(s);
       }
       int ans=0;
       REP(i,N/2){
           if(v[2*i]=="lu"&&v[2*i+1]=="ru")ans++;
           if(v[2*i]=="ru"&&v[2*i+1]=="lu")ans++;
           if(v[2*i]=="ld"&&v[2*i+1]=="rd")ans++;
           if(v[2*i]=="rd"&&v[2*i+1]=="ld")ans++;
       }
       cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3072
import { readFileSync } from "fs";

const [cin, nCin, biCin] = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return [cin, () => Number(cin()), () => BigInt(cin())];
})() as [() => string, () => number, () => bigint];

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

const getName = (n: bigint): string => {
  const alphabets = range(26).map((i) => String.fromCharCode("a".charCodeAt(0) + i));
  const getName = (n: bigint, l: bigint): string => {
    const m = 26n ** l;
    return n <= m
      ? range(l).reduce(
          ({ num, str }, _) => ({
            num: num / 26n,
            str: alphabets[Number(num % 26n)] + str,
          }),
          { num: n - 1n, str: "" }
        ).str
      : getName(n - m, l + 1n);
  };
  return getName(n, 1n);
};

{
  const N = biCin();
  console.log(getName(N));
}


Measured memory_bytes: 29648
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n;
    cin >> n;
    vector<int> a(n);
    int all = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        all ^= a[i];
    }

    for(int i = 0; i < n; i++) cout << (all ^ a[i]) << " ";
    cout << "\n";

    return 0;
}

Measured memory_bytes: 3880
n,k=gets.split.map(&:to_i)
lr=k.times.map{gets.split.map(&:to_i)}

dp=Array.new(n,0)
dp[0]=1
dp[1]=-1
n.times do |i|
  dp[i]+=dp[i-1] if i>0
  k.times do |j|
    a=lr[j][0]
    b=lr[j][1]+1
    dp[i+a]+=dp[i]%998244353 if i+a<n
    dp[i+b]-=dp[i]%998244353 if i+b<n
  end
end

puts dp[n-1]%998244353


Measured memory_bytes: 15788
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
  int n,r,p,c;
  int i;
  while(cin >> n >> r && n != 0){
    vector<int> A(n);
    for(i=0;i<n;i++) A[i] = n-i;
    for(i=0;i<r;i++){
      cin >> p >> c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout << A[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
int main(void) {
	while(1){
		int w;
		scanf("%d",&w);
		if(w==(-1)) break;
		int s=1150;
		if(w<=10){
		    s=s;
		}
		else if(w>10&&w<=20){
			s=s+(w-10)*125;
		}
		else if(w>20&&w<=30){
			s=s+10*125+(w-20)*140;
		}
		else{
			s=s+10*125+10*140+(w-30)*160;
		}
		printf("%d\n",4280-s);
	}
	return 0;
}


Measured memory_bytes: 2124
import java.io.*;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
           Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int a = n;
            n = in.nextInt();
            int b = n;
        
            in.close();
        
        
            System.out.println((a*b) + (" ") + (2*a + 2*b));
    }
    
 }



Measured memory_bytes: 26200
# ABC136B - Uneven Numbers
def main():
    n = int(input())
    d = len(str(n))
    if d == 6:
        ans = 90909
    elif d in (4, 5):
        ans = 909 + max(0, n - 9999)
    elif d in (2, 3):
        ans = 9 + max(0, n - 99)
    else:
        ans = n
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	int L;
	scanf("%d", &L);
	int n = 20, m = (n-2)*2;
	int l = L;
	foreach (i; 0..n) {
		m += l&1;
		if (i == n-1) m += l&1;
		l >>= 1;
	}
	writeln(n," ",m);
	foreach (i;0..n-2) {
		writeln(i+1," ",i+2," ",0);
		writeln(i+1," ",i+2," ",1<<i);
	}
	l = L;
	foreach (i; 0..n) {
		if (l>>i&1) {
			l ^= 1<<i;
			if (i+1 < n) {
				writeln(i+1," ",n," ",l);
			} else {
				writeln(n-1," ",n," ",l);
				writeln(n-1," ",n," ",l+(1<<(i-1)));
			}
		}
	}
}

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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

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

int gcd_d(int m, int n) { // Greatest Common Divisor
	return n==0 ? m : gcd_d(n, m%n);
}

int main(int argc, char *argv[])
{
    int K;
    cin >> K;

    ll ans = 0;

    reb(a, 1, K+1) {
        reb(b, 1, K+1) {
            reb(c, 1, K+1) {
                const int gcd_ab = gcd_d(a, b);
                ans += gcd_d(gcd_ab, c);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		final int MOD = 1000000007;

		//入力
		String a = sc.nextLine();
		String b = sc.nextLine();
		sc.close();

		//処理
		String ans;
		if(a.length() > b.length()){
			ans = "GREATER";
		}else if(a.length() < b.length()){
			ans = "LESS";
		}else{
			if(a.compareTo(b) > 0){
				ans = "GREATER";
			}else if(a.compareTo(b) < 0){
				ans = "LESS";
			}else{
				ans = "EQUAL";
			}
		}

		//出力	
		out.println(ans);
		out.flush();
	}

	static class Pair{
		int w,v;
		public Pair(int a, int b){
			this.w = a;
			this.v = b;
		}
	}
}

Measured memory_bytes: 23764
import numpy as np
n = int(input())
a = list(map(int, input().split()))
m = np.mean(a)
ans = 0
dist = abs(a[0] - m)

for i in range(n):
    if abs(a[i] - m) < dist:
        dist = abs(a[i] - m)
        ans = i

print(ans)

Measured memory_bytes: 12508
#include<iostream>
using namespace std;
int main(void){
  int a=0,b;
  string s;
 cin >> s;
  for(int i = 0;i < s.size();i++){
    if(s.at(i) == 'C'){
      a = 1;
    }
    if((a == 1) && (s.at(i) == 'F')){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

Measured memory_bytes: 256