akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String[] s = in.nextStringArray(3);

            int ans = 0;
            for (int i = 0; i < n; i++) {
                char c0 = s[0].charAt(i);
                char c1 = s[1].charAt(i);
                char c2 = s[2].charAt(i);
                if (c0 == c1 && c0 == c2) {

                } else if (c0 == c1 || c1 == c2 || c2 == c0) {
                    ans++;
                } else {
                    ans += 2;
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextString();
            }
            return res;
        }

    }
}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
int t[100001],v[100001];
char a[100001];
int main()
{
	int n,m,k=0,l,r,ans,i;
	scanf("%d%d",&n,&m);
	scanf("%s",a);
	for(i=0;i<n;i++)
	{
		if(a[i]=='A'&&a[i+1]=='C')
			v[i+1]=1;
	}
	for(i=1;i<=n;i++)
		t[i]=t[i-1]+v[i];
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&l,&r);
		ans=t[r]-t[l-1]-(v[r]?1:0);
		printf("%d\n",ans);
	}
	return 0;
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
vector<int> A(3);
int count =3;
rep(i,3){
	cin>>A[i];
  }
  rep(i,3){
	rep(j,3){
	if(i!=j&&j>i){
		if(A[i]==A[j]){
			count--;
			break;
		  }
	  }
	  }
}	
cout<<count<<endl;

}
	 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double dp[305][305][305];
int n,a[4];
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		a[x]++;
	}
	for(int k=0;k<=n;k++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int i=0;i<=n;i++)
			{
				if(i==0 && j==0 && k==0) 
					continue;
				if(i!=0) dp[i][j][k]+=dp[i-1][j][k]*i/(i+j+k);
				if(j!=0) dp[i][j][k]+=dp[i+1][j-1][k]*j/(i+j+k);
				if(k!=0) dp[i][j][k]+=dp[i][j+1][k-1]*k/(i+j+k);
				dp[i][j][k]+=n/(double)(i+j+k);
			}
		}
	}
	printf("%.10lf\n",dp[a[1]][a[2]][a[3]]);
	return 0;
} 

Measured memory_bytes: 219392
import scala.io.StdIn.readLine
 
object Main {
  def search(a:Array[Int],value:Int) = {
    def scan(l:Int,r:Int):Boolean = {
      val mid = (l+r)/2
      if(a(mid) == value) true
      else if(l>=r) false
      else if(a(mid)<value) scan(mid+1,r)
      else scan(l,mid-1)
    }
    scan(0,a.length-1)
  }
 
  def main(args:Array[String]) = {
    readLine
    val s = readLine.split(" ").map(_.toInt).toArray
    readLine
    val t = readLine.split(" ").map(_.toInt).toArray
    println(t.count(i=> search(s,i) ))
  }
}

Measured memory_bytes: 71028
H,W,N = map(int,input().split())
sr,sc = map(int,input().split())
S = input()
T = input()
hr = sc
hl = sc
hu = sr
hd = sr
State = "YES"
for i in range(N):
    if S[i] == "R":
        hr += 1
        if hr > W:
            State = "NO"
            break
    elif S[i] == "L":
        hl -= 1
        if hl < 1:
            State = "NO"
            break
    elif S[i] == "U":
        hu -= 1
        if hu < 1:
            State = "NO"
            break
    else:
        hd += 1
        if hd > H:
            State = "NO"
            break
    if T[i] == "R":
        if hl < W:
            hl += 1
    if T[i] == "L":
        if hr > 1:
            hr -= 1
    if T[i] == "U":
        if hd > 1:
            hd -= 1
    if T[i] == "D":
        if hu < H:
            hu += 1
print(State)

Measured memory_bytes: 3784
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static int decode(char[] input){
		int in = 0;
		
		for(int j = 0; j < input.length; j++){
			if(input[j] >= '0' && input[j] <= '9'){
				int tmp = input[j] - '0';
				
				if(input[j+1] == 'i'){
					
				}else if(input[j+1] == 'x'){
					tmp *= 10;
				}else if(input[j+1] == 'c'){
					tmp *= 100;
				}else if(input[j+1] == 'm'){
					tmp *= 1000;
				}
				
				in += tmp;
				j++;
			}else{
				if(input[j] == 'i'){
					in += 1;
				}else if(input[j] == 'x'){
					in += 10;
				}else if(input[j] == 'c'){
					in += 100;
				}else if(input[j] == 'm'){
					in += 1000;
				}
			}
		}
		
		return in;
	}
	
	public static String code(int out){
		StringBuilder sb = new StringBuilder();
		
		while(out != 0){
			if((out / 1000) != 0){
				sb.append(((out / 1000) > 1 ? (out / 1000) : "") + "m");
				out = out % 1000;
			}else if((out / 100) != 0){
				sb.append(((out / 100) > 1 ? (out / 100) : "") + "c");
				out = out % 100;
			}else if((out / 10) != 0){
				sb.append(((out / 10) > 1 ? (out / 10) : "") + "x");
				out = out % 10;
			}else if(out != 0){
				sb.append((out > 1 ? out : "") + "i");
				out = 0;
			}
		}
		
		return sb.toString();
	}

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

		final int n = sc.nextInt();
		
		for(int i = 0; i < n; i++){
			System.out.println(code(decode(sc.next().toCharArray()) + decode(sc.next().toCharArray())));
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define int long long 
using namespace std;
using Graph = vector<vector<int>>;

signed main() {
  int N, Q;
  cin >> N >> Q;
  Graph G(N);
  
  int A, B;
  for( int i = 0; i < N-1; i++ ){
    cin >> A >> B;
    A--;
    B--;
    G.at(A).push_back(B);
    G.at(B).push_back(A);
  }
  
  vector<int> cnt(N);
  int P, X;
  for( int i = 0; i < Q; i++ ){
    cin >> P >> X;
    cnt.at(P-1) += X;
  }
    
    
  
  vector<int> dist(N, -1);
  queue<int> que;
  
  dist.at(0) = 0;
  que.push(0);
  
  while( !que.empty() ){
    int v = que.front();
    que.pop();
    
    for( int nv : G.at(v) ){
      if( dist.at(nv) != -1 ) continue; //すでに通っていたらスルー
      dist.at(nv) = dist.at(v)+1;
      cnt.at(nv) += cnt.at(v);
      que.push(nv);
    }
  }
  
  for( int i = 0; i < N; i++ ) cout << cnt.at(i) << " ";
  cout << endl;
  

}

Measured memory_bytes: 19440
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

ar=[]
for i in range(3):
    ar.append(lis())
mark=[[0]*3 for _ in range(3)]
n=int(input())
for _ in range(n):
    k=int(input())
    for i in range(3):
        for j  in range(3):
            if ar[i][j]==k:
                mark[i][j]=1

for i in range(3):
    if mark[i][1]==mark[i][2]==mark[i][0]==1:
        print("Yes")
        quit()
for i in range(3):
    if mark[1][i]==mark[2][i]==mark[0][i]==1:
        print("Yes")
        quit()
if mark[0][0]==mark[1][1]==mark[2][2]==1:
    print("Yes")
    quit()
if mark[0][2]==mark[1][1]==mark[2][0]==1:
    print("Yes")
    quit()
print("No")




Measured memory_bytes: 62220
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const long long MAXN=200005;
const long long INF=9223372036854775807ll;
long long n,m,ecnt,key=0;
long long w[MAXN],d[MAXN],z[MAXN];
struct edge
{
	long long v,c,nxt;
	edge(){}
	edge(long long vv,long long cc,long long nn)
	{
		v=vv,c=cc,nxt=nn;
	}
}ed[MAXN*4];
void addedge(long long u,long long v,long long a)
{
	ecnt++;
	ed[ecnt]=edge(v,a,w[u]);
	w[u]=ecnt;
	
	ecnt++;
	ed[ecnt]=edge(u,a,w[v]);
	w[v]=ecnt;
}
void dfs(long long u,long long val,long long k)
{
	if(z[u]==0)
	{
		d[u]=val;
		z[u]=k;
		for(long long i=w[u];i;i=ed[i].nxt)
		{
			long long v=ed[i].v;
			long long c=ed[i].c;
			dfs(v,c-val,-k);
		}
	}
	else
	{
		if(k==z[u])
		{
			if(d[u]!=val)
			{
				printf("0\n");
				exit(0);
			}
			return ;
		}
		else
		{
			if(k==1)
			{
				key=d[u]-val;
				if((key&1)||(key<0))
				{
					printf("0\n");
					exit(0);
				}
				key/=2;
				return ;
			}
			else
			{
				key=val-d[u];
				if((key&1)||(key<0))
				{
					printf("0\n");
					exit(0);
				}
				key/=2;
				return ;
			}
		}
	}
}
bool check(int a)
{
	for(int i=1;i<=n;i++)
	{
		long long u=i;
		for(long long j=w[u];j;j=ed[j].nxt)
		{
			long long v=ed[j].v;
			long long c=ed[j].c;
			if(d[u]+z[u]*key+d[v]+z[v]*key!=c)
				return 0;
		}
	}
	return 1;
}
int main()
{
	key=-INF;
	scanf("%lld %lld",&n,&m);
	fill(d,d+MAXN,0);
	fill(z,z+MAXN,0);
	for(long long i=1;i<=m;i++)
	{
		long long u,v,s;
		scanf("%lld %lld %lld",&u,&v,&s);
		addedge(u,v,s);
		addedge(v,u,s);
	}
	dfs(1,0,1);
	if(key!=-INF)
	{
		for(long long i=1;i<=n;i++)
		{
			if(d[i]+z[i]*key<=0)
			{
				printf("0\n");
				return 0;
			}
		}
		if(check(key))
			printf("1\n");
		else
			printf("0\n");
		return 0;
	}
	long long da=-INF,x=INF;
	for(long long i=1;i<=n;i++)
	{
		if(z[i]==1)
		{
			da=max(da,-d[i]);
		}
		else
		{
			x=min(x,d[i]);
		}
	}
	da=max(da,0ll);
	x--;
	da++;
	if(x-da+1<=0)
		printf("0\n");
	else
		printf("%lld\n",x-da+1);
}

Measured memory_bytes: 17792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    if k == 0:
        print(sum(h))
        exit(0)
    h.sort()
    print(sum(h[:-k]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 26024
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int great = a[n - 1];
  int middle;
  if (great % 2) middle = great / 2 + 1;
  else middle = great / 2;
  int res = a[0];
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == great) continue;
    if (abs(a[i] - middle) < abs(res - middle)) {
      res = a[i];
    }
  }
  cout << great << " " << res << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

vector<vector<int>> g;
vector<ll> px;
vector<bool> visited;

void dfs(int p){
    visited[p] = true;
    for(int v: g[p]){
        if (visited[v]) continue;
        px[v] += px[p];
        dfs(v);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    g.resize(n);
    px.resize(n, 0);
    visited.resize(n, false);
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,q){
        ll p, x;
        cin >> p >> x;
        p--;
        px[p] += x;
    }
    dfs(0);
    rep(i,n){
        cout << px[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 25148
#include <iostream>
    #include <string>
    using namespace std;
     
    int main(){
      int N;
      cin >> N;
     
      int reverse = 0;
      while(N > 0){
        reverse += N % 10;
        N /= 10;
      }
      if(reverse == 1){
        reverse = 10;
      }
     
      cout << reverse << endl;
     
      return 0;
    }

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int X[200000];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<int> xs;
  rep(i, N) cin >> X[i] ,xs.pb(X[i]);
  sort(all(xs));
  int small = xs[N/2-1], large = xs[N/2];
  rep(i, N) {
    int ans = -1;
   if (X[i] <= small) ans = large;
   else ans = small;
   cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 3956
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll a, b, x, ans;

int main() {
    fast_io; cout_precision;
    cin >> a >> b >> x;
    ans = b / x + 1;
    if (a > 0) {
        ans -= (a - 1) / x + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

  int N; cin >> N;
  ll ans = 0LL;
  vel sum(N); rep(i,N) { ll a, b; cin >> a >> b; sum[i] = a + b; ans -= b; }

  sort(rall(sum));

  
  rep(i,N) {
    if(i % 2 == 0) ans += sum[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
int n,k,ans,di[101010];
struct point{
	int x,y;
};
point red[10101],blue[10101];
bool cmp(point a,point b){
    return a.x<b.x;
}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	cin>>n;
	for(register int i=1;i<=n;i++)cin>>red[i].x>>red[i].y;
	sort(red+1,red+n+1,cmp);
	for(register int i=1;i<=n;i++)cin>>blue[i].x>>blue[i].y;
	sort(blue+1,blue+n+1,cmp);
	for(register int i=1;i<=n;i++){
		while(red[k].x<=blue[i].x&&k<=n)k++;
		register int ma=0;
		for(register int j=1;j<k;j++){
			if(!di[j]&&red[j].y<=blue[i].y){
			    ma=red[ma].y>red[j].y?ma:j;
		    }
		}
		if(ma){
			di[ma]=1;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long num, count = 1;
    if(a > b) num = gcd(a, b);
    else num = gcd(b, a);
    long temp = num;
    for(int i = 2; i <= Math.sqrt(num); i++) {
      if(temp % i != 0) continue;
      count++;
      while(temp % i == 0) {
        temp /= i;
      }
    }
    if(temp != 1) count++;
    System.out.println(count);
  }

  public static long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, a % b);
  }
}


Measured memory_bytes: 23252
module Enumerable
  def cum_sum
    inject([0]) { |a, n| a << (a.last + n) }
  end
end

n = gets.to_i
s = gets.chomp

ws = s.each_char.map { |c| c.count 'W' }.cum_sum
es = s.each_char.map { |c| c.count 'E' }.cum_sum

p Array.new(n) { |i| ws[i] + es.last - es[i + 1] }.min


Measured memory_bytes: 15260
for e in iter(input,'0'):
 a=[list(map(int,input().split()))for _ in[0]*int(e)]
 b=[tuple(map(int,input().split()))for _ in[0]*int(input())]
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  if not set((u+x,v+y)for u,v in a)-set(b):print(x,y);break


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

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

Measured memory_bytes: 3748
L = [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]
K = int(input())
print(L[K-1])


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
// 最小公倍数
ll LCM(ll a, ll b){
    return a/GCD(a,b) * b;
}
int main(){
    ll A,B; cin >> A >> B;
    ll ans = LCM(A,B);
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/python3
import sys
import heapq

# main
q = []
S = sys.stdin.readlines()
for line in S:
    if line[0].startswith('i'):
        heapq.heappush(q, -int(line.split()[1]))
    elif line[1] == 'x':
        print(-heapq.heappop(q))
    else:
        exit()

Measured memory_bytes: 190340
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <limits.h>

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int diffabs(int l, int r)
{
	if (l < r)
		return r - l;
	else
		return l - r;
}


int main()
{
	int N;
	cin >> N;
	vi P(N), Q(N);
	for (int i = 0; i < N; i++)
		cin >> P[i];
	for (int i = 0; i < N; i++)
		cin >> Q[i];

	vi I(N);
	for (int i = 0; i < N; i++)
		I[i] = i+1;

	int a, b;
	int i = 0;
	do
	{
		if (P == I) a = i;
		if (Q == I) b = i;
		++i;
	}while(next_permutation(begin(I), end(I)));

	cout << diffabs(a, b) << endl;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a, b;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    rep(i,s.size()){
        if(s[i]!=t[i])return no,0;
    }
    if(s.size()+1==t.size())yes;
    else no;
}


Measured memory_bytes: 3656
n=int(input())
H=list(map(int,input().split()))
c=[10**10]*(n+1)
c[1]=0
c[2]=abs(H[1]-H[0])
if n>=3:
  for i in range(3,n+1):
    c[i]=min(c[i-2]+abs(H[i-1]-H[i-3]),c[i-1]+abs(H[i-1]-H[i-2]))
print(c[-1])
  

Measured memory_bytes: 13976
N,M,X = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(N)]

ans = 10**18

for b in range(2**N):
  b = bin(b)[2:].zfill(N)
  pay = [0]*(M+1)
  count = 0
  for i in range(N):
    if b[i] == "1":
      pay = [x + y for (x, y) in zip(pay, l[i])]
  for j in range(1,M+1):
    if pay[j] >= X:
      count += 1
  if count == M:
    ans = min(ans,pay[0])
if ans != 10**18:
  print(ans)
else:
  print(-1)

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

int main() {
    int N, ans=0;
    vector<int> a(5);
    for(int i=0; i<5; i++){
	cin >> a[i];
	if(a[i]==0)
	    cout << i+1 << endl;
    }
} 




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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n; cin >> n;
    map<int, int> mp;
    rep(i, n){
        int x; cin >> x;
        mp[x]++;
    }
    int m = mp.size(), b = 0;
    
    for(auto &p : mp){
        if(p.se % 2 == 0) b++;
    }

    out(m - b % 2);
}

Measured memory_bytes: 4992
N=int(input())
suits=["S","H","C","D"]
cards=[]
for n in range(N):
    s,n=input().split()
    if s=="S":
        cards.append(int(n))   
    elif s=="H":
        cards.append(13+int(n))   
    elif s=="C":
        cards.append(26+int(n))
    else:
        cards.append(39+int(n))

for i in range(1,53):
    if i not in cards:
        print(suits[(i-1)//13],(i-1)%13+1)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int MOD = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1);
    rep(i, m) {
        int ai;
        cin >> ai;
        a[ai] = 1;
    }
    vector<int> cnt(n+1);

    // 連続して壊れる床なら終了
    for(int i = 1; i <= n; i++){
        if (a[i-1] == 1 && a[i] == 1){
            cout << 0 << endl;
            return 0;
        }
    }

    cnt[0] = 1;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if (a[i] == 1) continue;

        if (i - 2 >= 0 && a[i-2] != 1) {
            cnt[i] += cnt[i-2];
            cnt[i] %= MOD;
        }
        if (a[i-1] != 1){
            cnt[i] += cnt[i-1];
            cnt[i] %= MOD;
        }
        
    }
    cout << cnt[n] << endl;

}

Measured memory_bytes: 1024
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll N, K;
	cin >> N >> K;
	// N = 1e6;
	ll h[N];
	for (ll i = 0; i < N; ++i) cin >> h[i];
	// for (ll i = 0; i < N; ++i) h[i] = i;
 
	// 解法
	sort(h, h + N);
	ll ans = 1e9;
	// REP(i, N) cout << h[i] << endl;
	REP(i, N-K+1){
		// cout << h[i+K-1]-h[i] << endl;
		if (h[i+K-1]-h[i]<ans) ans = h[i+K-1]-h[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){	
	int x, y;
	int w, h;
	int loop;
	char tile[101][101];


	while(1){
		x = 0;
		y = 0;
		loop = 0;

		for(int i=0; i<101; i++){
			for(int j=0; j<101; j++){
				tile[i][j] = 0;
			}
		}

		scanf("%d %d", &h, &w);
		if(w == 0 && h == 0) break;
		for(int i=0; i<h; i++){
			scanf("%s", tile[i]);
		}

		while(1){
			char c = tile[y][x];
			tile[y][x] = 'x';

			if(c == '>') x++;
			else if(c == '<') x--;
			else if(c == '^') y--;
			else if(c == 'v') y++;
			else if(c == '.') break;
			else{
				loop = 1;
				break;
			}
		}
		if(loop == 0)printf("%d %d\n", x, y);
		else printf("LOOP\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;

int h, w, n;
int sr, sc;
string s, t;
pair<int, int> winH[MAXN], winV[MAXN];

int main() {

  scanf("%d %d %d", &h, &w, &n);
  scanf("%d %d\n", &sr, &sc);
  sr--; sc--;
  getline(cin, s);
  getline(cin, t); 

  winH[n] = {0, w - 1};
  winV[n] = {0, h - 1};
  for (int i = n - 1; i >= 0; i--) {
    int dh1 = 0, dh2 = 0;
    int dv1 = 0, dv2 = 0;
    if (s[i] == 'L') {
      dh1 = -1;
    } else if (s[i] == 'R') {
      dh1 = 1;
    } else if (s[i] == 'U') {
      dv1 = -1;
    } else {
      dv1 = 1;
    }
    if (t[i] == 'L') {
      dh2 = -1;
    } else if (t[i] == 'R') {
      dh2 = 1;
    } else if (t[i] == 'U') {
      dv2 = -1;
    } else {
      dv2 = 1;
    }

    winH[i] = winH[i + 1];
    winH[i] = {max(0, min(winH[i].first, winH[i].first - dh2)), min(w - 1, max(winH[i].second, winH[i].second - dh2))};
    winV[i] = winV[i + 1];
    winV[i] = {max(0, min(winV[i].first, winV[i].first - dv2)), min(h - 1, max(winV[i].second, winV[i].second - dv2))};

    winH[i] = {max(winH[i].first, winH[i].first - dh1), min(winH[i].second, winH[i].second - dh1)};
    winV[i] = {max(winV[i].first, winV[i].first - dv1), min(winV[i].second, winV[i].second - dv1)};

    // cerr << "V: " << winV[i].first << " " << winV[i].second << endl;
    // cerr << "H: " << winH[i].first << " " << winH[i].second << endl;

    if (winH[i].first > winH[i].second || winV[i].first > winV[i].second) {
      puts("NO");
      return 0;
    }
  }

  if (sr >= winV[0].first && sr <= winV[0].second && sc >= winH[0].first && sc <= winH[0].second) {
    puts("YES");
  } else {
    puts("NO");
  }

  return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    int ans = abs(a[n - 1] - w);
    if(n >= 2)  chmax(ans, abs(a[n - 2] - a[n - 1]));
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long a, b, t, c, d;
    cin >> a >> b >> t >> c >> d;

    long long k = 0, ans = b + c - c % 2 + d - d % 2 + a - a % 2;
    while (k < 100 && a > 0 && c > 0 && d > 0) {
        a--;
        c--;
        d--;
        k++;
        ans = max(ans, b + c - c % 2 + d - d % 2 + a - a % 2 + 3 * k);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#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 n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  int ans = 0;
  rep(i, n) {
    if (x - a[i] < 0) break;
    x -= a[i];
    ans = i+1;
  }
  if (ans == n && x > 0) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=15;
int n,m,x,c[N],a[N][N];
int f[1<<N][N];
int main()
{
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	}
	int ans=0x3f3f3f3f;
	for(int i=1;i<(1<<n);i++)//共有2^n种选择方式，都不选可以忽略
	{
		int res[15];
		for(int j=1;j<=m;j++) res[j]=0;
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))//判断当前状态下，第j+1本书是否被选择
			{
				for(int k=1;k<=m;k++)//被选择后把这本书的贡献加进去
					res[k]+=a[j+1][k];
			}
		}
		bool flag=1;
		int cnt=0;
		for(int j=1;j<=m;j++)
			if(res[j]<x)
			{
				flag=0;
				break;
			}
		if(flag)
		{
			for(int j=0;j<n;j++)
				if(i&(1<<j))
					cnt+=c[j+1];
			ans=min(ans,cnt);
		}
	}
	if(ans==0x3f3f3f3f) puts("-1");
	else  cout<<ans;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long

using namespace std;
const int MAXN = (int)(1e6) + 10;
const int MOD = (int)(1e9) + 7;
const ll INF = (ll)(1e18);

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // Type your code here
    string s; int a;
    cin >> a >> s;
    if(a < 3200) cout << "red"; else cout << s;
    return 0;
}


Measured memory_bytes: 256
import itertools
import math

def main():
    N = int(input())
    x = [list(map(int,input().split())) for _ in range(N)]
    d_all = 0
    for root in itertools.permutations(range(N)):
        d_x,d_y = 0,0
        for i in range(N-1):
            d_x += x[root[i+1]][0]-x[root[i]][0]
            d_y += x[root[i+1]][1]-x[root[i]][1]
            d_all += (d_x**2+d_y**2)**(1/2)
    
    all_ = math.factorial(N)     
    print(d_all/all_)

if __name__ == "__main__":
    main()

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
//   cout<<std::setprecision(12)<<

int main()
{
    int i,j,k,l,m,n,x,y;
    cin >> n >> x >> y;
    mapii mm;
    for(i=1;i<n;i++)
    {
        mm[i] = n-i;
    }

    int u,v,vv;
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            u = j-i;
            v = abs(i-x)+1+abs(y-j);
            vv = abs(i-y)+1+abs(x-j);
            if(v<=u && v<=vv)
            {
                mm[u]--;
                mm[v]++;
            }
            else if(vv<=u && vv<=v)
            {
                mm[u]--;
                mm[vv]++;
            }
        }
    }

    for(auto x : mm)cout<<x.S<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define in insert

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

    string s;
    cin >> s;
    set<char> se;
    for(int i = 0; i < s.size(); i++) {
        se.in(s[i]);
    }
    if(se.size() == 3) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a+b+c<=21)cout << "win" << endl;
	else	cout << "bust" << endl;
}


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

int main() {
  int N; cin >> N;
  vector<string> word(N);
  for (int i = 0; i < N; i++) cin >> word.at(i);
  
  int same = 0;
  for (int i = 0; i < N - 1 && same == 0; i++)
    for (int j = i + 1; j < N && same == 0; j++)
      if (word.at(i) == word.at(j)) same = 1;
  
  if (same == 1)
    cout << "No" << endl;
  else {
    int miss = 0;
    for (int i = 0; i < N - 1 && miss == 0; i++)
      if (word.at(i).back() != word.at(i + 1).front()) miss = 1;
    if (miss == 1)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
}

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

int c[36] ;

int main(void){
    int n , m , i , j , k , ans ;
    int p3[16] ;
    
    for(p3[0] = 1 , i = 1 ; i < 16 ; i++){
        p3[i] = 3 * p3[i - 1] ;
    }
    while(scanf("%d%d" , &n , &m) && n > 0){
        for(i = 0 ; i < 3 ; i++){
            scanf("%d" , &j) ;
            while(j-- > 0){
                scanf("%d" , &k) , c[k - 1] = i ;
            }
        }
        ans = k = 0 ;
        for(i = 0 ; i < n ; i++){
            j = c[i] - k ;
            if(j < 0){
                j = -j ;
            }
            ans += j * p3[n - i - 1] ;
            if(j == 1){
                k = 2 - k ;
            }
        }
        k = p3[n] - ans - 1 ;
        if(ans > k){
            ans = k ;
        }
        if(ans > m){
            ans = -1 ;
        }
        printf("%d\n" , ans) ;
        
    }
    return 0 ;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  char a[5]={'a','i','u','e','o'};
  string s;
  cin >> s;
  for (int i=0;i<5;i++){
	if (s.at(0)==a[i]){
      cout<<"vowel"<<endl;
      return 0;
    }
  }
  cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
#!ruby -pl
def f s
s==""||(t=s.sub /#{c=s[0].to_i}{3}|#{c}(.*)#{c*11+12}/,'\1'
t!=s&&f(t))end
r=?1..?9
m=r.select{|i|s=($_+i).chars.sort*""
5>s.count(i)&&r.any?{|j|f s.sub j*2,""}}*" "
$_=m>""?m:?0

Measured memory_bytes: 6552
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A,N) for(ll i=0;i<N;i++) cin>>A[i];
int main()
{
    fasino
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    #endif
    int n,k;
    cin>>n>>k;
    vector<int> A(n);
    input(A,n);
    vector<ll> dp(n,INT32_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0){
                dp[i] = min(dp[i],dp[i-j] + abs(A[i-j]-A[i]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}

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

using namespace std;
typedef  long long ll;
int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    bool ok =true;
    const ll mod = 1e9+7;
    ll ans=1;
    for(int i=0;i<N;i++){
        int tmp;
        cin>>tmp;
        a[tmp]++;
        if(N%2==1&&tmp==0)
            a[tmp]++;
    }
    sort(a.begin(),a.end(),greater<int>());

    for(int i=0;i<N/2;i++){
        if(a[i]==2){
            ans*=2;
            ans%=mod;
        }else{
            ans = 0;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

bool dfs(vector<vector<pair<int, long long>>>& graph, vector<long long>& dist, int idx, int d) {
    if (dist[idx] == (1LL << 48)) {
        dist[idx] = d;

        bool res = true;
        for (int i = 0; i < static_cast<int>(graph[idx].size()); i++) {
            res = res && dfs(graph, dist, graph[idx][i].first, d + graph[idx][i].second);
        }

        return res;
    } else {
        return (dist[idx] == d);
    }
}

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

    vector<vector<pair<int, long long>>> graph(n, vector<pair<int, long long>>(0));
    for (int i = 0; i < m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        graph[l - 1].push_back(make_pair(r - 1, d));
        graph[r - 1].push_back(make_pair(l - 1, -d));
    }

    bool res = true;
    vector<long long> dist(n, 1LL << 48);
    for (int i = 0; i < n; i++) {
        if (dist[i] == (1LL << 48)) {
            res = res && dfs(graph, dist, i, 0);
        }
    }

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


Measured memory_bytes: 16512
#include <iostream>

using namespace std;
int main(void){
    long long N,T,S,ans,F,Z,m,M;
    cin>>N;
    M=1000000000;
    m=-1000000000;
    T=0;
    S=0;
    long long A[N];
    F=0;
    Z=0;
    int j;
    
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]<0){
            F=F+1;
            T=T+A[i];
            if(m<A[i]){
                m=A[i];
                
            }
        }else if(A[i]==0){
            Z=Z+1;
        }else{
            S=S+A[i];
            if(M>A[i]){
                M=A[i];
            }
        }
    
      
    }
    if(F%2==0){
        ans=S-T;
    }else if(Z>0){
        ans=S-T;
    }else{
        m=m*(-1);
        ans=S-T-min(M,m)*2;
    }
    
    cout<<ans<<endl;
    return 0;
    
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

//ダイクストラ高速版

struct edge { int src, dest, cost; };
using P = pair<int, int>; //距離、ノード番号

const int INF = INT_MAX;
int V;                      //Node数
map<int, vector<edge>> G; //edge集合、G[src][index]
// map<int, int> DIST;         //現状のコスト　DIST[Node][Cost]
vector< vector<int> > DIST;  //現状のコスト　DIST[Src][Dist]->[Cost]
map<int, int> preNode;      //最短経路上の1ホップ前のノード 




void init() {

	vector<int> vec(V, INF);
	for (int i = 0; i < V; i++) {
		DIST.push_back(vec);
	}

}

void setEdge(int src, int dest, int cost) {
	edge e = { src,dest,cost };
	G[src].push_back(e);
}

void dijkstra(int s) {
	//要素の型,内部コンテナの型、並べ替え方法
	//P->first＝距離で昇順にソート
	priority_queue<P, vector<P>, greater<P> > que;

	DIST[s][s] = 0;
	preNode[s] = s;
	que.push(P(0, s));

	while (!que.empty()) {

		P p = que.top(); que.pop();

		int tmp_node = p.second;
		if (DIST[s][tmp_node] < p.first) { continue; }
		for (auto g : G[tmp_node]) {
			edge e = g;
			if (DIST[s][e.dest] > DIST[s][tmp_node] + e.cost) {
				DIST[s][e.dest] = DIST[s][tmp_node] + e.cost;
				que.push(P(DIST[s][e.dest], e.dest));
				preNode[e.dest] = tmp_node;
			}
		}
	}


}


int main(void) {
	long long N, X, Y;
	map<long long, long long> ans;

	cin >> N >> X >> Y;


	V = N;//頂点数を登録

	//初期化
	init();

	//エッジの作成
	for (int i = 0; i < N-1; i++) {
		setEdge(i, i + 1, 1);
		setEdge(i + 1, i, 1);
	}
	setEdge(X - 1, Y - 1, 1);
	setEdge(Y - 1, X - 1, 1);

	for (long long i = 0; i < N; i++) {
		dijkstra(i);
	}

	for (long long i = 0; i < N; i++) {
		for (long long j = i; j < N; j++) {
			ans[DIST[i][j]]++;
		}
	}

	for (long long i = 1; i <= N - 1; i++) {
		cout << ans[i] << endl;
	}




	return 0;
}



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

int main(void){
    int n, r=0, b=0, i;
    scanf("%d", &n);
    char s[n];
    scanf("%s", s);
    for(i=0; i<n; i++){
        if(s[i] == 'R') r++;
        else b++;
    }
    if(r>b) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int result = 0;
        if (c - (a - b) >= 0) result = c - (a - b);
        System.out.println(result);
    }
}


Measured memory_bytes: 35664
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    string S; cin >> S;
    deque<char> dS(S.size());
    for (int i = 0; i < S.size(); i++) dS[i] = S[i];

    int Q; cin >> Q;
    int rev = 0;
    for (int i = 0; i < Q; i++) {
        int type; cin >> type;
        if (type == 2) {
            int f; char c;
            cin >> f >> c; f--;
            if (rev) f = 1 - f;
            if (f == 0) dS.push_front(c);
            else dS.push_back(c);
        }
        else rev = 1 - rev;
    }
    if (rev) reverse(dS.begin(), dS.end());
    for (auto c : dS) cout << c;
    cout << endl;
}


int main() {
    solve();
    return 0;
}

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

int main(void){
	string O,E,ans;
	cin >> O;
	cin >> E;
	int i;
	int n= O.size()+E.size();
	for(i=0;i<n;i++){
		if(i%2==0){
			printf("%c",O[i/2]);
		}else{
			printf("%c",E[i/2]);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, ans;
  cin >> N >> K;
  ans = 0;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  for (int i=0; i<K; i++) {
    ans += vec.at(i);
  }
  
  cout << ans << endl;
 
}

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

using namespace std;
const int MAXN=2005;
struct edge{int to,nxt;}e[MAXN<<2];
int n,k,x,y,head[MAXN],dist[MAXN],tot=0,tmp=0,res=0,S=0;

void add_edge(int from,int to)
{
	e[++tot].nxt=head[from];e[tot].to=to;head[from]=tot;
	e[++tot].nxt=head[to];e[tot].to=from;head[to]=tot;
}

int dfs(int x,int anc,int lmt)
{
	int ret=1;if(x==S) dist[x]=0;
	for(int i=head[x];i;i=e[i].nxt)
	{
		if(e[i].to==anc) continue;
		dist[e[i].to]=dist[x]+1;
		if(dist[e[i].to]<=lmt) ret+=dfs(e[i].to,x,lmt);
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
		scanf("%d%d",&x,&y),add_edge(x,y);
		
	for(int i=1;i<=n;i++)
		res=max(res,dfs(S=i,0,k/2));
	if(!(k&1)) return printf("%d",n-res),0;
	
	for(int i=1;i<=n;i++)
		for(int j=head[i];j;j=e[j].nxt)
			res=max(res,dfs(S=i,e[j].to,(k-1)>>1)+dfs(S=e[j].to,i,(k-1)>>1));
	printf("%d",n-res);
	return 0;
}

Measured memory_bytes: 384