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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
// clang-format on

using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;

int N, M;
VI adj[101010];
LL dp[101010];
LL ans[101010];

void dfs1(int u, int p = 0) {
    dp[u] = 1;
    for (auto v: adj[u]) {
        if (v == p) continue;
        dfs1(v, u);
        dp[u] *= dp[v] + 1;
        dp[u] %= M;
    }
}

void dfs2(int u, int p = 0) {
    ans[u] = 1;
    for (auto v : adj[u])
        ans[u] = ans[u] * (dp[v] + 1) % M;

    int n = adj[u].size();
    VLL left(n), right(n);
    forn(i, 0, n) left[i] = right[i] = dp[adj[u][i]] + 1;
    forn(i, 1, n) left[i] = left[i] * left[i-1] % M;
    for (int i = n - 2; i >= 0; i--)
        right[i] = right[i] * right[i+1] % M;

    forn(i, 0, n) {
        int v = adj[u][i];
        if (v == p) continue;
        dp[u] = 1;
        if (i) dp[u] = dp[u] * left[i-1] % M;
        if (i < n - 1) dp[u] = dp[u] * right[i+1] % M;
        dfs2(v, u);
    }
}

int main() {
    IOS;

    cin >> N >> M;
    int x, y;
    forn(i, 0, N - 1) {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    dfs1(1);
    dfs2(1);

    for (int i = 1; i <= N; i++)
        cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 21924
import java.util.Scanner;

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

        double[] p = new double[n];

        for(int i = 0; i < n; i++){
            p[i] = sc.nextDouble();
        }

        int T = 0;
        int H = 1;
        double[][] a = new double[n][n+1];

        a[0][0] = 1 - p[0];
        a[0][1] = p[0];

        for(int i = 1; i < n; i++){
            for(int j = 0; j <= i+1; j++){
                if(j != 0)
                a[i][j] = p[i]*(a[i-1][j-1]);
                a[i][j] += (1-p[i])*(a[i-1][j]);
            }
        }

        double ans = 0;

        for(int i = (int) Math.ceil(n/2.0); i <= n; i++){
            ans += a[n-1][i];
        }

        System.out.println(ans);
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

typedef ll V;
const V INF_V = INT_MAX;
const int ME = 17;
const int N = 1<<ME;
class RMQ_segtree{
public:
    V dat[2*N-1];
    RMQ_segtree(){
        REP(i, 2*N - 1) dat[i] = INF_V;
    }

    void update(int k, V a){
        //k?????????????´????a????????´
        k += N-1;
        dat[k] = a;
        while(k>0){
            k = (k-1)/2;
            dat[k] = min(dat[2*k+1], dat[2*k+2]);
        }
    }

    V recursion(int a, int b, int k, int l, int r){
        //????°?????¨??????¨????????°??¢??°
        if(r<=a || b<=l) return INF_V;
        if(a<=l && r<=b) return dat[k];
        else{
            V vl = recursion(a, b, 2*k+1, l, (l+r)/2);
            V vr = recursion(a, b, 2*k+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }

    V minimum(int a, int b){
        //??????[a, b)???????°????
        return recursion(a, b, 0, 0, N);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    RMQ_segtree rmq;
    REP(i, q){
        int com, x, y;
        cin >> com >> x >> y;
        if(com==0){
            rmq.update(x, y);
        }else{
            cout << rmq.minimum(x, y+1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5152
;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(defvar s-str (read-line))
(defvar t-str (read-line))

(defvar s-len (length s-str))

(format t "~:[No~;Yes~]" (string= s-str t-str :start1 0 :end1 s-len
				  :start2 0 :end2 s-len))


Measured memory_bytes: 23648
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
x = 2
res = 0
if N == 1: 
  print(M)
  exit(0)
while x * x <= M:
  if M % x == 0:
    if M // x >= N: res = max(res, x)
    y = M // x
    if M // y >= N: res = max(res, y)
  x += 1
if res == 0: print(1)
else: print(res)

Measured memory_bytes: 38640
def main():
    from heapq import heapify,heappop,heappush

    n,m=map(int,input().split())
    W=[list(map(int,input().split())) for _ in range(n)]
    W.sort(key=lambda x:x[0])
    
    q=[]
    heapify(q)
    j,income=0,0
    for i in range(1,m+1):
        while j<n and W[j][0]<=i:
            heappush(q,-W[j][1])
            j+=1

        if q:
            t=heappop(q)
            income+=-t
    print(income) 

if __name__=='__main__':
    main()

Measured memory_bytes: 31924
def within(low, mid1, mid2, high):
    return low <= mid1 and mid2 <= high


W, H, x, y, r = map(int, input().split())

left = x - r
right = x + r
top = y + r
bottom = y - r

if within(0, left, right, W) and within(0, bottom, top, H):
    print('Yes')
else :
    print('No')


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

using vi = vector<int>;
using vvi = vector<vi>;

int H;
int W;
vvi g;

int erase(vvi &g) {
    int res = 0;
    for (size_t j = 0; j < W; j++) {
        for (size_t i = 0; i < H; i++) {
            if (g[i][j] == 0 || g[i][j] == -1) continue;
            int k = i + 1;
            while (k < H && g[i][j] == g[k][j]) {
                ++k;
            }
            int d = k - i;
            if (d >= 3) {
                for (int l = i; l < k; ++l) {
                    res += g[l][j];
                    g[l][j] = -1;
                }
            }
        }
    }
    for (size_t i = 0; i < H; i++) {
        auto &row = g[i];
        auto it = remove(row.begin(), row.end(), -1);
        row.erase(it, row.end());
        while (row.size() < W) {
            row.push_back(0);
        }
    }
    return res;
}

int main() {
    while (cin >> H && H) {
        W = 5;
        g.assign(W, vi(H));
        for (size_t i = 0; i < H; i++) {
            for (size_t j = 0; j < W; j++) {
                cin >> g[j][i];
            }
        }
        swap(H, W);
        for (size_t i = 0; i < H; i++) {
            reverse(g[i].begin(), g[i].end());
        }
        int ans = 0;
        while (1) {
            int add = erase(g);

            //for (size_t i = 0; i < H; i++) {
            //    for (size_t j = 0; j < W; j++) {
            //        cout << g[i][j];
            //    }
            //    cout << endl;
            //}
            //cout << endl;


            if (add == 0) break;
            ans += add;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 300001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }


int arr[100001][2];
bool dp[100001][2];
int N;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N;  for(int i = 0; i < N; i++) cin >> arr[i][0];
    for(int i = 0; i < N; i++) arr[i][1] = arr[i][0] - 1;
    
    dp[0][0] = dp[0][1] = true;
    
    for(int i = 0; i < N - 1; i++)
    {
        
        if(i == 2)
        {
     //       cout << "debug" << endl;
        }
        for(int j = 0; j < 2; j++)
        {
            for(int k = 0; k < 2; k++)
            {
                if(arr[i][j] <= arr[i+1][k] && dp[i][j])
                    dp[i+1][k] = dp[i][j];
            }
        }
    }
    
    
    if(dp[N-1][0] || dp[N-1][1])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
  
    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
#define N 1000000

//"all" is the table of the answers for all pollock numbers
//"odd" is the table of the answers for odd pollock numbers
int all[N+1],odd[N+1];
int pollock[1000],num;

int BackTrack(int n,int type){
  int i,tmp,ans = N+1;
  //if n is already searched, return answer on table
  if(type && odd[n]<=N)return odd[n];
  if(!type && all[n]<=N)return all[n];

  for(i=num-1;i>0;i--){
    if(pollock[i]>n)continue;
    if(type && !(pollock[i]&1) )continue;
    tmp = BackTrack(n-pollock[i],type);
    if(ans > tmp+1)ans = tmp+1;
  }

  //memorize n-th answer
  if(type)odd[n] = ans;
  else all[n] = ans;
  return ans;
}

int main(void){
  int i,n,tmp;

  //initialize table (filling SUP)
  for(i=0;i<=N;i++)all[i] = odd[i] = N+1;
  all[0] = odd[0] = 0;

  for(num=1;;num++){
    tmp = num*(num+1)*(num+2)/6;
    if(tmp>N)break;
    pollock[num] = tmp;
  }

  while(scanf("%d",&n) && n){
    printf("%d %d\n",BackTrack(n,0),BackTrack(n,1));
  }
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  for (auto &v : vec)
    cin >> v;

  ll vmax = 0;
  ll ans = 0;
  for (auto &v : vec) {
    if (v < vmax)
      ans += vmax - v;
    else
      vmax = v;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4836
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << "1" << endl;
	}
	else if(a == b || b == c || c == a) {
		cout << "2" << endl; 
	}
	else {
		cout << "3" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n] = {0};

    for (int i = 0; i < k; i++)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int tmp;
            cin >> tmp;
            a[tmp - 1]++;
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == 0)
            count++;
    }

    cout << count;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}
const int D = 60;
int to[D][MX];

signed main(){
    string s;
    string n;
    cin >> n;
    cout << "ABC"+n << endl;


}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();// ???????????????
        String p = sc.next();// ????????????
         
        s += s;
        if(s.indexOf(p)!=-1) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 26004
def oprd(t0, t1, p)
  x0 = t1[0] - t0[0]
  y0 = t1[1] - t0[1]
  x1 = p[0] - t0[0]
  y1 = p[1] - t0[1]
  x0 * y1 - x1 * y0
end

def inside?(tps, pt)
  d0 = oprd(tps[0, 2], tps[2, 2], pt)
  d1 = oprd(tps[2, 2], tps[4, 2], pt)
  d2 = oprd(tps[4, 2], tps[0, 2], pt)

  (d0 > 0 && d1 > 0 && d2 > 0) ||(d0 < 0 && d1 < 0 && d2 < 0)
end

### main

n = gets.strip.to_i

n.times.each do
  tps = gets.strip.split(' ').map{|s| s.to_i}

  ap = tps[6, 2]
  bp = tps[8, 2]
  tps = tps[0, 6]

  a_in = inside?(tps, ap)
  b_in = inside?(tps, bp)

  puts (a_in && ! b_in || ! a_in && b_in) ? "OK" : "NG"
end

Measured memory_bytes: 6128
import sys

input = sys.stdin.readline

N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

# 各曜日時間帯に開くか開かないかは2**10=1024通りしかないので
# O(N*2**10) = O(10**5)で間に合う
# 長さ10の配列に0 or 1を格納するbit全探索を行う。
# F[i][j]: 店i, jは曜日と時間帯を表す0~9

n = 10
max_profit = - float("inf")
for bit in range(1, 1<<n):  # 2**10まで2進数で(1つ以上の時間帯で営業しないといけないから000000000を除くため、1スタート)
    profit = 0
    for i in range(N):  # 店の数
        count = 0
        for j in range(n):  # bit（10桁）のどこに1があるか調べる
            if F[i][j] == 1:
                if (bit>>j) & 1:  # 右シフトしたbitの最後の桁が1ならTrue
                    # 10回シフトして最後の桁が1か調べる == bitのj桁目に1があればTrue
                    count += 1
        profit += P[i][count]
    max_profit = max(max_profit, profit)

print(max_profit)





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

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

    int N;
    cin >> N;
    int p = (N + 1) / 2;
    double ret = (double) p / (double) N;
    cout << fixed << setprecision(10) << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int x, y, tem;
  while(1){
    scanf("%d %d", &x, &y);
    if(x==0 && y==0){
      break;
    }
    else if(x>y){
    printf("%d %d\n",y,x);
    }
    else if(x<=y){
      printf("%d %d\n",x,y);
    }
  }
  return 0;
}



Measured memory_bytes: 1920
fun main(args: Array<String>) {
    abc139b()
}

fun abc139b() {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }

    var answer = 0
    var outlet = 1
    while (outlet < b) {
        outlet += a - 1
        answer++
    }

    println(answer)
}


Measured memory_bytes: 37872
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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 (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll a(N+1);
        rep(i, 1, N+1) cin >> a[i];
        map<ll, ll> mp;
        rep(i, 1, N+1) mp[i] = a[i];

        ll cnt = 0;
        ll now = 1;
        rep(i, 0, 1000000) {
                now = mp[now];
                ++cnt;
                if (now == 2) break;
        }
        if (cnt < N) {
                cout << cnt << endl;
        } else {
                cout << -1 << endl;
        }
}

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

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

    const int MAXN = 200000;
    static int a[MAXN];

    int idx = -1;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (i > 0 and a[i] + a[i - 1] >= L) idx = i - 1;
    }

    cerr << "idx is " << idx << endl;

    if (idx < 0) {
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    for (int i = 0; i < idx; i++) {
        cout << i + 1 << endl;
    }
    for (int i = N - 2; i >= idx; i--) {
        cout << i + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
#define pii pair<int,int>
using namespace std;



int main() {

	int a, b, c, d;

	cin >> a >> b >> c >> d;
	if (a + b > c + d)cout << "Left" << endl;
	else if (a + b < c + d)cout << "Right" << endl;
	else cout << "Balanced" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <cstring>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	string s, t;
	cin >> s >> t;

	sort( ALL( s ) );
	sort( ALL( t ), []( char a, char b ) { return ( a > b ); } );

	if ( s < t )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 384
#include<cstdio>
int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
		if(A == 7&&B == 5&&C == 5||A == 5&&B == 7&&C == 5||A == 5&&B == 5&&C == 7)
		printf("YES");
		else
			printf("NO");
			return 0;
}


Measured memory_bytes: 128
def f():
 global d
 p=[]
 for i in range(len(d)-1):
  a,b=d[i],d[i+1]
  r=(b-a)/3
  p+=[a,a+r,a+r+r*(1+3**.5*1j)/2,b-r]
 d=p+[d[-1]]
d=[0j,100+0j]
for _ in[0]*int(input()):f()
for e in d:print(e.real,e.imag)


Measured memory_bytes: 5924
#include<stdio.h>

int main(){
    int a, b, c, d, e;
    int min = 10;
    int ans = 0;
    scanf("%d %d %d %d %d",&a, &b, &c, &d, &e);
    if(min > a%10 && a%10 != 0){
        min = a%10;
    }
    if(min > b%10 && b%10 != 0){
        min = b%10;
    }
    if(min > c%10 && c%10 != 0){
        min = c%10;
    }
    if(min > d%10 && d%10 != 0){
        min = d%10;
    }
    if(min > e%10 && e%10 != 0){
        min = e%10;
    }
    ans = (a+9)/10 + (b+9)/10 + (c+9)/10 + (d+9)/10 + (e+9)/10;
    ans *= 10;
  	ans = ans -10 + min;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    a = list(map(int, input().split()))
    total = 0
    for j in range(m):
        total += (b[j] * a[j])
    if total + c > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<string>
#define INF 100093100
using namespace std;
vector<tuple<int,int,int>> road;
typedef struct cityf{
    int x,y;
    
    bool operator< (const cityf &a) const
    {
        return x < a.x;
    }

}city;
map<city,int>ori;
int t,k,n,root[100005],hight[100005],dix,diy,q,w,e,ans=0,finish=1,j;
city town[100005];
int find(int a){
    if(root[a]==a)
        return root[a];
    else
        return root[a]=find(root[a]);
}
bool same(int a,int b){
    return find(a)==find(b);
}
void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(hight[b]>hight[a])
        swap(a,b);
    hight[a]+=hight[b];
    root[b]=a;
}
bool cmp(tuple<int,int,int>a,tuple<int,int,int>b){
    int o=get<2>(a);
    int p=get<2>(b);
    return o<p;
}
bool cmp2(city a,city b){
    return a.x<b.x;
}
bool cmp3(city a,city b){
    return a.y<b.y;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&t,&k);
        town[i].x=t;
        town[i].y=k;
        ori[town[i]]=i;
    }
    sort(town+1,town+1+n,cmp2);
    for(int i=1;i<n;i++){
        dix=abs(town[i+1].x-town[i].x);
        road.push_back({ori[town[i]],ori[town[i+1]],dix});
    }
    sort(town+1,town+1+n,cmp3);
    for(int i=1;i<n;i++){
        diy=abs(town[i+1].y-town[i].y);
        road.push_back({ori[town[i]],ori[town[i+1]],diy});
    }
    sort(road.begin(),road.end(),cmp);
    for(int i=1;i<=n;i++){
        root[i]=i;
        hight[i]=1;
    }
    for(auto k:road){
        tie(q,w,e)=k;
        if(!same(q,w)){
            unite(q,w);
            ans+=e;
            finish++;
        }
        if(finish==n)
            break;
    }
    printf("%d",ans);
}


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

using namespace std;

int main(){
  int i, j, n;
  string str, train;
  string::iterator iter;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> str;
    train.push_back(str[0]);

    for(j=1, iter=train.begin(); j<str.size(); j+=3){
      if(str[j] == '<' && str[j+1] == '-'){
	if(iter == train.begin()){
	  train.insert(train.begin(), str[j+2]);
	  iter = train.begin();
	}else{
	  --iter;
	}
      }else if(str[j] == '-' && str[j+1] == '>'){
	if(iter == train.end()-1){
	  train.push_back(str[j+2]);
	  iter = train.end()-1;
	}else{
	  ++iter;
	}
      }
    }

    cout << train << endl;
    train.clear();
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  vector<bool> chan(n + 1,false);
  rep(i,n)cin>>a[i];

  for(int i=0;i<n-1;i++){
    if(a[i]<=a[i+1])chan[i]=true;
  }

  chan[n]=true;

  ll kabu = 0;
  ll money = 1000;
  for(int i=0;i<n;i++){
    if(chan[i]){
      kabu += money / a[i];
      money -= ((ll)(money / a[i]) * a[i]);
      //cout<<kabu<<" "<<money<<endl;
    }else{
      //cout<<i<<endl;
      money += (kabu * a[i]);
      kabu = 0;
    }
  }

  cout<<money<<"\n";

  

  return 0;
}


Measured memory_bytes: 3624
import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
List=[]
for i in range(a):
  u,v=mi()
  List.append([u-v,u+v])
List=sorted(List , key=lambda x:x[1])
q=deque([List[0][1]])
ans=1
for i,j in List:
  u=q.pop()
  if u<=i:
    q.append(j)
    ans+=1
  else:
    q.append(u)
print(ans)

Measured memory_bytes: 22636
#include <bits/stdc++.h>
using namespace std;
int ans, n, a[1000000], mx, b[1000000];
int main() {
	cin>>n;
	for (int i = 1; i <= n; i++) {
		cin>>a[i];
		if (a[i] != i) ans++;
	}
	if (ans <= 2) cout<<"YES";
	else cout<<"NO";
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    if (A == B){
        cout << C;
    }else if (B == C){
        cout << A;
    }else{
        cout << B;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    s = input()
    flag = True
    if s[0] != "A":
        flag = False
    if "C" not in s[2:-1]:
        flag = False
    if count_upper(s) != 2:
        flag = False
    print("AC" if flag else "WA")

def count_upper(s):
    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    assert len(set(upper)) == 26
    res = 0
    for c in s:
        if c in upper:
            res += 1
    return res

main()


Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<stdlib.h>

#define INF -99999999999;
using namespace std;

class answer {
public:
	int s, e, ans;
	answer(){ s = 0; e = 0; ans = 0; }
	answer(int a, int b, int c) {
		s = a;
		e = b;
		ans = c;
	}
	void show3(void) { cout << s << " " << e << " " << ans; }
	void show1(void) { cout << ans << "\n"; }
};

answer fun2(int *B, int low, int mid, int high)
{
	int leftsum = INF;
	int rightsum = INF;
	int sum = 0;
	int maxleft, maxright;

	for (int i = mid; i >= low; i--) {
		sum += B[i];
		if (sum > leftsum) {
			leftsum = sum;
			maxleft = i;
		}
	}
	sum = 0;
	for (int j = mid + 1; j <= high; j++) {
		sum += B[j];
		if (sum > rightsum) {
			rightsum = sum;
			maxright = j;
		}
	}

	answer b(maxleft, maxright, leftsum + rightsum);
	return b;
}

answer fun3(int* B, int low, int high) {
	if (high == low) {
		answer a(low, high, B[low]);
		return a;
	}
	else {
		int mid = (int)floor((low + high) / 2);
		answer left = fun3(B, low, mid);
		answer right = fun3(B, mid + 1, high);
		answer cross = fun2(B, low, mid, high);

		if (left.ans >= right.ans&&left.ans >= cross.ans) {
			return left;
		}
		else if (right.ans >= left.ans&&right.ans >= cross.ans) {
			return  right;
		}
		else
			return cross;
	}

}



answer fun1(int *B,int n)
{
	int sum;
	int ans = -999999;
	int ansi, anse;
	for (int i = 1; i <= n; i++) {
		sum = 0;
		for (int j = i; j <= n; j++) {
			sum += B[j];
			if (sum > ans) {
				ans = sum;
				ansi = i;
				anse = j;
			}
		}
	}
	answer a(ansi, anse, ans);
	return a;
}



int main()
{
	// cout << "size--";
	int n;
	cin >> n;

	int*A;
	int*B;
	A = new int[n + 1];
	B = new int[n + 1];
	A[0] = 0;
	for (int i = 1; i <= n; i++){
		cin >> A[i];
		B[i] = A[i] - A[i - 1];
	}

	// answer a=fun2(B, n);
	answer a = fun3(B, 2, n);
	a.show1();

	delete A;
	delete B;

	return 0;
}

Measured memory_bytes: 4340
#include<cstdio>
const int N = 2333,mo=1e9+7;
int n,k,f[N][N],g[N*N],fac[N];
int power(int a, int n){
	int res=1;
	while(n){
		if(n&1)res=1LL*res*a%mo;a=1LL*a*a%mo;n>>=1;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&k);if(k==1){puts("1");return 0;}
	for(int i=k-2,j=1;i<=n*k;i++)g[i]=j,j=1LL*j*(i+1)%mo*power(i-k+3,mo-2)%mo;
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1LL*fac[i-1]*i%mo;
	for(int i=0;i<=n;i++)for(int j=i;j<=n;j++)
		if(i==0){
			if(j==0)f[i][j]=1;else f[i][j]=1LL*f[i][j-1]*g[i+j*k-j-1]%mo;
		}else f[i][j]=(f[i-1][j]+1LL*f[i][j-1]*g[i+j*k-j-1])%mo;
	printf("%lld",1LL*f[n][n]*fac[n]%mo);
	return 0;
}

Measured memory_bytes: 36992
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))



int main() {
    string s,t;
    cin>>s;
    for(int i=0;i<s.size();i++){
        t.push_back(s[s.size()-1-i]);
    }
    int i=0;
    while(i<s.size()){
        if(t.substr(i,5)=="maerd"){
            i+=5;
           // cout<<"d";
        }
        else if(t.substr(i,7)=="remaerd"){
            i+=7;
           // cout<<"s";
        }
        else if(t.substr(i,5)=="esare"){
            i+=5;
           // cout<<"b";
        }
        else if(t.substr(i,6)=="resare"){
            i+=6;
           // cout<<"a";
        }
        else{
            cout<<"NO"<<endl;
            return 0;
        }

    }
    
        cout<<"YES"<<endl;
        
    
    
   


    return 0;
}

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

typedef pair<int,int> P;

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    if (m2 < m1) {
        m2 += 60;
        h2--;
    }
    if (h2 < h1) h2 += 24;
    int up = (h2-h1)*60 + (m2-m1);
    cout << up-k << "\n";
}

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,d; cin >> n >> d;

    int i=0;
    while((2*d+1)*i<n){
        ++i;
    }

    cout << i ENDL;
    
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    int w, h; cin >> w >> h;
    priority_queue<ll, vector<ll>, greater<ll>> p, q;
    for (int i = 0; i < w; ++i) {
        ll pi; cin >> pi;
        p.push(pi);
    }
    for (int i = 0; i < h; ++i) {
        ll qi; cin >> qi;
        q.push(qi);
    }
    ll ans = 0;
    ll rest_w = w, rest_h = h;
    for (int c = 0; c < h + w; ++c) {
        if (p.empty()) {
            ll top = q.top();
            q.pop();
            ans += top * (rest_w + 1);
            --rest_h;
        } else if (q.empty()) {
            ll top = p.top();
            p.pop();
            ans += top * (rest_h + 1);
            --rest_w;
        } else {
            ll pt = p.top();
            ll qt = q.top();
            if (pt < qt) {
                p.pop();
                ans += pt * (rest_h + 1);
                --rest_w;
            } else {
                q.pop();
                ans += qt * (rest_w + 1);
                --rest_h;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2548
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

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

  if(N==100) printf("%d\n",101*(int)pow(100,D));
  else cout << N*pow(100,D) << endl;
  
  return 0;
}


Measured memory_bytes: 3904
#include <stdio.h>
int prime[1000000]={0};
int main(){
  int i,j,k,flag;
  while(scanf("%d",&i) != EOF){
    flag=0;
    for(j=2;j<=i/2;j++){
      for(k=2;k*j<=i;k++){
	prime[j*k]=1;
      }
    }
    for(j=2;j<=i;j++){
      if(prime[j] == 0){
	flag++;
      }
    }
    printf("%d\n",flag);
  }
  return (0);
}

Measured memory_bytes: 4500
#include <algorithm>
#include <bitset>
#include <complex>
#include <cassert>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <memory>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define INF_LL 4000000000000000000LL
#define INF 1000000000
#define EPS 1e-8
#define LL long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define setzero(a) memset(a,0,sizeof(a))
#define setdp(a) memset(a,-1,sizeof(a))
#define bits(a) __builtin_popcountll(a)

using namespace std;

int f[105][15];
int p[105][15];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%d", &f[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  LL ans = -INF_LL;
  for (int i = 1; i < (1 << 10); i++) {
    LL tmp = 0;
    for (int k = 0; k < n; k++) {
      int c = 0;
      for (int j = 0; j < 10; j++) {
        if (!f[k][j])
          continue;
        if (i & (1 << j)) {
          c++;
        }
      }
      tmp += p[k][c];
    }
    ans = max(ans, tmp);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr

if N == 1:
    print(0)
else:
    ans = 0
    l = factorization(N)
    for i in range(len(l)):
        now = l[i][1]
        c = 1
        while now-c >= 0:
            now -= c
            ans += 1
            c += 1
    print(ans)

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

int main() {

  int N,T;
  cin >> N >> T;

  vector<long long> time(N),dif(N);
  for(int i = 0;i < N;i++) {
    cin >> time.at(i);
  }

  
  for(int i = 1;i < N;i++) {
    dif.at(i) = time.at(i) - time.at(i - 1);
  }

  long long sum = T;
  for(int i = 0;i < N;i++) {
    if(dif.at(i) >= T) {
      sum += T;
    }else{
      sum += dif.at(i);
    }
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;

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

    string c[h];
    for (int i = 0; i < h; i++) {
        cin >> c[i];
        cout << c[i] << endl;
        cout << c[i] << endl;
    }
}


Measured memory_bytes: 256
def mine_count(board, h, w, i, j):
    if board[i][j] == '#':
        return '#'
    else:
        count = 0
        for row in range(max(i - 1, 0), min(i + 2, h)):
            for col in range(max(j - 1, 0), min(j + 2, w)):
                if board[row][col] == '#':
                    count += 1
        return str(count)


if __name__ == '__main__':
    h, w = map(int, input().split())
    board = [input() for _ in range(h)]
    for i in range(h):
        print(''.join([mine_count(board, h, w, i, j) for j in range(w)]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main(){
	string s1,s2;
	cin >> s1 >> s2;
	int a=0;
	for(int i=0;i<=2;i++){
		if(s1[i]==s2[i])
		a++;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	char s[1000];
	scanf("%s",&s);
	bool bo1=false,bo2=false;
	for(int i=0;s[i]!='\0';i++)
	{
		if(s[i]=='C')
			bo1=true;
		if(s[i]=='F'&&bo1)
			bo2=true;
	}
	if(bo2)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
mon = [0]* n
ac =0
wa = 0
for i in range(m):
    p,s = list(input().split())
    p = int(p)-1
    if mon[p] <0:
        continue
    if s == 'AC':
        ac += 1
        wa += mon[p]
        mon[p] = -1
    else:
        mon[p] += 1

print(ac,wa)


Measured memory_bytes: 3828
n = int(input())
w = list(map(int, input().split()))

point = sum(w)

total = 0
dif = 10**5

for i in w:
    total += i
    if abs(point - 2 * total) < dif:
        dif = abs(point - 2 * total)
    else:
        break
print(dif)

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

	public static void main(String[] args) {
		new Main().solve();
	}
	long INF=Long.MAX_VALUE/2;
	int n,m;
	long[] dist;
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		
		Edge[] v=new Edge[m];
		for(int i=0;i<m;i++){
			v[i]=new Edge();
			v[i].from=sc.nextInt();
			v[i].to=sc.nextInt();
			v[i].cost=-sc.nextInt();
		}
		
		//dist[i]:iにたどり着く最短距離
		dist=new long[n+1];
		Arrays.fill(dist, INF);
		dist[1]=0; //初期化
		
		//ベルマンフォード法
		boolean flag=true;
		long ans=0;
		int cnt=0;
		while(flag){
			flag=false;
			for(int i=0;i<m;i++){
				if(dist[v[i].from]+v[i].cost<dist[v[i].to]){
					dist[v[i].to]=dist[v[i].from]+v[i].cost;
					flag=true;
				}
			}
			if(cnt==n){
				ans=dist[n];
			}
			if(cnt==2*n){
				if(ans>dist[n]){
					System.out.println("inf");
					return;
				}else{
					System.out.println(-dist[n]);
					return;
				}
			}
			cnt++;
			if(!flag)break;
		}
		
		System.out.println(-dist[n]);
	}
	class Edge{
		int to;
		int from;
		int cost;
	}
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector< vector <int> > member(n+1, vector<int>(0));
		for (int i = 0; i < n; i++) {
			int m;
			cin >> m;
			int a;
			for (int j = 0; j < m; j++) {
				cin >> a;
				member[a].push_back(i+1);
			}
		}
		int k;
		cin >> k;
		vector<int> member2(n+1, 0);
		int b;
		for (int i = 0; i < k; i++) {
			cin >> b;
			for (int j = 0; j < member[b].size(); j++) {
				member2[member[b][j]]++;
			}
		}
		int counter = 0;
		int hannin;
		for (int i = 1; i < n+1; i++) {
			if (member2[i] == k) {
				counter++;
				hannin = i;
			}
		}
		if (counter == 1) {
			cout << hannin << endl;
		} else {
			cout << -1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1288
{-# LANGUAGE MultiWayIf #-}

import Data.Array (accumArray, assocs)
import Data.List (foldl', sortOn)

a#b = abs (a-b)

freq = filter ((>0).snd) . assocs . accumArray (+) 0 (1,100000) . flip zip (repeat 1)

split :: [a] -> ([a] -> [a] -> c) -> c
split [] c = c [] []
split (o:e:xs) c = split xs (\os es -> c (o:os) (e:es))

solv :: Int -> [Int] -> [Int] -> Int
solv n xs ys = case (xfreq, yfreq) of
    ([(o1,_)], [(e1,_)])
      | o1/=e1 -> 0
      | o1==e1 -> div n 2
    ([(o1,_)], ((e1,c1):(e2,c2):_))
      | o1/=e1 -> (div n 2)-c1
      | o1==e1 -> (div n 2)-c2
    (((o1,c1):(o2,c2):_), [(e1,_)])
      | o1/=e1 -> (div n 2)-c1
      | o1==e1 -> (div n 2)-c2
    (((o1,co1):(o2,co2):_), ((e1,ce1):(e2,ce2):_))
      | o1/=e1 -> n-(co1+ce1)
      | o1==e1 -> n- (max (co1+ce2) (co2+ce1))
  where
    xfreq = reverse.sortOn snd.freq $ xs
    yfreq = reverse.sortOn snd.freq $ ys

main = do
  n <- read <$> getLine
  xs <- map read . words <$> getLine :: IO [Int]
  let (os,es) = split xs $ flip (,)
  print $ solv n os es


Measured memory_bytes: 48508
#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()

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

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

    vector <int> num(n);
    iota(all(num),0);

    double total=0.0;

    do{
        double tot=0.0;
        for(int i=0; i<n-1; i++){
            double dx = x[num[i+1]] - x[num[i]];
            double dy = y[num[i+1]] - y[num[i]];
            double l2 = pow(dx,2) + pow(dy,2);
            double l = pow(l2,0.5);
            tot += l;
        }
        total += tot;
    }while(next_permutation(all(num)));

    double ans = total;
    for(int i=n; i>=1; i--){
        ans /= i;
    }

    cout << fixed << setprecision(10);
    cout << ans << endl;
}


Measured memory_bytes: 384
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut h: Vec<usize> = read_vec();

    if n == 1 {
      println!("Yes");
      return
    }

    // 後ろから左隣だけを見るようにする
    for i in (1..n).rev() {
      // 2 1 1
      if h[i] + 1 == h[i-1] {
        h[i-1] -= 1;
      }
      else if h[i] >= h[i-1] {
        continue;
      }
      else {
        println!("No");
        return
      }
    }

    println!("Yes");
}


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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 3e5 + 3;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
    return (a + b) < (b + a);
}

void solve(){
    int n;
    string s;
    cin >> n >> s;
    int mx = 0, cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'I'){
            cnt++;
            mx = max(cnt, mx);
        }
        else if(s[i] == 'D')
            cnt--;
    }
    cout << mx;
}


int main(){
    //freopen("slalom.in","r",stdin);
    //freopen("slalom.out","w",stdout);
    //faster();
    int n = 1;
    //cin >> n;
    while(n--){
        solve();
        cout << endl;
    }
    //fclose(stdout);
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 200200
li parent[2][UF_NUM];

inline void init_uf() {
    rep(i, UF_NUM)parent[0][i] = i;
    rep(i, UF_NUM)parent[1][i] = i;
}

inline li find_(li x, li i) {
    if (parent[i][x] == x)return x;
    else return (parent[i][x] = find_(parent[i][x], i));
}

inline void union_(li x, li y, li i) {
    li parent_x = find_(x, i);
    li parent_y = find_(y, i);
    parent[i][parent_x] = parent_y;
}

map<PI, li> res;

int main() {
    li n, k, l;
    cin >> n >> k >> l;
    init_uf();
    rep(i, k) {
        li p, q;
        cin >> p >> q;
        p--;
        q--;
        union_(p, q, 0);
    }
    rep(i, l) {
        li p, q;
        cin >> p >> q;
        p--;
        q--;
        union_(p, q, 1);
    }
    rin{
        res[{find_(i, 0), find_(i, 1)}]++;
    }
    rin{
        cout << res[{find_(i, 0), find_(i, 1)}] << endl;
    }

    return 0;
}

Measured memory_bytes: 15232