akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define M 1000000000000000000

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

    ll N, ret=1, temp, q;
    bool overflow = false;
    cin >> N;

    for(ll i=0; i<N; i++){
        cin >> temp;
        if (temp == 0){
            ret = 0;
            break;
        }else if(!overflow){
            q = M/ret;
            if(temp <= q) ret *= temp;
            else{
                ret = -1;
                overflow = true;
            }
        }
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3656
/*  -*- coding: utf-8 -*-
 *
 * 2956.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_K = MAX_N;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;

/* global variables */

int ps[MAX_N], cs[MAX_N], js[MAX_N];
vpii nbrs[MAX_N];
ll dp0[MAX_N], dp1[MAX_N], maxhs[MAX_K];

/* subroutines */

void dijkstra(priority_queue<pli> &q, ll dp[]) {
  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll &ud = u.first;
    int &ui = u.second;
    if (ud != dp[ui]) continue;

    vpii &nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = ud - vit->second;
      if (dp[vi] < vd) {
	dp[vi] = vd;
	q.push(pli(vd, vi));
      }
    }
  }
}

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < n; i++) scanf("%d", ps + i);
  for (int i = 0; i < n; i++) scanf("%d", cs + i), cs[i]--;
  for (int i = 0; i < n; i++) scanf("%d", js + i);

  for (int i = 0; i < m; i++) {
    int u, v, t;
    scanf("%d%d%d", &u, &v, &t);
    u--, v--;
    nbrs[u].push_back(pii(v, t));
    nbrs[v].push_back(pii(u, t));
  }

  fill(dp0, dp0 + n, -LINF);
  dp0[0] = 0;

  priority_queue<pli> q;
  q.push(pli(0, 0));
  dijkstra(q, dp0);

  fill(dp1, dp1 + n, -LINF);
  for (int i = 0; i < n; i++) {
    ll d = dp0[i] + ps[i];
    dp1[i] = d;
    q.push(pli(d, i));
  }
  dijkstra(q, dp1);

  fill(maxhs, maxhs + k, -LINF);

  for (int i = 0; i < n; i++) {
    ll h = dp1[i] + js[i] + dp0[i];
    if (maxhs[cs[i]] < h) maxhs[cs[i]] = h;
  }

  for (int i = 0; i < k; i++) printf("%lld\n", maxhs[i]);
  return 0;
}



Measured memory_bytes: 16824
#include <iostream>;
#include <ostream>;
#include <queue>;
#include <string>;
#include <vector>;
using namespace std;



int main() {
	int a, b, c, d, e;
	int k;
	cin >> a >> b >> c >> d >> e;
	cin >> k;
	if (e - a <= k) cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = [input() for _ in range(H)]

prev_left = 0
prev_right = 0

for i in range(H):
    left = A[i].find('#')
    right = A[i].rfind('#')
    if prev_right == left:
        prev_left = left
        prev_right = right
    elif right == W-1:
        right = W
        break
    elif prev_left == left and prev_right == right:
        break

if right == W-1:
    print('Possible')
else:
    print('Impossible')

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

int32_t main() {
	
	int n;	cin >> n;
	int a[n];
	for(int x=0;x<n;x++)	cin >> a[x];
	sort(a,a+n);
	int ans = abs(a[n-1] - a[0]);
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

def pm(a, t):
    ans = 0
    s = 0
    for i in a:
        s += i
        if t == 1 and s<1:
            ans += -s+1
            s = 1
        elif t==-1 and s>-1:
            ans += s+1
            s = -1
        t *= -1
    return ans
  
print(min(pm(a, 1), pm(a, -1)))

Measured memory_bytes: 19900
pub fn main() {
    let mut buf = String::new();
    let nums: Vec<i32> = {
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim()
            .chars()
            .map(|ch| ch as i32 - '0' as i32)
            .collect()
    };
    let k: i32 = {
        buf.clear();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().parse().unwrap()
    };
    fn comb(n: i32, k: i32) -> i32 {
        let mut c = 1;
        for i in 0..k {
            c *= n - i;
        }
        for i in 0..k {
            c /= k - i;
        }
        for _ in 0..k {
            c *= 9;
        }
        c
    }
    fn rec(nums: &[i32], k: i32) -> i32 {
        if k == 0 {
            1
        } else if nums.is_empty() {
            0
        } else if nums[0] == 0 {
            rec(&nums[1..], k)
        } else {
            let mut ans = 0;
            let l = nums.len() as i32;
            if k < l {
                ans += comb(l - 1, k);
            }
            if k <= l {
                if nums[0] > 1 {
                    ans += (nums[0] - 1) * comb(l - 1, k - 1);
                }
                ans += rec(&nums[1..], k - 1);
            }
            ans
        }
    }
    println!("{}", rec(&nums, k));
}

Measured memory_bytes: 4352
#include<stdio.h>

#define N 100

void funk(int);

int graph[N][N],A[N],B[N];
int x,time = 0;

int main() {
  int i,j,a,b,c;

  scanf("%d",&x);
  for(i = 0; i < x; i++) {
    scanf("%d%d",&a,&b);
    for(j = 0; j < b; j++) {
      scanf("%d",&c);
      graph[a - 1][c - 1] = 1;
    }
  }

  for(i = 0; i < x; i++) {
    if(A[i] == 0) {
      funk(i);
    }
  }

    for(i = 0; i < x; i++) {
      printf("%d %d %d\n", i + 1, A[i], B[i]);
    }

    return 0;
}

void funk(int a) {
  int n;
  time++;
  A[a] = time;

  for(n = 0; n < x; n++) {
    if(graph[a][n] != 0 && A[n] == 0) {
      funk(n);
    }
  }

  time++;
  B[a] = time;
}
			

  



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

#define ll long long int
#define ull unsigned long long int
#define lld long double
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vull vector<ull>
#define all(v) v.begin(),v.end()
#define mp make_pair
#define bitcount(x) __builtin_popcountll(x)
#define charcount(s,c) count(s.begin(), s.end(), c)
#define each(a,b) memset(a,b,sizeof a) //for b=0/-1, all pos,s for multidim arr too;
#define tofsi(s,c,t) memset(s,c,t) // for char s[n],first t;
#define tofs(s,pos,c,t) fill_n(s.begin()+pos, t, c);
#define fi first
#define se second
#define cfl cout.flush()

ll e_bit=0xAAAAAAAA;
ll o_bit=0x55555555;
lld pi = acos(-1.0);
ll gprime=402653189;
ll pprime=1610612741;
ll dulo=1000000007;

bool is_power2(ll n){
	return (n&&!(n&(n-1)));
}
ll power(ll x, ll y){
    ll temp;
    if( y == 0)
       return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return (temp*temp);
    else
    {
        if(y > 0)
            return (((x*temp))*temp);
        else
            return (temp*temp)/x;
    }
}

long long int mul_inv(long long int n,long long int p,long long int m){
	if(p==1){
		return n%m;
	}
	else if(p%2==0){
		long long int t= mul_inv(n,p/2,m);
		return ((t)*(t))%m;
	}
	else{
		long long int t= mul_inv(n,p/2,m);
		return ((((n%m)*t)%m)*t)%m;
	}
}

bool isprime(ll n){
	if(n==1){
		return false;
	}
	if(n==2){
		return true;
	}
	if(n%2==0){
		return false;
	}
	for(ll i=3;i<=sqrt(n);i+=2){
		if(n%i==0){
			return false;
		}
	}
	return true;
}


// getline(cin,s), cin.ignore() if cin>>p b4;


/*
struct compare {
    bool operator() (string a,string b) const{
    	string s1=a+b;
    	string s2=b+a;
        return s1<s2;
    }
};
*/


/*
---------------------Priority Queue Compare Operator------------------------

priority_queue<int, std::vector<int>, compare> pq;

*/


int main(){
    /*ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);*/
	/*freopen("fbh.in","r",stdin);
    freopen("B-large.out","w",stdout);*/
	/*float ans;
	std::cout << std::fixed;
    std::cout << std::setprecision(9);
    std::cout << ans;
	*/
	int n,a,b;
	cin>>n>>a>>b;
	if((abs(b-a)-1)%2){
		cout<<"Alice";
	}
	else{
		cout<<"Borys";
	}
	return 0;
}

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

using namespace std;

int main() {
    string s1, s2;
    int ans = 0;
    cin >> s1 >> s2;
    for(int i = 0; i < s1.size(); i++) ans += (s1[i] == s2[i]);
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  int point=0;
  int out_count=0;
  int runner=0;
  cin>>n;
  string event;
  for(int i=0;i<n;i++){
    out_count=0;
    point=0;
    runner=0;
    while(out_count<3){
      cin>>event;
      if(event=="HIT"){
	runner++;
	if(runner>3){
	  point++;
	  runner--;
	}
      }else if(event=="OUT"){
	out_count++;
      }else{
	point+=runner+1;
	runner=0;
      }
    }
    cout << point << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
N, M = map(int, input().split())
ab = [[int(x) for x in input().split()] for _ in range(N)]
cd = [[int(x) for x in input().split()] for _ in range(M)]

for a, b in ab:
    ans = [None, float('inf')]
    for i in range(M):
        c, d = cd[i]
        d = abs(a - c) + abs(b - d)
        if ans[1] > d:
            ans = [i + 1, d]
    print(ans[0])

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <vector>
//#include <numeric>
//#include <algorithm>
#include <cmath>
#include <string>
//#include <map>
//#include <iomanip>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc046_b(vector<vector<int>> v) {

    double n = double(v[0][0]);
    double k = double(v[0][1]);

    int val = pow(double(k - 1), double(n - 1));
    val*=k;
    
    cout << val << endl;


}

int main() {

    //    vector<vector < string>> vec_arr_result;
    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    abc046_b(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String a = sc.next();
        Map<Character, Long> map = new HashMap<>();
        long n = a.length();
        for (int i = 0; i < n; i++) {
            Character key = a.charAt(i);
            if (!map.containsKey(key)) {
                map.put(key, 0L);
            }
            map.put(key, map.get(key) + 1);
        }

        long res = 0;
        for (Character key : map.keySet()) {
            long k = map.get(key).longValue();
            res += k * (k - 1) / 2;
        }

        long ans = n * (n - 1) / 2 - res + 1;
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main(){
    int n, d, x, b;
    cin >> n >> d >> x;
    int A[n];
    int cnt = 0;

    for(int i = 0; i < n; i++){
        cin >> A[i];
        b = (d - 1) / A[i];
        cnt += b + 1;
    }
    cnt += x;

    cout << cnt << endl;

    return 0;
}

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

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> p(N);
  vector<double> pd(N);
  
  for(ll i = 0; i < N; i++){
    cin >> p[i];
    pd[i] = (double)p[i] / 2.0 + 0.5;
  }
  
  ll st_idx = 0, ed_idx = N;
  double ans = 0.0;
  double tmp = 0.0;

  for(ll i = 0; i < K; i++){
    tmp += pd[i];
  }

  ans = tmp;

  for(ll i = K; i < N; i++){
    tmp += pd[i];
    tmp -= pd[i - K];
    ans = max(ans, tmp);
  }
  
  cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std; 
int main(void){
  string s;
  cin >> s;
  vector<string> tmp = {"hi", "hihi", "hihihi", "hihihihi", "hihihihihi"};
  for(int i = 0; i < 5; i++){
    if(s == tmp[i]){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int b(int x){return x>0?x:-x;}
int main(){
  int n,w,t,u,i;
  scanf("%d%d%d",&n,&t,&w);
  for(i=0;i<n-1;i++)scanf("%d",&t);scanf("%d",&u);
  printf("%d",n==1?b(u-w):b(u-w)>b(t-u)?b(u-w):b(t-u));
}


Measured memory_bytes: 1676
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		double a = sc.nextDouble();
		// スペース区切りの整数の入力
		double b = sc.nextDouble();
		double c = sc.nextDouble();
		double d = a * a * b;
		if(2 * c > d){
			System.out.println(Math.toDegrees(Math.atan(2 * (b - c * b / d) /  a)));
		}else{
			System.out.println(90 - Math.toDegrees(Math.atan(2 * c / a / b/ b)));
		}
		
		
	}
}

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

int main() {
  string s; cin >> s;
  string ans = "";
  for(int i = 0; i<3; i++){
    if(s[i]=='1') ans+='9';
    if(s[i]=='9') ans+='1';
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll A, B;
    in >> A >> B;
    //vector<ll> X(N);

    if(A>B){
        out << 2*A-1 << endl;
    }else if(B>A){
        out << 2*B-1 << endl;
    }else if(B==A){
        out << A+B << endl;
    }

}

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

using namespace std;

void solve()
{
	int N;
	cin >> N;
	int a;
	a = ceil((double)N / 3);
	int count = 1;
	while(a != 1)
	{
		a = ceil((double)a / 3);
		++count;
	}
	cout << count << endl;
}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;++i)
typedef long long ll;
struct Comb{//组合数的一些相关数组
    const ll p=1e9+7;
    void init(int n){
        fac.resize(n+1);
        fac_inv.resize(n+1);
        inv.resize(n+1);
        fac[0]=fac[1]=fac_inv[0]=fac_inv[1]=inv[1]=1;
        for(int i=2;i<=n;++i){
            inv[i]=(p-p/i)*inv[p%i]%p;
            fac[i]=i*fac[i-1]%p;
            fac_inv[i]=fac_inv[i-1]*inv[i]%p;
        }
    }
    vector<ll> fac,fac_inv,inv;
}C;
const ll p=1e9+7;
const int N=2e5+10;;
const int M=2e5+10;
int head[N],ver[2*M],nex[2*M],tot=1;
inline void add(int x,int y) {ver[++tot]=y,nex[tot]=head[x],head[x]=tot;}
ll ans[N],sz[N],cnt[N];//ans[i]以i为根的答案，sz[i]i子树大小，cnt[i]i子树答案
void dfs1(int x,int fa){//第一遍dfs求出以1为根的答案
    sz[x]=cnt[x]=1;
    for(int i=head[x];i;i=nex[i]){
        int y=ver[i];
        if(y==fa)continue;
        dfs1(y,x);
        sz[x]+=sz[y];
        cnt[x]=cnt[x]*C.fac_inv[sz[y]]%p*cnt[y]%p;
    }
    cnt[x]=cnt[x]*C.fac[sz[x]-1]%p;
}
int n;
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//求逆元
void dfs2(int x,int fa,ll s,ll c){//换根分别求出以所有点为根的答案
    ans[x]=cnt[x]*C.fac_inv[sz[x]-1]%p*C.fac[n-1]%p*C.fac_inv[s]%p*c%p;
    for(int i=head[x];i;i=nex[i]){
        int y=ver[i];
        if(y==fa)continue;
        ll tmp=ans[x]*C.fac_inv[n-1]%p*C.fac[n-sz[y]-1]%p*C.fac[sz[y]]%p*inv(cnt[y],p)%p;
        dfs2(y,x,n-sz[y],tmp);
    }
}
int main(){
    C.init(N);
    scanf("%d",&n);
    rep(i,1,n-1){
        int x,y;
        scanf("%d%d",&x,&y);
        add(x,y);add(y,x);
    }
    dfs1(1,0);
    dfs2(1,0,0,1);
    rep(i,1,n)printf("%d\n",ans[i]);
    return 0;
}


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

int main() {
	long long N = 0;
	long long A[100000];
	long long count = 0;
	long long max = 0;
	
	std::cin >> N;

	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
		if (A[i] < 0) {
			A[i] *= -1;
			count++;
		}
	}

	std::sort(A, A + N);

	if (count % 2 == 0) {
		for (int i = 0; i < N; i++) {
			max += A[i];
		}
	}
	else if (count % 2 == 1) {
		for (int i = 1; i < N; i++) {
			max += A[i];
		}
		max -= A[0];
	}

	std::cout << max << std::endl;

}

Measured memory_bytes: 1024
// 2014/04/18 Tazoe

#include <iostream>
using namespace std;

int main()
{
	for(int i=0; i<4; i++){
		int t, n;
		cin >> t >> n;

		if(t==1){
			cout << 6000*n << endl;
		}
		else if(t==2){
			cout << 4000*n << endl;
		}
		else if(t==3){
			cout << 3000*n << endl;
		}
		else{
			cout << 2000*n << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main() {
    int a, b, n;
    while(cin >> a >> b >> n) {
        int t = a, sum = 0;
        for (int i = 0; i < n; i++) {
            t = (t % b) * 10;
            sum += t / b;
        }
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 10000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n, cn1 = 0, cn2 = 0;
	cin >> n;
	int a[100006];
	rep(i, n) {
		cin >> a[i];
	}
	int old;
	if (a[0] < 0) {
		old = a[0];
	}
	else {
		old = -1;
		cn1 += a[0] + 1;
	}
	for (int i = 1; i < n; i++) {
		int now = old + a[i];
		if ((now < 0 && old > 0) || (now > 0 && old < 0)) {
			old = now;
		}
		else if (now < 0 && old <= 0) {
			cn1 += 1 - now;
			old = now + (1 - now);
		}
		else {
			cn1 += now + 1;
			old = now - (now + 1);
		}
	}
	if (a[0] > 0) {
		old = a[0];
	}
	else {
		old = 1;
		cn2 = 1 - a[0];
	}
	for (int i = 1; i < n; i++) {
		int now = old + a[i];
		if ((now < 0 && old > 0) || (now > 0 && old < 0)) {
			old = now;
		}
		else if (now < 0 && old <= 0) {
			cn2 += 1 - now;
			old = now + (1 - now);
		}
		else {
			cn2 += now + 1;
			old = now - (now + 1);
		}
	}
	cout << min(cn1, cn2) << endl;

	return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def bfs01(g, s):
    d = {}
    for v in g.keys():
        d[v] = sys.maxsize
    d[s] = 0

    if s not in d:
        return d
    q = deque()
    q.append((d[s], s))

    NM = 1 << 30
    while q:
        _, u = q.popleft()
        for v in g[u]:
            if v > NM:
                c = 0
            else:
                c = 1
            alt = c + d[u]
            if d[v] > alt:
                d[v] = alt
                if c == 0:
                    q.appendleft((d[v], v))
                else:
                    q.append((d[v], v))
    return d


@mt
def slv(N, M):

    g = defaultdict(list)
    NM = 30
    for _ in range(M):
        p, q, c = input().split()
        p = int(p)
        q = int(q)
        c = int(c)

        cp = (c << NM) + p
        cq = (c << NM) + q
        g[cp].append(cq)
        g[cq].append(cp)
        g[cp].append(p)
        g[cq].append(q)
        g[p].append((cp))
        g[q].append((cq))

    d = bfs01(g, 1)
    return -1 if N not in d or d[N] == sys.maxsize else d[N]


def main():
    N, M = read_int_n()

    print(slv(N, M))


if __name__ == '__main__':
    main()


Measured memory_bytes: 159568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
unsigned long long c[100000];

int main() {
	unsigned long long M = 0, A = 0, R = 0, C = 0, H = 0;
	int N;
	string s[100001];
	cin >> N;
	REP(i, N)cin >> s[i];
	REP(i, N) {
		if (s[i][0] == 'M')M++;
		if (s[i][0] == 'A')A++;
		if (s[i][0] == 'R')R++;
		if (s[i][0] == 'C')C++;
		if (s[i][0] == 'H')H++;
	}
	unsigned long long ans = 0;
	ans = M * A*R + M * A*C + M * A*H + M * R*C + M * R*H + M * C*H + A * R*C + A * R*H + A * C*H + R * C*H;
	cout << ans << endl;
}


Measured memory_bytes: 6144
import sys

a=input()
count1=0
count2=0
for x in range(len(a)):
    if x%2==0:
        if a[x] != "0":
            count1=count1+1
    else:
        if a[x] != "1":
            count1=count1+1
for x in range(len(a)):
    if x%2==0:
        if a[x] != "1":
            count2=count2+1
    else:
        if a[x] != "0":
            count2=count2+1
        
if count1>count2:
    print(count2)
    sys.exit()
print(count1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
typedef int ll;
 
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
 
 
const ll N = 500002;
const ll mod = 1000000007;
const long long int inf = INT64_MAX;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;
 
 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


int main()
{
	fastIO();
	ll a[3][3];
	rep(i,3){
		rep(j,3) cin>>a[i][j];

	}
	ll cnt = 0;
	ll n;
	cin>>n;
	ll x;
	while(n--){
		cin>>x;
		rep(i,3){
			rep(j,3){
				if(a[i][j]==x){
					a[i][j] = -1;
					cnt++;
				}
			}
		}
	}
	ll f = 0;
	rep(i,3){
		if(a[i][0]==a[i][1] && a[i][1]==a[i][2] && a[i][0]==-1) f = 1;
	}
	rep(i,3){
		if(a[0][i]==a[1][i] && a[1][i]==-1 && a[2][i]==-1) f = 1;
	}
	if(a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1) f = 1;
	if(a[2][0]==-1 && a[1][1]==-1 && a[0][2]==-1) f = 1;
	if(f) cout<<"Yes\n";
	else cout<<"No\n";
}


	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    map<string,int> map;
    int n;
    cin>>n;
    int mx=0;
    while(n--)
    {
        string s;
        cin>>s;
        map[s]++;
        if(map[s]> mx)
            mx=map[s];
    }
    for(auto x : map)
    if(x.second == mx)
        cout << x.first <<  "\n";
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int sum = 700;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'o') {
            sum += 100;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define tddd tuple<double,double,double>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<int,pair<int,int> > >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 3005
int dp[N][N];
int main()
{
    int n,i,j;
    in(n);
    string str;
    inl(str);
    dp[1][1]=1;
    lp(i,2,n+1)
    {
        if(str[i-2]=='<')
        {
            lp(j,1,i+1)
                dp[i][j]=(dp[i-1][j-1]-dp[i-1][0]+M)%M;
        }
        else
        {
            lp(j,1,i+1)
                dp[i][j]=(dp[i-1][i-1]-dp[i-1][j-1]+M)%M;
        }
        lp(j,1,i+1)
            dp[i][j]=(dp[i][j]+dp[i][j-1])%M;
    }
    out(dp[n][n]);
}






Measured memory_bytes: 34176
#include<stdio.h>

int main(void){
  int a, b, c, i;
  
  scanf("%d %d %d", &a, &b, &c);
  for(i = 0;i < c;i++){
    if((b -= a) < 0){
      break;
    }
  }
  printf("%d\n", i);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int dp[N];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n ;
		cin >> n ;
		int ans =0;
		fn{
			ans+=(i+1)*(n-i);
		}
		n--;
		fn{
			int x ,y;
			cin>>x>>y;
			--x;
			--y;
			if(x>y)swap(x,y);
			ans-=((x+1)*(n+1-y));
		}
		cout<<ans;

	}
	return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
using namespace std;
long double power(long double x,int num);
int main(){
  int n,k;
  int power_num[100005]={0};
  cin>>n>>k;
  
  for(int i=1;i<=n;i++){
    int x=i;
    int cnt=0;
    while(x<k){
      x*=2;
      cnt++;
    }
    power_num[i]=cnt;
  }
  
  long double ans=0.0;
  for(int i=1;i<=n;i++){
    ans+=power((long double)1/2,power_num[i])/n;    
  }
  
  printf("%.10Lf\n",ans);
  return(0);
}

long double power(long double x,int num){
  if(num==0){
    return(1.0);
  }
  if(num==1){
    return(x);
  }
  
  long double temp=power(x,num/2);
  temp=temp*temp;
  if(num%2!=0){
    temp*=x;
  }
  return(temp);
}


Measured memory_bytes: 640
n = gets.strip.to_i
s = readlines.map {|line| line.strip.split('').sort.join('') }

log = {}
result = 0
s.each do |s|
  if log[s].nil?
    log[s] = 1
    next
  end
  log[s] += 1
  result+=log[s]-1 if log[s] > 1
end

p result

Measured memory_bytes: 37996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;
	
	vector<string> s(n);
	for(int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	
	sort(s.begin(), s.end(), [](const string &a, const string &b){return a < b;});
	
	string ans;
	for(auto itr = s.begin(); itr != s.end(); itr++)
	{
		ans += *itr;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int n, A[50];

int main() {
    int q, M, i;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for(i = 0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0, M)) {
            printf("yes\n");
        }
        else {
            printf("no\n");
        }
    }
}

int solve(int i, int m) {
    if(m==0) {
        return 1;
    }
    if(i >= n) {
        return 0;
    }
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}


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

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

    vector<string> s(N);

    for (int i=0; i<N;i++){
        cin>>s.at(i);
    }
    
    int M;
    cin>> M;
    vector<string> t(M);
    for (int j=0;j<M;j++){
        cin>>t.at(j);
    }
    
    vector<string> all(N);
    int l;
    l=0;
    for(int k=0;k<N;k++){
        //int l;
        //l=0;
        int countm;
        countm=0;
        for(int m=0;m<N;m++){
            if(all.at(m)==s.at(k)){
                countm++;
            }
        }
        if(countm==0){
            all.at(l)=s.at(k);
            l++;
        }
        countm=0;
    }
    vector<int> point(N);
    for(int i=0; i<N;i++){
        for(int j=0;j<N;j++){
            if(all.at(i)==s.at(j)){
                point.at(i)+=1;
            }
        }
        for(int k=0;k<M;k++){
            if(all.at(i)==t.at(k)){
                point.at(i)-=1;
            }
        }
    }
    int max;
    max=0;
    for(int i=0;i<l;i++){
        if(point.at(i)>max){
            max=point.at(i);
        }
    }
    if(max>=0){
        cout<<max<<endl;
    }
    else{
        cout<<0<<endl;
    }
    
}

Measured memory_bytes: 256
/*

Enclose Pins with a Rubber Band(https://onlinejudge.u-aizu.ac.jp/problems/0068)
前

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef pair<double, double> dP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

//外積を計算する関数
double gaiseki(comp a, comp b)
{
	return (conj(a)*b).imag();
}

//凸包

void solve(void){

	int N; char c;
	while (cin >> N && N) {

		vector <dP> pps(N);

		rep(N, i)
		{
			cin >> pps[i].fst >> c >> pps[i].snd;
		}

		sort(all(pps));

		int k = 0;

		vector <comp> ps(N), qs(2*N);

		rep(N, i)
		{
			ps[i] = comp(pps[i].fst, pps[i].snd);
		}

		//上側
		rep(N, i)
		{
			while(k > 1 && gaiseki(qs[k-1] - qs[k-2], ps[i]-qs[k-1]) <= 0)
			{
				k--;
			}
			qs[k++] = ps[i];
		}

		int t = k;

		//下側
		repr(N-1, i)
		{
			while(k > t && gaiseki(qs[k-1] - qs[k-2], ps[i]-qs[k-1]) <= 0)
			{
				k--;
			}
			qs[k++] = ps[i];
		}

		cout << N-k+1 << endl;


	}


}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;

vector<pii > g;

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(k>(n-1)*(n-2)/2) {printf("-1");return 0;}
	for(int i=2;i<=n;++i) g.pb(mk(1,i));
	int i=2,j=3;
	k=(n-1)*(n-2)/2-k;
	while(k--) {
		g.pb(mk(i,j));
		j++;
		if(j==n+1) i++,j=i+1;
	}
	printf("%d\n",g.size());
	for(int i=0;i<g.size();++i) printf("%d %d\n",g[i].first,g[i].second);
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    agc040a()
}

fun agc040a() {
    val s = readLine()!!.map { it == '<' }.toBooleanArray()

    var left = 0
    var right = 1
    val numbers = LongArray(s.size + 1) { 0 }

    while (left <= s.lastIndex) {
        while (right <= s.lastIndex && s[left] == s[right]) right++
        if (s[left]) {
            (left..right).withIndex().forEach {
                numbers[it.value] = Math.max(it.index.toLong(), numbers[it.value])
            }
        } else {
            (right downTo left).withIndex().forEach {
                numbers[it.value] = Math.max(it.index.toLong(), numbers[it.value])
            }
        }
        left = right
    }

    println(numbers.sum())
}


Measured memory_bytes: 55508
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int t=sc.nextInt();
	    int price[]=new int[n];
	    for(int i=0;i<n;i++){
	    	price[i]=sc.nextInt();
	    }
	    int min[]=new int[n];
	    min[0]=price[0];
	      for(int i=1;i<n;i++){
	    	if(price[i]>min[i-1])min[i]=min[i-1];
	    	else min[i]=price[i];
	    }
	      int ans=0;
	      int mc=-1;
	      for(int i=0;i<n;i++){
	    	  if(price[i]-min[i]>mc){
	    		  ans=1;mc=price[i]-min[i];
	    	  }
	    	  else if(price[i]-min[i]==mc)ans++;
	      }
	      System.out.println(ans);
	}
	
}

Measured memory_bytes: 34368
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=2005;
const int inf=1e9;
int n,dp[N][N];
pii a[N];

main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].fi;
        a[i].se=i;
    }
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n+1;j++) dp[i][j]=-inf;
    }
    dp[0][0]=0;
    int res=-inf;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            int l=j;
            int r=n+1-(i-j);
            if(j) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+abs(a[i].se-l)*a[i].fi);
            if(r!=n+1) dp[i][j]=max(dp[i][j],dp[i-1][j]+abs(a[i].se-r)*a[i].fi);
            if(i==n) res=max(res,dp[i][j]);
        }
    }
    cout<<res;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int test[16][16];

int bit_count (int bit, int N)
{
    int cnt = 0;
    REP0(i, N)
    {
        if (bit & (1 << i)) cnt++;
    }
    return cnt;
} 

void solve()
{
  int N; cin >> N;
  REP0(i, N)
  {
      int A; cin >> A;
      REP0(j, A)
      {
          int x; bool isHonest;
          cin >> x >> isHonest;
          test[i][x-1] = (isHonest) ? 1 : -1;
      }
  }

  int ans = 0;
//   honest/unkind を 1/0 にあてた bit 全探索
  for (int bit=0; bit<(1 << N); ++bit)
  {
      bool ok = true;
      REP0(i, N)
      {
        if (!(bit & (1 << i))) continue;
        REP0(j, N)
        {
            bool j_assumed_honest = bit & (1 << j);
            if (test[i][j]==-1 and j_assumed_honest) ok = false;
            if (test[i][j]==1 and !j_assumed_honest) ok = false;
        }
      }
      if (ok) ans = max(ans, bit_count(bit, N));
  }
  cout << ans << endl;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  int poor=0;
  if(a==b && b!=c) poor=1;
  if(b==c && c!=a) poor=1;
  if(c==a && a!=b) poor=1;
  if(poor){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
import sys
def input():
    return sys.stdin.readline()[:-1]
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]*=-1
import heapq
heapq.heapify(a)
for i in range(m):
    # print(a)
    tmp=heapq.heappop(a)
    tmp=tmp*-1
    tmp=tmp//2
    tmp*=-1
    heapq.heappush(a,tmp)

print(sum(a)*-1)

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

int main() {
    string S, T;
    cin >> S >> T;
    if(S.size() != T.size() -1){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<S.size();i++){
        if(S[i]!=T[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define saken string
#define erba continue
using namespace std;

ll n, a, b;

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

    cout << n / max(a, b) + (n % max(a, b) != 0) << '\n';

    return 0;
}


Measured memory_bytes: 256
A,B = map(int, input().split())

S = [["." if h < 50 else "#" for _ in range(100) ] for h in range(100)]

end_black = False
for i in range(0,50,2):
    if end_black:
        break
    for j in range(100):
        if B <= 1:
            end_black = True
            break
        
        if j % 2 == 0:
            S[i][j] = "#"
            B -= 1


end_white = False
for i in range(53,100, 2):
    if end_white:
        break
    for j in range(100):
        if A <= 1:
            end_white = True
            break
        
        if j % 2 == 0:
            S[i][j] = "."
            A -= 1

print(100,100)
for i in range(100):
    print("".join(S[i]))



Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

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

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

	cout << N - K << endl;



	return 0;
}

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

int main () {
	vector<string> t(8);
	for (int i = 0; i < 8; i++) {
		cin >> t[i];
	}
	for (int i = 0; i < 3; i++) {
		vector<string> res = t;
		for (int y = 0; y < 8; y++) {
			for (int x = 0; x < 8; x++) {
				t[x][8 - y - 1] = res[y][x];
			}
		}
		cout << 90 * (i + 1) << endl;
		for (int j = 0; j < 8; j++) {
			cout << t[j] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1192