akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<map>
#include<vector>
using namespace std;
const pair<int,int> no=make_pair(-1,2333333);
#define N 50050
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,T,x[N<<1],y[N<<1],col[N<<1];
void Output(){
	for(int i=1;i<=m;++i){
		putchar(col[i]?'^':'v');
	}
	putchar('\n');
}
namespace Task_1{
	bitset<N> to[N];
	int ok[N];
	void Find(int k){
		ok[x[k]]=ok[y[k]]=1;
		for(int i=k-1;i>=1;--i){
			if(!ok[x[i]]&&!ok[y[i]])continue;
			if(ok[x[i]])col[i]=1;
			ok[x[i]]=ok[y[i]]=1;
		}
	}
	void Solve(){
		for(int i=1;i<=n;++i){
			to[i][i]=1;
		}
		for(int i=1;i<=m;++i){
			to[x[i]]=to[y[i]]=to[x[i]]|to[y[i]];
			if((int)to[x[i]].count()==n){
				Find(i);
				Output();
				return;
			}
		}
		printf("-1\n");
	}
}
namespace Task_2{
	map<int,vector<pair<int,int> > > mp; 
	void Solve(){
		if(n==2){
			puts("-1");return;
		}
		for(int i=m;i>=1;--i){
			mp[x[i]].emplace_back(y[i],i);
			mp[y[i]].emplace_back(x[i],i);
		}
		int A=x[1],B=y[1]+1;
		if(B>n)A=x[1]-1,B=y[1];
		if(A<1)A=x[1]+1,B=y[1];
		for(int i=1;i<=m;++i){
			while(!mp[A].empty()&&mp[A].back().second<=i)mp[A].pop_back();
			while(!mp[B].empty()&&mp[B].back().second<=i)mp[B].pop_back();
			auto tA=mp[A].empty()?no:mp[A].back();
			auto tB=mp[B].empty()?no:mp[B].back();
			bool rev=(tA.second<tB.second&&tA.first==B)||(tA.second>=tB.second&&tB.first==A);
			if(x[i]==A||y[i]==A){
				col[i]=rev^(x[i]==A);
				if(rev)A=(x[i]==A)?y[i]:x[i];
			}
			else if(x[i]==B||y[i]==B){
				col[i]=rev^(x[i]==B);
				if(rev)B=(x[i]==B)?y[i]:x[i];	
			}
		}
		Output();
	}
}
int main(){
	n=read(),m=read(),T=read();
	for(int i=1;i<=m;++i){
		x[i]=read(),y[i]=read();
	}
	if(T==1){
		Task_1::Solve();
	}
	else{
		Task_2::Solve();
	}
	return 0;
}


Measured memory_bytes: 310684
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define fr first
#define sc second

using namespace std;


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

   int n , k; cin >> n >> k;
   set<int>st;
   for(int i = 0;i < k;i++){
    int d; cin >> d;
    while(d--){
        int x; cin >> x;
        st.insert(x);
    }
   }
   cout << n - st.size();

    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        int[][] hw = new int[h][w];
        int idx = 1;
        for (int i = 0; i < h; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < w; j++) {
                    while (a[idx] == 0) {
                        idx++;
                    }
                    hw[i][j] = idx;
                    a[idx]--;
                }
            } else {
                for (int j = w - 1; j >= 0; j--) {
                    while (a[idx] == 0) {
                        idx++;
                    }
                    hw[i][j] = idx;
                    a[idx]--;
                }
            }
        }

        for (int i = 0; i < h; i++) {
            StringJoiner sj = new StringJoiner(" ");
            for (int j = 0; j < w; j++) {
                sj.add(String.valueOf(hw[i][j]));
            }
            System.out.println(sj);
        }
    }

}


Measured memory_bytes: 31896
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, T, A;
	cin >> N >> T >> A;
	int H[N];
	for (int i = 0; i< N; i++) {
		cin >> H[i];
	}
	for (int i = 0; i < N; i++) {
		H[i] = (T - H[i] * 0.006)*1000;
		H[i] = abs(H[i] - A*1000);
	}
	int bans=H[0];
	int ans = 0;
	for (int i = 0; i < N; i++) {
		bans = min(bans, H[i]);
		if (bans ==H[i]) {
			ans = i + 1;
		}
	}
	cout << ans << endl;
	
}

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int max = 0;
  int now = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I'){
      now++;
    }
    else{
      now--;
    }
    if(now > max){
      max = now;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),Y = in()/1000,a = -1,b = -1,c = -1;
    REP(i,Y/10+1){
        REP(l,(Y - i*10)/5+1){
            if(10*i+5*l+N-i-l == Y){
                a = i;
                b = l;
                c = N-l-i;
            }
        }
    }
    cout << a << " " << b << " " <<c<<   "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;



public class Main{
    public static void main(String[] args){
        final Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a+b >= c)
          System.out.println("Yes");
        else
          System.out.println("No");
    }
}


Measured memory_bytes: 21844
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
import numpy as np

def main():
	N, K,*A = map(int, read().split())
	a = np.array(A,dtype=np.int64)
	ans = 0
	for i in range(50, -1, -1):
		s = np.sum((a >> i) & 1)
		#print((a >> i)&1)
		if N - s > s:
			ans += 1<<i
		if ans > K:
			ans -= 1<<i
		#print(ans)
	print(np.sum(ans ^ a))


if __name__ == "__main__":
	main()


Measured memory_bytes: 21516
import sys
from collections import deque
from itertools import product
input = sys.stdin.readline


def validate_pos(y, x, h, w):
    if y < 0 or y >= h or x < 0 or x >= w:
        return False
    else:
        return True


def main():
    h, w = map(int, input().split())
    sy, sx = map(int, input().split())
    gy, gx = map(int, input().split())
    field = [input().rstrip() for _ in range(h)]
    seen = set()
    todo = deque([(sy-1, sx-1)])
    tmp_visited = []

    shifts = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    warp_dist = [-2, -1, 0, 1, 2]
    warps = list(product(warp_dist, repeat=2))
    ans = 0
    while True:
        while todo:
            y, x = todo.popleft()
            tmp_visited.append((y, x))

            for dy, dx in shifts:
                ny, nx = y+dy, x+dx
                if not validate_pos(ny, nx, h, w):
                    continue
                if ny == gy-1 and nx == gx-1:
                    print(ans)
                    return
                if field[ny][nx] == "#":
                    continue
                if (ny, nx) in seen:
                    continue
                todo.append((ny, nx))
                seen.add((ny, nx))
                tmp_visited.append((ny, nx))

        ans += 1
        if not tmp_visited:
            print(-1)
            return

        for y, x in tmp_visited:
            for dy, dx in warps:
                ny, nx = y+dy, x+dx
                if not validate_pos(ny, nx, h, w):
                    continue
                if field[ny][nx] == "#":
                    continue
                if ny == gy-1 and nx == gx-1:
                    print(ans)
                    return
                if (ny, nx) in seen:
                    continue
                todo.append((ny, nx))
                seen.add((ny, nx))

        tmp_visited = []


if __name__ == "__main__":
    main()


Measured memory_bytes: 160396
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int a[maxn];
int b[maxn];
int st[maxn];
int main(){
	int i,j,k,m,n;
	cin>>n;
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=n;i>=1;i--){
		int x=i;b[i]=a[i];
		while(x<=n){
			x+=i;
			b[i]^=b[x];
		}
	}
	int ans=0;
	for(i=1;i<=n;i++){
		if(b[i]){
			st[++ans]=i;
		}
	}
	printf("%d\n",ans);
	for(i=1;i<=ans;i++){
		printf("%d ",st[i]);
	}
	return 0;
}

Measured memory_bytes: 9728
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
if min(a,b,c,d,e)==1:
    print(n//(min(a,b,c,d,e))+4)
else:
    print(n//(min(a,b,c,d,e))+5)

Measured memory_bytes: 61872
def solve(k):
    x = 7
    checked = set()
    ans = 1
    while True:
        x %= k
        if x == 0:
            return ans
        if x in checked:
            return -1
        checked.add(x)
        x = x * 10 + 7
        ans += 1


k = int(input())
print(solve(k))


Measured memory_bytes: 77876
def solve():
    import sys
    n, k = map(int, input().split())
    ws = tuple(map(int, sys.stdin))

    ok, ng = sum(ws), max(ws)-1

    while ok-ng > 1:
        mid = (ok+ng+1)//2
        current = 0
        count = 0
        for w in ws:
            if current + w > mid:
                current = w
                count += 1
            else:
                current += w
        if count < k:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 9580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) (ret*=x)%=mod;
        (x*=x)%=mod;
        n>>=1;
    }
    return ret;
}

ll mod_inv(ll x){
    return mod_pow(x,mod-2);
}

// void test(int n){

//     vector<int> p(n-1);
//     rep(i,n-1) p[i] = i;

//     vector<ll> ct(n-1);
//     do{

//         vector<bool> alive(n,true);
//         rep(i,n-1){
//             int t = p[i];
//             alive[t] = false;
//             while(!alive[t]){
//                 ++ct[t];
//                 ++t;
//             }

//         }

//     }while(next_permutation(all(p)));

//     dbg(ct);
// }

const int N = 100010;
ll f[N];

int main(){
    f[0] = 1;
    for(int i=1;i<N;++i) f[i] = (f[i-1])*i%mod;

    int n;
    cin >>n;

    vector<ll> x(n);
    rep(i,n) cin >>x[i];

    vector<ll> a(n-1);
    a[0] = f[n-1];

    ll pre = 1;
    for(int i=1; i<n-1; ++i){
        ll t = pre*(i+1)%mod;
        (t += f[i]) %= mod;

        pre = t;

        a[i] = pre*f[n-1]%mod;
        (a[i] *= mod_inv(f[i+1])) %= mod;
    }

    ll ans = 0;
    rep(i,n-1){
        ll d = x[i+1]-x[i];
        ans += (a[i]*d)%mod;
        ans %= mod;
    }

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


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N, M, A, B, C;
    string str1, str2;
    cin >> N;
    vector<ll> a(N);
    ll ans = 1;
    rep(i, N){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, N){
        ll ta = ans;
        ans *= a[i];
        if(ans > 1000000000000000000 || ta > ans){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long n;
	cin>>n;
	long a[n] = {0};
	for(long i=0;i<n;i++){
		cin>>a[i];
	}
	long long op=0;
	for(long i=0;i<n;i++){	
		while(!(a[i]&1)){
			a[i]/=2;
			op++;
		}
	}
	cout<<op;
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();

        for(int i=0; i<10; i++) {
            x = r * x - d;
            System.out.println(x);
        }

    }


}


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

int main()
{
	int x;
	cin >> x;
	int d = x / 500;
	int sum = 0;
	sum += d * 1000;
	x -= 500 * d;
	d = x / 5;
	sum += d * 5;
	cout << sum << "\n";

	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<Edge, int> P;

int dijkstra2(const Graph &g, int c, int s, int t) {
  int n = g.size();
  vector<Weight> dist[c+1];
  REP(i,c+1)
    dist[i].assign(n, INF);
  dist[c][s] = 0;
  priority_queue<P> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(P(Edge(-2, s, 0),c)); !Q.empty(); ) {
    Edge e = Q.top().first;
    int cc = Q.top().second;
    Q.pop();
    FOR(f,g[e.dst]) {
      if (dist[cc][f->dst] > e.weight+f->weight) {
        dist[cc][f->dst] = e.weight+f->weight;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight),cc));
      }
      if (cc > 0 && dist[cc-1][f->dst] > e.weight+f->weight/2) {
        dist[cc-1][f->dst] = e.weight+f->weight/2;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight/2),cc-1));
      }      
    }
  }
  int res = INF;
  REP(i,c+1) {
    res = min(dist[i][t], res);
  }
  return res;
}

int main() {
  int c,n,m,s,d;
  while(cin>>c>>n>>m>>s>>d,c) {
    s--;d--;
    Graph g(n);
    REP(i,m) {
      int a,b,f;
      cin >> a >> b >> f;
      a--;b--;
      g[a].push_back(Edge(a,b,f));
      g[b].push_back(Edge(b,a,f));
    }
    cout << dijkstra2(g,c,s,d) << endl;
  }
}

Measured memory_bytes: 0
N,M = map(int,input().split())

# dp[j] 箱の開封状態jのときの使用したお金の最小値

INF = 10**3 * 10**5 + 1
dp = [INF for _ in range(1<<N)]
dp[0] = 0

for i in range(M):
    ai, bi = map(int,input().split())
    cib = list(map(int,input().split()))
    bits = 0
    for ci in cib:
        bits |= 1 << (ci-1)
    for j in range(1<<N):
        dp[j|bits] = min(dp[j|bits], dp[j]+ai)

allbits = 0
for _ in range(N):
    allbits = 1 | allbits << 1
print(dp[allbits] if dp[allbits] != INF else -1)


Measured memory_bytes: 47448
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;

  X -= Z;
  cout << X / (Y + Z) << endl;

  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;
	cin >> n;
	string s;
	vector<vector<int>> l(1000, vector<int>(0));
	vector<vector<int>> r(1000, vector<int>(0));
	rep(ii, n){
		cin >> s;
		int a = 0;
		int b = 0;
		int am = 0;
		int bm = 0;
		int sn = s.size();
		rep(i, sn){
			if(s.at(i) == ')'){
				a++;
			}else{
				a--;
			}
			if(s.at(sn-1-i) == '('){
				b++;
			}else{
				b--;
			}
			if(a > am) am = a;
			if(b > bm) bm = b;
		}
		if(bm - am > 0){
			l.at(am).push_back(bm);
		}else{
			r.at(bm).push_back(am);
		}
	}
	rep(i, 1000){
		sort(l.at(i).begin(), l.at(i).end());
		reverse(l.at(i).begin(), l.at(i).end());
	}
	rep(i, 1000){
		sort(r.at(i).begin(), r.at(i).end());
		reverse(r.at(i).begin(), r.at(i).end());
	}
	int suml = 0;
	int sumr = 0;
	int fl = 0;
	int fr = 0;
	rep(i, 1000){
		rep(j, l.at(i).size()){
			suml -= i;
			if(suml < 0){
				fl = 1;
				break;
			}
			suml += l.at(i).at(j);
		}
		if(fl == 1) break;
	}
	rep(i, 1000){
		rep(j, r.at(i).size()){
			sumr -= i;
			if(sumr < 0){
				fr = 1;
				break;
			}
			sumr += r.at(i).at(j);
		}
		if(fr == 1) break;
	}
	if(fl == 1 || fr == 1 || suml != sumr){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 200 * 1000 + 13;

int n;
int a[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n){
		scanf("%d", &a[i]);
		--a[i];
	}
	return true;
}

int add(int a, int b){
	a += b;
	if (a >= MOD) a-= MOD;
	return a;
}

int sum[N];
int dp[N];

void solve(){
	n = unique(a, a + n) - a;
	memset(dp, 0, sizeof(dp));
	memset(sum, 0, sizeof(sum));
	
	sum[a[0]] = 1;
	forn(i, n){
		dp[i] = sum[a[i]];
		if (i < n - 1)
			sum[a[i + 1]] = add(sum[a[i + 1]], dp[i]);
	}
	
	printf("%d\n", dp[n - 1]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 2560
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, M[N][N];
int color[N], d[N], f[N], tt;
void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for ( v = 0; v < n; v++) {
        if (M[u][v] == 0 ) continue;
        if (color[v] == WHITE ) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}
void dfs() {
    int u;
    for ( u = 0; u < n; u++) {
        if ( color[u] == WHITE ) dfs_visit(u);
    }
    for (u = 0; u < n; u++) {
        printf("%d %d %d\n", u + 1, d[u], f[u]);
    }
}
int main() {
    int u, v, k, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) M[i][j] = 0;
    }
    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for ( j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}


Measured memory_bytes: 2104
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

//main
int main(){
  int N,X;
  cin >> N >> X;
  vector<int> L(N);
  vector<int> ans(N+1);
  int c=0;
  rep(i,N) cin >> L[i];
  ans[0] = 0;
  rep(i,N) ans[i+1] = ans[i]+L[i];
  rep(i,N+1) if(ans[i]<=X)  c += 1;
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double INF = 1e9;

ll a,b,c,d,e,f;

int main(){
    cin >> a >> b >> c >> d >> e >> f;
    //step1
    vector<bool>water(3010,false);
    for(int i=0;i*100*a<=f;i++){
        for(int j=0;j*100*b<=f;j++){
            if(i*100+j*100>f)continue;
            water[i*a*100+j*b*100]=true;
        }
    }
    vector<bool>sugar(3010,false);
    for(int i=0;i*c<=f;i++){
        for(int j=0;j*d<=f;j++){
            if(i*c+j*d>f)continue;
            sugar[i*c+j*d]=true;
        }
    }

    //step2
    double M = -1;
    P ans = {-1,-1};
    for(int i=1;i<=f;i++){
        for(int j=0;j<=f;j++){
            if(!water[i])continue;
            if(!sugar[j])continue;
            if(i+j>f)continue;
            if((100+e)*(100*j)>100*e*(i+j))continue;
            double now = 100.0*j;
            now = now/(i+j);
            if(chmax(M,now)){
                ans.first=i+j;
                ans.second=j;
            }
        }
    }
    cout << ans.first << ' ' << ans.second << endl;
    return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> n;
    string s;
    cin >> s;
    vi d(n);
    int sum = 0;
    REP(i, n) {
        d[i] += sum;
        if (s[i] == 'W') sum ++;
    }
    sum = 0;
    RREP(i, n) {
        d[i] += sum;
        if (s[i] == 'E') sum ++;
    }
    cout << *min_element(ALL(d)) << endl;
    return 0;
}


Measured memory_bytes: 1812
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>

using namespace std;
using lli = long long int;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b) {
		swap(a, b);
	}
	if (a <= c && c <= b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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




int main(){
#ifdef debug
    freopen("a.in", "r", stdin);
#endif
    long long n, k;
    cin>>n>>k;
    map<int, long long> mp;
    while(n--){
        int a, b;
        cin>>a>>b;
        mp[a]+=b;
    }
    for(auto it=mp.begin(); it!=mp.end(); ++it){
        long long a=it->first, b=it->second;
        if(k>b){
            k-=b;
        }
        else{
            cout<<a<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    char c[3][3];
    for (auto i = 0u; i < 3; ++i) {
        scanf("%s", c[i]);
    }
    for (auto i = 0u; i < 3; ++i) {
        cout << c[i][i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
using i64 = long long;
using namespace std;

const int maxn = 1e5;
i64 h[maxn], dp[maxn];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> h[i];
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = 2e9;
    for (int j = 1; j <= min(i, k); j++) {
      dp[i] = min(
        dp[i],
        dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[n - 1] << '\n';
}

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

int main() {
  long n, ans = 0;

  cin >> n;

  vector<int> a(n), b(n), c(n);

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

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

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

  sort(a.begin(), a.end());
  sort(c.begin(), c.end());

  for (int i = 0; i < n; i++) {
    auto aidx = lower_bound(a.begin(), a.end(), b[i]);
    auto cidx = upper_bound(c.begin(), c.end(), b[i]);
    long apos = distance(a.begin(), aidx);
    long cpos = n - distance(c.begin(), cidx);
    ans += apos * cpos;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 1408
program ABC172B
    implicit none
    integer(8)::i,ans=0
    character(200000)::S,T
    read*,S,T
    do i=1,len_trim(S)
        if(S(i:i)/=T(i:i))ans=ans+1
    end do
    print'(i0)',ans
end program ABC172B

Measured memory_bytes: 3472
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

int main()
{
	int a, b;

	cin >> a >> b;

	string s;
	cin >> s;

	s.at(b - 1) += 32;
	cout << s << endl;
}

Measured memory_bytes: 764
import math
import itertools
import numpy as np
N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
d=np.zeros((N,N))
for i in range(N-1):
    for j in range(i+1,N):
        dd=math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
        d[i,j]=dd
        d[j,i]=dd
ans=[]
path=list(itertools.permutations(range(N)))
for p in path:
    s=0
    for i in range(N-1):
        s+=d[p[i],p[i+1]]
    ans.append(s)
print(sum(ans)/len(ans))

Measured memory_bytes: 18288
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int N = 1e5+9;

int b[N];

void update(int l,int r){
    for(;l<N;l += l&-l){
        b[l]++;
    }
    r++;
    for(;r<N;r += r&-r){
        b[r]--;
    }
}

int soma(int i){
    int ans=0;
    for(;i>0;i -= i&-i) ans+=b[i];
    return ans;
}

signed main(){
    IOS;
    int n,m; cin >> n >> m;
    vector<pair<int,ii> > v;
    rep(i,0,n){
        int x,y; cin >> x >> y;
        v.pb(mp(y-x+1,ii(x,y)));
    }
    sort(all(v));
    int cur = 0;
    rep(i,1,m+1){
        if(cur<sz(v)){
            while(v[cur].F < i){
                int l = v[cur].S.F, r = v[cur].S.S;
                update(l,r);
                cur++;
                if(cur==sz(v)) break;
            }
        }
        int k = 0;
        for(int j = i;j<=m;j+=i){
            k+=soma(j);
        }
        cout << k + n - cur << "\n";
    }
}

Measured memory_bytes: 14572
n = int(input())
s = list(map(int, input().split()))
count = 0
sidx = 0
def div(l, ls):
    tmpl = []
    for i in l:
        if i == 0:
            if len(tmpl) != 0:
                ls.append(tmpl)
            tmpl = []
        else:
            tmpl.append(i)
    else:
        if len(tmpl) != 0:
            ls.append(tmpl)
    return ls

ls = [s]
count = 0
while len(ls) != 0:
    l = ls.pop()
    mins = min(l)
    for i in range(len(l)):
        l[i] -= mins
    count += mins
    div(l, ls)

print(count)

Measured memory_bytes: 3064
teams = dict()
while 1:
    a, b = map(int, raw_input().split(','))
    if a == b == 0:
        break
    teams[a] = b
cur = 1 << 30
cur_rank = 0
ret = dict()
for k, v in sorted(teams.items(), key=lambda a: a[1], reverse=True):
    if v < cur:
        cur_rank += 1
        cur = v
    ret[k] = cur_rank

while 1:
    try:
        query = input()
        print ret[query]
    except EOFError:
        break

Measured memory_bytes: 4236
n, d   = gets.split.map(&:to_i) # n個の点、d次元空間
points = []
n.times { points << gets.split.map(&:to_i) }
ans = 0
(0 .. n - 1).each do |i| # i番目の点
  (0 .. n - 1).each do |j| # j番目の点
    next if i >= j
    sq = 0
    (0 .. d - 1).each do |k| # k番目の次元
      s  = (points[i][k] - points[j][k]) #対応する座標の差
      sq += s * s # 差の自乗を合計 
    end
    s   = Math.sqrt(sq) + 0.5 # 自乗の合計の平方根を整数化
    ans += 1 if s.to_i ** 2 == sq # 整数化の自乗が差の合計になればok 
  end
end
p ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    ll N,D; cin >> N >> D;
    int ans = 0;
    REP(i,N) {
        ll x,y;
        cin >> x >> y;
        if(x*x + y*y <= D*D) ans++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	char op;
	while(1){
	cin>>a>>op>>b;
	if(op=='+') {c=a+b; cout<<c<<endl;}
	if(op=='-') {c=a-b; cout<<c<<endl;}
	if(op=='*') {c=a*b; cout<<c<<endl;}
	if(op=='/') {c=a/b*1.0; cout<<c<<endl;}
	if(op=='?') break;
	}
	return 0;
	}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    string N; cin >> N;
    bool ok = false;
    REP(i,3){
        if(N[i] == '7') ok = true;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

}


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

using int64 = long long;

const int MAX_N = 1000;
const int64 INF = (1LL << 50);

int64 x[MAX_N], y[MAX_N], z[MAX_N];

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

    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }

    int64 ans = -INF;
    // x, y, z をそれぞれ+方向に持っていくか, -方向に持っていくか
    for (int mask = 0; mask < (1 << 3); mask++) {
        static int64 score[MAX_N];

        int signs[2] = {1, -1},
            xsign = signs[(mask >> 0) & 1],
            ysign = signs[(mask >> 1) & 1],
            zsign = signs[(mask >> 2) & 1];

        for (int i = 0; i < N; i++) {
            score[i] = xsign * x[i] + ysign * y[i] + zsign * z[i];
        }
        sort(score, score + N, greater<int64>());

        int64 sum = 0;
        for (int i = 0; i < M; i++) {
            sum += score[i];
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}


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

int main(){

  int n;
  cin>>n;
  int i=1;
  while(1){
    if(i*2>n){
      break;
    }else{
      i *= 2;
    }
  }
  cout<<i<<endl;

  return 0;
}


Measured memory_bytes: 256
public class Main {

  private static void solve() {
    int n = ni();
    int h = ni();
    int d = ni();
    int mod = (int) 1e9 + 7;

    long[] dp = new long[h + 1];
    dp[0] = 1;

    long fs = 0;
    long f = 1;
    for (int i = 1; i <= n; i++) {
      f = f * i % mod;
      fs = (fs + f) % mod;
    }

    long sum = 0;
    for (int i = 1; i <= h; i++) {
      sum += dp[i - 1];
      sum %= mod;
      dp[i] = sum;

      if (i >= d) {
        sum += mod - dp[i - d];
        sum %= mod;
      }

      // min -> m
      dp[i] *= fs;
      dp[i] %= mod;
    }

    long ret = 0;
    for (int i = 1; i <= d; i++) {
      ret += dp[h - i];
      ret %= mod;
    }
    System.out.println(ret * f % mod);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 44644
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define MAX 100000
#define INF 1000000000
using ll=long long;

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> L(K),R(K);
  for(int i=0;i<K;i++){
    cin>>L[i]>>R[i];
  }
  vector<ll> cnt(N,0);
  vector<ll> sum(N+1,0);
  cnt[0]=1;
  sum[0]=0;
  sum[1]=1;
  for(int i=1;i<N;i++){
    for(int j=0;j<K;j++){
      if(i-L[j]<0){
        continue;
      }
      cnt[i]+=sum[i-L[j]+1]-sum[max(i-R[j],0)]+MOD;
    }
    cnt[i]%=MOD;
    sum[i+1]=sum[i]+cnt[i];
    sum[i+1]%=MOD;
  }
  cout<<cnt[N-1]<<endl;
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
	int N;
	cin >> N;
	vi p(N);
	REP(i,N) cin >> p[i];

	vector<bool> a(N+1,false);
	REP(i,N){
		if(p[i]==i+1) a[i] = true;
	}
	int count=0;
	REP(i,N){
		if(a[i]&&a[i+1]){
			count ++;
			i++;
		}
		else if(a[i]){
			count ++;
		}
	}

	cout << count << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    vi perm(n);
    iota(perm.begin(), perm.end(), 0);
    int cnt = 0;
    double ans = 0;
    do {
        double now = 0;
        for (int i = 1; i < n; ++i) {
            now += hypot(x[perm[i]] - x[perm[i-1]], y[perm[i]] - y[perm[i-1]]);
        }
        ans += now;
        cnt++;
    } while (next_permutation(perm.begin(), perm.end()));

    ans /= cnt;
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	string s, t;
	cin >> s >> t;
	int ss = s.size(), ts = t.size();
	vector<int> pos;
	if (ss < ts) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for (int i = 0; i <= ss - ts; ++i) {
		bool ok = true;
		rep(j, ts) {
			if (s[i + j] != t[j] && s[i + j] != '?') {
				ok = false;
				break;
			}
		}
		if (ok)	pos.push_back(i);
	}
	if (pos.size() == 0) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for (int i = pos.back(); i < pos.back() + ts; ++i) {
		s[i] = t[i - pos.back()];
	}
	rep(i, ss) {
		if (s[i] == '?')	s[i] = 'a';
	}
	cout << s << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define f first
#define s second

ll N;
ll bit[100];

int main(){

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

cin>>N;

if(N==0){
	cout<<0<<endl;
	return 0;
}

ll k=0;
while(1){
	if(N>0){
		if(N%2==0){
			bit[k]=0; k++;
			N=N/-2;
		}else{
			bit[k]=1; k++;
			N=-(N/2);
		}
	}
	else if(N<0){
		if(abs(N)%2==0){
			bit[k]=0; k++;
			N=N/-2;
		}else{
			bit[k]=1; k++;
			N=abs(N)/2+1;
		}
	}else if(N==0){
		break;
	}
}

rep(i,k){
	cout<<bit[k-i-1];
	if(k-i-1==0) cout<<endl;
}

}
	


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[101]={},b;
	while(cin>>b){
		if(b==0)break;
		a[b]++;
	}
	b=0;
	for(int i=1;i<=100;i++){
		if(b<a[i]){
			b=a[i];
		}
	}
	for(int i=1;i<=100;i++){
		if(b==a[i]){
			cout<<i<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n,int k) {
	//nのk桁目
	rep(i, k-1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int A, B,ans=0;
	cin >> A >> B;
	rep(i, B - A + 1) {
		if (DIGIT(A+i,1)==DIGIT(A+i,5)&&DIGIT(A+i,2)==DIGIT(A+i,4))
			ans++;
	}
	cout << ans;
}

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

using namespace std;

#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define rep(i, n) REP(i, 0, n)

int main(){
    int n,m;
    vector< pair<int, int> > v;
    while(cin>>n>>m, n+m) {
        v.clear();
        rep(_, n) {int d, p; cin >> d >> p; v.push_back({p, d});}
        sort(v.begin(), v.end(), greater< pair<int, int> >());
        int ans = 0;
        rep(i, n) ans += v[i].first * v[i].second;
        rep(i, n) {
            if (m > v[i].second) {
                m -= v[i].second;
                ans -= v[i].first * v[i].second;
            } else {
                ans -= m * v[i].first;
                break;
            }
        }
        cout << ans << endl;
    }
}
/*
2 8 5 6 4 5 0 0
 */


Measured memory_bytes: 3216