akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;
int A[1000];
void solve(){
	int n, k;
	cin>>n>>k;
	for(int i = 0; i < n; i++)
		cin>>A[i];
	vi v;
	int mans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i; j < n + 1; j++) {
			v.clear();
			int sum = 0;
			rep(k, 0, i) {
				v.pb(A[k]);
				sum += A[k];
			}
			rep(k, j, n) {
				v.pb(A[k]);
				sum += A[k];
			}
			int moves = v.size();
			if(moves > k)
				continue;
			sort(all(v));
			int t = k - moves, tsum = 0;
			int index = 0;
			while(index < v.size() && t--) {
				if(v[index] < 0)
					tsum += v[index];
				index++;
			}
			mans = max(mans, sum - tsum);
		}
	}
	cout<<mans<<endl;
}
int main() {
	int t;
	//cin>>t;
	t = 1;
	while(t--){
		solve();
	}
}


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

using namespace std;

int main()
{
   int N;
   int sum = 0;
   int tmp, t2;
   int min = INT_MAX;
   vector<int> vec;

   cin >> N;
   for (int i = 0; i < N; i++) {
       cin >> tmp;
       sum += tmp;
       vec.push_back(tmp);
   }

    for (int i = 0; i < N; i++) {
        t2 = sum - vec[i]*2;
        if (abs(sum) > abs(t2)) {
            min = abs(t2);
        }
        sum = t2;
        //cout << min << endl;
   }

   cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
	int n;
	while(cin>>n){
        char s[4444];cin>>s;
        long nr=0,ng=0,nb=0;
        for(int i=0;i<n;i++)nr+=s[i]=='R',ng+=s[i]=='G',nb+=s[i]=='B';
        //cout<<nr<<" "<<ng<<" "<<nb<<" = "<<nr*ng*nb<<endl;
        long ans=nr*ng*nb;
        for(int i=0;i<n;i++)
            for(int d=1;i+d+d<n;d++)
                if((s[i]^s[i+d]^s[i+d+d])==('R'^'G'^'B'))
                    ans--;
        cout<<ans<<'\n';
	}
    //cout<<('R'^'G'^'B')<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int pn[30];
int res[30];
int id;

void calcPnum(void){
	int n=2;
	id=0;
	while(n<=100){
		bool flag=true;
		for(int i=2;i<n;i++)if(n%i==0)flag=false;
		if(flag){
			pn[id]=n;
			id++;
		}
		n++;
	}	
}

void pfact(int n){
	rep(i,30)res[i]=0;
	int k=0;
	while(n>0 && k<id){
		if(n%pn[k]==0){
			res[k]++;
			n=n/pn[k];
		}
		else k++;
	}
}


int main(void){
	int n;
	cin>>n;
	calcPnum();
	int num[30];
	rep(i,id)num[i]=0;
	//rep(i,id)cout<<pn[i]<<",";
	//cout<<endl;
	for(int i=2;i<=n;i++){
		pfact(i);
		//rep(i,id)cout<<res[i]<<",";
		//cout<<endl;
		rep(i,id)num[i]+=res[i];
	}
	//rep(i,id)cout<<num[i]<<",";
	//cout<<endl;
	int cnt2=0,cnt4=0,cnt14=0,cnt24=0,cnt74=0;
	rep(i,id){
		if(num[i]>=74){
			cnt2++;
			cnt4++;
			cnt14++;
			cnt24++;
			cnt74++;
		}
		else if(num[i]>=24){
			cnt2++;
			cnt4++;
			cnt14++;
			cnt24++;
		}
		else if(num[i]>=14){
			cnt2++;
			cnt4++;
			cnt14++;
		}
		else if(num[i]>=4){
			cnt2++;
			cnt4++;		}
		else if(num[i]>=2) cnt2++;
	}
	//cout<<cnt2<<","<<cnt4<<","<<cnt14<<","<<cnt24<<","<<cnt74<<endl;
	cout<<cnt74+cnt24*(cnt2-1)+cnt14*(cnt4-1)+cnt4*(cnt4-1)*(cnt2-2)/2<<endl;

	return 0;
}


Measured memory_bytes: 256
s = input()

ans = 1
while(len(s)>0):
    if s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif  s[-6:] == "eraser":
        s = s[:-6]
    else:
        s = ""
        ans = 0
if ans > 0:
    print("YES")
else:    
    print("NO")


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define PI 3.1415926535897932384626
#define mod 1000000007
#define fo(i,n) for(i=0;i<n;i++)
#define endl "\n"
#define mset(m,v) memset(m,v,sizeof(m))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef vector<int>	vi;
#define FAST_IO  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

void solve()
{
	int n,i,ans=0,x,j;
	cin >> n;
	x=sqrt(n);
	for(i=1;i<=x;i++){
	    j=i;
	    while(i*j<n){
	        if(i==j)ans++;
	        else ans+=2;
	        j++;
	    }
	}
	cout << ans << endl;
}

int32_t main()
{
	FAST_IO;
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

Measured memory_bytes: 3680
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 999999999999971;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int Ceil(Int a, Int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return Floor(a, b) + 1;
    }
}

Int digits(Int n) {
    return (Int)to_string(n).size();
}

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

    int n;
    cin >> n;
    int od = 0;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;

        if (t & 1) {
            od++;
        }
    }

    if (!(od & 1)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3588
package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func cleanString(line string, separator string) []int {
	// Trims the stream and then splits
	trimmed := strings.TrimSpace(line)
	split_arr := strings.Split(trimmed, separator)
	// convert strings to integers and store them in a slice
	clean_arr := make([]int, len(split_arr))
	for index, val := range split_arr {
		clean_arr[index], _ = strconv.Atoi(val)
	}
	return clean_arr
}

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

func main() {
	inputreader := bufio.NewReader(os.Stdin)
	input, _ := inputreader.ReadString('\n')
	first := cleanString(input, " ")
	n := first[0]
	k := first[1]

	hs, _ := inputreader.ReadString('\n')
	h := cleanString(hs, " ")

	c := make([]int, n)
	c[0] = 0
	c[1] = abs(h[1] - h[0])

	for i := 2; i < n; i++ {
		cmin := -1 // special value
		for cur := i-1; cur > i-1-k; cur-- {
			if cur < 0 {
				break
			}
			val := abs(h[i] - h[cur]) + c[cur]
			if cmin == -1 || val < cmin {
				cmin = val
			}
		}
		c[i] = cmin
	}
	fmt.Println(c[n-1])
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int p[100010], q[100010];
    rep(i, N) cin >> p[i];
    rep(i, N) p[i]--;
    rep(i, N) q[p[i]] = i;
    multiset<int> L, R;
    L.insert(-1);
    L.insert(-1);
    R.insert(N);
    R.insert(N);
    ll ans = 0;
    RREP(i, N - 2, 0) {
        L.insert(q[i + 1]);
        R.insert(q[i + 1]);
        auto itrL = L.lower_bound(q[i]);
        auto itrR = R.lower_bound(q[i]);
        ll x2 = *(--itrL);
        ll x1 = *(--itrL);
        ll x3 = *(itrR);
        ll x4 = *(++itrR);
        //cout << x1 << " " << x2 << " " << q[i]<< " " << x3 << " " << x4 << endl;
        ans += ((i + 1) * (x2 - x1) * (x3 - q[i]));
        ans += ((i + 1) * (q[i] - x2) * (x4 - x3));
    }
    cout << ans << endl;



    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

ll score[65536];
ll a[17][17];

int main(){
  int n;cin>>n;
  rep(i, n)rep(j, n)cin>>a[i][j];

  rep(bit, 1<<n){
    ll s = 0;
    rep(i, n)rep(j, n){
      if(i==j)continue;
      if((bit>>i)%2==0 || (bit>>j)%2==0)continue;

      s += a[i][j];
    }
    score[bit]=s/2;
  }

//  rep(bit, 1<<n)cout<<score[bit]<<' ';cout<<endl;


  rep(bit1, 1<<n)for(int bit2=bit1; bit2>0; bit2 = (bit2-1)&bit1){
    if(bit1 == bit2)continue;
    score[bit1] = max<ll>(score[bit1], score[bit1-bit2] + score[bit2]);
  }
  int idx = (1<<n)-1;
  cout<<score[idx]<<endl;

  return 0;
}

Measured memory_bytes: 4072
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let (h, w, a, b) = (line[0], line[1], line[2], line[3]);
    let mut row = vec![1;w];
    for i in 0..a{
        row[i] = 0;
    }

    for i in 0..h{
        if i < b{
            println!("{}", row.iter().map(|x| std::char::from_digit(*x, 10).unwrap()).collect::<String>());
        }else{
            println!("{}",
                     row
                     .iter()
                     .map(|x|
                          if *x == 0{
                              '1'
                          }else{
                              '0'
                          }
                     )
                     .collect::<String>());
        }
    }
}


Measured memory_bytes: 5244
#include <stdio.h>

int main() {
    int n, i, j;
    scanf("%d", &n);

    int a[n*2+1], sum=0;
    for(i=0; i<n; i++) {
        scanf("%d",&a[i]);
        sum += a[i];
    }

    int mou[n], tmp;
    tmp = sum;
    for(i=0; i<(n/2); i++) {
        tmp -= a[j+1+i*2]*2;
    }
    mou[0] = tmp;

    for(j=1; j<n; j++) {
        mou[j] = a[j-1]*2 - mou[j-1];
    }

    for(i=0; i<n; i++) {
        printf("%d ", mou[i]);
    }
    printf("\n");

    return 0;

}

Measured memory_bytes: 2048
while True:
    try:
        a,b = (lambda row: [int(row[i]) for i in range(len(row))])(input().split())
        n = int(input())
        obstacle = [(lambda row: [int(row[i]) for i in range(len(row))])(input().split()) for __ in range(n)]
        roads = [[0 for __ in range(b+1)] for __ in range(a+1)]
        roads[1][1] = 1
        for i in range(1,a+1):
            for j in range(1,b+1):
                if not [i,j] in obstacle:
                    roads[i][j] += roads[i-1][j] + roads[i][j-1]
        
        print(str(roads[a][b]))
        
    except:
        break


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

int main() {
  string S,T;cin>>S>>T;
  
  ll slen=S.size(),tlen=T.size();
  ll a=0,correct=0;
  for(int i=0;i<=slen-tlen;i++){
    a=0;
    for(int j=0;j<tlen;j++){
      if(S[i+j]==T[j]) a++;
    }
    correct=max(a,correct);
  }
  
  cout << tlen-correct << endl;
    
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <regex>
#include <math.h>
typedef long long ll;
using namespace std;

int main(void){
  ll a,b;
  char op;
  cin >> a >> op >> b;
  if (op == '+'){
    cout << a + b << endl;
  }else{
    cout << a - b << endl;
  }
  return 0;
}

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

using namespace std;

bool b[100010];

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n, 1);
    b[0] = true;

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

        if (a[x] == 1 && b[x]) {
            b[x] = false;
            b[y] = true;
            --a[x];
            ++a[y];
        } else if (b[x] && !b[y]) {
            b[y] = true;
            ++a[y];
            --a[x];
        } else {
            --a[x];
            ++a[y];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (int) b[i];
    }

    cout << ans << endl;
}

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

void input(llong& rnMaxNum, vector<llong>& rvnCapcty)
{
  cin >> rnMaxNum;
  
  for (llong& rnCapcty : rvnCapcty)
    cin >> rnCapcty;
}

llong calcTransptCnt(llong nMaxNum, vector<llong>& rvnCapcty)
{
  for (int i = 0; i < rvnCapcty.size() - 1; i++)   // 交通機関の容量を直前の大きさに合わせる
    if (rvnCapcty[i] < rvnCapcty[i + 1])
      rvnCapcty[i + 1] = rvnCapcty[i];
  
  vector<llong> vnTime(6);                         // 各都市への移動時間

  for (int i = 0; i < vnTime.size() - 1; i++)      // 移動時間を計算
  {
    vnTime[i + 1] = (nMaxNum + (rvnCapcty[i] - 1)) / rvnCapcty[i]; 
    vnTime[i + 1] += i;
  }
  llong nTotalTime = 0;

  for (int i = 0; i < vnTime.size() - 1; i++)      // トータル時間を計算
    nTotalTime += vnTime[i + 1] - vnTime[i];       // 各都市間へ同時に移動しているため
                                                   // 移動時間の差分を加算
  return nTotalTime;
}
 
int main()
{
  llong nMaxNum;
  vector<llong> vnCapcty(5);

  input(nMaxNum, vnCapcty);
  cout << calcTransptCnt(nMaxNum, vnCapcty) << endl;

  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5

ll parent[100005];
ll size[100005];
void make_set(ll v) {
    parent[v] = v;
    size[v] = 1;
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}

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

    ll n, m;
    cin>>n>>m;
    loop(i,1,n+1){
        make_set(i);
    }
    loop(i,0,m){
        ll x, y, z;
        cin>>x>>y>>z;
        union_sets(x, y);
    }
    ll ans=0;
    loop(i,1,n+1){
        if(parent[i]==i) ans++;
    }
    cout<<ans<<endl;

    /*#ifndef ONLINE_JUDGE
        end_routine();
    #endif*/
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define mod 1000000007
#define mk make_pair

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;vector<vector<int>> v;
vector<int > leaforder;
    v.resize(n+1);
    int a,b;
    for(int i=1;i<n;i++)
    
    {cin>>a>>b;v[a].pb(b);v[b].pb(a);}
    int vis1[n+1]={0};vis1[1]=1;
    ll dp[n+1][2];dp[0][0]=0;dp[0][1]=0;
    for(int i=2;i<=n;i++)
    {dp[i][0]=0;dp[i][1]=0;}
    dp[1][1]=1;dp[1][0]=1;
    int par[n+1]={0};//cout<<"dfgh";
    for(int i=1;i<=n;i++)
    {
        if(v[i].size()==1)
        {par[i]=v[i][0];dp[i][0]=1;dp[i][1]=1;}
    }
    queue<int> q;q.push(1);vis1[1]=1;
    while(q.size()!=0)
    {
        int t=q.front();leaforder.pb(t);
        for(int i=0;i<v[t].size();i++)
        {
            if(vis1[v[t][i]]==0)
            { q.push(v[t][i]);vis1[v[t][i]]=1;}
        
        }
        q.pop();//cout<<t<<" ";
    }
   
     int vis2[n+1]={0};vis2[1]=0;
    for(int i=leaforder.size()-1;i>0;i--)
    {  
        
        for(int j=0;j<v[leaforder[i]].size();j++)
        {
            if(vis2[v[leaforder[i]][j]]==0)
            {par[leaforder[i]]=v[leaforder[i]][j];
            break;}
        }vis2[leaforder[i]]=1;
    }par[1]=0;
    
    for(int i=leaforder.size()-1;i>=0;i--)
    {  
        if(v[leaforder[i]].size()==1&&leaforder[i]!=1);
        
        else
        {   ll w=1;ll wb =1;
            for(int j=0;j<v[leaforder[i]].size();j++)
            {
                if(leaforder[i]==6);
                //cout<<par[leaforder[i]]<<" "<<v[leaforder[i]][j]<<" mbv";
                if(par[leaforder[i]]==v[leaforder[i]][j])
                continue;
                else
                {
                    w=(w*dp[v[leaforder[i]][j]][0])%mod;
                    wb=wb*(dp[v[leaforder[i]][j]][0]+dp[v[leaforder[i]][j]][1]);
                    wb%=mod;
                }
                
            }
            dp[leaforder[i]][0]=wb;dp[leaforder[i]][1]=w;
        }
       
    }  
    ll an=(dp[1][0]+dp[1][1])%mod;
    cout<<an;
    return 0;
}

Measured memory_bytes: 9916
xs, ys, xt, yt = map(int,input().split())
N = int(input())
L = [[xs, ys, 0], [xt, yt, 0]]

for _ in range(N):
    L.append(list(map(int,input().split())))

V = N + 2
G = [[] for _ in range(N+2)]
s = 0

for i in range(N+2):
    for j in range(N+2):
        if i != j:
            G[i].append([j, max(0, ((L[i][0] - L[j][0]) ** 2 + (L[i][1] - L[j][1]) ** 2) ** 0.5 - (L[i][2] + L[j][2]))])


INF = float('inf')

import heapq

def dijkstra(s):
    d = [INF for _ in range(V)]
    d[s] = 0
    que = []
    heapq.heappush(que, (0, s))
    
    while len(que) != 0:
        p = heapq.heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(G[v])):
            e = G[v][i]
            if d[e[0]] > d[v] + e[1]:
                d[e[0]] = d[v] + e[1]
                heapq.heappush(que, (d[e[0]], e[0]))

    return d

d = dijkstra(0)
print(d[1])

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

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

typedef pair<char,ll> p;
typedef vector<p> pv;

pv read_rle(){
  pv res;
  while(1){
    char c; ll n;
    cin>>c;
    if(c=='$')break;
    cin>>n;
    res.push_back(p(c,n));
  }
  return res;
}

void print_rle(pv s){
  rep(i,s.size()){
    printf("%c %lld ", s[i].fi,s[i].se);
  }
  printf("$\n");
}

int main(){
	cin.sync_with_stdio(false);
  pv a,b,c;
  a=read_rle(); b=read_rle(); c=read_rle();
  int na=a.size(),nb=b.size(),nc=c.size();
  int st=-1,en=-1;
  rep(i,na){
    if(i+nb-1>=na)continue;
    if(b[0].fi!=a[i].fi||b[0].se>a[i].se||b[nb-1].fi!=a[i+nb-1].fi||b[nb-1].se>a[i+nb-1].se)continue;
    bool ok=true;
    repl(j,1,nb-1){
      if(b[j]!=a[i+j])ok=false;
    }
    if(!ok)continue;
    st=i; en=i+nb-1; break;
  }
  if(st==-1)print_rle(a);
  else{
    pv res,res2;
    rep(i,st)res.push_back(a[i]);
    if(nb>1&&a[st].se-b[0].se>0)res.push_back(p(a[st].fi,a[st].se-b[0].se));
    rep(i,nc){
      res.push_back(c[i]);
    }
    if(a[en].se-b[nb-1].se>0)res.push_back(p(a[en].fi,a[en].se-b[nb-1].se));
    repl(i,en+1,na)res.push_back(a[i]);
    //print_rle(res);
    res2.push_back(res[0]);
    repl(i,1,res.size()){
      if(res[i-1].fi==res[i].fi){
        res2.back().se+=res[i].se;
      }else{
        res2.push_back(res[i]);
      }
    }
    print_rle(res2);
  }
	return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>

int main() {
  size_t N, K;
  scanf("%zu %zu", &N, &K);

  std::vector<std::pair<intmax_t, intmax_t>> xy(N);
  std::vector<intmax_t> xs(N), ys(N);
  for (size_t i = 0; i < N; ++i) {
    scanf("%jd %jd", &xy[i].first, &xy[i].second);
    std::tie(xs[i], ys[i]) = xy[i];
  }

  intmax_t res = 9e18;
  for (auto x0: xs)
    for (auto x1: xs)
      for (auto y0: ys)
        for (auto y1: ys) {
          size_t cur = 0;
          for (const auto& xyi: xy) {
            intmax_t x, y;
            std::tie(x, y) = xyi;
            if (x0 <= x && x <= x1 && y0 <= y && y <= y1) ++cur;
          }

          if (cur < K) continue;
          res = std::min(res, (y1-y0)*(x1-x0));
        }

  printf("%jd\n", res);
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int a,b;

int main(){
    cin>>a>>b;
    cout<<a*b<<endl;   
}

Measured memory_bytes: 3636
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	X,Y = MI()
	N3 = (2*Y-X)
	M3 = (2*X-Y)
	if(N3%3!=0 or M3%3!=0 or N3 < 0 or M3<0):
		print(0)
	else:
		N=N3//3
		M=M3//3

		K = min(N,M)

		def cmb(n, r, mod):
			if ( r<0 or r>n ):
				return 0
			r = min(r, n-r)
			return g1[n] * g2[r] * g2[n-r] % mod

		mod = 10**9+7 #出力の制限
		L = 10**6
		g1 = [1, 1] # 元テーブル
		g2 = [1, 1] #逆元テーブル
		inverse = [0, 1] #逆元テーブル計算用テーブル

		for i in range( 2, L + 1 ):
			g1.append( ( g1[-1] * i ) % mod )
			inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
			g2.append( (g2[-1] * inverse[-1]) % mod )

		print(cmb(N+M,K,mod))


main()

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

int N, M, Q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
int ans;

void dfs(vector<int> A) {
  if (A.size() == N+1) {
    int now = 0;
    rep(i, Q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    // cout << now << endl;
    ans = max(ans, now);
    return;
  }
  A.push_back(A.back());
  while (A.back() <= M) {
    dfs(A);
    A.back()++;
  }
}
int main()
{
  cin >> N >> M >> Q;
  a = b = c = d = vector<int>(Q);
  rep(i, Q) {
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }
  dfs(vector<int>(1, 1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#!/usr/bin/env python3

Q = int(input())
my_max = 10 ** 5

nums = [i for i in range(2, my_max + 1)]
p = 2
idx = 0
while p * p <= my_max and idx < len(nums):
    nums = [n for n in nums if n % p != 0 or n == p]
    idx += 1
    p = nums[idx]
primes = set(nums)

ruiseki = [0]
total = 0
for i in range(1, my_max + 1):
    if i % 2 == 1 and i in primes and int((i + 1) / 2) in primes:
        total += 1
    ruiseki.append(total)

for _ in range(Q):
    l, r = map(int, input().split())
    print(ruiseki[r] - ruiseki[l - 1])

Measured memory_bytes: 8092
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string s;
        cin >> s;
        ll apos = inf;
        ll zpos = -inf;
        rep(i, 0, len(s)) {
                if (s[i] == 'A') {
                        apos = i;
                        break;
                }
        }
        repreverse(i, len(s)-1, 0) {
                if (s[i] == 'Z') {
                        zpos = i;
                        break;
                }
        }
        cout << zpos - apos + 1 << endl;
}

Measured memory_bytes: 640
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    private static String solve(Scanner scanner) {
        long N = Integer.parseInt(scanner.nextLine());

        for (long n = 3500; n >= 1; n --) {
            for (long w = 3500; w >= 1; w --) {
                long denom = 4 * n * w - N * w - N * n;
                long numer = N * n * w;

                if (denom > 0 && numer % denom == 0) {
//                    System.out.println(denom);
//                    System.out.println(numer);

                    long h = numer / denom;
                    return n + " " + w + " " + h;
                }
            }
        }

        return null;
    }

    public static void main(String[] args) {
//        tests();

        Scanner scanner = new Scanner(System.in);
        System.out.println(solve(scanner));
    }

    private static String[] testCases = {
            "2",
            "3485",
            "4664"
    };

    private static void tests() {
        for (String t: testCases) {
            System.out.println(solve(new Scanner(testCaseToInputStream(t))));
        }
    }

    private static ByteArrayInputStream testCaseToInputStream(String ex) {
        try {
            return new ByteArrayInputStream(ex.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }

    private static int[] lineToIntNums(String line) {
        String[] numStrs = line.split(" ");
        int[] nums = new int[numStrs.length];
        for (int i = 0; i < nums.length; i ++) {
            nums[i] = Integer.parseInt(numStrs[i]);
        }
        return nums;
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int h, w;
vector<string> s;
int indices[13];

bool check3(vector<string> t)
{
    bool b[w];

    rep(i, w)
    {
        b[i] = false;
    }

    bool pal = false;

    rep(i, w)
    {
        if (b[i])
            continue;

        string revT(t[i]);
        reverse(revT.begin(), revT.end());

        bool discovered = false;
        loop(j, i + 1, w)
        {
            if (revT == t[j])
            {
                b[i] = true;
                b[j] = true;
                discovered = true;
                break;
            }
        }

        if (discovered)
            continue;

        if (pal)
            return false;

        if (t[i] != revT)
            return false;

        pal = true;
    }

    return true;
}

bool check2()
{
    vector<string> ss;
    int ii[h];
    if (h % 2 == 1)
    {
        ii[h / 2] = indices[0];

        rep(i, h / 2)
        {
            ii[i] = indices[i * 2 + 1];
            ii[h - i - 1] = indices[i * 2 + 2];
        }
    }
    else
    {
        rep(i, h / 2)
        {
            ii[i] = indices[i * 2];
            ii[h - i - 1] = indices[i * 2 + 1];
        }
    }

    rep(i, h)
    {
        int index = ii[i];
        ss.push_back(s[index]);
    }

    vector<string> t;
    rep(i, w)
    {
        char c[h + 1];
        c[h] = '\0';
        rep(j, h)
        {
            c[j] = ss[j][i];
        }

        t.push_back(c);
    }
    return check3(t);
}

bool check1(int confirmed)
{
    if (confirmed >= h)
        return check2();

    bool b[h];
    rep(i, h)
    {
        b[i] = false;
    }

    rep(i, confirmed)
    {
        b[indices[i]] = true;
    }

    int first;
    rep(i, h)
    {
        if (b[i])
            continue;

        first = i;
        indices[confirmed] = first;
        break;
    }

    if (confirmed + 1 == h)
    {
        if (check1(confirmed + 1))
            return true;
    }
    else
    {
        loop(i, first + 1, h)
        {
            if (b[i])
                continue;

            indices[confirmed + 1] = i;

            if (check1(confirmed + 2))
                return true;
        }
    }

    return false;
}

bool check()
{
    if (h % 2 == 1)
    {
        rep(i, h)
        {
            indices[0] = i;
            if (check1(1))
                return true;
        }

        return false;
    }
    else
    {
        return check1(0);
    }
}

int main(void)
{
    cin >> h >> w;
    rep(i, h)
    {
        string ss;
        cin >> ss;
        s.push_back(ss);
    }

    if (check())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::BufRead;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}
impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap(); 
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0], tmp_var[1])
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0], tmp_var[1], tmp_var[2])
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());

    let q = input!(r, usize);
    for _ in 0..q {
        let s: Vec<char> = input!(r, String).chars().collect();
        let t: Vec<char> = input!(r, String).chars().collect();
        let mut dp: Vec<Vec<usize>> = vec![vec![0; t.len()+1]; s.len()+1];

        for i in 1..s.len()+1 {
            for j in 1..t.len()+1 {
                if s[i-1] == t[j-1] {
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else {
                    use std::cmp::max;
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }
        println!("{}", dp[s.len()][t.len()]);
    }
}



Measured memory_bytes: 13164
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
	int l[11];
	for(int i=0; i<n; i++){
		cin>>l[i];
	}
	sort(l, l+n);
	int s=0;
	for(int i=0; i<n-1; i++) s+=l[i];
	if(s>l[n-1]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main(){
	string s;
	
	int tmp = 0;
	
	long int N;
	
	long int aux = 1;
	long int men = 1;
	
	//vector <long int> v(N);
	long int sum = 0;
	
	cin >> s;
	
	N = s.length() + 1;
	
	for(long int i = 0; i < N-1; i++){
		if(s[i] == s[i+1] && s[i] == '>'){
			aux++;
			continue;
		} else if(s[i] == '>'){
			sum += (aux*(aux - 1))/2;
			
			sum += max(men, aux);
			men = 1;
			aux = 1;
			continue;
		}
		
		if(s[i] == s[i+1] && s[i] == '<'){
			men++;
			continue;
		} else if(s[i] == '<'){
			sum += (men*(men - 1))/2;
			
			if(i == N-2){
				sum += men;
			}
			continue;
		}
	}	
	
	
	cout << sum << endl;
	return 0;	
}


Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class T>
class Dinic {
    struct edge {
        int to{}, rev{};
        T cap;
        edge() = default;
        edge(int to, T cap, int rev):to(to), cap(cap), rev(rev) {}
    };
    int n{};
    vector<vector<edge>> G;
    vector<int> level, iter;
public:
    Dinic() = default;
    explicit Dinic(int sz): n(sz), G(n), level(n), iter(n){}
    void add_edge(int from, int to, T cap, bool directed){
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, directed?0:cap, G[from].size()-1);
    }

    void bfs(int s){
        fill(level.begin(), level.end(), -1);
        queue<int> Q;
        level[s] = 0;
        Q.emplace(s);
        while(!Q.empty()){
            int v = Q.front(); Q.pop();
            for (auto &&e : G[v]) {
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v]+1;
                    Q.emplace(e.to);
                }
            }
        }
    }

    T dfs(int v, int t, T f){
        if(v == t) return f;
        for (int &i = iter[v]; i < G[v].size(); ++i) {
            edge &e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                T d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T flow(int s, int t, T lim = INF<T>){
        T fl = 0;
        while(true){
            bfs(s);
            if(level[t] < 0 || lim == 0) return fl;
            fill(iter.begin(), iter.end(), 0);
            T f;
            while((f=dfs(s,t, lim))>0){
                fl += f;
                lim -= f;
            }
        }
    }

    bool back_edge(int s, int t, int from, int to){
        for (auto &&e : G[from]) {
            if(e.to == to) {
                if(e.cap == 0 && flow(from, to, 1) == 0){
                    flow(from, s, 1);
                    flow(t, to, 1);
                    return true;
                }
            }
        }
        return false;
    }

};

int main() {
    int h, w;
    cin >> h >> w;
    Dinic<int> flow(h+w+2);
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            if(s[j] == 'S'){
                flow.add_edge(0, i+1, INF<int>, true);
                flow.add_edge(0, h+j+1, INF<int>, true);
            }else if(s[j] == 'T'){
                flow.add_edge(i+1, h+w+1, INF<int>, true);
                flow.add_edge(h+j+1, h+w+1, INF<int>, true);
            }else if(s[j] == 'o'){
                flow.add_edge(i+1, h+j+1, 1, false);
            }
        }
    }
    int ans = flow.flow(0, h+w+1);
    cout << (ans >= MOD ? -1 : ans) << "\n";
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"POSSIBLE":"IMPOSSIBLE")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,m;
	bool ans=false;
	cin >>n>>m;
	vector<vector<int>>path(n);
	int a,b;

	rep(i,m){
		cin>>a>>b;
		a--;
		b--;
		path[a].pb(b);
		path[b].pb(a);
	
	}
	rep(i,n){
		if(!path[i].empty()){
		sort(all(path[i]));
		if(path[i][0]==0 and path[i].back()==n-1){
			ans=true;
		}
		}
		
	}
	cout<<solve(ans)<<endl;
}

Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int n,m,k;
  cin>>n>>m>>k;
  typedef pair<int,int> P;
  map<P,int> mp;
  set<P> ng;
  vector<vector<int> > G(n);
  for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    mp[P(a,b)]=mp[P(b,a)]=c;
    if(c==0){
      ng.insert(P(a,b));
      ng.insert(P(b,a));
    }
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<bool> used(n,0);
  int INF=1e9;
  vector<P> vp;
  vector<int> dp(k+1,-INF);
  dp[0]=0;
  auto get=[&](int a,int b){return mp.count(P(a,b))?mp[P(a,b)]:0;};
  for(int i=0;i<n*2;i++){
    if(used[i%n]||(i<n&&G[i%n].size()>1)) continue;
    vector<int> vi;
    function<void(int,int)> dfs=[&](int v,int p){
      //cout<<v<<" "<<p<<endl;
      if(used[v]) return;
      used[v]=1;
      vi.push_back(v);
      for(int u:G[v]) if(u!=p) dfs(u,v);
    };
    dfs(i%n,-1);
    int vs=vi.size();
    //for(int u:vi) cout<<u<<" ";cout<<endl;
    static int dp2[2][2][2][2002];
    auto fi=[&](int f){
      for(int a=0;a<2002;a++)
	dp2[f][0][0][a]=dp2[f][0][1][a]=dp2[f][1][0][a]=dp2[f][1][1][a]=-INF;
    };
    fi(0);
    dp2[0][0][0][0]=0;
    dp2[0][1][1][1]=0;
    if(vs==2){
      fi(1);
      dp2[1][0][0][0]=0;
      dp2[1][1][1][1]=0;
      if(!ng.count(P(vi[0],vi[1])))
	dp2[1][1][1][2]=get(vi[0],vi[1]);
    }else{
      //vi.push_back(vi[0]);
      for(int a=0;a<vs-1;a++){
	int f=a%2;
	fi(!f);
	for(int b=0;b<2;b++){
	  for(int c=0;c<2;c++){
	    for(int d=0;d<vs;d++){
	      if(dp2[f][b][c][d]==-INF) continue;
	      dp2[!f][b][0][d]=max(dp2[!f][b][0][d],dp2[f][b][c][d]);
	    
	      //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
	      if(c&&ng.count(P(vi[a],vi[a+1]))) continue;
	      int dif=c*get(vi[a],vi[a+1]);
	      if(a+1==vs-1&&b){
		if(ng.count(P(vi[a+1],vi[0]))) continue;
		dif+=get(vi[a+1],vi[0]);
	      }
	      //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
	      //cout<<dif<<endl;
	      dp2[!f][b][1][d+1]=max(dp2[!f][b][1][d+1],dp2[f][b][c][d]+dif);
	    }
	  }
	}
      }
    }
    
    vector<int> dp3(vs+1,-INF);
    for(int a=0;a<=vs;a++)
      dp3[a]=max({dp2[!(vs%2)][0][0][a],
	    dp2[!(vs%2)][0][1][a],
	    dp2[!(vs%2)][1][0][a],
	    dp2[!(vs%2)][1][1][a]});
    
    vector<int> nx(k+1,-INF);
    for(int a=0;a<=vs;a++){
      //cout<<a<<":"<<dp3[a]<<endl;
      for(int j=k-a;j>=0;j--){
	if(dp[j]==-INF) continue;
	nx[j+a]=max(nx[j+a],dp[j]+dp3[a]);
      }
    }
    swap(dp,nx);
  }
  if(dp[k]==-INF) cout<<"Impossible"<<endl;
  else cout<<dp[k]<<endl;
  return 0;
}

Measured memory_bytes: 3732
import qualified Data.IntSet as S
import Control.Monad
import Data.Maybe

main = do
    n <- read <$> getLine
    ss <- map read <$> replicateM n getLine :: IO [Int]
    print . S.findMax . S.insert 0 . S.filter (\n -> mod n 10 /= 0) 
        $ foldr dp (S.singleton 0) ss

dp x set = let
    set' = S.map (+x) set
    in (set `S.union` set')

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n, d, x, y, temp;
  int cnt;
  cin >> n >> d;
  cnt =0;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
        temp = x * x + y * y;
        if (temp <= d*d ) {
        cnt = cnt + 1;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int MOD = 1e9+7;
const int INF = 1e9;
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif


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

  set<int> st;
  rep(i, N) {
    int a; cin >> a;
    st.insert(a);
  }
  if (st.size() == N)
    cout << "YES\n";
  else
    cout << "NO\n";

  return 0;
}


Measured memory_bytes: 9600
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();

        char[][] board = new char[H][W];
        for(int h=0; h<H; h++){
            board[h] = sc.next().toCharArray();
        }

        int[][] dp = new int[H][W];
        dp[0][0] = board[0][0] == '.' ? 0 : 1;
        for(int h=1; h<H; h++){
            dp[h][0] = dp[h-1][0];
            if(board[h-1][0]=='.' && board[h][0]=='#') dp[h][0]++;
        }
        for(int w=1; w<W; w++){
            dp[0][w] = dp[0][w-1];
            if(board[0][w-1]=='.' && board[0][w]=='#') dp[0][w]++;
        }
        for(int h=1; h<H; h++) for(int w=1; w<W; w++){
            int d = board[h-1][w]=='.' && board[h][w]=='#' ? 1+dp[h-1][w] : dp[h-1][w];
            int r = board[h][w-1]=='.' && board[h][w]=='#' ? 1+dp[h][w-1] : dp[h][w-1];
            dp[h][w] = Math.min(d,r);
        }

        System.out.println(dp[H-1][W-1]);
    }
}


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

int h, w;
vector<string> graph;
int dp[100][100];

int dfs(int y, int x) {
	if (y >= h || x >= w) return 1e9;
	if (dp[y][x] != -1) return dp[y][x];
	int r1 = 1e9, r2 = 1e9;
	if (y < h-1) {
		r1 = dfs(y+1, x);
		if (graph[y][x] != graph[y+1][x] && graph[y+1][x] == '#') r1++;
	} 
	if (x < w-1) {
		r2 = dfs(y, x+1);
		if (graph[y][x] != graph[y][x+1] && graph[y][x+1] == '#') r2++;
	} 
	if (y == h-1 && x == w-1) r1 = r2 = 0;
	return dp[y][x] = min(r1, r2);
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> h >> w;
	graph.resize(h);
	for (auto &i : graph) cin >> i;
	memset(dp, -1, sizeof(dp));
	int ans = dfs(0, 0);
	if (graph[0][0] == '#') ans++;
	cout << ans << endl;
}

Measured memory_bytes: 384