akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


class WeightedUnionFind:
    def __init__(self, nodes):
        """
        :param collections.Iterable nodes:
        """
        self._parents = {k: k for k in nodes}
        self._ranks = {k: 0 for k in nodes}
        self._sizes = {k: 1 for k in nodes}
        # 直近の親からの重み。root なら 0
        self._weights = {k: 0 for k in nodes}

    def unite(self, x, y, w):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        :param w: x と y の重みの差; (重み y) - (重み x)
        :return:
        """
        # それぞれの root をくっつけたいので root 間の重みに変換
        # x が上、y が下
        w += self.weight(x)
        w -= self.weight(y)

        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
            self._weights[x] = 0
            self._weights[y] = w
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            self._weights[x] = -w
            self._weights[y] = 0
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def find(self, x):
        """
        x が属する木の root
        :param x:
        :return:
        """
        if self._parents[x] == x:
            return x
        root = self.find(self._parents[x])
        self._weights[x] += self._weights[self._parents[x]]
        self._parents[x] = root
        return root

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        :return:
        """
        return self._sizes[self.find(x)]

    def weight(self, x):
        """
        :param x:
        :return:
        """
        # 経路圧縮
        self.find(x)
        return self._weights[x]

    def diff(self, x, y):
        """
        (y の重み) - (x の重み)
        :param x:
        :param y:
        :return:
        """
        if self.find(x) == self.find(y):
            return self.weight(y) - self.weight(x)
        return float('inf')


N, M = list(map(int, input().split()))
P = list(map(int, input().split()))

uf = WeightedUnionFind(range(N + 1))
for _ in range(M):
    x, y = list(map(int, input().split()))
    uf.unite(x, y, 0)

ans = 0
for i in range(N):
    if uf.find(P[i]) == uf.find(i + 1):
        ans += 1

print(ans)


Measured memory_bytes: 50524
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;



int main() {
	int n, k;
	cin >> n >> k;
	VI l(n);
	rep(i, 0, n) scanf("%d", &l[i]);
	sort(ALL(l), greater<int>());

	cout << accumulate(l.begin(), l.begin()+k, 0) << "\n";
}


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

using namespace std;

long long n, a, b;

int main() {

cin >> n >> a >> b;
if (a != b && n == 1) cout << 0;
else if (a <= b) cout << n * b - b + a - (n * a - a + b) + 1;
else cout << 0;


return 0;

}


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

using namespace std;

//skip
void C111()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
}


void pyramid()
{
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  int x1, y1, h1;
  for (int i = 0; i < n; ++i)
  {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] >= 1)
    {
      x1 = x[i];
      y1 = y[i];
      h1 = h[i];
    }
  }

  for (int i = 0; i <= 100; ++i)
  {
    for (int j = 0; j <= 100; ++j)
    {
      int h_max = max(0, h1 + abs(i - x1) + abs(j - y1));
      int exist_ans = 1;
      for (int k = 0; k < n; ++k)
      {
        if (h[k] != max(0, h_max - abs(i - x[k]) - abs(j - y[k])))
        {
          exist_ans = 0;
          break;
        }
      }
      if (exist_ans)
      {
        cout << i << " " << j << " " << h_max << "\n";
        return;
      }
    }
  }
}

int main()
{
  //C111();
  pyramid();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  string s,t;cin>>s>>t;
  vector<int> v[26];

  REP(i,s.size()){
    int r = s[i] - 'a';
    v[r].pb(i);
  }
  REP(i,26){
    VSORT(v[i]);
  }

  int count = -1;
  ll ans = -1;

  REP(i,t.size()){
    int r = t[i] - 'a';
    if(v[r].size() < 1){
      cout<<-1<<endl;
      return 0;
    }
    auto Iter = upper_bound(v[r].begin(),v[r].end(),count);
    if(Iter == v[r].end()){
      ans += v[r][0] + s.size() - count;
      count = v[r][0];
    }else{
      ans += *Iter - count;
      count = *Iter;
    }
    //cout<<ans<<endl;
  }

  cout<<ans+1<<endl;
 

  return 0;
}

Measured memory_bytes: 1216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aizu
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var fib = new int[n + 1];

            for (var i = 0; i <= n; i++)
            {
                if(i == 0 || i == 1)
                {
                    fib[i] = 1;
                }
                else
                {
                    fib[i] = fib[i - 1] + fib[i - 2];
                }
            }

            Console.WriteLine(fib[n]);
        }
    }
}



Measured memory_bytes: 17728
//Dragon_warrior7(IITK)
#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 pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
	//	cin>>
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,t,temp,x,y;
string str;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b;
	if(a%2==1 && b%2==1)
	{
	    cout<<"Yes";
	}
	else
	cout<<"No";
	
	
	
	
	
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  int n, m;
  int h[100100];
  cin >> n >> m;
  vector<pair<int, int>> vp;
  for (int i = 1; i <= n; i++)
  {
    cin >> h[i];
    // int h;
    // cin >> h;
    // vp.push_back(make_pair(h, i));
  }
  map<int, vector<int>> mp;
  for (int i = 0; i <= n; i++)
    mp[i] = vector<int>();

  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    mp[a].push_back(b);
    mp[b].push_back(a);
  }
  priority_queue<int, vector<int>, greater<int>> pq;
  int cnt = 0;
  for (int i = 1; i <= n; i++)
  {
    if (pq.size() != 0 && pq.top() == i)
    {
      pq.pop();
      continue;
    }
    if (mp[i].size() == 0)
    {
      // cout << "::" << i << endl;
      cnt++;
    }
    else
    {
      bool f = true;
      for (int j = 0; j < mp[i].size(); j++)
      {
        if (h[i] > h[mp[i][j]])
        {
          // cout << "mp[i][j]" << mp[i][j] << endl;
          pq.push(mp[i][j]);
        }
        else if (h[i] == h[mp[i][j]])
        {
          pq.push(mp[i][j]);
          f = false;
        }
        else
        {
          f = false;
        }
      }
      if (f)
      {
        // cout << "::" << i << endl;
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 16412
from collections import deque
while True:
    try:
        n,m = map(int,raw_input().split())
        if (n,m) == (0,0) :
            break
    except EOFError:
        break
        
    d = deque([i for i in range(1,1+n)])
    while len(d)> 1:
        d.rotate(-m+1)
        d.popleft()
    print d[0]

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


def solve(X: int, K: int, D: int):
    X=abs(X)

    mostl = X - K * D
    if mostl > 0:
        print(mostl)
        exit()

    if K%2 == 1:
        X -= D
        ans = min(abs(X), abs(X+2*D))
    else:
        ans = min(X, abs(X - K * D))

    Kh = K // 2

    N = X // (D*2)
    ans = min(ans, abs(X - D * 2 * (N - 1)))
    ans = min(ans, abs(X - D * 2 * N))
    if N < Kh:
        ans = min(ans, abs(X - D * 2 * (N + 1)))

    print(ans)

    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Input().Select(t=>long.Parse(t)).ToArray();
		var na = new long[n];
		
		Array.Sort(a);
		Array.Reverse(a);
		long wa = 0;
		
		
		var list = new LinkedList<long>();
		
		
			int j = 0;
			bool turn = false;
			LinkedListNode<long> ptr = null;
			
			for(int i = 0; i < n; i++)
			{
				LinkedListNode<long> t = null;
				if(j < n && !turn)
				{
					if(list.Count == 0)
					{
						list.AddFirst(a[i]);
						t = list.First;
						ptr = t;
					}
					else
					{
						t = list.AddAfter(ptr, a[i]);
						ptr = t;
					}
					j+=2;
				}
				else
				{
					if(!turn)
					{
						turn = true;
						j -= 1;
						if(n%2==1) j-=2;
						list.AddBefore(list.Last, new LinkedListNode<long>(a[i]));
						t = list.Last.Previous;
						ptr = t;
					}
					else
					{
						
						list.AddBefore(ptr.Previous, new LinkedListNode<long>(a[i]));
						ptr = ptr.Previous.Previous;
						t = ptr;
					}
				}
				if(list.Count > 1)
				{
					if(t == list.First)
					{
						wa += Math.Min(t.Next.Value, list.Last.Value);
					}
					else
					
						wa += Math.Min(t.Previous.Value, t.Next == null ? list.First.Value : t.Next.Value);
				}
				//Console.WriteLine(string.Join(",", list.Select(o=>o).ToArray() ));
				
			}
		/*
		if(n%2==0)
		{
			int j = 0;
			bool turn = false;
			for(int i = 0; i < n; i++)
			{
				if(j < n && !turn)
				{
					na[j] = a[i];
					j+=2;
				}
				else
				{
					if(!turn)
					{
						turn = true;
						j--;
					}
					na[j] = a[i];
					j-=2;
				}
			}
		}
		else
		{
		int j = 0;
			bool turn = false;
			for(int i = 0; i < n; i++)
			{
				if(j < n && !turn)
				{
					na[j] = a[i];
					j+=2;
				}
				else
				{
					if(!turn)
					{
						turn = true;
						j-=3;
					}
					na[j] = a[i];
					j-=2;
				}
			}
		}
		
		
		
		*/
/*
		for(int i = 1; i < n; i++)
		{
			wa += NearMax(i, na);
		}
		*/
		//Console.WriteLine(string.Join(",", list.Select(o=>o).ToArray() ));
		
		Console.WriteLine(wa);
	}
	
	static long NearMax(int k, long[] m)
	{
		return (long)Math.Max(m[(k+1)%m.Length], m[(k+(m.Length-1))%m.Length]);
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> grid(h);
  rep(i, h) cin >> grid[i];
  int sum = 0;
  int ans = 0;
  rep(i,h){
    rep(j, w){
      if(grid[i][j] == '#')sum++;
    }
  }
  if(sum < k){
    cout << 0 << endl;
    return 0;
  }
  for (int bit1 = 0; bit1 < (1 << h); bit1++){
    for (int bit2 = 0; bit2 < (1 << w); bit2++){
      vector<string> tmp_grid(h);
      tmp_grid = grid;
      int tmp = sum;
      rep(i, h){
        if(bit1 & (1 << i)){
          rep(d, w){
            if(tmp_grid[i][d] == '#'){
              tmp_grid[i][d] = '.';
              tmp--;
            }
          }
        }
      }
      rep(j, w){
        if(bit2 & (1 << j)){
          rep(d, h){
            if(tmp_grid[d][j] == '#'){
              tmp_grid[d][j] = '.';
              tmp--;
            }
          }
        }
      }
      if(tmp == k){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main(void){
    int n;
    long long ans = 0;
    std::cin >> n;
    std::vector<int> l(n);
    for(int i = 0; i < n; i++){
        std::cin >> l[i];
    }

    std::sort(l.begin(), l.end());

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int v = l[i] + l[j];
            auto cs = l.begin() + j + 1;
            auto it = std::lower_bound(cs, l.end(), v);
            ans += it - cs;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3608
S = input()
n = len(S)
N = []
M = []
for i in range(n):
    N.append(S[i])
Nsum = 0
a = 0
for Ni in N:
    n = len(S) - a
    m = 2 ** a
    Nsum += m * int(Ni) * 10 ** (n - 1)
    n -= 1
    while n > 0:
        Nsum += m * int(Ni) * 10 ** (n - 1)
        m *= 2
        n -= 1
    a += 1
print(Nsum)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            long iA = long.Parse(sS[0]);
            long iB = long.Parse(sS[1]);
            long iC = long.Parse(sS[2]);
            long iD = long.Parse(sS[3]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            long iC1 = (iA / iC) + (iA % iC == 0 ? 0 : 1);
            long iC2 = (iB / iC);
            long iCA = iC2 - iC1 + 1;
            long iD1 = (iA / iD) + (iA % iD == 0 ? 0 : 1);
            long iD2 = (iB / iD);
            long iDA = iD2 - iD1 + 1;
            long iE = Lcm(iC, iD);                              // CとDの最小公倍数
            long iE1 = (iA / iE) + (iA % iE == 0 ? 0 : 1);
            long iE2 = (iB / iE);
            long iEA = iE2 - iE1 + 1;
            long iOt = (iB - iA + 1) - (iCA + iDA - iEA);

            // 出力
            System.Console.WriteLine("{0}", iOt.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 最小公倍数取得
        private static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // 最大公約数取得
        private static long Gcd(long a, long b)
        {
            if (a < b) { return Gcd(b, a); }
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
int main(void)
{
    int n,r;
    cin>>n>>r;

    if(n>=10) cout<<r<<endl;

    else{
        cout<<r+(100*(10-n))<<endl;
    }



    return 0;
}
 

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

inline void Yes(){
    cout << "Yes" << "\n";
}
inline void No(){
    cout << "No" << "\n";
}
typedef pair<int,int> P;
double kitaichi(int a){
    double ret = 0;
    for (int i = 1; i <= a; i++){
        ret += (double)i/a;
    }
    return ret;
}
int main(){
    int n,k;
    cin >> n >> k;
    vector<int>v(n);
    for (int i = 0; i < n; i++){
        cin >> v.at(i);
    }
    vector<int>ruisekiwa(n+10);
    ruisekiwa.at(0) = 0;
    for (int i = 0; i < n; i++){
        ruisekiwa.at(i+1) = ruisekiwa.at(i) + v.at(i);
    }
    int max_num = 0;
    int itr;
    for (int i = k; i <= n; i++){
        if (max_num <= ruisekiwa.at(i) - ruisekiwa.at(i-k)){
            max_num = ruisekiwa.at(i) - ruisekiwa.at(i-k);
            itr = i;
        }
    }
    itr--;
    double ans = 0;
    for (int i = itr; i > itr -k; i--){
        ans += kitaichi(v.at(i));
    }
    cout << fixed << setprecision(15) << ans << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi           first
#define se           second
#define ll           long long
#define pb           push_back
#define mp           make_pair
#define pll          pair<ll,ll>
#define pii          pair<int,int>
#define SZ(x)        ((int)(x).size())
#define READ(x)      freopen(x,"r",stdin)
#define WRITE(x)     freopen(x,"w",stdout)
#define all(x)       (x).begin(),(x).end()
#define isWorking()  cout<<"Wroking"<<endl
#define FOR(i,x,y)   for(int i=x; i<y; i++)
#define SORT(x)      sort(x.begin(),x.end())
#define PRINT(ok)    cout<<(ok? "YES":"NO")<<endl
#define Fast_Input   ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
typedef vector<int> VI;
const ll mod= 1e9+7,INF=1e18,mx= 1e6+5,mn=100;
int testCase=1,cas=0;

int ar[mx];

int main() {

    Fast_Input

   // cin>>testCase;
    while(testCase--) {
        int n , m; cin>>n>>m;
        int cnt=0,k=m;
        while(m--){
            int a,b; cin>>a>>b;
            ar[a]++;
            ar[b+1]--;
        }
        for(int i=1; i<=n; i++){
            ar[i]+=ar[i-1];
            if(ar[i]>=k) cnt++;;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	long long int min = 1000000, max = -1000000, sum = 0;
	int n, a;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a <= min) min = a;
		if (a >= max) max = a;
		sum += a;
	}
	printf("%lld %lld %lld\n", min, max, sum);
	return 0;
}
	

Measured memory_bytes: 2740
N, M, C = map(int,input().split())
B = list(map(int,input().split()))

ans = 0
for i in range(N):
    A = list(map(int,input().split()))
    sum = C

    for j in range(M):
        sum += A[j] * B[j]

    if sum > 0:
        ans += 1

print(ans)

Measured memory_bytes: 9192
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}
int mid(int a, int b, int c) {
    if(a > b) swap(a, b);
    if(a > c) swap(a, c);
    if(b > c) swap(b, c);
    return b;
}
int simulate(vector<int> v) {
    int N = (v.size() + 1) / 2;
    vector<int> cur = v;
    REP(_, N-1) {
        vector<int> next;
        for(int i = 0; i+2 < cur.size(); i++) {
            next.push_back(mid(cur[i], cur[i+1], cur[i+2]));
        }
        cur.swap(next);
    }
    return cur[0];
}
void output(int N) {
    int L = 2 * N - 1;
    vector<int> a(L);
    REP(i, L) a[i] = i + 1;
    map<int, int> s;
    do{
        vector<int> cur = a;
        REP(_, N-1) {
            vector<int> next;
            for(int i = 0; i+2 < cur.size(); i++) {
                next.push_back(mid(cur[i], cur[i+1], cur[i+2]));
            }
            cur.swap(next);
        }
        s[cur[0]]++;
        if(s[cur[0]] == 1) {
            REP(i, a.size()) cout << a[i] << " ";
            cout << endl;
            cout << cur[0] << endl;
        }
    }while(next_permutation(a.begin(), a.end()));
    for(auto p : s) cout << p.first << "," << p.second << " ";
    cout << endl;
}
int main(){
    iostream_init();
    int N;
    cin >> N;
    int X;
    cin >> X;
    int L = 2 * N - 1;
    // 1 .. L
    if(X == 1 || X == L) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        int M = L / 2 + 1;
        if(X >= M) {
            REP(i, M-1) {
                cout << i+1 << endl;
            }
            cout << X << endl;
            int cur = L;
            REP(i, M-1) {
                while(cur == X) --cur;
                cout << cur-- << endl;
            }
        } else {
            vector<int> v;
            int cur = 1;
            REP(i, M-1) {
                while(cur == X) ++cur;
                v.push_back(cur++);
            }
            reverse(v.begin(), v.end());
            REP(i, v.size()) cout << v[i] << endl;
            cout << X << endl;
            REP(i, M-1) {
                cout << M+i+1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>

int main(void){
	int A,B,sum;
	char buf[10];
	fgets(buf,10,stdin);
	sscanf(buf,"%d %d",&A,&B);
	sum=A+B;
	if(sum<10)
		printf("%d\n",sum);
	else
		printf("error\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll dp[3007][3007];

int main(){
  string S,T;
  cin >> S >> T;
  rep(i,3005){
    dp[i][0]=0;
    dp[0][i]=0;
  }
  rep(i,S.size()){
    rep(j,T.size()){
      if(S[i]==T[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }
      else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  string s;
  ll i=S.size(),j=T.size();
  while(i>0||j>0){
    if(i>0&&j>0&&dp[i][j]>dp[i-1][j-1]&&dp[i][j]>dp[i-1][j]&&dp[i][j]>dp[i][j-1]){
      s=S[i-1]+s;
      i--;j--;
    }
    else if(i>0&&dp[i][j]==dp[i-1][j]){
      i--;
    }
    else{
      j--;
    }
  }
  cout << s << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for (int i = 2; i < n; i++) {
    int p1 = dp[i - 1] + abs(h[i - 1] - h[i]);
    int p2 = dp[i - 2] + abs(h[i - 2] - h[i]);
    dp[i] = min(p1, p2);
  }
  cout << dp[n - 1] << endl;
  return 0;
}

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

int N, T, H, L, t[102], h[102];

void dump(int i) {
	cout << i+1 << endl;
	exit(0);
}

int main() {
	cin >> N >> T >> H >> L;
	for (int i=0; i<N; ++i) cin >> t[i] >> h[i];
	
	int sum = 0;
	while (1) {
		for (int i=0; i<N; ++i) {
			if (t[i] > 0) {
				sum += 10;
				--t[i];
				++T;
				if (T > L) dump(i);
			}
			else if (h[i] > 0) {
				sum += 100;
				--h[i];
				++H;
			}
			else {
				dump(i);
			}
			
			if (sum >= 90) {
				int out = sum - 90;
				sum = 0;
				
				while (out > 0 && out/10 > T) {
					if (H == 0 || out < 100) dump(i);
					out -= 100;
					--H;
					++h[i];
				}
				
				T -= out/10;
				t[i] += out/10;
			}
		}
	}
}


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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define print(x) cout << x << endl
#define debug print("reaching\n")
#define mll map<ll,ll>
#define lsb(i) i&(-i)
#define printv(x) \
	FORALL(i, x.size()) \
	{ \
		cout << x[i] << ' '; \
	} \
	cout << endl \
;
#define printm(m) \
	for(auto i: m){\
		cout<<i.ff<<' '<<i.ss<<endl; \
	}\
;
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
	if(b<=0) return 1;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}



template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	else
	{
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m)
{
	T x, y;
	extGcd(a, m, x, y);
	return (x % m + m) % m;
}


int main()
{
	fast;
	// cin.tie(0);
	// cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int t=1;
	// cin>>t;
	ll tot=t;
	while(t--){
		ll n;
		cin>>n;
		cout<<(!n)<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        Integer a[] = new Integer[4];
        a[0] = null; a[1] = null; a[2] = null; a[3] = null;

        for (int i = 0; i < m; i++) {
            int s = scan.nextInt();
            int c = scan.nextInt();
            if (a[s] == null || a[s] == c) {
                a[s] = c;
            } else {
                System.out.println(-1);
                return;
            }
        }

        for (int i = 0; i < 1000; i++) {
            String s = String.valueOf(i);
            int len = s.length();
            if (len == n &&
                (a[1] == null || Integer.valueOf(s.substring(0,1)) == a[1]) &&
                (len >= 2 ? (a[2] == null || Integer.valueOf(s.substring(1,2)) == a[2]) : true) &&
                (len >= 3 ? (a[3] == null || Integer.valueOf(s.substring(2,3)) == a[3]) : true)) {
                    System.out.println(i);
                    return;
                }
        }

        System.out.println(-1);
    }
}


Measured memory_bytes: 21716
s = input()
ki = ["R", "U", "D"]
gu = ["L", "U", "D"]

flag = True
for i, s in enumerate(s):
  if (i+1) % 2 == 1:
    if s not in ki:
      flag = False
  else:
    if s not in gu:
      flag = False
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int main() {
	ll N, K, s = 0, p = 0;
	cin >> N >> K;
	vector<pair<ll, ll>> a(N);
	rep(i, 0, N)cin >> a[i].first >> a[i].second;
	sort(all(a));
	while (s + a[p].second < K) {
		if (p >= N) {
			p--;
			break;
		}
		s += a[p].second;
		p++;
	}
	printf("%lld\n", a[p].first);
	return 0;
}

Measured memory_bytes: 1792
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
S = [input() for _ in range(H)]

dy = [1, 1, 0, -1, -1, -1, 0, 1]
dx = [0, -1, -1, -1, 0, 1, 1, 1]

for i in range(H):
	for j in range(W):
		if S[i][j] == "#":
			print("#", end="")
		else:
			cnt = 0
			for k in range(8):
				ny = i + dy[k]
				nx = j + dx[k]
				if 0 <= ny < H and 0 <= nx < W:
					if S[ny][nx] == "#":
						cnt += 1
			print(cnt, end="")
	print()


Measured memory_bytes: 5588
#include <iostream>

using namespace std;

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

  memo = (a-c)>(c-a)? a-c : c-a;

  if(memo<=d){
    cout << "Yes" << endl;
    return 0;
  }

  memo = (a-b)>(b-a)? a-b : b-a;

  if(memo<=d){
    memo = (b-c)>(c-b)? b-c : c-b;
    if(memo<=d){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,h;
  cin>>n>>h;
  vector<int> a(n),b(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i]>>b[i];
  }
  int tmp=*max_element(a.begin(), a.end());
  sort(b.begin(), b.end(),greater<int>());
  int cnt=0;
  for (int i = 0; i < n; ++i)
  {
    if(b[i]>=tmp){
      cnt++;
      h-=b[i];
    }
    if(h<=0){
      cout<<cnt;
      return 0;
    }
  }
  cnt+=h/tmp;
  if(h%tmp!=0) cnt++;
  cout<<cnt;
}

Measured memory_bytes: 1024
# Aizu Problem ALDS_1_1_C: Maximum Profit
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


profit = -2**31
N = int(input())
min_so_far = int(input())
for _ in range(N - 1):
    r = int(input())
    profit = max(profit, r - min_so_far)
    min_so_far = min(min_so_far, r)
print(profit)

Measured memory_bytes: 7744
#include  <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;


int main(int argc, char const *argv[]) {
    /* code */
    int n,q,time;
    string name;
    cin >>n;
    cin >> q;
    queue<pair<string,int> > qround;
    for(int i=0;i<n;i++){
        cin >>name;
        cin >> time;
        qround.push(make_pair(name,time));
    }

    pair <string,int> u;
    int allTime=0,a;

    while(!qround.empty()){
        u=qround.front();
        qround.pop();
        a=min(u.second,q);
        u.second -=a;
        allTime +=a;
        if(u.second>0){
            qround.push(u);
        }else{
            cout << u.first << " "<<allTime << endl;
        }
    }

    // for(int i=0;i<n;i++){
    //     cin >> q.name.pop
    // }
    return 0;
}

Measured memory_bytes: 4404
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#include <cstring>
#include <iterator>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;

typedef long long LL;
int main()
{
    LL N, K;
    cin >> N >> K;

    map<LL, LL> freq;
    for (int i = 0; i < N; i++) {
        LL a, b;
        cin >> a >> b;
        if(!freq.count(a))
            freq[a] = 0;
        freq[a] += b;
    }

    map<LL, LL>::iterator it;
    LL k = 1;
    for (it = freq.begin(); k <= K && it != freq.end(); it++) {
        k += it->second;
    }
    it--;
    cout << it->first << endl;
}

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

int main(){
	int n, k;
	cin >> n>>k;
	vector<int>a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());
	vector<int>count;
	for (int i = 0;i < n;) {
		int j = i+1;
		while (j < n && a[i] == a[j]) {
			j++;
		}
		count.push_back(j - i);
		i = j;
	}

	sort(count.begin(), count.end());
	int ans = 0;
	int i = 0;
	while (k+i<count.size()) {
		ans += count[i];
		i++;
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;

    vector<int> D(K);
    for (int i = 0; i < K; i++)
    {
        cin >> D[i];
    }
    
    vector<bool> ok(10, true);
    for (int i = 0; i < K; i++)
    {
        ok[D[i]] = false;
    }
    
    int ans, x = N;
    bool flag = false;
    while(1)
    {
        string s = to_string(x);
        for (int i = 0; i < s.size(); i++)
        {
            if(!ok[s[i] - '0'])
            {
                break;
            }

            if(i + 1 == s.size())
            {
                flag = true;
            }
        }

        if(flag)
        {
            break;
        }

        else
        {
            x += 1;
        }
    }

    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#一次独立：rankが成分数
import numpy as np
#0-indexed,MSBがma以下の時
def msb(x,ma=59):
    for i in range(ma,-1,-1):
        if (x>>i)&1:
            return i
    return len()
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=input()
    #独立、msb同じものはない
    #逆に異なれば独立
    msbs=[0 for i in range(60)]
    for i in range(n-1,-1,-1):
        now=a[i]
        m=59
        #独立のときfはTrue、独立でない時fはFalse
        while True:
            m=msb(now,m)
            if msbs[m]==0:
                f=True
                break
            now=msbs[m]^now
            if now==0:
                f=False
                break
        if s[i]=="0":
            if f:
                msbs[m]=now
        else:
            if f:
                print(1)
                break
    else:
        print(0)

Measured memory_bytes: 26900
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
using namespace std;

int main () {
	int a, b, c;
	cin >> a >> b >> c; 
	if(a + b + c >= 22) cout << "bust";
	else cout << "win";
	return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    int sy, sx;
    cin >> sy >> sx;

    string S, T;
    cin >> S >> T;

    // 駒を取り除ける true 
    bool ans = false;

    char d1[] = {'U', 'D', 'R', 'L'};
    char d2[] = {'D', 'U', 'L', 'R'};
    rep(i, 4) {
        int y = sy - 1, x = sx - 1;
        char c1 = d1[i], c2 = d2[i];
        rep(j, N) {
            if (S[j] == c1) {
                if (c1 == 'U') y--;
                if (c1 == 'D') y++;
                if (c1 == 'R') x++;
                if (c1 == 'L') x--;
            }

            if (x < 0 || W <= x || y < 0 || H <= y) {
                ans = true;
            }

            if (T[j] == c2) {
                if (0 < y && c2 == 'U') y--;
                if (y < H - 1 && c2 == 'D') y++;
                if (x < W - 1 && c2 == 'R') x++;
                if (0 < x && c2 == 'L') x--;
            }
        }
    }

    if (!ans) {
        puts("YES");
    } else {
        puts("NO");
    }
}

Measured memory_bytes: 776
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ");
        int a1 = Integer.parseInt(line[0]);
        int a2 = Integer.parseInt(line[1]);
        int a3 = Integer.parseInt(line[2]);
        int a4 = Integer.parseInt(line[3]);
        int a5 = Integer.parseInt(line[4]);
        int a6 = Integer.parseInt(line[5]);
 
        int b = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < b; i++) {
            int c = scanner.nextInt();
            int d = scanner.nextInt();
            int result = 0;
            if (c == a1 || c == a6)
                if (d == a2)
                    result = 3;
                else if (d == a3)
                    result = 5;
                else if (d == a4)
                    result = 2;
                else
                    result = 4;
            else if (c == a2 || c == a5)
                if (d == a1)
                    result = 4;
                else if (d == a3)
                    result = 1;
                else if (d == a4)
                    result = 6;
                else
                    result = 3;
            else {
                if (d == a1)
                    result = 2;
                else if (d == a2)
                    result = 6;
                else if (d == a5)
                    result = 1;
                else
                    result = 5;
            }
            if (c == a4 || c == a5 || c == a6)
                result = 7 - result;
            System.out.println(line[result - 1]);
        }
    }
}



Measured memory_bytes: 26300
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = [0] * (n + 1)

ans = 0
cnt = {0: 1}
for i in range(n):
    s[i + 1] = s[i] + a[i]
    s[i + 1] %= m
    now = cnt.setdefault(s[i + 1], 0)
    cnt[s[i+1]] = now+1
#print(cnt)

for x in cnt.values():
    ans += x * (x-1) // 2
print(ans)


Measured memory_bytes: 15460
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	w := getNextInt(scanner)
	h := getNextInt(scanner)
	pp := make([]int, w)
	qq := make([]int, h)
	for i := 0; i < w; i++ {
		pp[i] = getNextInt(scanner)
	}

	sort.Ints(pp)
	for i := 0; i < h; i++ {
		qq[i] = getNextInt(scanner)
	}

	sort.Ints(qq)
	if pp[0] > qq[0] {
		pp, qq = qq, pp
		w, h = h, w
	}

	ss := make([]int64, h+1)
	for i := 0; i < h; i++ {
		ss[i+1] = ss[i] + int64(qq[i])
	}
	var ans int64
	ans = int64(h+1)*int64(pp[0]) + ss[h]
	for i := 1; i < w; i++ {
		l := -1
		r := h
		for l+1 < r {
			m := (l + r) >> 1
			if qq[m] < pp[i] {
				l = m
				continue
			}
			r = m
		}
		ans += int64(h-r+1)*int64(pp[i]) + ss[r]
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 5888
#include <string>
#include <bits/stdc++.h>
#include <set>    
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<int> st;

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<int,int> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<int> sta;   
    //queue<int> que;


int main(){
	
	long long N,M,K;
	string s;
    
	std::cin >> N;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    
    
	std::vector<long long> v(N);
	std::vector<long long> w(N);
    //std::cin >> s;
    
    
    // 配列入力
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
		if(st.find(v[i])==st.end()){
			st.insert(v[i]);
		}
		else{
			st.erase(v[i]);
		}
	}
	
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
	
	
	//ソート
    //std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    int sum,sum1;
	sum=0;
	sum1=0;
	int flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	int max;
	int max1;
	max=0;
	max1=0;
	
    /*
	for(long long i=0; i<N; i++){
		
	}
	*/
	
	//文字列入力
	/*
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]!='1'){
	}
	*/
    if(1){
    	printf("%d",st.size());
    	//puts("Yes");
    	//文字列の出力
    	//std::cout << s.size << std::endl;
	}
	else{
		//puts("No");
	}
	return 0;
}

Measured memory_bytes: 6528
import numpy as np
n, a = map(int, input().split())
x = list(map(int, input().split()))

s = sum(x)
dp = np.zeros((n, s+1), dtype = np.int64)
for i in range(n):
  for j in range(i)[::-1]:
    dp[j+1][x[i]:] += dp[j][:-x[i]]
  dp[0][x[i]] += 1
ans = 0
for i in range(n):
  if (i+1)*a <= s:
    ans += dp[i][(i+1)*a]
print(ans)

Measured memory_bytes: 27600
N=int(input())
dums = list(map(int, input().split()))

M_1 = 0
for i,val in enumerate(dums):
    i+=1
    if i%2==1:
        M_1 += val
    else:
        M_1 -= val

out_dict = {i+1:0 for i in range(N)}
out_dict[1] = M_1

for i in range(1,N):
    out_dict[i+1] = 2*dums[i-1] - out_dict[i]

print(" ".join(list(map(str, out_dict.values()))))

Measured memory_bytes: 28344
#include <bits/stdc++.h>
using namespace std;
 
void solve(std::string S){
    bool s1 = S[0] == 'R';
    bool s2 = S[1] == 'R';
    bool s3 = S[2] == 'R';
    if( s1 && s2 && s3){
      cout << 3 << endl;
    } else if(!( s1 || s2 || s3)){
      cout << 0 << endl;
    } else if(s2 && (s1 || s3)){
      cout << 2 << endl;
    } else {
      cout << 1 << endl;
    }
}
 
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3616