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

int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
  int answer;
  
  if(op =="+"){
    answer = A + B;
  }
  else{
    answer = A - B;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    h = list(map(int, readline().split()))
    h.sort(reverse=True)
    print(sum(h[k:n]))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 75888
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, i, j, k, s, ans, x, xx;
	cin >> n >> k;
	vector<long long> a(n), b(n);
	for (i = 0; i < n; i++) cin >> a[i] >> b[i];

	vector<long long> t;
	t.push_back(k);
	xx = 0;
	for (i = 40; i >= 0; i--) {
		x = 1LL << i;
		if (x & k) {
			t.push_back(xx + (x - 1));
			xx += x;
		}
	}

	ans = 0;
	for (auto p : t) {
		s = 0;
		for (i = 0; i < n; i++) {
			if ((a[i] | p) == p) s += b[i];
		}
		ans = max(ans, s);
	}
	cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 2168
#include <stdarg.h>
#include <stdio.h>
#include <string.h>

int max(int len, ...) {
    int i, _max, num;
    va_list ap;
    va_start(ap, len);

    _max = va_arg(ap, int);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, int);
        if (num > _max)
            _max = num;
    }
    va_end(ap);
    return _max;
}

int main(void) {
    int dp[20]={0}, i, j, len, m;
    char S[20];
    scanf("%s", &S);
    len = strlen(S);

    for (i=0;i<len;i++) {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
            dp[i]++;
            for (j=i+1;j<len;j++) {
                if (S[j] == 'A' || S[j] == 'T' || S[j] == 'C' || S[j] == 'G') {
                    dp[i]++;
                } else break;
            }
        }
    }

    m = 0;
    for (i=0;i<len;i++) m = max(2,m,dp[i]);
    printf("%d\n", m);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
LL INF = 1e9;

int main(){
    int N, K;
    string s;
    cin >> N >> K >> s;
    vector<int> ss, p;
    for(int i = 0;i < s.size();i++){
        if(s[i] == '0') ss.push_back(-1);
        else    ss.push_back(1);
    }
    int cnt = ss[0];
    for(int i = 1;i < s.size();i++){
        if(cnt*ss[i] > 0){
            cnt += ss[i];
        }else{
            p.push_back(cnt);
            cnt = ss[i];
        }
        if(i == s.size()-1) p.push_back(cnt);
    }
    if(N == 1)  p.push_back(cnt);
    cnt = 0;
    int r = -1, l = -1;
    LL ans = -INF;
    LL res = 0;
    while(true){
        while(cnt <= K){
            if(l == p.size()-1){
                ans = max(ans, res);
                goto loop;
            }
            if(p[l+1] < 0 && cnt == K)  break;
            res += abs(p[++l]);
            if(p[l] < 0)    cnt++;
        }
        ans = max(ans, res);
        res -= abs(p[++r]);
        if(p[r] > 0)    res -= -p[++r];
        cnt--;
    }
loop:
    cout << ans << endl;
}

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

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

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

int main(void){

    int n;
    cin >> n;

    map<string, int> mp;

    roop(i, n){
        string s; cin >> s;
        mp[s];
    }

    cout << mp.size() << endl;

    return 0;
}


Measured memory_bytes: 19260
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000000007

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))
#define mx 6e5 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#include<bits/stdc++.h>
#define ll long long
const int maxn = 20005;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


int main ()
{
    fast;
    ll n;
    cin>>n;
    ll c =0;
    while(n/2 != 0 )
    {
        c++;
        n = n/2;
    }
    
    
    ll ans = 1;
    for(int i=0;i<=c;i++)
    {
        ans *= 2;
    }
    
    cout<<ans-1<<endl;
    
    
}


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
	static int[][] list;
	public static void main(String[] args) {
		
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			PriorityQueue<Integer> que = new PriorityQueue<Integer>(n);
			for(int i = 0; i < n; i++) {
				que.add(sc.nextInt());
			}
			long sum = 0;
			long time = 0;
			for(int i = 0; i < n; i++) {
				time += sum;
				sum += que.poll();
			}
			
			out.println(time);
		}
		out.flush();
	}
	static void solv(int a, int b, boolean[] c) {
		list[a][b]++;
		if(a == 9) return;
		if(b > 1000) return;
		
		for(int i = 0; i < 101; i++) {
			if(a == 8) {
				if(!c[i]) {
					list[a+1][b+i]++;
				}
			}
			
			else if(!c[i]) {
				c[i] = true;
				solv(a+1,b+i,c);
				c[i] = false;
			}
		}
	}
}
//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
    

}

Measured memory_bytes: 20504
/*
    e
*/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define N 15
#define bit(i) (1 << i)

using namespace std;

int n, m;
int f[5000];

inline void cmin(int &u, const int delta) { (u > delta) && (u = delta); }
inline int Rd() {
	int x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}

int main() {
	n = Rd(), m = Rd();
	int upp = 1 << n;
	memset(f, 32, sizeof f), f[0] = 0;
	for(int i = 1; i <= m; ++i) {
		int a = Rd(), b = Rd(), mask = 0;
		for(int j = 1; j <= b; ++j) {
			int v = Rd();
			mask |= bit(v - 1);
		}
		for(int sta = 0; sta < upp; ++sta) {
			cmin(f[sta | mask], f[sta] + a);
		}
	}

	if(f[upp - 1] == f[4999]) {
		puts("-1");
		return 0;
	}
	cout << f[upp - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,a[100010]={},ans[100010]={};
  scanf("%d",&n);
  for(int i=1;i<n+1;i++){
    scanf("%d",&a[i]);
    //printf("a[%d]=%d",i,a[i]);
    ans[a[i]]=i;
  }
  for(int i=1;i<n+1;i++){
    printf(" %d",ans[i]);
  }
  return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

int main(void) {
    int N, P;
    int sum = 0, max_price = 0;
    if (scanf("%d ", &N) != EOF) {
        for (int i = 0; i < N; i++) {
            if (scanf("%d", &P) != EOF) {
                sum += P;
                if (max_price < P) {
                    max_price = P;
                }
            }
        }
    }
    printf("%d", sum-max_price+(max_price/2));
    return 0;
}

Measured memory_bytes: 128
#!python3

# input
N = int(input())


def solve(x):
    ans = []
    while x != 1:
        if x % 2 == 1:
            ans.append(1)
            x = (x - 1) // -2
        else:
            ans.append(0)
            x //= -2
    
    ans.append(1)
    s = sum([-2 ** i for i in range(len(ans)) if ans[i] == 1])
    if s != x:
        ans = ans[::-1]
    print("".join(map(str, ans)))


def main():
    if N == 0:
        print(0)
    else:
        solve(N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, k;
  cin >> n >> k;
  int tgt = 0;
  for (int i=0; i<n; ++i) {
    int a;
    cin >> a;
    if (a == 1) tgt = i;
  }
  cout << (n-2)/(k-1)+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char A[11];
char B[11];
char C[11];

int main() 
{
	int i;
	int f = 0;
	int rtn;

	rtn = scanf("%s %s %s", A, B, C);

	for (i = 0; i < 11; i++) {
		if (A[i] == '\0') {
			if (A[i - 1] == B[0]) {

				for (i = 0; i < 11; i++) {
					if (B[i] == '\0') {
						if (B[i - 1] == C[0]) {
							f = 1;
						}
						else {
							f = 0;
						}
						break;
					}
				}
			}
			else {
				f = 0;
			}
			break;
		} 
	}

	

	if (f == 1) printf("YES");
	if (f == 0) printf("NO");

	return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	n = n+1
	emp := make([]int,n)
	
	num := 0
	for i := 2; i < n; i++ {
		fmt.Scan(&num)
		emp[num]++
	}

	for i := 1; i < n; i++ {
		fmt.Println(emp[i])
	}
}

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

using i64 = int_fast64_t;
using f64 = double;

void solve() {
    i64 h, w, n;
    cin >> h >> w >> n;
    i64 p = max(h, w);
    cout << (n + p - 1) / p << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int ans;
int n, s;
//cnt := ??????????????????
void bfs(int cnt, int sum, int times){
    if(cnt == n){
        if(sum == s){
            ans++;
        }
        return;
    }
    if(times == 10){
    	return;
    }
    bfs(cnt+1, sum+times, times+1);
    bfs(cnt, sum, times+1);
}
int main(void){
    while(cin >> n >> s && n+s != 0){
        ans = 0;
        bfs(0,0,0);
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

const int INF = 111111111;


struct edge{
    int f,t,c,id;
    edge(){};
    edge(int f_,int t_,int c_,int id_):f(f_),t(t_),c(c_),id(id_){};
    bool operator< (const edge &e){
        return c < e.c;
    }
};

struct graph{
    vector<vector<edge> > E;
    int V;
    graph(int V_):E(V_),V(V_){};
};

vector< vector<int> > WF_L(graph &G){
    vector< vector<int> > res(G.V,vector<int>(G.V,INF));
    for(int i=0;i<G.V;i++)res[i][i] = 0;
    for(auto&& V:G.E){
        for(auto&& e:V){
            if(e.id==0)continue;
            res[e.f][e.t] = min(res[e.f][e.t],e.c);
        }
    }
    for(int k=0;k<G.V;k++){
        for(int i=0;i<G.V;i++){
            for(int j=0;j<G.V;j++){
                if(res[i][k]<INF && res[k][j]<INF)res[i][j] = min(res[i][j],res[i][k] + res[k][j]);
            }
        }
    }
    return res;
}

vector< vector<int> > WF_S(graph &G){
    vector< vector<int> > res(G.V,vector<int>(G.V,numeric_limits<int>::max()/4));
    for(int i=0;i<G.V;i++)res[i][i] = 0;
    for(auto&& V:G.E){
        for(auto&& e:V){
            if(e.id==1)continue;
            res[e.f][e.t] = min(res[e.f][e.t],e.c);
        }
    }
    for(int k=0;k<G.V;k++){
        for(int i=0;i<G.V;i++){
            for(int j=0;j<G.V;j++){
                if(res[i][k]<INF && res[k][j]<INF)res[i][j] = min(res[i][j],res[i][k] + res[k][j]);
            }
        }
    }
    return res;
}

int main(){
    int n,m;
    while(true){
        cin >> n >> m;
        if(!n && !m)break;
        graph G(n);
        for(int i=0;i<m;i++){
            int x,y,t;char s;
            cin >> x >> y >> t >> s;
            x--;y--;
            G.E[x].emplace_back(x,y,t,(int)s=='L');
            G.E[y].emplace_back(y,x,t,(int)s=='L');
        }
        int r;
        cin >> r;
        vector<int> R(r);
        for(int i=0;i<r;i++){
            cin >> R[i];R[i]--;
        }
        vector<vector<int> > L = WF_L(G);
        vector<vector<int> > S = WF_S(G);
        vector<vector<int> > dp(r,vector<int>(n,INF));
        // cerr << L.size() << " " << L[0].size() << endl;
        // cerr << dp.size() << " " << dp[0].size() << endl;
        dp[0][R[0]] = 0;
        //todo
        //dp[wentRs][ship]
        //land -> ship -> land
        for(int i=0;i<r-1;i++){
            // cerr << i << endl;
            for(int j=0;j<n;j++){
                // cerr << i << " " << j << endl;
                if(L[R[i]][R[i+1]]<INF)dp[i+1][j] = min(dp[i+1][j],dp[i][j] + L[R[i]][R[i+1]]);
                for(int k=0;k<n;k++){
                    if(L[R[i]][k] < INF && S[k][j] < INF && L[j][R[i+1]] < INF)
                        dp[i+1][j] = min(dp[i+1][j],dp[i][k] + L[R[i]][k] + S[k][j] + L[j][R[i+1]] );
                }
            }
        }
        int res = INF;
        for(int i=0;i<n;i++){
            res = min(dp[r-1][i],res);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 4388
function main(input) {
    var moneys = [300000,200000,100000];
    var inputs = input.split(' ');
    var codeRank = parseInt(inputs[0],10);
    var machineRank = parseInt(inputs[1],10);
    var ret = 0;
    if(codeRank <= 3)
        ret += moneys[codeRank -1];
    if(machineRank <= 3)
        ret += moneys[machineRank -1];
    if((codeRank == 1) && (machineRank == 1))
        ret += 400000;
    console.log(ret);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <stdio.h>

int main(void) {

  int a,b,c,d,e,f;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
  int operation_a,operation_b,operation_c,operation_d;
  int w,s,max_s;
  int percent_n,percent_d;
  int max_percent_n = 0;
  int max_percent_d = 1;
  int ans_w = 0;
  int ans_s = 0;
  for (operation_a = 0; a*100*operation_a <= f; operation_a++) {
    for (operation_b = 0; ; operation_b++) {
      w = (a*operation_a+b*operation_b)*100;
      if (w > f) {
        break;
      }
      if (w == 0) {
        continue;
      }
      max_s = w/100*e;
      if (max_s > f-w) {
        max_s = f-w;
      }
      for (operation_c = 0; c*operation_c <= max_s; operation_c++) {
        operation_d = (max_s-c*operation_c)/d;
        s = c*operation_c+d*operation_d;
        percent_n = s;
        percent_d = w+s;
        if (max_percent_n*percent_d <= max_percent_d*percent_n) {
          max_percent_n = percent_n;
          max_percent_d = percent_d;
          ans_w = w;
          ans_s = s;
        }
      }
    }
  }
  printf("%d %d\n", ans_w+ans_s, ans_s);

  return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N, K, S;
    const int M = 1000000000;
    cin >> N >> K >> S;

    vector<int> ans;

    if (K == 0) {
        if (S == M) {
            REP(i, N) {
                ans.push_back(M-1);
            }
        } else {
            REP(i, N) {
                ans.push_back(M);
            }
        }
    } else {
        while (K > 0) {
            ans.push_back(S);
            K--;
        }
        REP(i, N-K) {
            if (S == M) {
                ans.push_back(M-1);
            } else {
                ans.push_back(M);
            }
        }
    }
    REP(i, N) {
        cout << ans[i];
        if (i == N-1) cout << endl;
        else cout << " ";
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 2292
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		
		if(S>W){
			System.out.println("safe");
        }else{
			System.out.println("unsafe");
        }
    }
}


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

signed main(){
    int a,b;cin>>a>>b;
    if(a<=0&&b>=0) cout<<"Zero"<<endl;
    else if(a>0||(b-a+1)%2==0) cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] arg) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		if(s.equals("ABC")){
			System.out.println("ARC");
		} else if(s.equals("ARC")){
			System.out.println("ABC");
		}
	}
}


Measured memory_bytes: 35740
/* author   : mpily :-()
title : Competing.cpp
time :Sat Dec 21 08:03:17 2019

*/
#include<bits/stdc++.h>
using namespace std;
int info[16][16];

int dfs(vector<int>&status, int pos){
	int witho= 0; int withw = 0;
	if(pos >= status.size()){
		int count = 0;
		for(int i = 1; i < status.size(); i++){
			count+=status[i];
		}
		return count;
	}
	int can = 1;
	for(int i = 1; i < pos; i++){
		if(status[i] && info[i][pos] == 0){
			can = 0; break;
		}
		if(status[i] && info[pos][i] == 0){
			can = 0; break;
		}
		if(!status[i] && info[pos][i] == 1){
			can = 0 ; break;
		}
	}
	if(can){
		status[pos] = 1;
		witho = (dfs(status,pos+1));
	}
	can = 1;
	for(int i = 1; i < pos; i++){
		if(status[i] && info[i][pos] == 1){
			can = 0; break;
		}
		
	}
	if(can){
		status[pos] = 0;
		withw = (dfs(status,pos+1));
	}
	return max(witho, withw);
}
int main(){
	int N;	
	cin>>N;
	vector<int>status(N+1);
	for(int i = 1; i <= N; i++){
		for(int j = 1 ; j <= N; j++)info[i][j] = -1;
		int A;
		cin>>A;
		for(int j = 0; j < A; j++){
			int X,Y;
			cin>>X>>Y;
			info[i][X] = Y;
		}
		
	}
	int ans1 = 0;int ans2 = 0;
	status[1] = 0;
	ans1 = dfs(status,2);
	status[1] = 1;
	ans2 = dfs(status,2);
	int ans3 = max(ans1,ans2);
	cout<<ans3<<"\n";
	
	return 0;
}


Measured memory_bytes: 256
def printlist(l):
    s = str(l[0])
    for i in range(len(l)-1):
        s += " " + str(l[i+1])
    print(s)
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
clist = []
for i in range(n):
    clist += [i+1 for j in range(a[i])]
for i in range(h):
    if i%2 == 0:
        printlist(clist[i*w:(i+1)*w])
    else:
        printlist(clist[(i+1)*w-1:i*w-1:-1])

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 998244353;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll a, b;
    string s;
    cin >> a >> b >> s;
    ll n = s.size();

    rep(i, n) {
        if(s[a] != '-') {
            out("No");
            re0;
        }
        if(i != a && s[i] == '-') {
            out("No");
            re0;
        }
    }
    
    out("Yes");
    re0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = [int(n) for n in input().split()]
ex = [0]*N
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        ex[B-1] += 1
    elif H[A-1] < H[B-1]:
        ex[A-1] += 1
    else:
        ex[B-1] += 1
        ex[A-1] += 1
count = 0
for i in range(N):
    if ex[i] == 0:
        count += 1
print(count)

Measured memory_bytes: 20152
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll solve(ll w,ll a,ll b){
    int res;
    int c = min(a,b);
    int d = max(a,b);
    c += w;
    res = d-c<0 ? 0:d-c;
    return res;
}

int main(){
    int n,m;cin>>n>>m;
    vector<pair<int,int>> students;
    vector<pair<int,int>> checkPoints;

    fore(i,0,n){
        int val1,val2;cin>>val1>>val2;
        students.pb(make_pair(val1,val2));
    }
    fore(i,0,m){
        int x,y;cin>>x>>y;
        checkPoints.pb(make_pair(x,y));
    }

    fore(i,0,n){
        ll min = 300000000;
        int idx = -1;
        fore(j,0,m){
            ll temp = abs(students[i].first-checkPoints[j].first)+abs(students[i].second-checkPoints[j].second);
            //cout<<temp<<"- \n";
            if(temp<min){min=temp;idx=j+1;}
        }
        cout<<idx<<"\n";
    }
    
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

int main() {
	int n;
	string s[100],result = "Three";
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	for (int i = 0; i < n; ++i) {
		if (s[i] == "Y") result = "Four";
	}
	cout << result << endl;
	
	return 0;
}

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

map<int, int> mp;

int main()
{
    int a, n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        scanf("%d", &a);
        if(mp[a]){
            puts("NO");
            return 0;
        }
        else mp[a] = 1;
    }
    puts("YES");

    return 0;
}

Measured memory_bytes: 9600
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0])-1;
        long diff = int.Parse(str[2])-int.Parse(str[1]);
        long C = int.Parse(str[3]);
        long D = int.Parse(str[4]);
        int bf = 0;
        int bl = N+1;
        while(bf != bl){
            int bc = (bf+bl)/2;
            if(bc == N+1 || bc*D-(N-bc)*C >= diff){
                bl = bc;
            }
            else{
                bf = bc+1;
            }
        }
        if(bf == N+1){
            sb.Append("NO\n");
            return;
        }
        if(bf*C-(N-bf)*D <= diff){
            sb.Append("YES\n");
        }
        else{
            sb.Append("NO\n");
        }
    }
}

Measured memory_bytes: 11092
def solve(fld)
  $h.times do |y|
    fld[y].each_cons(2).with_index do |(a, b), x|
      if a != b
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
        return true if search(adjust(fld.transpose))
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
      end
    end
  end
  false
end
 
def search(fld)
  return true if fld.flatten.all?{ |v| v == '.' }
  nfld = fld.map{ |f| f.dup }
  count(fld, $w) do |ret|
    ret.each do |y, x|
      $n.times{ |i| nfld[y][x + i] = nil }
    end
  end
  count(fld.transpose, $h) do |ret|
    ret.each do |y, x|
      $n.times{ |i| nfld[x + i][y] = nil }
    end
  end
  return false unless nfld.flatten.any?{ |v| v.nil? }
  search(adjust(nfld))
end
 
def count(fld, r)
  ret = []
  r.times do |y|
    fld[y].each_cons($n).with_index do |ar, x|
      next if ar[0] == '.'
      ret << [y, x] if ar.all?{|v| v == ar[0] }
    end
  end
  yield(ret)
end
 
def adjust(fld)
  $w.times do |x|
    fld[x].map! { |v| v if /[A-Z]/ =~ v }.compact!
    ($h - fld[x].size).times{ fld[x].unshift('.') }
  end
  fld
end
 
$h, $w, $n = gets.split.map(&:to_i)
fld = $h.times.map{ gets.chomp.split('') }
puts solve(fld) ? 'YES' : 'NO'

Measured memory_bytes: 11292
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}
 
struct IoSetup {
  	IoSetup() {
    	cin.tie(nullptr);
    	ios::sync_with_stdio(false);
    	cout << fixed << setprecision(10);
  	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        sz--;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() {return sz;}
};

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

	UnionFind uf(N);

	rep (i, M) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		uf.unionSet(a, b);
	}

	int ans = 0;
	rep (i, N) chmax(ans, uf.size(i));

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


Measured memory_bytes: 4000
#define _CRT_SECURE_NO_WARNINGS
#define lp(i,n) for(int i=0;i<n;i++)
#include<bits/stdc++.h>

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (b % a == 0)
		cout << a + b << endl;
	else
		cout << b - a << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int 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^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int main()
{
    int n;
    cin>>n;
    n%=10;
    if(n==2||n==4||n==5||n==7||n==9) cout<<"hon"<<endl;
    else if(n==0||n==1||n==6||n==8) cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	double a[1005];
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> a[i];
		a[i] = 1 / a[i];
	}
	double s = 0;
	for(int i = 0; i < N; i++){
		s += a[i];
	}
	cout << (1 / s);
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;



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

	int K,N;
	cin >> K >> N;

	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
	}

	int submax = 0;
	rep(i, N) {
		int sub;
		if (i == N - 1) {
			sub = K - A[i] + A[0];
		}
		else {
			sub = A[i + 1] - A[i];
		}

		if (submax < sub) {
			submax = sub;
		}
	}

	cout << K - submax << endl;

	return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict
N = int(input())
li = [int(x) for x in input().split()]
Q = int(input())

d = defaultdict(int)

for i in li:
    d[i] += 1

ans = sum(li)
for i in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * d[B]
    d[C] += d[B]
    d[B] = 0
    print(ans)


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

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long num = 0;
	sort(a.begin(), a.end());
	for (int i = 0; i < n - k ; i++) {
		num += a[i];
	}
	cout << num;
	
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;
//const int p = 31;

int a[1000], b[1000], mark[1000], n;

int main()
{
    //ifstream cin ("gen.in");
    //ofstream cout ("sysadmin.txt");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    for (int i = 0; i < 9; i++)
    {
        cin >> a[i];
    }
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
        for (int j = 0; j < 9; j++)
        {
            if (b[i] == a[j]) mark[j] = 1;
        }
    }
    if (mark[0] == 1 && mark[1] == 1 && mark[2] == 1) {cout << "Yes"; return 0;}
    if (mark[3] == 1 && mark[4] == 1 && mark[5] == 1) {cout << "Yes"; return 0;}
    if (mark[6] == 1 && mark[7] == 1 && mark[8] == 1) {cout << "Yes"; return 0;}
    if (mark[0] == 1 && mark[3] == 1 && mark[6] == 1) {cout << "Yes"; return 0;}
    if (mark[1] == 1 && mark[4] == 1 && mark[7] == 1) {cout << "Yes"; return 0;}
    if (mark[2] == 1 && mark[5] == 1 && mark[8] == 1) {cout << "Yes"; return 0;}
    if (mark[0] == 1 && mark[4] == 1 && mark[8] == 1) {cout << "Yes"; return 0;}
    if (mark[2] == 1 && mark[4] == 1 && mark[6] == 1) {cout << "Yes"; return 0;}
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lson x<<1
#define rson x<<1|1
#define mid ((l+r)>>1) 
int n,m,a[200100],mx[800100],f[200100];
vector<int>v[200100],u;
void pushup(int x){
	mx[x]=max(mx[lson],mx[rson]);
}
int modify(int x,int l,int r,int P,int vl){
	if(l>P||r<P)return 0;
	if(l==r){int tmp=mx[x];mx[x]=vl;return tmp;}
	int tmp=modify(lson,l,mid,P,vl)+modify(rson,mid+1,r,P,vl);
	pushup(x);
	return tmp;
}
int query(int x,int l,int r,int P){
	if(l>P)return 0;
	if(r<=P)return mx[x];
	return max(query(lson,l,mid,P),query(rson,mid+1,r,P));
}
void dfs(int x,int fa){
	f[x]=query(1,1,m,a[x]-1)+1;
	int las=modify(1,1,m,a[x],f[x]);
	f[x]=max(f[x],f[fa]);
	for(auto y:v[x])if(y!=fa)dfs(y,x);
	modify(1,1,m,a[x],las);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),u.push_back(a[i]);
	sort(u.begin(),u.end()),u.resize(m=unique(u.begin(),u.end())-u.begin());
	for(int i=1;i<=n;i++)a[i]=lower_bound(u.begin(),u.end(),a[i])-u.begin()+1;
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),v[x].push_back(y),v[y].push_back(x);
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d\n",f[i]);
	return 0;
}

Measured memory_bytes: 30720
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        int count = 0;
        for(String s: String.valueOf(input).split("")){
            if(s.equals("1")){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		String[] s = stdIn.next().split("");
		
		long a = 0;
		for(int i = 0; i < s.length; i++) {
			a += Integer.parseInt(s[i]);
		}
		if(a % 9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		

	}

}


Measured memory_bytes: 54368
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

bool fun(vi &a,vi &b)
{
    ll sum1=0;
    ll sum2=0;
    for(ll i=0;i<3;i++)
    {
        sum1+=a[i];
        sum2+=b[i];
    }
    return sum1>sum2;
}

int main()
{
    fast();
    ll n,m;
    cin>>n>>m;
    vv a(n,vi(3));
    cin>>a;
    ll ans=-inf;
    for(ll mask=0;mask<8;mask++)
    {
        vi mul(3,-1);
        for(ll i=0;i<3;i++)
        {
            if(mask&(1<<i))
            {
                mul[i]=1;
            }
        }
        vv b(a);
        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<3;j++)
            {
                b[i][j]*=mul[j];
            }
        }
        sort(all(b),fun);
        ll curr=0;
        for(ll i=0;i<m;i++)
        {
            for(ll j=0;j<3;j++)
            {
                curr+=b[i][j];
            }
        }
        ans=max(ans,curr);
    }
    cout<<ans<<nl;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  string s;
  cin >> s;
  if(s>"2019/04/30")printf("TBD");
  else printf("Heisei");
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

def comp(i, j):
    for x in range(m):
        for y in range(m):
            if a[i+x][j+y] != b[x][y]:
                return False
    return True

ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        if comp(i, j):
            ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)


string s;
long long k;
int main(){
    cin >> s >> k;
    int i = 0;
    while(s[i]=='1') ++i;
    if(i >= k) cout << '1' << endl;
    else cout << s[i] << endl;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------
ll dist1[limit], dist4[limit];

struct edge {
    ll to;
    ll cost;
};

vector<edge> Ea[limit], Eb[limit];
ll n, m, s, t;

void dijkstra1() {
    priority_queue <pll, vector<pll>, greater<pll> > que;
    fill(dist1, dist1 + limit, LINF);
    dist1[s] = 0;
    que.push(MP(0LL, s));

    while (!que.empty()) {
        pll p = que.top();
        que.pop();
        ll v = p.second;
        if (dist1[v] < p.first) continue;

        rep(i, Ea[v].size()) {
            edge e = Ea[v][i];
            if (dist1[e.to] > dist1[v] + e.cost) {
                dist1[e.to] = dist1[v] + e.cost;
                que.push(MP(dist1[e.to], e.to));
            }
        }
    }
}

void dijkstra4() {
    priority_queue <pll, vector<pll>, greater<pll> > que;
    fill(dist4, dist4 + limit, LINF);
    dist4[t] = 0;
    que.push(MP(0LL, t));

    while (!que.empty()) {
        pll p = que.top();
        que.pop();
        ll v = p.second;
        if (dist4[v] < p.first) continue;

        rep(i, Eb[v].size()) {
            edge e = Eb[v][i];
            if (dist4[e.to] > dist4[v] + e.cost) {
                dist4[e.to] = dist4[v] + e.cost;
                que.push(MP(dist4[e.to], e.to));
            }
        }
    }
}

struct input {
    ll u, v, a, b;
};

int main() {
    cin >> n >> m >> s >> t;

    rep(i, m) {
        ll qu, qv, qa, qb;
        cin >> qu >> qv >> qa >> qb;
        Ea[qu].push_back({qv, qa});
        Ea[qv].push_back({qu, qa});
        Eb[qu].push_back({qv, qb});
        Eb[qv].push_back({qu, qb});
    }


    dijkstra1();
    dijkstra4();

    ll Min = LINF;

    vector<ll> ans;

    for (int i = n; i >= 1; --i) {
        Min = min(Min, dist1[i] + dist4[i]);
        ans.push_back((ll) 1e15 - Min);
    }

    reverse(ans.begin(), ans.end());
    for (auto answer : ans) cout << answer << endl;

    return 0;
}



Measured memory_bytes: 19964
N, M, X = gets.chomp.split(' ').map(&:to_i)
C = Array.new
N.times do |i|
  C[i] = gets.chomp.split(' ').map(&:to_i)
end
min = Float::INFINITY

N.times do |i|
  combinations = (0..N-1).to_a.combination(i+1).to_a
  combinations.each do |combination|
    sum = Array.new(M+1, 0)
    (M+1).times do |k|
      (i+1).times do |j|
      	sum[k] += C[combination[j]][k]
      end
    end
    if sum.slice(1..-1).all?{ |value| value >= X }
      min = [min, sum[0]].min
    end
  end
end

p (min.infinite? ? -1 : min)

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

int main(){

int x;
cin>>x;
int ans;
if(x>=400){
ans=8;
}if(x>=600){
ans=7;
}if(x>=800){
    ans=6;
}if(x>=1000){
    ans=5;
}if(x>=1200){
    ans=4;
}if(x>=1400){
    ans=3;
}if(x>=1600){
    ans=2;
}if(x>=1800){
    ans=1;
}
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
import java.util.*;


public class Main {
  static int N, L;
  static String[] S;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    N = sc.nextInt();
    L = sc.nextInt();

    S = new String[N];
    for(int i = 0; i < N; i++) {
      S[i] = sc.next();
    }

    Arrays.sort(S);

    for(int i = 0; i < N; i++) {
      System.out.print(S[i]);
    }
    System.out.println("");
  }
}


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

int main(){
  static const double pi = 3.141592653589793;
  int A,B,H,M;
  cin >> A >> B >> H >> M;

  long double x = pi * 2 * ((long double)H / 12.0 + ((long double)M / 60.0) / 12.0 - (long
double)M / 60.0);

  long double rsq = (long double)(A * A + B * B) - (long double)(2 * A * B) * (long double)cos(x);

  printf("%20.20Lf\n", sqrtl(rsq));
}

Measured memory_bytes: 4104
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL K,i,ans=0;
  LL S[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  scanf("%lld",&K);

  printf("%lld\n",S[K-1]);
	return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    XYZ=[tuple(map(int,input().split())) for _ in range(n)]
    ans=-INF

    from itertools import product
    for cx,cy,cz in product(range(2),repeat=3):
        XYZ.sort(lambda a:(2*cx-1)*a[0]+(2*cy-1)*a[1]+(2*cz-1)*a[2],reverse=1)
        score=0
        for i in range(m):
            a=XYZ[i]
            score+=(2*cx-1)*a[0]+(2*cy-1)*a[1]+(2*cz-1)*a[2]
        ans=max(ans,score)
    print(ans)
resolve()

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


int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    rep(i,1,1111){
        if(k*i>=a&&k*i<=b){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;

}
    









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

using namespace std;

typedef long long LL;

int gcd(int a, int b){
  if(a<b) swap(a,b);
  int r;
  while(r = a % b, r){
    a=b;
    b=r;
  }
  return b;
}

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

    vector<int> a(n);
    int mx = 0;
    int gc = -1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == k) {
            cout << "POSSIBLE" << endl;
            return 0;
        }

        mx = max(mx, a[i]);

        if (gc == -1) {
            gc = a[i];
        } else {
            gc = gcd(gc, a[i]);
        }
    }

    if (mx < k) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    if (k % gc == 0) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
s = gets.chomp
n = s.size

m = Array.new(n, 1)
1.upto(n-1) {|i| m[i] = m[i-1] * 10 % 2019}

h = Hash.new(0)
pre = 0
s.reverse.each_char.with_index do |c, i|
    pre = (pre + c.to_i * m[i]) % 2019
    h[pre] += 1 
end

puts h.inject(0) {|r,(_,v)| r + v * (v - 1) / 2} + h[0]

Measured memory_bytes: 16436