akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
 
int n, a[9], b[10];  

int main(){
    int isChecked[9];
    for (int i = 0; i < 9; i++){
        isChecked[i] = 0;
    }
    for (int i = 0; i < 9; i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&n);
    for (int i = 0; i < n; i++){
        scanf("%d",&b[i]);
    }

    for (int i = 0; i < n; i++){
        for (int j = 0; j < 9; j++){   //コピペするなら全部確認しろ、jに変換忘れ
            if (b[i]==a[j]){
                isChecked[j] = 1;
            }
        }
    }
    if(isChecked[0] && isChecked[1] && isChecked[2]){
        printf("Yes\n");
    }
    else if(isChecked[3] && isChecked[4] && isChecked[5]){
        printf("Yes\n");
    }
    else if(isChecked[6] && isChecked[7] && isChecked[8]){
        printf("Yes\n");
    }
    else if(isChecked[0] && isChecked[3] && isChecked[6]){
        printf("Yes\n");
    }
    else if(isChecked[1] && isChecked[4] && isChecked[7]){
        printf("Yes\n");
    }
    else if(isChecked[2] && isChecked[5] && isChecked[8]){
        printf("Yes\n");
    }
    else if(isChecked[0] && isChecked[4] && isChecked[8]){
        printf("Yes\n");
    }
    else if(isChecked[2] && isChecked[4] && isChecked[6]){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    } 
    return 0;
}


Measured memory_bytes: 1624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector< vector<int> >ahzong(h,vector<int>(w));
  vector<vector<long long> >dp(h,vector<long long>(w,INT_MAX));
  for(int i = 0; i < h; i++) for(int j = 0; j < w; j++)
    {
    	char a; cin >> a;
    	if(a == '#') ahzong[i][j] = 1;
    }
    dp[0][0] = ahzong[0][0];
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++)
    {
    	if(i!=0)
    	{
    		int b = (ahzong[i][j] && (ahzong[i][j] != ahzong[i - 1][j]));
    		dp[i][j] = min(dp[i][j], dp[i - 1][j] + b);
    	}
    	if(j!=0)
    	{
    		int b = (ahzong[i][j] && (ahzong[i][j] != ahzong[i][j - 1]));
    		dp[i][j] = min(dp[i][j], dp[i][j - 1] + b);
       	}
    }
    cout << dp[h - 1][w - 1];
 
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005;
const LL INF=1e18;
int n,m,rt;
LL a[N],b[N],c[N];
vector <int> son[N];
namespace Build_Tree{
	vector <int> e[N];
	int id[N];
	bool cmp(int x,int y){
		if (a[x]!=a[y])
			return a[x]<a[y];
		return b[x]>b[y];
	}
	int fa[N],vis[N];
	int getf(int x){
		return fa[x]==x?x:fa[x]=getf(fa[x]);
	}
	void main(){
		For(i,1,m){
			int x=read(),y=read();
			e[x].pb(y),e[y].pb(x);
		}
		For(i,1,n)
			id[i]=fa[i]=i;
		sort(id+1,id+n+1,cmp);
		For(i,1,n){
			int x=id[i];
			for (auto y : e[x])
				if (vis[y]&&getf(y)!=x){
					son[x].pb(getf(y));
//					printf("%d -> %d\n",x,getf(y));
					fa[getf(y)]=x;
				}
			vis[x]=1;
		}
		rt=id[n];
	}
}
bool cmp(int x,int y){
	return a[x]-b[x]<a[y]-b[y];
}
pair <LL,LL> Merge(pair <LL,LL> a,pair <LL,LL> b){
	return mp(max(a.fi,a.se+b.fi),a.se+b.se);
}
void dfs(int x){
	for (auto y : son[x])
		dfs(y);
	sort(son[x].begin(),son[x].end(),cmp);
	reverse(son[x].begin(),son[x].end());
	int m=son[x].size();
	vector <pair <LL,LL> > pre(m+1,mp(0,0)),suf(m+1,mp(0,0));
	For(i,0,m-1){
		int y=son[x][i];
		pre[i+1]=Merge(pre[i],mp(a[y],b[y]));
	}
	Fod(i,m-1,0){
		int y=son[x][i];
		suf[i]=Merge(mp(a[y],b[y]),suf[i+1]);
	}
	c[x]=INF;
	For(i,0,m-1){
		int y=son[x][i];
		pair <LL,LL> tmp=Merge(pre[i],suf[i+1]);
		tmp=Merge(tmp,mp(a[x],b[x]));
		c[x]=min(c[x],Merge(tmp,mp(c[y],b[y])).fi);
	}
	pair <LL,LL> tmp=Merge(pre[m],mp(a[x],b[x]));
//	outval(pre[m].fi),outval(pre[m].se);
//	printf("%d: %lld,%lld,%lld\n",x,a[x],b[x],c[x]);
	a[x]=tmp.fi,b[x]=tmp.se;
	c[x]=min(c[x],a[x]);
//	printf("%d: %lld,%lld,%lld\n",x,a[x],b[x],c[x]);
}
int main(){
	n=read(),m=read();
	For(i,1,n)
		a[i]=read(),b[i]=read();
	Build_Tree::main();
	dfs(rt);
	cout<<max(b[rt],c[rt])<<endl;
	return 0;
}

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

#define ll long long

using namespace std;

int main() {
	ll n, d; cin >> n >> d;
	d *= d;
	int res = 0;
	while (n--) {
		ll x, y; cin >> x >> y;
		ll dis = x * x + y * y;
		if (dis <= d) ++res;
	}
	cout << res;
}

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



int main(){
    int a, b, c;
    int times; 
    cin >> a >> b;

    c = b;
    times = 10;
    while(c>0){
        int tmp = c/10;
        if(tmp>0){
            times*=10;
        }
        c/=10;
    }
    
    a = a*times;
    a+=b;
    int sqrtVal = (int)sqrt(a);
    bool  res = (sqrtVal * sqrtVal) == a;
    if(res){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
ll a[maxn];
int main(){
    string s;
    cin>>s;
    int l=s.size();
    if(s[0]==s[l-1]){
        if(l%2) cout<<"Second\n";
        else cout<<"First\n";
    }
    else{
        if(l%2) cout<<"First\n";
        else cout<<"Second\n";
    }
    return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

import sys
import math

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        for line in sys.stdin:
            lines.append(line)
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    # 出力
    nm = lines[0].split(" ")
    n = int(nm[0])
    m = int(nm[1])

    rows = []
    for i in range(1, n+1):
        rows.append([int(e) for e in lines[i].split(" ")])

    return (n, m, rows)

def solve(n, m, rows):

    result = []
    for k in range(1, m + 1):
        tmp = []
        for i in range(0, n):
#            print(rows[i])
            r = rows[i]
#            print(r[1:r[0] + 1])
            if k in r[1:r[0]+1]:
               tmp.append(i+1)
        if len(tmp) == n:
            result.append(k)

    return len(result)

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
string a[3];
vec A[3][3];
int main(){
    rep(i,3) cin>>a[i];
    rep(i,3)rep(j,3){
        if(i==j) continue;
        rep(k,a[i].size()){
            int z=1;
            rep(l,min(a[j].size(),a[i].size()-k)) if(a[i][l+k]!=a[j][l]&&a[i][l+k]!='?'&&a[j][l]!='?') z=0;
            A[i][j].push_back(z);
        }
    }
    int ans=a[0].size()+a[1].size()+a[2].size();
    vec B={0,1,2};
    do{
        rep(i,a[B[0]].size()+1)rep(j,max(a[B[0]].size()-i,a[B[1]].size())+1){
            if((i>=a[B[0]].size()||A[B[0]][B[1]][i])&&(j>=a[B[1]].size()||A[B[1]][B[2]][j])&&(i+j>a[B[0]].size()||A[B[0]][B[2]][i+j])) ans=min(ans,int(max({a[B[0]].size(),i+a[B[1]].size(),i+j+a[B[2]].size()})));
        }
    }while(next_permutation(all(B)));
    cout<<ans<<"\n";
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#define PAI 3.1415926
#define DtoR(ang)	((ang*PAI)/180)

struct Pos{
	double x,y;
};

void VAdd(Pos *v1,Pos *v2){
	v1->x += v2-> x;
	v1->y += v2-> y;
}
Pos AtoV(double vsize,double ang){	//極座標を直交座標に変換
	Pos v;
	v.x = vsize*cos(ang);
	//if(v.x>0)v.x -= 1e-6;
	//else if(v.x < 0)v.x += 1e-6;
	v.y = vsize*sin(ang);
	//if(v.y>0)v.y -= 1e-6;
	//else if(v.y < 0)v.y += 1e-6;
	return v;
}
int main(){
	double vsize,ang,sum_ang = 90;
	Pos sumv = {0,0},v;
	while(~scanf("%lf,%lf",&vsize,&ang)){
		v = AtoV(vsize,DtoR(sum_ang));
		VAdd(&sumv,&v);
		sum_ang -= ang;
	}
	if(sumv.x>0)v.x += 1e-5;
	else if(sumv.x < 0)v.x -= 1e-5;
	if(v.y>0)v.y += 1e-5;
	else if(v.y < 0)v.y -= 1e-5;
	int x = sumv.x;
	int y = sumv.y;
	printf("%d\n%d\n",x,y);
	return 0;
}

Measured memory_bytes: 1060
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
 
using namespace std;

int main(){
    int N;
    int A,B;

    cin >> N;

    if(N == 1){
        cout << "Hello World" << endl;
    }else{
        cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#define MAX_L (1010)
using namespace std;

int q;
int dp[2][MAX_L];

int main()
{
    scanf("%d", &q);


    for ( int i = 0; i < q; i++ ) {
	string a, b;
	char str[MAX_L];
	scanf("%s", str);
	a = str;
	scanf("%s", str);
	b = str;	
	memset(dp, 0, 2 * MAX_L * sizeof(int));
	
	for ( int j = 1; j <= a.length(); j++ ) {
	    for ( int k = 1; k <= b.length(); k++ ) {
		if ( a[j-1] == b[k-1] ) {
		    dp[j%2][k] = dp[(j-1)%2][k-1] + 1;
		}
		else {
		    dp[j%2][k] = max(dp[(j-1)%2][k], dp[j%2][k-1]);
		}
	    }
	}
	printf("%d\n", dp[(a.length())%2][b.length()]);
    }

    return 0;
}

Measured memory_bytes: 1064
#include<iostream>
#include<functional>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>

using namespace std;

#define LL long long

queue<pair<string,int>>qsi;
int n,q,t=0;

int main() {
	cin>>n>>q;
	for(int i=0;i<n;i++){
		string name;
		int time;
		cin>>name>>time;
		qsi.push({name,time});
	}
	while(!qsi.empty()){
		auto tp=qsi.front();
		qsi.pop();
		if(tp.second<=q){
			t+=tp.second;
			cout<<tp.first<<" "<<t<<endl; 
		}
		else{
			t+=q;
			qsi.push({tp.first,tp.second-q});
		}
	}

	return 0;
}



Measured memory_bytes: 6248
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* class */
class DisjointSet {
public:
    // d[i] is root => d[i] < 0 & d[i] is the size of tree
    // d[i] is child => d[i] >= 0 & d[i] = i.parent
    vector<int> d;

    DisjointSet() {}
    DisjointSet(int size) : d(size, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if ( d[x] > d[y] ) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
/* global variables */
/* function */
/* main */
int main(){
    int n, m;
    cin >> n >> m;
    DisjointSet ds = DisjointSet(n);

    int ans = n - 1;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (!ds.same(a, b)) {
            ds.unite(a, b);
            ans--;
        }
    }
    cout << ans << '\n';

}


Measured memory_bytes: 3740
N, K = map(int,input().split())
if K % 2 == 1:
    c = N//K
    ans = c*(c-1)*(c-2)+3*c*(c-1)+c
    print(ans)
else:
    K //= 2
    e = 0
    o = 0
    for i in range(1, N+1):
        if i % K == 0:
            if (i//K) % 2 == 0:
                e += 1
            else:
                o += 1
    c = e
    ans = c*(c-1)*(c-2)+3*c*(c-1)+c
    c = o
    ans += c*(c-1)*(c-2)+3*c*(c-1)+c
    print(ans)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	vector<int> x = {1, 2, 3};
	int a, b;
	cin >> a >> b;
	rep(i, 3) {
		if (x[i] != a && x[i] != b) {
			cout << x[i] << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n;
    cin >> n;
    n--;
    string ans = "";
    while(n >= 0){
        ans.push_back(n%26 + 'a');
        n/=26;
        n--;
        if(n == 0){
            ans.push_back('a');
            break;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}






Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

/*#pragma GCC optimize("O3")
#pragma target("avx2")
#pragma GCC optimize("unroll-loops")*/

using namespace std;

/*random_device rd;
mt19937 gen(rd());*/

typedef long long ll;
typedef long double ld;

#define int ll
//#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 1e5 + 7;

void solve() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size(), ans = 0;
    loop1(i, n - 1) {
        if (k == 1) 
            ans += 9;
        if (k == 2)
            ans += 81ll * (i - 1);
        if (k == 3)
            ans += 729ll * (i - 1) * (i - 2) / 2;
    }
    if (k == 1)
        ans += s[0] - '0';
    if (k == 2) {
        ans += 9ll * (n - 1) * (s[0] - '1');
        for (int i = 1; i < n; ++i)
            if (s[i] > '0') {
                ans += (s[i] - '0') + 9ll * (n - i - 1);
                break;
            }
    }
    if (k == 3) {
        ans += 81ll * (n - 1) * (n - 2) / 2 * (s[0] - '1');
        for (int i = 1; i < n; ++i)
            if (s[i] > '0') {
                ans += 9ll * (s[i] - '1') * (n - i - 1) + 81ll * (n - i - 1) * (n - i - 2) / 2;
                for (int j = i + 1; j < n; ++j)
                    if (s[j] > '0') {
                        ans += (s[j] - '0') + 9ll * (n - j - 1);
                        break;
                    }
                break;
            }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{   int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else if(op=='?') {
            break;
        }
    }
    return 0;
}

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

const long long MOD = 1e9 + 7;

int main(){
  string s; cin >> s;
  int N = s.size();
  vector<vector<long long> > dp(2, vector<long long>(N+1, 0));
  dp[0][1] = 1LL; dp[1][1] = 2LL;
  
  for(int i = 1; i < N; i++){
    if(s[i] == '1'){
      dp[0][i+1] = ((dp[0][i] * 3) % MOD + dp[1][i]) % MOD;
      dp[1][i+1] = (dp[1][i] * 2) % MOD;
    }else{
      dp[0][i+1] = (dp[0][i] * 3) % MOD;
      dp[1][i+1] = dp[1][i] % MOD;
    }
  }
  cout << (dp[0][N] + dp[1][N]) % MOD;
}

Measured memory_bytes: 2816
import sys
from collections import deque
from itertools import *


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


s = S()

ans = 0
temp = 0
for s_s in s:
    if s_s in 'ACGT':
        temp += 1
    else:
        temp = 0
    ans = max(ans, temp)
print(ans)


Measured memory_bytes: 64988
from math import radians, sin, cos, sqrt
A,B,H,M = list(map(int, input().split()))

frad = radians(M*6)
fx,fy = B * sin(frad), B * cos(frad)

jrad = radians(H*30 + M * 0.5)
jx,jy = A * sin(jrad), A * cos(jrad)

dis = sqrt( (jx - fx) ** 2 + (jy - fy) ** 2)
print(dis)


Measured memory_bytes: 9500
def solve(string):
    s, k = string.split()
    counter = 0
    for _s in s:
        if _s == "1":
            counter += 1
            continue
        break
    return s if len(s) == 1 else "1" if int(k) <= counter else s[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


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

int main(){
	string s;
	getline(cin,s);
	for (int i = 0; i < 3; i++)
	{
		if (s[i] ==s[i+1])
		{
				cout << "Bad";
				return 0;
		}
	}
	cout << "Good";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int N,M;
int pre[10010];
struct node1{
	double x,y;
}point[10010]; 
struct node2{
	int u,v;
	double cost;
}rode[100010];
bool cmp(node2 x,node2 y){
	return x.cost>y.cost;
}
double dis(int x,int y){
   double sum;
   sum=sqrt((point[x].x-point[y].x)*(point[x].x-point[y].x)+(point[y].y-point[x].y)*(point[y].y-point[x].y));
   return sum;
}
void init(){
	for(int i=0;i<10010;i++){
		pre[i]=i;
	}
}
int  find(int x){
	if(pre[x]==x)
	  return x;
	return pre[x]=find(pre[x]);
}
void mar(int x,int y){
	int xx=find(x);
	int yy=find(y);
	if(xx!=yy);
	pre[xx]=yy;
}
double kruskra(){
	double ans=0;
	int num=0;
	sort(rode,rode+M,cmp);
	for(int i=0;i<M;i++){
		if(find(rode[i].v)!=find(rode[i].u)){
			mar(rode[i].u,rode[i].v);
			ans=ans+rode[i].cost;
			num++;
		}
	}
	return ans;
}
int main(){
	while(cin>>N>>M){
	double sum1=0,sum2=0;
	   for(int i=1;i<=N;i++){
		  cin>>point[i].x>>point[i].y;
	   }
	    for(int i=0;i<M;i++){
		  cin>>rode[i].u>>rode[i].v;
		  rode[i].cost=dis(rode[i].u,rode[i].v);
		  sum1=rode[i].cost+sum1;
	   }
	   init();
	   sum2=kruskra();
	   printf("%.3lf\n",sum1-sum2);
   }
}



Measured memory_bytes: 3864
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {


    int h,w;

    
    while(1){
        cin >> h >> w;
        
        if(h==0 && w==0)
            break;
        
        for(int i=0; i<h; i++){
            if(i==0 || i==h-1){
                for(int j=0; j<w; j++){
                    cout << "#" ;
                }
                cout << endl;
            }
            else{
                for(int j=0; j<w; j++){
                    if(j==0 || j==w-1)
                       cout << "#";
                   else
                       cout << ".";
                }
                cout << endl;
            }

        }
        cout << endl;
    }
    
    return 0;
    
}



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

using namespace std;

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

const int N = 1e3;
string s[N];

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dis[N][N], h, w, k;

void bfs(int sx, int sy){
	memset(dis, -1, sizeof dis);
	dis[sx][sy] = 0;
	queue<pii> q;
	q.push(pii(sx, sy));

	while(q.size()){
		int r = q.front().first, c = q.front().second;
		q.pop();

		for (int i = 0; i < 4; i++){
			int nr = r + dx[i], nc = c + dy[i];
			if (nr >= 0 && nr < h && nc >= 0 && nc < w && dis[nr][nc] == -1 && s[nr][nc] == '.'){
				dis[nr][nc] = dis[r][c] + 1;
				q.push(pii(nr, nc));
			}
		}
	}
}

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

	cin >> h >> w >> k;

	int sx, sy;
	for (int i = 0; i < h; i++){
		cin >> s[i];
		for (int j = 0; j < w; j++)
			if (s[i][j] == 'S') sx = i, sy = j, s[i][j] = '.';
	}

	bfs(sx, sy);

	int ans = 1e9;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) if (dis[i][j] <= k && dis[i][j] != -1){
			int t = min({i, j, h - i - 1, w - j - 1});
			//cerr << i << ", " << j << " : " << t << endl;
			ans = min(ans, (t + k - 1) / k + 1);
		}

	cout << ans << endl;
}

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

using namespace std;
int main(){
	int n, k, q = 0;
    cin >> n >> k;
    vector <int> a(n);
    for(int i = 0; i < n; i++)a[i] = 0;
    for(int i = 0; i < k; i++){
        int d,A;
        cin >> d;
        for(int i = 0; i < d; i++){
            cin >> A;
            a[A-1] = 1;
        }
    }
    for(int i = 0; i < n; i++)if(a[i] == 0)q++;
    cout << q;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int n; cin >> n;
    int sum = 0;
    vector<int> t(n);
    rep(i, n){
        cin >> t[i];
        sum += t[i];
    }
    int m; cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    rep(i, m){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    int ans = 0;
    int ans_min = INFINITY;
    for(int i = 0; i < m; ++i){
        ans = sum + x[i] - t[p[i]];
        cout << ans << endl;
    }
}

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

long long calc_digit(long long N){
    long long ans = 0;
    while(N>0){
        ans++;
        N/=10;
    }
    return ans;
}


int main(){
    long long N; cin >> N;
    long long ans = 1LL << 60;
    for(long long A = 1; A*A <= N; A++){
        if(N%A!=0)continue;
        long long B = N/A;
        long long res = max(calc_digit(A),calc_digit(B));
        ans = min(res,ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3556
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector<pair<int, int> > vepa;
typedef set<string>se;
typedef map<char,int> mpp;
const ll N=3000,OO=1e14,MOD=1e9+7;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,m,k,a,b,c,d,x,y,l,r,cnt,sum,mx,mn,arr[N];
bool f,vis[N];
int main(){
   IOS;
   string s;
   cin>>a>>b>>c>>d;
   cout<<max( {max(a,b)*max(c,d) ,min(a,b)*max(c,d), max(a,b)*min(c,d),min(a,b)*min(c,d)});
go;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int max_n = 1e5 + 5;
const int mod = 1e9 + 7;

VI g[max_n];
int dp[max_n][2];

void dfs(int v, int p) {
	dp[v][0] = 1;
	dp[v][1] = 1;
	FORE(i, g[v]) {
		int w = *i;
		if (w == p) continue;
		dfs(w, v);
		dp[v][0] = (dp[v][0] * 1LL * dp[w][1]) % mod;
		dp[v][1] = (dp[v][1] * 1LL * (dp[w][1]+dp[w][0])) % mod;
	}
}

int main () {
	make(n);
	FOR(i,0,n-1) {
		make2(a, b); a--; b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0,0);
	printf("%d\n", (dp[0][0] + dp[0][1])%mod);

}	





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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#else
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#endif
template<class T> inline void dump2D(T &d, size_t sizey, size_t sizex) { ostream&o=
#ifdef USE_COUT
  cout;
#else
  cerr;
#endif
  for(size_t i = 0; i < sizey; i++) { for(size_t j = 0; j < sizex; j++) o << d[i][j] << " "; o << endl; }
}
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (42)
#define dump2D(...) (42)
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
/// }}}--- ///


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(auto&e:a)cin>>e;
  auto b = a;
  sort(begin(b), end(b));
  int ok = 0, ng = n;
  while(ng - ok > 1) {
    int mid = (ok + ng) >> 1;
    int now = 0;
    int h = 0;
    ll bias = 0;
    ll up = 0;
    ll sum = 0;
    map<int, int>mp;
    for(int i = 0; i < n; i++) {
      if(a[i]>=b[mid]) {
        up++;
        now++;
        up += mp[-now];
        mp[1-now]++;
      } else {
        up -= mp[-now];
        now--;
        mp[-1-now]++;
      }
      sum+=up;
    }
    dump(mid, b[mid], sum);
    if(sum >= (n*(n+1)/2+1)/2) ok = mid; else ng = mid;
  }
  cout << b[ok] << endl;
  return 0;
}


Measured memory_bytes: 6528
coin500, coin100, coin50, total = map(int, [int(input()) for i in range(4)])
count = 0;
for i in range(coin500 + 1):
  for j in range(coin100 + 1):
    for z in range(coin50 + 1):
      if 500 * i + 100 * j + 50 * z == total:
        count += 1
print(count)

Measured memory_bytes: 9016
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}



int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    cout << H*W - (h*W+w*H)  +h*w << endl;

    

    return 0;
}


Measured memory_bytes: 3544
/*
ID: vasu090
TASK: 
LANG: C++
*/
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define mp make_pair
#define pb push_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

bool checkSame(int arr[], int arr2[], int N){
	list(i,N){
		if(arr[i]!=arr2[i]) return false;
	}
	return true;
}

int32_t main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int N; cin >> N;
//	string PS=""; string QS="";
	int P[N]; list(i,N) cin >> P[i];// PS+=to_string(P[i]);
	int Q[N]; list(i,N) cin >> Q[i]; //QS+=to_string(Q[i]);

	int arr[N]; list(i,N) arr[i] = i+1;
	
	//first find the rank of P
	int rankP=0;
	do {
		if(checkSame(arr,P,N)) break;
		else rankP++;
	}while(next_permutation(arr,arr+N));
	
	//second find the rank of Q
	int rankQ=0;
	list(i,N) arr[i] = i+1;
	do {
		if(checkSame(arr,Q,N)) break;
		else rankQ++;
	}while(next_permutation(arr,arr+N));
	
	cout << abs(rankP-rankQ) << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=212345;
int n,c=1,now,pre;
char s[maxn];
int main()
{
    scanf("%d%s",&n,s);
    if (s[0]=='W') return 0*puts("0");
    int res=1;
    for (int i=1;i<n+n;++i) {
        now=(s[i]==s[i-1])^pre;
        if (now) res=1ll*res*c%mod,--c;
        else ++c;
        pre=now;
    }
    if (c) return 0*puts("0");
    else {
        for (int i=2;i<=n;++i) res=1ll*res*i%mod;
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,n;
    cin>>n;
    int a[n],b[n],c[n];
    int dp[n][3];
    for(i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(i=1;i<n;i++){
        dp[i][0]=a[i]+ max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+ max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i] + max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

// a:0,g:1,c:2,t:3
int main(){
    int n, len, i, j, k, l;
    long long s = 0;
    cin >> n;
    long long dp[n+1][4][4][4] = {};
    dp[0][3][3][3] = 1;
    for(len=0; len<n; len++){
        for(i=0; i<4; i++){
            for(j=0; j<4; j++){
                for(k=0; k<4; k++){
                    for(l=0; l<4; l++){
                        if(j==0 && k==1 && l==2) continue;
                        if(j==1 && k==0 && l==2) continue;
                        if(j==0 && k==2 && l==1) continue;
                        if(i==0 && k==1 && l==2) continue;
                        if(i==0 && j==1 && l==2) continue;
                        dp[len+1][j][k][l] += dp[len][i][j][k];
                        dp[len+1][j][k][l] %= MOD;
                    }
                }
            }
        }
    }
    for(i=0; i<4; i++){
        for(j=0; j<4; j++){
            for(k=0; k<4; k++){
                s += dp[n][i][j][k];
            }
        }
    }
    s %= MOD;
    cout << s;
    return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

inline void failure(){puts("Impossible");exit(0);}

const int _ = 103;

int n,m,val[_];
vector<int> ans;

int main()
{
	n=ty(),m=ty();
	for(int i=1;i<=m;i++)val[i]=ty();

	int cnt=0;
	for(int i=1;i<=m;i++)cnt+=val[i]&1;
	if(cnt>2)failure();

	for(int i=2;i<=m;i++)
	{
		if(!(val[i]&1))continue;
		if(val[1]&1)swap(val[i],val[m]);
		else swap(val[i],val[1]);
	}

	if(m==1)
	{
		ans.emplace_back(1);
		if(val[1]>1)ans.emplace_back(val[1]-1);
	}
	else
	{
		ans.emplace_back(val[1]+1);
		for(int i=2;i<m;i++)ans.emplace_back(val[i]);
		if(val[m]>1)ans.emplace_back(val[m]-1);
	}

	for(int i=1;i<=m;i++)printf("%d%c",val[i]," \n"[i==m]);
	printf("%lu\n",ans.size());
	for(auto i:ans)printf("%d ",i);
	puts("");

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

signed main(){
	int N,M;
	cin >> N >> M;
	vector<int>a(N);
	REP(i,N){
		cin >> a[i];
	}
	sort(ALL(a));
	reverse(ALL(a));
	int cnt = 0;
	int as = accumulate(ALL(a),0ll);
	REP(i,N){
		if(as <= 4 * M * a[i])++cnt;
	}
	if(cnt >= M)out("Yes");
	else out("No");
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
const int maxn=200000;
vector<int>eds[maxn],vv;
int n,x,y;
pair<int,int>go[maxn];
int ad[maxn],ans[maxn];
void dfs1(int v,int p,pair<int,int>ma)
{
    if(ma.second<v) ma.second=v;
    if(ma.second>ma.first) swap(ma.second,ma.first);
    go[v]=ma;
    for(int i=0;i<eds[v].size();i++)
    {
        int u=eds[v][i];
        if(u==p) continue;
        dfs1(u,v,ma);
    }
}
void dfs3(int v,int p,int cnt)
{
    cnt+=ad[v];
    ans[v]=cnt;
    for(int i=0;i<eds[v].size();i++)
    {
        int u=eds[v][i];
        if(u==p) continue;
        dfs3(u,v,cnt);
    }
}
void dfs2(int v,int p)
{
    vv.push_back(v);
    if(v==0) ad[0]++;
    else
    {
        int l=0;
        int r=vv.size()-1;
        while(r-l>1)
        {
            int m=l+r>>1,x=vv[m],f1=0;
            if(go[x].first!=x&&go[x].first==go[v].first
               ||go[x].first==x&&go[x]==go[v]) f1=1;
            if(f1) r=m;
            else l=m;
        }
        ad[vv[r]]++;
    }
    for(int i=0;i<eds[v].size();i++)
    {
        int u=eds[v][i];
        if(u==p) continue;
        dfs2(u,v);
    }
    vv.pop_back();
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        x--;y--;
        eds[x].push_back(y);
        eds[y].push_back(x);
    }
    dfs1(0,-1,make_pair(-1,-1));
    dfs2(0,-1);
    dfs3(0,-1,0);
    for(int i=1;i<n;i++)
        printf(i==n-1?"%d\n":"%d ",ans[i]-1);
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(b,a*n)<<endl;
    return 0;
}


Measured memory_bytes: 764
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, m, ans, dist, pos;
ii stu[55], ch[55];

int main(){
    ios::sync_with_stdio(0);
    cin >> n >> m;
    forn(i,n){
        cin >> stu[i].first >> stu[i].second;
    }
    forn(i,m){
        cin >> ch[i].first >> ch[i].second;
    }

    forn(i,n){
        ans = INF;
        pos = -1;
        forn(j,m){
            dist = abs(stu[i].first-ch[j].first) + abs(stu[i].second-ch[j].second);
            //cout << "DIST " << dist << " STU " << i+1 << " CH " << j+1 << "\n";
            if(dist < ans){
                ans = dist;
                pos = j+1;
            }
        }
        cout << pos << "\n";
    }
    return 0;
}

Measured memory_bytes: 3656
from bisect import*
N=int(input())
r=lambda:sorted(map(int, input().split()))
A,B,C,w=r(),r(),r(),[0]*(N+1)
for i in range(N-1,-1,-1):w[i]=w[i+1]+N-bisect(C,B[i])
print(sum(w[bisect(B,A[i])]for i in range(N)))

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

#define WHITE 0
#define BLACK 1

int main() {
    ll N, M;
    cin >> N >> M;
    set<ll> FriendShip[N];
    for (ll i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        FriendShip[a].insert(b);
        FriendShip[b].insert(a);
    }
    vector<ll> col(N, WHITE);
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (col[i] == BLACK) continue;
        ll friends = 1;
        queue<ll> Q;
        Q.push(i);
        col[i] = BLACK;
        while (!Q.empty()) {
            ll u = Q.front();
            Q.pop();
            for (ll v : FriendShip[u]) {
                if (col[v] == BLACK) continue;
                col[v] = BLACK;
                Q.push(v);
                friends++;
            }
        }
        ans = max(ans, friends);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 33476
#include<iostream>
using namespace std;
int n,k,ok;
int main (void) {
    cin >> n;
    ok = 0;
    while (true) {
        if (n < 7 && n != 0 && n != 4) {
            break;
        }
        if (n % 4 == 0) {
            cout << "Yes";
            ok = 1;
            break;
        }
        if (n < 7) {
            break;
        }
        n-=7;
    }
    if (ok == 0) {
        cout <<"No";
    }
    return 0;
}


Measured memory_bytes: 256
s = list(input())
n = len(s)
count = 0
maxcount = 0
for i in range(n):
  if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
    count += 1
    maxcount = max(maxcount,count)
  else:
    count = 0

print(maxcount)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  long long H;
  cin >> N >> H;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++) cin >> a.at(i) >> b.at(i);

  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());
  int i;
  for(i=0; i<N; i++){
    if(a[0] > b[i]){break;}
  }
  int j;
  for(j = 0; H > 0; j++){
    if(j < i) H = H - b[j];
    else H = H - a[0];
  }
  cout << j;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000000000
#define MOD 1000000007
#define N 500005
#define M 27000
#define LOG 21
#define KOK 650
#define EPS 0.00001
using namespace std;

vector<int> k2,k3,k6;
int n;

int main() {

//	freopen("input.txt","r",stdin);

//	freopen("curling.gir","r",stdin);
//	freopen("curling.cik","w",stdout);

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	for(int i=1;i<=30000;i++) {

		if(i%6==0) {

			k6.pb(i);

		}
		else if(i%3==0) {

			k3.pb(i);

		}
		else if(i%2==0) {

			k2.pb(i);

		}

	}

	cin>>n;

	if(n>=5) {

		int tot3=2,tot2=2;

		for(int i=0;i<tot3;i++) cout<<k3[i]<<" ";

		for(int i=0;i<tot2;i++) cout<<k2[i]<<" ";

		n-=tot3+tot2;
		
		while(n>sz(k6)) {

			if(tot3+2<sz(k3)) {

				for(int i=tot3;i<tot3+2;i++) cout<<k3[i]<<" ";

				tot3+=2;
				n-=2;

			}
			else if(tot2+2<sz(k2)) {

				for(int i=tot2;i<tot2+2;i++) cout<<k2[i]<<" ";

				tot2+=2;
				n-=2;

			}
			else {

				for(int i=tot3;i<sz(k3);i++) {cout<<k3[i]<<" ";n--;}

				for(int i=tot2;i<sz(k2);i++) {cout<<k2[i]<<" ";n--;}

			}

		}

		for(int i=0;i<n;i++) cout<<k6[i]<<" ";
	
	}
	else {

		if(n==3) {

			cout<<"2 5 63";

		}
		else {

			cout<<"2 5 20 63";

		}

	}

}



Measured memory_bytes: 512
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    vi v(5);
    for (int i = 0; i < 5; i++) {
        cin >> v[i];
    }

    vector<pair<int,int>> vp;
    for (int i = 0; i < 5; i++) {
        vp.push_back(make_pair( ((v[i]+9)/10) * 10 - v[i], v[i]));
    }


    sort(all(vp));
    // reverse(all(vp));
    int ans = vp[4].second;
    for (int i = 0; i < 4; i++) {
        ans += vp[i].first + vp[i].second;
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <vector>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MOD 1000000007

struct UnionFind {
	std::vector<int> data;
	UnionFind (int size) : data(size, -1) {}
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) {
			if (data[y] < data[x]) std::swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
	bool connected() { return size(0) == (int) data.size(); }
};

int main() {
	int h = ri();
	int w = ri();
	char s[h][w + 1];
	for (auto &i : s) scanf("%s", i);
	
	UnionFind uni(h / 2 + w / 2);
	int res = 1;
	for (int i = 0; i < h / 2; i++) for (int j = 0; j < w / 2; j++) {
		char tmp[4] = {s[i][j], s[h - 1 - i][j], s[i][w - 1 - j], s[h - 1 - i][w - 1 - j]};
		std::sort(tmp, tmp + 4);
		int cnt = 0;
		do cnt++; while (std::next_permutation(tmp, tmp + 4));
		res = (int64_t) res * std::min(12, cnt) % MOD;
		if (cnt == 24 && uni.unite(i, h / 2 + j)) res = res * 2 % MOD;
	}
	if (h & 1) {
		char tmp[w];
		memcpy(tmp, s[h / 2], sizeof(tmp));
		std::reverse(tmp, tmp + w);
		if (strncmp(tmp, s[h / 2], w)) res = res * 2 % MOD;
	}
	if (w & 1) {
		char tmp0[h], tmp1[h];
		for (int i = 0; i < h; i++) tmp0[i] = s[i][w / 2];
		std::reverse_copy(tmp0, tmp0 + h, tmp1);
		if (strncmp(tmp0, tmp1, h)) res = res * 2 % MOD;
	}
	printf("%d\n", res);
	return 0;
}


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

using namespace std;
int main(){
	string S;
	cin >> S;

	int N = 0;

	for (size_t i = 0; i < 4;i++){
		if(S[i]=='+'){
			N++;
		}else{
			N--;
		}
	}
	cout << N;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i= 0;i<n;i++)
#define REP(n) rep(i,n) 
#define all(n) n.begin(),n.end()

const int MAXDAY = 110;

int main()
{
    int n , q;
    while(cin >> n >> q && (n || q))
    {
        int m,  day, comb = 0, maxq = q - 1;
        int sc[MAXDAY]  = {};
        
        REP(n)
        {
            cin >> m;
            rep(j, m)
            {
                cin >> day;
                sc[day]++;
            }
        }
        REP(MAXDAY)if(sc[i] > maxq ){ maxq = sc[i]; comb = i;}

        cout << comb << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
// Vicfred
// https://atcoder.jp/contests/dp/tasks/dp_d
// dynamic programming
import std.algorithm;
import std.stdio;

void main() {
    int N, W;
    readf("%s %s\n", &N, &W);

    long[] dp = new long[W+1];

    long w, v;
    foreach(_; 0..N) {
        readf("%s %s\n", &w, &v);
        for(int i = W; i >= w; --i)
            dp[i] = max(dp[i], dp[i - w] + v);
    }

    dp[W].writeln;
}



Measured memory_bytes: 3364