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

using namespace std;

int main()
{
  long long a, b, k;
  cin >> a >> b >> k;
  long long tmp = min(a, k);
  a -= tmp, k -= tmp;
  tmp = min(b, k);
  b -= tmp;
  cout << a << ' ' << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 5000000000000000
#define endl '\n'
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;

signed main(){
    int n,t; cin>>n>>t;
    vector<int> a(n),max_a(n),profit(n);
    rep(i,n)cin>>a.at(i);
    
    int max_A=0;
    for(int i=n-1; i>=0; i--){
        chmax(max_A, a.at(i));
        max_a.at(i)=max_A;
    }
    
    t/=2;
    rep(i,n){
        profit.at(i)=(max_a.at(i)-a.at(i))*t;
    }
    
    sort(all(profit),greater<int>());
    int ans=1;
    rep(i,n-1){
        if(profit.at(i)==profit.at(i+1))ans++;
        else break;
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(void){
    long int a,b,c,d,e,f,r=1,i,n,cd,count1=0,count2=0,count3=0;
    scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
    e=c;
    f=d;
    do{
        r = e % f;
        e = f;
        f = r;
    }while(r!=0);
    cd=(c*d)/e;
    if(a%c==0){
        count1=(b/c)-(a/c)+1;
    }else{
        count1=(b/c)-(a/c);
    }
    if(a%d==0){
        count2=(b/d)-(a/d)+1;
    }else{
        count2=(b/d)-(a/d);
    }
    if(a%cd==0){
        count3=(b/cd)-(a/cd)+1;
    }else{
        count3=(b/cd)-(a/cd);
    }
    //printf("%d %d %d",count1,count2,count3);
    printf("%ld",b-a+1-count1-count2+count3);
    return 0;
}


Measured memory_bytes: 128
// inputに入力データ全体が入る
function Main(input) {
	var array = input.split("\n");
  	var count = Number(array[0]) - 1;
	var forcount = count - 1;
  		array = array[1].split(" ");

  	var front_sum = Number(array[0]);
    var back_sum = Number(array[count]);

  	var front_count = 0;
	var back_count = count;
  	
	for(var i = 0; i < forcount; i++){
		if(front_sum < back_sum) {
          front_count = front_count + 1;
          front_sum = front_sum + Number(array[front_count]);
        }
        else{
          back_count = back_count - 1;
          back_sum = back_sum + Number(array[back_count]);
        }
    }
 	console.log(Math.abs(front_sum - back_sum));
 }
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
s = input()
if s[-1] =='<':
  s = s+'>' 
if s[0] =='>':
  s = '<'+s 
n = len(s)+1

def rui(n):
  return n*(n+1)//2
  
tani = []
yama = []
tani.append(0)

for i in range(n-1):
  if s[i:i+2] =='><':
    tani.append(i+1)
  elif s[i:i+2] =='<>':
    yama.append(i+1)
    
tani.append(n-1)

count = 0
for i in range(len(yama)):
  d1 = yama[i] - tani[i]
  d2 = tani[i+1] - yama[i]
  count += rui(max(d1,d2)) + rui(min(d1,d2)-1)
  
print(count)
  

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

const int MAXN = 3010;

int len[MAXN][MAXN];
pair<int, int> pre[MAXN][MAXN];





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

  string s, t; cin >> s >> t;

  for (int a = 1; a <= s.size(); ++a) for (int b = 1; b <= t.size(); ++b) {
    if (len[a][b] < len[a - 1][b - 1] + (s[a - 1] == t[b - 1])) {
      pre[a][b] = {a - 1, b - 1};
      len[a][b] = len[a - 1][b - 1] + (s[a - 1] == t[b - 1]);
    }
    if (len[a][b] < len[a][b - 1]) {
      pre[a][b] = {a, b - 1};
      len[a][b] = len[a][b - 1];
    }
    if (len[a][b] < len[a - 1][b]) {
      pre[a][b] = {a - 1, b};
      len[a][b] = len[a - 1][b];
    }
  }
  




  int a = s.size(), b = t.size();
  string ans;
  while (a != 0 or b != 0) {
    int pa, pb; tie(pa, pb) = pre[a][b];
    if (pa == a - 1 and pb == b - 1 and s[pa] == t[pb]) ans.push_back(s[pa]);
    a = pa, b = pb;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << '\n';

}


Measured memory_bytes: 106368
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    long long a,b,x;
    cin >> a >> b >> x;
    long long ans = (b / x) - (a - 1) / x;
    if(a == 0){
        ans = b / x + 1;
    }
    cout << ans << endl;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  if(a>=13){
    cout << b << endl;
  }else if(6 <= a && a <= 12){
    cout << b/2 << endl;
  }else{
    cout << 0 << endl;
  }
    
  return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define EPS 1e-8

int main(){
    int a=0,b=0,c=0,d=0;
    int x,y,z;
    while(cin>>x>>y>>z){
        vi in;
        in.pb(x);
        in.pb(y);
        in.pb(z);
        sort(all(in));
        
        if(in[0]+in[1]<=in[2]){
            cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
            while(cin>>x>>y>>z);
            break;
        }
        else a++;
        
        double l,m,n;
        l = acos( (-1*in[0]*in[0] + in[1]*in[1] + in[2]*in[2])/(2.0*in[1]*in[2]) );
        m = acos( (-1*in[1]*in[1] + in[2]*in[2] + in[0]*in[0])/(2.0*in[2]*in[0]) );
        n = acos( (-1*in[2]*in[2] + in[0]*in[0] + in[1]*in[1])/(2.0*in[0]*in[1]) );
        
        l=l*180/3.141592;
        m=m*180/3.141592;
        n=n*180/3.141592;

        
        if( (l-90)*(l-90)<EPS || (m-90)*(m-90)<EPS || (n-90)*(n-90)<EPS ){
            b++;
        }
        else if( l>90-EPS || m>90-EPS || n>90-EPS ){
            d++;
        }
        else c++;
    }
}

Measured memory_bytes: 1264
/* 
   AOJ 2589
   North North West
   2015/8/7
*/

#include<stdio.h>
#include<string.h>

#define INPUT_MAX 100
#define N_W_MAX 25

struct fraction
{
  int numerator, denominator;
};

void translate_n_w_from_back(char* in_str, char* back_n_w, int length)
{
  int i = length - 1, j = 0;
  while(i >= 0)
    {
      if(in_str[i] == 'h')
	{
	  back_n_w[j] = 'n';
	  j++;
	  i = i - 5;
	}
      else
	{
	  back_n_w[j] = 'w';
	  j++;
	  i = i - 4;
	}
    }
  back_n_w[j] = '\0';
}

int powered_two(int n)
{
  int i, ret = 1;

  for(i = 0; i < n; i++)
    {
      ret *= 2;
    }
  return ret;
}

/* void calc_fraction(char* n_w, int* numerator, int* denominator) */
/* { */
/*   int i; */

/*   for(i = 0; n_w[i] != '\0'; i++) */
/*     { */
/*       if(n_w[i] == 'n') */
/* 	{ */
/* 	  *numerator += 0; */
/* 	} */
/*       else */
/* 	{ */
/* 	  *numerator += 90 * *denominator; */
/* 	} */
/*       *denominator = powered_two(i); */
/*     } */

/*   //  return numerator / denominator; */
/* } */

struct fraction calc_fraction(char* n_w)
{
  struct fraction frac;
  int max_bound = 90, min_bound = 0, i, angle = 0;
  
  frac.numerator = 0;
  frac.denominator = 1;

  for(i = 0; n_w[i] != '\0'; i++)
    {
      if(i == 0)
	{
	  if(n_w[i] == 'w')
	    {
	      frac.numerator = 90;
	    }
	}
      else
      	{
	  if(n_w[i] == 'n')
	    {
	      frac.numerator = frac.numerator * 2 - 90;
	    }
	  else
	    {
	      frac.numerator = frac.numerator * 2 + 90;
	    }
	  frac.denominator = powered_two(i);
      	}
    }
  return frac;
}

struct fraction lowest_terms(struct fraction frac)
{
  while(frac.denominator != 1)
    {
      if(frac.numerator % 2 == 0)
	{
	  frac.numerator = frac.numerator / 2;
	  frac.denominator = frac.denominator / 2;
	}
      else
	{
	  return frac;
	}
    }
  return frac;
}

struct fraction ans_f(char* in_str)
{
  struct fraction frac;
  int in_str_len = strlen(in_str);
  char back_n_w[N_W_MAX];
  //  printf("%d", len);

  translate_n_w_from_back(in_str, back_n_w, in_str_len);

  //  printf("%s\n", back_n_w);
  //printf("%d\n", back_n_w_len);

  frac = calc_fraction(back_n_w);
  
  // printf("%d/%d\n", *numerator, *denominator);
  frac = lowest_terms(frac);

  //  printf("%d %d\n", numerator, denominator);

  return frac;
}

int main(void)
{
  //  int numerator = 0, denominator = 1;
  struct fraction frac;
  char in_str[INPUT_MAX];
  while(1)
    {
      gets(in_str);
      if(in_str[0] == '#')
	{
	  break;
	}
      frac = ans_f(in_str);
      if(frac.denominator == 1)
	{
	  printf("%d\n", frac.numerator);
	}
      else
	{
	  printf("%d/%d\n", frac.numerator, frac.denominator);
	}

      //      printf("%s", out_str);
    }
  return 0;
}

Measured memory_bytes: 524
// ------------------------------------
// Date:2018/ 2/23
// Problem:ABC 046 PaintinBallsWithAtCoDeer b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

#define MOD 1000000007

int main()
{
  int N,K;
  cin >> N >> K;
  ll ans = K;
  REP(i,N-1) ans *= K-1;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int main(void) {
	long long n, d, a;
	cin >> n >> d >> a;
	d *= 2;
	vector<pair<int, int> > monster(n);
	for (int i = 0; i < n; ++i)
		cin >> monster[i].first >> monster[i].second;
	sort(monster.begin(), monster.end());
	queue<pair<long long, long long> > bomb;

	long long ans = 0, damage_sum = 0;
	for (int i = 0; i < n; ++i) {
		long long pos = monster[i].first;

		while (bomb.size() && bomb.front().first < pos) {
			damage_sum -= bomb.front().second;
			bomb.pop();
		}
		long long health = monster[i].second - damage_sum;

		if (health > 0) {
			long long threw = (health + a - 1) / a;
			ans += threw;
			long long damage = threw * a;
			damage_sum += damage;
			bomb.push({ pos + d,damage });
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
import scala.io.StdIn.{readLine,readInt}
/**
  * AOJ
  */

object Main {

  def main(args: Array[String]): Unit = {
    println(if(find(read,read)){"Yes"}else{"No"})
  }

  def find(dice1:Array[Int],dice2:Array[Int]) : Boolean = {
    for(i <- createDiceArray(dice1,"WNNNW"); j <- createDiceArray(i,"HHH")){
      if(diceMatch(j,dice2)){return true}
    }
    return false
  }

  def createDiceArray(dice:Array[Int],commands:String) : List[Array[Int]] = {
    var dices = List(dice)
    for(cmd <- commands.toCharArray){
      dices :+= getNextStatus(cmd,dices.last)
    }
    dices
  }

  def read() : Array[Int] = {readLine().split(" ").map(_.toInt)}

  def diceMatch(dice1:Array[Int],dice2:Array[Int]):Boolean = (dice1 zip dice2).forall(x => x._1 == x._2)

  def getNextStatus(cmd:Char,dice:Array[Int]): Array[Int] = {
    cmd match {
      case 'N' => Array(dice(1), dice(5), dice(2), dice(3), dice(0), dice(4))
      case 'W' => Array(dice(2), dice(1), dice(5), dice(0), dice(4), dice(3))
      case 'H' => Array(dice(0), dice(2), dice(4), dice(1), dice(3), dice(5))
    }
  }
}

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

int main() {
string s;
cin >> s;
string a,b,c;
a = s.substr(0,5);
b = s.substr(6,7);
c = s.substr(14,5);
cout << a << " " << b << " " << c << endl;
 }

Measured memory_bytes: 3608
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

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

#define         rep(i,n)       for ( i=0 ; i<n ; i++ )
#define         rep1(i,n)      for ( i=1 ; i<=n ; i++ )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"YES"<<"\n"
#define         no             cout<<"NO"<<"\n"
#define         pb             push_back
#define         prl            pair< ll , ll >
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         ss             second
#define         Faysal         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){Faysal

    ll ans,sum,tot,cnt,mx,mn,idx,chk,rem,ret,tmp,mid,lft,rgt,pos;

    ll tc,n,m,a,b,c,d,g,h,l,r,x,y,i,j,k;

    cin>>n>>k;
    cnt=0;
    while(n>0)
    {
        cnt++;
        n/=k;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
N = input()
length = len(N)
N = int(N)
answer = 0

for i in range(1, length, 2):
    answer += 10 ** i - 10 ** (i - 1)

if length % 2 == 1:
    answer += N - 10 ** (length - 1) + 1

print(answer)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 100005
#define ll long long int
long long int MOD=998244353;
long long int mod=1e9+7;
long long int INF=1e18;

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            {cout<<"NO";return 0;}

    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    char a;
    cin>>a;
    if(a<='Z'){
        cout<<"A"<<endl;
    }
    else
    cout<<"a"<<endl;
}


Measured memory_bytes: 3628
# frozen_string_literal: true

def factor(n)
  return [1] if n == 1

  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n`.split.map(&:to_i)
end

# Example: factors(100) => {2=>2, 5=>2}
def factors_and_num(n)
  factors = factor(n)
  ret = Hash.new(0)
  factors.each do |i|
    ret[i] += 1
  end
  ret
end

def uniq_factor(n)
  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n|uniq`.split.map(&:to_i)
end

n = gets.to_i

if n == 1
  puts 0
  exit
end

f = factors_and_num(n)

ans = 0

f.each do |_k, v|
  s = 0
  count = 1
  while v - count >= 0
    s += 1
    v -= count
    count += 1
  end
  ans += s
end

puts ans


Measured memory_bytes: 14436
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int main(){
	int n;
	cin>>n;
	int a[n];
	ordered_set oset;
	vector<int> q;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
//	cout<<"q"<<q[1]<<endl;
	for(int i=1;i<n-1;i++){
		q.clear();
		q.pb(a[i-1]);
	q.pb(a[i]);
	q.pb(a[i+1]);
		sort(q.begin(),q.end());
		if(q[1]==a[i])
		oset.insert(q[1]);
	//	cout<<"q="<<q[1]<<endl;
	}
	cout<<oset.size();
}

Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=input()
    N=len(S)
    a=S[0]
    ans=0
    for i in range(N):
        if S[i]!=a:
            ans+=1
            a=S[i]
            
    print(ans)

main()


Measured memory_bytes: 39408
#include<iostream>
#include<vector>
#define debug_C(a) cout << a << endl;
using namespace std;
int main() {
	int x=0, y=0,N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		x += 800;
		if (i % 15 == 0) y += 200;
	}
	cout << x - y << endl;
	

	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool as[26] = {};
    for(int i = 0; i < n ; i++){
        as[(int)s[i] - (int)'a'] = 1;
    } 
    for(int i = 0; i < 26; i++){
        if(as[i] == 0){
            cout << (char)(i+(int)'a') << endl;
            return 0; 
        }
    }
    cout << "None" << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#define INF 999999999
#define pause system("pause")
using namespace std;

typedef long long int ll;


int n;



int main() {
	map<string, int> m;
	string s;
	cin >> s;
	m["SUN"] = 7;
	m["MON"] = 6;
	m["TUE"] = 5;
	m["WED"] = 4;
	m["THU"] = 3;
	m["FRI"] = 2;
	m["SAT"] = 1;
	cout << m[s];
	//pause;
	return 0;
}

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int cnt = 0, i = 0;
  for(int i = 0; i < n - 2; i++){
    if(s.at(i) == 'A' && s.at(i+ 1) == 'B'&& s.at(i+ 2) == 'C'){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
n, a = map(int, input().split())
x = list(map(int, input().split()))
y = [v-a for v in x]

dp = [[0] * 5000 for _ in range(n+1)]
zero = 2500
dp[0][zero] = 1
for i in range(n):
    for j in range(5000):
        dp[i+1][j] += dp[i][j]
        if j + y[i] < 5000:
            dp[i+1][j+y[i]] += dp[i][j]

print(dp[n][zero] - 1)

Measured memory_bytes: 69636
from bisect import bisect_right


def main():

    N,W = map(int, input().split())
    wv = []
    for _ in range(N):
        v,w = map(int, input().split())
        wv.append([w,v])

    d1 = [[0,0]]
    d2 = [[0,0]]
    half = N // 2

    for i in range(half):
        w,v = wv[i]
        size = len(d1)
        # i-1までに作っている組について、iを足すパターンを加える
        for j in range(size):
            d1.append([d1[j][0] + w, d1[j][1] + v])

    for i in range(N - half):
        w,v = wv[half + i]
        size = len(d2)
        for j in range(size):
            d2.append([d2[j][0] + w, d2[j][1] + v])

    d1.sort()
    d2.sort()

    # i+1番目はiより重いが、iより価値が低いなら、i+1の重さまででiの価値ができるやで、に塗り替える
    for i in range(len(d2) - 1):
        if d2[i+1][1] < d2[i][1]:
            d2[i+1][1] = d2[i][1]

    ans = 0
    INF = float("inf")
    for w,v in d1:
        if w > W:
            continue

        rest = W - w
        idx = bisect_right(d2, [rest, INF])
        ans = max(ans, d2[idx - 1][1] + v)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 358596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll T;
int K,Q;

int main(){
	cin>>T;
	cin>>K;
	set<P> events;
	rep(i,K){
		int t;
		cin>>t;
		events.insert(P(t,-1));	//reverse query
	}
	cin>>Q;
	rep(i,Q){
		ll t,f;
		cin>>t>>f;
		events.insert(P(t,f));
	}

	bool inc = 0;
	ll pt = 0;
	ll a = 0, b = T, c = 0;
	for(P e:events){
		ll t = e.fs;
		ll x = e.sc;

		if(inc){
			ll d = t-pt;
			c += d;
			if(b+c>T) b = T-c;
			if(a>b) a = b;
		}else{
			ll d = t-pt;
			c -= d;
			if(a+c<0) a = -c;
			if(a>b) b = a;
		}
		if(x==-1){	//reverse
			inc = !inc;
		}else{		//answer
			cout<<max(a,min(b,x))+c<<endl;
		}
		pt = t;
	}
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000

int main() {
  string s; cin >> s;
  int i = 0, scnt = 0, ecnt = 0;
  while (1) {
    if (s.at(i) == 'A') {
      break;
    }
    scnt++;
    i++;
  }
  i = s.size() - 1;
  while (1) {
    if (s.at(i) == 'Z') {
      break;
    }
    ecnt++;
    i--;
  }
  cout << s.size() - ecnt - scnt << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

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

int main()
{

    int n, k, h[N] = {};

    cin >> n >> k;
    FOR(i, 0, n)
    {
        cin >> h[i];
    }

    sort(h, h + n);
    int res = INF;
    FOR(i, 0, n - k + 1)
    {
        res = min(res, h[i + k - 1] - h[i]);
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    char[] cs;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int i = 0;
        for (; i < cs.length; i++) {
            if (cs[i] == 'A') {
                break;
            }
        }
        int j = cs.length - 1;
        for (; j >= 0; j--) {
            if (cs[j] == 'Z') {
                break;
            }
        }
        System.out.println(j - i + 1);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 27860
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 1e5 + 10;
pair<ll,ll> a[MAXN];

void solve(){
    ll n; cin>>n;

    FOR(i,1,n){
        cin>>a[i].first;
        a[i].second = i;
    }

    sort(a+1,a+n+1);

    FOR(i,1,n) cout<<a[i].second<<" ";
}
 
signed main(){
 
   FastRead;    
 

    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 2432
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];sort(a,a+n);
    ll ans=0;
    ll s=n-k;
    rep(i,0,s-1)ans+=a[i];
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1792
unittest
{
	assert( [ "7", "beat", "vet", "beet", "bed", "vet", "bet", "beet" ].parse.expand.solve == "beet\nvet" );
	assert( [ "8", "buffalo", "buffalo", "buffalo", "buffalo", "buffalo", "buffalo", "buffalo", "buffalo" ].parse.expand.solve == "buffalo" );
	assert( [ "7", "bass", "bass", "kick", "kick", "bass", "kick", "kick" ].parse.expand.solve == "kick" );
	assert( [ "4", "ushi", "tapu", "nichia", "kun" ].parse.expand.solve == "kun\nnichia\ntapu\nushi" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto ss = new dchar[][ n ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front.to!( dchar[] );
	}
	return tuple( ss );
}

auto solve( dchar[][] ss )
{
	auto gs = ss.sort().group.array.sort!( ( a, b ) => b[ 1 ] < a[ 1 ] );
	auto fs = gs.filter!( ( a ) => gs.front[ 1 ] == a[ 1 ] ).map!( ( a ) => a[ 0 ] ).array.sort();
	return fs.join( "\n" );
}


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

signed main(void)
{
	int h, w, cnt;
	int c[10][10];

	cin >> h >> w;
	rep(i, 10) rep(j, 10) cin >> c[i][j];
	cnt = 0;
	rep(k, 10) rep(i, 10) rep(j, 10)
		c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
	rep(i, h) rep(j, w)
	{
		int a;
		cin >> a;
		if (a >= 0) cnt += c[a][1];
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
N = input()

s_n = 0
for n in N:
  s_n += int(n)

if int(N) % s_n == 0:
  print("Yes")
else:
  print("No")

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

int main(){
  ll h,n,ma1=0,ma2=0,ma2i=0,maryoku=0,ans=0;
  cin >> h >> n;
  double a2,b2;
  ll a[n],b[n],dp[10000001]={0};
  r(i,n){
    cin >> a[i] >> b[i];
    ma1=max(a[i],ma1);
    a2=a[i]*10000000; b2=b[i];
    if(ma2<a2/b2){
      ma2i=i;
      ma2=a2/b2;
    }
  }
  
  while(ma1*100<h){
    h-=a[ma2i];
    ans+=b[ma2i];
  }
   while(dp[maryoku]<h){
    maryoku++;
     dp[maryoku]=dp[maryoku-1];
    r(i,n){
      if(maryoku-b[i]>=0&&dp[maryoku]<dp[maryoku-b[i]]+a[i]){
        dp[maryoku]=dp[maryoku-b[i]]+a[i];
      }
    }
  }
cout<<maryoku+ans<<endl;
}

Measured memory_bytes: 78336
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
int n;
int a[200001];
long long s1,s2;
long long ans=1e18;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i),s2+=a[i];
	for(int i=1;i<n;i++)
	{
		s1+=a[i];
		s2-=a[i];
		ans=min(ans,abs(s1-s2));
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
list = [list(map(int,input().split())) for i in range(N)]
if N%2 == 1:
  list.sort()
  #print(list)
  m = list[(N+1)//2-1][0]
  #print('m',m)
  list.sort(key=lambda x: x[1])
  #print(list)
  M = list[(N+1)//2-1][1]
  #print('M',M)
  print(M-m+1)
else:
  list.sort()
  m = list[N//2-1][0]+list[N//2][0]
  list.sort(key=lambda x: x[1])
  M = list[N//2-1][1]+list[N//2][1]
  print(M-m+1)

Measured memory_bytes: 49092
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
template<typename T>
T rabs(T x)
{
	return x>0?x:-x;
}
vector<int>cc[2];
int o=0;
int n;
char str[8005];
int tx,ty;
int sum1,sum2;
bitset<8005>dp1;
bitset<8005>dp2;
int main()
{
	scanf("%s",str);
	n=strlen(str);
	read(tx);
	read(ty);
	str[n]='T';
	n++;
	str[n]=0;
	int las=-1;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='T')
		{
			if(las!=-1)
				cc[o].push_back(i-las-1);
			else
				tx-=i;
			las=i;
			o=!o;
		}
	}
	int sz1=cc[0].size();
	int sz2=cc[1].size();
	tx=rabs(tx);
	ty=rabs(ty);
	for(int i=0;i<sz1;i++)
		sum1+=cc[0][i];
	for(int i=0;i<sz2;i++)
		sum2+=cc[1][i];
	if((sum1%2!=tx%2) || (sum2%2!=ty%2) || tx>sum1 || ty>sum2)
	{
		printf("No\n");
		return 0;
	}
	tx=(tx+sum1)/2;
	ty=(ty+sum2)/2;
	dp1[0]=1;
	dp2[0]=1;
	for(int i=0;i<sz1;i++)
		dp1|=(dp1<<cc[0][i]);
	for(int i=0;i<sz2;i++)
		dp2|=(dp2<<cc[1][i]);
	if(dp1[tx] && dp2[ty])
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
main = do
  line <- getLine
  let 
    [a,b,c,d] = map read $ words line :: [Int]
    judge =
      if (abs (a - c) <= d || (abs (a-b) <= d && abs (b-c) <= d))
        then "Yes"
        else "No"
    in
      putStrLn $ judge


Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, m, s = 0;

    cin >> n;

    m = n;

    while (m) {

        s+=m%10;
        m/=10;
    }

    if (n%s) cout << "No";
    else cout << "Yes";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    rep (i, 2 * b) {
        if (a * i % b == c) {
            cout << "YES\n"; return 0;
        }
    }
    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

char map[6][6] = {};
int main()
{
    int H, W, K;
    std::cin >> H >> W >> K;
    for (int j = 0; j < H; j++)
    {
        for (int i = 0; i < W; i++)
        {
            std::cin >> map[j][i];
        }
    }
    int count = 0;
    // 2^H * 2^W <= 2^6 * 2^6 = 2^12 = 4096
    for (int row = 0; row < (1 << H); row++)
    {
        for (int column = 0; column < (1 << W); column++)
        {
            int n = 0; // 残る黒石の数
            for (int i = 0; i < H; i++)
            {
                if (row & (1 << i))
                    continue;
                for (int j = 0; j < W; j++)
                {
                    if (column & (1 << j))
                        continue;
                    if (map[i][j] == '#')
                        n++;
                }
            }
            if (n == K)
                count++;
        }
    }
    std::cout << count << std::endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define ll long long 
#define N 3005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define piii pair<int, pii>
#define print(x) cout << #x << "=" << x << "\t";
#define endl "\n"
#define newline cout << endl;

int n;
double p[N];
double dp[N][N];

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); 
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> p[i];
    dp[1][0] = 1 - p[1];
    dp[1][1] = p[1];
    for(int i=2;i<=n;i++) {
        dp[i][0] = dp[i - 1][0] * (1 - p[i]);
        for(int j=1;j<=i;j++)
            dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
    }
    double ans = 0;
    for(int j = (n + 1) / 2; j <= n; j++)
        ans += dp[n][j];
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}


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

int main(void){
	int n;
	cin>>n;
	ll a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	ll sum =abs( a[0]);
	for(int i=1; i<n; i++){
		sum += abs(a[i]-a[i-1]);
	}
	sum +=abs( a[n-1]);
	ll b[n];
	for(int i=0; i<n-1; i++){
		if(i==0){
			ll val = sum;
			val -= (abs(a[i]) + abs(a[i] - a[i+1]));
			val += abs(a[i+1]);
			b[i] = val;
			continue;
		}
		ll val = sum;
		val -= (abs(a[i-1] - a[i]) + abs(a[i]-a[i+1]));
		val += abs(a[i-1]-a[i+1]);
		b[i] = val;
	}
	ll val = sum;
	val -= (abs(a[n-2] - a[n-1])+ abs(a[n-1]));
	val += abs(a[n-2]);
	b[n-1] = val;
	for(int i=0 ;i<n; i++){
		cout<<b[i]<<endl;
	}
}

Measured memory_bytes: 2816
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
s = sum(a)

cum = [0]
for i in range(2*n):
    cum.append(cum[-1] + a[(i*2+1)%n])
anss = [0] * n
for i in range(n):
    anss[i*2%n] = s - 2*(cum[i+n//2]-cum[i])

for x in anss:
    print(x, end="")
    print(" ", end="")

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


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################


class UnionFind:
    def __init__(self, N):
        self.rank = [0] * N
        self.parent = [i for i in range(N)]
        self.n = N
        self.size = [1 for i in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if (x == y):
            return

        if (self.rank[x] < self.rank[y]):
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_parents(self):
        count = 0
        for i in range(self.n):
            if self.find(i) == i:
                count += 1

        return count

    def get_size(self, x):
        root = self.find(x)
        return self.size[root]


N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    A.append(a)
    B.append(b)

uf = UnionFind(N)

ans = [0] * M

i = M-1
ans[i] = (N*(N-1)) // 2
while i > 0:
    if not uf.same(A[i], B[i]):
        ans[i-1] = ans[i] - (uf.get_size(A[i]) * uf.get_size(B[i]))
        uf.unite(A[i], B[i])
    else:
        ans[i-1] = ans[i]

    i -= 1

print(*ans, sep="\n")


Measured memory_bytes: 20104
from collections import defaultdict
def main():
  def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n ** (1 / 2)) + 1):
      if is_prime[i]:
        for j in range(i * i, n + 1, i):
          is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
  
  prime_list = primes(100000)
  solvers = [[] for _ in range(100001)]
  for p in prime_list:
    for i in range(p, 100001, p):
      solvers[i].append(p)
   
  n = int(input())
  a_list = list(map(int, input().split()))
  parent = [i for i in range(100001)]
  
  def find(x):
    if x == parent[x]:
      return x
    parent[x] = find(parent[x])
    return parent[x]
  
  for i, v in enumerate(a_list):
    p_rep = find(min(solvers[v]))
    for s in solvers[v]:
      parent[find(s)] = p_rep
    parent[find(v)] = p_rep
  
  dic = defaultdict(set)
  for i, v in enumerate(a_list):
    dic[find(v)].add(i)
  
  a_list.sort()
  for i, v in enumerate(a_list):
    if i not in dic[find(v)]:
      print(0)
      break
  else:
    print(1)

main()



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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  vector<int> B(N);
  for(int i = 0; i < N + 1; i++) cin >> A[i];
  for(int i = 0; i < N; i++) cin >> B[i];
  long ans = 0;
  long capa1, capa2;
  capa1 = B[0];
  if(A[0] <= capa1) {
    ans += A[0];
    capa1 -= A[0];
  } else {
    ans += capa1;
    capa1 = 0;
  }
  for(int i = 1; i <= N; i++) {
    capa2 = B[i];
    if(A[i] <= capa1) ans += A[i];
    else {
      ans += capa1;
      if((A[i] - capa1) <= capa2) {
        ans += A[i] - capa1;
        capa2 -= A[i] - capa1;
      } else { 
        ans += capa2;
        capa2 = 0;
      }
    }
    capa1 = capa2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    double W,H,x,y;
    bool ok=false;
    cin >> W >> H >> x >> y;
    double ans = W*H/2.0;
    
    if(W == x*2 && H == y*2) ok = true;
    cout << fixed << setprecision(10)<<ans << " ";
    if(ok) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int n,minj;

typedef struct card{
    char mark;
    int num;
}card;

card C[36], D[36], tmp;

void bubble_sort(card C[]){
    for(int i=0 ; i<n ; i++){
        for(int j=n-1 ; j>i ; j--){
            if(C[j].num<C[j-1].num){
                tmp = C[j], C[j] = C[j-1], 
                C[j-1] = tmp;
            }
        }
    }
}

void select_sort(card C[]){
    for(int i=0 ; i<n-1 ; i++){
        minj=i;
        for(int j=i ; j<n ; j++)
            if(C[j].num<C[minj].num) minj=j;
        tmp=C[i], C[i]=C[minj] , C[minj]=tmp;
    }
}

void print(card C[]){
    for(int i=0 ; i<n ; i++)
        if(i==n-1)    printf("%c%d\n",C[i].mark,C[i].num);
        else          printf("%c%d ", C[i].mark, C[i].num);
}

void stable_check(card C[], card D[]){
    for(int i=0 ; i<n ; i++){
        if(C[i].num!=D[i].num || C[i].mark!=D[i].mark){
            printf("Not stable\n");
            break;
        }
        if(i==n-1)
            printf("Stable\n");
    }
}

int main(void){
    
     scanf("%d",&n);
     for(int i=0 ; i<n ; i++){
        scanf(" %c%d",&C[i].mark, &C[i].num);
        D[i]=C[i];
     }
    
    bubble_sort(C);
    select_sort(D);

    print(C);
    printf("Stable\n"); //バブルソートは安定
    print(D);
    stable_check(C, D);

    return 0; 
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#include <string>
using namespace std;
int N,M;

int main(){
    cin >> N;
    int a[100];
    int b[100];
    int c[100];

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

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

        cin >> b[i];
    }
   for(int i=0;i<N-1;i++){
  
        cin >> c[i];
    }
    int ans=0;

   for(int i=0;i<N;i++){
        ans += b[a[i]-1];
        if(i!=0 && a[i]-a[i-1]==1) ans +=c[a[i-1]-1];
        // cout << i <<" "<<ans << endl;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++)cin>>s[i];
  int ACcnt=0,WAcnt=0,TLEcnt=0,REcnt=0;
  for(int i=0;i<n;i++){
    if(s[i]=="AC")ACcnt++;
    if(s[i]=="WA")WAcnt++;
    if(s[i]=="TLE")TLEcnt++;
    if(s[i]=="RE")REcnt++;
  }
  cout<<"AC x "<<ACcnt<<endl;
  cout<<"WA x "<<WAcnt<<endl;
  cout<<"TLE x "<<TLEcnt<<endl;
  cout<<"RE x "<<REcnt<<endl;
  return 0;
}

Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int N,M;
  cin >>N>>M;
  long long int c = N;
  N = max(M,N);
  M = min(c,M);
  if(N > 1 && M > 1){
    cout << (N-2)*(M-2) << endl;
    return 0;
  }
  else if(N == 1){
    cout << 1 << endl;
    return 0;
  }
  else if(M ==1){
    cout << N-2 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int gcd(int a, int b){
	int n = b/2;
	int result;
	if(a%b==0) return b;
	else{
		for(int i=1; i<=n; i++){
			int flag = (a%i==0) & (b%i==0);
			if(flag == 1) result = i; 	
		}
		return result;
	}
}

int main(int argc, char const *argv[]){
	// Input 2 natural numbers 
	int a,b;
	scanf("%d %d", &a, &b);
	if(a>=b) printf("%d\n", gcd(a,b));
	else	 printf("%d\n", gcd(b,a));
	return 0;
}


Measured memory_bytes: 2060
#include<iostream>
#include<cstdio>
#define INF 1<<30
#define FinishFunction return 0
#define MAX 1000000
using namespace std;
    
struct edge {
  int from,to,cost,k;
};
  
edge es[MAX];
  
int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);
  
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
     
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }
  
  // Ika berumanfo-do   
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    bool update = false;
    for(int i=0;i<E;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
    d[e.to] = d[e.from] + e.cost;
    update = true;
      }
    }
    if(!update)break;
  }
  for(int i=0;i<n;i++)cout << i << " " << d[i] << endl;
  FinishFunction;// return 0
}

Measured memory_bytes: 8644
n=int(input())
a=input()
b=input()
c=input()
d=0
for i in range(n):
	if a[i]!=b[i] and b[i]!=c[i] and a[i]!=c[i]:
		d+=2
	elif not a[i]==b[i]==c[i]:
		d+=1
print(d)

Measured memory_bytes: 3060
s = input()
remain_str = ''
count = 0
for i in s:
    if len(remain_str) == 0:
        remain_str += i
    elif (i == '0' and remain_str[-1] == '1') or (i == '1' and remain_str[-1] == '0'):
        count += 2
        remain_str = remain_str[:-1]
    else:
        remain_str += i
print(count)

Measured memory_bytes: 3400
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")
    };
}
fn main() {
    input!{
        n: usize,
        k: i32,
        q: i32,
        a: [usize; q],
    }
    let mut right = vec![k - q; n];
    for i in a {
        right[i - 1] += 1;
    }
    for i in right {
        println!("{}", if i > 0 { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 6780