akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

int main(){
          vector<int> vec(3);
          int n=3;
          while(n--){
                    int input;
                    cin >> input;
                    vec.push_back(input);
          }
          int k;
          cin >> k;
          int keep=*max_element(vec.begin(),vec.end());
          int ans=keep;
          REP(i,k){
                    ans=ans*2;
          }
          cout << accumulate(vec.begin(),vec.end(),0)+ans-keep<< endl;

          return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 5000
#define MAXH 4
#define MAXM 4
#define INF 1LL << 62
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;

int main(){
	fast_io();
	int n;
	cin >> n;
	vector<pll> v(n),w(n);
	ll x,y;
	cu(i,0,n){
		cin >> x >> y;
		if(x > y)swap(x,y);
		v[i].F = x, v[i].S = y;
	}
	sort(all(v));
	cu(i,0,n){
		w[i] = {v[i].S, i};
	}
	sort(all(w));
	int wh = n - 1;

	ll a = INF, b = v[n-1].F;
	x = w[0].F;
	ll mn = INF;
	ll ans = (b - v[0].F) * (w[wh].F - x);
	cu(i,0,n-1){
		if(v[i].F > mn)break;
		gmin(mn, v[i].S);
		gmax(b, v[i].S);
		gmin(a, v[i].S);
		while(w[wh].S <= i)--wh;
		gmin(ans, (b - min(v[i+1].F, a)) * (w[wh].F - v[0].F));
	}
	cout << ans << '\n';
}


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

int k[10];
int s[10];
int p[10];

int xxor(int n){
    int res=0;
    while(n>=1){
        if(n&1==1) res^=1;
        n/=2;
        //cout << n << endl;
    }
    return res;
}

int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> k[i];
        for(int j=0;j<k[i];j++){
            int a;
            cin >> a;
            s[i]+=(1<<(a-1));
        }
    }
    for(int i=0;i<m;i++){
        cin >> p[i];
    }
    int ans=0;
    int mm=1<<n;
    for(int i=0;i<mm;i++){
        bool flag=true;
        for(int j=0;j<m;j++){
            if(xxor(s[j]&i)!=p[j]){
                flag=false;
            }
            //cout << (s[j]&i) << endl;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import collections, heapq, sys

n = int(sys.stdin.readline().rstrip())
g = collections.defaultdict(list)
visited = set()
deg = collections.defaultdict(int)
for i in range(n-1):
    a, b = map(int, sys.stdin.readline().rstrip().split(' '))
    deg[a] += 1
    deg[b] += 1
    g[a].append(b)
    g[b].append(a)

pq = []
for i in range(1, n+1):
    heapq.heappush(pq, [deg[i], i])
wts = map(int, sys.stdin.readline().rstrip().split(' '))
wts.sort(reverse=True)
    
vToWt = [-1 for _ in range(n+1)]
sm = 0
while len(pq):
    _, v = heapq.heappop(pq)
    
    if vToWt[v] != -1:
        continue
    vToWt[v] = wts.pop()
    for nei in g[v]:
        if vToWt[nei] != -1:
            continue
        sm += vToWt[v]
        deg[nei] -= 1
        heapq.heappush(pq, [deg[nei], nei])

print(sm)
print(' '.join(map(str, [x for x in vToWt[1:]])))




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

map<string, int> Index;
long long timeleft[52];

int N;

int main() {
    string S;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> S >> timeleft[i];
        Index[S] = i;
    }
    for(int i = N-2; i >= 0; i--) {
        timeleft[i] += timeleft[i+1];
    }
    cin >> S;
    cout << timeleft[Index[S] + 1];
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Sol();
        }

        public void Sol()
        {
            int x = int.Parse(Console.ReadLine());
            if (x < 1200)
            {
                Console.WriteLine("ABC");
            }
            else
            {
                Console.WriteLine("ARC");
            }
        }
    }
}

Measured memory_bytes: 11092
import math
n=int(input())
ans=0
s=set()
s.add(1)
s.add(n)
s.add(n-1)
for i in range(2,math.ceil(math.sqrt(n))+1):
  nn=n
  key=0
  while nn % i ==0:
    nn=nn//i
    key=1
  if nn % i ==1:
    s.add(i)
    if key==0:
      s.add((nn-1)//i)
s.remove(1)
print(len(s))

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
#define rep(i,n) for(int i=0;i<(n);++i)

//example rep(i,n) cin >> h[i];

int main (){

double a,b,x;

  cin>>a>>b>>x;

double s= x/a;

double rad;
if(s>=a*b/2){
    double h= (a*b-s)*2/a;
    rad=atan2(h,a);
}
else{
    double w=s*2/b;
    rad=atan2(b,w);

}
double PI =acos(-1);//パイ
double deg =rad/(2*PI)*360;
printf("%.10f\n",deg);



  //sort(vec.begin(),vec.end());
  //reverse(vec.begin(),vec.end());

  
 return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <limits.h>
using namespace std;
 
void north(int* faces) {
    int tmp[7];
 
    //top(1) to back(5)
    tmp[5] = faces[1];
 
    //front(2) to top(1)
    tmp[1] = faces[2];
 
    //right(3) to right(3)
    tmp[3] = faces[3];
 
    //left(4) to left(4)
    tmp[4] = faces[4];
 
    //back(5) to bottom(6)
    tmp[6] = faces[5];
 
    //bottom(6) to front(2)
    tmp[2] = faces[6];
 
    memcpy(faces, tmp, sizeof(tmp));
 
}
void west(int* faces) {
    int tmp[7];
 
    //top(1) to left(4)
    tmp[4] = faces[1];
 
    //front(2) to front(2)
    tmp[2] = faces[2];
 
    //right(3) to top(1)
    tmp[1] = faces[3];
 
    //left(4) to bottom(6)
    tmp[6] = faces[4];
 
    //back(5) to back(5)
    tmp[5] = faces[5];
 
    //bottom(6) to right(3)
    tmp[3] = faces[6];
 
    memcpy(faces, tmp, sizeof(tmp));
 
}
bool check(int* faces, int* taget, int frontNum) {
     
    int tmp[7];
    for (int i = 1; i < 7; i++)
    {
        tmp[i] = faces[i];
    }
     
    tmp[frontNum] = INT_MAX;
     
 
    if (frontNum == 3 || frontNum == 4) west(tmp);
 
    while (true)
    {
        north(tmp);
        if (tmp[2] == INT_MAX)break;
    }
    tmp[2] = faces[frontNum];
 
 
 
    for (int i = 1; i < 7; i++)
    {
        if (tmp[i] != taget[i]) break;
        if (i == 6) return true;
    }
 
    for (int i = 0; i < 3; i++)
    {
        west(tmp);
        for (int j = 1; j < 7; j++)
        {
            if (tmp[j] != taget[j]) break;
            if (j == 6) return true;
        }
    }
 
 
    return false;
}
 
bool dice(int *faces, int *taget, int front) {
 
    for (int i = 1; i < 7; i++)
    {
        if (faces[i] == front) {
            if (check(faces, taget, i)) return true;
        }
    }
 
 
 
    return false;
}
 
 
int main() {
    int faces_1[7],faces_2[7];
 
    for (int i = 1; i < 7; i++) cin >> faces_1[i];
 
    for (int i = 1; i < 7; i++) cin >> faces_2[i];
     
    if (dice(faces_2, faces_1, faces_1[2])) {
        cout << "Yes" << endl;
        return 0;
    }
 
    cout << "No" << endl;
     
    return 0;
}


Measured memory_bytes: 3076
chomp($_ = <STDIN>);
my @tmp = split;
my ($a, $b, $c) = sort {$b <=> $a} @tmp;


my $ans = 0;

if ($b % 2 == $c % 2) {
    $ans += (($b - $c) / 2);
    $ans += ($a - $b);
} else {
    $ans += 1; # $a と $c を増やす
    $ans += (($b - $c - 1) / 2);
    $ans += ($a + 1 - $b);
}

print "$ans\n";


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

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

    if(s[0] >= 'a' && s[0] <= 'z' ){
        cout << "a" << endl;
    } else if(s[0] >= 'A' && s[0] <= 'Z'){
        cout << "A" << endl;
    }
}

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

int main()
{
  long long n, i, wa = 0, keta = 0;
  string str;
  cin >> n;

  i = n;

  while (i)
  {
    keta = i % 10;
    wa = wa + keta;
    i /= 10;
  }

  if (n % wa == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
     long long int a,b,c,d,x,y,z;
     scanf("%lld %lld",&a,&b);
     x=a+b;
     y=a-b;
     z=a*b;
     if(x>=y&&x>=z)
     printf("%lld\n",x);
     else if(x<=y&&y>=z)
     printf("%lld\n",y);
     else  if(x<=z&&y<=z)
     printf("%lld\n",z);
    return 0;
}


Measured memory_bytes: 1692
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		  try(Scanner sc = new Scanner(System.in)) {
			  String str=sc.nextLine();
			  String ans=str.replace("apple", "wwwp");
			  ans=ans.replace("peach", "wwwa");
			  ans=ans.replace("wwwp", "peach");
			  ans=ans.replace("wwwa", "apple");
			  System.out.println(ans);
		  }
	}
}


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

#define mod 1000000007
#define LOCAL 0
#define pb push_back
#define ll long long

ll po(ll a,ll b){
	ll x = 1,y=a;
	while(b>0){
		if(b%2){
			x = x*y;
			x %= mod;
		}
		y=y*y;
		y%=mod;
		b/=2;
	}
	return x;
}

int main(){
	if(LOCAL){
    	freopen("C:/Users/gold/Desktop/sublime IO/input.txt","r",stdin);
    	freopen("C:/Users/gold/Desktop/sublime IO/output.txt","w",stdout);
	}
	int T = 1;
	//scanf("%d",&T);
	while(T--){
		long long a,b,c,d,n;
		scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&n);
		long long ans = min(min(a*4ll,b*2ll),c);
		long long x = n / 2ll * d;
		if(n%2){
			x += ans;
		}
		ans = min(ans*n,x);
		printf("%lld\n",ans);
	}
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
 
ll mpow(ll x,ll n);
int main(void);

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n>=1){
        if(n%2 == 0){
            x = x * x %MOD;
            n = n/2;
        }else{
            ans = ans * x %MOD;
            n = n-1;
        }
    }
    
    return ans;
}
 
 
int main(void){
	ll N,K;
    cin >> N >> K;
    
    ll ans1 = N-K+1;
    ll ans2 = 1;
    ll ans = ans1;
    cout << ans1 << endl;
    for(ll i = 1; i<K; i++){
        /* ans1 = ans1 * (N-K+1-i)%MOD * (i+1)^(MOD-2);
        ans2 = ans2 * (K-i)%MOD * i^(MOD-2);
        ans1 = ans1%MOD;
        ans2 = ans2%MOD;
        ans = ans1*ans2; */
        ans = ans * (N-K+1-i) % MOD * (K-i) % MOD * mpow(i, MOD-2) %MOD * mpow(i+1, MOD-2) % MOD; 
        cout << ans << endl;
    }
    

    

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; ++i) {
        cin >> d.at(i);
    }
    //小さい順にソート
    sort(d.begin(),d.end());

    //境界値のminとmaxを取得
    int divmin = d.at(N/2-1);
    int divmax = d.at(N/2);

    //境界の間にいくつ整数があるかを数える
    int count = 0;
    for (int i = divmin + 1; i <= divmax; ++i) {
        count++;
    }

    cout << count;

    return 0;
}

Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int a, b, c;
    scan(a, b, c);
    writeln(a + b >= c ? "Yes" : "No");
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())
a = [0] * n
for i in range(1, n):
    for j in range(i+1, n+1):
        k = min(j - i, abs(x - i) + abs(y - j) + 1)
        a[k] += 1
for i in range(1,n):
    print(a[i])

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

typedef vector<int> vi;
int main() {
	int N, M;
	cin >> N;
	vi vec1(N);
	rep(i, N)
		cin >> vec1.at(i);
	cin >> M;
	vi vec2(M);
	rep(i, M)
		cin >> vec2.at(i);
	vi vec3(N + M);
	vi::iterator	it;
	it = set_symmetric_difference(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), vec3.begin());
	vec3.resize(it - vec3.begin());
	for (it = vec3.begin(); it != vec3.end(); it++)
		cout << *it << endl;
}



Measured memory_bytes: 5904
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
map<ll,string>mp;
int main()
{
    ll n,m,s=0;
    cin>>n>>m;
    ll a[m+5];

    for(ll i=0;i<m;i++){
        cin>>a[i];
        s+=a[i];
    }
    if(s>n){
        cout<<-1<<endl;
    }
    else{
        cout<<n-s<<endl;
    }

}


Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a, &b, &c, &d, &e, &k)
	if (e - a) <= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ( (A + B) < (C + D) ) {
    cout << "Right" << endl;
  }
  else if ( (A + B) == (C + D) ) {
    cout << "Balanced" << endl;
  }
  else { 
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

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

    unsigned long long ans = 0;
    for(int i=0;i<n;i++)ans += 2 * min(abs(0-x[i]),abs(k-x[i]));

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();
	
		String[] strAry = str.split(" ");

		int ar[] = new int[5];

		for(int i=0;i<5;i++){
			ar[i] = Integer.parseInt(strAry[i]);
		}

		int W = ar[0];
		int H = ar[1];
		int x = ar[2];
		int y = ar[3];
		int r = ar[4];

		if( x >= r && x <= W-r){
				if( y >= r && y <= H-r){
					System.out.println("Yes");
				}else{
					System.out.println("No");
				}
		}else{
				System.out.println("No");
		}

	}
}

Measured memory_bytes: 24428
#include <iostream>
#include <algorithm>

using namespace std;

const int MOD = 998244353;
long long K,N,A,B,ans;
int fact[300005];
int ifact[300005];

int lgpow(int b,int e){
    int p = 1;
    while(e){
        if(e & 1){
            p = 1LL * p * b % MOD;
        }
        b = 1LL * b * b % MOD;
        e >>= 1;
    }
    return p;
}

int C(int N,int K){
    return 1LL * (1LL * fact[N] * ifact[K] % MOD) * ifact[N - K] % MOD;
}

int main(){
    cin >> N >> A >> B >> K;

    fact[0] = 1;

    for(int i = 1;i <= N;i++){
        fact[i] = 1LL * i * fact[i - 1] % MOD;
    }

    ifact[N] = lgpow(fact[N],MOD - 2);

    for(int i = N - 1;i >= 0;i--){
        ifact[i] = 1LL * ifact[i + 1] * (i + 1) % MOD;
    }

    for(long long numA = 0;numA <= N;numA++){
        long long scoreA = A * numA;
        long long scoreB = K - scoreA;
        if(scoreB >= 0 && scoreB % B == 0 &&scoreB <= N * B){
            long long numB = scoreB / B;
            ans = (ans + 1LL * C(N,numA) * C(N,numB)) % MOD;
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 2560
d = int(input())
c = list(map(int,input().split()))
s_di=[list(map(int,input().split())) for i in range(d)]
last=[0 for i in range(26)]

#donyoku
total_manzoku=0
for i in range(1,d+1):
    tmp_max=-10**10
    tmp_choice=-1
    fuman=sum([(i-last[k])*c[k] for k in range(26)])
    for j in range(26):
        tmp=-fuman+(i-last[j])*c[j]+s_di[i-1][j]
        if tmp>tmp_max:
            tmp_max=tmp
            tmp_choice=j
    print(tmp_choice+1)
    total_manzoku+=max(tmp_max,0)
    last[tmp_choice]=i

#print(total_manzoku)


Measured memory_bytes: 68776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main () {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  
  if (u==s) a-=1;
  else b-=1;
  printf("%d %d\n", a, b);
}


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

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

using ll = long long;

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

int main() {
  int N;
  cin >> N;
  vector<vector<pair<int,int>>> vvp(N);
  int ans = 0;
  for(int i = 0; i < N; i++) {
    int A;
    cin >>A;
    for(int j = 0; j < A; j++) {
      int x,y;
      cin >> x >> y;
      vvp.at(i).push_back(make_pair(x,y));
    }
  }
  for(int bit = 0; bit < (1<<N); bit++) {
    vector<pair<int,int>> vp;
    bool can = true;
    for(int i = 0; i < N; i++) {
      if(bit&(1<<i)){
        int l = vvp.at(i).size();
        for(int j = 0; j < l; j++) {
          vp.push_back(vvp.at(i).at(j));
        }
      }
    }
    sort(vp.begin(),vp.end());
    int l = vp.size();
    for(int i = 0; i < l-1; i++) {
      if(vp.at(i).first==vp.at(i+1).first && vp.at(i).second!=vp.at(i+1).second){
        can=false;
        break;
      }
    }
    bitset<17> b(bit);
    for(int i = 0; i < l; i++) {
      if(vp.at(i).second==1&&!b.test(vp.at(i).first-1)) can =false;
      if(vp.at(i).second==0&&b.test(vp.at(i).first-1)) can=false;
    }
    if(can){
      int cnt = b.count();
      chmax(ans,cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;


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

  int N, W;
  cin >> N >> W;
  P p[N];
  rep(i,N){
    cin >> p[i].first >> p[i].second;
  }
  int dp[N+1][W+1]{};
  for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
      if(j < p[i-1].first) dp[i][j] = dp[i-1][j];
      else dp[i][j] = max(dp[i-1][j], dp[i-1][j-p[i-1].first] + p[i-1].second);
    }
  }

  cout << dp[N][W] << endl;

}

Measured memory_bytes: 79232
import Data.List( sort, group)
main = do
    n_ <- readLn
    reports_ <- return . map read . words =<< getLine
    let chkOdd list = all odd list
	chkEven list = all even list
	twoList [_,_]	= True
	twoList _	= False
	check r
	  | even n_ = if chkOdd r
		    then let l = group.sort$r
			 in if all twoList l then (2::Integer)^(length l)
						    else 0
		    else 0
	  | otherwise = if chkEven r
		      then let zero:rem = group.sort$r
			   in if zero==[0]  then (2::Integer)^(length rem)
					    else 0
		      else 0
    print $ (check reports_) `mod` (10^9 + 7)

Measured memory_bytes: 28668
#include<iostream>
using namespace std;
int main(){
  int k,s;
  cin>>k>>s;
  int c=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int z=s-x-y;
      if(z>=0 and z<=k) c++;
    }
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
// #include <prettyprint.hpp>
using namespace std;
typedef long long ll;


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

int main(){
    ll N, K, A;
    scanf("%lld %lld", &N, &K);
    ll min_gcd = -1;
    ll max_v = 0;
    for(ll i=0;i<N;i++){
        scanf("%lld", &A);
        max_v = max(max_v, A);
        if(min_gcd==-1){
            min_gcd = A;
        }else{
            min_gcd = gcd(min_gcd, A);
        }
    }
    if(K % min_gcd == 0 && max_v >= K){
        printf("POSSIBLE\n");
    }else{
        printf("IMPOSSIBLE\n");

    }

    return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def myAnswer(N:int,T:list) -> int:
   return lcm_list(T)

def modelAnswer():
   return
def main():
   N = int(input())
   T = [int(input()) for _ in range(N)]
   print(myAnswer(N,T))
if __name__ == '__main__':
   main()

Measured memory_bytes: 64748
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

struct TWO{
    long long int a,b;
};

bool cmp(TWO x,TWO y){
    if(x.a!=y.a){
        return x.a<y.a;
    }else{
        return x.b<y.b;
    }
}

int main() {
    const long long int mod = 1000000007,INF=50000000000000;
    typedef pair<long long int,long long int>P;
	map<long long int, long long int>mp;
    priority_queue<P,vector<P>,greater<P> >mazuisushi;
    
    priority_queue<P>umaisushi;
	cout << fixed << setprecision(10);
    string str;
    long long int y,m,d;

    while(1){
        cin>>str;
        
        if(str=="#"){return 0;}
        cin>>y>>m>>d;
        if(y==31&&m>=5||y>=32){
            y-=30;
            str="?";
        }
        cout<<str<<" "<<y<<" "<<m<<" "<<d<<endl;
    }
} 



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
int n,k;
vector<pi>spots;
int arr[55][55];
int psum[55][55];
vector<ll>y_index;
vector<ll>x_index;
vector<ll>::iterator it;
long long minarea = numeric_limits<long long>::max();
void solve(){
	for(int y_start=0; y_start<y_index.size(); y_start++){
		for(int y_fin = y_start+1; y_fin<y_index.size(); y_fin++){
			for(int x_start = 0; x_start<x_index.size(); x_start++){
				for(int x_fin = x_start+1; x_fin<x_index.size(); x_fin++){
					int num = psum[y_fin+1][x_fin+1]-psum[y_start][x_fin+1]-psum[y_fin+1][x_start]+psum[y_start][x_start];
					if(num>=k){
						long long x = x_index[x_fin]-x_index[x_start];
						long long y = y_index[y_fin]-y_index[y_start];
						minarea = min(minarea,x*y);
					}
				} 
			}
		}
	}
}
int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++){
		long long x,y;
		cin>>x>>y;
		spots.push_back(pi(y,x));
		x_index.push_back(x);
		y_index.push_back(y);
	}
	sort(all(y_index));
	sort(all(x_index));
	y_index.erase(unique(all(y_index)),y_index.end());
	x_index.erase(unique(all(x_index)),x_index.end());
	for(int i=0; i<spots.size(); i++){
		int y = spots[i].first;
		int x = spots[i].second;
		it = lower_bound(all(y_index),y);
		int yindex = (int)(it-y_index.begin()+1);
		it = lower_bound(all(x_index),x);
		int xindex = (int)(it-x_index.begin()+1);
		arr[yindex][xindex]++;
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			psum[i][j] = arr[i][j];
			psum[i][j]+=psum[i][j-1];
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++) psum[i][j]+=psum[i-1][j];
	}
	solve();
	cout<<minarea;
}

Measured memory_bytes: 3576
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>h(n);
	vector<int>dp(n,1000000000);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), 
			dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
from functools import reduce


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(x, y):
    return (x * y) // gcd(x, y)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def lcm_list(numbers):
    return reduce(lcm, numbers)


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

print(gcd_list(a))

Measured memory_bytes: 14596
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=22,M=1<<21;
int n,k;
char s[M];
int dp[N][M],f0[M],f1[M];
int head=0,tail=0;
int Log[1<<N];
int main(){
	n=read(),k=read();
	For(i,2,(1<<N)-1)
		Log[i]=Log[i>>1]+1;
	For(i,0,n){
		scanf("%s",s);
		For(j,0,(1<<i)-1){
			dp[0][j+(1<<i)]=s[j]-'0';
			f0[j+(1<<i)]=f1[j+(1<<i)]=-1;
			For(t,0,i-1)
				if (~j>>t&1){
					f0[j+(1<<i)]=t;
					break;
				}
			For(t,0,i-1)
				if (j>>t&1){
					f1[j+(1<<i)]=t;
					break;
				}
		}
	}
	int ansl=-1,ans=0;
	For(ls,0,n)
		For(s,0,(1<<ls)-1)
			Fod(lt,n-ls,0){	
				int ad=1<<(ls+lt);
				if (lt==0){
					if (dp[ls][s+ad]>=k)
						if (ls>ansl||(ls==ansl&&s<ans))
							ansl=ls,ans=s;
				}
				else {
					For(t,0,(1<<lt)-1){
						int v=dp[ls][(s<<lt|t)+ad];
						if (!v)
							continue;
						dp[ls][s+(1<<ls)]+=v;
						int F0=f0[t+(1<<lt)],F1=f1[t+(1<<lt)];
						if (~F0)
							dp[ls+1][((s|0<<ls)<<(lt-F0-1)|t>>(F0+1))+(1<<(ls+lt-F0))]+=v;
						if (~F1)
							dp[ls+1][((s|1<<ls)<<(lt-F1-1)|t>>(F1+1))+(1<<(ls+lt-F1))]+=v;
					}
				}
			}
	Fod(i,ansl-1,0)
		putchar('0'+(ans>>i&1));
	return 0;
}

Measured memory_bytes: 207232
import sys

S = input()

k = 0
cnt = 0
s0 = S[0]
s1 = S[1]

while k < len(S):
    for i in range(k, len(S)):
        if s0 != S[k+1:i+2]:
            s0 = S[k+1:i+2]
            cnt += 1
            k = i + 1
        else:
            continue

    break

if len(S) == k:
    print(cnt)
else:
    print(cnt + 1)



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

int main(){
	int x,y;
	cin >> x >> y;
	while(!(x == 0 && y == 0)){
		if(x < y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
		cin >> x >> y;
	}
	return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N;
    cin >> N;
    vector<ll> x(N), y(N);
    REP(i,0,N) cin >> x[i] >> y[i];

    double d = 0.0, dx, dy;
    REP(i,0,N){
        REP(j,0,N){
            dx = x[i] - x[j];
            dy = y[i] - y[j];
            d += sqrt(dx*dx + dy*dy);
        }
    }

    printf("%.10f", d / N);


    return 0;
}

/*



*/

Measured memory_bytes: 256
def f(n) n>0?1<<n.to_s(2).size: 1 end
a,b=$<.map &:to_i
(p 1;exit)if 0==x=a^b
c=f(x)
a&=c-1
b&=c-1
i=c>>1
b=f(b-i)-1
p c-a-[a-1-b,0].max

Measured memory_bytes: 1788
s=" "+input()
f=[0]*(len(s))
pre=""
f[1]=1
f[2]=2 if s[1]!=s[2] else 1
#f[3]=3 if f[2]==2 and s[1]!=s[2] else 2
for i in range(3, len(s)):
  f[i]=f[i-1]+1 if s[i]!=s[i-1] else f[i-3]+2
print(f[-1])

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

int mod_num = 1000000007;

unsigned long long fac(int n) {
	unsigned long long res = 1;
	for (int i = 1; i <= n; i++) {
		res *= i;
		res %= mod_num;
	}
	return res;
}

int main() {
	int N, M;
	cin >> N >> M;
	if (N - M > 1 || M - N > 1) {
		cout << 0 << endl;
	}
	else if (M - N == 1 || N - M == 1) {
		unsigned long long fac_1 = fac(M);
		unsigned long long fac_2 = fac(N);
		cout << (fac_1 * fac_2 % mod_num) << endl;
	}
	else {
		unsigned long long fac_1 = fac(M);
		unsigned long long fac_2 = fac(M - 1);
		unsigned long long res = (fac_1 * fac_2 % mod_num);
		res = (res * M % mod_num);
		res = (res * 2 % mod_num);
		cout << res << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        string s = Console.ReadLine();
        bool b = true;
        for (int i = 0; i < s.Length; i++)
        {
            if (i != a[0])
            {
                if (!char.IsDigit(s[i]))
                {
                    b = false;
                }
            }
            else
            {
                if (s[i] != '-')
                {
                    b = false;
                }
            }
        }
        Console.WriteLine(b ? "Yes" : "No");
    }
}

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

int A[1000000] = { 0 }, n;

int main()
{
	int q = 0, nKey = 0, nSum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	cin >> q;
	for (int i = 0; i < q; ++i)
	{
		cin >> nKey;
		if (*lower_bound(A, A + n, nKey) == nKey)
		{
			++nSum;
		}
	}
	cout << nSum << endl;
	return 0;
}


Measured memory_bytes: 3464
#include <stdio.h>

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) comp(const void *a, const void *b)
#define MOD 1000000007
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;

void yes_or_no(char boolean){
    if(boolean){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}
ull pow2(uint k){
    if(k == 0){
        return 1;
    }else{
        return (2 * pow2(k - 1)) % MOD;
    }
}
int main(){
    uint N, i;
    uint A;
    scanf("%d", &N);
    char flag = 1;

    if(N % 2 == 1){
        uint num[N/2 + 1];
        REP(i, N/2 + 1){
            num[i] = 0;
        }

        REP(i, N){
            scanf("%d", &A);
            if(A % 2 == 1 || A > N - 1){
                flag = 0;
                break;
            }
            else{
                num[A/2]++;
                if(A == 0 && num[A/2] > 1){
                    flag = 0;
                    break;
                }else if(num[A/2] > 2){
                    flag = 0;
                    break;
                }
            }
        }

        REP(i, N/2 + 1){
            if(i == 0 && num[i] != 1){
                flag = 0;
                break;
            }else if(i > 0 && num[i] != 2){
                flag = 0;
                break;
            }
        }
    }else{
        uint num[N/2];
        REP(i, N/2){
            num[i] = 0;
        }
        REP(i, N){
            scanf("%d", &A);
            if(A % 2 == 0 || A > N - 1){
                flag = 0;
                break;
            }
            else{
                num[A/2]++;
                if(num[A/2] > 2){
                    flag = 0;
                    break;
                }
            }
        }

        REP(i, N/2){
            if(num[i] != 2){
                flag = 0;
                break;
            }
        }
    }

    if(flag == 0){
        printf("0\n");
    }else{
        printf("%lld\n", pow2(N/2));
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define repr(i, n) for(int i = n; i >= 0; i--)
    #define FOR(i, m, n) for(int i = m; i < n; i++)
    #define INF 1e17
    #define ALL(v) v.begin(), v.end()
    using namespace std;
    typedef long long ll;
    struct edge {ll to,cost;};
    typedef pair<ll,ll> P;
    ll V=100005;
    vector<edge> G[100005];
    ll d[100005];

    void dijkstra(ll s){
        priority_queue<P,vector<P>,greater<P>> que;
        fill(d,d+V,INF);
        d[s]=0;
        que.push(P(0,s));
        while(!que.empty()){
            P p =que.top();
            que.pop();
            int v =p.second;
            if (d[v] < p.first) continue;
            rep(i,G[v].size()){
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }
    }
    int main()
    {
        ll N,M;
        cin>>N>>M;
        rep(i,M){
            ll a,b,c;
            cin>>a>>b>>c;
            edge ed;
            ed.to=b-1;
            ed.cost=c;
            G[a-1].push_back(ed);
        }
        for(ll i=N-1;0<i;i--) {
            edge ed;
            ed.to=i-1;
            ed.cost=0;
            G[i].push_back(ed);
        }
        dijkstra(0);
        if (d[N-1]==INF){
            cout<<-1<<endl;
        }else{
            cout<<d[N-1]<<endl;
        }
    }

Measured memory_bytes: 9592
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
	if a[i]>=b[i]:
		ans+=b[i]
		a[i]-=b[i]
	elif a[i]+a[i+1]>=b[i]:
		ans+=b[i]
		a[i+1]-=(b[i]-a[i])
	else:
		ans+=a[i]+a[i+1]
		a[i+1]=0
print(ans)



Measured memory_bytes: 19156
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define mod (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
	int x,n;
	cin>>x>>n;
	vector<bool>used(201,0);
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		used[a] = 1;
	}
	int rg = 101,lf = -1;
	for(int i=x;i<=101;i++)if(!used[i]){rg = i;break;}
	for(int i=x;i>=0;i--)if(!used[i]){lf = i;break;}
	//cout<<lf<<" "<<rg;
	if(abs(x-lf) == abs(x-rg))cout<<lf;
	else{
		if(abs(x-lf) > abs(x-rg))cout<<rg;
		else cout<<lf;
	}
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

ll a,b,c,d;

void solve(){
    cin >> a >> b >> c >> d;
    ll ans=-INF;
    chmax(ans,a*c);
    chmax(ans,a*d);
    chmax(ans,b*c);
    chmax(ans,b*d);
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

using namespace std;

#define FOR(i, a, b) for (int i=(a);i<(b);++i)
#define ROF(i, a, b) for (int i=(b)-1;i>=(a);--i)
#define REP(i, n) for (int i=0;i<(n);++i)
#define PRE(i, n) for (int i=(n)-1;i>=0;--i)
#define FOREACH(a, v) for(auto a : v)

#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cerr<<#x<<": "<<x<<endl
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)

#define INF INT_MAX/3
#define eps 1e-14

#define ll long long
using vint = vector<int>;

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

int main() {
    int X, A, B, C;
    cin >> A >> B >> C >> X;
    int ret = 0;
    REP(i, A+1)REP(j, B+1)REP(k, C+1) if (i * 500 + j * 100 + k * 50 == X) ret += 1;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
n,m,q=map(int,input().split())
Q=[]
for i in range(q):
    a,b,c,d=map(int,input().split())
    Q.append([a-1,b-1,c,d])    
ans=0
for i in range(m):
    L=[i for i in range(1,n+i-1)]
    C=itertools.combinations(L,n-2)
    for c in C:
        #print(c)
        cnt=0
        A=[1]
        now=0
        for j in range(n-2):
            A.append(A[-1]+c[j]-now-1)
            now=c[j]
        A.append(i+1)
        #print(A)
        for que in Q:
            if A[que[1]]-A[que[0]]==que[2]:
                cnt+=que[3]
        ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 9252
#include <iostream>
#include <vector>
#include <map>

using namespace std;

vector<pair<int,int>> d(8);

int main(){
  d[0] = make_pair(1,0);
  d[1] = make_pair(0,1);
  d[2] = make_pair(-1,0);
  d[3] = make_pair(0,-1);
  d[4] = make_pair(1,1);
  d[5] = make_pair(1,-1);
  d[6] = make_pair(-1,-1);
  d[7] = make_pair(-1,1);
  long long int N,M;
  cin >> N >> M;
  if(N>2 && M > 2){
  cout << N * M - (2 * N + 2 * M - 4);
  }else{
    if(min(N ,M) == 2){
      cout << 0;
    }else if(min(N,M) == 1 && max(N,M) != 1){
      cout << max(N, M) - 2;
    }else if(N == 1 && M == 1){
      cout << 1;
    }
  }
}


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

using ll = long long;

using namespace std;

#define INF 10000000

#define minimize(a, b) a = min(a, b)

int main() {
    int n;
    cin >> n;
    int white[n], black[n],
        wrui[n+1][2*n+1], brui[n+1][2*n+1];
    fill(wrui[0], wrui[n+1], 0);
    fill(brui[0], brui[n+1], 0);
    for (int i=0, a; i<2*n; i++) {
        char c;
        cin >> c >> a;
        a--;
        if (c == 'W') {
            white[a] = i;
            for (int j=a+1; j<=n; j++) wrui[j][i]++;
        }
        else {
            black[a] = i;
            for (int j=a+1; j<=n; j++) brui[j][i]++;
        }
    }
    for (int i=0; i<=n; i++) {
        for (int j=2*n; j>0; j--) {
            wrui[i][j-1] += wrui[i][j];
            brui[i][j-1] += brui[i][j];
        }
    }
    int dp[n+1][n+1];
    fill(dp[0], dp[n+1], INF);
    dp[0][0] = 0;
    for (int i=0; i<=n; i++) {
        for (int j=0; j<=n; j++) {
            if (i < n) minimize(dp[i+1][j], dp[i][j] + wrui[i][white[i]] + brui[j][white[i]]);
            if (j < n) minimize(dp[i][j+1], dp[i][j] + wrui[i][black[j]] + brui[j][black[j]]);
        }
    }
    cout << dp[n][n] << '\n';
    return 0;
}

Measured memory_bytes: 78464
#include<stdio.h>
#include<string.h>
#define N 36
#define CHECKPOINT printf("CHECKPOINT\n");
void bubbleSort(int,char[],int[]);
void selectionSort(int,char[],int[]);
void printArray(int,char[],int[]);
int main(void)
{
  int i;//counter
  int n;//length of input
  char b1[N],s1[N];//array for bubble/selection sort
  int b2[N],s2[N];//array for bubble/selection sort
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf(" %c%d",&b1[i],&b2[i]);
      s1[i]=b1[i];
      s2[i]=b2[i];
    }
  bubbleSort(n,b1,b2);
  printArray(n,b1,b2);
  printf("Stable\n");
  selectionSort(n,s1,s2);
  printArray(n,s1,s2);
  for(i=0;i<n;i++)
    {
      if(s1[i]!=b1[i]||s2[i]!=b2[i]) break;
    }
  if(i==n) printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}
void bubbleSort(int n,char a1[],int a2[])
{
  int i,j;//counter
  char tmpc;//temporary value for swapping
  int tmpi;
  for(i=0;i<n;i++)
    {
      for(j=n-1;j>i;j--)
	{
	  if(a2[j]<a2[j-1])
	    {
	      tmpc=a1[j];
	      a1[j]=a1[j-1];
	      a1[j-1]=tmpc;
	      tmpi=a2[j];
	      a2[j]=a2[j-1];
	      a2[j-1]=tmpi;
	    }
	}
    }
}
void selectionSort(int n,char a1[],int a2[])
{
  int i,j;//counter
  int mini;//valuable for min. index
  char tmpc;//temporary value for swapping
  int tmpi;
  for(i=0;i<n;i++)
    {
      mini=i;
      for(j=i+1;j<n;j++)
	{
	  if(a2[j]<a2[mini]) mini=j;
	}
      tmpc=a1[i];
      a1[i]=a1[mini];
      a1[mini]=tmpc;
      tmpi=a2[i];
      a2[i]=a2[mini];
      a2[mini]=tmpi;
    }
}
void printArray(int n,char a1[],int a2[])
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%c%d",a1[i],a2[i]);
    }
  printf("\n");
}



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

int main(){
  vector<int> a;
  int temp;
  for(int i = 0;i < 12;++i){
    cin >> temp;
    a.push_back(temp);
  }

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

  bool flag = true;
  for(int i = 0;i < 4 - 1 && flag;++i){
    if(a[i] != a[i + 1]) flag = false;
  }

  for(int i = 4;i < 8 - 1 && flag;++i){
    if(a[i] != a[i + 1]) flag = false;
  }

  for(int i = 8;i < 12 - 1 && flag;++i){
    if(a[i] != a[i + 1]) flag = false;
  }

  if(flag){
    cout << "yes" << endl;
  }else{
    cout << "no" << endl;
  }

  return 0;
}



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

int main(){
    int n;
    cin >> n;
    vector<int> v;
    v.push_back(0);
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        v.push_back(a);
    }

    int light = 1, cnt = 0;
    bool ok = false;
    set<int> st;
    st.insert(1);
    for(int i=0;i<n;++i){
        light = v[light];
        cnt++;
        if(light == 2){
            ok = true;
            break;
        }
        if(st.count(light))break;
        st.insert(light);
    }

    if(ok)cout << cnt << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 5368
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n, y = map(int, input().split())

# a+b+c=n
# 10000*a + 5000*b + 1000*c = y

result = False

for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if y == 10000*k + 5000*j + 1000*i:
            print(k, j, i)
            result = True
            break
    if result:
        break

if result == False:
    print(-1, -1, -1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
using namespace std;

void solve(int test){
	ll d,t,s;
	cin>>d>>t>>s;
	if (s*t >= d)
	{
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}
  
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1,k;
	//cin>>t;
	k = t;
	while(t--){
		solve(k - t);
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

Measured memory_bytes: 3796
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

float A,B;

int main(){

    scanf("%f%f",&A,&B);

    float lower_bound_included_A=A/0.08f;
    float upper_bound_excluded_A=(A+1.0f)/0.08f;
    float lower_bound_included_B=B/0.1f;
    float upper_bound_excluded_B=(B+1.0f)/0.1f;

    float lower_bound_included=max(lower_bound_included_A,lower_bound_included_B);
    float upper_bound_excluded=min(upper_bound_excluded_A,upper_bound_excluded_B);

    for (int i=ceilf(lower_bound_included);i<upper_bound_excluded;i++){
        printf("%d\n",i);
        return 0;
    }

    puts("-1");

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <functional>
#include <climits>

using namespace std;

typedef long long ll;

ll a[300005];

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<3*N;i++){
		scanf(" %lld",&a[i]);
	}
	
	priority_queue<ll, vector<ll>, greater<ll> > q1;

	vector<ll>v1(N+1);

	ll sum=0ll;

	for(i=0;i<N;i++){
		q1.push(a[i]);
		sum+=a[i];
	}
	v1[0]=sum;

	for(i=1;i<=N;i++){
	auto in=a[N-1+i];
	q1.push(in);
	auto out=q1.top();q1.pop();
	v1[i]=v1[i-1]+in-out;
	}

	priority_queue<ll, vector<ll>, less<ll> > q2;

	vector<ll>v2(N+1);

	sum=0ll;

	for(i=2*N;i<3*N;i++){
		q2.push(a[i]);
		sum+=a[i];
	}
	v2[N]=sum;

	for(i=N;i>0;i--){
	auto in=a[N-1+i];
	q2.push(in);
	auto out =q2.top();q2.pop();
	v2[i-1]=v2[i]+in-out;
	}

	ll ans=-LLONG_MAX;

	for(i=0;i<=N;i++){
	ans=max(ans,v1[i]-v2[i]);
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 6516
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

M, D = map(int, input().split())

count = 0
for i in range(1, M+1):
    for j in range(1, D+1):
        if j < 20:
            continue

        J = list(str(j))
        d10 = int(J[0])
        d1 = int(J[1])

        if d1 >= 2 and d10 >= 2 and d1*d10 == i:
            count += 1

print(count)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
  int n, m; cin >> n >> m;
  int cnt[n + 1];
  // 初期化
  for (int i = 1; i <= n; i++) cnt[i] = 0;

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

  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
(defvar +maxiter+ 52)

(let* ((a (read))
       (b (read))
       (c (read))
       (d (read))
       (e (read))
       (f (read))
       (rate -1)
       (max-sugar -1)
       (max-water -1))
  (dotimes (ai +maxiter+)
    (dotimes (bi +maxiter+)
      (dotimes (ci +maxiter+)
        (dotimes (di +maxiter+)
          (let ((water (+ (* a ai 100) (* b bi 100)))
                (sugar (+ (* c ci) (* d di))))
            (when (<= (* sugar 100) (* e water))
              (let ((sw (+ sugar water)))
                (when (and (< 0 sw)
                           (<= sw f))
                  (let ((current (/ (* 100 sugar) sw)))
                    (when (< rate current)
                      (setf rate current
                            max-sugar sugar
                            max-water water)))))))))))
  (format t "~A ~A~%"
          (+ max-sugar max-water)
          max-sugar))


Measured memory_bytes: 16096