akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

#define INF 1e9

int W, H;
int cost[30][30];
bool wall[30][30][4];

void init()
{
	rep(i, 30) rep(j, 30) {
		cost[i][j] = INF;
		rep(k, 4) wall[i][j][k] = true;
	}
}

int main()
{
	cin >> W >> H;
	while (W) {
		init();
		rep(i, W-1) {
			CIN(int, t);
			if (t == 0) {
				wall[0][i][1] = wall[0][i+1][3] = false;
			}
		}
		reps(i, 1, H) {
			rep(j, W) {
				CIN(int, t);
				if (t == 0) {
					wall[i][j][0] = wall[i-1][j][2] = false;
				}
			}
			rep(j, W-1) {
				CIN(int, t);
				if (t == 0) {
					wall[i][j][1] = wall[i][j+1][3] = false;
				}
			}
		}
		cost[0][0] = 1;
		queue<pair<int, int> > q;
		q.push(MP(0, 0));
		while(!q.empty()) {
			auto p = q.front();
			int r = p.first;
			int c = p.second;
			int dr[] = {-1, 0, 1, 0};
			int dc[] = { 0, 1, 0,-1};
			rep(i, 4) {
				int nr = r+dr[i];
				int nc = c+dc[i];
				if (cost[nr][nc] == INF && !wall[r][c][i]) {
					cost[nr][nc] = cost[r][c] + 1;
					q.push(MP(nr, nc));
				}
			}
			q.pop();
		}
		if (cost[H-1][W-1] == INF) cout << 0 << endl;
		else cout << cost[H-1][W-1] << endl;
		cin >> W >> H;
	}
}



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

int main(void)
{
    int n;
    int H_i;
    cin >> n;
    vector<int> aVector;
    for (int i = 0; i < n; i++)
    {
        cin >> H_i;
        aVector.push_back(H_i);
    }
    bool aBoolean = true;
    for (int i = aVector.size() - 2; i >= 0; i--)
    {
        if (aVector[i] <= aVector[i + 1])
        {
        }
        else if (aVector[i] - 1 == aVector[i + 1])
        {
            aVector[i]--;
        }
        else
        {
            aBoolean = false;
            break;
        }
    }
    // for (int i = 0; i < n; i++)
    // {
    //     cout << aVector[i] << endl;
    // }
    
    cout << (aBoolean?"Yes":"No") << endl;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+105;
int ax[maxn],bx[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%d",&ax[i]);
        int l=0,r=n-1,index=n-1,cnt=0;
        while(1)
        {
           if(cnt%2==0)
             bx[l++]=ax[index--];
           else
             bx[r--]=ax[index--];
           cnt++;
           if(n%2==0&&r==(n/2)-1)
             break;
           if(n%2==1&&l==n/2+1)
               break;
        }
        for(int i=0;i<n;i++)
        {
            if(i!=0)
                printf(" ");
            printf("%d",bx[i]);
        }
        printf("\n");
    }


    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2];
int R[MAX / 2 + 2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

void mergesort(int B[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergesort(B, n, left, mid);
		mergesort(B, n, mid, right);
		merge(B, n, left, mid, right);
	}
}

int main()
{
	int C[MAX], n, i;
	cnt = 0;
	cin >> n;
	for (i = 0; i < n; i++) cin >> C[i];

	mergesort(C, n, 0, n);

	for (i = 0; i < n; i++) {
		if (i)cout << " ";
		cout << C[i];
	}
	cout << endl;
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6908
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 10000)
	sc.Buffer(buf, 100000+1024)

	s := readLine(sc)
	sInts := strings.Split(s, "")

	outputValue := 0
	var tileColorNumber string

	for index, sInt := range sInts {
		if index == 0 {
			tileColorNumber = sInt
			continue
		}

		if tileColorNumber == sInt {
			outputValue++
			if tileColorNumber == "0" {
				tileColorNumber = "1"
			} else {
				tileColorNumber = "0"
			}
		} else {
			tileColorNumber = sInt
		}
	}

	fmt.Println(outputValue)
}

// helper

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return strings.TrimSpace(sc.Text())
}

func readLineToInt(sc *bufio.Scanner) int {
	intValue, err := strconv.Atoi(readLine(sc))
	if err != nil {
		panic(err)
	}

	return intValue
}

func explodeString(delimiter string, inputValue string) []string {
	splittedValue := strings.Split(inputValue, delimiter)

	var trimmedValues []string

	for _, value := range splittedValue {
		if value != "" {
			trimmedValues = append(trimmedValues, value)
		}
	}

	return trimmedValues
}

func explodeInt(delimiter string, inputValue string) []int {
	inputStrings := explodeString(" ", inputValue)

	var splittedInts []int

	for _, inputString := range inputStrings {
		var (
			intValue int
			err      error
		)
		intValue, err = strconv.Atoi(inputString)

		if err != nil {
			panic(err)
		}
		splittedInts = append(splittedInts, intValue)
	}

	return splittedInts
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

ll n,m,a,sum=0;
cin>>n>>m;
for(int i=0;i<m;i++)
{
    cin>>a;
    sum+=a;
}
if(n<sum)
{
    cout<<-1<<endl;
}
else
{
    cout<<n-sum<<endl;
}

return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
int c[55];
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int t = m;
    while(m--){
        int a, b;
        cin >> a >> b;
        c[a]++;
        c[b]++;
    }
    for(int i = 1; i <= n; i++){
        cout << c[i] << '\n';
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int D = sc.nextInt();
    int N = sc.nextInt();
    
    int a = 1;
    
    for (int i = 0; i < D; i++) {
      a *= 100;
    }
    
    System.out.println(N == 100 ? a * (N + 1) : a * N);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int s;
    cin >> s;
    int l=s/100, r=s%100;
    if(l>=1 && l<=12) {
        if(r>=1 && r<=12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }else{
        if(r>=1 && r<=12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}



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

int main() {
  string c;
  cin >> c;
  if (c=="a"||c=="i"||c=="u"||c=="e"||c=="o") {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3548
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define itn int
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    int cnt=0;
    int now_i=2;
    vl p;
    while(cnt<N){
        FOR(i,2,sqrt(now_i)+1){
            if(now_i%i==0){
                break;
            }
            if(i==(int)sqrt(now_i)){
                p.pb(now_i);
                cnt++;
            }
        }
        now_i+=5;
    }
    rep(i,N){
        cout << p[i] << ( i==N-1 ? '\n' : ' ' );
    }
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>
#define INF -1
#define N 102
#define white 0
#define gray 1
#define black 2

int q[N],color[N],a[N][N],d[N],n,head=0,tail=0;

void enqueue(int x){
  int next=(tail+1)%N;

  if(head==next){
    printf("Queue overflow!\n");
    exit(2);
  }
  
  q[tail]=x;
  tail=next;
}
int dequeue(void){
  int x;

  if(head==tail){
    printf("Queue is empty!\n");
    exit(3);
  }
  
  x=q[head];
  head=(head+1)%N;
  return x;
}

void bfs(){
  int s=1,i;

  for(i=1;i<=n;i++){
    color[i]=white;
    d[i]=INF;
  }

  color[s]=gray;
  d[s]=0;
  enqueue(s);

  while(head!=tail){
    int u=dequeue();
    for(i=0;i<=n;i++){
      if(a[u][i]&&color[i]==white){
	color[i]=gray;
	d[i]=d[u]+1;
	enqueue(i);
      }
    }
    color[u]=black;
  }
}

void print(){
  int i;
  for(i=1;i<=n;i++) printf("%d %d\n",i,d[i]);
}

int main(){
  int i,j,u,k,v;

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

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      a[u][v]=1;
    }
  }

  bfs();
  print();

  return 0;
}



Measured memory_bytes: 2108
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x,long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var x = Read();
            long n = 1;
            while (true)
            {
                if (n * (n + 1) / 2 >= x) break;
                n++;
            }
            WriteLine(n);

            

            Console.Out.Flush();
        }
    }
}


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

int main(){
  string s;cin>>s;
  bool f=1;
  REP(i,s.size()){
    if(!(i%2)&&s.at(i)!='h') f=0;
    else if(i%2&&s.at(i)!='i') f=0;
  }
  if(s.size()%2) f=0;

  cout<<(f?"Yes":"No");
}


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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int a, b;
void in(){
    cin >> a >> b;
}

void solve(){

    if(b % a == 0){
        print(a + b);
    }else{
        print(b - a);
    }


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll unsigned long long

int main()
{
	int x,y;
	char t;
	cin>>x>>y;

	vector<vector<char> >g(x+2,vector<char>(y+2,'.'));
	auto ans = g;
	for(int i=0;i<x;i++)
	{
		for(int j=0;j<y;j++)
		{
			cin>>g[i][j];
		}
	}

	x+=2;
	y+=2;

	for(int i=0;i<x;i++)
	{
		for(int j=0;j<y-2;j++)
		{
			if(!(g[i][j]=='.'&&g[i][j+1]=='#'&&g[i][j+2]=='.')&&!(g[i][j]=='#'&&g[i][j+1]=='.'&&g[i][j+2]=='#')&&!(g[i][j]=='#'&&g[i][j+1]=='.'&&g[i][j+2]=='.'))
			{
				ans[i][j]=g[i][j];
				ans[i][j+1]=g[i][j+1];
				ans[i][j+2] = g[i][j+2];
			}
		}
	}
	for(int i=0;i<y;i++)
	{
		for(int j=0;j<x-2;j++)
		{
			if(!(g[j][i]=='.'&&g[j+1][i]=='#'&&g[j+2][i]=='.')&&!(g[j][i]=='#'&&g[j+1][i]=='.'&&g[j+2][i]=='#')&&!(g[j][i]=='#'&&g[j+1][i]=='.'&&g[j+2][i]=='.'))
			{
				ans[j][i]=g[j][i];
				ans[j+1][i]=g[j+1][i];
				ans[j+2][i] = g[j+2][i];
			}
		}
	}
	if(ans==g)
		cout<<"Yes";
	else
		cout<<"No";

	system("pause");
	return 0;
}

Measured memory_bytes: 504
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        String S = s.next();
        String T = s.next();
        if(T.length()==S.length()+1)
        {
            if((S+T.charAt(T.length()-1)).equals(T))
                System.out.println("Yes");
            else
                System.out.println("No");
        }
        else
            System.out.println("No");
    }
}


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

bool is_prime(int n)
{
  switch (n)
  {
  case 0:
    return 0;
  case 1:
    return 0;
  case 2:
    return 1;
  }

  if (n % 2 == 0)
    return 0;
  for (int i = 3, s_n = (int)sqrt(n); i <= s_n; i += 2)
  {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main()
{
  int n, ans, i;
  cin >> n;
  i = n;
  while (1)
  {
    if (is_prime(i))
      break;
    i++;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e6;
const int size=1000;
const int INF=1e9;
int N;
vector<int> g[size];
long table[size+1][size+1];
template<typename T>
void pascal(T n){//O(N^2)
	rep(i,0,n+1){
		rep(j,0,i+1){
			if(j==0||j==i) table[i][j]=1;
			else table[i][j]=(table[i-1][j-1]+table[i-1][j])%mod;
		}
	}return;
}

pair<long,int> dfs(int v){
	int n=g[v].size();
    pair<long,int> res[n];
	rep(i,0,n){
		int u=g[v][i];
		res[i]=dfs(u);
	}
	long ans=1;int sum=0;
	rep(i,0,n){
        sum+=res[i].second;
		(ans*=table[sum][res[i].second])%=mod;
        (ans*=res[i].first)%=mod;
	}//cout<<v<<" "<<ans<<" "<<sum+1<<endl;
	return {ans,sum+1};
}
int main(){
	cin>>N;
	int a,b;
	vector<pair<int,int>> match(N-1);
	int lose[N]={};
	rep(i,0,N-1){
		cin>>a>>b;a--;b--;
		match[i]={a,b};
		lose[b]=i+1;
	}
	rep(i,0,N-1){
		a=match[i].first;
		g[lose[a]].push_back(i+1);
	}
    pascal(N);
	cout<<dfs(0).first<<endl;
	return 0;
}


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

int main(){
	int a,b,c,x;
	cin >> a >> b >> c >> x;
	int cnt = 0;
	for(int i = 0;i <= a;i++){
		for(int j = 0;j <= b;j++){
			for(int k = 0;k <= c;k++){
				if(500*i + 100*j + 50*k == x) cnt++;
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
def solve():
    #start here
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0 for i in range(n)]
    for i in range(1, n):
        x = float('inf')
        for j in range(1, 1 + min(k, i)):
            x = min(x, dp[i-j] + abs(h[i]-h[i-j]))
        dp[i] = x
    print(dp[n-1])

solve()

Measured memory_bytes: 90088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ab,n,ans,sum,a[200005];
multiset<ll> s;
multiset<ll>::iterator it;
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		ll x,y,z;
		cin >> y;
		if(y==1){
			cin >> z >> x;
			ans+=x,s.insert(z);
			if(ab==0)it=s.begin(),ab=*it;
			else{
				ll t=ab;
				ans+=abs(z-ab);
				if(z>=ab and sum%2==0)ab=*++it,ans-=ab-t;
				else if(z<ab and sum%2==1)ab=*--it;
			}
			sum++;
		}
		else cout << ab << " " << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>

int main(){
  int x,y,w,h,i;
  double s,w2,h2;
  scanf("%d %d %d %d",&w,&h,&x,&y);
  w2 = (double)w;
  h2 = (double)h;
  if((x==w2/2)&&(y==h2/2))
    i=1;
  else
    i=0;
  printf("%.6f %d",(w2 * h2) / 2.000000,i);
    
}

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

using namespace std;

int n,m,q;
bool dp[100001][12];
vector<int> G[100001];
int color[100001];
int v[100001],d[100001],c[100001];

void dfs(int v, int d, int c) {
  if(dp[v][d]) return;
  
  if(color[v] == 0) color[v] = c;
  
  dp[v][d] = true;
  
  for(int i = 0; i < G[v].size(); i++) {
    if(d > 0){
    dfs(G[v][i],d-1,c);
    dfs(v,d-1,c);
    }
  }
  return;
}

  
int main() {

  cin >> n >> m;

  for(int i = 0; i < m; i++) {
    int a,b;
    cin >> a >> b;

    G[a].push_back(b);
    G[b].push_back(a);
  }

  cin >> q;
  
  for(int i = 0; i < q; i++) cin >> v[i] >> d[i] >> c[i];

  for(int i = q-1; i >= 0; i--) dfs(v[i],d[i],c[i]);
  
  
  for(int i = 1; i <= n; i++) {
    cout << color[i] <<endl;
  }
}

  
  


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


int conv(char c){
  switch(c){
    case 'A':return 0;
    case 'B':return 1;
    case 'C':return 2;
  }
  return 1;
}

int main(){
  bool b[3];
  b[0] = 1;
  b[1] = 0;
  b[2] = 0;
  string s;
  while(cin>>s){
    int swap1,swap2;
    swap1 = conv(s[0]);
    swap2 = conv(s[2]);
    swap(b[swap1],b[swap2]);
  }
  int ans = 0;
  for(int i=0;i<3;i++){
    if(b[i])ans = i;
  }
  switch(ans){
    case 0:
      cout<<"A"<<endl;
      break;
    case 1:
      cout<<"B"<<endl;
      break;
    case 2:
      cout<<"C"<<endl;
      break;
  }

}

Measured memory_bytes: 1176
import sys

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

INF = 10**20
dp = [[[-INF]*2 for _ in range(2)] for _ in range(N+1)]


if N&1:
    dp[0][1][0] = 0
    for i in range(N):
        if i&1:
            dp[i+1][0][0] = max(dp[i][0][0], dp[i][0][1])
            dp[i+1][1][0] = max(dp[i][1][0], dp[i][1][1])
            dp[i+1][1][1] = dp[i][0][0] + A[i]

        else:
            dp[i+1][0][0] = max(dp[i][1][0], dp[i][1][1])
            dp[i+1][0][1] = dp[i][0][0] + A[i]
            dp[i+1][1][1] = dp[i][1][0] + A[i]

    ans = max(dp[N][0][0], dp[N][0][1])            

else:
    dp[0][1][0] = 0
    for i in range(N):
        if i&1:
            dp[i+1][1][0] = dp[i][1][1]
            dp[i+1][1][1] = dp[i][0][0] + A[i]            

        else:
            dp[i+1][0][0] = max(dp[i][1][0], dp[i][1][1])
            dp[i+1][1][1] = dp[i][1][0] + A[i]
    ans = max(dp[N][1][0], dp[N][1][1])

print(ans)

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  int C[555], S[555], F[555];
  rep(i, N - 1) {
    cin >> C[i] >> S[i] >> F[i];
  }

  rep(k, N) {
    int u = 0;
    REP(i, k, N - 1) {
      if (u <= S[i]) {
        u = S[i];
      }
      else {
        u += u % F[i] > 0 ? F[i] - u % F[i] : 0;
      }
      u += C[i];
    }
    cout << u << endl;
  }
  
  return 0;
}

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

int main(){
    vector<int>vec(3);
    cin >> vec[0] >> vec[1] >> vec[2];
    sort(vec.begin() ,vec.end());

    int ans = 0;
    while(!(vec[0] == vec[1] && vec[1] == vec[2])){
        if(vec[1]!=vec[2]){
            vec[0]++;
            vec[1]++;
            ans++;
        }else{
            vec[0] += 2;
            ans++;
        }sort(vec.begin() ,vec.end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,ans; 
char s[102030];

int main()
{
	cin>>n>>(s+1);
    for(int i=2,las=1;i<=n;i++)
    	if(s[i]!=s[las]) ans++,las=i;
    cout<<ans+1<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807



void solve(void)
{
    int N;
    cin>>N;
    vector<int> vec(N,0);
    for (int i = 0; i < N; i++)
    {
        cin>>vec[i];
    }

    for (int i = N-1; i >= 0; i--)
    {
        cout<<vec[i];

        if(i!=0)cout<<" ";

    }

    cout<<endl;
    
    
  return;
}

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

  solve();

  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){

  int a, b, c, k;

  cin >> a >> b >> c >>k;

  int d = max({a, b, c});

  int sum = a + b + c + int(pow(2, k)) * d - d;

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>

using namespace std;

double sq(double x){return x*x;}

int main(){
	int n;
	while(cin>>n){
		vector<int> ans;
		for (int i = 0; i < 10; i++)
		{
			if(n & (1 << i)) ans.push_back(1<<i);
		}
		for (int i = 0; i < (int)ans.size(); i++)
		{
			printf("%d%c",ans[i],(i == (int)ans.size()-1) ? '\n' : ' ');
		}
	}


	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
long long int a[200005], b[4], sadness;
using namespace std;
int main()
{
    long long int n, m = 0;
    cin >> n;
    for ( int i = 1; i <= n; i++ )
    {
        cin >> a[i];
        a[i] = a[i] - i;
    }
    sort(a+1, a+1+n);
    if ( n % 2 == 1 )
    {
        m = a[(n+1)/2];
    }
    else
    {
        m = a[n/2];
    }
    for ( int i = 1; i <= n; i++ )
    {
        sadness = sadness + abs(a[i] - m);
    }
    cout << sadness;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,A[200000],B[200000]={0},ans=0;
    cin>>n;
    rep(i,n) cin>>A[i],B[A[i]]=i+1;
    set<ll> C;
    C.insert(0),C.insert(n+1);
    rep(i,n) ans+=(i+1)*(B[i+1]-(*--C.lower_bound(B[i+1])))*(*C.upper_bound(B[i+1])-B[i+1]),C.insert(B[i+1]);
    cout<<ans;
}

Measured memory_bytes: 12800
// I think of what the world could be, A vision of the one I see, A million dreams is all it's gonna take

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn = 110, mod = 1e9 + 7, inf = 1e9 + 10;

string s[maxn];
int dp[maxn][maxn];

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

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
	cin >> s[i];
    }
    dp[0][0] = s[0][0] == '#';
    for(int i = 0; i < n; i++){
	for(int j = 0; j < m; j++){
	    if(i == 0 && j == 0)
		continue;
	    int A = i == 0 ? inf : (dp[i-1][j] + (s[i][j] == '#' && s[i-1][j] == '.'));
	    int B = j == 0 ? inf : (dp[i][j-1] + (s[i][j] == '#' && s[i][j-1] == '.'));
	    dp[i][j] = min(A, B);
	}
    }
    return cout << dp[n-1][m-1] << "\n", 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define N 200100
#define Inf 100000000000LL
#define ll long long
struct node{
	ll x,y;
	node(){}
	node(ll x,ll y):x(x),y(y){};
}s1[N<<2],s2[N<<2];
ll tag[N<<2],x[N];
void down(ll t){
	if (tag[t]!=0){
		s1[t<<1].y+=tag[t];
		s2[t<<1].y+=tag[t];
		s1[t<<1|1].y+=tag[t];
		s2[t<<1|1].y+=tag[t];
		tag[t<<1]+=tag[t];
		tag[t<<1|1]+=tag[t];
		tag[t]=0;
	}
}
void update(ll t){
	if (s1[t<<1].y-s1[t<<1].x<s1[t<<1|1].y-s1[t<<1|1].x) s1[t]=s1[t<<1]; else s1[t]=s1[t<<1|1];
	if (s2[t<<1].y+s2[t<<1].x<s2[t<<1|1].y+s2[t<<1|1].x) s2[t]=s2[t<<1]; else s2[t]=s2[t<<1|1];
}
void build(ll k,ll l,ll r){
	if (l==r){s1[k]=s2[k]=node(l,Inf); return;}
	ll mid=l+r>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	update(k);
}
void add(ll t,ll l,ll r,ll L,ll R,ll k){
	if (L<=l && r<=R){
		s1[t].y+=k;	s2[t].y+=k;	tag[t]+=k;
		return;
	}
	down(t);
	ll mid=l+r>>1;
	if (L<=mid) add(t<<1,l,mid,L,R,k);
	if (R>mid) add(t<<1|1,mid+1,r,L,R,k);
	update(t);
}
ll get1(ll t,ll l,ll r,ll L,ll R){
	if (L<=l && r<=R){return s1[t].y-s1[t].x;}
	down(t);
	ll mid=l+r>>1,ans=Inf*10;
	if (L<=mid) ans=min(ans,get1(t<<1,l,mid,L,R));
	if (R>mid) ans=min(ans,get1(t<<1|1,mid+1,r,L,R));
	return ans;
}
ll get2(ll t,ll l,ll r,ll L,ll R){
	if (L<=l && r<=R)return s2[t].y+s2[t].x;
	down(t);
	ll mid=l+r>>1,ans=Inf*10;
	if (L<=mid) ans=min(ans,get2(t<<1,l,mid,L,R));
	if (R>mid) ans=min(ans,get2(t<<1|1,mid+1,r,L,R));
	return ans;
}
ll get(ll t,ll l,ll r){
	if (l==r){return s1[t].y;}
	down(t);
	ll mid=l+r>>1;
	return min(get(t<<1,l,mid),get(t<<1|1,mid+1,r));
}

int main(){
	ll n,a,b,Q;
	scanf("%lld%lld%lld%lld",&n,&Q,&a,&b);
	x[0]=a;
	for (ll i=1;i<=Q;i++)
		scanf("%lld",&x[i]);
	build(1,1,n);
	add(1,1,n,b,b,-Inf);
	get(1,1,n);
	for (ll i=1;i<=Q;i++){
		ll t1=get1(1,1,n,1,x[i])+x[i],t2=get2(1,1,n,x[i],n)-x[i];
		ll tmp=min(t1,t2);
		add(1,1,n,1,n,abs(x[i]-x[i-1]));
		ll t3=get1(1,1,n,x[i-1],x[i-1])+x[i-1];
		if (tmp<t3) add(1,1,n,x[i-1],x[i-1],tmp-t3);
	}
	printf("%lld\n",get(1,1,n));
	return 0;
}


Measured memory_bytes: 27008
words = lambda t : list(map(t, input().split()))
n = int(input())
xs = []
fst = 0
snd = 0
for i in range(n):
    x = int(input())
    xs.append(x)
    if x > fst:
        t = fst
        fst = x
        x = t
    if x > snd:
        snd = x

for a in xs:
    if a == fst:
        print(snd)
    else:
        print(fst)


Measured memory_bytes: 12532
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>
#include <numeric>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double

#ifdef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
#define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
#endif

#ifndef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
#define finish return 0
#endif

using namespace std;


//vector input
template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &i : vec) {
        cin >> i;
    }
    return is;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}

int n, k;
vector<int> a;

bool can(int len) {
    int amount = 0;
    for (int i = 0; i < n; ++i) {
        int el = a[i];
        amount += (el + len - 1) / len - 1;
        if (amount > k) {
            return false;
        }
    }
    return amount <= k;
}


int32_t main() {
    start;


    cin >> n >> k;

    a.resize(n);
    int sum = 0;
    int mx = 0;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
        if (mx < a[i]) {
            mx = a[i];
        }
    }

//    sort(a.rbegin(), a.rend());

    int l = max(0ll, sum / (n + k) - 1);
    int r = mx;

    while (r != l + 1) {
        int m = (l + r) / 2;
        if (can(m)) {
            r = m;
        } else {
            l = m;
        }
    }

    cout << r << '\n';

    finish;
}

Measured memory_bytes: 4692
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k;
	vector<int> v(5);
	for(int i=0;i<5;i++){
		cin >> v.at(i);
	}
	cin >> k;
	bool flag = true;
	for(int i=0;i<4;i++){
		for(int j=i+1;j<5;j++){
			if(v.at(j)-v.at(i) > k){
				flag = false;
			}
		}
	}
	if(flag) cout << "Yay!" << endl;
	else cout << ":(" << endl;

}	


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]

    inis = [s[0] for s in S if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H']
    c = Counter(inis)
    ans = 0
    for tpl in list(combinations(c.values(), 3)):
        ans += list(accumulate(tpl, mul))[-1]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17656
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    string s, t; cin >> s >> t;

    int count = 0;
    FOR(i, 0, s.size()) {
        if (s[i] != t[i]) ++count;
    }
    cout << count << endl;
}

signed main() {
    solve();
    return 0;
}

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

int main(){
  long long n;
  cin >> n;
  long long ans = n-1;
  for (long long  i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      long long x = n/i + i -2;
      if (ans > x) ans = x;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
n=int(input())
job=[]
for i in range(n):
    a,b=map(int,input().split())
    job.append((a,b))
job=sorted(job,key=lambda x : x[1])
# print(job)
load=0
for cost,limit in job:
    load+=cost
    if load>limit:
        print("No")
        import sys 
        sys.exit()
print("Yes")

Measured memory_bytes: 75992
def acinput():
    return list(map(int, input().split(" ")))


N = int(input())
H = acinput()

dp=[0]*N
for i in reversed(range(N-1)):
    if H[i] >= H[i+1]:
        dp[i] = dp[i+1]+1
    else:
        dp[i] = 0

import numpy as np
print(np.max(dp))



Measured memory_bytes: 21400
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    int flag=0;//0は高橋
    for(int i=0;i<k;i++){
        if(flag==0){
            if(a%2==0){
                b+=a/2;
                a/=2;
            }else{
                a--;
                b+=a/2;
                a/=2;
            }
            flag=1-flag;
        }else if(flag==1){
            if(b%2==0){
                a+=b/2;
                b/=2;
            }else{
                b--;
                a+=b/2;
                b/=2;
            }
            flag=1-flag;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	vector<vector<double>> x(n, vector<double>(d));
	int cnt = 0;

	rep(i, n)
	{
		rep(j, d)
		{
			cin >> x[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			double tmp = 0;

			for (int k = 0; k < d; k++)
				tmp += pow(x[i][k] - x[j][k], 2);

			if (sqrt(tmp) == ceil(sqrt(tmp))) cnt++;
		}
	}
	ANS(cnt);
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  int b[100002]={};
  int c[100002]={};

  for(int i=0;i<n;i+=2){
    b[a[i]]++;
  }
  for(int i=1;i<n;i+=2){
    c[a[i]]++;
  }

  int mb=0,mc=0;
  int ib=0,ic=0;
  for(int i=1;i<=100000;i++){
    if(mb<b[i]) ib=i;
    if(mc<c[i]) ic=i;
    mb=max(mb,b[i]);
    mc=max(mc,c[i]);
  }
  if(ib!=ic) cout<<n-mb-mc<<endl;
  else{
    int mb1=0,mc1=0;
    int ib1=0,ic1=0;
    for(int i=1;i<=100000;i++){
      if(i!=ib){
        if(mb1<b[i]) ib1=i;
        mb1=max(mb1,b[i]);
      }

      if(i!=ic){
        if(mc1<c[i]) ic1=i;
        mc1=max(mc1,c[i]);
      }
    }
    //cout<<mc1<<" "<<mb1<<endl;
    if(mc1<mb1){
      cout<<n-mc-mb1<<endl;
    }else{
      cout<<n-mb-mc1<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
    if p[i-1] > p[i] and p[i] > p[i+1]:
        ans += 1
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
# xより小さい料金所と大きい料金所の数をかぞえたら終了
left = 0
right = 0
for a in A:
  if a < x:
    left += 1
  else:
    right += 1
print(min(left,right))

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

typedef long long ll;

int n, sum;
string s;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'I')
            ++sum;
        else
            --sum;
        ans = max(ans, sum);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           (long long)1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }


template<typename T>
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

void solve(){
    int n; cin>>n;
    int a[n];
    vector<int> suff(n);
    FOR(i, 0, n) cin>>a[i];
    suff[n-1] = a[n-1];
    for(int i=n-2;i>=0;i--) {
        suff[i] = (suff[i+1]+a[i])%inf;
    }
    int res=0;
    FOR(i, 0, n-1) {
        res = (res + (a[i] % inf * (suff[i+1])%inf )%inf)%inf;
    }
    cout<<res;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);     
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){ 
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
 
}

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

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=2000+5,inf=N*10;
char qa[N*2],*a=qa+N,b[N];
int need[N],need2[N],q[N],nq[N];
int ans=inf;
int n;

bool need_xiao(int a,int b)
{
	return need[a]<need[b];
}

void solve(char *a)
{
	need[0]=inf;
	rep(i,1,n)need[i]=b[i]=='1'?0:need[i-1]+1;
	need[0]=need[n];
	rep(i,1,n)need[i]=b[i]=='1'?0:need[i-1]+1;
	need2[n+1]=inf;
	per(i,n,1)need2[i]=b[i]=='1'?0:need2[i+1]+1;
	need2[n+1]=need2[1];
	per(i,n,1)need2[i]=b[i]=='1'?0:need2[i+1]+1;
	rep(i,1,n)q[i]=i;
	sort(q+1,q+n+1,need_xiao);
	need[0]=0;
	rep(tmp,0,n-1)
	{
		int top=0;
		rep(i,1,n)
		if(a[q[i]]!=b[q[i]])nq[++top]=q[i];
		int suf=0,mn=max(0,need[nq[top]]-tmp);
		per(i,top,1)
		{
			if(suf<need2[nq[i]])suf=need2[nq[i]];
			if(mn>max(0,need[nq[i-1]]-tmp)+suf)mn=max(0,need[nq[i-1]]-tmp)+suf;
		}
		chmin(ans,tmp+top+mn*2);
		a[0]=a[n];
		--a;
	}
}

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%s%s",a+1,b+1);n=strlen(a+1);
	solve(a);
	reverse(a+1,a+n+1);reverse(b+1,b+n+1);
	solve(a);
	if(ans==inf)puts("-1");
	else cout<<ans;
}

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

#define INF 1<<20



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

    vector<int> c_v(n);
    vector<vector<int>> a_v(n, vector<int>(m,0));
    
    int s;
    for (int i=0; i<n; i++){
        cin >> s;
        c_v[i] = s;
        for(int j=0; j<m; j++){
            cin >> s;
            a_v[i][j] = s;
        }
    }
    int money, ans;
    ans = 10000000;
    for (int bit=1; bit < (1<<n); bit++){
        money = 0;
        bool tmp;
        tmp = false;
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                S.push_back(i);
            }
        }
        vector<int> x_v(m, x);
        for (int i = 0; i < (int)S.size(); ++i) {
            for (int j=0; j<m; j++){
                x_v[j] = x_v[j] - a_v[S[i]][j];
            }
            money += c_v[S[i]];
        }
        int i;
        for (int i=0; i<m; ++i) {
            if(x_v[i]>0) {
                tmp = true;
                break;
            }
        }
        if(tmp) continue;
        ans = min(money, ans);
    }
    if (ans == 10000000) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<vector<lli> > vvi;
typedef vector<ii> vii;
 
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define FF first
#define SS second

lli mod = 1e9 +7;
lli n, arr[410][410], inp[410], presum[410];

lli dp(int l, int r)
{
	if(arr[l][r]<1e18) return arr[l][r];
	else if(l==r) return arr[l][r]=0;
	else
	{
		for(int i=l; i<r; i++)
			arr[l][r] = min(dp(l,i)+dp(i+1,r)+presum[r]-presum[l-1], arr[l][r]);
		return arr[l][r];
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	for(int i=0; i<410; i++)
	{
		for(int j=0; j<410; j++)
			arr[i][j]=1e18;
	}
	cin >> n;
	for(int i=1; i<=n; i++)
		cin >> inp[i], presum[i]=presum[i-1]+inp[i];
	cout << dp(1, n)<<'\n';
}

Measured memory_bytes: 5012
def main():
    N, *ABCnum = (int(i) for i in input().split())
    l = [int(input()) for _ in range(N)]
    ans = 10 ** 6
    from itertools import product
    for pattar in product(range(4),repeat=N):
        ABC = [[] for i in range(3)]
        for i,g in enumerate(pattar):
            if g == 0:
                ABC[0].append(l[i])
            elif g == 1:
                ABC[1].append(l[i])
            elif g == 2:
                ABC[2].append(l[i])
        cur = 0
        if not ABC[0] or not ABC[1] or not ABC[2]:
            continue
        for i in range(3):
            cur += abs(ABCnum[i] - sum(ABC[i])) + 10*(len(ABC[i]) - 1)
        ans = min(ans,cur)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 49884