akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const ll INF = 21474836470000;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  ll a[n][n] = {};
  ll d[n][n] = {};

  REP(i, n) {
    REP(j, n) {
      cin >> a[i][j];
      d[i][j] = a[i][j];
    }
  }

  REP(k, n) {
    REP(i, n) {
      REP(j, n) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
    }
  }

  REP(i, n) {
    REP(j, n) {
      if (a[i][j] > d[i][j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  ll ans = 0;
  REP(i, n) {
    REP(j, n) {
      if (i >= j)
        continue;
      bool flag = true;
      REP(k, n) {
        if (i == k || j == k)
          continue;
        // 迂回路がある場合、辺を張る必要はない
        if (d[i][j] == d[i][k] + d[k][j]) {
          flag = false;
        }
      }
      if (flag) {
        ans += a[i][j];
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1664
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    vector<tuple<string, int, int>> vt;
    for (int i = 0; i < N; i++) {
        string tmp; cin >> tmp;
        int tmpi; cin >> tmpi;
        vt.push_back({tmp, 100-tmpi, i});
    }
    sort(vt.begin(), vt.end());

    for (int i = 0; i < vt.size(); i++) {
        cout << get<2>(vt[i]) + 1 << endl;
    }
}

Measured memory_bytes: 888
n = gets.chomp.to_i
a = [] * n
b = [] * n
c = [] * n
n.times do
  ai, bi, ci = gets.chomp.split.map(&:to_i)
  a << ai
  b << bi
  c << ci
end
dp = Array.new(n){Array.new(3){ 0 }}
max = [a[0], b[0], c[0]].max
3.times {|i| dp[0][i] = max }

(1...n).to_a.each do |i|
  v0 = dp[i - 1][0] > dp[i - 1][1] ? dp[i - 1][0] : dp[i - 1][1]
  v1 = dp[i - 1][1] > dp[i - 1][2] ? dp[i - 1][1] : dp[i - 1][2]
  v2 = dp[i - 1][2] > dp[i - 1][0] ? dp[i - 1][2] : dp[i - 1][0]

  dp[i][0] = v1 + a[i]
  dp[i][1] = v2 + b[i]
  dp[i][2] = v0 + c[i]
end

puts [dp[-1][0], dp[-1][1], dp[-1][2]].max

Measured memory_bytes: 10064
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    lint n, k;
    cin >> n >> k;
    lint ans = 0;
    rep(a, k){
        lint b = (k-(a%k))%k;
        lint c1 = (k-(a%k))%k, c2 = (k-(b%k))%k;
        lint MAX = max({a, b, c1});
        if(c1 == c2 && MAX <= n){
            ans += ((n+a)/k)*((n+b)/k)*((n+c1)/k);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*  ex4_1
    supercomputerjoi    */

#include <stdio.h>
#include <math.h>

int main(void){
    int treeNum, range;
    int ans = 0;    // answer

    // input N
    scanf("%d", &treeNum);

    // input D
    scanf("%d", &range);

    // calculate answer
    ans = ceil(treeNum / (range * 2.0 + 1));

    // print answer
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005
ll p[1<<19],q[1<<19];
int main()
{
	ios
	ll n,i,j;
	cin>>n;
	ll a[(1<<18)+1];
	for(i=0;i<(1<<n);i++){
		cin>>a[i];
		p[i]=a[i],q[i]=0;
	}
	for(i=0;i<n;i++){
		for(j=0;j<(1<<n);j++){
			if(j&(1<<i)){
				ll x[4];
				x[0]=p[j],x[1]=q[j],x[2]=p[j^(1<<i)],x[3]=q[j^(1<<i)];
				sort(x,x+4);
				p[j]=x[3],q[j]=x[2];
			}
		}
	}
	ll ans=0;
	for(i=1;i<(1<<n);i++){
		ans=max(ans,p[i]+q[i]);
		cout<<ans<<"\n";
	}
	return 0;
}

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

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

	vector<bool> wrong(n, true);
	vector<vector<string>> ans(n);
	int correct = 0, penalty = 0;
	for (int i = 0; i < m; i++) {
		int p;
		string s;
		cin >> p >> s;
		p--;
		ans.at(p).push_back(s);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < ans.at(i).size(); j++) {
			if (ans.at(i).at(j) == "AC") {
				wrong.at(i) = false;
				correct++;
				break;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (!wrong.at(i)) {
			for (int j = 0; j < ans.at(i).size(); j++) {
				if (ans.at(i).at(j) == "WA") {
					penalty++;
				}
				else break;
			}
		}
	}
	cout << correct << ' ' << penalty << endl;
}


Measured memory_bytes: 10496
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int m = sc.nextInt();
      int xc = sc.nextInt();
      int yc = sc.nextInt();

      int[] x = new int[n];
      for (int i = 0; i < x.length; i++) {
         x[i] = sc.nextInt();
      }

      int[] y = new int[m];
      for (int i = 0; i < y.length; i++) {
         y[i] = sc.nextInt();
      }

      Arrays.sort(x);
      Arrays.sort(y);

      if (x[x.length - 1] >= y[0]) {
         System.out.println("War");
      }
      else {
         if (x[x.length - 1] < yc && y[0] > xc) {
            System.out.println("No War");
            }
         else {
            System.out.println("War");
         }
      }

   }
}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
using namespace std;
int main(){
    string command,q,str,str1,p;
    int n,a,b,c,d;
    cin>>str>>n;
    for(int i=0;i<n;i++){
        cin>>command>>a>>b;
        if(command=="print"){
            q=str.substr(a,b-a+1);
            cout<<q<<endl;
        }
        if(command=="reverse"){
            str1=str.substr(a,b-a+1);
            c=str1.size();
            for(int i=0;i<c;i++){
                str[i+a]=str1[c-i-1];
            }
        }
        if(command=="replace"){
            cin>>p;
            str=str.replace(a,b-a+1,p);
            
        }
    }
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  	double A, B, H, M, deg1, deg2, degdiff, pi=3.1415926535, C;
  	cin >> A >> B >> H >> M;
  	deg1=(2*pi)*(H/12+M/720);
  	deg2=(2*pi)*(M/60);
  	/*cout << pi << endl;
  	cout << deg1 << endl;
  	cout << deg2 << endl;*/
  	if(deg1>=deg2){
    	degdiff=deg1-deg2;
    }else{
    	degdiff=deg2-deg1;
    }
  
  	if(degdiff>=pi/2){
    	degdiff = 2*pi - degdiff;
    }

  	//cout << degdiff << endl;
  	C=A*A+B*B-2*A*B*cos(degdiff);
  	C=sqrt(C);
  	cout << fixed << setprecision(10) << C << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>

int main(){
	int a,b,c,d,e,ave;
	scanf("%d \n %d \n %d \n %d \n %d",&a,&b,&c,&d,&e);
	if(a < 40){
		a = 40;
	}
	if(b < 40){
		b = 40;
	}
	if(c < 40){
		c = 40;
	}
	if(d < 40){
		d = 40;
	}
	if(e < 40){
		e = 40;
	}
        ave = (a+b+c+d+e)/5;
	printf("%d\n",ave);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
const long mod=1e9+7;
int main(){
	int a,b,c;cin>>a>>b>>c;
	cout<<max(c-a+b,0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll MOD = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

int main(){
    fastio;
    int n;
    cin>>n;
    string str;
    cin>>str;
    vector<int> pree(n+1,0),prew(n+2,0);
    for(int i=1;i<=n;i++){
        if(str[i-1]=='W'){
            pree[i] = pree[i-1] + 1;
        }
        else{
            pree[i] = pree[i-1];
        }
    }
    for(int i=n;i>0;i--){
        if(str[i-1]=='E'){
            prew[i] = prew[i+1] + 1;
        }
        else{
            prew[i] = prew[i+1];
        }
    }
    
    int ans = INT_MAX;
    for(int i=1;i<=n;i++){
        if(i==1){
            ans = min(ans,prew[i+1]);
        }
        else if(i==n){
            ans = ans = min(ans,pree[i-1]);
        }
        else{
            ans = min(ans,prew[i+1]+pree[i-1]);
        }
        
    }
    cout<<ans<<"\n";
    
}




Measured memory_bytes: 2964
from collections import deque
deq = deque()
def check(f1, f2, f3):
    return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0])
def f(f1, x):
    return f1[0]*x + f1[1]
def add_line(a, b):
    f1 = (a, b)
    while len(deq) >= 2 and check(deq[-2], deq[-1], f1):
        deq.pop()
    deq.append(f1)
def query(x):
    while len(deq) >= 2 and f(deq[0], x) >= f(deq[1], x):
        deq.popleft()
    return f(deq[0], x)

N, C = map(int, input().split())
*H, = map(int, input().split())

add_line(-2*H[0], H[0]**2)
for i in range(1, N):
    y = H[i]**2 + C + query(H[i])
    add_line(-2*H[i], y + H[i]**2)
print(y)

Measured memory_bytes: 87332
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	ll h, n;
	cin >> h >> n;
	
	ll s = 0;
	for(int i = 0; i < n; i++){
		ll x;
		cin >> x;
		s += x;
	}
	
	if(s >= h)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

#define CO const
#define IN inline
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

CO int P=1e9+7,i2=(P+1)/2;
IN int add(int a,int b){
	return (a+=b)>=P?a-P:a;
}
IN int mul(int a,int b){
	return (int64)a*b%P;
}
IN int fpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1) ans=mul(ans,a);
	return ans;
}

CO int N=3e3+10;
int A[N],F[N][N];

int main(){
	int n=read<int>(),m=read<int>();
	for(int i=1;i<=n;++i) read(A[i]);
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)
		F[i][j]=A[i]>A[j];
	for(int i=1;i<=m;++i){
		int x=read<int>(),y=read<int>();
		F[x][y]=F[y][x]=mul(add(F[x][y],F[y][x]),i2);
		for(int j=1;j<=n;++j)if(j!=x and j!=y){
			F[x][j]=F[y][j]=mul(add(F[x][j],F[y][j]),i2);
			F[j][x]=F[j][y]=mul(add(F[j][x],F[j][y]),i2);
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i)for(int j=i+1;j<=n;++j)
		ans=add(ans,F[i][j]);
	ans=mul(ans,fpow(2,m));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define base1 131
#define base2 13131
char str[12];
unsigned long long num[30];
map<unsigned long long ,ll>mp1,mp2;
int main()
{
    unsigned long long xx1,xx2;
    int n;cin>>n;
    ll answer=0;
    for(int i=1;i<=n;i++){
        xx1=0,xx2=0;
        memset(num,0,sizeof num);
        scanf("%s",str+1);
        for(int j=1;j<=10;j++)num[str[j]-'a']++;
        for(int j=0;j<=25;j++)xx1=xx1*base1+num[j],xx2=xx2*base2+num[j];
      //  cout<<xx<<endl;
        if(mp1[xx1]&&mp2[xx2]&&mp1[xx1]==mp2[xx2])answer+=mp1[xx1];
        mp1[xx1]+=1ll,mp2[xx2]+=1ll;
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 12800
#include <stdio.h>
#include <math.h>

int main(void)
{
  int n,num[10000],i,j,ans=0,jud=0;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &num[i]);
    if(num[i]==2||num[i]==3||num[i]==5){
      ans++; continue;
    }
    if(num[i]%2==0) continue;
    for(j=3;j<sqrt(num[i])+1;j+=2){
      if(num[i]%j==0){
	jud=0; break;
      } else {
	jud=1;
      }
    }
    if(jud==1) ans++;
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,ans;
  ans=1;
  cin>>n;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  for(int i=0;i<n;i++){
    if(a.at(i)==0){
      ans=0;
    }
  }
  for(int i=0;i<n;i++){
    if(ans!=0 && ans!=-1){
      if(1000000000000000000/ans>=a.at(i)){
        ans=ans*a.at(i);
      }else{
        ans=-1;
      }
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3988
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        a: isize,
        op: char,
        b: isize,
    }


    if op == '+' { 
        println!("{}", a + b);
    } else {
        println!("{}", a - b)
    }
}


Measured memory_bytes: 2132
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # a % kの値で全探索
    n,k = readInts()
    NUM = [0] * k
    for i in range(1,n+1):
        NUM[i%k] += 1
    # NUM[x] = k で割って、x余る数が1以上N以下に何個あるか
    res = 0
    for a in range(k):
        # a % k を決め打つと、 b % K , c % K を取るべき値が一意に決まる
        # a + b, a + c が k の倍数であることから
        # そうして決まったb,cについて、 b + c が K の倍数になっているかどうかをcheck
        
        b = (k-a) % k
        c = (k-a) % k
        if (b+c) %k != 0:
            continue
        res += NUM[a]*NUM[b]*NUM[c]
    print(res)





if __name__ == '__main__':
  main()


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

using namespace std;

int main(){
  long long int a, b , c[100010], x[100010];
  
  cin >> a >> b;
  
  for(int i=1;i<=a;i++)
    cin >> c[i];
  
  x[0] = 1e15;
  
  for(int i=1;i<=a;i++){
    x[i] = min(c[i] , x[i-1]);
  }
    int p = -1e9;
    int ans = 0;
  
  for(int i=1;i<=a;i++){
    
    if(c[i]-x[i] > p){
      p = c[i] - x[i];
      ans = 1;
    }
    
    else if(c[i] - x[i] == p){
      ans ++;
    }
    
  }
  
  cout << ans << endl;
  
}
      
      


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

using namespace std;

int main()
{
    string word;
    cin >> word;
    if(word.find_last_of("s")+1 == word.length())
    {
        word.insert(word.length(), "es");
    }
    else word.insert(word.length(), "s");
    cout << word;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	bool flg = true;
	for(ll i=0;i<s.length();i++)
	{
		if (s[i]!=t[i])
			flg = false;
	}

	if (flg)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

Measured memory_bytes: 3616
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] array = new int [n];
		
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		
		int lastDistance = k - array[n - 1] + array[0];
		int longest = lastDistance;
		for(int i = 0; i < n - 1; i++) {
			int distance = array[i + 1] - array[i];
			if(longest < distance) {
				longest = distance;
			}
		}
		
		System.out.println(k - longest);
		sc.close();
		
	}
	
}

Measured memory_bytes: 85460
#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);
	
	int a, ans;
	
	cin >> a;
	ans = (a + 1) * a / 2;
	cout << ans << "\n";

	return 0;
}


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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){
    return (a/gcd(a,b)*b);
}

int main() {
    ll ans = 0;
    int N;
    cin >> N;
    vl A(N), B(N), C(N), ans_b(N, 0);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    
    rep(i, N){
        int value = B[i];   
        auto itr = upper_bound(C.begin(), C.end(), value);

        if(value >= C[N-1]) break;
        ans_b[i] = (C.end() - itr);
    }
    rep(i,N-1) ans_b[N-2-i] += ans_b[N-1-i];

    rep(i, N){
        int value = A[i];   
        auto itr = upper_bound(B.begin(), B.end(), value);

        if(value >= B[N-1]) break;
        ans += ans_b[itr - B.begin()];
    }

    cout << ans;
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3328
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n, m, a, b, depth = 1;
    cin >> n >> m;
    vector<vector<int>>road(n);
    vector<pi>info(n, make_pair(-1, -1));
    info[0] = make_pair(0, 0);
    queue<int>q;
    rep(i, m) {
        cin >> a >> b;
        a--, b--;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    q.push(0);
    while (!q.empty()) {
        int parent = q.front(); q.pop();
        for (int s : road[parent]) {
            if (info[s].first != -1)continue;
            q.push(s);
            info[s] = make_pair(parent + 1, depth + 1);
        }
        depth++;
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++)cout << info[i].first << endl;
}


Measured memory_bytes: 10600
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N, W = sc.nextInt()
  val items = (for (i <- 1 to N) yield (sc.nextInt, sc.nextInt)).toList
  type Item = (Int,Int)

  class DP(wgt:Int, items:List[Item]) {
    val memo = Array.fill(wgt+1)(0)
    def solver():Int = {
      for ((v, w) <- items) {
        for (i <- w to wgt) {
          val v0 = memo(i-w) + v
          if (v0 > memo(i)) memo(i) = v0  
        }
      }
      memo(wgt)
    }
  }
  
  val dp = new DP(W, items)

  println(dp.solver())
}


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

int main() {
  string s,t;
  cin >> s >> t;
  ll a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if(u==s) {
    a--;
  }
  else {
    b--;
  }
  cout << a << " " << b << endl;;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;

long long N, K, ANS = 1, MOD = 1000000007;
static vector<int> V[100000];
bool visited[100000] = {};

void DFS(int X) {
	visited[X] = true;
	for (int i = 0; i < V[X].size() - 1; i++) {
		ANS *= (K - 2 - i);
		ANS = ANS % MOD;
	}
	for (int Y : V[X]) {
		if (!visited[Y]) DFS(Y);
	}
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N - 1; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back(B);
		V[B].push_back(A);
	}
	for (int i = 0; i <= V[0].size(); i++) {
		ANS *= (K - i);
		ANS = ANS % MOD;
	}
	visited[0] = true;
	for (int i : V[0]) {
		DFS(i);
	}
	cout << ANS << endl;
}

Measured memory_bytes: 8192
N, M = gets.split.map(&:to_i)
s, c = [], []
flag = false
hash = {}

M.times do |i|
  s[i], c[i] = gets.split.map(&:to_i)
  if hash[s[i]].nil?
    hash[s[i]] = c[i]
  # 同じ桁数に異なる2つの数が要求された場合，-1出力
  elsif hash[s[i]] != c[i]
    flag = true
  end
end

# puts "#{hash}"

# 左から1桁目が0かつ桁数が2以上の時，-1出力
if hash[1] == 0 and N >= 2
  flag = true
end

if flag
  puts -1
  exit
end

# ansは最初は先頭に'1'と，その後にN-1個の'0'で埋めておく
ans = []
ans = ans.fill('0',0..N-1)
if N >= 2
  ans[0] = '1'
end

hash.each do |key, val|
    ans[key-1] = val.to_s
end 

puts "#{ans.inject(:+)}"

Measured memory_bytes: 14292
#include <bits/stdc++.h>
using namespace std;
#define BMAX 50005
#define INFI 2100000000
struct card{
    int value;
    char suit;
};

card L[BMAX], R[BMAX];
void swap(card *a, card *b){
    card tem = *b;
    *b = *a;
    *a = tem;
}

int Partition(card S[], int left, int right){
    int i=left-1,j=left;
    for(j;j<right;++j){
        if(S[j].value<=S[right].value){
            i++;
            swap(&S[i],&S[j]);
        }
    }
    swap(&S[i+1],&S[right]);
    return (i+1);
}

void quickSort(card S[], int left, int right){
    if(left<right){
        int pos = Partition(S,left,right);
        quickSort(S,left,pos-1);
        quickSort(S,pos+1,right);
    }
}

void Merge(card M[], int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    for(int i=0;i<n1;i++){
        L[i] = M[left+i];
    }
    for(int i=0;i<n2;i++){
        R[i] = M[mid+i];
    }
    L[n1].value = INFI;
    R[n2].value = INFI;
    int i=0,j=0;
    for(int k=0;k<n1+n2;++k){
        if(L[i].value<=R[j].value){
            M[left+k].value = L[i].value;
            M[left+k].suit = L[i].suit;
            i++;
        }
        else{
            M[left+k].value = R[j].value;
            M[left+k].suit = R[j].suit;
            j++;
        }
    }
}

void MergeSort(card M[], int left, int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        MergeSort(M,left,mid);
        MergeSort(M,mid,right);
        Merge(M,left,mid,right);
    }
}



int main(){
    int n;
    scanf("%d",&n);
    card S[100001],M[100001];
    int value;
    char suit[10];
    for(int i=0;i<n;++i){
        scanf("%s %d",suit,&value);
        M[i].suit = S[i].suit = suit[0];
        M[i].value = S[i].value = value;
    }
    quickSort(S,0,n-1);
    MergeSort(M,0,n);
    int stable = 1;
    for(int i=0;i<n;++i){
        if(S[i].suit != M[i].suit || S[i].value != M[i].value) stable = 0;
    }
    if(stable) printf("Stable\n");
    else printf("Not stable\n");
    for(int i=0;i<n;++i){
        printf("%c %d\n",S[i].suit,S[i].value);
    }
    return 0;
}




Measured memory_bytes: 5480
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <numeric>
#include <math.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    vector<int> A(26,0);

    for(int i=0;i<4;i++){
        A[s[i]-'A']++;
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    if(A[0]==A[1]&&A[0]==2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

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

int main() {
  ll N, sum = 0;
  cin >> N;
  vector<ll> vec(N);
  rep(i, N){
  	cin >> vec.at(i);
  }
  if(N == 1){
  	cout << 0 << endl;
  }else{
    rep(i, N - 1){
     if(vec.at(i) >= vec.at(i + 1)){
      sum += vec.at(i) - vec.at(i + 1);
      vec.at(i + 1) = vec.at(i);
     }
    }
    cout << sum << endl;
  }
   return 0;
}

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

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  bool g[h+2][w+2];

  for (int j = 0; j < w+2; j++) {
    for(int i = 0; i < h+2; i++ ) {
      g[i][j] = true;
    }
  }

  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s.at(j) == '.') {
        g[i + 1][j + 1] = false;
      } else {
        g[i + 1][j + 1] = true;
      }
    }
  }

  int left[h+2][w+2];
  int right[h+2][w+2];
  int up[h+2][w+2];
  int down[h+2][w+2];
  for (int j = 0; j < w+2; j++) {
    for(int i = 0; i < h+2; i++ ) {
      left[i][j] = 0;
      right[i][j] = 0;
      up[i][j] = 0;
      down[i][j] = 0;
    }
  }

  // left
  for (int i = 1; i < h+2; i++) {
    for (int j = 1; j < w+2; j++) {
      if (!g[i][w-j+1]) {
        left[i][w-j+1] = left[i][w-j+2] + 1;
      }
    }
  }

  // right
  for (int i = 1; i < h+2; i++) {
    for (int j = 1; j < w+2; j++) {
      if (!g[i][j]) {
        right[i][j] = right[i][j-1] + 1;
      }
    }
  }

  // up
  for (int i = 1; i < h+2; i++) {
    for (int j = 1; j < w+2; j++) {
      if (!g[h-i+1][j]) {
        up[h-i+1][j] = up[h-i+2][j] + 1;
      }
    }
  }

  // down
  for (int i = 1; i < h+2; i++) {
    for (int j = 1; j < w+2; j++) {
      if (!g[i][j]) {
        down[i][j] = down[i-1][j] + 1;
      }
    }
  }

  int ans = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!g[i+1][j+1]) {
        //cout << i+1 << "_" << j+1 << " " << right[i+1][j+1] << " " << left[i+1][j+1] << " " << up[i+1][j+1] << " " <<  down[i+1][j+1] << "\n";
        int light = right[i+1][j+1] + left[i+1][j+1] + up[i+1][j+1] + down[i+1][j+1] - 3;
        if (light > ans) {
          //cout << i + 1 << " " << j + 1 << "\n";
          ans = light;
        }
      }
    }
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 66944
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

ll n;
VecS s;
VecC ans;

void dfs(ll a, ll b, ll c, ll t){
	if(a < 0 || b < 0 || c < 0) return;
	if(t == n){
		puts("Yes");
		rep(i, n) co(ans[i]);
		exit(0);
	}

	if(s[t] == "AB"){
		ans[t] = 'A';
		dfs(a + 1, b - 1, c, t + 1);
		ans[t] = 'B';
		dfs(a - 1, b + 1, c, t + 1);
	}else if(s[t] == "AC"){
		ans[t] = 'A';
		dfs(a + 1, b, c - 1, t + 1);
		ans[t] = 'C';
		dfs(a - 1, b, c + 1, t + 1);
	}else{
		ans[t] = 'B';
		dfs(a, b + 1, c - 1, t + 1);
		ans[t] = 'C';
		dfs(a, b - 1, c + 1, t + 1);
	}
}

int main(void){
	ll a, b, c;
	cin >> n >> a >> b >> c;
	s.resize(n);
	ans.resize(n);
	rep(i, n) cin >> s[i];

	dfs(a, b, c, 0);

	puts("No");
	return 0;
}


Measured memory_bytes: 14320
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int Binary_search(int n, vector<int>&d, int l, int r) {
	if (l == r) {
		if (n > d[l])
			return l + 1;
		else
			return l;
	}
	int p = (r + l) >> 1;
	if (n <= d[p])
		return Binary_search(n, d, l, p);
	else
		return Binary_search(n, d, p + 1, r);
}

int main(void) {
	int num, i, j;
	ll ans = 0;
	cin >> num;
	vector<int> d(num);
	for (i = 0; i < num; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	for (i = 0; i < num; i++) {
		for (j = i + 1; j < num; j++) {
			ans += Binary_search(d[i] + d[j], d, 0, num - 1) - j - 1;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
/*input
codefestival
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
set<int> st;
int main()
{
	IOS;
	REP(i,3){
      int tmp;
		cin>>tmp;
		st.insert(tmp);
	}
	cout<<SZ(st);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Feb 16 21:00:33 JST 2020
 **/

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

signed main() {
    Int n;
    cin >> n;
    map<string, Int> mp;
    REP(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    Int ma = -1;
    for (auto& p : mp) {
        chmax(ma, p.second);
    }
    for (auto& p : mp) {
        if (p.second == ma) {
            cout << p.first << endl;
        }
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

#define ll long long

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b) {
  // Eucledean algorithm
  while (a) {
    if (a < b) {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

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

  ll n;
  cin >> n;

  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll ans = a[0];

  REP(i, n) {
    ans = gcd(ans, a[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
n = gets.to_i
a = gets.chomp.split.map(&:to_i)

dp = Array.new(n)
dp[0] = 1000

1.upto(n-1) do |i|
  m = 0
  0.upto(i-1) do |j|
    t = dp[j] / a[j]
    k = dp[j] - a[j] * t
    k += a[i] * t
    m = [m, k].max
  end
  dp[i] = [dp[i-1], m].max
end

puts dp[n-1]


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



int main(){
	
	int n,x,d=0,ans=0;
	cin>>n>>x;

	vector<int>l(n);
	for(int i=0;i<n; i++)cin>>l[i];


	for(int i=1;i<n+1; i++){
		d+=l[i-1];
			if(d>x){
				ans=i;
				break;
			}
			ans=i;
	}
	if(d>x){
			cout<<ans;
	}else cout<<ans+1;
}


Measured memory_bytes: 256
n, m, c = map(int, input().split())
listb = list(map(int, input().split()))
lista = [list(map(int, input().split())) for i in range(n)]

def dot(a, b, c):
  res = c
  for i in range(len(a)):
    res += a[i]*b[i]
  return res

counter = 0
for i in range(n):
  if dot(lista[i], listb, c) > 0:
    counter += 1
print(counter)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for(int i=0; i<N; i++){
		cin >> d[i];
	}
	sort(d.begin(),d.end());
	int K;
	K=d[N/2]-d[N/2-1];
	cout << K <<endl;
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int ans = 1;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    map<string, int> M;
    string temp = "", last = {S[0]};
    for (int i = 1; i < (int)S.size(); i++) {
        temp += S[i];
        if (temp != last) {
            ans++;
            last = temp;
            temp = "";
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int mn = max(-1000000,b-a+1);
  int mx = min(1000000,b+a-1);
  cout << mn;
  for(int i = mn+1;i<mx+1;i++) cout << " " << i ;
}

Measured memory_bytes: 3632
a, b = map(int, input().split())
ans = 20000000
n = a//2019
m = b//2019
a = a % 2019
b = b % 2019

if a > b:
    ans = 0
else:
    for i in range(a, b):
        for j in range(a+1, b+1):
            ans = min(ans, i*j%2019)
if m != n:
    ans = 0

if a == b:
    ans = 0

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
//#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const long long linf = 4523372036854775807;
const int inf = 1500000000;
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	int from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
int fact(int i) {
	ll sum = 1;
	for (int j = 2; j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
 //---------------------------------------------------
 //+++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[100000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int ans = 0;
	for (int i = 0; i < n; ) {
		int j = i;
		while (j < n&&a[i] == a[j])
			j++;
		if (a[i] < j - i)
			ans += (j - i) - a[i];
		if (a[i] > j - i)
			ans += (j - i);
		i = j;
	}
	cout << ans << endl;
	getchar(); getchar();
}

Measured memory_bytes: 640
n,m=list(map(int,input().split()))
l_lm=1
r_lm=n
for i in range(m):
    l,r=list(map(int,input().split()))
    
    if l>l_lm:
        l_lm=l
    if r<r_lm:
        r_lm=r
if r_lm<l_lm:
    print(0)
else:
    print(r_lm-l_lm+1)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var s=Console.ReadLine().Split(' ');
			if(s[0]=="0" &&s[1]=="0")break; 
			Sol mySol=new Sol(int.Parse(s[0]),int.Parse(s[1]));
			Console.WriteLine(mySol.Ans);
		}
	}
}


class Sol{
	int ans;
	public int Ans{
		get{return ans;}
	}
	
	public Sol(int n,int m){
		int[] Data=new int[n+m+1];
		int[] Data2=new int[n+m];
		if(n>0){
			var s=Console.ReadLine().Split(' ');
			for(int i=0;i<n;i++)Data[i]=int.Parse(s[i]);
		}
		if(m>0){
			var s=Console.ReadLine().Split(' ');
			for(int i=0;i<m;i++)Data[i+n]=int.Parse(s[i]);
		}
		Data[n+m]=0;
		
		Array.Sort(Data,(a,b)=>a>b?1:(a<b?-1:0) );
		for(int i=0;i<n+m;i++)Data2[i]=Data[i+1]-Data[i];
		Array.Sort(Data2,(a,b)=>a>b?1:(a<b?-1:0) );
		ans=Data2[n+m-1];
	}
}

Measured memory_bytes: 7172
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);

    void run() {
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        char[] a = Arrays.copyOf(s, s.length);
        System.out.println(check(s, t, a) || check(t, s, a) ? "Yes" : "No");
    }

    boolean check(char[] s, char[] t, char[] a) {
        boolean f = true;
        int index = 0;
        for (int i = 0, j = 0; i < s.length || j < t.length;) {
            if (f) {
                while (i < s.length) {
                    if (s[i++] == a[index]) {
                        index++;
                        f = !f;
                        break;
                    }
                }
                if (f) break;
            } else {
                while (j < t.length) {
                    if (t[j++] == a[index]) {
                        index++;
                        f = !f;
                        break;
                    }
                }
                if (!f) break;
            }
            if (index == a.length) return true;
        }
        return false;
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 26208
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007
int n,k;
int dp[100005];
int a[100005];
int dfs(int i)
{
	if(dp[i]!=-1)
		return dp[i];
	if(i==n-1)
		return dp[i]=0;
	if(i>=n)
		return dp[i]=mod;
	int ret=mod;
	f(j,1,k+1)
		ret=min(dfs(i+j)+abs(a[i+j]-a[i]),ret);
	return dp[i]=ret;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	f(i,0,100005)
		dp[i]=-1;
	cin>>n>>k;
	f(i,0,n)
		cin>>a[i];
	cout<<dfs(0)<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

void bsort(int *a,int n,int *bucket,int sup){
  int i;
  for(i=0;i<n;i++) bucket[a[i]]++;
  int j=0;
  for(i=0;i<sup;i++){
    while(bucket[i]>0){
      a[j++]=i;
      bucket[i]--;
    }
  }
  return;
}

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

//a+b>=v 
int64 calc(int *a,int *b,int n,int v){
  int i=0;
  int j=n-1;
  while(i<n && a[i]+b[j]<v) i++;
  int64 cnt=0;
  for(;i<n;i++){
    while(j>=0 && a[i]+b[j]>=v) j--;
    cnt+=n-1-j;
  }
  return cnt;
}

void run(void){
  const int c=17;
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*n);
  int *b=(int *)malloc(sizeof(int)*n);
  int *bucket=(int *)calloc(1<<c,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  for(i=0;i<n;i++) scanf("%d",b+i);
  int ans=0;
  int bit;
  for(bit=29;bit>=0;bit--){
    for(i=0;i<n;i++) a[i]=a[i]&((1<<(bit+1))-1);
    for(i=0;i<n;i++) b[i]=b[i]&((1<<(bit+1))-1);
    if(bit+1<=c){
      bsort(a,n,bucket,1<<(bit+1));
      bsort(b,n,bucket,1<<(bit+1));
    } else {
      qsort(a,n,sizeof(int),cmp);
      qsort(b,n,sizeof(int),cmp);
    }
    int64 cnt=(calc(a,b,n,1<<bit)-calc(a,b,n,2*(1<<bit))+calc(a,b,n,3*(1<<bit)));
    if(cnt%2) ans+=1<<bit;
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


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


int main(){
  int N;
  cin >> N;
  long long int ans = 0;
  for(int ii=1; ii<=N; ii++){
    if(ii%3==0) continue;
    if(ii%5==0) continue;
    ans += ii;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int H[] = new int[N];
        int sum[] = new int[N];
        int sum2[] = new int[N];
        int sumsum = 0;
        for(int i=0;i<N;i++)
        {
            H[i] = sc.nextInt();
            sum[i] = 0;
            sum2[i] = 0;
        }
        int A[] = new int[M];
        int B[] = new int[M];
        for(int i=0;i<M;i++)
        {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
            sum[A[i]-1]++;
            sum[B[i]-1]++;
        }
        for(int i=0;i<M;i++)
        {
            if(H[A[i]-1]>H[B[i]-1])
            {
                sum2[A[i]-1]++;
            }
            else if(H[A[i]-1]<H[B[i]-1])
            {
                sum2[B[i]-1]++;
            }
        }
        for(int i=0;i<N;i++)
        {
            if(sum2[i]==sum[i])
            {
                sumsum++;
            }
        }
        System.out.println(sumsum);
    }
}

Measured memory_bytes: 62028
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a,b,h,m] <- map fromIntegral <$> getIntList
    let ji = (h*60 + m) / 2
        hun = 6 * m
        kaku = if 180 < abs (ji - hun) then 360 - abs (ji - hun) else abs (ji - hun)
        c | kaku == 0 = abs (a - b)
          | kaku == 180 = a + b
          | otherwise = sqrt $ a^2 + b^2 - 2*a*b* (cos (pi * kaku / 180)) 
    print c

Measured memory_bytes: 4236
#include <iostream>

using namespace std;

int main()
{
    long long int N,sum=0;
    cin>>N;
    long long int num[N+1];
if(N>=1&&N<=1000000){
    for(int i=1;i<=N;i++){
    num[i]=i;
    if(i%3>=1&&i%5>=1){
        sum+=i;
    }
    }
    cout<<sum;
}
    return 0;
}

Measured memory_bytes: 11364
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long N, std::vector<string> S){
  vector<vector<ll>> rinsetsu(N);
  For(i,N)For(j,N){
    if(S[i][j]=='1'){
      rinsetsu[i].push_back(j);
    }
  }
  vector<ll> color(N,-1);
  deque<ll> q;
  q.push_back(0);
  color[0]=0;
  while(!q.empty()){
    auto tmp=q.back();q.pop_back();
    for (auto &&i : rinsetsu[tmp])
    {
      if(color[i]==-1){
        color[i]=color[tmp]^1;
        q.push_front(i);
      }else if(color[i]==color[tmp]){
        cout<<-1<<endl;
        return;
      }
    }
  }
  vector<vector<ll>> d(N,vector<ll>(N,N+1));
  For(i,N)For(j,N)if(S[i][j]=='1')d[i][j]=1;
  REP(N)d[i][i]=0;
  For(k,N)For(i,N)For(j,N)if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];
  ll max_depth=0;
  REP(N){
    max_depth=max(max_depth,*max_element(d[i].begin(),d[i].end()));
  }
  cout<<max_depth+1<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<string> S(N);
    for(int i = 0 ; i < N ; i++){
      cin>>S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 896