akhauriyash/Code-Regression huggingface dataset:
class Dice
  attr_reader :top, :bottom, :front, :back, :left, :right #dice.top????????§???????????????????????????

  def initialize(dice_numbers) 
    @top = dice_numbers[0]
    @back = dice_numbers[1]
    @right = dice_numbers[2]
    @left = dice_numbers[3]
    @front = dice_numbers[4]
    @bottom = dice_numbers[5]
  end

  def roll_dice(order_top, order_back)
      while true
        order = []
        order << ['N', 'W'].sample
        execute_order(order)
      break if @top == order_top && @back == order_back
    end
  end

  private 
  def move_north
    tmp = @top
    @top = @back
    @back = @bottom
    @bottom = @front
    @front = tmp
  end

  def move_west
    tmp = @top
    @top = @right
    @right = @bottom
    @bottom = @left
    @left = tmp
  end

  def execute_order(orders) 
      orders.each do |order|
        if order == "N"
          move_north
        elsif order == "S" 
          3.times do
            move_north
          end
        elsif order == "W"
          move_west
        elsif order == "E" 
          3.times do
            move_west
          end
        else
          puts "error!" 
        end
      end
  end
end

dice_numbers = gets.chomp.split.map(&:to_i)
n = gets.chomp.to_i
answers = []
n.times do
  orders = gets.chomp.split.map(&:to_i)
  dice = Dice.new(dice_numbers)
  dice.roll_dice(orders[0], orders[1])
  answers << dice.right
end
answers.each do |answer|
  puts answer
end

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int bucket[26] = {0};
    string alpha = "abcdefghijklmnopqrstuvwxyz";

    for(int i = 0; i < S.length(); ++i){
        bucket[S[i] - 'a'] += 1;
    }

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

        if(bucket[i] == 0){
            cout << alpha[i] << endl;
            return 0;
        }
    }

    cout << "None" << endl;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define fread           freopen("input.txt","r",stdin)
#define fwrite          freopen("output.txt","w",stdout)
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define memo(ara,val)   memset(ara,val,sizeof(ara))
#define II              ( { int a ; read(a) ; a; } )
#define LL              ( { ll a ; read(a) ; a; } )
#define DD              ({double a; scanf("%lf", &a); a;})
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              printf("\n")
#define sc(x)           scanf("%lld",&x)
#define scw(x)          scanf("%I64d",&x)
#define sci(x)          scanf("%d",&x)
#define sc2(x,y)        scanf("%lld %lld",&x,&y)
#define sc3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define Found(a, b)     a.find(b) != a.end()
// bool operator< (const node& sx) const { return sx.val < val; }
//set<ll,greater<ll> >st;
//priority_queue<ll , vector<ll> , greater<ll> >
template<class T>inline bool read(T &x){ int c=getchar();int sgn=1;
  while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=getchar();}
  for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())x=x*10+c-'0';x*=sgn;return ~c;
}
const ll N = 100005;
const ll MOD = 1e9+7;
ll ara[N];
int main(){
    ll n = LL;
    rep1(i, n) ara[i] = LL;
    sort(ara + 1 , ara+n+1);
    n/=2;
    pf(ara[n+1]-ara[n]),ln;
}












Measured memory_bytes: 1024
using System;

namespace AtCoderABC052B
{
    class Program
    {
        static void Main()
        {
            String S = Console.ReadLine();
            int favorite_Num = 753;
            int saisyou = 1000;
            int num = 0;
            for(int i = 0; i < S.Length - 2; i ++){
                num = int.Parse(S.Substring(i,3));
                if( Math.Abs(favorite_Num - num) < saisyou ){
                    saisyou = Math.Abs(favorite_Num - num);
                }
            } 
            Console.WriteLine(saisyou);
        }
    }
}

Measured memory_bytes: 11220
n=int(input())

a={}
ans=0
for i in range(n):
    s=input()
    b=sorted(s)
    w=''.join(b)
    if not a.get(w):
        a[w]=1
    else:
        v=a[w]
        v +=1
        a[w]=v

for v in a.values():
    if v > 1:
        c=int((v*(v-1))/2)
        ans +=c
    
print(ans)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int cnt_4 = 0;
  int cnt_2 = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a % 4 == 0) {
      cnt_4++;
    } else if (a % 2 == 0) {
      cnt_2++;
    }
  }
  if (cnt_4 * 2 + 1 + max(cnt_2 - 1, 0) >= N) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a,b,sub=0,sum=0;
    scanf("%d%d",&a,&b);
    sub = abs(a) - abs(b);
    sum = abs (sub);

    if((a<b && a>0 && b>0)||(a<0 && b==0)||(a==0 && b>0)||(a<0 && b<0&& a<b)){
        printf("%d",sum);
    }  if((a<0 && b>0)||(a>0 && b<0)||(a==0 && b<0||(a>0 && b==0))){
        printf("%d",sum+1);
    }  if((a>b && a>0 && b>0)||(a<0 && b<0 && a>b)||(a==b&&a>0)){
        printf("%d",sum+2);
    }  if((a==0 &&b==0)||(a==b && a<0 && b<0)){
        printf("0");
    }
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define int long long
using namespace std;
signed main() {
	int N;
	cin >> N;
	int A = 0;

	vector<int>a(N);
	for (int i = 0; i < N; i++) {
		cin >> a.at(i);
	
	}
	for (int j = 0; j < N; j += 2) {
		if (a.at(j) % 2 == 1) {
			A++;
		}
	}
	cout << A << endl;

}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

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

const ll INF = 1e9;
/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n,w;
    cin >> n >> w;
    vector<ll> W(n),V(n);
    for (int i = 0;i < n;i++){
        cin >> W[i] >> V[i];
    }

    vector<vector<ll>> dp(n+1,vector<ll>(w+1));
    dp[0][0] = 0;

    for (int i = 0;i < n;i++){
        for (int j = 0;j <= w;j++){
            if (j - W[i] >= 0){
                dp[i+1][j] = max(dp[i][j],dp[i][j-W[i]] + V[i]);
            }
            else dp[i+1][j] = dp[i][j];
        }
    }
    
    cout << dp[n][w] << endl;
}

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

#define llint long long int

using namespace std;

llint L, R, memo[64][2][2][2];

llint calc_ans(int bit, int equal_R, int equal_L, int is_max_bit){
    int arg2, arg3, arg4;

    llint ans = 0;

    if(bit == -1){
        return 1;
    }
    if(memo[bit][equal_R][equal_L][is_max_bit] != -1){
        return memo[bit][equal_R][equal_L][is_max_bit];
    }
    if((R >> bit & 1) == 1 || equal_R == 0){
        arg2 = equal_R;

        if(equal_L == 1 && (L >> bit & 1) == 0){
            arg3 = 0;
        }else{
            arg3 = equal_L;
        }
        if(is_max_bit == 0){
            arg4 = 1;
        }else{
            arg4 = is_max_bit;
        }
        ans += calc_ans(bit - 1, arg2, arg3, arg4);
    }
    if(((R >> bit & 1) == 1 || equal_R == 0) && ((L >> bit & 1) == 0 || equal_L == 0) && is_max_bit == 1){
        arg2 = equal_R;
        arg3 = equal_L;
        arg4 = is_max_bit;

        ans += calc_ans(bit - 1, arg2, arg3, arg4);
    }
    if((L >> bit & 1) == 0 || equal_L == 0){
        if(equal_R == 1 && (R >> bit & 1) == 1){
            arg2 = 0;
        }else{
            arg2 = equal_R;
        }
        arg3 = equal_L;
        arg4 = is_max_bit;

        ans += calc_ans(bit - 1, arg2, arg3, arg4);
    }
    ans %= (llint) 1e9 + 7;
    memo[bit][equal_R][equal_L][is_max_bit] = ans;
    
    return ans;
}

int main(){
    cin >> L >> R;

    for(int i = 0; i < 64; i ++){
        for(int j = 0; j < 2; j ++){
            for(int k = 0; k < 2; k ++){
                for(int l = 0; l < 2; l ++){
                    memo[i][j][k][l] = -1;
                }
            }
        }
    }
    cout << calc_ans(63, 1, 1, 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int m,f,r;
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r == -1)break;
        int a = m+f;
        if(m==-1 || f == -1)cout << "F" << endl;
        else if( a>=80) cout << "A" << endl;
        else if(a >= 65) cout << "B" << endl;
    else if(a >= 50) cout << "C" << endl;
    else if(a >= 30){
      if(r >= 50) cout << "C" << endl;
      else cout << "D" << endl;
    } else cout << "F" << endl;
  }



    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 int n;
 cin>>n;
 vector<string> blue(n);

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

 int m;
 cin>>m;
 vector<string> red(m);

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

 int ans=0;

 for(int i=0;i<n;i++){
  int tmp=0;
   for(int j=0;j<n;j++){
    if(blue[i]==blue[j])tmp++;
   }

   for(int j=0;j<m;j++){
    if(blue[i]==red[j])tmp--;
   }
  ans=max({ans,tmp});
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string S;
    ll K;
    cin >> S >> K;

    REP(i, K) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
    }

    cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;
long long p[5];
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for(int i=0; i<N; ++i){
   string s;
   cin >> s;
   if(s[0] == 'M') ++p[0];
   if(s[0] == 'A') ++p[1];
   if(s[0] == 'R') ++p[2];
   if(s[0] == 'C') ++p[3];
   if(s[0] == 'H') ++p[4];
  }
  long long res = 0;
  for(int i=0; i<5; ++i)
    for(int j=i+1; j<5; ++j)
      for(int k=j+1; k<5; ++k)
        res += p[i]*p[j]*p[k];
  cout << res << "\n";
  return 0; 
}



Measured memory_bytes: 256
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int sum = 0;
    char curr = s[0];
    vector<pair<char, int>> arr;
    arr.emplace_back(s[0], 1);
    for (int i = 1; i < n; i++)
    {
        if (s[i] == arr.back().first)
        {
            arr[arr.size() - 1].second++;
        }
        else
        {
            arr.emplace_back(s[i], 1);
        }
    }
    for (auto i : arr)
    {
        sum += i.second - 1;
    }
    int N = arr.size();
    while (N > 1 and k > 0)
    {
        if (N == 2)
        {
            N--;
            k--;
            sum++;
        }
        else
        {
            N -= 2;
            k--;
            sum += 2;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 1480
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a,k) distance((v).begin(),(k)+upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a,k) distance((v).begin(),(k)+lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};

struct D21{
  int is,js;
  D21(int isize,int jsize){
    is = isize;
    js = jsize;
  }
  int operator()(int i,int j){
    return i*js+j;
  }
};


void Main(){
  int n;
  cin>>n;
  vi h(n);
  cin>>h;
  h.pb(0);
  h.pb(0);
  vi dp(n+2,INF);
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  rep(i,n){
    dp[i+2] = min(dp[i] + abs(h[i+2]-h[i]) , dp[i+1] + abs(h[i+2]-h[i+1]));
  }
  cout<<dp[n-1]<<endl;

} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 1024
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
int p[50],t[50];


void solve() {
    int dp[50][5];
    rep(i,50) rep(k,5) dp[i][k]=INF;

    if(t[0]<p[0]) {
        printf("NG 1\n");
        return;
    }

    dp[0][1]=p[0];
    rep(i,n-1)  rep(k,4)  {
        if(dp[i][k]==INF) continue;
        int time=t[i+1]-t[i];
        if(p[i+1]+p[i]*(k+1)<=time) dp[i+1][1]=min(dp[i+1][1],dp[i][k]+p[i]+p[i+1]);
        if(k<3&&(abs(p[i+1]-p[i])*(k+1)<=time)) dp[i+1][k+1]=min(dp[i+1][k+1],dp[i][k]+abs(p[i+1]-p[i]));
    }
    /*
    rep(i,n+1) {
        rep(k,5) cout<<dp[i][k]<<" ";
        cout<<endl;
    }
    */
    int ans=INF;
    rep(k,4) ans=min(ans,dp[n-1][k]);
    if(INF>ans) {
        printf("OK %d\n",ans+p[n-1]);
    }
    else {
        int idx=0;
        rep(i,n) {
            bool f=true;
            rep(k,4) f&=dp[i][k]==INF;
            if(f) {
                idx=i;
                break;
            }
        }
        printf("NG %d\n",idx+1);
    }

}

int main() {
    while(cin>>n) {
        if(!n) break;
        rep(i,n) cin>>p[i]>>t[i];
        solve();
    }
    return 0;
}

Measured memory_bytes: 1148
mondai = int(raw_input())
time_array = raw_input().split(" ")
drink_num = int(raw_input())

for i in range(drink_num):
    d = raw_input().split(" ")
    m_i = int(d[0]) - 1
    d_time = int(d[1])

    s = 0
    for j in range(len(time_array)):
        if j == m_i:
            s += (d_time)
        else:
            s += int(time_array[j])
    print s


Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void) {
	int n, i, ft, pt, fx, px, fy, py;

	ft = fx = fy = 0;

	cin >> n;
	for (i - 0; i < n; i++) {
		cin >> pt >> px >> py;
		if (abs(px - fx) + abs(py - fy) > pt - ft || abs(px + py - fx - fy) % 2 != (pt - ft) % 2) {
			cout << "No" << endl;
			return 0;
		}
		ft = pt;
		fx = px;
		fy = py;
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double n = sc.nextDouble();
        double M = sc.nextDouble();
        double[] a = new double[(int)n];
        double cnt = 0;
        double sum = 0;
        for(int i = 0; i<n; i++) {
            a[i] = sc.nextDouble();
            sum += a[i];
        }
        System.err.println(sum);
        for(int i = 0; i<n; i++) {
            System.err.println(a[i]/sum);
            if(a[i]/sum >= 1/(4*M)) cnt++;
        }
        if(cnt>= M) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23252
#include<stdio.h>
int main(){
	int n,k,a=1;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		if(a<k)
			a*=2;
		else
			a+=k;
		}
	printf("%d",a);
	return 0;
	}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int a[110][110] = {0};
int h, w, n, num = 1;
int color[10010];
//bool mark[110][110] = {0};
int go[][2] = {
    1,0,
    -1,0,
    0,1,
    0,-1
};
int what_color(int num)
{
    int i = 1;
    while(num - color[i] > 0)
    {
        num -= color[i];
        i++;
    }
    return i;
}
void dfs(int x, int y)
{
    if(num == h*w)
        return;
    for(int i = 0; i < 4; i++)
    {
        int nx = x + go[i][0];
        int ny = y + go[i][1];
        if(nx < 1 || nx > h || ny < 1 || ny > w)
            continue;
        if(a[nx][ny] != 0)
            continue;
        a[nx][ny] = what_color(num);
        num++;
        dfs(nx, ny);
        if(num == h*w)
            return;
        num--;
        a[nx][ny] = 0;
    }
}
int main()
{
    cin >> h >> w >> n;
    for(int i = 1; i <= n; i++)
        cin >> color[i];
    a[1][1] = 1;
    color[1]--;
    dfs(1,1);
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            if(j != 1)
                cout << ' ';
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

int main () {
  string S;
  cin >> S;
  
  int ans = 0;
  int count = 0;
  rep(i, 3) {
    if (S[i] == 'R') {
      count++;
      if (i == 2) {
        ans = count;
      }
    } else {
      if (ans < count) ans = count;
      count = 0;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
string abc;
int main()
{
    cin>>abc;
    int ans=0;
    int tmp=0;
    for(int i=0;i<abc.size();i++)
    {
        if(abc[i]=='A'||abc[i]=='T'||abc[i]=='C'||abc[i]=='G')
        {
            tmp++;
            ans=max(tmp,ans);
        }
        else
            tmp=0;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a, a+3);
    cout<<a[2]*10+a[1]+a[0]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool issame (deque<char> train, char c )
{
	deque<char>::iterator it = train.begin();
	for (; it != train.end(); ++it){
		if ((*it) == c ){
			return true;
		} // end if
	} // end for

	return false;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.train", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		if (n == 0 ){
			break;
		} // end if
		int i,j;
	
		for (i = 0; i < n; ++i){

			deque<char> train;

			getline (cin, str );

			int len = str.length();
			str += 'E';
			train.push_back(str[0]);
			
			for (j = 1; j < len - 1; ++j){
				if (str[j] != '<' && str[j] != '>' && str[j] == 'E'){
					continue;
				} // end if
				if (str[j] == '>'){
					if (!issame(train, str[j+1] ) ) {
						train.push_back(str[j+1]);
					} // end if
				}else if (str[j] == '<'){
					if (!issame(train, str[j+2] ) ) {
						train.push_front(str[j+2]);
					} // end if
				} // end if
			} // end for

			// train output
			deque<char>::iterator it = train.begin();
			for (; it != train.end(); ++it){
				cout << (*it);
			} // end for
			cout << endl;
			train.clear();
		} // end for

	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

const int mod=1000000007;
//const int mod=998244353;




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d;
    cin>> n>> m;
    b=0;
    for(int i=0; i<m ; i++){
        cin>>a;
        b+=a;
    }
    cout<< (b>n?-1:n-b)<<'\n';
    return 0;
}


Measured memory_bytes: 3612
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x))
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 1e5 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
int n, arr[N], gcd, x;
int main()
{
    MuhammedAly
    cin >> n >> x;
    for(int i = 0 ; i < n ; i++)
        cin >> arr[i];
    arr[n] = x;
    sort(arr, arr + n + 1);
    for(int i = 1 ; i <= n ; i++)
        gcd = __gcd(arr[i] - arr[i - 1], gcd);
    cout << gcd;
    return 0;
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}



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

  ll ans = (1900 * m + 100 * (n - m)) * (ll)pow(2, m);
  cout << ans << endl;
  return 0;
}


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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int n;
int x[10], y[10];
int order[10];

double calcDistance(int x1, int y1, int x2, int y2) {
	return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x[i], &y[i]);
		order[i] = i;
	}

	double sum = 0, cnt = 0;
	do {
		for (int i = 0; i < n-1; i++) {
			int a = order[i], b = order[i+1];
			sum += calcDistance(x[a], y[a], x[b], y[b]);
		}
		cnt++;
	}
	while (next_permutation(order, order+n));

	double avg = sum/(double)cnt;
	printf("%.9lf\n", avg);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int64_t n, m;
    cin >> n >> m;

    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    vector<int64_t> asum(n + 1);
    asum[n] = 0;
    rrep(i, n)
    {
        asum[i] = asum[i + 1] + a[i];
    }

    int lb = 0, ub = 2 * a[n - 1] + 1;
    int64_t lbM = (int64_t)n * n;
    int64_t lbScore = asum[0] * 2 * n;

    while (ub - lb > 1)
    {
        int mid = (lb + ub) / 2;
        int64_t cnt = 0;
        int64_t score = 0;
        rep(i, n)
        {
            int j = lower_bound(a.begin(), a.end(), mid - a[i]) - a.begin();
            cnt += n - j;
            score += asum[j] + (int64_t)(n - j) * a[i];
        }

        if (cnt >= m)
        {
            lb = mid;
            lbM = cnt;
            lbScore = score;
        }
        else
        {
            ub = mid;
        }
    }

    //cerr << lb << " " << lbM << " " << lbScore << endl;
    int64_t p = lbM - m;
    if (p < 0)
    {
        throw runtime_error("");
    }
    int64_t result = lbScore - p * lb;
    cout << lbScore - (lbM - m) * lb << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n, a, b;
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    cin >> n >> a >> b;
    ll ans = (a) * (n / (a + b));
    n %= (a + b);
    ans += min(n, a);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

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

        Arrays.sort(a);
        int m = a[n-1];
        int l = 0;
        int max = 0;
        int k = 0;

        for(int i=0; i<n-1; i++) {
            if(a[i]*2 < m) {
                l = a[i];
            } else {
                l = m - a[i];
            }
            if(max < l) {
                max = l;
                k = a[i];
            }
        }

        System.out.println(m + " " + k);
    }

}


Measured memory_bytes: 52964
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

a,b,c,d = na()
if a+b == c+d:
    print("Balanced")
elif a+b > c+d:
    print("Left")
else:
    print("Right")


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
string s,t;
int c[26],d[26];
main()
{
	cin>>s>>t;
	for(int i=0;i<26;i++)c[i]=d[i]=-1;
	for(int i=0;i<s.size();i++)
	{
		int j=s[i]-'a',k=t[i]-'a';
		if(c[j]==-1)
		{
			c[j]=k;
		}
		if(d[k]==-1)
		{
			d[k]=j;
		}
		if(c[j]!=k||d[k]!=j)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

map<int,int> mp;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
        mp[vec[i]]++;
    }
    vector<int> v;
    each(it,mp){
        if(it.se >= 2){
            v.pb(it.fi);
        }
        if(it.se >= 4){
            v.pb(it.fi);
        }
    }
    sort(all(v),greater<int>());
    if(v.size() <= 1){
        cout << "0\n";
    }else{
        cout << (ll)v[0]*v[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <queue>
using namespace std;
 
#define int long long
#define INF 1001001001
int ans[2200];
int dis[2200][2200];
vector<int> v[2200];
 
void bfs(int start){
	
    queue<int> q;
    dis[start][start] = 1;
    
    q.push(start);
    
    while(!q.empty()){
    	
    	int u = q.front();
		
		q.pop();
		
		for(int tmp : v[u]){
			
			if(dis[tmp][start]==0){
                dis[tmp][start]=dis[u][start]+1;
                q.push(tmp);
        	}
			
		}	
    	
	}
	
}
 
 
int32_t main() {
	
    int N,X,Y;
  
    cin >> N >> X >> Y;
	
	X--;Y--;
	
	
	for(int i=0; i<N-1;i++){
		
		v[i].push_back(i+1);
		v[i+1].push_back(i);
		
	}
	
	v[X].push_back(Y);
	v[Y].push_back(X);
	for(int i=0;i<N;i++)
        bfs(i);
    for(int i=0;i<N;i++)
        for(int j=i+1;j<N;j++)
            ++ans[dis[i][j]-1];
    for(int i=1;i<N;i++)
        cout<<ans[i]<<"\n";
}

Measured memory_bytes: 37668
#include <stdio.h>

int main()
{
	int i;
	char S[11], T[12];
	scanf("%s", S);
	scanf("%s", T);
	for (i = 0; S[i] != 0; i++) if (S[i] != T[i]) break;
	if (S[i] == 0) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1636
#include <cstdio>

#define FOR( i, k, n ) for ( int i = ( k ); i < ( int )( n ); ++i )
#define REP( i, n ) FOR( i, 0, n )

#define MAX_N 20

bool dfs( int, int );

int n;
int A[ MAX_N ];

int main() {
	scanf( "%d", &n );
	REP( i, n ) scanf( "%d", &A[ i ] );
	int q;  scanf( "%d", &q );
	REP( i, q ) {
		int M;
		scanf( "%d", &M );
		if( dfs( 0, M ) ) printf( "yes\n" );
		else printf( "no\n" );
	}
	return 0;
}

// i番目以降でnumが作れるか
bool dfs( int i, int num ) {
	if( num == 0 ) return true;
	else if( num < 0 ) return false;
	if( i == n - 1 ) return A[ i ] == num;
	if( A[ i ] > num ) return dfs( i + 1, num );
	if( dfs( i + 1, num ) || dfs( i + 1, num - A[ i ] ) ) return true;
	return false;
}

Measured memory_bytes: 1008
#include <iostream>
using namespace std;
int main() {
	int a, b, k[100005], mon;
	cin >> a >> b;
	bool canunrap = false;
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
		if (i != 0 && k[i] + k[i - 1] >= b) {
			canunrap = true;
			mon = i-1;
		}
	}
	if (!canunrap) {
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	for (int i = 1; i <= mon; ++i) {
		cout << i << endl;
	}
	for (int i = a-1; i > mon; --i) {
		cout << i << endl;
	}
}

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

int main() {
  int n, d, s = 0, x;
  cin >> n >> d;
  vector<vector<int>> v(n, vector<int>(d));
  for(int i = 0;i < n;i++) for(int j = 0;j < d;j++) cin >> v[i][j];
  for(int i = 0;i < n;i++) {
    for(int j = i + 1;j < n;j++) {
      x = 0;
      for(int k = 0;k < d;k++) x += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
      if(x == (int)(sqrt(x))*sqrt(x)) s++;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int N, M; cin >> N >> M;
	int A[3][55] = {};
	fill(A[0], A[3], M);
	rep(i, 0, N)rep(j, 0, M) {
		char c; cin >> c;
		if (c == 'W')A[0][i]--;
		if (c == 'B')A[1][i]--;
		if (c == 'R')A[2][i]--;
	}
	rep(i, 0, N)rep(h, 0, 3)A[h][i + 1] += A[h][i];
	int ans = INF;
	rep(a, 0, N - 2)rep(b, a + 1, N - 1) {
		int temp = 0;
		temp += A[0][a];
		temp += A[1][b] - A[1][a];
		temp += A[2][N - 1] - A[2][b];
		ans = min(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3052
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>
#include <set>

class disjoint_set {
public:
  using size_type = size_t;

private:
  mutable std::vector<intmax_t> M_c;

public:
  disjoint_set() = default;
  disjoint_set(disjoint_set const&) = default;
  disjoint_set(disjoint_set&&) = default;

  disjoint_set(size_t n): M_c(n, -1) {}

  disjoint_set& operator =(disjoint_set const&) = default;
  disjoint_set& operator =(disjoint_set&&) = default;

  void reset() { M_c.assign(M_c.size(), -1); }

  size_type representative(size_type v) const {
    if (M_c[v] < 0) return v;
    return (M_c[v] = representative(M_c[v]));
  }

  bool unite(size_t u, size_t v) {
    u = representative(u);
    v = representative(v);
    if (u == v) return false;
    if (-M_c[u] > -M_c[v]) std::swap(u, v);
    M_c[v] += M_c[u];
    M_c[u] = v;
    return true;
  }

  bool equivalent(size_t u, size_t v) const {
    return (representative(u) == representative(v));
  }

  size_type size() const noexcept { return M_c.size(); }
  size_type size(size_type v) const {
    return -M_c[representative(v)];
  }
};

int main() {
  size_t n, m, q;
  scanf("%zu %zu %zu", &n, &m, &q);

  std::set<size_t> appears;

  std::vector<std::pair<size_t, size_t>> zeros, ones;
  for (size_t i = 0; i < q; ++i) {
    size_t a, b, c;
    scanf("%zu %zu %zu", &a, &b, &c);
    ((c == 0)? zeros: ones).emplace_back(a, b);
    appears.insert(a);
    appears.insert(b);
  }

  std::set<size_t> unappears;
  for (size_t i = 0; i < n; ++i)
    if (appears.count(i) == 0) unappears.insert(i);

  disjoint_set ds(n);
  for (auto const& p: zeros) {
    size_t u, v;
    std::tie(u, v) = p;
    ds.unite(u, v);
  }

  std::set<std::pair<size_t, size_t>> er;
  for (auto const& p: ones) {
    size_t u, v;
    std::tie(u, v) = p;
    if (ds.equivalent(u, v)) return puts("No"), 0;
    er.insert(std::minmax(ds.representative(u), ds.representative(v)));
  }

  std::set<size_t> reps;
  for (auto x: appears) reps.insert(ds.representative(x));

  size_t m_lb = n-1;
  size_t m_ub = n*(n-1) / 2;
  if (reps.size() == 1) {
    assert(ones.empty());
    m_lb = n-1;
    m_ub = ds.size(*reps.begin())-1;
    if (!unappears.empty()) {
      ++m_ub;
      m_ub += unappears.size() * (unappears.size()-1) / 2;
    }
  } else if (reps.size() == 2) {
    size_t s0 = ds.size(*reps.begin());
    size_t s1 = ds.size(*++reps.begin());
    if (!ones.empty()) {
      m_lb = s0 + s1 + 1;
      if (m_lb > n) return puts("No"), 0;
    }
    m_ub = s0 + s1 - 1;
    size_t nr = n - (s0+s1);
    m_ub += nr*(nr-1) / 2 + 2*nr;
  } else {
    size_t nr = n;
    for (auto x: reps) nr -= ds.size(x);
    if (!ones.empty()) {
      m_lb = reps.size();
      for (auto x: reps) m_lb += ds.size(x) - 1;
    }
    m_ub = 0;
    for (auto x: reps) m_ub += ds.size(x) - 1;
    nr += reps.size();
    m_ub += nr*(nr-1) / 2;
  }

  if (!(m_lb <= m && m <= m_ub)) return puts("No"), 0;
  puts("Yes");
}


Measured memory_bytes: 18160
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pr=pair<ll,ll>;
int main(){
  ll N,M;
  cin>>N>>M;
  vector<vector<int>>Data(100010);
  for(int i=0;i<N;i++){
    int A,B;
    cin>>A>>B;
    Data[A].push_back(B);
  }
  priority_queue<int>que;
  int ans=0;
   for(int i=1;i<=M;i++){
    for(auto a:Data[i]){
      que.push(a);
    }
    if(!que.empty()){
    ans+=que.top();
    que.pop();
    }
    //cnt--;
    //if(cnt==-1)break;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 8292
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[][] p = new int[10][10]; //x,y
		while(stdIn.hasNext()) {
			String tmp = stdIn.nextLine();
			String[] k = tmp.split(",");
			int x = Integer.parseInt(k[0]);
			int y = Integer.parseInt(k[1]);
			int size = Integer.parseInt(k[2]);
			
			if(size >= 1) {
				if(check(x,y)) {
					p[x][y]++;
				}
				if(check(x+1,y)) {
					p[x+1][y]++;
				}
				if(check(x-1,y)) {
					p[x-1][y]++;
				}
				if(check(x,y+1)) {
					p[x][y+1]++;
				}
				if(check(x,y-1)) {
					p[x][y-1]++;
				}
			}
			if(size >= 2) {
				if(check(x+1,y+1)) {
					p[x+1][y+1]++;
				}
				if(check(x-1,y-1)) {
					p[x-1][y-1]++;
				}
				if(check(x+1,y-1)) {
					p[x+1][y-1]++;
				}
				if(check(x-1,y+1)) {
					p[x-1][y+1]++;
				}
			}
			if(size >= 3) {
				if(check(x+2,y)) {
					p[x+2][y]++;
				}
				if(check(x-2,y)) {
					p[x-2][y]++;
				}
				if(check(x,y+2)) {
					p[x][y+2]++;
				}
				if(check(x,y-2)) {
					p[x][y-2]++;
				}
			}
		}
		int whiteCounter = 0;
		int max = 0;
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				if(p[i][j] > max) {
					max = p[i][j];
				}
				if(p[i][j] == 0) {
					whiteCounter++;
				}
			}
		}
		System.out.println(whiteCounter+"\n"+max);
	}
	static boolean check(int x, int y) {
		if(x < 0 || x > 9 || y < 0 || y > 9) {
			return false;
		}
		return true;
	}
}

Measured memory_bytes: 17192
// This  Program is made by Jan(Codezebra)
#include<bits/stdc++.h>
//#define int long long
//#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
signed main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	int n;
	cin>>n;
	int ans=0;
	int m=0;
	for(int i=0;i<n;i++){
		int h;
		cin>>h;
		if(h>=m){
			ans++;
			m=h;
		}
	}
	cout<<ans;
	return 0;
}



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


int main(){

  int l;
  while(1){
    cin >> l;
    if(l == 0)break;
    int sum=0;
    bool f = true;
    for(int i=0;i<12;i++){
      int m,n;
      cin >> m >> n;
      sum += (m-n);
      if(l <= sum && f){
	cout << i+1 << "\n";
	f = false;
      }
    }
    if(l>sum)
      cout << "NA\n";
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>> g(100000);
//map<pair<int,int>,int> W;
bool seen[100000];
int color[100000];
int N;

void dfs(int n, int c){
  //cout << n << endl;
  seen[n] = true;
  color[n] = c;
  int cc;
  if(c==0)cc=1;
  else cc=0;
  int w;
  for(auto to : g.at(n)){
    if(seen[to.first]){}
    else{
      w = to.second;
      if(w%2==0)dfs(to.first,c);
      else dfs(to.first,cc);
    }
  }
  return ;
}
int main(){
  cin >> N;
  //memset(g, -1, sizeof(g));
  memset(seen, false, sizeof(seen));
  int u,v,w;
  for(int i=0; i<N; i++){
    cin >> u >> v >> w;
    g.at(u-1).push_back(make_pair(v-1,w));
    g.at(v-1).push_back(make_pair(u-1,w));
    //W[make_pair(u-1,v-1)] = w;
  }
  dfs(0,0);
  for(int i=0; i<N; i++){
    cout << color[i] << endl;
  }
}

Measured memory_bytes: 8448
#include <stdio.h>

void bubbleSort(int num[],int n){
    int flag=1,j,tmp,count=0;
    while(flag){
        flag=0;
        for(j=n-1;j>0;j--){
            if(num[j]<num[j-1]){
                tmp=num[j];
                num[j]=num[j-1];
                num[j-1]=tmp;
                count++;
                flag=1;
            }
        }
    }
    for(j=0;j<n;j++){
        printf("%d%s",num[j],(j==n-1?"\n":" "));
    }
    printf("%d\n",count);
} 

int main(void){
    int num[101];
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&num[i]);
    }
    bubbleSort(num,n);
    return 0;
}



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

#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()

#define INF 1000000000

using namespace std;

int main() {
    string s;
    cin >> s;

    string ss = s;
    reverse(ALL(ss));

    int N = s.size();

    string a = "", b = "";

    for (int i = 0; i < N; ++i) {
        if (i < (N - 1) / 2)
            a += s[i];
        else if (i == (N - 1) / 2)
            continue;
        else
            b += s[i];
    }

    string aa = a, bb = b;
    reverse(ALL(aa));
    reverse(ALL(bb));

    if (aa == a && bb == b && ss == s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
//  Author: Tanuj Johal
//  It's a show time, Enjoy your everyday.

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         1e18
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}
#define run_time cout << "\nTIME = " << clock() - tt << endl; tt = clock();

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;
ll tt;
const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 1e5+10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;


void solve(){

    ll n;cin>>n;
    ll a[n+1];
    ll ans=0;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        if(i&1 and a[i]&1)
            ans ++;
    }
    cout << ans;

}

int main()
{
 #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
 #endif
    fio
    int t=1;
    if(imp) cin>>t;
    tt = clock();
    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }
//    run_time;

}


Measured memory_bytes: 3640