akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.TreeMap;

public class Main {
	static int MOD = (int)1e9 + 7;
	long N;
	TreeMap<Key,Long> map;

	private class Key implements Comparable<Key>{
		long x,y;
		public Key(long x,long y){
			this.x = x;
			this.y = y;
		}

		public int compareTo(Key p){
			if(Long.compare(this.x,p.x) == 0){
				return Long.compare(this.y, p.y);
			}
			return Long.compare(this.x, p.x);
		}
	}

	public long dfs(long S,long X){

		if(S == 0)return 1;

		Key key = new Key(S,X);

		if(map.containsKey(key)){
			return map.get(key);
		}

		long ret = 0;
		ret += dfs(S >> 1,X >> 1) % MOD;
		ret %= MOD;

		if(S > 1){
			ret += dfs((S - 2) >> 1,X >> 1) % MOD;
			ret %= MOD;
		}

		ret += dfs((S - 1) >> 1,(X - 1) >> 1) % MOD;
		ret %= MOD;

		map.put(key, ret);
		return ret;
	}

	public void solve() {
		N = nextLong();
		map = new TreeMap<Key,Long>();
		out.println(dfs(N,N));
	}

	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[2048];
	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: 8656
from collections import deque

N, M = map(int, input().split())
d = {i:[] for i in range(1, N+1)}
l = []
INF = 10**12
v = INF

for _ in range(M):
    A, B = map(int, input().split())
    d[A].append(B)
    l.append((A, B))

ans = []
for i, j in l:
    INF = 10**12
    dist = [-1]*(N+1)
    prev = [-1]*(N+1)
    dist[j] = 0
    prev[j] = 0
    q = deque([j])

    while q:
        a = q.popleft()
        for b in d[a]:
            if dist[b]==-1:
                dist[b] = dist[a]+1
                prev[b] = a
                q.append(b)

    if v>dist[i]+1 and dist[i]!=-1:
        v = dist[i]+1
        buf = i
        ans = []
        while buf!=0:
            ans.append(buf)
            buf = prev[buf]

if ans:
    print(len(ans))
    for i in ans:
        print(i)
else:
    print(-1)


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

using namespace std;
typedef long long ll;

int main() {
    int n;
    int w[ 1000];
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++){
      cin >> w[i];
      sum += w[i];
    }
    int min = sum;
    int sum1=0;
    for(int i=0;i<n;i++){
      sum1+=w[i];
      int sum2 = sum-sum1;
      int a = abs(sum1-sum2);
      if(min>a) min=a;
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
def lrCount(rCount,lCount,ansList,i):
    count = rCount + lCount
    c = 0
    if i == len(s) - 1:
        c = 1
    if count % 2 == 0:
        ansList[i - lCount + c] = count // 2
        ansList[i - lCount - 1 + c] = count // 2
    else:
        if rCount % 2 == 1:
            ansList[i - lCount + c] = count // 2
            ansList[i - lCount - 1 + c] = count // 2 + 1
        else:
            ansList[i - lCount + c] = count // 2 + 1
            ansList[i - lCount - 1 + c] = count // 2

import sys

s = input()

if s == "RL":
    print("1 1")
    sys.exit()

check = "N"
ansList = [0 for i in range(len(s))]

for i in range(len(s)):
    if check == "N":
        count = 0
        check = "R"
        rCount = 1
        
    else:
        if s[i] == check and i != len(s) - 1:
            if s[i] == "R":
                rCount += 1
            else:
                lCount += 1
        elif i == len(s) - 1:
            if s[i-1] == "R":
                lCount = 1
            else:
                lCount += 1
            lrCount(rCount,lCount,ansList,i)
        else:
            if s[i] == "L":
                check = "L"
                lCount = 1
            if s[i] == "R":                
                lrCount(rCount,lCount,ansList,i)
                check = "R"
                rCount = 1
                count = 0

for i in range(len(ansList)):
    if i == 0:
        ans = str(ansList[0])
    else:
        ans = ans + " " + str(ansList[i])

print(ans)

Measured memory_bytes: 10320
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		if(sc.nextInt() == sc.nextInt()) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	bool h = false;
	for (int i = 0; i < t.size(); i++) {
		string t2 = t.substr(i) + t.substr(0, i);
		if (s == t2) {
			h = true;
		}
	}
	if (h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<string, pair<int, int>>PP;
typedef long long ll;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int m = max(a, max(b, c));
	int n = m;
	for (int i = 0; i < k; i++) {
		n *= 2;
	}
	cout << a + b + c - m + n << endl;
	return 0;
}

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

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

using namespace std;

const int INF = 1000000001;

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

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

  vector<int> dp(n, INF);

  rep(i, n) { *lower_bound(dp.begin(), dp.end(), a[i]) = a[i]; }

  cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << '\n';

  return 0;
}



Measured memory_bytes: 3616
import sys
from math import sqrt

inf = 1<<60

def solve():
    N, M = map(int, sys.stdin.readline().split())

    edges = [None] * M
    Adj = [[] for i in range(N)]
    Adjr = [[] for i in range(N)]

    for i in range(M):
        ai, bi, ci = map(int, sys.stdin.readline().split())
        edges[i] = (ai - 1, bi - 1, -ci)
        Adj[ai - 1].append(bi - 1)
        Adjr[bi - 1].append(ai - 1)

    visitable = [False] * N
    dfs(N, M, Adj, visitable, 0)

    reachable = [False] * N
    dfs(N, M, Adjr, reachable, N - 1)

    valid = [visitable[i] and reachable[i] for i in range(N)]

    edges = [(u, v, c) for (u, v, c) in edges if valid[u] and valid[v]]

    ans = BellmanFord(N, M, edges, valid)

    if ans is None:
        print('inf')
    else:
        print(-ans)

def dfs(N, M, Adj, visited, u):
    visited[u] = True

    for v in Adj[u]:
        if not visited[v]:
            dfs(N, M, Adj, visited, v)

def BellmanFord(N, M, edges, valid):
    d = [inf] * N
    d[0] = 0

    for i in range(N):
        flag = False

        for (u, v, c) in edges:
            if d[u] != inf and d[u] + c < d[v]:
                d[v] = d[u] + c
                flag = True

        if not flag:
            break

        if flag and i == N - 1:
            return None

    return d[N - 1]

if __name__ == '__main__':
    solve()

Measured memory_bytes: 45168
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int n, m, a[1009], b[1009];
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
	sort(a, a + m, greater<int>());
	int ret = 0;
	for (int i = 0; i < m - 1; i++) {
		if (a[i] < n) ret += n - a[i];
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

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


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		int sum=a+b;
		int digit=1;
		while(1){
			if(sum/10>0){
				sum/=10;
				digit++;
			}else {
				break;
			}
		}
		printf("%d\n",digit);
	}
	return 0;
}

Measured memory_bytes: 1024
def check(ry, rx, x, y, f):
    tmpmin = float("inf")
    for yi in range(ry):
        tmpmin = min(tmpmin, f[yi + y][x])
    for xi in range(rx):
        tmpmin = min(tmpmin, f[y][xi + x])
    for yi in range(ry):
        tmpmin = min(tmpmin, f[yi + y][x + rx - 1])
    for xi in range(rx):
        tmpmin = min(tmpmin, f[ry - 1 + y][x + xi])
    res = 0

    for yi in range(y + 1, y + ry - 1):
        for xi in range(x + 1, x + rx - 1):
            res += tmpmin-f[yi][xi]
            if f[yi][xi] >= tmpmin:
                return 0
    return res

def main(d, w):
    field = [list(map(int, input().split())) for i in range(d)]
    res = 0
    for ry in range(3,d+1):
        for rx in range(3,w+1):
            for y in range(d - ry + 1):
                for x in range(w - rx + 1):
                    res = max(res, check(ry, rx, x, y, field))
    print(res)

while 1:
    d, w = map(int, input().split())
    if d == w == 0:
        break
    main(d, w)


Measured memory_bytes: 5628
n, m = map(int, input().split())
li = []
for i in range(n):
    array = list(map(int, input().split()))
    array = array[1:]
    li.append(array)

shugou = set(li[0])
for i in range(n):
    shugou = shugou & set(li[i])

print(len(shugou))

Measured memory_bytes: 3188
from math import sqrt
n,d=map(int,input().split())
xs=[tuple(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    xi=xs.pop()    
    for xj in xs:
        o=sqrt(sum((y-z)**2 for y,z in zip(xi,xj)))
        ans += o//1==o
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define umap unordered_map
#define uset unordered_set
#define MOD 1000000007
#define imax INT_MAX
#define imin INT_MIN
#define exp 1e9
#define sz(x) (int((x).size()))

int32_t main()
{

    int n, pp;
    cin >> n >> pp;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < n - pp; i++)
    {
        if (arr[i] < arr[i + pp])
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }

    return 0;
}

Measured memory_bytes: 5192
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int ret=0;
	for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)for(int k=0;k<=c;k++){
		if(i*500+j*100+k*50==d)ret++;
	}printf("%d\n",ret);
}


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

using ll = long long;
const long long INF = (1LL << 32);

class FloydWarshall {
    private:
    int size;
    vector<vector<long long>> d;

    public:
    FloydWarshall(int n) {
        size = n;
        d.resize(n);
        for (int i = 0; i < n; ++i) {
            d[i].resize(n);
            for (int j = 0; j < n; ++j) {
                d[i][j] = i == j ? 0 : INF;
            }
        }
    }

    void add_edge(int u, int v, int w) { d[u][v] = w; }

    long long get_distance(int src, int dest) { return d[src][dest]; }

    void set_distances() {
        for (int k = 0; k < size; ++k)
            for (int i = 0; i < size; ++i)
                for (int j = 0; j < size; ++j)
                    if (d[i][k] < INF && d[k][j] < INF)
                        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    bool has_negative_cycle() {
        for (int i = 0; i < size; ++i) {
            if (d[i][i]) return true;
        }
        return false;
    }
};

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

    int V, E;
    cin >> V >> E;

    FloydWarshall fw(V);

    for (int i = 0; i < E; ++i) {
        int s, t, w;
        cin >> s >> t >> w;
        fw.add_edge(s, t, w);
    }

    fw.set_distances();

    if (fw.has_negative_cycle()) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < V; ++j) {
                ll d = fw.get_distance(i, j);
                if (d < INF)
                    cout << d;
                else
                    cout << "INF";
                if (j < V - 1) cout << ' ';
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3236
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */



#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
#include <limits>




#include <ostream>
#include <sstream>


using namespace std;
class A {
public:
	void solve(std::istream& in, std::ostream& out) {
    ios::sync_with_stdio(false);
		int a, b, c;
		in >> a >> b >> c;
		out << (c >= a && c <= b ? "Yes" : "No") << endl;

	}
};


int main() {
	A solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007

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

int main() {
	int n;
	cin >> n;
	vector<int> v(n);

	rep(i, n)
		cin >> v[i];
	int result = 0;
	int max_res = 0;
	int piv = 0;
	rep(i, n) {
		if (piv == 0) {
			piv = v[i];
			result = 0;
			continue;
		}
		if (piv >= v[i]) {
			result++;
			piv = v[i];
			max_res = max(max_res, result);
		}
		else {
			result = 0;
			piv = v[i];
		}
	}
	cout << max_res << endl;


}



Measured memory_bytes: 640
#![allow(non_snake_case)]

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let N : isize = buf.trim().parse().unwrap();

    let mut A = vec![vec![0;13];4];
    for _ in 0..N {
        buf.clear();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        let S = iter.next().unwrap();
        let I : usize = iter.next().unwrap().parse().unwrap();
        match S {
            "S" => A[0][I - 1] = 1,
            "H" => A[1][I - 1] = 1,
            "C" => A[2][I - 1] = 1,
            "D" => A[3][I - 1] = 1,
            _ => break
        }
    }
    let suite = ["S", "H", "C", "D"];
    for s in 0..4 {
        for i in 0..13 {
            if A[s][i] == 0 {
                println!("{} {}", suite[s], i + 1);
            }
        }
    }
}



Measured memory_bytes: 5036
#define ll long long
#define dd long double
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
//#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<bitset>
dd pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll fact[100] ;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n
// ll seed;
//mt19937 rnd(seed=chrono::steady_clock::now().time_since_epoch().count()); // include bits


void solve()
{
    ll n ;
    cin >> n ;
    ll arr[n] ;
    fo(i , n)
    {
        cin >> arr[i] ;
    }
    ll ans = 0 ;
    for(ll i = 0 ; i < n ; i+=2)
    {
        if(arr[i]%2)
            ans++ ;
    }
    cout << ans << endl ;
    return ;
}

int main()
{
    /*ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif*/
    
    ll t ;
    //cin >> t ;
    t = 1 ;
   
    while(t--)
    {
        solve() ;
    }
    //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);}} premain;


static void add(ll &dst, ll src) {
	dst = (dst + src) % MOD;
}

int main() {
	int N, K;

	cin >> N >> K;

	//dp[i:左から見終わった数][j:ボール保留数][k:奇妙さ]
	ll dp[N+1][N+2][N*N+1] = {0};
	REP(i, N) REP(j, N+1) REP(k, K+1) {
		dp[i][j][k] = 0;
	}

	dp[0][0][0] = 1;

	REP(i, N) REP(j, N+1) REP(k, K+1) {
		if (0 == dp[i][j][k]) {
			continue;
		}
		int kNext = k + 2*j; //2jは見込み分

		//1. ボールiを箱iにそのまま入れる
		add(dp[i+1][j][kNext], dp[i][j][k]);

		//2. ボールiを保留している箱に入れ、箱iを保留
		add(dp[i+1][j][kNext], (dp[i][j][k] * j));

		//3. ボールiを保留している箱に入れ、箱iに保留しているボールを入れる
		if (0 < j) {
			add(dp[i+1][j-1][kNext], (dp[i][j][k] * j * j));
		}

		//4. ボールiを保留して、箱iに保留しているボールを入れる
		add(dp[i+1][j][kNext], (dp[i][j][k] * j));

		//5. ボールiを保留して、箱iを保留
		add(dp[i+1][j+1][kNext], dp[i][j][k]);
	}
	
	print(dp[N][0][K]);
	return 0;
}


Measured memory_bytes: 52096
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;


int main(){
 int n; 
string s ;
  cin >> n;
  cin >> s;
  
  long long int ans,g=0,r=0,b=0;
  
  for(int i=0;i<n;i++){
    if(s[i] == 'G') g++;
    if(s[i] == 'R') r++;
    if(s[i] == 'B') b++;
  }
  
   ans = g*r*b;
  
  for(int i=0;i<n;i++){
  for(int j=1;2*j<n-i;j++){
    if( s[i] != s[i+j] && s[i+j] != s[i+2*j] && s[i] != s[i+2*j]){
      ans--;
    }
  }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}

signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b < c + d) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
}


Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define inver(a) power(a,mod-2)
using namespace std;
inline char nc()
{
    // return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
typedef long long ll;
const int mod=1e9+7;
const int maxn=16+5;
const int maxm=16+5;
const int maxs=(1<<16)+5;
int n,m,a[maxm];
int bit[maxn];
int fac[maxs],inv[maxs];
int f[maxm][maxs];
inline void upd(int &x,int y){x+=y; if(x>=mod) x-=mod;}
ll binom(int x,int y)
{
    if(x<y) return 0;
    return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;
}
ll power(ll x,ll y)
{
    ll re=1;
    while(y)
    {
        if(y&1) re=re*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return re;
}
void init()
{
    bit[0]=1;
    for(int i=1;i<=n;++i) bit[i]=bit[i-1]<<1;
    fac[0]=1;
    for(int i=1;i<=bit[n];++i) fac[i]=(ll)fac[i-1]*i%mod;
    inv[bit[n]]=inver(fac[bit[n]]);
    for(int i=bit[n];i>=1;--i) inv[i-1]=(ll)inv[i]*i%mod;
}
int main()
{
    read(n),read(m);
    for(int i=1;i<=m;++i) read(a[i]);
    init();
    f[m+1][0]=1;
    for(int i=m;i>=1;--i) 
    {
        for(int s=0;s<bit[n];++s) if(f[i+1][s])
        {
            upd(f[i][s],f[i+1][s]);
            int tot=bit[n]-a[i]-s;
            for(int j=0;j<n;++j) if(~s&bit[j])
            {
                upd(f[i][s^bit[j]],f[i+1][s]*binom(tot,bit[j]-1)%mod*fac[bit[j]]%mod);
            }
        }
        // debug("%d\n",i);
    }
    int an=0;
    for(int s=0;s<bit[n];++s)
    {
        int c=1,tot=bit[n]-1-s;
        for(int j=0;j<n;++j) if(s&bit[j]) c=mod-c;
        upd(an,(ll)f[1][s]*c%mod*fac[tot]%mod);
        // debug("%d %d %lld\n",s,f[1][s],(ll)f[1][s]*fac[tot]%mod);
    }
    an=(ll)an*bit[n]%mod;
    printf("%d\n",an);
    return 0;
}

Measured memory_bytes: 4608
//#include "bits/stdc++.h"
//using namespace std;
//typedef long long ll;
//typedef pair<int,int> pii;
//#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
//#define all(a)  (a).begin(),(a).end()
//#define pb push_back
//#define INF 999999999
//

#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_V 100001
#define INF 999999999

struct edge{int to,cost;};
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s,int V){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep(i,V)d[i]=INF;
    d[s]=0;
    que.push(pii(0,s));
    
    while(que.size()){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[v]<p.first)continue;
        
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int v,e,r;
    cin>>v>>e>>r;
    rep(i,e){
        int s,t,d;
        cin>>s>>t>>d;
        G[s].push_back(edge{t,d});
    }
    dijkstra(r,v);
    rep(i,v){
        if(d[i]==INF)   cout<<"INF"<<endl;
        else            cout<<d[i]<<endl;
    }
}

Measured memory_bytes: 11304
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define frr(j,i,n) for(int i=j;i<=n;++i)
using namespace std;
int n;
double p[3001];
double dp[3001][3001];
double go(int index,int h)
{
	if(index==n)
	{
		if(h>(n-h))
			return (double)1;
		return (double)0;
	}
	if(dp[index][h]!=-1)
		return dp[index][h];

	double x=(p[index+1]*go(index+1,h+1));
	double y= (1-p[index+1])*go(index+1,h);
	
	return dp[index][h]= x +y;
	// return x+y;
}
void solve()
{
	frr(0,i,3000)
	{
		frr(0,j,3000)	dp[i][j]=-1;
	}
	cin>>n;
	frr(1,i,n)	cin>>p[i];
	cout<<fixed<<setprecision(10)<<go(0,0)<<"\n";
}
int main() 
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--)
	solve();
	return 0;
}



Measured memory_bytes: 74392
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    
    lli h,n;
    cin>>h>>n;
    // lli a[n];
    lli sum=0;
    lli x;
    f1(i,n) {
        cin>>x;
        sum+=x;
        // cin>>a[i];
    }
    

    (sum>=h)?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

int l1, l2, r1, r2, u1, u2, d1, d2;

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

	int h, w, n;
	cin >> h >> w >> n;
	int X, Y;
	cin >> X >> Y;
	X--; Y--;
	string a, b;
	cin >> a >> b;
	int x = X, y = Y; 
	for(int i = 0; i < n; i++){
		if(a[i] == 'U')
			x--;
		if(x < 0)
			return cout << "NO", 0;
		if(b[i] == 'D' && x < h - 1)
			x++;
	}
	x = X, y = Y;
	for(int i = 0; i < n; i++){
		if(a[i] == 'D')
			x++;
		if(x >= h)
			return cout << "NO", 0;
		if(b[i] == 'U' && x > 0)
			x--;
	}
	x = X, y = Y;
	for(int i = 0; i < n; i++){
		if(a[i] == 'L')
			y--;
		if(y < 0)
			return cout << "NO", 0;
		if(b[i] == 'R' && y < w - 1)
			y++;
	}
	x = X, y = Y;
	for(int i = 0; i < n; i++){
		if(a[i] == 'R')
			y++;
		if(y >= w)
			return cout << "NO", 0;
		if(b[i] == 'L' && y > 0)
			y--;
	}
	cout << "YES";
}

Measured memory_bytes: 920
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9+1
using namespace std;

const int maxn = 110000;

int n,m,X;
int t[maxn];
struct node{int i,a,t;}a[maxn];
inline bool cmp(const node x,const node y){return x.t<y.t;}

struct segment
{
	int lc,rc;
	int upd,add;
	int mn,mx;
}seg[maxn*50]; int root,cnt;
int newnode(const int l,const int r){ seg[++cnt]=(segment){0,0,-1,0,l,r}; return cnt; }
void pushdown(const int x,const int l,const int r)
{
	int mid=l+r>>1;
	int &lc=seg[x].lc,&rc=seg[x].rc;
	if(!lc) lc=newnode(l,mid);
	if(!rc) rc=newnode(mid+1,r);
	
	if(seg[x].upd!=-1)
	{
		int upd=seg[x].upd; seg[x].upd=-1;
		
		seg[lc].mx=seg[lc].mn=seg[lc].upd=upd; seg[lc].add=0;
		seg[rc].mx=seg[rc].mn=seg[rc].upd=upd; seg[rc].add=0;
	}
	if(seg[x].add)
	{
		int add=seg[x].add; seg[x].add=0;
		
		seg[lc].mx+=add; seg[lc].mn+=add; seg[lc].add+=add;
		seg[rc].mx+=add; seg[rc].mn+=add; seg[rc].add+=add;
	}
}
void pushup(const int x)
{
	int lc=seg[x].lc,rc=seg[x].rc;
	seg[x].mx=seg[lc].mx>seg[rc].mx?seg[lc].mx:seg[rc].mx;
	seg[x].mn=seg[lc].mn<seg[rc].mn?seg[lc].mn:seg[rc].mn;
}
int c;
void dec(int &x,const int l,const int r)
{
	if(!x) x=newnode(l,r);
	if(seg[x].mx<=c) {seg[x].mn=seg[x].mx=seg[x].upd=0;seg[x].add=0;return;}
	if(seg[x].mn>=c) {seg[x].mx-=c;seg[x].mn-=c;seg[x].add-=c;return;}
	pushdown(x,l,r);
	int mid=l+r>>1;
	dec(seg[x].lc,l,mid); dec(seg[x].rc,mid+1,r);
	pushup(x);
}
void add(int &x,const int l,const int r)
{
	if(!x) x=newnode(l,r);
	if(seg[x].mn>=X-c) {seg[x].mn=seg[x].mx=seg[x].upd=X;seg[x].add=0;return;}
	if(seg[x].mx<=X-c) {seg[x].mn+=c;seg[x].mx+=c;seg[x].add+=c;return;}
	pushdown(x,l,r);
	int mid=l+r>>1;
	add(seg[x].lc,l,mid); add(seg[x].rc,mid+1,r);
	pushup(x);
}
int loc;
int query(int &x,const int l,const int r)
{
	if(!x) x=newnode(l,r);
	if(l==r) return seg[x].mn;
	pushdown(x,l,r);
	int mid=l+r>>1;
	if(loc<=mid) return query(seg[x].lc,l,mid);
	else return query(seg[x].rc,mid+1,r);
}

int ans[maxn];

int main()
{
	scanf("%d%d",&X,&n);
	for(int i=1;i<=n;i++) scanf("%d",&t[i]); t[n+1]=inf;
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		a[i]=(node){i,y,x};
	}
	sort(a+1,a+m+1,cmp);
	
	int pos=1,si=0;
	root=cnt=0;
	for(int i=0;i<=n;i++,si=!si)
	{
		while(pos<=m&&a[pos].t<=t[i+1])
		{
			loc=a[pos].a; int now=query(root,1,X);
			if(!si) now=max(0,now-(a[pos].t-t[i]));
			else now=min(X,now+(a[pos].t-t[i]));
			ans[a[pos++].i]=now;
		}
		if(pos>m) break;
		c=t[i+1]-t[i];
		if(!si) dec(root,1,X);
		else add(root,1,X);
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	
	return 0;
}


Measured memory_bytes: 68224
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int a, b, c;
    cin >> a >> b >> c;
    if (a > b) {
        swap(a, b);
    }
    if (a < c && c < b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string str;
  cin >> str;
  if(n%2 != 0){
    cout << "No" << endl;
  }
  else{
    int i,j;
    int mid = n/2;
    int code = 1;
    for(i=0,j = mid;i<mid,j<n;i++,j++){
      if(str[i] != str[j]){
        code = 0;
        break;
      }
    }
    if(code == 0){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 256
//abc140_e.cpp
//Wed Oct 30 21:24:02 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

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

	ll p[n];
	vector<P> largeorderindex;
	for (int i=0;i<n;i++){
		cin >> p[i];
		largeorderindex.push_back(P(p[i],i));
	}

	sort(largeorderindex.rbegin(),largeorderindex.rend());

	multiset<ll> ms;
	ms.insert(-1);
	ms.insert(-1);
	ms.insert(n);
	ms.insert(n);

	ll ans = 0;
	for (int i=0;i<n;i++){
		ll curindex = largeorderindex[i].second;
		ms.insert(curindex);
		auto left_pos = ms.lower_bound(curindex);
		auto right_pos = ms.lower_bound(curindex);
		left_pos--;
		right_pos++;
		auto lleft_pos = left_pos;
		auto rright_pos = right_pos;
		lleft_pos--;
		rright_pos++;

		ll range = (*left_pos - *lleft_pos)*(*right_pos-curindex);
		range += (curindex-*left_pos)*(*rright_pos - *right_pos);
		ans += range*largeorderindex[i].first;

	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 7280
#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    #include <bitset> 
    #include <unordered_map>
    #include <unordered_set> 
using namespace std;
#define for1(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,maxn) for1(i,0,maxn)
#define ford(i,b,a) for(int i=(int)(b)-1;i>=a;--i)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii > piii;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define dprintf(...) printf(__VA_ARGS__)
const int maxn=1e5+10;
int n,m;
unordered_map<int,vector<int> > g[maxn];
unordered_map<int,int> dist[maxn];
unordered_set<int> com[maxn];
int main()
{
	scanf("%d %d",&n,&m);
	rep(i,m)
	{
		int p,q,c;
		scanf("%d %d %d",&p,&q,&c);
		p--,q--;
		g[p][c].pb(q);
		g[q][c].pb(p);
		com[p].insert(c);
		com[q].insert(c);
	}
	deque<piii > que;
	que.push_back(mp(0,mp(0,0)));
	dist[0][0]=0;
	while(!que.empty())
	{
		int d=que.front().st;
		int x=que.front().nd.st;
		int c=que.front().nd.nd;
		que.pop_front();
		if(!c)
		{
			for(unordered_set<int>::iterator it=com[x].begin();it!=com[x].end();it++)
			{
				int to=*it;
				if(dist[x].find(to)==dist[x].end()||d+1<dist[x][to])
				{
					dist[x][to]=d+1;
					que.push_back(mp(d+1,mp(x,to)));
				}
			}
			continue;
		}
		rep(i,g[x][c].size())
		{
			int to=g[x][c][i];
			if(dist[to].find(c)==dist[to].end()||d<dist[to][c])
			{
				dist[to][c]=d;
				que.push_front(mp(d,mp(to,c)));
			}
		}
		if(dist[x].find(0)==dist[x].end()||d<dist[x][0])
		{
			dist[x][0]=d;
			que.push_front(mp(d,mp(x,0)));
		}
	}
	if(dist[n-1].find(0)==dist[n-1].end())
		printf("-1\n");
	else printf("%d\n",dist[n-1][0]);
	return 0;
}

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

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

    //string s = "";
    string temp = "";

    // PWGY

    int cnt = 0;
    bool P = false;
    bool W = false;
    bool G = false;
    bool Y = false;

    for (int i = 0; i < N; i++) {
        cin >> temp;

        if (temp == "P" && !P){
            P = true;
            cnt++;
        }

        if (temp == "W" && !W){
            W = true;
            cnt++;
        }
        if (temp == "G" && !G){
            G = true;
            cnt++;
        }
        if (temp == "Y" && !Y){
            Y = true;
            cnt++;
        }
    }
    //cout <<  << endl;
    if (cnt == 3){
        cout << "Three" << endl;
    }
    if (cnt == 4){
        cout << "Four" << endl;
    }

    return 0;

}





Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

vector<pair<int, int>> solve(int n, int m) {
  int l = 1, r = n;
  vector<pair<int, int>> res;
  vector<bool> used(n + 1);
  while (m > 0) {
    if (r - l == n - r + l || used[r - l]) {
      l++;
    }
    used[r - l] = true;
    used[n - (r - l)] = true;
    res.pb({l++, r--});
    m--;  
  }
  return res;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  /*for (int n = 1; n <= 20; n++) {
    for (int m = 1; m * 2 + 1 <= n; m++) {
      cout << n << ' ' << m << endl;  
      vector<pair<int, int>> kek = solve(n, m);
      vector<int> a(n + 1);
      for (int i = 1; i <= n; i++) {
        a[i] = i;
      }
      vector<vector<bool>> used(n + 1, vector<bool>(n + 1));
      for (int i = 1; i <= n; i++) {
        for (auto it : kek) {
          for (int p1 = 1; p1 <= n; p1++) {
            for (int p2 = p1 + 1; p2 <= n; p2++) {
              if ((a[p1] == it.F && a[p2] == it.S) || (a[p1] == it.S && a[p2] == it.F)) {
                if (used[p1][p2]) {
                  cout << "ERROR\n";
                  cout << n << ' ' << m << '\n';
                  cout << p1 << ' ' << p2 << '\n';
                  //cout << i << '\n';
                  for (auto it : kek) {
                    cout << it.F << ' ' << it.S << '\n';
                  }
                  exit(0);
                }
                used[p1][p2] = true;
              }
            }
          }
        }
        for (int j = 1; j <= n; j++) {
          a[j]++; 
          if (a[j] == n + 1) {
            a[j] = 1;
          }
        }
      }
    }
  }*/
  int n, m;
  cin >> n >> m;
  auto rez = solve(n, m);
  for (auto it : rez) {
    cout << it.F << ' ' << it.S << '\n';
  }
}
    

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

int main() {
    int a, b;
    cin>>a>>b;
    
    int ans=0;
    for(int i=1; i<b-a; i++){
        ans += i;
    }
    ans -= a;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

const int MAX_N = 8;
const int RULE_NUM = 3;
const int RULE[MAX_N][RULE_NUM] = {{1, 4, -1}, {0, 2, 5}, {1, 3, 6}, {2, 7, -1},
                                   {0, 5, -1}, {1, 4, 6}, {2, 5, 7}, {3, 6, -1}};

map<string, int> BFS() {
    string goal_numbers;
    for (size_t i = 0; i < MAX_N; i++) {
        goal_numbers.push_back(i + '0');
    }

    map<string, int> distances;
    queue<string> que;
    que.push(goal_numbers);
    distances[goal_numbers] = 0;

    while (que.size()) {
        string now_numbers = que.front();
        que.pop();

        auto zero_pos = now_numbers.find('0');
        for (size_t i = 0; i < RULE_NUM; i++) {
            int new_zero_pos = RULE[zero_pos][i];
            if (new_zero_pos < 0) { continue; }
            string new_numbers = now_numbers;
            swap(new_numbers[zero_pos], new_numbers[new_zero_pos]);
            if (distances.find(new_numbers) == distances.end()) {
                que.push(new_numbers);
                distances[new_numbers] = distances[now_numbers] + 1;
            }
        }
    }

    return distances;
}

int main() {
    map<string, int> distances = BFS();

    string line;
    while (getline(cin, line)) {
        stringstream ss;
        ss << line;
        string numbers;
        for (size_t i = 0; i < MAX_N; i++) {
            char c;
            ss >> c;
            numbers += c;
        }
        cout << distances[numbers] << endl;
    }

    return 0;
}

Measured memory_bytes: 5380
//https://ykmaku.hatenablog.com/entry/2018/08/30/181652
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll MAXN = 8020;

int main()
{
  string s;
  cin >> s;
  int x,y;
  cin >> x >> y;

  vector<int> t;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'T'){
      if(cnt != 0) t.push_back(cnt);
      t.push_back(0);
      cnt = 0;
    }else{
      cnt++;
      if(i == s.size()-1) t.push_back(cnt);
    }
  }

  set<int> pos_x,pos_y;
  pos_x.insert(0);
  pos_y.insert(0);
  bool xy = true;
  for(int i = 0; i < t.size(); i++){
    set<int> pos;
    if(t[i] == 0) xy = !xy;
    else if(xy){
      for(auto itr = pos_x.begin(); itr != pos_x.end(); itr++){
        pos.insert(*itr+t[i]);
        if(i!=0) pos.insert(*itr-t[i]);
      }

      pos_x = pos;
    }else{
      for(auto itr = pos_y.begin(); itr != pos_y.end(); itr++){
        pos.insert(*itr+t[i]);
        pos.insert(*itr-t[i]);
      }
      pos_y = pos;
    }
  }

  // for(auto itr = pos_x.begin(); itr != pos_x.end(); itr++){
  //       cout << *itr << endl;
  // }

  cout << ((pos_x.find(x) != pos_x.end() && pos_y.find(y) != pos_y.end()) ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		//A
		int N = sc.nextInt();
		String N_S = String.valueOf(N);
		char N1,N2,N3,N4;
		N1 = N_S.charAt(0);
		N2 = N_S.charAt(1);
		N3 = N_S.charAt(2);
		N4 = N_S.charAt(3);
		if((N1==N2&&N1==N3)||(N2==N4&&N3==N4))
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
using namespace std;
int dp[1001][1001];
string s,t;
int n,m,a,ans;
int main(){
  cin>>a;
  for(int b=0;b<a;b++){
    cin>>s>>t;
    for(int i=0;i<=1000;i++)
      for(int j=0;j<=1000;j++)
	dp[i][j]=0;
    m=s.size();
    n=t.size();
    ans=0;
    for(int i=1;i<=m;i++){
      for(int j=1;j<=n;j++){
	if(s[i-1]==t[j-1]){
	  dp[i][j]=dp[i-1][j-1]+1;
	}else{
	  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
      }
    }  
    cout<<dp[m][n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 5116
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}


ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}


int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll s1=a*c;
    ll s2=b*d;
    ll s3=a*d;
    ll s4=b*c;
    ll s5=max(s3,s4);
    cout<<max(max(s1,s2),s5)<<endl;
}


Measured memory_bytes: 81184