akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define pb push_back
#define mk make_pair
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, pair<int, int> >piii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int inf = 1e9;
const LL INF = 1e18;
const int M = 1e9 + 7;
//__int128


int main(int argc, char const *argv[])
{

	int a[3];
	for(int i = 0; i < 3; ++i){
		cin >> a[i];
	}
	sort(a, a + 3);
	cout << a[0] + a[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#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>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  rep(i,n) cin >> h[i];
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    if (h[a] <= h[b]) ok[a] = false;
    if (h[b] <= h[a]) ok[b] = false;
  }
  int ans = 0;
  rep(i,n) if (ok[i]) ans++;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3752
package main

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

func main() {
	N := nextInt()
	M := nextInt()
	X := nextInt()

	table := make([][]int, N)
	for i := range table {
		table[i] = make([]int, M+1)
	}

	for i := 0; i < N; i++ {
		for j := 0; j < M+1; j++ {
			table[i][j] = nextInt()
		}
	}

	ans := maxInt()
	for i := 0; i < (1 << N); i++ {
		cost := 0
		values := make([]int, M)
		for j := 0; j < N; j++ {
			if (i>>j)&1 == 1 {
				cost += table[j][0]
				for k := 0; k < M; k++ {
					values[k] += table[j][k+1]
				}
			}
		}

		ok := true
		for _, v := range values {
			if v < X {
				ok = false
			}
		}

		if ok {
			ans = Min(cost, ans)
		}
	}
	if ans == maxInt() {
		fmt.Println(-1)
		return
	}
	fmt.Println(ans)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func maxInt() int {
	return math.MaxInt32
}

func maxInt64() int64 {
	return math.MaxInt64
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>                                                                           
using namespace std;
int main(){
  int X;
  cin >> X;
  if(X==7)
    cout << "YES" << endl;
  else if(X==5)
    cout << "YES" << endl;
  else if(X==3)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
// 2020-08-15 12:37:58
#include<bits/stdc++.h>
#define rep(i, n) REP(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = long long;

const int mod = 1000000007;
namespace combinatorics {
  const int limit = 200020;
  bool initialized = false;
  long long fac_table[limit], inv_table[limit], finv_table[limit];
  void initialize() {
    fac_table[0] = fac_table[1] = 1;
    inv_table[1] = 1;
    finv_table[0] = finv_table[1] = 1;
    for (int i = 2; i < limit; i++) {
      fac_table[i] = fac_table[i - 1] * i % mod;
      inv_table[i] = mod - inv_table[mod % i] * (mod / i) % mod;
      finv_table[i] = finv_table[i - 1] * inv_table[i] % mod;
    }
    initialized = true;
  }
  long long com(int n, int k) {
    if (!initialized) initialize();
    if (n < k || n < 0 || k < 0) return 0;
    else return fac_table[n] * (finv_table[k] * finv_table[n - k] % mod) % mod;
  }
  long long perm(int n, int k) {
    if (!initialized) initialize();
    if (n < k || n < 0 || k < 0) return 0;
    else return fac_table[n] * finv_table[n - k] % mod;
  }
}
using combinatorics::com;

void answer() {
  int n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  rep(_, 2) {
    rep(i, n) {
      ll cur = i;
      (cur *= n-i) %= mod;
      (cur *= m) %= mod;
      (cur *= m) %= mod;
      (ans += cur) %= mod;
    }
    swap(n, m);
  }
  (ans *= com(n*m-2, k-2)) %= mod;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 8344
#include<iostream>
#include<vector>

using namespace std;

int main(void)
{
  vector<int> x(5);
  for(int i=0;i<5;i++){
    cin>>x[i];
    if(x[i]==0){
      cout<<i+1<<endl;
      return 0;
    }
  }
  
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

int n;
string in[100];

int over(string a,string b){
  int ov = min(a.size(),b.size()) - 1;
  for(;ov;--ov){
    if(a.substr(a.size()-ov) == b.substr(0,ov)){
      //cout << a << " " << b << " " << ov << endl;
      return ov;
    }
  }
  return 0;
}

int cost[100][100];
int memo[1<<14][14];

int rec(int st,int l){
  if(st == (1<<l)){
    //cout << "hitt" << endl;
    return 0;//cost[l][l];
  }
  
  if(memo[st][l] >= 0)
    return memo[st][l];
  
  int& ret = memo[st][l] = 0;
  for(int i = 0; (1<<i) <= st; ++i){
    if(~st&(1<<i)) continue;
    if(i == l) continue;
    ret = max(ret, cost[i][l] + rec(st^(1<<l),i));
  }
  //cout << st << " " << l << " " << ret << endl;
  return ret;
}

int main(){
  while(cin >> n && n){
    set<string> app;
    for(int i = 0; i < n; ++i){
      string s;
      cin >> s;
      app.insert(s);
    }

    set<string> use;
    for(auto s : app){
      bool ok = 1;
      for(auto e : app){
        if(s == e) continue;
        ok &= e.find(s) == string::npos;
      }
      if(ok) use.insert(s);
    }

    vector<string> vs(use.begin(), use.end());

    memset(cost, 0 , sizeof(cost));
    for(int i = 0; i < vs.size(); ++i){
      for(int j = 0; j < vs.size(); ++j)
        cost[i][j] = over(vs[i], vs[j]);
      cost[i][i] = 0;//vs[i].size();
    }
    
    int ans = 0;
    memset(memo,-1 ,sizeof(memo));
    int sum = 0;
    for(int i = 0; i < vs.size(); ++i){
      ans = max(ans, rec((1<<vs.size()) - 1, i));
      sum += vs[i].size();
    }
    
    cout << sum - ans << endl;
  }
}

Measured memory_bytes: 2172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	
	public static void main(String[] args) throws IOException{
		
		InputStreamReader inputStreamReader = new InputStreamReader(System.in);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		
		String nInput = bufferedReader.readLine();
		int n = Integer.parseInt(nInput);
		int numberOfBars = n * 2;
		
		String barsInput = bufferedReader.readLine();
		
		String[] barsStrings = new String[numberOfBars];
		barsStrings = barsInput.split("[\\s]+");
		
		int[] bars = new int[numberOfBars];
		
		for(int i = 0; i < numberOfBars; i++) {
			bars[i] = Integer.parseInt(barsStrings[i]);
		}
		
		Arrays.sort(bars);
		
		int result = 0;
		
		for(int i = 0; i < numberOfBars; i = i + 2) {
			result = result + bars[i];
		}
		
		System.out.println(result);
	}
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    bool is_found['z'+1];
    reps(i,'a','z') is_found[i] = false;
    string s;
    cin >> s;
    rep(i,s.length()) is_found[s[i]] = true;
    reps(i,'a','z'){
        if(!is_found[i]){
            cout << (char)i << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
struct TT{int nu;int sco;int jun;};

int main(){

	struct TT TR[101]={};
int n,x;
int c=0;
while(1)
{
	scanf("%d,%d",&n,&x);if(n==0&&x==0)break;
	TR[c].nu=n;TR[c].sco=x;
	c++;
}
for(int i=0;i<c;i++)
	for(int j=c-1;j>i;j--)
		if(TR[j].sco>TR[j-1].sco){struct TT QQ=TR[j];TR[j]=TR[j-1];TR[j-1]=QQ;}

int cn=1;TR[0].jun=1;
for(int i=1;i<c;i++){

	
if(TR[i].sco!=TR[i-1].sco)cn++;
TR[i].jun=cn;

}

while(scanf("%d",&x)!=EOF){


for(int i=0;i<c;i++)
if(x==TR[i].nu)printf("%d\n",TR[i].jun);
}
return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
const double pi = acos(-1);

int main(){
  int N;
  long long L;
  cin >> N >> L;
  vector<double> T(N);
  for (int i=0;i<N;i++){
    scanf("%lf", &T.at(i));
    T.at(i) = 2.0 * pi * T.at(i) / L;
  }
  double rratio = 1.0 * N * (N - 1) * (N - 2) / 6.0;
  double x = 0, y = 0;
  for (int i=0;i<N-1;i++){
    for (int j=i+1;j<N;j++){
      double arg = (T.at(i)+T.at(j))/2.0;
      x += (N-2*j+2*i)*cos(arg);
      y += (N-2*j+2*i)*sin(arg);
    }
  }
  printf("%.15lf %.15lf\n", x/rratio, y/rratio);
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];

  }
  int sum=arr[0];
  for(int i=1;i<n;i++)
    sum=sum^arr[i];
  
  for(int i=0;i<n;i++)
  {
    cout<<(sum^arr[i])<<" ";

    
  }
  
  

  
  
}

Measured memory_bytes: 4372
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>

using namespace std;
using ll = long long;
using ld = long double;

#define all(collection) (collection).begin(), (collection).end()              // begin to end
#define divc(a, b) ceil((ld) a / (ld) b);                                     // div ceiling
#define rep(i, begin, end) for (ll i = begin; i < end; i++)                   // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)                  // repeat reverse
#define size(collection) ((ll) (collection).size())                           // collection size
/********** for each macro **********/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define forir(i, ...) if(ll i = size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, v) forir(i, auto& e: boost::adaptors::reverse(v))

int main(void)
{
	ll N; cin >> N;
	string s; cin >> s;

	if (size(s) % 2 == 1)
	{
		cout << "No";
		return 0;
	}

	string ans;
	rep(i, 0, size(s) / 2)
	{
		ans += s[i];
	}

	ans += ans;
	each(i, e, s)
	{
		if (e != ans[i])
		{
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	long long i,n,ans=1;
	cin >> n;
	for(i=1;i<=n;i++){
		ans=ans*i;
		if(ans>=1000000007) ans=ans%1000000007;
	}
	cout << ans << endl;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    vi s(n);
    map<string,int> items;
    REP(i,n) {
        string s;
        cin>>s;
        items[s] += 1;
    }
    int ans = 0;

    for(auto i:items) ans++;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19568
#include<stdio.h>
#include<string.h>
#include<math.h>
#define N_MAX 200001
#define ll long long
#define MOD 2019



int main(){
  int g=1,len;
  ll ans=0;
  char a[N_MAX];
  scanf("%s",a);
  len=strlen(a);
  int T[N_MAX]={};
  T[len]=0;
  int counter[MOD]={};
  counter[0]=1;
  for(int k=len-1;k>=0;k--){
    T[k]=(T[k+1]+g*(a[k]-'0'))%MOD;
    counter[T[k]]++;
          g*=10;
          g%=2019;
  };
  for(int b=0;b<MOD;b++){
    ans+=counter[b]*(counter[b]-1)/2;
  };
  printf("%lld",ans);
};


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

int main() {
	string s; cin >> s;
	int n = s.size();
	int ans = 0;
	int l = 0, r = n - 1;
	while(l < r) {
		if(s[l] == s[r]) {
			l++;
			r--;
			continue;
		}
		if(s[l] == 'x') {
			l++;
			ans++;
		} else if(s[r] == 'x') {
			r--;
			ans++;
		} else {
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << ans << '\n';
	return 0;
}


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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans;
    if (a >= k) ans = k;
    else if (a + b >= k) ans = a;
    else ans = a - (k - a - b);
    cout << ans << endl;
}


Measured memory_bytes: 3632
#ABC154D
def main():
    import sys
    N, K = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    L =[0 for _ in range(N)]
    #期待値 (初項+末項)/2
    for i in range(N):
        L[i]=(1 +P[i])/2
    #print(L)
    #累積和
    for i in range(N-1):
        L[i+1] +=L[i]
    #print(L)
    ans = L[K-1]
    for i in range(N-K):
        s = L[i+K]-L[i]
        if ans < s:
            ans = s
    print(ans)

if __name__=='__main__':
    main()

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,v) VL v(n);rep(i,n)cin>>v[i]
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>)
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl
#define debgp(a) cout<<#a<<" "<<a.fi<<" "<<a,se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(const auto&y:a){for(const auto&x:y)cout<<x<<" ";cout<<endl;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define PQ priority_queue
typedef long long ll;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<PL> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T gcd(T a,T b){return (b==0?a:gcd(b,a%b));}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*a;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  str s[2];
  cin>>n>>s[0]>>s[1];
  
  int res=0;
  rep(i,n){
    bool can=true;
    rep(j,i+1){
      if(s[0][n-1-i+j]!=s[1][j])can=false;
    }
    if(can)res=i+1;
  }
  out(2*n-res);

  
  
  
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc158_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var A = CIn.ReadInt();
      var B = CIn.ReadInt();

      for (int i = 1; i <= 1000; i++)
      {
        if ((int)(i * 0.08) == A && (int)(i * 0.1) == B)
        {
          Console.WriteLine(i);
          return;
        }
      }

      Console.WriteLine(-1);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


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

using namespace std;

typedef long long ll;

const ll M = 300000, R = 998244353; ll factorial[ M + 1 ], inv_factorial[ M + 1 ];

inline ll mod_pow( ll a, ll b )
{
	ll x = 1, y = a;

	while( b > 0 )
    {
		if ( b & 1 )
			x *= y, x %= R;

		y *= y, y %= R, b >>= 1;
	}

	return x % R;
}

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    ll A, B, K, N, count = 0; cin >> N >> A >> B >> K;

    const auto mod_inv = [] ( ll n ) { return mod_pow( n, R - 2 ); };

    inv_factorial[ 0 ] = mod_inv( factorial[ 0 ] = 1 );

    for( ll i = 0, j = 1; j <= N; i = j++ )
        inv_factorial[ j ] = mod_inv( factorial[ j ] = j * factorial[ i ] % R );

    const auto C = [] ( ll n, ll k )
    {
        return ( factorial[ n ] * inv_factorial[ k ] % R ) * inv_factorial[ n - k ] % R;
    };

    ll u_min = max( 0LL, ( K - B * N ) / A ), u_max = min( K / A, N );

    for( ll u = u_min, w = K - A * u; u <= u_max; u++, w -= A )
        if ( ( w % B ) == 0 )
            count += C( N, u ) * C( N, w / B ) % R, count %= R;

    cout << count;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int INF=1001001001;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>A(n),B(m),C(m);
  rep(i,n)cin>>A[i];
  rep(i,m)cin>>B[i]>>C[i];
  priority_queue<pair<int,int>>q;
  rep(i,n){
    q.push(make_pair(A[i],1));
  }
  rep(i,m){
    q.push(make_pair(C[i],B[i]));
  }
  ll ans =0;
  rep(i,n){
    auto p=q.top();
    q.pop();
    ans+=p.first;
    if(p.second>1){
      p.second--;
      q.push(p);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3572
import sys
input = sys.stdin.readline

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

if M==2:
    ANS0=0
    ANS1=0

    for i in range(N):
        if A[i]%2==i%2:
            ANS0+=1
        else:
            ANS1+=1

    print(min(ANS0,ANS1))

else:
    A.append(10**10)
    count=0
    ANS=0

    for i in range(N+1):
        if A[i]==A[i-1]:
            count+=1
        else:
            ANS+=count//2
            count=1
    print(ANS)
            



Measured memory_bytes: 16520
// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

void play(int n,int m,int p){
    int mas[105];
    int sum=0;
    
    for(int i = 1 ; i <= n ; i++){
        cin >> mas[i];
        sum+= mas[i];
    }
    
    sum*=100;
    
    sum = sum - (sum/100)*p;
    
    if(mas[m] == 0) cout << "0" << endl;
    else cout << int(double(sum)/double(mas[m])) << endl;
}
main(){
    int n,m,p;
    
    while(cin >> n >> m >> p){
        if(n == 0) break;
        play(n,m,p);
    }
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b) cout<<c<<endl;
    else if(a==c) cout<<b<<endl;
    else if(b==c)cout<<a<<endl;

    return 0;
}



Measured memory_bytes: 256
ans = []
while True:
    n, k, m = map(int, input().split())
    if n == k == m == 0:
        break
    stones = [i + 1 for i in range(n)]
    m -= 1
    while n > 1:
        stones.pop(m)
        n -= 1
        m = ((m + k) - 1) % n
    ans.append(stones[0])

for i in ans:
    print(i)


Measured memory_bytes: 5928
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
x = 0
for i in range(len(t)):
    if i >= k and t[i] == t[i-k]:
        t[i] = ' '
    if t[i] == "r":
        x += p
    elif t[i] == "s":
        x += r
    elif t[i] == "p":
        x += s
print(x)

Measured memory_bytes: 4084
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
using namespace std;
int main(){
    long long int n,m;
    long long int ans;
  cin>>n>>m;
    if(m<=2*n){
        ans=m/2;
    }else{
       ans=n;
       ans+=(m-2*n)/4;
    }
    cout<<ans<<endl;
}   




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int n,d;
	cin>>n>>d;
	double X[n][d];
	rep(i,n){
		rep(j,d){
			cin>>X[i][j];
		}
	}
	int cnt = 0;
	rep(i,n-1){
		for(int j = i+1;j<n;j++){

			double work=0;
			rep(k,d){
				work += pow(X[i][k]-X[j][k],2.0);
			}
			work = sqrt(work);
			// ceil 切り下げ関数 , floor 切り上げ関数
			// 切り下げても 切り上げても 値が一致すれば、それは整数である。
			if(ceil(work)==floor(work)) cnt++;
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

int n;
Vi perm;

bool check(int k) {
	auto at = [k](int i) { return perm[i] >= k; };

	if (at(n-2) == at(n-1) || at(n) == at(n-1)) {
		return at(n-1);
	}

	int l = n-2, r = n;
	while (l >= 1 && at(l) != at(l-1)) l--;
	while (r+1 < sz(perm) && at(r) != at(r+1)) r++;

	int dist = 1e6;
	if (l >= 1) dist = min(dist, n-1-l);
	if (r+1 < sz(perm)) dist = min(dist, r-n+1);

	if (dist <= n-1) {
		if (l >= 1 && dist == n-l-1) return at(l);
		return at(r);
	}
	return at(n-1) ^ ((n+1) % 2);
}

void run() {
	cin >> n;
	perm.resize(n*2-1);
	each(e, perm) cin >> e;

	int begin = 1, end = n*2;

	while (begin+1 < end) {
		int mid = (begin+end) / 2;
		if (check(mid)) {
			begin = mid;
		} else {
			end = mid;
		}
	}

	cout << begin << endl;
}


Measured memory_bytes: 1024
K = int(input())
A, B = map(int, input().split())
ans = 'NG'

if A % K == 0 or B % K == 0:
    print('OK')
    exit(0)
for i in range(A + 1, B + 1):
    if i % K == 0:
        print('OK')
        exit(0)
print(ans)

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  while(k--){
    if(a>=b) b*=2;
    else if(b>=c) c*=2;
    else break;
  }
  if(a<b&&b<c)cout <<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}


Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var item1 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = item1[0];
            var K = item1[1];

            var item2 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var R = item2[0];
            var S = item2[1];
            var P = item2[2];

            var T = Console.ReadLine();

            var victoryTable = new Dictionary<char, char>()
            {
                { 'r', 'p' },
                { 's', 'r' },
                { 'p', 's' },
            };

            var loseTable = new Dictionary<char, char>()
            {
                { 'r', 's' },
                { 's', 'p' },
                { 'p', 'r' },
            };

            var scoreTable = new Dictionary<char, int>()
            {
                { 'r', R },
                { 's', S },
                { 'p', P },
            };

            var score = 0;
            var history = new List<char>();
            foreach (var i in Enumerable.Range(0, T.Length))
            {
                var choise = victoryTable[T[i]];
                if (i - K >= 0 && choise == history[i - K])
                {
                    // 勝ち手を出せない場合は次で勝てる手を出しておく
                    choise = (i + K < T.Length) ? loseTable[T[i + K]] : 'r';
                }
                else
                {
                    score += scoreTable[choise];
                }

                history.Add(choise);
            }

            Console.WriteLine(score);
        }
    }
}


Measured memory_bytes: 14304
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
	int n, A[1000];

	while (1) {
		cin >> n;
		if (n == 0) break;

		for (int i = 0; i < n; i++) cin >> A[i];
		int sum = 0;
		for (int i = 0; i < n; i++) sum += A[i];
		double avg = 1.0 * sum / n;
		double dist = 0.0;
		for (int i = 0; i < n; i++) {
			dist += (avg - A[i]) * (avg - A[i]);
		}

	printf("%lf\n", sqrt(dist / n));
	}
}


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

void judge(int s,int r){
    if(s >= 80) cout << 'A' << endl;
    else if(s >= 65) cout << 'B' << endl;
    else if(s >= 50) cout << 'C' << endl;
    else if(s >= 30){
        if(r >= 50) cout << 'C' << endl;
        else cout << 'D' << endl;
    }
    else cout << 'F' << endl;
}

int main(){
    int m,f,r;
    
    while(cin >> m >> f >> r){
        if(m==-1&&f==-1&&r==-1) break;
        int sum = m+f;
        if(m == -1 || f == -1) cout << 'F' << endl;
        else judge(sum,r);
    }
    
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#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() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索
// 偶奇，逆から，ソート
// 存在判定：構成方法，入力の特徴
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int N; cin >> N;
map<int, int> m;
rep(i, 0, N) {
    int a;
    cin >> a;
    ++m[a];
}

if (N % 3){
    if (m[0] == N){
        cout <<"Yes\n"; 
        return 0;
    }
}
else {
    if (m.size() == 1){
        if (m[0] == N) {
            cout << "Yes\n"; 
            return 0;
        }
    }
    else if (m.size() == 2){
        if (m[0] == N/3){
            cout << "Yes\n"; 
            return 0;
        }
    }
    else if (m.size() == 3) {
        VP mp(3);
        int i = 0,  X = 0;
        for (PII p: m) {
            mp[i] = p;
            X ^= p.first;
            ++i;
        }
        if (X == 0 && mp[0].second == mp[1].second && mp[1].second == mp[2].second){
            cout <<"Yes\n"; 
            return 0;
        }
    }
}
cout << "No\n";
}

// 境界，出力文字列 チェック



Measured memory_bytes: 3840
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(n, m, i) for (i32 i = (n); i < (m); ++i)
#define upto(n, m, i) for (i64 i = (n); i <= (m); ++i)
#define downto(n, m, i) for (i32 i = (n); i >= (m); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

using u64 = unsigned long long;

u64 h, w, n;
i64 a[100001], b[100001];
map<pair<i64,i64>, i64> m;

i32 main()
{
    cin >> h >> w >> n;
    times(n, i) {
        cin >> a[i] >> b[i];
        upto(-2, 2, y) {
            upto(-2, 2, x) {
                i64 ay = a[i]+y, ax = b[i]+x;
                if (1 <= ay && ay <= h-2 && 1 <= ax && ax <= w-2) {
                    m[make_pair(a[i]+y, b[i]+x)] = 0;
                }
            }
        }
    }

    times(n, i) {
        upto(-2, 0, y) {
            upto(-2, 0, x) {
                i64 ay = a[i]+y, ax = b[i]+x;
                if (1 <= ay && ay <= h-2 && 1 <= ax && ax <= w-2) {
                    pair<i64, i64> t = make_pair(a[i]+y, b[i]+x);
                    if (m.find(t) != m.end()) {
                        m[t]++;
                    }
                }
            }
        }
    }

    u64 ans[10]; memset(ans, 0, sizeof(ans));
    
    foreach(m, p) {
        ans[p.second]++;
    }

    u64 acc = 0;
    range(1, 10, i) {
        acc += ans[i];
    }
    ans[0] = (h-2)*(w-2) - acc;

    times(10, i) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char const *argv[]) {
	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	
	int c = 0;
	vector<int> cnt(N, 0);
	rep(i, N-1) {
		if (S[i] == 'A' && S[i+1] == 'C') c++;
		cnt[i+1] = c;
	}

	rep(i, Q) {
		int l, r; cin >> l >> r;
		cout << cnt[r-1] - cnt[l-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int d1,d2;
	double s;
	scanf("%d %d",&d1,&d2);
	if(d1>d2)	swap(d1,d2);
	if(d2-d1>180)	{
		d1+=360;	swap(d1,d2);
	}
	s=(double)(d2+d1)/2.0;
	if(s>=360.0)	s-=360.0;
	if(s<0.0)	s+=360.0;
	printf("%lf\n",s);
	return 0;
}


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

static const int nmax = 40, abmax = 10, inf = 1000000; 

int main(){

    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for(int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];

    vector<vector<vector<int> > > dp(N + 1, vector<vector<int> >((nmax * abmax) + 1, vector<int>((nmax * abmax) + 1, inf)));
    dp[0][0][0] = 0;

    for(int i = 0; i < N; i++){
        for(int ca = 0; ca <= nmax * abmax; ca++){
            for(int cb = 0; cb <= nmax * abmax; cb++){
                if(dp[i][ca][cb] == inf) continue;
                dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
                dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
            }
        }
    }

    int ans = inf;
    for(int ca = 1; ca <= nmax * abmax; ca++){
        for(int cb = 1; cb <= nmax * abmax; cb++){
            if(ca * Mb == cb * Ma) ans = min(ans, dp[N][ca][cb]);
        }
    }

    if(ans == inf) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 27264
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <numeric>
#include <cassert>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/


int relu(int x) {
	if (x < 0)return 0;
	return x;
}

void proc() {
	LOAD(int, N);
	LOAD(int, K);
	LOADVEC(int, a, N);

	std::vector<int> tot(N + 1);
	std::vector<int> totPos(N + 1);
	tot[0] = 0;
	totPos[0] = 0;
	for (int i = 0; i < N; ++i) {
		tot[i + 1] = tot[i] + a[i];
		totPos[i + 1] = totPos[i] + relu(a[i]);
	}
	int maxScore = -1000000000000000;
	for (int k = 0; k < N - K + 1; ++k) {
		int score = 0;
		score += totPos[k];
		score += totPos[N] - totPos[k + K];
		score += relu(tot[k + K] - tot[k]);
		if (maxScore < score) {
			maxScore = score;
		}
	}
	cout << maxScore;
}

#endif


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

int main() {
  int N,K;
  cin >> N >> K;
  if(K>N){
    K=N;
  }
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());
  
  for(int i=0; i<K; i++){
    H.at(i)=0;
  }
  
  int64_t ans=0;
  for(int i=0; i<N; i++){
    ans += H.at(i);
  }
  
  cout << ans << endl;
  
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

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

using namespace std;

int main()
{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	string s;
	cin >> s;
	int len = s.length(),ans1 = 0,ans2 = 0,a,i;
	for (i = 0; i < len; ++i)
	{
		if (i % 2 == 0 && s.at(i) != '0')
		{
			ans1++;
		}
		else if (i % 2 != 0 && s.at(i) != '1')
		{
			ans1++;
		}
	}

	for (a = 0; a < len; ++a)
	{
		if (a % 2 == 0 && s.at(a) != '1')
		{
			ans2++;
		}
		else if (a % 2 != 0 && s.at(a) != '0')
		{
			ans2++;
		}
	}

	cout << min(ans1,ans2);

    return 0;
}

Measured memory_bytes: 512
// Contest: AtCoder Beginner Contest 175 (https://atcoder.jp/contests/abc175)
// Problem: D: Moving Piece (https://atcoder.jp/contests/abc175/tasks/abc175_d)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    int n, k; cin >> n >> k;
    vi p(n), c(n);
    trav(pi, p) cin >> pi, --pi;
    trav(ci, c) cin >> ci;

    vector<bool> seen(n);
    ll mx = -INFL;
    rep(i, n) {
        if (seen[i]) continue;
        vi circ = {i};
        while (p[circ.back()] != i)
            circ.push_back(p[circ.back()]);
        trav(j, circ) seen[j] = true;
        ll full = 0;
        trav(j, circ) full += c[j];
        full = max(0ll, full);
        rep(j, sz(circ)) {
            ll sum = 0;
            for (int l = 1; l <= sz(circ); ++l) {
                if (l > k)
                    break;
                sum += c[circ[(j + l - 1) % sz(circ)]];
                int rounds = (k - l) / sz(circ);
                mx = max(mx, sum + full * rounds);
            }
        }
    }

    cout << mx << '\n';
    return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

ll modpow(ll a, ll n, int mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;

        n >>= 1;
    }
    return res;
}

ll nCr(int n, int r) {
    ll a = 1;
    ll b = 1;
    
    for (int i = 0; i < r; ++i) {
        a *= (n - i);
        b *= (i + 1);
        a %= MOD;
        b %= MOD;
    }
    return (a * modpow(b, MOD - 2, MOD))%MOD;
}

int main() {
    ll n, a, b; cin >> n >> a >> b;
    ll mpow = modpow(2, n, MOD);
    ll ho = nCr(n, a);


    ll ans = (modpow(2, n, MOD) - 1 + MOD - nCr(n, a)%MOD + MOD - nCr(n, b)%MOD) % MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

vvi g(100001, vi(0));
vi dp(100001, -1);

int dfs(int node) {
  if (dp[node] != -1) return dp[node];
  int r = 0;
  for (int to : g[node]) {
    chmax(r, dfs(to) + 1);
  }
  dp[node] = r;
  return r;
}

int main() {
  init();

  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> xy(M);
  cin >> xy;

  rep(i, M) {
    g[xy[i].first].push_back(xy[i].second);
  }

  int ans = 0;
  rep(i, 1, N + 1) {
    chmax(ans, dfs(i));
  }
  out(ans);
}


Measured memory_bytes: 8960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int l= A+B;
  int r = C+D;
  if(l==r)cout << "Balanced" << endl;
  else if(l>r) cout << "Left" << endl;
  else cout << "Right" << endl;
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
	input = input.split("");
var arr = [];
for(var i=0;i<input.length;i++){
	if(arr[input[i]]){
		arr[input[i]]++;
	}else{
		arr[input[i]] = 1;
	}
}
 // console.log(arr)
var flag = true;
Object.keys(arr).forEach(function(key){
	if(arr[key]%2==1){flag = false;}
});
if(flag){
	console.log("Yes");
}else{
	console.log("No");
}
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
a, b, c = map(int, input().split())

if a < b:
    if c < a:
        print(c, b)
    elif b < c:
        print(a, c)
    else:
        print(a, b)
else:
    if c < b:
        print(c, a)
    elif a < c:
        print(b, c)
    else:
        print(b, a)


Measured memory_bytes: 5596
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}


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

// [0,a]
li totient(li a,int c,int d){
  li l=lcm(c,d);
  return a-(a/c+a/d-a/l);
}

int main(){
  int n,k; cin >>n >>k;
  string s; cin >>s;
  vector<int> smry;
  if(s[0]=='0') smry.push_back(0);
  int cnt=1;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      cnt++;
    }else{
      smry.push_back(cnt);
      cnt=1;
    }
  }
  smry.push_back(cnt);
  if(s[n-1]=='0') smry.push_back(0);
  int m=smry.size();
  if(df)print(m,k);
  if(k*2+1>=m){
    print(n);
    return 0;
  }
  if(df)print(smry);
  int sum=0;
  rep(i,2*k+1) sum+=smry[i];
  if(df)print("sum:",0,2*k,":",sum);
  int ma=sum,lim=m/2-k;
  rep(i,lim){
    sum-=smry[i*2]+smry[i*2+1];
    int c=smry[(i+k)*2+1],d=smry[(i+k+1)*2];
    sum+=c+d;
    if(df) print("-",smry[i*2],smry[i*2+1],"+",c,d,"->",sum);
    ma=max(ma,sum);
  }
  print(ma);
}





Measured memory_bytes: 4096
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

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

    vector<pair<long long, long long>> ab(n, make_pair(0, 0));
    for (int i = 0; i < n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }

    sort(ab.begin(), ab.end());

    long long price = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        if (sum + ab[i].second < m) {
            price += ab[i].first * ab[i].second;
            sum += ab[i].second;
        } else {
            price += ab[i].first * (m - sum);
            break;
        }
    }

    cout << price << endl;
}


Measured memory_bytes: 1792