akhauriyash/Code-Regression huggingface dataset:
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n,m, d[N], vis[N];

vector<pair<int, int>> g[N];

bool dfs(int node, int v, int p){
    d[node] = v;
    vis[node] = 1;
    for(auto edge: g[node]){
        if(edge.first==p)continue;
        if(vis[edge.first]!=0){
            if(d[edge.first]!=d[node] + edge.second) return false;
            continue;
        }
        if(!dfs(edge.first, d[node] + edge.second, node))return false;
    }
    return true;
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    
    int x,y,c;
    for (int i = 1; i <= m; i++){
        cin>>x>>y>>c;
        g[x].push_back({y,c});
        g[y].push_back({x,-c});
    }
    
    memset(d, -1, sizeof(d));
    for (int i = 1; i <= n; i++){
        if(vis[i]==0){
            if(!dfs(i, 0, -1)){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    
    cout<<"Yes"<<endl;
    
    
    return 0;
}



Measured memory_bytes: 12416
#include<bits/stdc++.h>
#define lli long long int
using namespace std;

int main()
{
    lli n, c;
    cin >> n >> c;
    lli w[n], v[n];
    for(lli i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    lli dp[n + 1][c + 1];
    for(lli i = 0; i <= n; i++)
    {
        for(lli j = 0; j <= c; j++)
        {
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else if(w[i - 1] <= j)
                dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]],dp[i - 1][j]);
            else
                dp[i][j] = dp[i - 1][j];
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    cout << dp[n][c];
    return 0;
}

Measured memory_bytes: 79104
import java.io.*;

import java.util.*;

class pair{
	int a ;int b;
	public pair(int a,int b){
		this.a=a;
		this.b=b;
	}}

public class Main {
	

	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[] arr=new int[n+1];
		
		
		for (int i = 1; i < arr.length; i++) {
			arr[i]=s.nextInt();
		}
				long ans=0;
		HashMap<Integer,Integer> jj1=new HashMap<>();  //n1>n2

		HashMap<Integer,Integer> jj2=new HashMap<>(); //n1<n2
		
		for (int i = 1; i < arr.length; i++) {
			jj1.put(i+arr[i],jj1.getOrDefault(i+arr[i],0)+1);
		}
		for (int i = 1; i < arr.length; i++) {
			jj2.put(i-arr[i],jj2.getOrDefault(i-arr[i],0)+1);
		}
		
		
		for (int i = 1; i < arr.length; i++) {
			int tt1=i-arr[i];
			int tt2=i+arr[i];
			if(jj1.containsKey(tt1)) {
				ans+=jj1.get(tt1);
			}
			if(jj2.containsKey(tt2)) {
				ans+=jj2.get(tt2);
			}
		}
		
		System.out.println(ans/2);

	}


}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"


int main(){
    double pi = 3.141592653589;
    double r;
    cin >> r;
    printf("%f %f\n",r*r*pi,2*r*pi);
}



Measured memory_bytes: 3200
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

typedef long long ll;

int main(void) {

    ll N, A;
    cin >> N >> A;

    ll ans = N;
    for (int i = 0; i < 40; ++ i) {
        multiset<ll> s;
        ll tmp = 1;
        ll sum = 0;
        for (int j = 0; j <= i; ++ j) {
            ll x = pow(N, 1.0 / (i + 1));
            s.insert(x);
            tmp *= x;
            sum += x;
        }
        while ( true ) {
            //cerr << tmp << endl;
            if (tmp >= N) {
                break;
            }
            ll v = *begin(s);
            s.erase(begin(s));
            s.insert(v + 1);
            tmp /= v;
            tmp *= v + 1;
            ++ sum;
        }

        ans = min(ans, sum + A * i);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B;
  cin >> A >> B;
  int result = A * B;
  if (A > 9 || B > 9) result = -1;
  cout << result << endl;
}


Measured memory_bytes: 256
from math import floor


def main():
    a, b = map(int, input().split())
    for yen in range(1, 1100):
        if floor(yen * 0.08) == a and floor(yen * 0.1) == b:
            print(yen)
            return
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
int mod = (int) 1e9 + 7;

int main(){
    
    long a;
    double b;
    cin >> a >> b;
    
    int c = b * 100 + 0.001;
    
    long d = a * c / 100;
    
    cout << d << "\n";
    
    return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007

void solve() {
    int n,m;
    cin >> n >> m;
    ll s = 0;
    rep(i,0,m) {
        int tmp;
        cin >> tmp;
        s += tmp;
    }
    ll ans = n - s;
    if (ans < 0) ans = -1;
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
s = input()
# left should record the first w
# right should record the last r
for i in range(n):
    if s[i] == 'W':
        left = i
        break
else:
    print(0)
    exit()
for i in range(n-1, -1, -1):
    if s[i] == 'R':
        right = i
        break
else:
    print(0)
    exit()
ans = 0
while left < right and left < n and right >= 0:
    ans += 1
    # perform the swap
    left += 1
    right -= 1
    while left < n and s[left] != 'W':
        left += 1
    while right >= 0 and s[right] != 'R':
        right -= 1
print(ans)

Measured memory_bytes: 67684
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  int N, A[100];

  cin >> N;
  REP(i, N) cin >> A[i];
  sort(A, A + N);
  cout << A[N - 1] - A[0] << endl;

  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

n,m,s,t = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
    u,v,a,b = map(int,input().split())
    e[u].append((v,a,b))
    e[v].append((u,a,b))

S = [float("INF")]*(n+1)
S[s] = 0
h = []
heappush(h,[0,s])
while h:
    d,now = heappop(h)
    for nex,a,b in e[now]:
        if d+a < S[nex]:
            S[nex] = d+a
            heappush(h,[d+a,nex])
T = [float("INF")]*(n+1)
T[t] = 0
h = []
heappush(h,[0,t])
while h:
    d,now = heappop(h)
    for nex,a,b in e[now]:
        if d+b < T[nex]:
            T[nex] = d+b
            heappush(h,[d+b,nex])

ans = [0]*(n+1)
cost = 10**15
now = 0
for i in range(n,0,-1):
    now = max(now,cost-S[i]-T[i])
    ans[i] = now
for i in ans[1:]:
    print(i)

Measured memory_bytes: 60472
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var ln1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var n = ln1[0];
            var a = ln1[1];
            var b = ln1[2];

            var s = Console.ReadLine();

            var left_all = a+b;
            var foreign = 0;

            var ans = 0;

            for (var i = 0; i < n; ++i) {
                if (s[i] == 'a') {
                    if (ans < left_all) {
                        ++ans;

                        Console.WriteLine("Yes");
                        continue;
                    }
                }
                else if (s[i] == 'b') {
                    if ((ans < left_all) && (foreign < b)) {
                        ++foreign;
                        ++ans;
                        Console.WriteLine("Yes");
                        continue;
                    }
                }

                Console.WriteLine("No");

            }
        }
    }
}


Measured memory_bytes: 28440
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

struct Room {
	int x, y;
	std::vector<Room> neighbors() const {
		return std::vector<Room>{ Room{x + 1, y}, Room{x - 1, y}, Room{x, y + 1}, Room{x, y - 1} };
	}
	bool operator==(const Room that) const { return x == that.x && y == that.y; }
	bool operator!=(const Room that) const { return !((*this) == that); }
};
bool set_next_room(const Room current, std::vector<std::vector<Room>>& next_room, std::vector<std::vector<int>> &searching, const std::vector<std::string> &office, const Room goal, const int current_step) {
	if (current == goal) return true;
	if (searching[current.y][current.x] == current_step) return false;
	searching[current.y][current.x] = current_step;
	for (const auto next : current.neighbors()) if (0 <= next.y && next.y < office.size() && 0 <= next.x && next.x < office[next.y].size() && office[next.y][next.x] != '#'){
		if (set_next_room(next, next_room, searching, office, goal, current_step)) {
			next_room[current.y][current.x] = next;
			return true;
		}
	}
	return false;
}
struct Light {
	int hold, on, off;
};
int main() {
	int r, c, m; std::cin >> r >> c >> m;
	std::vector<std::string> office(r); for (auto& o : office) std::cin >> o;
	std::vector<std::vector<Room>> next_room(r, std::vector<Room>(c));
	std::vector<std::vector<int>> searching(r, std::vector<int>(c, -1));
	std::vector<std::vector<std::vector<int>>> visit_timing(r, std::vector<std::vector<int>>(c));
	std::vector<std::vector<Light>> lights(r, std::vector<Light>(c));
	for (auto ri = 0; ri < r; ++ri) for (auto ci = 0; ci < c; ++ci) {
		std::cin >> lights[ri][ci].hold;
	}
	for (auto ri = 0; ri < r; ++ri) for (auto ci = 0; ci < c; ++ci) {
		std::cin >> lights[ri][ci].on;
	}
	for (auto ri = 0; ri < r; ++ri) for (auto ci = 0; ci < c; ++ci) {
		std::cin >> lights[ri][ci].off;
	}
	int current_time = 0;
	Room current; std::cin >> current.y >> current.x;
	visit_timing[current.y][current.x].push_back(0);
	for (auto i = 1; i < m; ++i) {
		Room dist; std::cin >> dist.y >> dist.x;
		set_next_room(current, next_room, searching, office, dist, i);
		while (current != dist) {
			current = next_room[current.y][current.x];
			visit_timing[current.y][current.x].push_back(++current_time);
		}
	}
	int sum_cost = 0;
	for (auto ri = 0; ri < r; ++ri) for (auto ci = 0; ci < c; ++ci) {
		sum_cost += visit_timing[ri][ci].size() * (lights[ri][ci].on + lights[ri][ci].off);
		for (auto i = 1; i < visit_timing[ri][ci].size(); ++i) {
			auto time = visit_timing[ri][ci][i] - visit_timing[ri][ci][i - 1];
			if (lights[ri][ci].hold * time < lights[ri][ci].on + lights[ri][ci].off) {
				sum_cost += lights[ri][ci].hold * time - lights[ri][ci].on - lights[ri][ci].off;
			}
		}
	}
	std::cout << sum_cost << '\n';
}


Measured memory_bytes: 8544
#include <bits/stdc++.h>
using namespace std;
 
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main() {
    int N, x, ans = 0;
    cin >> N >> x;
    VI a;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        a.PB(tmp);
    }
    sort(ALL(a));

    REP(i, N) {
        if(i+1 == N) {
            ans += (a[i] == x);
        } else if (a[i] <= x) {
            x -= a[i];
            ans++;
        } else {
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val arr = listOfInt()
    var result = arr[0] - 2 * arr[1]
    if(result < 0){
      result = 0
    }
    println(result)
}

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

Measured memory_bytes: 37936
#include<iostream>
#include<vector>
using namespace std;
bool check[9]{ 0 };
int dp[1 << 9][9];
int N, M;
int nl() {
	int a = 0;
	for (int i = 0; i < 9; ++i) {
		if (check[i])a += (1 << i);
	}
	return a;
}
vector<vector<int> > map(9);
int search(int, int);
int main() {
	cin >> N >> M;
	for (int i = 0; i < (1 << 9); ++i) {
		for (int j = 1; j < 9; ++j) {
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		map[a].push_back(b);
		map[b].push_back(a);
	}
	check[1] = true;
	cout << search(1, 1) << endl;
	return 0;
}

int search(int np, int nu) {
	if (nu == N)return 1;
	int slide = nl();
	int res = 0;
	if (dp[slide][np] > -1)return dp[slide][np];
	for (int i = 0, nmax = map[np].size(); i < nmax; ++i) {
		if (!check[map[np][i]]) {
			check[map[np][i]] = true;
			res += search(map[np][i], nu + 1);
			check[map[np][i]] = false;
		}
	}
	dp[slide][np] = res;
	return res;
}

Measured memory_bytes: 256
#なぜ通らない？
from collections import Counter
from operator import itemgetter

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

c = Counter(a)

d = sorted(list(c.items()), key=itemgetter(0), reverse=True)

a = 0
b = 0
for i in d:
	if i[1] >= 4 and a == 0:
		a = i[0]
		b = i[0]
		break
	elif i[1] >= 2 and a == 0:
		a = i[0]
		continue
	elif i[1] >= 2 and a != 0:
		b = i[0]
		break

print(a * b)

Measured memory_bytes: 23204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	int c = a + k - 1;
	int d = b - k + 1;
	if (c >= d) {
		for (int i = a; i <= b; i++) {
			cout << i << endl;
		}
	}
	else {
		for (int i = a; i <= c; i++) {
			cout << i << endl;
		}
		for (int i = d; i <= b; i++) {
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int l,a[11][11];
	string str;
	while((cin>>str)!=0){
		for(int i=0;i<10;i++)a[0][i]=str[i]-48;
		for(int i=1;i<10;i++){
			for(int j=0;j<10-i;j++){
				a[i][j]=(a[i-1][j]+a[i-1][j+1])%10;	
			}
		}
		cout<<a[9][0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
int a[MAXN],b[MAXN];
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    int n,m;
	cin>>n>>m;
	for (int i = 0; i < m; ++i)
	{
		int u,v;
		cin>>u>>v;
		u--;v--;
		a[u]++,a[v]--;
	}
	int now = 0;
	for (int i = 0; i < n; ++i)
	{
		// debug(i);
		// debug(a[i]);
		// debug(now);
		now+=a[i];
		b[i]+=now;
	}
	bool can = true;
	for (int i = 0; i < n-1; ++i)
	{
		// debug(i);
		// debug(b[i]);
		if(b[i]&1) can = false;
	}
	if(can) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
    return 0;        

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn=105;
int main()
{
	int n,x;
    int a[maxn];
    cin>>n>>x;
    for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
    sort(a+1,a+n+1);
    int ans=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]<=x)
		{
			ans++;
		}
        x=max(0,x-a[i]);
    }
    if(x==a[n])
	{
		ans++;
	}
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int compare( const void * a, const void * b){ return *( int *)a - *( int *)b; }
int search( int *a, int length, int key ){
  int low = 0, high = length - 1;
  while( 1 ){
    if( low > high ) return 0;
    int mid = low + ( high - low ) / 2;
    if( a[ mid ] < key ){
      low = mid + 1;
      continue;
    }
    else if( a[ mid ] == key ) return 1;
    else {
      high = mid - 1;
      continue;
    }
  }
}

int main( void ){
  int n;
  scanf("%d\n", &n );
  int *s = ( int * ) malloc ( n * sizeof( int ) );
  for( int i = 0; i < n; i ++ )
    scanf("%d", s + i );

  //qsort( ( void * )s, n, sizeof( int ), compare );                                                                          

  int q;
  scanf("%d\n", &q );
  int count = 0;
  for( int i = 0; i < q; i ++ ){
    int t;
    scanf("%d", &t );
    count += search( s, n, t );
  }
  printf( "%d\n", count );
  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  
  vector<ll> p(n);
  vector<ll> v(n);
  cin >> p[0];
  v[0] = p[0];
  for(int i=1; i<n; i++){
  	cin >> p[i];
    v[i] = min(p[i], v[i-1]);
  }
  ll ans=1;
  for(int i=1; i<n; i++){
  	if(v[i-1] >= p[i]){
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  cout << max(0,min(b,d)-max(a,c)) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Point[] points = new Point[n];
		for (int i = 0; i < n; i++) {
			points[i] = new Point(sc.nextInt(), sc.nextInt());
		}
		HashMap<Point, Integer> map = new HashMap<>();
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				Point p;
				if (points[i].x < points[j].x) {
					p = new Point(points[j].x - points[i].x, points[j].y - points[i].y);
				} else if (points[i].x > points[j].x) {
					p = new Point(points[i].x - points[j].x, points[i].y - points[j].y);
				} else {
					p = new Point(0, Math.abs(points[i].y - points[j].y));
				}
				if (map.containsKey(p)) {
					int x = map.get(p);
					map.put(p, x + 1);
				} else {
					map.put(p, 1);
				}
			}
		}
		int max = 0;
		for (int x : map.values()) {
			max = Math.max(max, x);
		}
		System.out.println(n - max);
	}
	
	static class Point {
		int x;
		int y;
		
		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
		
		public int hashCode() {
			return x + y;
		}
		
		public boolean equals(Object o) {
			Point p = (Point) o;
			return p.x == x && p.y == y;
		}
	}
}


Measured memory_bytes: 22228
#include<iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include<bits/stdc++.h>
#include<cstdio>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define bll __builtin_popcountll
#define bufclr while((getchar())!='\n')
#define bufcl int ws=cin.get()
#define bl "\n"
#define mp make_pair
#define pb push_back
#define ll long long int
#define UI unsigned int
#define mod  1000000007 /*998244353*/ 
//#define fs first
//#define sc second
#define fora(i,a,x) for(int i=a; i<x; ++i)
#define fors(i,x,a) for(int i=x; i>a; --i)
using namespace std;
void op(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif
}
int C(pair<int,int> &a ,pair<int,int> &b){
    return a.first<b.first;
}
void dfs(vector<vector<int> > &vec, int i,int nw, int k,int n){
    //cout<<nw;
    ll res=1;
    if(i==n && nw==k){
        res = (res + 1)%mod;
        return;
    }
    else if(nw>k)
        return;
    else{
    //    vis[i]=1;
        for(auto itr: vec[i]){
         dfs(vec,itr,nw+1,k,n);    
    }
}    

    }
    

long long power(long long x, int y) 
{ 
    long long res = 1;    
   
    while (y > 0) 
    { 
      
        if (y & 1) 
            res = (res*x)%mod; 
   
        y = y>>1; 
        x = (x*x)%mod;  
    } 
    return res%mod; 
}

int main(){
	op();
	int n;
	cin>>n;
	int a,b;
	int w=0;
	bool flag=0;
	for(int i=0; i<n; ++i){
		cin>>a>>b;
		if(a==b){
			w++;
		}
		else if(a!=b)
			w=0;
		if(w==3)
			flag=1;
	//cout<<w<<bl;
	}
	if(flag)
		cout<<"Yes";
	else
		cout<<"No";
}


        





            


Measured memory_bytes: 3624
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
string s;

int main() {
	cin >> n;
	cin >> s;
	int d = 0;
	int i = 0;
	while (i < n) {
		if (s[i] == '(') {
			d++;
		}
		else {
			d--;
			if (d < 0) {
				s = '(' + s;
				i++;
				n++;
				d = 0;
			}
		}
		i++;
	}
	for (int j = 0; j < d; j++) {
		s += ')';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>

using namespace std;

#define fs first
#define sc second

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

const ll mod = 1e9+7;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}


#define MAX_N 410000
template<typename T>
class SegTree{
public:
    //セグメント木を持つグローバル変数
    int n;
    T dat[2 * MAX_N - 1];

    void init(int n_, T init_num){
        n = 1;
        while(n < n_) n *= 2;
        for(int i = 0; i < 2*n-1; i++){
            dat[i] = init_num;
        }
    }

    // k番目の値(0-indexed)をaに変更
    void update(int k, T a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = max(dat[k*2+1], dat[k*2+2]);
        }
    }

    // [a, b)の最小値を求める。
    // kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
    // query(a, b, 0, 0, n)で外からは呼び出す。
private: T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return 0;
        }

        if (a <= l && r <= b) {
            return dat[k];
        } else {
            ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    // [a, b)の最小値を求める。
public: T query(int a, int b){
        return query(a, b, 0, 0, this->n);
    }
};


int main(){
    int N, h[210000];
    ll a[210000];
    cin >> N;
    h[0] = 0;
    a[0] = 0;
    for(int i = 1; i <= N; i++){
        cin >> h[i];
    }
    for(int i = 1; i <= N; i++){
        cin >> a[i];
    }

    SegTree<ll> seg;
    seg.init(N+1, 0);

    ll res = 0;
    for(int i = 1; i <= N; i++){
        ll tmp = seg.query(0, h[i]) + a[i];
        seg.update(h[i], tmp);
        res = max(res, tmp);
    }

    cout << res << endl;


    return 0;
}

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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
   long long k,x;
   cin>>k>>x;

   int mx=k+x-1;
   int mn=x-k+1;

   for(int i=mn;i<=mx;i++){
    cout<<i<<" ";
   }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a,b = gi
c = 0
repl a,b do |i|
  c += 1 if i.to_s == i.to_s.reverse
end
puts c


Measured memory_bytes: 2556
// at_abc154d.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define FOR(i,a) for(int i=0;i<a;i++)
int main()
{
    int n,k;cin >> n>>k;
    vector<int>v(n, 0);
    FOR(i, n) {
        cin >> v[i];
    }
    int ans = 0;
    int cursum = 0;
    int idx = 0;
    FOR(i, k) {
        ans += v[i];
    }
    cursum = ans;
    while (idx + k < n) {
        //cout << cursum << "\n";
        cursum += v[idx+ k];
        cursum -= v[idx];
        ans = max(ans, cursum);
        idx++;
    }
    printf("%.6f",((float)ans + k )/ 2);
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int h,n; cin>>h>>n;
    ll m_dam = 0; rep(i,n){int tmp; cin >>tmp; m_dam+=tmp;}
    cout<<((m_dam>=h)?"Yes":"No")<<endl;return 0;
}


Measured memory_bytes: 256
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

itn main() {
	std::ios::sync_with_stdio(false);

	int n, k;

	cin >> n >> k;

	if (!k) {
		cout << n * n;
		return 0;
	}

	int res = 0;

	REP2(i, k + 1, n + 1) {
		res += (i - k) * (n / i) + max(n % i - k + 1, (int)0);
	}

	cout << res;

	return 0;
}


Measured memory_bytes: 256
while True:
  try:
    a, b, c, d, e, f = map(float, input().split())
  except EOFError:
    break

  det = a * e - b * d
  if det != 0:
    x = (1 / det) * (e * c - b * f)
    y = (1 / det) * (a * f - c * d)
    if x >= 0:
      xx = (int)(x * 1000)
      if xx % 10 <= 4:
        ansx = (xx - xx%10) / 1000
      else:
        ansx = (xx + (10 - xx%10)) / 1000
    else:
      xx = (int)(x * -1000)
      if xx % 10 <= 4:
        ansx = (xx - xx%10) / -1000
      else:
        ansx = (xx + (10 - xx%10)) / -1000
      
    if y >= 0:
      yy = (int)(y * 1000)
      if yy % 10 <= 4:
        ansy = (yy - yy%10) / 1000
      else:
        ansy = (yy + (10 - yy%10)) / 1000
    else:
      yy = (int)(y * -1000)
      if yy % 10 <= 4:
        ansy = (yy - yy%10) / -1000
      else:
        ansy = (yy + (10 - yy%10)) / -1000
    print("{0:.3f} {1:.3f}".format(ansx, ansy))


Measured memory_bytes: 5600
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

ll n,m;

ll dfs(vector<vector<int>> &da){
	vector<int> ju(n, 0);
	ju[0] = 1;
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		int now = q.front();
		q.pop();
		rip(i, da[now].size(),0){
			if(ju[da[now][i]]){
				if(ju[now] == ju[da[now][i]]) return -1;
			}
			else{
				ju[da[now][i]] = 3 - ju[now];
				q.push(da[now][i]);
			}
		}
	}
	ll ret = 0;
	rip(i,n,0){
		if(ju[i] == 1) ret++;
	}
	return ret;
}

int main(){
	cin >> n >> m;
	vector<vector<int>> da(n, vector<int>(0));
	rip(i,m,0){
		int a,b; cin >> a >> b;
		a--; b--;
		da[a].push_back(b);
		da[b].push_back(a);
	}
	int k = dfs(da);
	if(k == -1) cout << n*(n-1)/2 - m<< endl;
	else cout << k*(n-k)-m << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
	string S;
	int flag[100];
	int i=0;
	int count = 0;//連続
	int pre_count = 0;//連続格納
	int result = 0;
	int flag_count = 0;
	cin >> S;

	for (i = 0; i < S.size(); ++i)
	{
		if (S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T')
		{
			flag[i] = 1;
			++flag_count;
		}
		else {
			flag[i] = 0;
		}
	}

	for (i = 0; i < S.size()+1; ++i)
	{
		if (flag[i] == flag[i + 1]&&flag[i]==1&&flag[i+1]==1) {
			++count;
			if (pre_count<=count) {
				pre_count = count;
			}
			else {

			}
			
		}

		else  {
			count = 0;
		}
	}
	if (pre_count == 0 && flag_count == 0){
		cout << 0;
	}
	else if (pre_count == 0&&flag_count>0) {
		cout << 1;
	}
	else {
		cout << pre_count + 1 << endl;
	}



}

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

int main(){
	int N; cin>>N;
	int c2 = 0, c4 = 0;
	for(int i=0; i<N; ++i){
		int a; cin>>a;
		if(a%4 == 0) c4++;
		else if(a%2 == 0) c2++;
	}
	puts(N/2 <= c4+c2/2? "Yes":"No");
}

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;
const ll mod = 1e9+7;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i,n)cin >> p[i];
    int pre = 0;
    int next = 0;
    int count = 0;
    REP(i,n-2){
        if(p[i] > p[i+1]){
            pre = 0;
        }else{
            pre = 1;
        }
        if(p[i+1] > p[i+2]){
            next = 0;
        }else{
            next = 1;
        }
        if((pre + next)%2 == 0)count++;
    }
    cout <<count<< "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll a[100000];
ll cnt[100000];
ll gcd(ll a,ll b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	int n;
	ll m;
	ll ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]/=2;
		ll tmp=0;
		while(a[i]%(1LL<<tmp)==0)
			tmp++;
		cnt[i]=tmp;
	}
	bool f=true;
	ll tmp=cnt[0];
	for(int i=0;i<n;i++)
	{
		if(cnt[i]!=tmp)
			f=false;
	}
	if(!f)
	{
		cout<<0<<endl;
		return 0;
	}
	//最小公倍数を調べる
	ll lcm=a[0];
	for(int i=0;i<n;i++)
	{
		lcm=(lcm/gcd(lcm,a[i]))*a[i];
		if(lcm>m)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	cerr<<lcm<<endl;
	ans=(m/lcm+1)/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve(ll N, ll K, vector<ll> P, vector<ll> C) {

  ll ans(-1E9);
  REP(i, N) {
    ll score(0);
    ll max_score(-1E9);
    ll place(i + 1);
    vector<ll> history;
    // printf("place=%lld\n",place);
    REP(k, K) {
      history.emplace_back(place);
      place = P[place - 1];
      score += C[place - 1];
      // printf("place=%lld score=%lld\n", place,score);

      if (history.front() == place) {
	// printf("place=%lld is in history\n", place);
	ll n = K / history.size();
	max_score = max(max_score, max_score + score * (n - 1));
	score *= n;
	k = n * history.size() - 1;
	history.clear();
      }

      max_score = max(max_score, score);
    }
    // printf("max_score=%lld ans=%lld\n",max_score, ans);
    ans = max(max_score, ans);
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> P(N);
  REP(i, N) {
    cin >> P[i];
  }
  vector<ll> C(N);
  REP(i, N) {
    cin >> C[i];
  }

  solve(N, K, move(P), move(C));

  return 0;
}


Measured memory_bytes: 3848
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000007
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
bool is_prime(ll N)
{
    for (ll i = 2; i * i <= N; ++i)
    {
        if (N % i == 0)
            return false;
    }
    return true;
}
vector<ll> soinsubunkai(long long N)
{
    vector<ll> tmp;
    ll num = N;
    for (ll i = 2; i * i <= N; ++i)
    {
        if (N % i == 0)
        {
            ll j = N / i;
            if (is_prime(i))
            {
                while (num % i == 0)
                {
                    tmp.push_back(i);
                    num /= i;
                }
            }
            if (is_prime(j))
            {
                while (num % j == 0)
                {
                    tmp.push_back(j);
                    num /= j;
                }
            }
        }
    }
    return tmp;
}

int main(void)
{
    int a[1000];
    rep(i, 0, 1001) a[i] = 0;
    ll n;
    cin >> n;
    rep(i, 2, n + 1)
    {
        vector<ll> tmp = soinsubunkai(i);
        if (is_prime(i))
            a[i]++;
        else
            rep(j, 0, tmp.size()) a[tmp[j]]++;
    }
    ll ans = 1;
    rep(i, 2, 1001) if (a[i] != 0) ans = (ans * (a[i] + 1)) % MOD;
    cout << ans << endl;
}

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

lin calc()
{
    lin res = 0;
    lin mm = m;
    for(pair<lin, lin> ii : vii)
    {
        lin mmm = min(mm, ii.second);
        res += mmm * ii.first;
        mm -= mmm;

        if(mm <= 0)
        {
            return res;
        }
    }
}

bool compare(pair<lin, lin> p1, pair<lin, lin> p2 )
{
    return p1.first < p2.first;

}

int main(void)
{
    cin >> n >> m;
    rep(i,n)
    {
        lin a,b;
        cin >> a >> b;
        vii.push_back(make_pair(a,b));
    }

    sort(vii.begin(), vii.end(), compare);

    lin res = calc();

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2420
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs 
cout << lcs; 
} 

/* Driver program to test above function */
int main() 
{ 
string X,Y;cin>>X>>Y;
int m = X.size(); 
int n = Y.size(); 
lcs(X, Y, m, n); 
return 0; 
} 


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

int findSumOfDigits(int n){
    int sum =0;
    while(n>0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int main() {
    int N,A,B;
    cin >> N >> A >> B;
    int res = 0;
    for(int i=1;i<=N;i++){
        int sumD =findSumOfDigits(i);
        if(A<=sumD && sumD<=B){
            res+=i;
        }
    }
    cout << res <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> v[111111];
int h[111111];

int main(void)
{
	int n, m, i, j;

	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; i++)
		scanf("%d", &h[i]);

	while (m--)
	{
		int a, b;

		scanf("%d %d", &a, &b);

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

	int ans = 0;
	for (i = 1; i <= n; i++)
	{
		bool good = true;
		for (j = 0; j < v[i].size(); j++)
			if (h[i] <= h[v[i][j]])
				good = false;

		if (good)
			++ans;
	}

	printf("%d", ans);
	return 0;
}

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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int MOD = 1000000007;
ll dp[100000][2];
int main() {
    IOS;
    int n;
    cin >> n;
    std::vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    dp[0][0] = dp[0][1] = 0;
    dp[1][0] = abs(h[1] - h[0]);
    dp[1][1] = 1000000000000;
    for(int i = 2; i < n; i++) {
        dp[i][0] = MIN(dp[i - 1][0], dp[i - 1][1]) + abs(h[i] - h[i - 1]);
        dp[i][1] = MIN(dp[i - 2][0], dp[i - 2][1]) + abs(h[i] - h[i - 2]);
    }
    cout << MIN(dp[n - 1][0], dp[n - 1][1]);
    return 0;
}

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

using namespace std;

int main(){
   long long int A,B,C;
   cin >> A >> B >> C;
   if(!(A%2)||!(B%2)||!(C%2)){
      cout << 0 << endl;
      return 0;
   }
   vector<long long int> a{A,B,C};
   sort(a.begin(),a.end());
   cout << a[0] * a[1] << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int t[5],sum;
  sum=0;
  for(int i=0;i<5;i++){
    cin>>t[i];
    if(t[i]>=40){
      sum+=t[i];
    }else{
      sum+=40;
    }

  }
    cout<<sum/5<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 10000007
#define MAXN 200002
ll dp[2000002],h[200002],a[200002];
ll query(ll node,ll st,ll en,ll l,ll r)
{
  
  if(st>=l and en<=r) return dp[node];
  if(en<l or st>r) return 0;
  ll mid=(st+en)/2;
  return max(query(2*node,st,mid,l,r),query(2*node+1,mid+1,en,l,r));
}
void upd(ll node,ll st,ll en,ll ind,ll val)
{
  if(st==en)
  {
    dp[node]=val;
    return;
  }
  ll mid=(st+en)/2;
  if(ind<=mid) upd(2*node,st,mid,ind,val);
 else upd(2*node+1,mid+1,en,ind,val);
 dp[node]=max(dp[2*node],dp[2*node+1]);
}
int main() {
       ios::sync_with_stdio(false);
       cin.tie(0);
       cout.tie(0);
       ll n;
       cin>>n;
       for(ll i=1;i<=n;i++) cin>>h[i];
       for(ll i=1;i<=n;i++) cin>>a[i];
        ll ans=0;
       for(ll i=1;i<=n;i++)
       {
        ll dd=query(1,1,n,1,h[i])+a[i];
        upd(1,1,n,h[i],dd);
        ans=max(ans,dd);
       }
       cout<<ans;
       return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  string s;
  int a,b;
  while(cin >> s >> a >> b) {
    cout << s;
    printf(" %d %d\n", a+b, a*200+b*300);
  }
}

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

int main() {
  long N, l, l1 = 1, l2 = 2;
  cin >> N;
  if(N == 0){
  	l = 2;
  }else if(N == 1){
  	l = 1;
  }else{
  	for (int i = 1; i < N; i++) {
  		l = l1 + l2;
  		l2 = l1;
  		l1 = l;
  	}
  }
  cout << l << endl;
}

Measured memory_bytes: 384
import heapq

N, M = map(int, input().split())
A = [int(i) * (-1) for i in input().split()]
heapq.heapify(A)
h = heapq.heappop(A)

for i in range(M):
  h = heapq.heappushpop(A, (h*(-1))//2*(-1))
    
print((sum(A)+h) * (-1))

Measured memory_bytes: 71448