akhauriyash/Code-Regression huggingface dataset:
var i,j,tmp,sum:byte;
	s,t:string;
    a:array[1..3] of byte;

begin
	for i:=1 to 3 do read(a[i]);
	s:='';
    for i:=1 to 2 do 
    	 for j:=i+1 to 3 do 
         	if (a[i]<a[j]) then 
            	begin
                	tmp:=a[i];
                    a[i]:=a[j];
                    a[j]:=tmp;
                end;
    for i:=1 to 2 do 
    	begin
        	str(a[i],t);
            s:=s+t;
        end;
    val(s,sum);
    write(sum+a[3]);
end.

Measured memory_bytes: 128
n = int(input())
s = input()

ok = [0,0,0,0,0,0,0,0,0,0]
ans = 0

for i in range(n):
    if sum(ok) == 10:
        break
    if ok[int(s[i])] == 1:
        continue
    ok[int(s[i])] = 1
    nd = [0,0,0,0,0,0,0,0,0,0]
    for j in range(i+1,n):
        if sum(nd) == 10:
            break
        if nd[int(s[j])] == 1:
            continue
        nd[int(s[j])] = 1
        rd = [0,0,0,0,0,0,0,0,0,0]
        for k in range(j+1, n):
            if sum(rd) == 10:
                break
            if rd[int(s[k])] == 1:
                continue
            rd[int(s[k])] = 1
            ans += 1

print(ans)


Measured memory_bytes: 9300
#include<iostream>
#include<cstdio>

using namespace std;


#define MAX 110
#define PA	10000

int K;
int N;
int dp[MAX][4][4][4];


int days[MAX];


//3日保持
int dfs(int day , int b1 , int b2 , int b3)
{
	//ここにreturn条件
	if (b1 != 0 && b2 != 0 && b3 != 0 &&
		b1 == b2 && b2 == b3)
	{
		return 0;
	}

	//既に到達しているならそのまま返す
	if (dp[day][b1][b2][b3] != 0)
	{
		return dp[day][b1][b2][b3];
	}

	//最後までたどり着いたとき(3日"前"までの値を保持しているので、1日分増やさなければならない)
	if (day == N + 1)
	{
		if (b1 == b2 && b2 == b3)
		{
			return 0;
		}
		return dp[day][b1][b2][b3] + 1;
	}

	if (days[day] != 0)
	{
		return dp[day][b1][b2][b3] += (dfs(day + 1 , days[day] , b1 , b2)) % PA;
	}
	//上の処理にはずれた場合
	dp[day][b1][b2][b3] += dfs(day + 1 , 1 , b1 , b2);
	dp[day][b1][b2][b3] += dfs(day + 1 , 2 , b1 , b2);
	dp[day][b1][b2][b3] += dfs(day + 1 , 3 , b1 , b2);

	return dp[day][b1][b2][b3] % PA;
}

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

	for (int i = 0; i < K; i++)
	{
		int index;
		cin >> index;
		
		cin >> days[index];
	}

	int ans = dfs(1 , 0 , 0 , 0) % PA;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1192
n, m = map(int, input().split())
constrict = [list(map(int, input().split())) for _ in range(m)]
flag = False
for i in range(10**(n-1)-1, 10**n):
    if len(str(i)) != n:
        continue
    is_correct = True
    for j, k in constrict:
        if str(i)[j-1] != str(k):
            is_correct = False
            break
    if is_correct:
        flag = True
        print(i)
        break
if not flag:
    print(-1)
        

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  string s;
  cin >> s;
  int n = s.size();
  REP(i, n-1){
    if(s[i] == s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
    if(i < n-1 && s[i] == s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    int x[n], y[n], h[n];
    int l;
    rep (i, 0, n) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0) l = i;
    }
    rep (i, 0, 101) {
        rep (j, 0, 101) {
            //{i,j}を中心,高さを求めていく
            int height = h[l] + abs (x[l] - i) + abs (y[l] - j);
            bool chk = 1;
            rep (m, 0, n) {
                if (h[m] == 0) {
                    int hm = height - abs (x[m] - i) - abs (y[m] - j);
                    if (hm <= 0) continue;
                    else {
                        chk = 0;
                        break;
                    }
                }
                int H = h[m] + abs (x[m] - i) + abs (y[m] - j);
                if (height != H) {
                    chk = 0;
                    break;
                }
            }
            if (chk) {
                cout << i << " " << j << " " << height << "\n";
                return 0;
            }
        }
    }
}

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

int main()
{
  int result = 0;
  string S;
  cin >> S;

  int length = S.size();

    rep(i,length/2){
      if(S[i]!=S[length-i-1]) result++;
    }

  cout << result;
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif
 
#define ARG4(_1,_2,_3,_4,...) _4
 
#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)
 
#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)
 
#define forv(i,v) for (auto i = v.begin(); i != v.end(); ++i)
#define forr(i,v) for (auto i = v.end(); i != v.begin() && (--i, 1); )
#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;
 
const ld pi = 3.1415926535897932384626433832795l;
 
template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T> inline T abs (T x) {return x > T() ? x : -x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 110;

string s[N];
int d[N][N];
 
int main () {
	//std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	memset(d, 1, sizeof(d));
	int n, m;
	cin >> n >> m;
	string qwe;
	getline(cin, qwe);
	forn(i, n) {
		getline(cin, s[i]);
	}
	d[0][0] = (s[0][0] == '#');
	forn(i, n) {
		forn(j, m) {
			if (i == 0 && j == 0) {
				continue;
			}
			if (i > 0) {
				int cost = (s[i - 1][j] == '.' && s[i][j] == '#');
				umn(d[i][j], d[i - 1][j] + cost);
			}
			if (j > 0) {
				int cost = (s[i][j - 1] == '.' && s[i][j] == '#');
				umn(d[i][j], d[i][j - 1] + cost);
			}
		}
	}
	cout << d[n - 1][m - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int solve()
{
    int N;

    std::cin >> N;

    int prev, curr, counter = 0, maxCounter = 0;
    std::cin >> prev;
    for (int i = 1; i < N; ++i)
    {
        std::cin >> curr;
        if (curr <= prev)
        {
            ++counter;
            maxCounter = std::max(maxCounter, counter);
        }
        else
        {
            counter = 0;
        }
        prev = curr;
    }

    return maxCounter;
}

int main()
{
    std::cout << solve() << std::endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            int[] white = new int[n];
            int[] black = new int[n];

            white[n - 1] = s[n - 1] == '.' ? 1 : 0;
            black[0] = s[0] == '#' ? 1 : 0;

            for (int i = 1; i < s.Length; i++)
            {
                black[i] = black[i - 1] + (s[i] == '#' ? 1 : 0);
            }
            for (int i = n - 2; i >= 0; i--)
            {
                white[i] = white[i + 1] + (s[i] == '.' ? 1 : 0);
            }

            int min = Math.Min(black[n - 1], white[0]);
            for (int i = 1; i < n; i++)
            {
                int next = white[i] + black[i - 1];
                min = Math.Min(next, min);
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13280
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,k=map(int,readline().split())
if k > a+b:
  print(0,0)
  quit()
if k <= a:
  print(a-k, b)
else:
  print(0, b-k+a)


Measured memory_bytes: 2940
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		m[x]++
	}

	switch len(m) {
	case 1:
		if m[0] == n {
			fmt.Println("Yes")
			return
		}
	case 2:
		if m[0] == n/3 {
			fmt.Println("Yes")
			return
		}
	case 3:
		x := 0
		for k, v := range m {
			if v != n/3 {
				fmt.Println("No")
				return
			}
			x ^= k
		}
		if x == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int a,f=0;
    a = s.size();
    for(int i=0; i<a; i++){
        if(s.at(i)!=s.at(a-i-1)) f = f + 1;
    }
    cout << f/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main(void){
	int N;
	ll H;
	cin >> N >> H;
	VL a(N), b(N);
	REP(i, N) cin >> a[i] >> b[i];
	ll amax = *max_element(a.begin(), a.end());
	int ai = distance(a.begin(), max_element(a.begin(), a.end()));
	ll bai = b[ai];
	b.erase(b.begin() + ai);
	sort(b.begin(), b.end(), greater<ll>());

	ll c = 0;

	REP(i, b.size()) {
		if (H <= bai) {
			c++;
			cout << c << endl;
			return 0;
		}
		
		if (b[i] <= amax) break;
		c++;
		H -= b[i];
		if (H <= 0) {
			cout << c << endl;
			return 0;
		}
	}

	while (H > 0) {
		if (H <= bai) H -= bai;
		H -= amax;
		c++;
	}
	
	//if (amax < bai) {
	//	H -= bai;
	//	c++;
	//}
	//if (H%amax == 0) c += H / amax;
	//if (H%amax != 0) c += H / amax + 1;

	cout << c << endl;

	return 0;
}





Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int MOD = 1e9 + 7;

ll N,M,K,H,W;

vector<ll> v;
int main(){
	cin >> N;
	double p;
	vector<vector<double>> dp(N+1, vector<double> (N+1, 0.0));
	//dp[i][j]: i枚までコイントスをしたときに、j枚が表の確率
	dp[0][0] = 1;
	for(int i = 1; i <= N; ++i){
		cin >> p;
		for(int j = 0; j <= i; ++j){
			if(j > 0) dp[i][j] += dp[i-1][j-1] * p;
			dp[i][j] += dp[i-1][j]*(1-p);
		}
	}
	double ans;
	for(int i = N/2 + 1; i <= N; ++i){
		ans += dp[N][i];
	}
	cout << setprecision(12) <<ans;
	return 0;
}
//345263555



Measured memory_bytes: 70656
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        // programming
        int n = getInputInteger(sc);
        int t = 0;
        int x = 0;
        int y = 0;
        boolean pos = true;

        for (int i = 0; i < n; i++) {
            int next_t = getInputInteger(sc);
            int next_x = getInputInteger(sc);
            int next_y = getInputInteger(sc);

            int diff_t = next_t - t;
            int diff_x = Math.abs(next_x - x);
            int diff_y = Math.abs(next_y - y);
            if (diff_t < diff_x + diff_y || (diff_t - diff_x - diff_y) % 2 != 0) {
                pos = false;
                break;
            }

            t = next_t;
            x = next_x;
            y = next_y;
        }

        if (pos) {
            output("Yes");
        } else {
            output("No");
        }
	}

	

    // ===============common===============
	public static String getInputString(Scanner sc) {
		return sc.next();
	}

	public static int getInputInteger(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	public static void output(String... params) {
		boolean isInit = true;
		String str = "";
		for (String s : params) {
			if (!isInit) {
				str += " ";
			}
			str += s;
			isInit = false;
		}
		System.out.println(str);
	}

    public static int[] toIntegerList(String[] ss) {
        return Stream.of(ss).mapToInt(Integer::parseInt).toArray();
    }

    public static String[] toList(String s) {
        String[] ret = s.split("");
        return ret;
    }

    public static int sum(int[] vals) {
        int sum = 0;
        for (int val : vals) {
            sum += val;
        }
        return sum;
    }

    public static int[] sort(int[] vals, boolean isAsc) {
        Arrays.sort(vals);
		if (isAsc) {
			return vals;
		}
        int[] ret = new int[vals.length];
        for (int i = 0; i < vals.length; i++) {
            ret[vals.length - i - 1] = vals[i];
        }
		return ret;
	}

    public static void gc() {
        System.gc();
    }
}

Measured memory_bytes: 62896
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<pair<string, ll>> st(N);
    rep(i, N) {
        string s;
        ll t;
        cin >> s >> t;
        st[i] = make_pair(s, t);
    }
    string X;
    cin >> X;
    ll ans = 0;
    bool is_add = false;
    rep(i, N) {
        if (is_add == true) {
            ans += st[i].second;
        }
        else {
            if (X == st[i].first)
                is_add = true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/* Atcoder abc151c
 * See tasks at: https://atcoder.jp/contests/abc151/tasks/abc151_c
 */
#include <iostream>
#include <vector>
#include <algorithm>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = long long;
int main()
{
    int n, m;
    cin >> n >> m;
    
    vector<int> q(m);
    vector<bool> s(m);
    vector<bool> finallly_ac(n);
    until(i, m)
    {
        int qi;
        string res;
        cin >> qi >> res;
        bool ac = res == "AC";

        q[i] = qi;
        s[i] = ac;
        if (ac)
        {
            finallly_ac[qi - 1] = true;
        }
    }

    vector<bool> ac_list(n);
    ll correct = 0, penalty = 0;
    until(i, m)
    {
        if (!ac_list[q[i] - 1])
        {
            if (s[i])
            {
                ac_list[q[i] - 1] = true;
                correct++;
            }
            else
            {
                if (finallly_ac[q[i] - 1])
                    penalty++;
            }
        }
    }

    cout << correct << " " << penalty;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t)printf("Yes");
    else printf("No");
    return 0;
    
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
# from typing import List
sys.setrecursionlimit(10 ** 7)


class UnionFind(object):
    """docstring for UnionFind"""

    def __init__(self, n):
        super(UnionFind, self).__init__()
        self.v = [-1 for _ in range(n)]

    def find_root(self, x):
        if self.v[x] < 0:
            return x
        else:
            self.v[x] = self.find_root(self.v[x])
            return self.v[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:
            x, y = y, x
        self.v[x] += self.v[y]
        self.v[y] = x

    def is_root(self, x):
        return self.v[x] < 0

    def has_same_root(self, x, y):
        return self.find_root(x) == self.find_root(y)


def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    uf = UnionFind(N)
    for x, y, z in zip(X, Y, Z):
        uf.unite(x - 1, y - 1)

    print(sum(1 for i in range(N) if uf.is_root(i)))

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    Z = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14172
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MAX = 100000;
const int INF = 1001001001;

int main() {
	int n, m;
	cin >> n >> m;
	function<int(int, int)> idx = [&](int x, int m) {
		return m % 3 * n + x;
	};
	vector<vector<int>> g(n*3);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		for (int j = 0; j < 3; j++) {
			g[idx(u, j)].push_back(idx(v, j+1));
		}
	}
	int s, t;
	cin >> s >> t;
	s--; t--;
	int d[MAX*3]; fill(d, d+MAX*3, INF);
	d[s] = 0;
	queue<int> que;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int i : g[v]) {
			if (d[i] != INF) continue;
			d[i] = d[v] + 1;
			que.push(i);
		}
	}

	int ans = d[t]!=INF ? d[t] / 3 : -1;
	cout << ans << endl;
	return 0;
}

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

class P {
public:
    P(double _x, double _y): x(_x), y(_y) {}
    P(): x(0), y(0) {}
    double x;
    double y;
    P operator-(const P& p) const {
        P point;
        point.x = x - p.x;
        point.y = y - p.y;
        return point;
    }
    P operator+(const P& p) const {
        P point;
        point.x = x + p.x;
        point.y = y + p.y;
        return point;
    }
    P operator*(double k) const {
        P point;
        point.x = x * k;
        point.y = y * k;
        return point;
    }
    double dot(const P& p) const {
        return x * p.x + y * p.y;
    }
    double length() const {
        return sqrt(x * x + y * y);
    }
};

P projection(const P& p1, const P& p2, const P& p) {
    P v1 = p - p1;
    P v2 = p2 - p1;
    double t = v1.dot(v2) / v2.length() / v2.length();
    return v2 * t + p1;
}

P reflection(P p1, P p2, P p) {
    P p3 = projection(p1, p2, p);
    return p3 - p + p3;
}
int main() {
    P p1, p2;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        P p;
        cin >> p.x >> p.y;
        p = reflection(p1, p2, p);
        cout << fixed << setprecision(15);
        cout << p.x << ' ' << p.y << endl;
    }
}



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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    ll H[100001];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    ll cnt = 0;
    ll ans = 0;
    for (int i = 0; i < N-1; i++) {
        if(H[i] >= H[i+1]){
            cnt++;
        } else {
            cnt = 0;
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4296
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=1e18;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 500005
using namespace std;
ll fact[N],invf[N];
long long powmod(long long a,long long po){
	if(po==0)return 1;
	if(po==1)return a;
	long long int p1=powmod(a,po/2ll);
	long long int p2=p1*p1;
	long long p3=powmod(a,po%2ll);
	return ((p2%mod)*(p3%mod))%mod;
}
ll ncr(ll n,ll r){
	return fact[n]*invf[r]%mod*invf[n-r]%mod;
}
void solve(){
	ll n,m;
	cin>>n>>m;
	fact[0]=invf[0]=fact[1]=invf[1]=1;
	for(ll i=2;i<=m;i++){
		fact[i]=fact[i-1]*i%mod;
		invf[i]=invf[i-1]*powmod(i,mod-2)%mod;
	}
	ll ans=ncr(m,n)*ncr(m,n)%mod*fact[n]%mod*fact[n]%mod;
	for(ll i=1;i<=n;i++){
		ll nci=ncr(n,i);
		ll mci=ncr(m,i);
		ll micni=ncr(m-i,n-i);
		ans=ans+powmod(-1ll,i)*nci%mod*mci%mod*fact[i]%mod*micni%mod*micni%mod*fact[n-i]%mod*fact[n-i]%mod;
		ans%=mod;
	}
	ans+=mod;
	ans%=mod;
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

int main() {
	std::string str;
  	std::cin >> str;
    
    std::vector<int> cnts(str.size(), 0);
  	int max = 0;
    for (int i = 0; i < str.size(); ++i) {
    	const char& c = str[i];
        if (c == 'A' || c == 'C' || c == 'T' || c == 'G') {
    		if (i == 0) {
            	cnts[i] = 1;
            } else {
            	cnts[i] = cnts[i - 1] + 1;
            }
           max = std::max(max, cnts[i]);
        } else {
        	cnts[i] = 0;
        }
    }
    
    std::cout << max << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<deque>
#include<stack>
#include<queue>
#include<sstream>
#include<cstdlib>
#define INF 16777216
typedef long long llong;
using namespace std;
deque<int>deq;
int init();
int dfs();
int s2i(string);
string i2s(int);
llong EN2D(llong,llong);
llong EN2R(llong,llong);
llong D2EN(llong,llong);
llong R2EN(llong,llong);
//
int n,tmp,flg,mx,mn,num,sum,i,j,k,H,W,avg;
int main(){
  llong M,Cd,Cr,MD,MR,RA,DA;
  int rD,rR;
  cin >> M >> rD >> rR >> Cd >> Cr;
  
  MD=D2EN(Cd,rD);
  MR=R2EN(Cr,rR);
  if(M<MD+MR){
    cout<<-1<<endl;
  }else{
    // cout<<MD<<" is MD"<<endl;
    // cout<<MR<<" is MR"<<endl;
    DA=D2EN( EN2D(10000,rD),rD);
    RA=R2EN( EN2R(10000,rR),rR);
    if(DA>RA ){
      if(DA>10000){
	//Rで最小限 Dで残りぜんぶ
	MD=M-MR;
	
	MD=D2EN(EN2D(MD,rD),rD);
	MR=R2EN(EN2R(MR,rR),rR);
	cout<<MR+MD<<endl;
	return 0;
      }
      
      
    }else{
      if(RA>10000){
      //Dで最小限 Rで残りぜんぶ
	MR=M-MD;
	
	MD=D2EN(EN2D(MD,rD),rD);
	MR=R2EN(EN2R(MR,rR),rR);
	cout<<MR+MD<<endl;
	return 0;
      }
    }
    
    cout<<M-MD-MR<<endl;
  }

  return 0;
}

llong EN2D(llong x,llong rD){
  return (rD*x)/100 + ((rD*x)%100>0);
}
llong EN2R(llong x,llong rR){
  return (rR*x)/100 + ((rR*x)%100>0);
}
llong D2EN(llong x,llong rD){
  return (100*x)/rD + ((100*x)%rD>0);
}
llong R2EN(llong x,llong rR){
  return (100*x)/rR + ((100*x)%rR>0);
}


int init(){
}
int dfs(){
}


int s2i(string str){
  int num;
  num=atoi(str.c_str());
  return num;
}

string i2s(int num){
  string str;
  stringstream s;
  s<<num;
  s>>str;
  return str;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()


const int N = 1e6 + 5, MOD = 998244353;
ll fac[N], inv[N];

ll bp(ll a, ll p) {
    ll r = 1;
    while (p > 0) {
        if (p & 1)
            r = r * a % MOD;
        a = a * a % MOD;
        p >>= 1;
    }
    return r;
}

ll c(int n, int k) {
    return fac[n] * inv[k] % MOD * inv[n - k] % MOD;
}

ll get_ways_count(int x, int y) {
    if (x < 0 || y < 0)
        return 0;
    return c(x + y, x);
}

ll get_limited_ways_count(int x, int y, int t) {
    return (get_ways_count(x, y) - get_ways_count(x + t, y - t) + MOD) % MOD;
}

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

    fac[0] = inv[0] = 1;
    for (int i = 1; i < N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = bp(fac[i], MOD - 2);
    }

    int n, k;
    cin >> n >> k;

    ll ans = 0;

    for (int i = max(n, (k + 1) / 2); i <= k; i++) {
        int j = k - i;

        if (i == j) {
            ans = (ans + get_limited_ways_count(i, j - 1, j - n + 1)) % MOD;
        }
        else {
            ans = (ans + get_limited_ways_count(i, j, i - n + 1)) % MOD;
        }
    }

    cout << ans << "\n";

    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b == c || b + c == a || a + c == b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    L = input().rstrip("\n")
    n = len(L)
    dp = [[0]*2 for _ in range(n+1)]
    dp[0][1]=1
    for i in range(n):
        if L[i]=="1":
            dp[i+1][1] = (dp[i][1]*2)%DIV
            dp[i+1][0] = (dp[i][0]*3+ dp[i][1]) % DIV
        else:
            dp[i+1][1]=dp[i][1]
            dp[i+1][0]=(dp[i][0]*3)%DIV
    return (dp[n][0]+dp[n][1])%DIV

print(main())


Measured memory_bytes: 54236
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb; 

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


int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    // ll ans = floor(N/(A+B)) * A;
    // cout << ans << endl;
    ll ans = N/(A+B) * A;
    // cout << ans << endl;
    
    ll result = N % (A+B);
    if(result < A){
        ans += result;
    }else{
        ans += A;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>

#define pi acos(-1)

#define Rep(i,x,y) for (int i=x,_Lim=y;i<=_Lim;i++)
#define Dep(i,x,y) for (int i=x,_Lim=y;i>=_Lim;i--)

using namespace std;

inline int read(){
	int f=1,res=0,ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') f=-1;ch=getchar();
	}
	while (ch>='0' && ch<='9') res=res*10+ch-48,ch=getchar();
	return f*res;
}

typedef long long ll;

int n,a,b;
int main(){
	n=read(),a=read(),b=read();
	puts((a-b)%2==0?"Alice":"Borys");
}

Measured memory_bytes: 128
/* #pragma GCC optimize("O3") */
/* #pragma GCC target ("avx2") */
/* #pragma GCC optimize("Ofast") */
/* #pragma GCC optimize("unroll-loops") */
/* #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T, typename cmp=less<T>>
using ordered_set=tree<T,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>;
template<typename K, typename V, typename cmp=less<K>>
using ordered_map=tree<K, V, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
using ll = long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax = 1000*1007;
#define ar array
#define len(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define tT template<typename T
#define tV typename V
#define ins inline string
#ifdef LOCAL
tT>ins to_string(T& t);
ins to_string(string s) {return '"' + s + '"';}
ins to_string(char c){string res="'";res.push_back(c);return res+"'";}
ins to_string(const char* s) {return to_string((string)s);}
ins to_string(char* s) {return to_string((string)s);}
template <size_t N>ins to_string(bitset<N> v) {string res="";for(size_t i = 0; i < N; i++){
res += static_cast<char>('0' + v[i]);}return res;}
ins to_string(bool b) {return (b ? "true" : "false");}
tT,tV>ins to_string(pair<T, V>& p){return "("+ to_string(p.first)+", "+to_string(p.second)+")";}
tT>ins to_string(T& v){string res="{";for(auto& i:v){res+=to_string(i)+',';} return res+'}';}
#define log(...) cerr<< "[" << #__VA_ARGS__ << " : "<< to_string(__VA_ARGS__) << "]"<<endl
#else
#define log(...) 0x30
#endif

bool solve(vector<vector<int>>& dp,int x, int y){
    if(y<0 || (y == 0 && x != 0) ||(x == 0 && y!= 0) ) return false;
    if(x == 0 && y == 0) return true;
    if(dp[x][y] != -1) return dp[x][y];
    return dp[x][y] = ((solve(dp, x-1, y-2) || solve(dp, x-1, y-4) == true)?1:0);
}

inline void test_case(){
    int x, y;
    cin>>x>>y;
    vector<vector<int>> dp(x+1, vector<int>(y+1, -1));
    if(solve(dp, x, y)){
        cout<<"Yes\n";
    }
    else cout<<"No\n";
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    tt = 1;
    for(int qq=1; qq<=tt; qq++){
        /* cout<<"Case #"<<qq<<": "; */
        test_case();
    }
}   



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

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long
#define pil pair <int, ll>
#define pii pair <int, int>

using namespace std;

ll arr[100100];
vector <pii> sweep;
set <int> nums;
ll out[100100];

bool cmp(pii a, pii b) {
  return a.first > b.first;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n) {
    cin >> arr[i];
    sweep.push_back({arr[i], i});
  }
  sweep.push_back({0, 0});
  sort(sweep.begin(), sweep.end(), cmp);

  ll tr = 0;
  int i = 0;
  while (i <= n) {
    if (i == 0) {
      tr = sweep[i].first;
      while (i <= n && sweep[i].first == tr) {
        nums.insert(sweep[i].second);
        i++;
      }
      continue;
    }
    ll novi = sweep[i].first;
    ll raz = tr - novi;
    int ind = *nums.begin();
    out[ind] += (nums.size()) * raz;
   // cout << raz << " ";
   // cout << ind << endl;
    tr = novi;
    while (i <= n && sweep[i].first == tr) {
      nums.insert(sweep[i].second);
      i++;
    }
  }
  REP(i, n) cout << out[i] << "\n";

  return 0;
}


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

int main() {
    ll s;
    cin >> s;
    int y2 = (s+1000000000-1)/1000000000;  
    int y1 = 1000000000*y2-s;
    cout << "0 0 " << 1000000000 << " " << y1 << " "<< 1 << " " << y2 << " " << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

typedef pair<int, int> P;  // index, original_value

int N;
vector<int> a, dp, ans;
vector<vector<int>> G;
stack<P> st;

void dfs(int par, int now) {
  int temp_a = a[now];
  auto iter = lower_bound(all(dp), temp_a);
  int ind = distance(dp.begin(), iter);
  st.push(P(ind, dp[ind]));
  dp[ind] = temp_a;

  iter = lower_bound(all(dp), INF);
  int inf_ind = distance(dp.begin(), iter);

  ans[now] = inf_ind;
  for (int next : G[now]) {
    if (next == par)
      continue;
    dfs(now, next);
  }

  auto ind_val = st.top();
  st.pop();
  dp[ind_val.fi] = ind_val.se;
}


signed main() {
  cin >> N;
  a.assign(N, 0);
  rep(i, N) {
    cin >> a[i];
  }

  G.assign(N, vector<int>(0));
  vector<int> u(N - 1), v(N - 1);
  rep(i, N - 1) {
    cin >> u[i] >> v[i];
    u[i]--, v[i]--;
    G[u[i]].pb(v[i]);
    G[v[i]].pb(u[i]);
  }


  ans.assign(N, 0);
  dp.assign(N, INF);

  dfs(-1, 0);
  rep(i, len(ans)) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 42132
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
  int n;
  vector<int> a;
  int k;
  cin >> n;
  rep(i,n){
    cin >> k;
    if(k%2 ==0){
      if (!(k%5==0 || k%3==0)){
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
}

Measured memory_bytes: 256
def con(m,n):
  ln = len(str(n))
  return m * 10 ** ln + n
n = int(input())
lst = [int(input()) for i in range(n)]
lst.sort()
lst = lst[0:4]
save = []
for i in lst:
  for j in lst:
    if i != j:
      save.append(con(i, j))
save.sort()
print(save[2])



Measured memory_bytes: 5924
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if a1>b1:
    a1, a2, b1, b2 = b1, b2, a1, a2
init = (a1-b1)*t1+(a2-b2)*t2
if init<0:
    print(0)
    exit(0)
elif init==0:
    print('infinity')
    exit(0)
lim = (b1-a1)*t1
if lim%init==0:
    print(lim//init*2)
else:
    print(lim//init*2+1)

Measured memory_bytes: 9160
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int64_t, int >prime_factor(int64_t n){map< int64_t, int > ret;for(int64_t i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VI d(n); REP(i,n) cin >> d[i];
    int ans = 0;
    REP(i,n)FOR(j,i+1,n) ans+=d[i]*d[j];
    out(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m;
	cin >> n >> m;
	int a[m], sum = 0;
	rep(i, m) {
		cin >> a[i];
		sum += a[i];
	}
	if(n - sum < 0) puts("-1");
	else cout << n - sum << endl;
	return 0;
}

Measured memory_bytes: 3716
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>

using namespace std;


int main()
{

  string S;
  cin >> S;

  if(S == "Sunny")  cout << "Cloudy" << endl;
  else if(S == "Cloudy")  cout << "Rainy" << endl;
  else if(S == "Rainy")  cout << "Sunny" << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N, 0);
    REP(i, N) { cin >> H[i]; }
    SORT(H);
    ll ans = LLINF;
    for(int i = 0; i + K - 1 < N; ++i) {
        ll cand = H[i + K - 1] - H[i];
        ans = min(ans, cand);
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
  int N;
  int num = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int l;
    int r;
    cin >> l >> r;
    num += r - l + 1;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
object Main extends App {
  var nm = scala.io.StdIn.readLine()
  var nm1 = nm.split(" ")
  val n = nm1(0).toInt
  val m = nm1(1).toInt
  var x = scala.io.StdIn.readLine()
  val xArray =  x.split(" ").toVector.map(_.toInt).sortBy(i => i)
  var dArray = Vector.empty[(Int,Int)]
  if(xArray.length > 1) {
    for (i <- 0 to (m - 2)) {
      val diff = (xArray(i + 1) - xArray(i)).abs
      dArray = (i + 1, diff) +: dArray
    }
    dArray = dArray.sortBy(_._2).reverse
    var sum = 0
    dArray.zipWithIndex.foreach{v =>
      if(v._2 > (n -2)) {
        sum += v._1._2
      }
    }
    println(sum)
  } else {
    println(0)
  }
}

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

int main() {
  int n,k;
  cin>>n>>k;
  int ac=0;
  int wa=0;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<k;i++){
    int x;
    string s;
    cin>>x>>s;
    if(s=="AC"){
      if(a.at(x-1)==0){
        ac++;
        a.at(x-1)=1;
      }
    }
    else{
      if(a.at(x-1)==0){
        b.at(x-1)++;
      }
    }
  }
  for(int i=0;i<n;i++){
    if(a.at(i)==1){
      wa+=b.at(i);
    }
  }
  cout<<ac<<" "<<wa<<endl;
}


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

int main(){
	int n, a[100000];
	//input
	scanf(" %d", &n);
	for(int i=0; i<n; ++i) scanf(" %d", &a[i]);
	
	const int INF = 1e9+1;
	//dp[i]:=?????????i+1??§????????????????¢??????¨????????????????????????????´????????°????
	int dp[100000];
	//initialize
	fill(dp, dp+n, INF);
	for(int i=0; i<n; ++i){
		*lower_bound(dp, dp+n, a[i]) = a[i];
	}
	
	printf("%d\n", lower_bound(dp, dp+n, INF)-dp);
}

Measured memory_bytes: 1968
//------(▼皿▼#) fxxk vjudge-------
#include <algorithm>
#include <cstdio>

const int Maxv = 200010; 

int num[Maxv], n; 
long long ans; 

int main() {
    scanf("%d", &n); 
    for (int i = 0; i < n; i++) {
        scanf("%d", &num[i]); 
        num[i] -= i + 1; 
    }
    
    std::sort(num, num + n); 
    int tmp = num[(n >> 1)]; 

    for (int i = 0; i < n; i++) 
        ans += abs(num[i] - tmp); 

    printf("%lld\n", ans); 

    return 0; 
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{ 
  int f,x,y,q,i,j,xmx[200000],xmy[200000],ymx[200000],ymy[200000];
  int xct=1,yct=1,xmm=200000,ymm=200000;
  long long int ans,n;
  cin>>n>>q;
  
  for(i=0;i<20000;i++){xmx[i]=0;xmy[i]=0;ymx[i]=0;ymy[i]=0;}
  
  xmx[0]=n;xmy[0]=n;ymx[0]=n;ymy[0]=n;
  xmm=n;ymm=n;
  
  ans=(n-2)*(n-2);
  
 
  for(i=0;i<q;i++)
  {
    cin>>f;
    
    if(f==1)
    {
      cin>>x;
      if(xmm>x)
      {
        xmm=x;
        xmx[xct]=x;
        xmy[xct]=ymy[yct-1];
        xct++;
        ans-=ymy[yct-1];
        ans+=2;

      }
      else
      {
        for(j=0;j<n;j++)
        {
          if(ymx[j]<x)
          {
            break;
          }
        }
        j--;
        ans-=ymy[j];
        ans+=2;
      }

    }
    if(f==2)
    {
      cin>>y;
      if(ymm>y){
        ymm=y;
        ymy[yct]=y;
        ymx[yct]=xmx[xct-1];
        yct++;
      
        ans-=xmx[xct-1];
        ans+=2;
       
      }
      else{
       for(j=0;j<n;j++)
        {
          if(xmy[j]<y)
          {
            break;
          }
        }
      j--;
      ans-=xmx[j];
      ans+=2;
      }
    }
  
   
 }
    cout<<ans<<endl;
  
  
  return 0;
}

Measured memory_bytes: 5060