akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n;
    cin >> n;
    ll odd, even;
    vector<ll> a, b;
    map<ll, ll> oddm, evenm;
    
    rep(i, n){
        if(i%2){
            cin >> odd;
            oddm[odd]++;
            a.push_back(odd);
        }else{
            cin >> even;
            evenm[even]++;
            b.push_back(even);
        }
    }
    //for(auto i : b) cout << i << " "; cout << endl;
    //for(auto i : a) cout << i << " "; cout << endl;
    pair<ll, ll> oddmax, oddmax2, evenmax, evenmax2;
    ll m = 0;
    for(auto i : oddm){
        if(i.second >= m){
            oddmax2 = make_pair(oddmax.first, oddmax.second);
            oddmax = make_pair(i.first, i.second);
            m = i.second;
        }
        if(i.second != oddmax.second && i.second >= oddmax2.second){
            oddmax2 = make_pair(i.first, i.second);
        }
    }
    m = 0;
    for(auto i : evenm){
        if(i.second >= m){
            evenmax2 = make_pair(evenmax.first, evenmax.second);
            evenmax = make_pair(i.first, i.second);
            m = i.second;
        }
        if(i.second != evenmax.second && i.second >= evenmax2.second){
            evenmax2 = make_pair(i.first, i.second);
        }
    }
    ll ans = 0;
    //cout << oddmax.first << " " << oddmax.second << endl;
    //cout << oddmax2.first << " " << oddmax2.second << endl;
    //cout << evenmax.first << " " << evenmax.second << endl;
    //cout << evenmax2.first << " " << evenmax2.second << endl;
    if(oddmax.first == evenmax.first){
        if(oddmax.second > evenmax.second){
            ans += n/2 - oddmax.second;
            ans += n/2 - evenmax2.second;
        }else if(oddmax.second < evenmax.second){
            ans += n/2 - oddmax2.second;
            ans += n/2 - evenmax.second;
        }else{
            if(oddmax2.second > evenmax2.second){
                ans += n/2 - oddmax2.second;
                ans += n/2 - evenmax.second;
            }else{
                ans += n/2 - oddmax.second;
                ans += n/2 - evenmax2.second;
            }
        }
    }else{
        ans = n/2 - oddmax.second;
        ans += n/2 - evenmax.second;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int M = (int) 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= M) return a - M;
  if (a < 0) return a + M;
  return a;
}

int mul(int a, int b) {
  return a * (ll) b % M;
}

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) r = mul(r, a);
    a = mul(a, a);
    b /= 2;
  }
  return r;
}

int dv(int a, int b) {
  return mul(a, pw(b, M - 2));
}

const int N = (int) 2e6 + 7;
int f[N];

int comb(int n, int k) {
  return dv(f[n], mul(f[k], f[n - k]));
}

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

  f[0] = 1;
  for (int i = 1; i < N; i++) f[i] = mul(f[i - 1], i);
  int len, n, w = 0;
  string s;
  cin >> len >> s;
  n = (int) s.size();
  len += n;
  for (int f = n; f <= len; f++) {
    int cur = comb(f - 1, n - 1);
    cur = mul(cur, pw(25, f - n));
    cur = mul(cur, pw(26, len - f));
    w = add(w, cur);
  }
  cout << w << "\n";
  return 0;
}


Measured memory_bytes: 12128
#include <bits/stdc++.h>
#define eb emplace_back
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<60;
template<class T> void chmin(T &a,T b){a=min(a,b);}
template<class T> void chmax(T &a,T b){a=max(a,b);}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;cin>>s;
	if(s=="AAA"||s=="BBB"){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
}


Measured memory_bytes: 764
package main

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

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var x int
  x,_ = strconv.Atoi(NextLine())
  return x
}
func Next2Ints() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}
func Next3Ints() (int,int,int) {
  var x,y,z int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  z,_ = strconv.Atoi(s[2])
  return x,y,z
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  var h,w,d int = Next3Ints()
  var s int = h*w
  var n [][]int = make([][]int,s)
  for i:=0;i<h;i++ {
    var a []int = NextIntArray()
    for j:=0;j<w;j++ {
      n[a[j]-1] = []int{i,j}
    }
  }
  var m [][]int = make([][]int,d)
  for i:=0;i<d;i++ {
    m[i] = []int{0}
    var k int = 0
    for j:=i+d;j<s;j+=d {
      m[i] = append(m[i],m[i][k]+abs(n[j][0]-n[j-d][0])+abs(n[j][1]-n[j-d][1]))
      k++
    }
  }
  var q int = NextInt()
  for k:=0;k<q;k++ {
    var l,r int = Next2Ints()
    var i int = (l-1)%d
    fmt.Println(m[i][(r-1-i)/d]-m[i][(l-1-i)/d])
  }
}
func abs(n int) int {
  if n < 0 { return -n }
  return n
}

Measured memory_bytes: 12800
import math	
N, P = map(int, input().split())
if N == 1:
	print(P)
else:
	ans = 1
	for i in range(2, P):
		if N * math.log(i) > math.log(P):
			break
		if P % (i ** N) == 0:
			ans = i
	print(ans)

Measured memory_bytes: 40300
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
 
//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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 (b < a) { a = b; return true; } return false; }
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d; cin >> a >> b >> c >> d;
	cout << max(0, min(b, d) - max(a, c)) << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a_list = [a for a in map(int, input().split())]
a_list.sort()
a_list.reverse()
alice = 0
bob = 0

for i in range(N):
    if i % 2 == 0:
        alice += a_list[i]
    else:
        bob += a_list[i]
print(alice-bob)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    long long n;
    string s;
    cin>>n;
    cin>>s;
    long long counter = 0;
    for(long long i=0;i<n;i++){
    	char c = s.at(i);
    	if(c=='R'){
    		counter++;
    	}
    	else{
    		counter--;
    	}
    }
    if(counter>0){
    	cout<<"Yes"<<endl;
    }
    else{
    	cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
program abc129b
  implicit none
  integer :: n, t, s1, s2, ans, diff
  integer, allocatable :: w(:)

  read(*,*) n
  allocate(w(n))
  read(*,*) w(:)

  ans = sum(w)
  diff = 0
  
  do t = 1, n-1
    s1 = sum(w(1:t))
    s2 = sum(w(t+1:n))
    diff = abs(s1-s2)
    if (ans>diff) ans = diff
  enddo

  print *, ans

end program abc129b


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

#define inf 2000000000
#define INF 1e18

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

#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define f0r(i, a) for (ll i=0; i<a; i++)
#define FOR(i, a) for (ll i=1; i<=a; i++)
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll a[100005];
char c[10];
map<string,ll>mp;

int main()
{
    fastread;
     ll i,j,k,n,m,x,y,t;
    cin>>n;
    //ll c1=0,c2=0,c3=0,c4=0;
  FOR(i,n)
  {
      string s;
      cin>>s;
      mp[s]++;
  }
   cout<<"AC"<<" "<<"x "<<mp["AC"]<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<mp["WA"]<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<mp["TLE"]<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<mp["RE"]<<endl;
   return 0;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename W>
struct N003 {
   typedef std::vector<long> LI;
   typedef std::vector<W>    LW;
   long n, e;
   LI ss, ds;
   LW ws;
   std::vector<LI> iss;
   N003(long n_, const LI& ss_, const LI& ds_, const LW& ws_)
      : n(n_), e(ss_.size()), ss(ss_), ds(ds_), ws(ws_) {
      iss.resize(n+1);
      for(long i = 0; i < e; ++i) {
         iss[ss[i]].push_back(i);
      }
   }
};

template<typename W>
struct N004 {
   std::vector<long> xs;
   N004(const N003<W>& g, long s, W inf) : xs(g.n+1, inf) {
      std::priority_queue<std::pair<W, long>> q;
      q.push(std::make_pair(0, s));
      while( not q.empty() ) {
         W d2; long i;
         std::tie(d2, i) = q.top(); q.pop();
         W d = -d2;
         if( not ( d < xs[i] ) ) continue;
         xs[i] = d;
         for(long k : g.iss[i]) {
            W nd = d + g.ws[k];
            if( not ( nd < xs[g.ds[k]] ) ) continue;
            q.push(std::make_pair(-nd, g.ds[k]));
         }
      }
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      typedef std::vector<long> LI;
      long v, e, r;
      scan(v, e, r);
      LI ss(e+1), ds(e+1);
      LI ws(e+1);
      for(long i = 0; i < e; ++i) {
         scan(ss[i], ds[i], ws[i]);
      }
      N003<long> g(v, ss, ds, ws);
      N004<long> dijkstra(g, r, (1LL << 60));
      for(long i = 0; i < v; ++i) {
         long res = dijkstra.xs[i];
         if( res == (1LL << 60) ) {
            puts("INF");
         }
         else {
            printf("%ld\n", res);
         }
      }
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}

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

using namespace std;

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

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

    vector<double> dp(n + 1, 0);
    irep(i, n)
    {
        if (i == 0) {
            dp[0] = 1;
        } else {
            double p;
            cin >> p;

            rirep(j, n)
            {
                dp[j] = (1 - p) * dp[j];
                if (j > 0) {
                    dp[j] += p * dp[j - 1];
                }
            }
        }
    }

    double result = 0;
    rirep(i, n)
    {
        if (2 * i > n) {
            result += dp[i];
        }
    }
    cout << fixed << setprecision(11) << result << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
flag1 = True
flag2 = True
s_dic = {}
t_dic = {}
for i, c in enumerate(s):
    if c not in s_dic.keys():
        s_dic[c] = []
    s_dic[c].append(i)
for i in s_dic.keys():
    l = []
    for ind in s_dic[i]:
        l.append(t[ind])
    if len(set(l)) != 1:
        flag1 = False

for i, c in enumerate(t):
    if c not in t_dic.keys():
        t_dic[c] = []
    t_dic[c].append(i)
for i in t_dic.keys():
    l = []
    for ind in t_dic[i]:
        l.append(s[ind])
    if len(set(l)) != 1:
        flag2 = False



if flag1 and flag2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 21292
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,c,k,i,j,h;
    cin>>a>>b>>c;
    k=(a+b);
    i=(b+c);
    j=(a+c);
    h=min(k,min(i,j));
    cout<<h<<endl;
    return 0;


}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<unordered_map>

using namespace std;
const int mod = 1e9+7;

int main(){
	int t,n,maxnum = 0;
	cin >> t; cin >> n;
	vector<int> s;
	s.push_back(n);
	while(--t){
        cin >> n;
		if(n == s.back())continue;
		s.push_back(n);
	}
    vector<int> dp(s.size()+1);
    unordered_map<int,int> save;
    dp[0] = 1;
    for(int i = 0; i < s.size(); ++i){
		if(save.count(s[i]) == 0){
			save[s[i]] = dp[i];
			dp[i+1] = dp[i];
		}
		else{
			dp[i+1] = (dp[i] + save[s[i]])%mod;
			save[s[i]] = (save[s[i]]+ dp[i])%mod; 
		}
    }
    cout << dp[s.size()];
	return 0;
} 

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    int x;
    int out=0;
    set<int> sheet;
    cin >> n;
    while(n--){
        cin >> x;
        if(sheet.find(x)==sheet.end()){
            sheet.insert(x);
            out++;
        }
        else{
            sheet.erase(x);
            out--;
        }
    }
    cout << out;
    return 0;
}

Measured memory_bytes: 4992
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val res = (1..n).map {
        (""+it+" "+readLine()!!).split(" ")
    }

    res.sortedByDescending { it[2].toInt() }.sortedBy { it[1] }.joinToString("\n") { it[0] }
})



Measured memory_bytes: 36036
#include <iostream>
using namespace std;
 
int main(void){
    int r,c,sum,total_sum = 0;
    scanf("%d %d",&r,&c);
    int table[r+1][c+1];
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c+1; j++){
            table[i][j] = 0;
        }
    }
 
    for(int i = 0; i < r; i++){
        sum = 0;
        for(int j = 0; j < c; j++){
            scanf("%d",&table[i][j]);
            sum += table[i][j];
            table[r][j] += table[i][j];
        }
        table[i][c] = sum;
        total_sum += sum;
    }
    table[r][c] = total_sum;
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            printf("%d ",table[i][j]);
        }
        printf("%d\n",table[i][c]);
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1000000007;


int main() {
    int n;
    cin >> n;
    LL ans = 0 ,cntm = 0, cnta = 0, cntr= 0, cntc=0, cnth=0;
    string S ;
    LL C[5] = {0};

    for (int i =0 ;i < n; i++){
        string S;
        cin >> S;
        if ( S[0]== 'M' )  cntm++;
        else if(S[0]== 'A' )  cnta++;
        else if(S[0]== 'R' )  cntr++;
        else if( S[0]== 'C' )  cntc++;
        else if(S[0]== 'H' )  cnth++;
    }

    C[0] = cntm;  C[1] = cnta; C[2] = cntr; C[3] = cntc;  C[4] = cnth;

    for (int i = 0; i < 5; i++){
        for (int j = i + 1; j < 5; j++){
            for (int k = j + 1; k < 5; k++){
                ans += C[i]*C[j]*C[k];
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
ll a;
int dfs(string s, bool is3, bool is5, bool is7){
  if(stoll(s) > a){
    return 0;
  }else{
    if(is3&&is5&&is7){
      // cout << s << endl;
      return 1 + dfs(s + "3", true, is5, is7) + dfs(s + "5", is3, true, is7)+ dfs(s + "7", is3, is5, true);
    }else{
      return dfs(s + "3", true, is5, is7) + dfs(s + "5", is3, true, is7)+ dfs(s + "7", is3, is5, true);
    }

  }
}
int main()
{
  cin >> a;
  cout << dfs("0",false, false, false) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n;
  cin>>n;
  vector<P> v;
  if(n%2==1){
    for(int i=2;i<=n;i++){
      for(int j=1;j<i;j++){
        if(i+j!=n) v.push_back(P(i,j));
      }
    }
  }
  else{
    for(int i=2;i<=n;i++){
      for(int j=1;j<i;j++){
        if(i+j!=n+1) v.push_back(P(i,j));
      }
    }
  }
  cout<<v.size()<<endl;
  for(int i=0;i<v.size();i++) cout<<v[i].first<<" "<<v[i].second<<endl;
}


Measured memory_bytes: 384
var
 x,y,i:longint;
 a:array[0..15] of longint;
begin
 readln(x,y);
 a[1]:=14; 
 for i:=2 to 13 do a[i]:=i;
 if a[x]>a[y] then writeln('Alice')
  else if a[x]<a[y] then writeln('Bob')
   else writeln('Draw');
end.

Measured memory_bytes: 128
# ABC 043: B – バイナリハックイージー / Unhappy Hacking (ABC Edit)
s = input()
editor = ''
for c in s:
    if c == '0':
        editor += '0'
    elif c == '1':
        editor += '1'
    elif c == 'B':
        if len(editor) > 0:
            editor = editor[:-1]
print(editor)

Measured memory_bytes: 3064
from bisect import bisect_left, bisect_right

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

a = sorted(a)
c = sorted(c)
ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])) * (n - bisect_right(c, b[i]))
print(ans)


Measured memory_bytes: 23232
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 1050;
long long a[MAX_N];
int N, K;

const int BIT_SIZE = 50;
long long ac[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> K;

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

    for (int i = 1; i <= N; i++) {
        ac[i] = ac[i-1] + a[i];
    }

    std::vector<std::bitset<BIT_SIZE>> sum_value;

    for (int i = 1; i <= N; i++) {
        for (int j = i; j <= N; j++) {
            sum_value.push_back(std::bitset<BIT_SIZE>(ac[j] - ac[i-1]));
        }
    }

    std::bitset<BIT_SIZE> ret;

    for (int i = BIT_SIZE - 1; 0 <= i; i--) {
        std::vector<std::bitset<BIT_SIZE>> sum_value_cand;
        for (auto sum : sum_value) {
            if (sum.test(i)) {
                sum_value_cand.push_back(sum);
            }
        }
        if (K <= sum_value_cand.size()) {
            ret.set(i, true);
            sum_value = sum_value_cand;
        } else {
            ret.set(i, false);
        }
    }

    std::cout << ret.to_ullong() << std::endl;


    return 0;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double A,B;
    int a,b;
    cin>>A>>B;
    a=A;
    b=B;
    long double K;
    long long k;
    K=(A+B)/2;
    k=(a+b)/2;
    if(K==k){
        cout<<k<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,k;
string s;
vector<int> v;

int main(){
	cin>>n>>k;
	cin>>s;
	v.push_back(0);
	if(s[0]=='0'){
		v.push_back(0);
	}
	for(int i=0;i<n-1;i++){
		if(s[i]!=s[i+1])
			v.push_back(i+1);
	}
	if(s[n-1]=='0'){
		v.push_back(n);
	}
	v.push_back(n);
	int ans=0;
	for(int i=0; i<v.size(); i+=2){
		ans = max(ans,v[min(i+2*k+1,v.size()-1)]-v[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 1e6;
int t[5][5];
ll n,T;
int ans = 1;
bool memo[15][15] = {0};
int main(){
  cin >> n >> T;
  ll t[n];
  for(int i=0 ; i<n ; i++){
    cin >> t[i];
  }
  ll now = 0;
  ll sum = 0;
  for(int i=0 ; i<n ; i++){
    if(now <= t[i]){
      sum += T;
      now = t[i]+T;
    }else{
      sum += t[i] + T - now;
      now = t[i]+T;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define Max 3000

void judge(int);

int num[2][Max];

int main(){
  int i, j;
  
  for(i=0;i<Max;i++){
    scanf("%d%d",&num[0][i],&num[1][i]);
    if(num[0][i]==0 && num[1][i]==0) break;
  }

  for(j=0;j<i;j++){
    judge(j);
    printf("%d %d\n",num[0][j],num[1][j]);
  }
  
  return 0;
}

void judge(int j){
  int tmp;
  if(num[0][j]>num[1][j]){
    tmp=num[0][j];
    num[0][j]=num[1][j];
    num[1][j]=tmp;
  }
}



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

int main()
{
  string a;
  string b; 
  int i = 0;
  int c = 0;
  
  cin >> a;
  cin >> b;
  
  if(a[i] == b[i]){
    c++;
  }
  if(a[i + 1] == b[i + 1]){
    c++;
  }
  if(a[i + 2] == b[i + 2]){
    c++;
  }
  cout<<c<<endl;
}
  
  
  
  

Measured memory_bytes: 256
#include <stdio.h>
int main (){
int k,n,a,b,s[1000]={0};
  scanf ("%d%d",&k,&n);
  for (int i;i<n;i++){
  scanf ("%d",&a);
  scanf ("%d",&b);
  s[a]++;
  s[b]++;
  }
  for (int j=1;j<k+1;j++){
  printf ("%d\n",s[j]);
  }
return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int R = sc.nextInt();
			final int G = sc.nextInt();
			final int B = sc.nextInt();
			final int N = sc.nextInt();

			long answer = 0;
			for(int r = 0; r * R <= N; r++) {
				for(int g = 0; r * R + g * G <= N; g++) {
					final int rest = N - (r * R + g * G);
					
					if(rest % B != 0) { continue; }
					
					answer += 1;
					
					//final int b = rest % B;
					//System.out.println(r + " " + g + " " + b);
				}
				
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21460
#include <cstdio>

int H, W, K;
char A[810][810];
int vis[810][810];
int q[810*810*5];
int front, tail;
int si, sj;
int step[4][2] = {{-1,0}, {1,0}, {0,-1}, {0,1}};
int res;

void EnQueue(int x)
{
	q[tail] = x;
	tail ++;
}

int DeQueue()
{
	int r = q[front];
	front ++;
	return r;
}

void solve()
{
	int i, j;
	for(i=0; i<H; i++){
		for(j=0; j<W; j++)
			vis[i][j] = 0;
	}
	for(i=0; i<H; i++){
		for(j=0; j<W; j++){
			if(A[i][j] == 'S'){
				si = i, sj = j;
				break;
			}
		}
	}
	front = tail = 0;
	EnQueue(si);
	EnQueue(sj);
	EnQueue(0);
	vis[si][sj] = 1;
	int ui, uj, ul;
	int vi, vj, vl;
	int ok = 0;
	while(front != tail){
		ui = DeQueue();
		uj = DeQueue();
		ul = DeQueue();
		if(ui==0 || ui==H-1 || uj==0 || uj == W-1){
			ok = 1;
			break;
		}
		if(ul == K)
			break;
		for(i=0; i<4; i++){
			vi = ui + step[i][0];
			vj = uj + step[i][1];
			vl = ul + 1;
			if(A[vi][vj] == '.' && vis[vi][vj] == 0){
				EnQueue(vi);
				EnQueue(vj);
				EnQueue(vl);
				vis[vi][vj] = 1;
			}
		}
	}
	if(ok == 1){
		printf("%d\n", 1);
		return ;
	}
	front = tail = 0;
	for(i=0; i<H; i++){
		for(j=0; j<W; j++){
			if(vis[i][j] == 1){
				EnQueue(i);
				EnQueue(j);
				EnQueue(0);
			}
		}
	}
	while(front != tail){
		ui = DeQueue();
		uj = DeQueue();
		ul = DeQueue();
		if(ui==0 || ui==H-1 || uj==0 || uj == W-1){
			ok = 1;
			break;
		}
		for(i=0; i<4; i++){
			vi = ui + step[i][0];
			vj = uj + step[i][1];
			vl = ul + 1;
			if(vis[vi][vj] == 0){
				EnQueue(vi);
				EnQueue(vj);
				EnQueue(vl);
				vis[vi][vj] = 1;
			}
		}
	}
	res = (ul-1)/K + 1 + 1;
	printf("%d\n", res);
}

int main()
{
	int i;
	scanf("%d%d%d", &H, &W, &K);
	for(i=0; i<H; i++)
		scanf("%s", &A[i]);
	solve();
	return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1,0)
char a[110][110];
int main()
{
   int m,n;
   cin>>m>>n;
   for(int i=1;i<=m;i++)
   {
       for(int j=1;j<=n;j++)
       {
           cin>>a[i][j];
       }
   }

   for(int i=1;i<=m;i++)
   {
       for(int j=1;j<=n;j++)
       {
            printf("%c",a[i][j]);
       }

       printf("\n");

       for(int j=1;j<=n;j++)
       {
           printf("%c",a[i][j]);
       }

       printf("\n");

   }
   return 0;
   // 2 2 4 1 3
   //
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
// const ll INF = LONG_LONG_MAX;
const int INF = INT_MAX;
// const ll MOD = 1000000007; // 998244353;

// #include <atcoder/all>
// using namespace atcoder;

// iの倍数は1~Nに[N/i]個ある->合計を求められる
// i=1~Nについて上記を加算する

int main() {
	int N; cin >> N;
	ll ans = 0;
	rep2(i, 1, N + 1) {
		ll m = N / i; // iの倍数の個数
		ll temp = (i + m * i) * m / 2;
		ans += temp;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3604
import copy
n = int(input())
# cur = n
# ans = 0
# while cur >= 6:
#     div6 = 0
#     a = copy.deepcopy(cur)
#     while a != 0:
#         a //= 6
#         div6 += 1
#     div9 = 0
#     b = copy.deepcopy(cur)
#     while b != 0:
#         b //= 9
#         div9 += 1
#     div6 -= 1
#     div9 -= 1
#     if 6**div6 > 9**div9:
#         cur -= 6**div6
#     else:
#         cur -= 9**div9
#     ans += 1
#     print(cur)
# print(ans + cur)

dp = [0]*(n+1)
moto = []
a = 1
while a <= n:
    a *= 6
    if a <= n:
        moto.append(a)
a = 1
while a <= n:
    a *= 9
    if a <= n:
        moto.append(a)

for i in range(1, n+1):
    tar = [dp[i-1]+1]
    for j in moto:
        if i >= j:
            tar.append(dp[i-j]+1)
    dp[i] = min(tar)
print(dp[n])






Measured memory_bytes: 41452
#include<stdio.h>
int main(void)
{
    int a,b,c,d,i,j,n,e,temp;
    while(scanf("%d %d",&a,&b)!=EOF){
    for(i=0;i<1;i++){
        for(j=i+1;j<2;j++){
        if(a<b){
            temp=a;
            a=b;
            b=temp;
            }
        }
    }
    e=a;
    d=b;
    while(1){
        n=e%d;
       if(n==0)break;
        e=d;
        d=n;
    }
    printf("%d",d);
    c=a/d*b;
    printf(" %d\n",c);
    }
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 3e3 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "1";

int m, n;
int a[siz][siz];
int f[siz][siz][4];

int dp(int x, int y, int cnt) {
    if (x == m && y == n) {
        if (cnt < 3) {
            return a[x][y];
        }
        return 0;
    }

    int &res = f[x][y][cnt];
    if (res != -1) {
        return res;
    }

    res = 0;
    if (x < m) {
        if (cnt < 3) {
            res = max(res, dp(x + 1, y, 0) + a[x][y]);
        }
        else {
            res = max(res, dp(x + 1, y, 0));
        }
    }

    if (y < n) {
        res = max(res, dp(x, y + 1, cnt));
        if (cnt < 3) {
            res = max(res, dp(x, y + 1, cnt + 1) + a[x][y]);
        }
    }

    return res;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int k;
    cin >> m >> n >> k;
    while (k--) {
        int x, y, v;
        cin >> x >> y >> v;

        a[x][y] = v;
    }

    memset(f, -1, sizeof(f));
    cout << dp(1, 1, 0) << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 357680
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){

	int N,K;
	cin>>N>>K;
	
	vector<int> l(N);
	for(int i=0;i<N;i++)cin>>l[i];
	
	sort(l.begin(),l.end(),greater<int>());
	
	int ans = 0;
	
	for(int i=0;i<K;i++){
		ans += l[i];
	}
	
	cout<<ans<<endl;
	
    return 0;
}



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

typedef pair<int, int> pii;

const int mod = 1e9 + 7;
const int MN = 200010;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}
int fact[MN], invf[MN];

int N, X, Y;
pii P[MN];
vector<int> V[MN];

int main() {
    fact[0] = 1;
    for(int i = 1; i < MN; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < MN; i++) {
        invf[i] = inv(fact[i]);
    }

    scanf("%d %d %d", &N, &X, &Y);

    int mn1 = 1e9 + 2, p1 = -1;
    int mn2 = 1e9 + 2, p2 = -1;
    for(int i = 0; i < N; i++) {
        int c, w; scanf("%d %d", &c, &w);
        c--;

        P[i] = {c, w};
        V[c].push_back(w);

        if(mn1 > w) {
            if(c != p1) mn2 = mn1, p2 = p1;
            mn1 = w, p1 = c;
        }
        else if(mn2 > w) {
            if(c != p1) mn2 = w, p2 = c;
        }
    }
    for(int i = 0; i < N; i++) {
        sort(V[i].begin(), V[i].end());
    }

    vector<int> C;
    int tot = 0;
    for(int i = 0; i < N; i++) {
        if(V[i].size() == 0) continue;

        int mn = i == p1? mn2 : mn1;
        if(mn + V[i][0] > Y) {
            continue;
        }

        int cnt = 1;
        for(int j = 1; j < V[i].size(); j++) {
            if(V[i][j] + mn > Y && V[i][j] + V[i][0] > X) break;
            cnt++;
        }
        tot += cnt;
        C.push_back(cnt);
    }

    int ans = fact[tot];
    for(int i = 0; i < C.size(); i++) ans = 1LL * ans * invf[ C[i] ] % mod;
    printf("%d", ans);
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n),c(n,0);
	for(auto&i:a){
		cin>>i;
		--i;
		++c.at(i);
	}
	int64_t ans=0,tmp,tmp2;
	for(auto&i:c)ans+=(int64_t)i*(i-1)/2;
	for(auto&i:a){
		tmp=c.at(i);
		tmp=tmp*(tmp-1)/2;
		tmp2=c.at(i)-1;
		tmp2=tmp2*(tmp2-1)/2;
		cout<<ans-tmp+tmp2<<"\n"s;
	}
}

Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <complex>

using namespace std;
typedef complex<double> xy_t;
double x[3], y[3];
char c;


double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }

int main(void){
	while(cin >> x[0] >> c >> y[0] >> c >> x[1] >> c >> y[1] >> c >> x[2] >> c >> y[2]){
		xy_t P1(x[0], y[0]), P2(x[1], y[1]), Q(x[2], y[2]);
		xy_t S = projection(Q - P1, P2 - P1) + P1;
		xy_t T = S + S - Q;
		printf("%.6f %.6f\n", real(T), imag(T));
	}
	
    return 0;
}

Measured memory_bytes: 1264
n=int(input())
arr=[]
for i in range(n):
    arr.append(int(input()))
maxp=[]
max_=0
min_=20000000000
rooped=0
for j in arr:
    if max_<j:
        max_=j
        
        maxp.append(max_-min_)
    if min_>j:
        min_=j
        max_=0
maxp.sort()
maxp.reverse()
    
print(maxp[0])
    


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

struct BinaryIndexedTree {
private:
    int n,b;
    vector<int> bit;
public:
    BinaryIndexedTree(int n_) {
        n = n_+10;
        b = 1;
        while (b < n) b <<= 1;
        b >>= 1;
        bit = vector<int>(n,0);
    }

    void add(int a,int w) {
        a++;
        for (int x = a;x < n;x += x&-x) bit[x] += w;
    }

    int sum(int a) {
        a++;
        int ret = 0;
        for (int x = a;x > 0;x -= x&-x) ret += bit[x];
        return ret;
    }

    void update(int a,int w) {
        // a++;
        int v = w-sum(a)+sum(a-1);
        add(a,v);
    }

    int lower_bound(int w) {
        if (w <= 0) return 0;
        int x = 0;
        for (int k = b;k > 0;k /= 2) {
            if (x+k < n && bit[x+k] < w) {
                w -= bit[x+k];
                x += k;
            }
        }
        return x;
    }
};

struct query {
    int l,r,i;
    bool operator<(const query& a) const {
        return r < a.r;
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    vector<int> c(n);
    BinaryIndexedTree bit(n);
    vector<query> a(q);
    vector<int> ans(q),b(n,-1);
    for (int i = 0;i < n;++i) cin >> c[i],c[i]--;
    for (int i = 0;i < q;++i) {
        cin >> a[i].l >> a[i].r;
        a[i].i = i;
        a[i].l--;
        a[i].r--;
    }
    sort(a.begin(),a.end());
    int j = 0;
    for (int i = 0;i < n;++i) {
        if (b[c[i]] >= 0) bit.add(b[c[i]],-1);
        bit.add(i,1);
        b[c[i]] = i;
        while (j < q && a[j].r <= i) {
            ans[a[j].i] = bit.sum(a[j].r)-(a[j].l ? bit.sum(a[j].l-1) : 0);
            j++;
        }
    }
    for (int i = 0;i < q;++i) cout << ans[i] << newl;
}

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

using namespace std;

string s, t;
int dp[3010][3010];
int path[3010][3010];

int go(int i, int j) {
    if(i < 0 || j < 0) return 0;

    if(dp[i][j] != -1) return dp[i][j];

    if(s[i] == t[j]) {
        path[i][j] = 0;
        return dp[i][j] = 1 + go(i - 1, j - 1);
    }
    else {
        if(go(i - 1, j) > go(i, j - 1)) {
            path[i][j] = 1;
        }
        else {
            path[i][j] = 2;
        }
        return dp[i][j] = max(go(i - 1, j), go(i, j - 1));
    }
}

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

    cin >> s >> t;

    memset(dp, -1, sizeof dp);

    int i = s.size() - 1, j = t.size() - 1;
    go(i, j);

    string ans = "";

    while(i >= 0 && j >= 0) {
        if(path[i][j] == 0) {
            ans += s[i];
            i--, j--;
        }
        else if(path[i][j] == 1) i--;
        else j--;
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;

}

/**
 * Knapsack 2
 * dp[i][j] = lcs of s[0:i] and t[0:j]
 */

Measured memory_bytes: 71552
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextLong();
        long d=sc.nextLong();
        
        System.out.println(Math.max(Math.max(a*c, a*d), Math.max(b*c, b*d)));
        
        
    }
}

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

int main() {
	int N,a,b,sum;
	cin >>N;
	int P[10],Q[10];

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

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

	for(int i=1;i<N;i++){
		sum=1;
		for(int j=1;j<=N-i;j++){
			sum*=j;
		}
		a=a+(P[i]-1)*sum;
		for(int j=i+1;j<=N;j++){
			if(P[i]<P[j]){
				P[j]--;
			}

		}
	}

	for(int i=1;i<N;i++){
		sum=1;
		for(int j=1;j<=N-i;j++){
			sum*=j;
		}
		b=b+(Q[i]-1)*sum;
		for(int j=i+1;j<=N;j++){
			if(Q[i]<Q[j]){
				Q[j]--;
			}

		}
	}

	cout <<abs(a-b)<<endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int main(){
  int n;
  string str[100005];
  
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str[i];
    sort(str[i].begin(),str[i].end());
  }
  
  sort(str,str+n);
  long long ans=0;
  int index=0;
  long long num;
  for(int i=1;i<n;i++){
    if(str[i]!=str[index]){
      num=i-index;
      ans+=num*(num-1)/2;
      index=i;
    }
  }
  num=n-index;
  ans+=num*(num-1)/2;
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 7296
A, B, C, K = map(int, input().split())

def f():
    if K <= A:
        return K
    elif K <= A + B:
        return A
    else:
        #1が書かれたカードの枚数 - -1が書かれたカードの枚数（）
        return A - (K - A - B)

print(f())


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

const ll INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100005;
ll dp[MAX_N][MAX_V];

int main(void){
    int N,W;
    cin >> N >> W;
    vector<int> weight(MAX_N),value(MAX_N);
    for(int i=0;i<N;i++) cin >> weight[i] >> value[i];

    for(int i=0;i<MAX_N;i++) for(int j=0;j<MAX_V;j++) dp[i][j] = INF;

    for(int j=0;j<MAX_V;j++) dp[0][0] = 0;

    for(int i=0;i<N;i++){
        for(int j=0;j<MAX_V;j++){
            if(j-value[i]>=0) dp[i+1][j] = min(dp[i+1][j],dp[i][j-value[i]]+weight[i]);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans = 0;
    for(int i=0;i<MAX_V;i++){
        if(dp[N][i]<=W) ans = i;
    }
    cout << ans << endl;

}


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

int N, Q;
long long T;
long long A[100010];
bool dir[100010];
long long st[100010];

long long query(int i) {
  if (st[i] != -1) return st[i];
  long long ans;
  // ->
  if (dir[i]) {
    if (i == N-1)       ans = 0;
    else if (!dir[i+1]) ans = (A[i+1] - A[i]) / 2;
    else {
      long long t = query(i+1);
      if (t == 0) ans = 0;
      else        ans = (A[i+1] - A[i]) + t;
    }
  }
  // <-
  else {
    if (i == 0)        ans = 0;
    else if (dir[i-1]) ans = (A[i] - A[i-1]) / 2;
    else {
      long long t = query(i-1);
      if (t == 0) ans = 0;
      else        ans = (A[i] - A[i-1]) + t;
    }
  }
  return st[i] = ans;
}

int main() {
  cin >> N >> T >> Q;
  for (int i=0; i<N; i++) {
    int d;
    cin >> A[i] >> d;
    if (d == 1) dir[i] = true;
    st[i] = -1;
  }

  for (int i=0; i<Q; i++) {
    int x;
    cin >> x;
    long long t = query(x-1);
    cout << A[x-1] + (t == 0 ? T : min(t, T))*(dir[x-1]?1L:-1L) << "\n";
  }
  return 0;
}

Measured memory_bytes: 6256
N = int(input())
flag = [-1]*N
ans = []
lst = list(map(int, input().split()))
for i in range(N-1, -1, -1):
    cnt = 0
    for j in range(i, N, i+1):
        if j == i:
            continue
        else:
            if flag[j] == 1:
                cnt += 1
    if (lst[i]+cnt)%2 == 0:
        flag[i] = 0
    else:
        flag[i] = 1
        ans.append(i+1)
num = len(ans)
if num == 0:
    print(0)
else:
    print(num)
    print(*ans)

Measured memory_bytes: 14100
import sys
sys.setrecursionlimit(10**6)
N = int(input())
g = [[] for _ in range(N)]
ans = [0 for _ in range(N-1)]

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(g[v])):
        u = g[v][i][0]
        ei = g[v][i][1]
        if u == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k
        k += 1
        dfs(u, ans[ei], v)


for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append([b, i])
    g[b].append([a, i])
dfs(0)
mx = 0
for i in range(N):
    mx = max(mx, len(g[i]))
print(mx)
for i in range(N-1):
    print(ans[i])

Measured memory_bytes: 88820
N=int(input())
S=input()

alpha=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']*2
anslist=[alpha[ord(i)-65+N] for i in S]
print(''.join(anslist))


Measured memory_bytes: 3188
#include <stdio.h>
int main(){
  int a=100000,b=0;
  int i,j;
  scanf("%d",&i);
  for(j=0;j<i;j++){
    a=(a*0.05)+a;
    if(a%1000 != 0){
      a=a/1000;
      a+=1;
      a=a*1000;
    }
  }
  printf("%d\n",a);
  return (0);
}

Measured memory_bytes: 592
using System;
using System.Collections.Generic;

class Program
{
 static void Main( string[] args )
 {
   int[] num = new int[3];
   int loopNum = 0;
   int cnt =0;
   var intList = new List<int>();
   
   var str = Console.ReadLine().Split(' ');
   
   for( cnt =0; cnt < 3; cnt++ )
   {
     num[cnt] = int.Parse(str[cnt]);
   }
  
   if( num[0] > num[1] )
   {
    loopNum = num[1];
   }
   else
   {
     loopNum = num[0];
   }
   
   for( cnt =1; cnt <= loopNum; cnt++ )
   {
     if( ( ( num[0] % cnt ) == 0 ) && ( ( num[1] % cnt ) == 0 ) )
     {
       intList.Add(cnt);
     }
   }
   
   intList.Sort((a, b) => b - a);
   
   Console.WriteLine(intList[(num[2]-1)]);
 }
}

Measured memory_bytes: 11220
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = 1001001001001001

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	a := make([]int, M)
	c := make([]int, M)
	for i := 0; i < M; i++ {
		a[i] = getInt()
		b := getInt()
		for j := 0; j < b; j++ {
			n := getInt() - 1
			c[i] |= (1 << n)
		}
	}

	dp := make([][]int, M+1)
	for i := 0; i <= M; i++ {
		dp[i] = make([]int, 1<<N)
		for j := 0; j < 1<<N; j++ {
			dp[i][j] = inf
		}
		dp[i][0] = 0
	}

	for i := 1; i <= M; i++ {
		for j := 0; j < 1<<N; j++ {
			dp[0][j|c[i-1]] = min(dp[0][j|c[i-1]], dp[0][j]+a[i-1])
		}
	}

	ans := dp[0][1<<N-1]
	if ans == inf {
		out(-1)
		return
	}
	out(ans)
}


Measured memory_bytes: 35224
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

string s;
int k;
string cand[6];

void check(int i,string s){
    if (i==5) return;
    REP(i,6) if (s == cand[i]) return;
    if (cand[i] < s){
        check(i+1,s);
    } else {
        string tmp = cand[i];
        cand[i] = s;
        check(i+1,tmp);
    }
}

int main(){
    REP(i,6) cand[i] = "zzzzzzzzzzzzzzzzzzzzzzz";
    cin >> s;
    cin >> k;

    int ln = s.size();
    REP(i,ln){
        REP(j,5){
            if (i < j) break;
            string substring = s.substr(i-j,j+1);
            check(0,substring);
        }
    }

    cout << cand[k-1] << endl;
}


Measured memory_bytes: 256