akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int ans=1145148100;
		for(int i=0;i!=a;i++){
			int c=scan.nextInt();
			int d=scan.nextInt();
			if(d<=b) {
				if(c<=ans) {
					ans=c;
				}
			}
		}
		System.out.println(ans==1145148100?"TLE":ans);
		}
}

Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int keta(int n){
    int ans=0;
    while(n>0){
        ans++;
        n/=10;
    }
    return ans;
}
int main(void){
    string s;
    cin>>s;
    vector<long long> a(s.size());
    for(int i=0;i<s.size();i++){
        for(int j=0;j<i;j++){
            a[i]+=pow(2,j)*pow(10,i-j);
        }
        a[i]/=10;
        a[i]+=pow(10,keta(a[i]));
        a[i]*=pow(2,s.size()-i-1);
    }
    long long ans=0;
    for(int i=0;i<s.size();i++){
        ans+=(s[i]-'0')*a[s.size()-i-1];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n;
 
   cin >> n;
  
  if(n%2==0){
    cout << n/2 << endl;
  }else{
   cout << n/2+1 << endl; 
  }
  
   
   
  return 0;
}

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

using namespace std;
int d[100005];
int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++)cin>>d[i];
	sort(d,d+n);
	cout<<d[n/2]-d[n/2-1];
	return 0;
}

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

int main(void){
  string input;
  bool start_flag = false;
  int max_combo=0, current_combo=0;
  cin >> input;
  for(int i=0;i<input.size();++i){
    if(input[i] == 'A' && !start_flag){
      current_combo = 0;
      start_flag = true;
    }
    if(start_flag){
      ++current_combo;
    }
    if(input[i] == 'Z'){
      if(current_combo > max_combo){
        max_combo = current_combo;
      }
    }
  }
  cout << max_combo << endl;
}


Measured memory_bytes: 640
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<cstdio>
#include<ctime>
#include<bitset>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
LL read(){
	LL f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return f*x;
}
#define MAXN 20
#define Mod 2019
#define INF 0x3f3f3f3f
int main(){
	LL L=read(),R=read();
	if(L/Mod!=R/Mod){
		puts("0");
		return 0;
	}
	int tmp=INF;
	L%=Mod,R%=Mod;
	for(int i=L;i<=R;i++)
		for(int j=i+1;j<=R;j++)
			tmp=min(tmp,i*j%Mod);
	printf("%d\n",tmp);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N,K;
	string S;
	cin >> N;
	cin >> S;
	cin >> K;
	string s = S.substr(K-1,1);
	for (int i = 0; i < N; ++i)
	{
		if (S.substr(i,1) != s)
		{
			S.replace(i,1,"*");
		}
	}
	cout << S;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

struct custom_tf : std::numpunct<char> {
  std::string do_truename() const { return "Yes"; }
  std::string do_falsename() const { return "No"; }
};

struct Initializer {
  Initializer() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15) << std::boolalpha;
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_tf));
  }
} initializer;

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { std::cout<<'\n'; }
template<class T> inline void print(const T &x) { std::cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { std::cout<<x<<", "; print(y...); }
#define dump(...) std::cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);std::cout<<'\n';

template<class T, class U>inline bool chmax(T &a, const U &b) { if(a<b){ a=b; return 1; } return 0; }
template<class T, class U>inline bool chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }


int main() {
  int n; cin>>n;
  string a, b, c;
  cin>>a>>b>>c;
  int ans = 0;
  rep(i, n) {
    if (a[i]!=b[i] and b[i]!=c[i] and a[i]!=c[i]) ans += 2;
    else if(a[i]==b[i] and b[i]==c[i]) ans += 0;
    else ans += 1;
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=998244353;
ll mul(ll a, ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll add(ll a, ll b)
{
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a, ll b)
{
	return ((a%mod)-(b%mod)+mod)%mod;
}
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll out=0;
	out+=min(a,k);
	k-=min(a,k);
	k-=min(b,k);
	out-=min(c,k);
	cout<<out;
}

Measured memory_bytes: 3640
n = int(input())
ok = 0
i = 0
while i <= n // 4:
    j = 0
    while j <= n // 7:
        if 4*i + 7*j == n:
            ok = 1
        j += 1
    i += 1
if ok == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import javax.swing.*;
import java.io.*;
import java.sql.Struct;
import java.text.DecimalFormat;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner rd = new Scanner(System.in);
        int n = rd.nextInt();
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n - 1; i++) {
            int start = rd.nextInt() - 1;
            int end = rd.nextInt() - 1;
            if (graph[start] == null) {
                graph[start] = new ArrayList<Integer>();
            }
            if (graph[end] == null) {
                graph[end] = new ArrayList<Integer>();
            }
            graph[start].add(end);
            graph[end].add(start);
        }
        long[][] dp = new long[n][2];
        for (int i = 0; i < n; i++) {
            dp[i][0] = -1;
            dp[i][1] = -1;
        }
        long bValue = recursion(true, -1, graph, 0, dp);
        long wValue = recursion(false, -1, graph, 0, dp);
        System.out.println((bValue + wValue) %1000000007);
    }

    private static long recursion(boolean isBlack, int parent, ArrayList<Integer>[] graph, int pos, long[][] dp) {
        if (dp[pos][isBlack ? 0 : 1] != -1) {
            return dp[pos][isBlack ? 0 : 1];
        }
        long sum = 1;
        if (graph[pos] != null) {
            for (int i = 0; i < graph[pos].size(); i++) {
                int next = graph[pos].get(i);
                if (next != parent) {
                    long curSum = 0;
                    if (!isBlack) {
                        curSum += recursion(true, pos, graph, next, dp);
                    }
                    curSum += recursion(false, pos, graph, next, dp);
                    curSum = curSum % 1000000007;
                    sum = sum * curSum % 1000000007;
                }
            }
        }
        dp[pos][isBlack ? 0 : 1] = sum;
        return sum;
    }
}

Measured memory_bytes: 121996
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
map<ll, ll> mp;

int main() {
	ll sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	ll dx = tx - sx, dy = ty - sy;
	REP(i, dy) cout << "U";
	REP(i, dx) cout << "R";
	REP(i, dy) cout << "D";
	REP(i, dx) cout << "L";
	cout << "L";
	REP(i, dy + 1) cout << "U";
	REP(i, dx + 1) cout << "R";
	cout << "DR";
	REP(i, dy + 1) cout << "D";
	REP(i, dx + 1) cout << "L";
	cout << "U" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) 
{
    int a, b;
    char op;

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

    while (op != '?') {
        switch(op){
            case '+': printf("%d\n", a + b); break;
            case '-': printf("%d\n", a - b); break;
            case '*': printf("%d\n", a * b); break;
            case '/': printf("%d\n", a / b); break;
            default: break;
        }
        scanf("%d %c %d", &a, &op, &b);    
    }
    
    return 0;
} 


Measured memory_bytes: 2104
def main():
	S = input()
	K = int(input())
	# day = 5*(10**15)
	pos = 1
	for c in S:
		c_int = int(c)
		if c_int > 1:
			print(c)
			break
		if pos == K:
			print(c)
			break
		pos += 1



if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

point = 0

prev = -2

for i in range(n):
    food = a[i]-1
    point += b[food]
    if food == prev + 1:
        point += c[prev]
    prev = food

print(point)


Measured memory_bytes: 9184
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
 
#define pb push_back
#define VDEL(v, n) v.erase(v.begin() + (n))
#define ALL(v) v.begin(), v.end()
 
#define INT_INF 200000000
 
#define TINT(str) atoi(str.c_str())
#define TSTR(num) to_string(num)
 
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
 
//the end of library zone

int H, W;

int ans;

vector<string> S;

char OK[1000][1000];

void solve(int h, int w){
	queue<PII> q;
	q.push(make_pair(h, w));
	OK[h][w] = true;
	
	int sharpCount = 0;
	int dotCount = 0;
	
	int x, y;
	while(!q.empty()){
		PII now = q.front(); q.pop();
		
		char n = S[now.first][now.second];
		if(n == '#') sharpCount++;
		else dotCount++;
		
		REP(i, 4){
			x = now.first + dx[i];
			y = now.second + dy[i];
			if((0 <= x) && (x < H) && (0 <= y) && (y < W)){
				if(!((n == S[x][y]) || OK[x][y])){
					q.push(make_pair(x, y));
					OK[x][y] = true;
				}
			}
		}
	}
	
	ans += sharpCount * dotCount;
}

signed main(){
	cin >> H >> W;
	
	REP(i, H){
		string s;
		cin >> s;
		S.push_back(s);
	}
	
	REP(h, H){
		REP(w, W){
			if(!OK[h][w]) solve(h, w);
		}
	}
	
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 896
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nk = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var towns = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var trees = towns.Select(x => new Node()).ToArray();
            for (var i = 0; i < trees.Length; i++)
            {
                trees[i].Index = i;
                trees[i].Next = trees[towns[i] - 1];
            }
            var counter = new int[trees.Length];
            var index = 0;
            while (true)
            {
                counter[index]++;
                if (counter[index] == 3) break;
                index = trees[index].Next.Index;
            }
            var loopCount = 0L;
            var stepCount = 0L;
            for (var i = 0; i < counter.Length; i++)
            {
                if (counter[i] >= 2) loopCount++;
                if (counter[i] > 0) stepCount++;
            }

            var end = 0L;
            if (nk[1] < stepCount)
            {
                end = nk[1];
                index = 0;
            }
            else
            {
                end = (nk[1] - stepCount) % loopCount;
            }
            var answer = 0L;
            for (var i = 0; i <= end; i++)
            {
                answer = trees[index].Index + 1;
                index = trees[index].Next.Index;
            }
            Console.WriteLine(answer);
        }

        public class Node
        {
            public int Index { get; set; }
            public Node Next { get; set; }
        }
    }
}


Measured memory_bytes: 52556
/*input
6 18 100
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n>>x>>y;
	cout<<min(y,n*x);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,k,a[110000],dp[110000];
signed main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    fill(dp+1,dp+n,INF);
    rep(i,n-1){
        for(int j=1;j<=k;j++){
            if(i+j<n)chmin(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main() {
    string s;
    cin>>s;
    int n=s.size();
    int b=1;
    rep(i,n/2){
        if (s.at(i)!=s.at(n-1-i)){
            b=0;
        }
    }
    rep(i,n/4){
        if (s.at(i)!=s.at((n-1)/2-i-1)){
            b=0;
        }
    }
    rep(i,n/4){
        if (s.at(n-1-i)!=s.at((n+3)/2-1+i)){
            b=0;
        }
    }
    if (b==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

const int MAXN = 100005;

int n, a, b, d, x[MAXN], y[MAXN], cnt[MAXN];
bool visited[MAXN];
map<int, ordered_map> posX, posY;

int count(ordered_map &m, int lo, int hi) {
    return m.order_of_key(hi + 1) - m.order_of_key(lo);
}

int popFirst(ordered_map &m, int lo, int hi) {
    auto it = m.lower_bound(lo);
    if (it == m.end() || it->first > hi)
        return -1;
    int id = it->second;
    m.erase(it);
    return id;
}

int main() {
    scanf("%d%d%d", &n, &a, &b);
    for(int u = 1; u <= n; ++u) {
        scanf("%d%d", &x[u], &y[u]);
        // x = x + y; y = x - y
        x[u] = x[u] + y[u];
        y[u] = x[u] - 2 * y[u];
    }
    d = max(abs(x[a] - x[b]), abs(y[a] - y[b]));

    for(int u = 1; u <= n; ++u) {
        posX[x[u]][y[u]] = u;
        posY[y[u]][x[u]] = u;
    }

    for(int u = 1; u <= n; ++u) {
        cnt[u] = count(posX[x[u] - d], y[u] - d, y[u] + d);
        cnt[u] += count(posX[x[u] + d], y[u] - d, y[u] + d);
        cnt[u] += count(posY[y[u] - d], x[u] - d + 1, x[u] + d - 1);
        cnt[u] += count(posY[y[u] + d], x[u] - d + 1, x[u] + d - 1);
    }

    queue<int> q;
    q.push(a); visited[a] = true;
    q.push(b); visited[b] = true;

    while (!q.empty()) {
        int u = q.front(); q.pop();

        vector<int> toAdd;
        int v;
        while ((v = popFirst(posX[x[u] - d], y[u] - d, y[u] + d)) != -1)
            toAdd.push_back(v);
        while ((v = popFirst(posX[x[u] + d], y[u] - d, y[u] + d)) != -1)
            toAdd.push_back(v);
        while ((v = popFirst(posY[y[u] - d], x[u] - d, x[u] + d)) != -1)
            toAdd.push_back(v);
        while ((v = popFirst(posY[y[u] + d], x[u] - d, x[u] + d)) != -1)
            toAdd.push_back(v);

        for(v: toAdd) {
            if (!visited[v]) {
                visited[v] = true;
                q.push(v);
            }
        }
    }

    long long ans = 0;
    for(int u = 1; u <= n; ++u)
        if (visited[u])
            ans += cnt[u];
    ans /= 2;

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

    return 0;
}


Measured memory_bytes: 66432
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], a = rd[1], b = rd[2];
  auto v = readln.split.to!(long[]);

  v.sort!"a > b";

  auto vs = v[0..a];
  writefln("%.7f", vs.sum.to!real / a);

  auto i = 0;
  while (a-1-i >= 0 && v[a-1] == v[a-1-i]) ++i;

  auto j = 0;
  while (a-1+j <  n && v[a-1] == v[a-1+j]) ++j;

  auto pt = pascalTriangle!long(n);
  if (v[a-1] != v[0]) {
    writeln(pt[i+j-1][i]);
  } else {
    auto ans = 0L;
    foreach (k; 0..min(b-a+1,j)) ans += pt[i+j-1][i+k];
    writeln(ans);
  }
}

pure T[][] pascalTriangle(T)(size_t n)
{
  auto t = new T[][](n + 1);
  t[0] = new T[](1);
  t[0][0] = 1;
  foreach (i; 1..n+1) {
    t[i] = new T[](i + 1);
    t[i][0] = t[i][$-1] = 1;
    foreach (j; 1..i)
      t[i][j] = t[i - 1][j - 1] + t[i - 1][j];
  }
  return t;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

struct Edge
{
    int to;
    int cap;
    int rev;
};

void add_edge(map<int, vector<Edge>> &g, int from, int to, int cap)
{
    g[from].push_back((Edge){to, cap, (int)g[to].size()});
    g[to].push_back((Edge){from, 0, (int)g[from].size() - 1});
}

int dfs(map<int, vector<Edge>> &g, map<int, bool> &visited, int cur, int dst, int f)
{
    if (cur == dst)
        return f;
    visited[cur] = true;
    for (auto &e : g[cur])
    {
        if (!visited[e.to] && e.cap > 0)
        {
            int tmp = dfs(g, visited, e.to, dst, min(f, e.cap));
            if (tmp > 0)
            {
                e.cap -= tmp;
                g[e.to][e.rev].cap += tmp;
                return tmp;
            }
        }
    }
    return 0;
}
int maxFlow(map<int, vector<Edge>> &g, int s, int t)
{
    map<int, bool> visited;
    int ret = 0, tmp = 0;
    do
    {
        visited.clear();
        tmp = dfs(g, visited, s, t, IINF);
        ret += tmp;
    } while (tmp != 0);
    return ret;
}

int main(int argc, char const *argv[])
{
    map<int, vector<Edge>> g;
    int h, w;
    cin >> h >> w;
    int start = h + w;
    int end = start + 1;
    rep(i, h)
    {
        string s;
        cin >> s;
        rep(j, w)
        {
            int x = h + j;
            int y = i;
            if (s[j] == 'S')
            {
                add_edge(g, start, x, IINF);
                add_edge(g, start, y, IINF);
            }
            else if (s[j] == 'T')
            {
                add_edge(g, x, end, IINF);
                add_edge(g, y, end, IINF);
            }
            else if (s[j] == 'o')
            {
                add_edge(g, y, x, 1);
                add_edge(g, x, y, 1);
            }
        }
    }
    int ans = maxFlow(g, start, end);
    if (ans >= IINF)
        ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
import sys
readline = sys.stdin.readline

# 左から順に見ていく
# 縦に同じものが並んでいた場合、
# ・その直前が横だったら1通り
# ・その直前が縦だったら2通り
# ・最初だけは3通り
# インデックスを1進める
# 縦に違うものが並んでいた場合、(横)
# ・その直前が横だったら3通り
# ・その直前が縦だったら2通り
# ・最初だけは6通り
# インデックスを2進める

N = int(readline())
S1 = readline().rstrip()
S2 = readline().rstrip()

DIV = 1000000007

ans = 1
i = 0
same = True
while i < N:
  if S1[i] == S2[i]:
    if i == 0:
      ans *= 3
    elif not same:
      ans *= 1
    else:
      ans *= 2
    ans %= DIV
    same = True
    i += 1
  else:
    if i == 0:
      ans *= 6
    elif not same:
      ans *= 3
    else:
      ans *= 2
    ans %= DIV
    same = False
    i += 2
    
print(ans)

Measured memory_bytes: 3064
import { readFileSync } from 'fs'

const status = ['AC', 'WA', 'TLE', 'RE']

function main(input: string) {
  const [n, ...lines] = input.split('\n')

  for (const s of status) {
    const count = lines.filter(v => v === s).length
    console.log(`${s} x ${count}`)
  }
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 44844
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A >= B && A >= C){
        cout << A*10+B+C << '\n';
    }else if(B >= A && B >= C){
        cout << A+B*10+C << '\n';
    }else{
        cout << A+B+C*10 << '\n';
    }
}


Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#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>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;


signed main() {
int N,M,kl,ol,nl;
cin >> N >> M;
vector<ll> x(N),y(N),z(N),sum(N);
vector<ll> X(8);
int ite=0;
ll ans;


REP(i,N){
cin >> x[i] >> y[i] >> z[i];
}
for(int k=0;k<2;k++){
    for(int o=0;o<2;o++){
        for(int n=0;n<2;n++){
            if(k==0){
                kl=1;
            }
            else kl=-1;
            if(o==0){
                ol=1;
            }
            else ol=-1;
            if(n==0){
                nl=1;
            }
            else nl=-1;

            REP(i,N){
                sum[i] = kl*x[i]+ol*y[i]+nl*z[i];
            }
            sort(sum.begin(),sum.end());
            reverse(sum.begin(),sum.end());
            ll tmp=0; 
            REP(i,M){
                tmp+=sum[i];
            }
            X[ite]=tmp;
            ite++;




        }
    }
}
sort(X.begin(),X.end());
ans = X[7];

answer(ans);
return 0;
}


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

int main(){

   int a, b;
   
   char op;   
   
   while(1){
       cin >> a >> op >> b;
        if(op == '?')break;
        if(op == '+'){
            cout << a + b <<endl;
        }else if(op == '-'){
           cout << a - b <<endl;
        }else if(op == '*'){
           cout << a * b <<endl;
        }else if(op == '/'){
           cout << a / b <<endl;
        }
            
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<1010> fact; constexpr Prime<10> prime;
constexpr long long comb(int a, int b){if(a < b) return 0LL;if(!a or !b) return 1LL; long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b]; return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr long double PI = abs(acos(-1));
constexpr int sqrtN = 512, logN = 32;
constexpr long long LINF=1e18;

int main(){
	int a, b, x; cin >> a >> b >> x;
	
	if(x < a){
		cout << "NO" << endl;
	}else if(a <= x and x <= a + b){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i=0; i<(int)(n); ++i)
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

const int N_MAX = 1e5+1;
const int M_MAX = 1e5+1;

int main() {
  int a[5];
  REP(i, 3) cin >> a[i];
  sort (a, a+3);
  int ans = abs(a[1]-a[0]) + abs(a[2]-a[1]);
  cout << ans << endl;
}


Measured memory_bytes: 256
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e15+100)
#define N 100005



// Driver code to tes above functions
int32_t main()
{
    
 
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    
    int l, r;
    cin >> l >> r;

    if(r-l>2019)
        cout << 0;
    else
    {
        int ans = MAXI;
        for(int i=l;i<=r;i++)
        {
            for(int j=i+1;j<=r;j++)
            {
                ans = min(ans, (i*j)%2019);
            }
        }
        cout << ans;
    }

    return 0;
    
} 

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

using namespace std;

#define endl '\n'

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

const int N = 1e6+100;


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

	string s;
	cin >> s;
	if(s.find("AC")!= s.npos ){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string a;
  cin>>a;
  int answer=1;
  if(a=="RRR"){answer=3;}
  if(a=="SSS"){answer=0;}
  if(a=="RRS"){answer=2;}
  if(a=="SRR"){answer=2;}
  cout<<answer;
}

Measured memory_bytes: 3620
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int Q;
    cin>>Q;
    vector<ll> A(Q),B(Q);
    REP(i,Q) cin>>A[i]>>B[i];
    ll a,b;
    REP(i,Q){
        a=min(A[i],B[i]);
        b=max(A[i],B[i]);
        if(a!=b){
            ll c1=sqrt(a*b);
            ll ans=2*(a-1);
            if(pow(c1,2)==a*b) ans--;
            if(c1*(c1+1)>=a*b){
                ans+=min(c1-a+1,b-c1+1);
                ans+=min(b-c1-1,c1-a-1);
            }else{
                ans+=min(c1-a,b-c1-1);
                ans+=min(b-c1+1,c1-a+1);
            }
            
            cout<<ans<<endl;
        }else cout<<2*(a-1)<<endl;
    }
}

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

int N,M;
int X[101];
int A[101],B[101],C[101];
int dp[111][111][11];
int solve(int l,int r,int x){
  if( dp[l][r][x] != -1 ) return dp[l][r][x];
  if( l == r && A[x] == X[l] ) return dp[l][r][x] = 1;
  for(int i=l;i<=r-1;i++){
    if( solve(l,i,B[x]) == 1 &&
	solve(i+1,r,C[x]) == 1 ) return dp[l][r][x] = 1;
  }
  return dp[l][r][x] = 0;
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin >> N;
  for(int i=0;i<N;i++) cin >> X[i];
  cin >> M;
  for(int i=0;i<M;i++){
    cin >> A[i] >> B[i] >> C[i];
    --B[i]; --C[i];
  }
  if( solve(0,N-1,0) ) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1700
#include<stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int m[200];
	int i,k;
	int Alice = 0;
	int Bob = 0;
	int max=0;
	int number;

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

		for (i = 0; i < n;i++) {
			if (m[i] > max) {
				max = m[i];
				number = i;
			}

		}
		Alice = Alice + max;
		max = 0;
		m[number] = 0;
		number = 0;


		for (i = 0; i < n; i++) {
			if (m[i] > max) {
				max = m[i];
				number = i;
			}

		}
		Bob = Bob + max;
		max = 0;
		m[number] = 0;
		number = 0;

	}

		printf("%d",Alice-Bob);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
template<class T> inline constexpr T min(vector<T>v){return *min_element(v.begin(),v.end());}
template<class T> inline constexpr T max(vector<T>v){return *max_element(v.begin(),v.end());}
int main (){
    ll n,m,X,Y;
    cin>>n>>m>>X>>Y;
    vector<ll>x(n),y(m);
    rep(i,0,n)cin>>x[i];
    rep(i,0,m)cin>>y[i];
    x.push_back(X);
    y.push_back(Y);
    if(max(x)<min(y))cout<<"No ";
    cout<<"War\n";
}


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

using namespace std;

void init(){

}

void solve(){
    char c[4];
    scanf("%s", c);
    int tab[300];
    for(int i = 0; i < 300; i++)
        tab[i] = 0;
    for(int i = 0; i < 4; i++)
        tab[c[i]]++;
    int p = 0;
    for(int i = 65; i <= 90; i++)
        if(tab[i] == 2) p++;
    if(p != 2) printf("No\n");
    else printf("Yes");
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}



Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

max_digit = 0
for i in range(N):
    a[i] = bin(a[i])[2:][::-1]
    max_digit = max(max_digit, len(a[i]))
    
for i in range(N):
    l = '0'*(max_digit-len(a[i]))
    a[i] += l
    a[i] = a[i][::-1]

digits = [0]*max_digit    
for i in range(max_digit):
    for j in range(N):
        if a[j][i] == '1':
            digits[i] += 1
    digits[i] %= 2

ans = ['']*N
for i in range(N):
    num = a[i]
    for j in range(max_digit):
        ans[i] += str((int(num[j]) + digits[j]) % 2)
    ans[i] = str(int(ans[i],2))
        
ans = ' '.join(ans)

print(ans)

Measured memory_bytes: 142320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,m;
    cin >> n >> m;
    map<int,int>a;
    int ans=0;
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int tabemono;
            cin >> tabemono;
            a[tabemono]++;
        }
    }
   for(int i=1; i<=m; i++){
       if(a[i] == n)ans++;
   }
   cout << ans << endl;
}

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

int arr[100010] = {0};
int dp[100010] = {0};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	while(t != 0) {
	    int n;
        cin >> n;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
        }
        dp[1] = 0;
        dp[2] = abs(arr[2] - arr[1]);
        for(int i = 3; i <= n; i++) {
            dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
        }
        cout << dp[n] << "\n";
	    t--;
	}
	return 0;
}


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

using namespace std;

int main()
{
   int n,k; cin>>n>>k;
   vector<bool>v(n, 0);
   for(;k--;){
      int d;
      cin>>d;
      for(int i=0;i<d;++i){
       int x; cin>>x;
       v[x-1] = 1;
       }
   }
   cout<<count(v.begin(),v.end(),0);
   
  
   
   return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    ll sum = 0;
    rep(i,n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(all(a), greater<ll>());
    bool ok = true;
    rep(i,m){
        if(a[i] * 4 * m < sum)ok = false;
    }

    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>

#define mem(a) memset(a,0,sizeof(a))
#define inf 0x7ffffff

using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    int a,b;
    while(cin>>a>>b)
    {
        if(a*b%2==0)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 256
I=->{gets.split.map &:to_i};N,Q=I[];A=[1,c=1,1,*[0]*(N-2),1];Q.times{a,b=I[];A[a],A[b]=A[b],A[a];c=c==a ?b:c==b ?a:c;A[c-1]=A[c+1]=1};p A.reduce(:+)-2

Measured memory_bytes: 4092
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#define range(i,a,b) for(int i = (a); i <= (b); i++)
#define rrange(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,b) for(int i = 1; i <= (b); i++)
#define rrep(i,b) for(int i = (b); i >= 1; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=1e5+11;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001LL;
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int h,w,n;
ll ans,t;
struct node{
	ll c;int id;
	bool operator <(node &b){
		return c<b.c;
	}
}cost[N<<1];
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
ll ll_read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	w=read();h=read();
	n=h+w;
	rep(i,n){
		cost[i].c=ll_read();
		if(i<=w) cost[i].id=0;
		else cost[i].id=1;
	}
	sort(cost+1,cost+1+n);
	rep(i,n){
		if(cost[i].id==0){
			t=h+1;
			w--;
		}
		else{
			t=w+1;
			h--;
		}
		ans+=t*cost[i].c;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3456
mod = 1000000007
n,m = map(int, input().split())
ans = 1 if abs(n-m) == 1 else 2
if abs(n-m) > 1:
    print(0)
    quit()
for i in range(1,n+1):
    ans *= i
    ans %= mod
for i in range(1,m+1):
    ans *= i
    ans %= mod
print(ans)

Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int x[101];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> x[i];
  sort(x, x + n);
  int now = x[0], p, m = 100 * 100 * 100;
  while(now < x[n-1] + 1){
    int tmp = 0;
    for(int i = 0; i < n; i++){
      tmp += pow(x[i] - now, 2);
    }
    if (tmp < m ){
      p = now;
      m = tmp;
    }
    now++;
  }

  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 


int main() {
    int n,m;
    cin >> n >> m;
    vector<int> xs(m);
    rep(i, m) cin >> xs[i];
    if (n >= m) {
        cout << 0 << endl; 
        return 0;
    }
    vector<int> ds(m-1);
    sort(xs.begin(), xs.end());
    rep(i, m-1) ds[i] = xs[i+1] - xs[i];
    sort(ds.begin(), ds.end());
    int ret = 0;
    rep(i, m-n) ret += ds[i];
    cout << ret << endl; 
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
  int k,n,sum=0;
  cin >> n >> k;
  int l[n];
  for (int i=0;i<n;i++){
    cin >> l[i];
  }
  sort(l,l+n,greater<int>());
  for (int i=0;i<k;i++){
    sum += l[i];
  }
  cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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 = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	ll a, b;
	cin >> a >> b;
	if (a <= 9 && b <= 9) {
		cout << a * b << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 256
while True:
    n = int(raw_input())
    if n == 0:
        break
    else:
        l = []
        for i in range(n):
            num = int(raw_input())
            l.append(num)
            l.sort()
        l = l[1:-1]
        ave = float(sum(l))/len(l)
        print int(ave)
    
    

Measured memory_bytes: 6340
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
          string s;
          cin>>s;
          if(s.size()==3)  std::reverse(s.begin(), s.end());
          cout<<s;
           return 0;

        }


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 1) cout << "Hello World\n";
  else {
    int a, b;
    cin >> a >> b;
    cout << a + b << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
MOD = 10**9 + 7

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())

factorial = [1]
for i in range(1, N+1):
    factorial.append((i * factorial[-1]) % MOD)

def nCk(n, k):
    numerator = factorial[n]
    denominator = factorial[n-k] * factorial[k]
    return numerator * pow(denominator, MOD - 2, MOD)

ans = 0

A.sort()
for i in range(N-K+1):
    best = A[i]
    contribution = (best * nCk(N-i-1, K-1))
    ans = (ans - contribution) % MOD

A = A[::-1]
for i in range(N-K+1):
    best = A[i]
    contribution = (best * nCk(N-i-1, K-1))
    ans = (ans + contribution) % MOD

print ans


Measured memory_bytes: 12800
from itertools import accumulate as ac
n=int(input())
s=list(ac(list(map(int,input().split()))))
c=0
d=2
f=s[-1]
k=f
for i in range(1,n-1):
    while s[i]>s[c]+s[c+1]:
        c+=1
    while s[i]+f>s[d]+s[d+1]:
        d+=1
    j=[s[c],s[i]-s[c],s[d]-s[i],f-s[d]]
    k=min(max(j)-min(j),k)
print(k)

Measured memory_bytes: 24176
M=998244353;char S[4000];d[4001][4001];i,j,k,x;main(y){gets(S);for(**d=1;i<2*strlen(S);++i)for(S[j=i]?y=2*i+2-(x+=S[i]-48):0;~j;--j)for(k=2;k--;)d[j+!k][i-j+k]+=j-k<x&&i-j+k<=y?d[j][i-j]%M:0;printf("%d",d[x][y]%M);}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;

lint powint(lint x, lint y){
    int ret = 1;
    for (int i=0; i < y; i++) ret *= x;
    return ret;
};

vector<int> dx = {1, 0, 0, -1, 1, 1, -1, -1};
vector<int> dy = {0, -1, 1, 0, 1, -1, 1, -1};

lint powmod(lint a, lint b, lint mod = 1000000007) {
   lint res = 1;
   for (a %= mod; b; a = a * a % mod, b >>= 1)
     if (b & 1) res = res * a % mod;
   return res;
 }

int main() {
    lint n, t; cin >> n >> t;
    vlint a(n+1), b(n+1);
    rep(i, n){
        cin >> a[i+1]; cin >> b[i+1];
    }

    vlint2 dp1(n+5, vlint(t));
    vlint2 dp2(n+5, vlint(t));
    For(i, 1, n+1){
        rep(j, t){
            if (j - a[i] >= 0){
                dp1[i][j] = max(dp1[i - 1][j - a[i]] + b[i], dp1[i - 1][j]);
            }
            else{
                dp1[i][j] = dp1[i - 1][j];
            }
        }
    }
    for (int i = n+1; 1 < i; i--){
        rep(j, t){
            if (j - a[i - 1] >= 0){
                dp2[i-1][j] = max(dp2[i][j - a[i - 1]] + b[i - 1], dp2[i][j]);
            }
            else{
                dp2[i-1][j] = dp2[i][j];
            }
        }
    }

    lint ans = 0;
    For(i, 1, n+1){
        rep(j, t){
            ans = max(ans, dp1[i - 1][j] + dp2[i+1][t-1 - j] + b[i]);
        }
    }
    cout << ans << endl;
}



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

using namespace std;

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

int main(){
    int N;
    cin >> N;
    string A, B, C;
    cin >> A >> B >> C;
    ll ans = 0;
    REP(i, N){
        char a = A[i];
        char b = B[i];
        char c = C[i];

        if(a == b && b == c){
            continue;
        }
        else if(a == b || b == c || a == c){
            ans++;
        }
        else{
            ans += 2;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <functional>

using namespace std;

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

    int len = n.size();

    for(int i = 0;i < len - 8;i++){
        cout << n[i];
    }

    cout << endl;
    
  return 0;
  
}


Measured memory_bytes: 256
N,S=map(int,input().split())
A=[0]+list(map(int,input().split()))

H=[[0]*(S+1) for i in range(N+1)]

#H[x][y]:1,...xに制限したときに,和がyになるのは何個?
M=998244353

for x in range(N+1):
    H[x][0]=2**x

for x in range(1,N+1):
    for s in range(S+1):
        if s>=A[x]:
            H[x][s]=(2*H[x-1][s]+H[x-1][s-A[x]])%M
        else:
            H[x][s]=(2*H[x-1][s])%M

print(H[-1][-1])


Measured memory_bytes: 418668
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	ans = 0
	for i in range(K + 1, N + 1):
		ans += (N // i) * (i - K)
		if N % i >= K and N % i != 0:
			ans += N % i - K + 1

	if K == 0:
		print(N ** 2)
	else:
		print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  int F=0;
  int T=0;
  int O=0;
  vector<long long>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]%4==0){
      F++;
    }
    else if(A[i]%2==0){
      T++;
    }
    else{
      O++;
    }
  }
  bool flag=true;
  if(T!=0){
    if(O>F){
      flag=false;
    }
  }
  else{
    if(O>F+1){
      flag=false;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
  

Measured memory_bytes: 1024
n,m=map(int,input().split())
if m==0:
  print(0,0)
else:
  q=[0]*(n+1)
  s=[0]*(n+1)
  t=0
  for i in range(m):
    p,u=map(str,input().split())
    p=int(p)
    if q[p]==1:
      continue
    
    elif u=='AC':
      q[p]=1
      
      t+=s[p]
      
      
    elif u=="WA":
      if q[p]==0:
        s[p]+=1
        
  
  
  
  
  print(sum(q),t)
  

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            int count=0,a=1;
            for (int i=2;n-a>0;i++) {
                if ((n-a)%i==0) {
                    count++;
                }
                a+=i;
            }
            cout<<count<<endl;
        }
    }
}



Measured memory_bytes: 3064