akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define isFile 0
#define NAME "taskA"
#define scan 1
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;

#define mp make_pair
#define pb push_back
#define fr first
#define sc second

#define ins insert
#define all(v) v.begin(), v.end()
#define rep(i,a,n) for (int i=a;i<n;i++)
#define bit(n, i) (n >> i) & 1
#define bpc(x) __builtin_popcountll(x)
#define rev(a) reverse(all(a))
#define skip continue
#define read(a) for(auto &i : a) cin >> i
#define print(a) for(auto i : a) cout << i << ' '
#define unique(a) sort(all(a));    a.resize(unique(all(a)) - a.begin())

//                D  R  U   L
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void faster() {
    if (isFile) {
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    if (scan) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
}

const ll  INF = 1e18;
const int inf = 2e9;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ld  PI = acos(-1);
const ld  EPS = 3E-16;
const int ALPHA = 27;
const int N = (int)3e3 + 5;
const int M = 123;

string s, t;
int dp[N][N];
// dp[i][j] - lcs for the first i characters of the first string
// and for the first j characters of the second string

void solve() {
    cin >> s >> t;
    int n = (int)s.size(), m = (int)t.size();
    int last_i = -1, last_j = -1;
    int ans = -1;

    for(int j = 1; j <= m; j++) {
        for(int i = 1; i <= n; i++) {
            if (t[j - 1] == s[i - 1]) {
                if (dp[i][j] < dp[i - 1][j - 1] + 1) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
            if (dp[i][j] > ans) {
                ans = dp[i][j];
                last_i = i;
                last_j = j;
            }
        }
    }

    string res = "";
    while(last_i && last_j) {
        if (dp[last_i][last_j] == dp[last_i - 1][last_j]) {
            last_i--;
        } else
        if (dp[last_i][last_j] == dp[last_i][last_j - 1]) {
            last_j--;
        } else {
            last_i--;
            last_j--;
            res += s[last_i];
        }
    }

    rev(res);
    cout << res << endl;
}

int main() {
    faster();
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <stack>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
vector<string> split(const string &s, char c);
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, q, cnt = 0;
void search(int num, int memo[10001]){
	rep(i,n){
		if(memo[i]==num){
			cnt++;
			break;
		}
	}
}

int main(void){
	int memo[10001];
	fill_n(memo, 10001, 0);
	cin >> n;
	rep(i,n)cin >> memo[i];
	cin >> q;
	rep(i,q){
		int a;
		cin >> a;
		search(a,memo);
	}
	cout << cnt << endl;
	return 0;
}

int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (int i = 0; i < s.size(); i++) {
    	char ch = s[i];
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

Measured memory_bytes: 1208
import math
def ip():return int(input())
def inp():return map(int,input().split())
def inpstr():return map(str,input().split())
def linp():return list(map(int,input().split()))
def linpstr():return list(map(str,input().split()))

yen=0
coin=0
ans=0
for _ in range(ip()):
    x,u=inpstr()
    x=float(x)
    if u=="BTC":x=x*380000.0
    ans+=x
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  if(a>=b*2-1){
    cout<<"YES"<<'\n';
  }
  else cout<<"NO"<<'\n';
  return 0;
}


Measured memory_bytes: 256
def main():
    l, r = map(int, input().split())
    ans = solve(l, r)
    print(ans)


def solve(l, r):
    N = 2019

    r = min(r, l+N)

    ans = N
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, (i*j)%N)
    return ans


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int h = 3, w = 3;
    int c[h][w];
    rep(i, h){
        rep(j, w) cin >> c[i][j];
    }
    int a[h], b[w];
    a[0] = 0;
    rep(i, w) b[i] = c[0][i] - a[0];
    rep(i, h) a[i] = c[i][0] - b[0];
    bool is = true;
    rep(i, h){
        rep(j, w){
            if(a[i] + b[j] != c[i][j]) is = false;
        }
    }
    if(is) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
int main(){
    string s;
    std::cin >> s;
    int n=s.size();
    int x,y;
    std::cin >> x>>y;
    std::vector<int> a,aa;
    int c=0,cc=0;
    rep(i,n){
        if(s[i]=='F')cc++;
        else{
            if(c%2==0)a.pb(cc);
            else aa.pb(cc);
            cc=0;
            c++;
            
        }
    }
    if(c%2==0)a.pb(cc);
    else aa.pb(cc);
    int a0=a[0];
    a.erase(a.begin());
    vvector(dp,bool,a.size()+1,16001,0);
    vvector(ddp,bool,aa.size()+1,16001,0);
    ddp[0][8000]=1;
    dp[0][8000+a0]=1;
    rep(i,a.size()){
        rep(j,16001){
            if(dp[i][j]){
                if(j+a[i]<=16000)dp[i+1][j+a[i]]=1;
                if(j-a[i]>=0)dp[i+1][j-a[i]]=1;
            }
        }
    }
    rep(i,aa.size()){
        rep(j,16001){
            if(ddp[i][j]){
                if(j+aa[i]<=16000)ddp[i+1][j+aa[i]]=1;
                if(j-aa[i]>=0)ddp[i+1][j-aa[i]]=1;
            }
        }
    }
    if(dp[a.size()][8000+x]&&ddp[aa.size()][8000+y])std::cout << Yes << std::endl;
    else std::cout << No << std::endl;
}






Measured memory_bytes: 16256
#include<iostream>
using namespace std;
int main(void)
{
    int p1,p,dr1,dr;
    for(int i=0;i<2;i++){
        if(i==0)cin>>p1;
        cin>>p;
        if(p1>p)p1=p;
    }
    cin>>dr1>>dr;
    if(dr1>dr)dr1=dr;
    cout<<p1+dr1-50<<"\n";
}

Measured memory_bytes: 1168
/*Program from Luvwgyx*/
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
int n,m,cnt;
vector<int >v[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
struct Binary_Index_Tree{
    int tree[maxn];
    void change(int x,int v){for(;x<=m;x+=(x&(-x)))tree[x]+=v;}
    int  query (int x){int ret=0;for(;x;x-=(x&(-x)))ret+=tree[x];return ret;}
}T;
int main(){
    cnt=n=read();m=read();
    for(int i=1;i<=n;i++){
        int l=read(),r=read();
        v[r-l+1].push_back(l);
    }
    for(int i=1;i<=m;i++){
        int ans=cnt;
        for(int j=i;j<=m;j+=i)ans+=T.query(j);
        for(vector<int > :: iterator it=v[i].begin();it!=v[i].end();it++)
            T.change(*it,1),T.change(*it+i,-1),--cnt;
        write(ans);
    }
    return 0;
}


Measured memory_bytes: 6784
import java.util.*;

class Main {
public static void main(String[] args) {
 Scanner stdIn = new Scanner(System.in);
  String a = stdIn.next();
  String b = stdIn.next();
  String ab = a + b;
  int c = Integer.parseInt(ab);
  int i = 1;
  
  for(i = 1; i < c; i++) {
    if(i * i == c) break;
  }
  if(i != c) System.out.println("Yes");
  else System.out.println("No");
}
}

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


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

    int H,M;
    cin >> H >> M;
    char a[H][M];
    rep(i,H){
        rep(j,M){
            cin >> a[i][j];
        }
    }
    bool z[H],z1[M];
    rep(i,H) z[i]=false;
    rep(i,M) z1[i]=false;
    rep(i,H){
        rep(j,M){
            if(a[i][j]=='#') {
                z[i]=true;
                z1[j]=true; 
            }
        }
    }
    rep(i,H){
        if(z[i]){
            rep(j,M){
                if(z1[j]){
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }


}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

// auto mod int
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi cnt(3);
    mint ans = 1;
    rep(i, n) {
        int can = 0;
        rep(j, 3) {
            if (cnt[j]==a[i]) ++can;
        }
        ans *= can;
        rep(j, 3) {
            if (cnt[j]==a[i]) {
                cnt[j]++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3772
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	c := intSliceScanner(26)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = intSliceScanner(26)
	}
	best := -mod
	bestSchedule := make([]int, d)
	for x := 0; x < 1; x++ {
		schedule := make([]int, d)
		for i := 0; i < d; i++ {
			schedule[i] = rand.Intn(26)
		}
		score := calcScore(schedule, c, s, d)
		for y := 0; y < 100000; y++ {
			change := rand.Intn(d)
			val := rand.Intn(26)
			pre := schedule[change]
			schedule[change] = val
			nextScore := calcScore(schedule, c, s, d)
			t = float64(score) * 0.1
			if prob(score, nextScore) >= math.Abs(rand.Float64()) {
				score = nextScore
			} else {
				schedule[change] = pre
			}
			if nextScore >= best {
				best = nextScore
				copy(bestSchedule, schedule)
			}
			t *= 0.9999
		}
	}
	for i := 0; i < d; i++ {
		fmt.Println(bestSchedule[i] + 1)
	}
}
func calcScore(schedule []int, c []int, s [][]int, d int) int {
	score := 0
	last := make([]int, 26)
	for i, v := range schedule {
		score += s[i][v]
		for j, _ := range last {
			last[j]++
		}
		last[v] = 0
		for j, v := range last {
			score -= c[j] * v
		}
	}
	return score
}
func prob(before int, after int) float64 {
	if before <= after {
		return 1.0
	}
	return math.Exp((float64(after) - float64(before)) / float64(t))
}


Measured memory_bytes: 1976
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_156
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nr = ReadInts();
            int n = nr[0];
            int r = nr[1];
            WriteLine(n <= 10 ? r + 100 * (10 - n) : r);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define maxn 4086 
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;

inline ll read(){
	ll x = 0, f = 1;char ch = getchar();
	while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
	return x * f;
}
int t, n;
int dp[705][2005],sum[2006];
int main(){
	int i, j, x, mx,k;
	n = read();
	dp[0][0] = 1;
	for(i = 0;i <= 2000;i++) sum[i] = 1;
	for(i = 1;i <= 700;i++){
		for(j = 1;j <= n;j++) dp[i][j] = sum[j - 3] % mod;
		sum[0] = 0;
		for(j = 1;j <= n;j++) sum[j] = (sum[j - 1] + dp[i][j] ) % mod;
	}
	int ans = 0;
	for(i = 1;i <=700;i++) ans = (ans + dp[i][n]) % mod;
	cout<<ans;
}

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

int main()
{
	int n,i,f=0,ff=0;
	cin>>n;
	int a[n+5];
	for(i=1;i<=n;i++)
	   cin>>a[i];
	   
	for(i=1;i<=n;i++)
	   if(a[i]%2==0){
	   	 if(a[i]%3==0||a[i]%5==0){
	   	   f=1;
	     }
	     else{
	       ff=1;
	     }
	   }
	   
	if(ff==1)
	  cout<<"DENIED";
	else
	  cout<<"APPROVED";
	
	return 0;
	
}

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

int main() {
  int N;
  cin >> N;
  int p = sqrt(N*2);
  if (p*(p+1)/2 < N && N <= (p+1)*(p+2)/2) {
    p++;
  }
  int sum = p*(p+1)/2;
  int cut = sum - N;
  for (int i=1; i<p+1; i++) {
    if (i == cut) {
      continue;
    }
    cout << i << endl;
  }
  
    
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    private static final int INF = (int)1e9 + 7;

    int A,B,C;

    int[][][] dp;

    private void solve() {
        A = nextInt();
        B = nextInt();
        C = nextInt();

        dp = new int[260][260][260];
        for(int i = 0;i < 260;i++) {
            for(int j = 0;j < 260;j++) {
                for(int k = 0;k < 260;k++) {
                    dp[i][j][k] = INF;
                }
            }
        }

        dp[A][B][C] = 0;
        for(int i = 0;i < 250;i++) {
            for(int j = 0;j < 250;j++) {
                for(int k = 0;k < 250;k++) {
                    dp[i+1][j+1][k] = Math.min(dp[i+1][j+1][k],dp[i][j][k] + 1);
                    dp[i+1][j][k+1] = Math.min(dp[i+1][j][k+1],dp[i][j][k] + 1);
                    dp[i][j+1][k+1] = Math.min(dp[i][j+1][k+1],dp[i][j][k] + 1);
                    dp[i+2][j][k] = Math.min(dp[i+2][j][k],dp[i][j][k] + 1);
                    dp[i][j+2][k] = Math.min(dp[i][j+2][k],dp[i][j][k] + 1);
                    dp[i][j][k+2] = Math.min(dp[i][j][k+2],dp[i][j][k] + 1);
                }
            }
        }

        int ans = INF;
        for(int i = 0;i < 260;i++) {
            ans = Math.min(ans,dp[i][i][i]);
        }

        out.println(ans);
    }
    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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

Measured memory_bytes: 131724
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int D;
vector<int64_t> C(26);
vector<vector<int64_t>> S(D, vector<int64_t>(26));

int64_t calcScore(vector<int>& T) {
  int64_t ret = 0;
  vector<int> Last(26, 0);
  rep(i, D) {
    Last[T[i]] = i + 1;
    int64_t down = 0;
    rep(j, 26) { down += C[j] * (i + 1 - Last[j]); }
    ret += S[i][T[i]] - down;
  }
  return ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin >> D;
  C.resize(D);
  rep(i, 26) cin >> C[i];
  S.resize(D);
  rep(i, D) {
    S[i].resize(26);
    rep(j, 26) cin >> S[i][j];
  }
  vector<int> T(D);
  rep(i, D) {
    cin >> T[i];
    --T[i];
  }

  int M;
  cin >> M;
  rep(i, M) {
    int d, q;
    cin >> d >> q;
    --d;
    --q;
    T[d] = q;
    cout << calcScore(T) << endl;
  }
  return 0;
}


Measured memory_bytes: 3700
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 5000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int a[N];
int dp[N];
int main() {
    int n,k;
    scanf("%d%d",&n,&k);
    int sum=0;
    for(int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        a[i]=min(a[i],k);
        sum+=a[i];
    }
    sort(a+1,a+n+1+1);

    dp[0]=1;
    for(int i=n+1; i>0; i--) {
        bool flag=true;
        for(int j=k-1; j>=k-sum&&j>=0; j--){
            if(dp[j]){
                flag=false;
                break;
            }
        }
        if(flag) {
            printf("%d",i-1);
            break;
        }
        for(int j=k; j>=a[i]; j--)
            dp[j]|=dp[j-a[i]];
        sum-=a[i];
    }
    return 0;
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

vector<int>E[200000];
int d[200000];
int d2[200000];

void dfs(int v,int p){
	if(p!=-1)d[v]=d[p]+1;
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
	}
}

void dfs2(int v,int p){
	if(p!=-1)d2[v]=d2[p]+1;
	for(int u:E[v]){
		if(u==p)continue;
		dfs2(u,v);
	}
}

int main(){
	int n,a,b;cin>>n>>a>>b;a--;b--;
	rep(i,n-1){
		int u,v;scanf("%d%d",&u,&v);u--;v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(a,-1);
	dfs2(b,-1);
	int Max=0;
	rep(i,n){
		if(d[i]<d2[i]){
			Max=max(Max,d2[i]);
		}
	}
	cout<<Max-1<<endl;
}

Measured memory_bytes: 12672
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int z,a,f = 0;
	double x,y,c,min,d,e;
	scanf("%d",&z);
	scanf("%lf %lf",&x,&y);
	for(a = 0;a < z;a++)
	{
		scanf("%lf",&c);
		d = x -(c * 0.006);
		e = fabs(d - y);
		if (a == 0) min = e;
		else if (min > e) 
		{
			min = e;
			f = a;
		}
	}
	printf("%d\n",f+1);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define fr(a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define triplet pair<int,pair<int,int>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

double dp[3000][3000];
double magic(vector<double>& bias, int i, int heads)
{
    if(heads < 0)
        return 0;
    
    if(i == -1 && heads == 0)
        return 1;

    if(i == -1)
        return 0;

    if(dp[i][heads] >= 0)
        return dp[i][heads];

    double p1 = bias[i] * magic(bias, i - 1, heads - 1);
    double p2 = (1 - bias[i]) * magic(bias, i - 1, heads);

    return dp[i][heads] = p1 + p2;
}
int main(){
    ll i,j,t,n,m,p,k;
    fast_io;
    t = 1;
    //cin>>t;
    while(t--)
    {
        cin>>n;
        memset(dp, -1, sizeof dp);
        double ans = 0;
        vector<double> coins(n);
        fr(0,n)cin>>coins[i];
        int reqHeads = n/2 + 1;
        while(reqHeads <= n)
            ans += magic(coins, coins.size() - 1, reqHeads++);
        cout<<fixed<<setprecision(9)<<ans;
    }
    return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){    ;
int main() {
 char b;
 cin>>b;
 if(b=='A'){
     cout<<"T"<<endl;
 }
 else if(b=='T'){
     cout<<"A"<<endl;
 }
 else if(b=='C'){
     cout<<"G"<<endl;
 }
 else if(b=='G'){
     cout<<"C"<<endl;
 }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  int MAX=1000*100+1;
  cin>>N;
  int m[MAX]={0};
  REP(i,N){
    int a;
    cin>>a;
    m[a]+=1;
  }
  int ans=0;
  FOR(x,1,MAX-1){
    int temp=m[x-1]+m[x]+m[x+1];
    if(temp>ans)ans=temp;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int p[n];
  rep(i,n)cin >> p[i];
  rep(i,n)p[i]--;
  int ind[n];
  rep(i,n)ind[p[i]]=i;
  set<int> s;
  ll ans = 0;
  drep(i,n){
    s.insert(ind[i]);
    auto it = s.find(ind[i]);
    ll c = 0;
    {
      vector<ll> l(2,-1);
      vector<ll> r(2,n);
      auto itl = it;
      auto itr = it;
      rep(j,2){
        if(itl==s.begin())break;
        itl--;
        l[j]=*itl;
      }
      rep(j,2){
        itr++;
        if(itr==s.end())break;
        r[j]=*itr;
      }
      c = (l[0]-l[1])*(r[0]-*it)+(*it-l[0])*(r[1]-r[0]);
    }
    ans += c*(i+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 8552
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 100005;

int n, m, u, v, w, ans = 0, sz[N];
long long dsu[N];

struct SEdge
{
    int u, v;
    long long w;
};
vector<SEdge> ed, tr;
vector<pair<int, long long>> ch;

int trace(int u)
{
    return dsu[u] < 0 ? u : trace(dsu[u]);
}

bool unity(SEdge cur)
{
    if ((cur.u = trace(cur.u)) == (cur.v = trace(cur.v)))
        return false;
    if (sz[cur.u] < sz[cur.v])
        swap(cur.u, cur.v);
    ch.push_back(make_pair(cur.v, dsu[cur.v]));
    sz[cur.u] += sz[cur.v];
    dsu[cur.u] += dsu[cur.v];
    dsu[cur.v] = cur.u;
    return true;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", dsu + i);
        dsu[i] = -dsu[i];
      	sz[i] = 1;
    }
    while (m--)
    {
        scanf("%d%d%d", &u, &v, &w);
        ed.push_back((SEdge){u, v, w});
    }
    sort(ed.begin(), ed.end(), [](const SEdge &a, const SEdge &b) {
        return a.w < b.w;
    });
    for (SEdge &v : ed)
        if (unity(v))
            tr.push_back(v);
    for (int i = n - 2; i >= 0; i--)
    {
        SEdge cur = tr[i];
        int u = trace(cur.u);
        if (-dsu[u] < cur.w)
            dsu[u] -= (dsu[ch[i].first] = ch[i].second);
    }
    for (SEdge &v : ed)
        if (trace(v.u) != trace(v.v) || -dsu[trace(v.u)] < v.w)
            ans++;
    printf("%d", ans);
}


Measured memory_bytes: 7920
#include<iostream>
int w,h,d[5]={1,0,-1,0,1},i,j,M,Y,X;std::string s[50];int r(int y,int x){if(s[y][x]!=41&&s[y][x]!=20)s[y][x]|=M;for(int i=0;i<5;){Y=y+d[i];X=x+d[++i];if(Y<0||h<=Y||X<0||w<=X||s[Y][X]==41||s[Y][X]==20||(s[Y][X]&M)==M)continue;r(Y,X);}}main(){for(;std::cin>>w>>h,w|h;printf("%d %d\n",X,Y)){for(M=i=0;i<h;i++)for(std::cin>>s[i],j=w;j-->0;)s[i][j]-=46;for(i=h;i-->0;)for(j=w;j-->0;M=2*(X==41)+(X==20),M&&r(i,j))X=s[i][j];for(X=Y=i=0;i<h;i++)for(j=w;j-->0;s[i][j]==2&&Y++)s[i][j]==1&&X++;}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <map>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


char data[10010];
int poll[10010];
int sum[10010];

int main(){
    int z;
    cin >> z;
    for(int zz = 0;zz < z;zz++){
        cin >> data;
        int count = 0,k = 0;
        for(int i = 0;i < strlen(data);i++){
            if(data[i] == '['){
                k++;
                sum[count] = k;
                poll[count] = -1;
                count++;
            }else if(data[i] == ']'){
                k--;
            }else{ //数字の時
                int num = data[i] - '0';
                for(int j = i+1;j < strlen(data);j++){
                    if(data[j] != '[' && data[j] != ']'){
                        num = num * 10 + (int)(data[j] - '0');
                        i++;
                    }else{
                        break;
                    }
                }
                count--;
                poll[count] = num;
                count++;
            }
        }
        for(int i = 0;i < count;i++){
//            cout << sum[i] << " " << poll[i] << endl;
        }
        while(count > 1){
            int kmax = 0,o = 0;
            for(int i = 0;i < count;i++){
                if(sum[i] > kmax){
                    kmax = sum[i];
                    o = i;
                }
            }
            priority_queue<int, vector<int> , greater<int> >que;
            int len = 0;
            for(int i = o;i < count;i++){
                if(sum[i] == kmax && poll[i] != -1){
                    len++;
                    que.push(poll[i]);
                }else{
                    break;
                }
            }
            int ne = 0; // next
            for(int i = 0;i < (len+1)/2;i++){
                int q = que.top(); que.pop();
                ne += (q+1)/2;
            }
            poll[o-1] = ne*2 -1;
            for(int i = o+len;i < count;i++){
                poll[i-len] = poll[i];
                sum[i-len] = sum[i];
            }
            count -= len;
        }
        cout << (poll[0]+1)/2 << endl;
    }
}


Measured memory_bytes: 3200
N, K = map(int, input().split())
A = list(map(int, input().split()))

fin = min(A) == N
for j in range(K):
    if fin:
        break
    T = [0] * (N + 1)
    for i in range(N):
        T[max(i - A[i], 0)] += 1
        T[min(i + A[i] + 1, N)] -= 1
    A[0] = T[0]
    fin = A[0] == N
    for i in range(1, N):
        A[i] = A[i - 1] + T[i]
        if A[i] < N:
            fin = False
print(' '.join(list(map(str, A))))


Measured memory_bytes: 156616
/*⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄
⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄
⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄
⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄
⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰
⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤
⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗
⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄
⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄
⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄
⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄
⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄
⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴
⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

ll memo[55][55];
ll nCk(int i,int j){
	if (i<j) return 0;
	if (j==0) return 1;
	if (memo[i][j]!=-1) return memo[i][j];
	
	else return memo[i][j]=nCk(i-1,j)+nCk(i-1,j-1);
}

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

int arr[300000];

ll val[55];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	memset(memo,-1,sizeof(memo));
	
	cin>>n>>k>>s>>t;
	
	rep(x,0,55){
		rep(y,0,k) val[x]+=nCk(x,y);
	}
	
	rep(x,0,n){
		int temp;
		cin>>temp;
		
		if (((temp&s)==s) && ((temp|t)==t)) v.push_back(temp);
	}
	
	//for (auto &it:v) cout<<it<<" "; cout<<endl;
	
	if ((t&s)!=s){
		cout<<"0"<<endl;
		return 0;
	}
	
	t^=s;
	
	ll ans=0;
	rep(x,1,k+1) ans+=nCk(sz(v),x);
	
	rep(bm,1,(1<<18)) if ((bm&t)==bm){
		for (auto &it:v){
			//cout<<val[arr[it&bm]]<<" "<<(__builtin_popcount(bm)%2?1:-1)<<endl;
			ans+=val[arr[it&bm]]*(__builtin_popcount(bm)%2?-1:1);
			arr[it&bm]++;
		}
		
		for (auto &it:v){
			arr[it&bm]--;
		}
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 4672
#include <cstdio>
#include <string>

using namespace std;

char t[19];

int main() {
  const string a[3] = {"Sunny", "Cloudy", "Rainy"};
  scanf("%s", t);
  string s = string(t);
  for (int i = 0; i < 3; ++i) {
    if (s == a[i]) {
      puts(a[(i + 1) % 3].c_str());
      break;
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(M);
    vector<unordered_map<int, ll>> edges(N);
    loop(i, M){
        scanInt(Ai); --Ai;
        scanInt(Bi); --Bi;
        edges[Ai].emplace(Bi, 1);
        edges[Bi].emplace(Ai, 1);
    }
    // vector<pair<char, char>> flags(N, make_pair(false, false));
    // flags[0].first = true;
    bool all_flag = false;

    /* 木構造を作る */
    struct Node {
        int parent = -1; // 親ノードのi
        ll distance = -1; // 根からの距離
        vector<int> children; // 子ノード（複数）のi
    };
    vector<Node> nodes(N); // 各ノード（木構造）
    array<int, 2> count = {0, 0};
    function<void(int, ll)> makeTree = [&](int n, ll dist){ // 頂点n以下の木構造を作る
        if (all_flag) return;
        nodes[n].distance = dist;
        ++count[dist % 2];
        for (auto& e : edges[n]){
            auto& next = e.first;
            if (next == nodes[n].parent) continue; // 親に戻らない
            // if (nodes[next].distance != -1 || 0 < nodes[next].children.size()) continue; // 余分な辺がある場合は、既に訪れた頂点を弾く処理をする
            if (nodes[next].distance != -1){ // 余分な辺がある場合
                if (nodes[n].distance % 2 == nodes[next].distance % 2){ // 偶奇不一致
                    all_flag = true;
                    break;
                }else{
                    continue;
                }
            }
            nodes[n].children.emplace_back(next);
            nodes[next].parent = n;
            makeTree(next, dist + e.second);
        }
    };
    const int R = 0; // 根
    nodes[R].parent = -1; // 根の親は適当に入れておく
    makeTree(R, 0); // 根（距離0）から始める
    if (all_flag){
        printf("%lld\n", static_cast<ll>(N) * (N - 1) / 2 - M);
    }else{
        printf("%lld\n", static_cast<ll>(count[0]) * count[1] - M);
    }
}


Measured memory_bytes: 21888
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] array = new int[n - 1][3];
        int[] ans = new int[n];
        
        for (int i = 0; i < n - 1; i++) {
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
            array[i][2] = sc.nextInt();
        }
        
        for (int i = 0; i < n - 1; i++) {
            int t = 0;
            for (int j = i; j < n - 1; j++) {
                if (t > array[j][1]) {
                    int a = (t - array[j][1]) / array[j][2];
                    if ((t - array[j][1]) % array[j][2] != 0) {
                        a++;
                    }
                    t = array[j][1] + array[j][2] * a + array[j][0];
                } else {
                    t = array[j][1] + array[j][0];
                }
            }
            
            System.out.println(t);
        }
        System.out.println(0);
    }
}


Measured memory_bytes: 27008
N = int(input())
W = []
for i in range(N):
    W.append(input())
flag = True
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        flag = False
        break
    for j in range(i):
        if W[i+1] == W[j]:
            flag = False
            break
print("Yes") if flag else print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
  
int main(){
  int h,w;
  cin>>h>>w;
  string a[h];
  REP(i,h){
    cin>>a[i];
  }
  
  queue<pair<int,int>> q;
  vector<vector<bool>> vis(h,vector<bool>(w,false));
  int dist[h][w];
  REP(i,h){
    REP(j,w){
      if(a[i][j]=='#'){
        vis[i][j]=true;
        dist[i][j]=0;
        q.push(make_pair(i,j));
      }
    }
  }
  
  int x,y;
  int nx,ny;
  int res=0;
  while(!q.empty()){
    pair<int,int> p=q.front();
    q.pop();
    x = p.first;y = p.second;
    REP(i,4){
      nx = x+dx[i];ny=y+dy[i];
      if(0<=nx && nx<h && 0<=ny && ny<w && !vis[nx][ny]){
        vis[nx][ny] = true;
        dist[nx][ny] = dist[x][y]+1;
        q.push(make_pair(nx,ny));
        res = max(res,dist[nx][ny]);
      }
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 13584
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{
    int n;cin>>n;
    int x,y;

    vector<pair<int,int>> vp;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        vp.pb({x,y});
    }

    bool ok=false;
    int cnt=0;
    for(int i=0;i<n;i++){
        int idx;
        if(vp[i].F==vp[i].S)
        {
            for(int j=i;j<n;j++){
                if(vp[j].F==vp[j].S)
                    cnt++;
                else
                {
                    // cout<<"Im count: "<<cnt<<endl;
                    if(cnt>=3)
                        ok=true;
                    cnt=0;
                    i=j;
                    // cout<<"Im at j :  " <<j<<endl;
                    break;
                }
                idx=j;
                // cout<<"Im cnt at j: "<<j<< "  " <<cnt<<endl;
            }
        }
        if(idx==n-1)
            break;
    }

    // cout<<cnt<<endl;
    if(cnt>=3)
        ok=true;

    if(ok)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> a(3*n);
  for (ll i = 0; i < 3*n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<ll>());

  ll ans = 0;
  for (ll i = 1; i < (3*n)-n; i+=2) {
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (ll)1e9+7
#define LLINF (ll)1e30
// #define int ll
using namespace std;
const int MAX =100000;
const int MOD = 1e9 +7;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
    queue<int> q;
    q.push(s);
    V[s]=true;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        out.push_back(u);
        for(int i=0;i<G[u].size();i++){
            int v=G[u][i];
            indeg[v]--;
            if(indeg[v]==0 && !V[v]){
                V[v]=true;
                q.push(v);
            }
        }
    }
}

void  tsort(){
    for(int i=0;i<N;i++){
        indeg[i]=0;
    }
    for(int u=0;u<N;u++){
        for(int i=0;i<G[u].size();i++){
            int v= G[u][i];
            indeg[v]++;
        }
    }
    for(int u=0;u<N;u++){
        if(indeg[u]==0 && !V[u]) bfs(u);
    }
    for(list<int>::iterator it=out.begin();it !=out.end();it++){
        cout<<*it<<endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s,t,M;
    cin>>N>>M;
    rep(i,N) V[i]=false;
    rep(i,M){
        cin>>s>>t;
        G[s].pb(t);
    }
    tsort(); 
    return 0;
}


Measured memory_bytes: 6276
/*
 © 2020-09-13 21:16:02 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;

int main(){ _
  lli x; cin >> x;
  if(x) cout << 0 << ENDL;
  else cout << 1 << ENDL;
  return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}



///////////////////////////




int main() {

	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	cout << min(A, B) + min(C, D);

	system("PAUSE");

}


Measured memory_bytes: 504