akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

bool flag = false;
void dfs(string s){
	if(s.size() < 3) return;
	if(s == "ABC"){
		// cout << s << endl;
		flag = true; return;
	}
	static string b[] = {"A", "B", "C"};
	rep(k, 3){
		string t = s;
		bool f = false;
		/* ????????????"ABC"???b[k]??\????????????, ????????????????????????b[k]?????????????????????????????? */
		int cnt = 0;
		rep(i, t.size()){
			if(i < t.size() - 2 && t[i] == 'A' && t[i + 1] == 'B' && t[i + 2] == 'C'){
				f = true;
				t.replace(i, 3, b[k]);
			}else if(t[i] == "ABC"[k]){
				cnt++;
			}
		}
		if(f && cnt == 0){
			// cout << t << endl;
			dfs(t);
		}
	}
	return;
}

int main(void){
	string s; cin >> s;
	dfs(s);
	if(flag) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main()
{
    int n, x;
    cin >> n >> x;
    int l[n];
    int ans = 1;
    int bound = 0;
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    for(int j=0;j<n;j++){
        bound = bound + l[j];
        if(bound <= x){
            ans++;
        }
        else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

bool br[100008];
int a[100008];
int dp[100008];
int n, m; 

int main()
{
    
    cin >> n >> m;
    int i, j, d;
    memset(br, false, sizeof(br));
    memset(dp, 0, sizeof(dp));
    for(i = 0; i < m; i++)
    {
        cin >> a[i];
        if(i >= 1 && a[i] == a[i-1]+1)
        {
            cout << 0;
            return 0;
        }
        br[a[i]] = true;
    }
    
    dp[0] = 1;
    for(i = 1; i <= n; i++)
    {
        if(!br[i])
        {
            if(i == 1)
                dp[i] = dp[i - 1];
            else
                dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007;
        }
    }
    
    cout << dp[n];

    return 0;
}


Measured memory_bytes: 896
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


if __name__ == '__main__':
    r, D, x = mi()
    for i in range(10):
        x = r * x - D
        print(x)


Measured memory_bytes: 5716
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
 
		int N = scan.nextInt();

		int count = 0;
		int M = N;

		while(M != 0){
			count += M%10;
			M = M/10;
		}
		
		if(N % count == 0){
			System.out.println("Yes");	
		}else{
			System.out.println("No");
		}


	}
 
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	float a, b, c, d, e, f;
	float x, y;
	while(cin >> a >> b >> c >> d >> e >> f){
	x = (c*e - b*f) / (a*e - b*d);
	y = (a*f - c*d) / (a*e - b*d);
	x = floor(100 * (x + 0.005)) / 100;
	y = floor(100 * (y + 0.005)) / 100;
	cout << setprecision(3) << fixed << x << " " << y <<endl;
	}
	return 0;
}

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

using namespace std;

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

    set<int> s;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (s.find(a) == s.end()) {
            s.insert(a);
        } else {
            s.erase(a);
        }
    }

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


Measured memory_bytes: 4864
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	string a, b;

	cin >> a >> b;

	if (a == "H") {
		if (b == "H")cout << "H\n";
		else cout << "D\n";
	}else{
		if (b == "H")cout << "D\n";
		else cout << "H\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template <typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main()
{
    int N;
    cin >> N;
    
    ve<pii> x(N),y(N);
    rep(i,N){
        int a,b;
        cin >> a >> b;
        x[i] = {a,i};
        y[i] = {b,i};
    }
    sort(all(x));
    sort(all(y));
    
    
    ve<ve<pii>> G(N);
    rep(i,N-1){
        G[x[i].se].pb({abs(x[i].fi-x[i+1].fi), x[i+1].se});
        G[y[i].se].pb({abs(y[i].fi-y[i+1].fi), y[i+1].se});
        G[x[i+1].se].pb({abs(x[i].fi-x[i+1].fi), x[i].se});
        G[y[i+1].se].pb({abs(y[i].fi-y[i+1].fi), y[i].se});
    }
    
    
    pq1<pii> A;
    vi f(N,1);
    A.push({0,0});
    
    ll ans = 0;
    
    while (!A.empty()) {
        
        pii a = A.top();
        A.pop();
        
        if(!f[a.se]) continue;
        //cout << "111" csp a.se csp a.fi << endl;
        f[a.se] = 0;
        ans += (ll)(a.fi);
        //cout << ans << endl;
        for (auto p : G[a.se]) {
            if(!f[p.se]) continue;
            A.push(p);
            //cout << p.fi csp p.se << endl;
        }
        
    }
    
    
    
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 10872
alphabet = [chr(i) for i in range(ord('a'), ord('z') + 1)]
# print(chr(ord('z')+1))
s = input()
ans = ''
if s == 'zyxwvutsrqponmlkjihgfedcba':
    ans = '-1'

elif len(s) == 26:
    pre = '`'
    end = 0
    for x in reversed(s):
        if ord(pre) > ord(x):
            ans = s[:end]
            break
        end -= 1
        pre = x
    for a in alphabet:
        if a not in ans and ord(a) > ord(ans[-1]):
            ans = ans[:len(ans)-1] + a
            break
else:
    for a in alphabet:
        if a not in s:
            ans = s + a
            break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b){
    cout<<c<<"\n";
  }else if(a==c){
    cout<<b<<"\n";
  }else if(b==c){
    cout<<a<<"\n";
  }
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  string s;
  cin >> n >> s;

  for (int i = 0; i < s.size(); i++)
  {
    int x = s[i] - 'A';
    x = (x+n) % 26;
    s[i] = 'A' + x;
  }

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 3648
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;
const double sqrt3 = sqrt(3);

#define SIZE 10010
#define debug(x) cerr << #x << " : " << x << endl;

int x[SIZE];
int y[SIZE];
pair<int,pair<double,double> > sorted_v[SIZE];
pair<pair<pair<double,double>, int>,int> vec[SIZE], vec2[SIZE];

int main(){
  int n,k;

  while (1){  
    scanf("%d%d", &n, &k);
    if(!n) return 0;
    
    for(int i = 0; i < n; i++){
      scanf("%d%d", x+i, y+i);
      sorted_v[i] = {y[i], {x[i] - y[i]/sqrt3, x[i] + y[i]/sqrt3}};
    }
    
    std::sort(sorted_v,sorted_v+n);

    for(int i=0;i<n;i++) vec[i] = {{sorted_v[i].second, sorted_v[i].first}, 0};
    vec[n] = {{{1e20, 1e20},-1},0};

    sort(vec, vec + n, [](auto a, auto b){return a.first.first.second < b.first.first.second;});
    for(int i=0;i<=n;i++){
      vec[i].second = i;
      vec2[i] = vec[i];
    }
    sort(vec, vec + n);
    
    double ans = 1e20;
    
    for(int i=0; i<=k; i++){
      
      int y = sorted_v[i].first; 
      
      int r = n;
      int counter = 0;
      bool memo[SIZE] = {};
      
      for(int j=n-1;j>=0;j--){
        if(vec[j].first.second < y) continue;
        memo[vec[j].second] = 1;
        counter += vec[j].second < r;
        
        while(counter >= n-k) counter -= memo[--r];

        ans = min(ans, vec2[r].first.first.second - (vec[j].first.first.first + 2 * y/sqrt3));
      }
    }
    
    printf("%.10lf\n", ans * 3);
  }
}



Measured memory_bytes: 4144
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    string s; cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }
    int n = s.size();
    if(n != 26){
        set<char> count;
        rep(i, n){
            count.insert(s[i]);
        }
        char c = 'a';
        bool flag = false;
        for(auto it : count){
            if(it != c){
                s += c;
                cout << s << endl;
                flag = true;
                return 0;
            }
            c++;
        }
        if(!flag){
            s += c;
            cout << s << endl;
            return 0;
        }
    }

    if(n == 26){
        vector<char> vec;
        int m = s.size();
        for(int i = 0; i < m; i++){
            vec.push_back(s[i]);
        }
        string t = s;
        next_permutation(vec.begin(), vec.end());
        string ans = "";

        for(int i = 0; i < vec.size(); i++){
            ans += vec[i];
            if(vec[i] > t[i])break;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    string s;
    string word;
    cin >> word;
    int ans = 0;
    while(1){
        cin >> s;
        if(s == "END_OF_TEXT") break;
        F(i, 0, s.size()){
            if('A' <= s[i] && s[i] <= 'Z'){
                s[i] = tolower(s[i]);
            }
            if(!('a' <= s[i] && s[i] <= 'z')){
                s.erase(s.begin() + i);
            }
        }
        if(s == word) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3160
'use strict'

/////////////////////////////////////
//コピペスペース//////////////////////

//定数
const INF  =  900719925474099 // Math.floor(Number.MAX_SAFE_INTEGER / 10);

//スペース区切りの数字列を数字の配列にして返す
function mapint(line){return line.split(' ').map((v)=>parseInt(v));}

function lower_bound(d,a,b,e){
    for(var c;1<b-a;)
        d[c=0|(a+b)/2]<e ? a=c : b=c;
    return d[a]<e?b:a
};

const MOD = 1000000007;

//コピペスペース//////////////////////
/////////////////////////////////////

function Main(input){
	let temp = input.trim();
	let tt = mapint(temp);
	let l = tt.shift();
	let r = tt.shift();

	let min = INF;
	//console.log('----------------------');
	let e = Math.min(r,l+2019);
	for(let i=l;i<r;i++){
		for(let j=i+1;j<=e;j++){
			min = Math.min(min,(((i%2019)*j)%2019) );
			//console.log(i,j,min);

		}
		if(min<=0) break;
	}
	console.log(min);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8268
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;

 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

signed main(){
    ll h,w,a,b;
    cin >> h >> w >> a >> b;

    rep(i,0,h){
        rep(j,0,w){
            if(b > i && a > j || b <= i &&  a <= j){
                cout << 0;
            }
            else{
                cout << 1;
            }
        }
        cout << endl;
    }
    return 0;
}


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

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

typedef pair<int, int> P;

ll dp[1010][1010];
vector<string> a(1010);
// dp[i][j]は，(i,j)に至るまでの経路の数
int main()
{
    int H, W;
    cin >> H >> W;
    rep(i, H)
    {
        cin >> a.at(i);
    }

    dp[0][0] = 1;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i + 1 < H) {
                if (a.at(i + 1).at(j) == '.') {
                    dp[i + 1][j] += dp[i][j];
                    dp[i + 1][j] %= MOD;
                }
            }
            if (j + 1 < W) {
                if (a.at(i).at(j + 1) == '.') {
                    dp[i][j + 1] += dp[i][j];
                    dp[i][j + 1] %= MOD;
                }
            }
        }
    }

    ll ans = dp[H - 1][W - 1] % MOD;

    cout << ans << endl;
}


Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll x[5];
    rep(i,0,5)cin>>x[i];
    rep(i,0,5)if(x[i] == 0)cout<<i+1;
    return 0;
}

Measured memory_bytes: 3632
MOD = 1_000_000_007

FACT = [1]
(1..2000).each do |k|
  FACT << FACT[-1] * k % MOD
end

def exp(n, k)
  x = 1
  r = n
  while k > 0
    x *= r if k & 1 == 1
    r *= r
    x %= MOD
    r %= MOD
    k >>= 1
  end
  x
end

def inv(n)
  exp(n, MOD - 2)
end

def perm(n, k)
  n >= k ? FACT[n] * inv(FACT[n - k]) % MOD : 0
end

def comb(n, k)
  perm(n, k) * inv(FACT[k]) % MOD
end

n, k = gets.split.map(&:to_i)
p comb(n - 1, k - 1)


Measured memory_bytes: 6948
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    int H, W; cin >> H >> W;

    vector<vector<int>> graph(10, vector<int>(10));

    REP(i, 10)
        REP(j, 10)
            cin >> graph[i][j];

    for( int i = 0; i < 10; i++ )
    {
        for( int j = 0; j < 10; j++ )
        {
            for( int k = 0; k < 10; k++ )
            {
                graph[j][k] = min( graph[j][k], graph[j][i] + graph[i][k] );
            }
        }
    }

    unsigned long long score = 0;
    REP(i, H)
    {
        REP(j, W)
        {
            int v; cin >> v;
            if( v != -1 )
                score += graph[v][1];
        }
    }
    
    cout << score << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

int main(){
  ll N;
  cin >> N;
  vector<ll> L;
  ll buf;
  for(ll i=0; i<N; ++i){ cin >> buf; L.emplace_back(buf); }
  sort(L.begin(), L.end());

  ll ans = 0;

  for(ll i=0; i<N; ++i)
  for(ll j=i+1; j<N; ++j){
    auto itr = lower_bound(L.begin(), L.end(), L[i]+L[j]);
    ans += max(0, (int)(itr-L.begin()-j-1));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt(); //N人の仲間たち
    int k = sc.nextInt(); //ジェットコースターに乗るのに必要なKcm
    int a[] = new int[n]; //仲間たちの身長を格納する配列
    int num = 0;          //乗ることのできる人数

    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      if(a[i] >= k){
        num++;
      }
    }

    System.out.println(num);
  }
}

Measured memory_bytes: 48388
import sys
input = sys.stdin.buffer.readline

mod = 10**9 + 7

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

se = []
hu = []

for e in a:
    if e > 0:
        se.append(e)
    elif e < 0:
        hu.append(-e)
se.sort()
hu.sort()

S = len(se)
H = len(hu)

Z = n - S - H

if Z + k > n:
    print(0)
    exit()

#negative個数の最小と最大
Hmi = max(0,k-Z-S)
Hma = min(k,H)

#正が無理なパターン
if Hmi == Hma and Hmi%2 == 1:
    if Z > 0:
        print(0)
    else:
        hu_mul = 1
        for i in range(Hmi):
            hu_mul = hu_mul*hu[i]%mod
        se_mul = 1
        for i in range(k-Hmi):
            se_mul = se_mul*se[i]%mod
        print((-hu_mul)*se_mul%mod)
else:
    se = se[::-1]
    hu = hu[::-1]
    hu_mul = 1
    se_mul = 1
    for i in range(Hmi):
        hu_mul = hu_mul*hu[i]%mod
    
    if Hmi%2 == 0:
        k -= Hmi
    else:
        hu_mul = hu_mul*hu[Hmi]%mod
        Hmi += 1
        k -= Hmi
    hidx = Hmi
    sidx = 0
    

    if k%2 == 1:
        if S == 0:
            print(0)
            exit()
        se_mul = se[0]
        sidx += 1
        k -= 1


    while k > 0:
        if hidx + 1 >= H and sidx + 1 >= S:
            print(0)
            exit()
        elif hidx + 1 >= H:
            se_mul = se_mul*(se[sidx]*se[sidx+1]%mod)%mod
            sidx += 2
        elif sidx + 1 >= S:
            hu_mul = hu_mul*(hu[hidx]*hu[hidx+1]%mod)%mod
            hidx += 2
        else:
            if hu[hidx]*hu[hidx+1] > se[sidx]*se[sidx+1]:
                hu_mul = hu_mul*(hu[hidx]*hu[hidx+1]%mod)%mod
                hidx += 2
            else:
                se_mul = se_mul*(se[sidx]*se[sidx+1]%mod)%mod
                sidx += 2
        k -= 2

    print((hu_mul)*se_mul%mod)





Measured memory_bytes: 106748
n = int(input())
s = input()

num_w = 0
num_e = s[1:].count("E")
ans = num_e
for i in range(n):
    if i == 0:
        continue
    if s[i] == "E":
        num_e -= 1
    if s[i-1] == "W":
        num_w += 1        
    ans = min(ans, num_w + num_e)
print(ans)

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

signed main(){
  int n,a,b; cin>>n>>a>>b;
  if(n%(a+b)==0){
    cout<<(n/(a+b))*a;
  }
  else if(n-n/(a+b)*(a+b)>a)
    cout<<n/(a+b)*a+a<<endl;
  else
    cout<<n/(a+b)*a+n-n/(a+b)*(a+b)<<endl;
}

Measured memory_bytes: 3580
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

def ptget(strings):
    if strings == "r":
        return p
    elif strings == "s":
        return r
    else:
        return s

dic = {}
point = 0
for i in range(len(t)):
    if i % k in dic:
        dic[i%k].append(t[i])
        if dic[i%k][len(dic[i%k])-2] == "n":
            point += ptget(t[i])
        elif dic[i%k][len(dic[i%k])-2] == dic[i%k][len(dic[i%k])-1]:
            dic[i%k][len(dic[i%k])-1] = "n"
        else:
            point += ptget(t[i])
    else:
        dic[i%k] = [t[i]]
        point += ptget(t[i])
print(point)

Measured memory_bytes: 23332
n, W = map(int, input().split())
w, v = [], []
for i in range(n):
	a, b = map(int, input().split())
	w.append(a)
	v.append(b)
sum_v = sum(v)
dp = [float('inf')] * (sum_v + 1)
dp[0] = 0
for i in range(n):
	for j in range(sum_v - v[i], -1, -1):
		dp[j + v[i]] = min(dp[j] + w[i], dp[j + v[i]])
res = 0
for vi, wi in enumerate(dp):
	if wi <= W:
		res = vi
print(res)

Measured memory_bytes: 91220
#include <stdio.h>

int main(void){

	int W,H,x,y,r;
	
	scanf ("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	int yokohabaminus,yokohabaplus;
	
	yokohabaminus = x - r;
	
	yokohabaplus = x + r;
	
	int tatehabaminus,tatehabaplus;
	
	tatehabaminus = y - r;
	
	tatehabaplus = y + r;
	
	if(yokohabaminus >= 0 && yokohabaplus <= W && tatehabaminus >= 0 && tatehabaplus <=H){
	
		printf ("Yes\n");
	 
	}else{
		
		printf ("No\n");
		
	}
	
	return 0;
	
}
		
	  


Measured memory_bytes: 2108
N, X = input().split()
N = int(N); X = int(X, 2)
p = int(input(), 2)
for i in range(N-1):
    v = int(input(), 2)
    if p > v:
        p, v = v, p
    while 0 < p:
        q = (v ^ (p << (v.bit_length() - p.bit_length())))
        if p < q:
            p, v = p, q
        else:
            p, v = q, p
    p = v

lx = X.bit_length()
lp = p.bit_length()

MOD = 998244353
ans = (X >> (p.bit_length() - 1)) % MOD

q = p << (lx - lp)
b = 1 << (lx - 1)

x = 0; y = 0
for k in range(lx - lp, -1, -1):
    if b & (X ^ y):
        y ^= q
    b >>= 1; q >>= 1
if y <= X:
    ans = (ans + 1) % MOD
print(ans)

Measured memory_bytes: 3188
object Main extends App {

  val n = scala.io.StdIn.readInt()

  def solve(): Int = {
    var ans = 0
    for(i <- 1 to n by 2) {
      var numOfDividers = 0
      for(j <- 1 to i) {
        if(i % j == 0) numOfDividers += 1
      }
      if(numOfDividers == 8) ans += 1
    }
    ans
  }


  println(solve)

}


Measured memory_bytes: 27204
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,t) for(int i=0;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N = 1e6 + 60; 
char s[N];
int n, ans, mc;
vector<int> a;

void solve() {
	lop(i, n) if (!i || s[i] != s[i - 1]) a.pb(s[i] - 'A');
	{
		int c[3] = {}; 
		for (int x : a) ++c[x];
		mc = min_element(c, c + 3) - c;		
		ans = c[mc];
		for (int &x : a) x = x == mc ? 0 : (x == 0 ? mc : x);
	}
	//for (int x : a) Pr("%d ", x); Pr("\n"); 
	if (ans) {
		int x[2] = {}, y[2] = {}, cur[2] = {};
		vector<array<int, 3>> w;
		int f = 1, h = -1;
		auto upd = [&]() {
			lop(k, 2) if (cur[k]) { 
				++x[k];
				y[k] += cur[k ^ 1] == 0 && !f;
			}
			f = 0; 
			w.pb({ cur[0], cur[1], h });
			cur[0] = cur[1] = 0;
			h = -1;
		}; 
		for (int x : a) {
			if (x == 0) upd(); 
			else {
				++cur[x - 1];
				if (h == -1) h = x - 1;
			}
		}
		f = 1, upd(); 

		lop(k, 2) if (x[k ^ 1] < y[k]) ans -= y[k] - x[k ^ 1];
		lop(k, 2) {
			vector<array<int, 3>> t;
			lop(i, w.size()) {
				if (x[k ^ 1] < y[k]) {
					if (i && i + 1 < w.size() && !w[i][k ^ 1]) {
						--x[k], --y[k]; 
						continue;
					}
				}
				t.pb(w[i]); 
			}
			w = t;
		}
		int len = w.size(), c[2] = {}; 
		
		for (auto e : w) lop(k, 2) c[k] += e[k];
		lop(k, 2) lop(i, len) {
			if (i && i + 1 < len && w[i][k ^ 1] == 0) continue;
			while (c[k] > c[k ^ 1] && w[i][k] && w[i][k] >= w[i][k ^ 1]) {
					--w[i][k], --c[k];
			}
		}
		vector<int> res;	
		lop(i, len) {
			while (c[0] >= len) {
				int g = w[i][0] + w[i][1]; 
				if (g <= 1) break;
				if (0 < i && i < len - 1 && g == 2) break;
				lop(k, 2) --c[k], --w[i][k]; 
			}
			int of = w[i][2];
			lop(k, 2) if (w[i][k] > w[i][k ^ 1]) of = k;
			lop(j, w[i][0] + w[i][1]) res.pb((j + of)% 2 + 1);
			if (i + 1 < len) res.pb(0); 
		}
		for (int v : res) {
			v = v == 0 ? mc : (v == mc ? 0 : v);
			putchar(v + 'A'); 
		}
	}
	puts(""); 
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	scanf("%s", s); 
	n = strlen(s); 
	solve(); 
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

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

    if(a <= c && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int num;  
  	int co[num];
  	int result=0;
  	scanf("%d",&num);
  	for(int i=0;i<num;i++){
  	     	scanf("%d",&co[i]);
  	 }
  	for(int u=0;u<num-1;u++){
 		for(int r=u+1;r<num;r++){
     		result+=co[u]*co[r];
    	}
    }
         printf("\n%d\n",result);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output2.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long N,A[200009];
    cin>>N;
    for(long i=0;i<N;i++)
        cin>>A[i];
    if(N%2)
    {
        for(long i=N;i>=1;i-=2)
            cout<<A[i-1]<<" ";
        for(long i=1;i<N-1;i+=2)
            cout<<A[i]<<" ";
    }
    else
    {
        for(long i=N;i>=1;i-=2)
            cout<<A[i-1]<<" ";
        for(long i=1;i<N;i+=2)
            cout<<A[i-1]<<" ";
    }
    return 0;
}

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

const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> dp(n+1,INF);
  dp[0] = 0;
  for(int i = 1; i <= n; i++) {
    dp[i] = dp[i-1]+1;
    for(int j = 1; pow(6,j) <= n; j++) {
      int six = pow(6,j);
      if(i < six) break;
      dp[i] = min(dp[i], dp[i-six]+1);
    }
    for(int j = 1; pow(9,j) <= n; j++) {
      int nine = pow(9,j);
      if(i < nine) break;
      dp[i] = min(dp[i], dp[i-nine]+1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 4008
def f(i, n, s)
  if n == 0
    $a += 1 if $u == s
    return
  end
  return if i == 10
  f(i+1, n, s)
  f(i+1, n-1, s+i)
end

while true
  $a = 0
  n, $u = gets.split.map(&:to_i)
  break if n == 0 && $u == 0
  f(0, n, 0)
  puts $a
end

Measured memory_bytes: 6092
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mxv=1e5+10;
int f[mxv];
int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    ++x;
    ++x;
    f[x]++;
  }
  int ans=0;
  for(int i=1;i<mxv-1;i++){
    ans=max(ans,f[i-1]+f[i+1]+f[i]);
  }
  printf("%d\n",ans);
  return 0;
}


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

long long N;
vector<long long> val;

int main(){
  cin >> N;

  long long i = 0;
  for(long long p = 1; p * p <= N; p++){
     if(N % p == 0) val.push_back(p + N / p);
  }
  
  /*平方根に最も近いやつ*/
  cout  << val[val.size()-1] - 2 << endl;   //2は(1,1)の1+1
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (S, T) = readInputLine().split(" ")
    val (A, B) = readInputLine().split(" ").map { it.toInt() }
    val U = readInputLine()

    if (U == S) {
        println("${A - 1} $B")
    } else {
        println("$A ${B - 1}")
    }

}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37992
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    ll X; cin>>X;

    for (int i = -120; i <= 120; ++i) {
        for (int j = -120; j <= 120; ++j) {
            if(pow(i,5)-pow(j,5) == X){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }


}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N;
    string S,T;
    cin >> S >> T;
    if(S.size()+1 == T.size()  && S == T.substr(0,S.size())){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long M = 1_000_000_007;
    int N = scanner.nextInt();
    int[][] a = new int[N + 1][N];
    for (int i = 1; i <= N; i++) for (int j = 0; j < N; j++) a[i][j] = scanner.nextInt();

    long[] dp = new long[1 << N];
    dp[0] = 1;

    for (int i = 1; i < 1 << N; i++) {
      int j = 0;
      for (int n = i; n > 0; n &= n - 1) j++;

      for (int k = 0; k < N; k++) {
        if ((i & (1 << k)) != 0) {
          dp[i] += dp[i ^ (1 << k)] * a[j][k];
          if (dp[i] > M) dp[i] -= M;
        }
      }
    }
    System.out.println(dp[(1 << N) - 1]);
  }
}


Measured memory_bytes: 42196
#include<stdio.h>
int main(void){
	int S,h,m,s;
	
	scanf("%d",&S);
	h=S/3600;
	m=(S%3600)/60;
	s=(S%3600)%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define ll long long int
using namespace std;
int n ;
double a[3005];
double dp[3005];
int main()
{
    cin>>n;
   // memset(dp,-1.00,sizeof(dp));
    rep(i,0,n)
    cin>>a[i];
    dp[0] = 1;
    for(int coin = 0;coin<n;++coin)
    {
        for(int i = coin+1;i>=0;i--)
        {
            dp[i] = (i == 0 ? 0 : dp[i-1]*a[coin] ) + dp[i]*(1-a[coin]);
        }
    }
    double ans = 0;
    for(int heads = 0;heads<=n;++heads)
    {
        int tails  = n-heads;
        if(heads>tails)
        {
            ans+=dp[heads];
        }
    }
    cout<<setprecision(12)<<ans<<endl;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<ll,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<int> a(n),b(n),c(n);
	rep(i, n)  cin >>a[i];
	rep(i, n)  cin >>b[i];
	rep(i, n)  cin >>c[i];
	sort(all(a)); sort(all(b)); sort(all(c));
	
	VL smb(n), smc(n);
	for(int i=0, j=0; i<n; i++){
		for(; j<n && a[j] < b[i]; j++){
			smb[i] = j+1;
		}
		if(i) smb[i] = max(smb[i], smb[i-1]);
	}
	//for(auto x :smb) printf("%lld, ",x); puts("");
	VL srb(n+1);
	rep(i, n) srb[i+1] = srb[i] + smb[i];
	for(int i=0, j=0; i<n; i++){
		for(; j<n && b[j] < c[i]; j++){
			smc[i] = j+1;
		}
		if(i) smc[i] = max(smc[i], smc[i-1]);
	}

	
	ll ans = 0;
	rep(i, n){
		ans += srb[smc[i]];
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 3712
def main():
    N, M, K = map(int, input().split())
    ok = False
    for i in range(N+1):
        for j in range(M+1):
            if K == i*(M-j) + j*(N-i):
                ok = True
                break
    print("Yes" if ok else "No")
         


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val S = nextLong()
    val x1 = 0L
    val y1 = 0L
    val x2 = 1000000000L
    val y2 = 1L
    val x3 = (x2 - S % x2) % x2
    val y3 = (S + x3) / x2
    println("${x1} ${y1} ${x2} ${y2} ${x3} ${y3}")
}
fun next() = readLine()!!
fun nextLong() = next().toLong()

Measured memory_bytes: 29788
import sys
sys.setrecursionlimit(15000)
n = int(input())
A = list(map(int,input().split()))

for i in range(n):
  if i != 0:
    parent = "parent key = {}, ".format(str(A[(i-1)//2]))
  else:
    parent = ""
  if i*2+1 < n:
    left = "left key = {}, ".format(str(A[i*2+1]))
  else:
    left = ""
  if i*2+2 < n:
    right = "right key = {}, ".format(str(A[i*2+2]))
  else:
    right = ""
  print("node {}: key = {}, {}{}{}".format(i+1,str(A[i]),parent,left,right))



Measured memory_bytes: 5624
#include <bits/stdc++.h> 
using namespace std; 
typedef   long long int  ll;
int main () 
{
  ll a,b,a1,b1,a2,b2,k;cin>>a>>b;
  b1=(b+1)/2;b2=b-b1;
  a1=(a+1)/2;a2=a-a1;
  k= (a1*b1)+(a2*b2);
  if (a==1||b==1) {cout<<"1"<<endl;}
  else {
  cout<<k<<endl;
  }
}

Measured memory_bytes: 256
import sys
import math
import bisect
import atexit
import io
import heapq
from collections import defaultdict, Counter
MOD = int(1e9+7)



# n = map(int, raw_input().split())
# input = map(int, raw_input().split())
def main():
    a, b = map(int, raw_input().split())
    print max(a+b, a-b, a*b)



main()


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

int main(){
    int n;
    cin >> n;
    vector<int>h(n);
    rep(i,n)cin >> h[i];
    bool ok = true;
    for(int i = n-1;i>0;i--){
        if(h[i-1]-1==h[i])h[i-1]--;
        if(h[i]<h[i-1])ok=false;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

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

int main(){
    int a, b, ans = 0;
    cin >> a >> b;
    ans = max({a + a - 1, a + b, b + b - 1});
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
for i in range(min(a),max(a)+1):
  cnt = 0
  for j in a:
    cnt += (j-i)**2
  if i == min(a):
    ans = cnt
  else:
    if cnt < ans:
      ans = cnt
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int r[200001]={0};
ll inf=1e18;
vec G[200001],A(200001),dp(200001,inf),ans(200001);
int dfs(int x){
    if(r[x]) return 0;
    r[x]=1;
    ll a=lower_bound(all(dp),A[x])-dp.begin(),b=*lower_bound(all(dp),A[x]);
    *lower_bound(all(dp),A[x])=A[x];
    ans[x]=lower_bound(all(dp),inf)-dp.begin();
    for(auto i:G[x]) dfs(i);
    dp[a]=b;
    return 0;
}
int main(){
    int n,u,v;
    cin>>n;
    rep(i,n) cin>>A[i+1];
    rep(i,n-1) cin>>u>>v,G[u].push_back(v),G[v].push_back(u);
    dfs(1);
    rep(i,n) cout<<ans[i+1]<<"\n";
}

Measured memory_bytes: 31208
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
p = l()

for i in range(n):
    if p[i] != i+1:
        cnt += 1

print("YES" if cnt <= 2  else "NO")

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

int main(){
    int a, b; cin >> a >> b;
    int cnt=1;
    int ans=0;

    while(cnt < b){
        cnt--;
        cnt += a;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

Measured memory_bytes: 73332
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int n,m;
void proc(){
 int date[101];
 memset(date,0,sizeof(date));
 rep(i,n){
  int x;
  cin>>x;
  rep(i,x){
   int t;
   cin>>t;
   ++date[t];
  }
 }
 int M=-1,md;
 rep(i,101){
  if(date[i]>=m){
   if(date[i]>M){
    M=date[i];
    md=i;
   }
  }
 }
 if(M==-1)cout<<0<<endl;
 else cout<<md<<endl;
}
int main(){
 while(true){
  cin>>n>>m;
  if(!n&&!m)return 0;
  proc();
 }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((a <= c && c <= b) || (b <= c && c <= a))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int main() {
  
  int64_t N, M; cin >> N >> M;
  
  if (N == 1 && M == 1) { cout << 1 << endl; return 0; }
  
  if (N == 1 || M == 1) { cout << max(N, M) - 2 << endl; return 0; }
  
  if (N == 2 || M == 2) { cout << 0 << endl; return 0; }
  
  cout << (N - 2) * (M - 2) << endl;
  
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cctype>
#include <queue>
#include <complex>
#include <functional>
#include <sstream>
#include <tuple>

using namespace std;

int main()
{
#ifdef IMPETUS
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    int result = 0;
    for (int i = 1; i <= n; i += 2)
    {
    	int cnt = 0;
    	for (int j = 1; j <= i; j++)
    		cnt += i % j == 0;
    	result += cnt == 8;
    }
    cout << result;
    return 0;
}

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

sum_W = sum(W_lis)
s = 0

min_ = sum_W

for n, w in enumerate(W_lis[:-1]):
  s += w
  tmp = abs(sum_W - 2 * s)
  if tmp < min_:
    min_ = tmp

print(min_)

Measured memory_bytes: 3060
N=gets.to_i;r=1.step(N-2,2).map{|i|[0,i]};(N%2).step(N-1,2){|i|r<<[N-1,i]<<[i,N-1]};1.step(N-2,3){|j|(1+j%2).step(N-2,2){|i|r<<[i,j]}};p r.size;puts r.map{|e|e*' '}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int W, H, N;
	cin >> W >> H >> N;
	VI xs, ys, as;
	rep (i, N) {
		int x, y, a;
		cin >> x >> y >> a;
		xs.pb(x);
		ys.pb(y);
		as.pb(a);
	}
	int sx = 0, sy = 0;
	rep (i, N) {
		switch (as[i]) {
			case 1:
				sx = max(sx, xs[i]);
				break;
			case 2:
				W = min(W, xs[i]);
				break;
			case 3:
				sy = max(sy, ys[i]);
				break;
			case 4:
				H = min(H, ys[i]);
				break;
			default:
				break;
		}
	}
	cout << max(H - sy, 0) * max(W - sx, 0) << endl;
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional> // for less 
    using namespace __gnu_pbds; 
    using namespace std;
    //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;    
    #define ll            long long
    #define pb            push_back
    #define ppb           pop_back
    #define si            set <ll>
    #define endl          '\n'
    #define fr            first
    #define sc            second
    #define mii           map<ll,ll>
    #define msi           map<string,ll>
    #define mis           map<ll,string>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define all(v)        v.begin(),v.end()
    #define sort(v)       sort(all(v))
    #define pii           pair<ll ,ll >
    #define vi            vector<ll >
    #define vii           vector<pair<ll,ll>>
    #define vs            vector<string>
    #define sz(x)         (ll)x.size()
    #define M             1000000007
    #define bs            binary_search
    #define rev(a)        reverse(all(a));
    #define sp(n)         setprecision(n)
    #define spl           " "
    #define arr(a,n)      rep(i,0,n) cin>>a[i]
    #define mod           998244353
    #define print_vector(a)  for(auto t:a) cout<<t<<" ";cout<<endl;
    #define print_arr(a,n)   rep(i,0,n) cout<<a[i]<<" "; cout<<endl;        
    #define show(a,n)     for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    #define N             100000000
    #define debug(x)      cout << #x << " is " << x << endl;
    #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    #define INF           1ll<<31
    #define hi            cout<<"hi"<<endl;
    const ll maxn=200005;
    void solve()
    {
      ll a,b,c;
      cin>>a>>b>>c;
      cout<<c<<" "<<a<<" "<<b<<endl;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        //#endif
        ll t=1;
        //cin>>t;
        while(t--) solve();
    }
    
  

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>


#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;

using namespace std;

int gcd(int a, int b)
{
   if (b > a)
   {
      std::swap(a, b);
   }

   if (a % b == 0)
   {
      return b;
   }
   else
   {
      return gcd(b, a % b);
   }
}

int main () {

   int k; cin >> k;

   ll sum = 0;
   for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
         for (int n = 1; n <= k; n++) {
            int t = gcd(i, j);
            sum += gcd(t, n);
         }
      }
   }

      cout << sum << endl;
}
   
   


   


Measured memory_bytes: 3612
N=int(input())
l={}

for i in range(N):
  s=input()
  if s in l:
    l[s]+=1
  else:
    l[s]=1


# l=sorted(l,key=lambda x:x[1])

# ma=max(l)
# max_value=l[ma]
max_value=0
for i in l:
  if max_value<l[i]:
    max_value=l[i]
# print(max_value)

ans=[]

for i in l:
  if max_value==l[i]:
    ans.append(i)
ans.sort()

for i in ans:
  print(i)


Measured memory_bytes: 32096
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
mae = -1
for i in range(n):
    a = A[i]
    ans += B[a-1]
    if a - 1 == mae:
        ans += C[mae-1]
    mae = a
print(ans)


Measured memory_bytes: 38504
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x,m,k=1000,ans; cin>>n>>x;
  for(int i=0; i<n; i++){
    cin>>m; x-=m;
    k=min(k,m);
  }
  cout<<n+x/k;
}

Measured memory_bytes: 256