akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();

    let mut ans = vec![];
    for i in 1..=n {
        for j in i + 1..=n {
            if j != n - i + 1 - n % 2 {
                ans.push((i, j));
            }
        }
    }

    println!("{}", ans.len());
    for (i, j) in ans.into_iter() {
        println!("{} {}", i, j);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}

#[allow(dead_code)]
fn yn(flag: bool) {
    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int classify(int rate){
    if(rate < 400)  return 0;
    if(rate < 800)  return 1;
    if(rate < 1200)  return 2;
    if(rate < 1600)  return 3;
    if(rate < 2000)  return 4;
    if(rate < 2400)  return 5;
    if(rate < 2800)  return 6;
    if(rate < 3200)  return 7;
}

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

    bool color[8] = {};

    int a, wild = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a >= 3200)   wild++;
        else            color[classify(a)] = true;
    }

    int ans = 0;
    for(int i = 0; i < 8; i++)  if(color[i])    ans++;

    cout << max(ans, 1) << " " << ans + wild << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int E,Y;
	scanf("%d %d",&E,&Y);
	if(E==0){
			if(1868<=Y&&Y<=1911){printf("M%d\n",Y-1867);
		}else if(1912<=Y&&Y<=1925){printf("T%d\n",Y-1911);
		}else if(1926<=Y&&Y<=1988){printf("S%d\n",Y-1925);
		}else if(1989<=Y&&Y<=2016){printf("H%d\n",Y-1988);}
	}else if(E==1){printf("%d\n",1867+Y);
	}else if(E==2){printf("%d\n",1911+Y);
	}else if(E==3){printf("%d\n",1925+Y);
	}else if(E==4){printf("%d\n",1988+Y);}
	
	
	
	
	
	
	return 0;
}

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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 1000

int N;
long long T[MAX];
long long A[MAX];

int main() {
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> T[i] >> A[i];
	}

	long long t = 1;
	long long a = 1;
	for( int i = 0; i < N; i++ ) {
		long long j = max( (long long)ceill( (long double)t / T[i] ), (long long)ceill( (long double)a / A[i] ) );
		t = T[i] * j;
		a = A[i] * j;
	}
	long long ans = t + a;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const long double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
	
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}
int dp[100005];
int visited[100005]={};
int long_path(int x, vector<int> edge[])
{
	if(dp[x] >= 0)
		return dp[x];
	
	else if(edge[x].size()==0) 
	{
		dp[x]=0;
		return dp[x];
	}
	else	
	{
		for(int i=0;i<edge[x].size();i++)
		{
			dp[x]=max(dp[x], 1+long_path(edge[x][i],edge));
		}
		return dp[x];
	}		
}

int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int N, M;
	cin >> N >> M;
	memset(dp, -1, sizeof(dp));
	vector<int> edge[N + 1] = {};
	for(int i = 0; i < M; i++)
	{
		int a,b;
		cin >> a >> b;
		edge[a].push_back(b);
	}

	int l = 0;
	for (int i = 1; i <= N; ++i)
	{
		l = max(l, long_path(i, edge));
	}
	cout << l;
	// cerr<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 8192
#include<stdio.h>
main(){
	long long n;
	scanf("%lld",&n);
	long long x=n;
	int sum=0;
	while(n){
		int m=n%10;
		sum+=m;
		n=n/10;
	}
	if(x%sum==0){
		printf("Yes\n");
	}
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void)
{
	int n,k;
	cin >> n >> k;

	int ans = 1;

	for(int i=1;i<=n;i++)
	{
		if(i!=1)ans*=(k-1);
		else ans*=k;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
S = list(input())

if len(S) < 26:
    W = list('abcdefghijklmnopqrstuvwxyz')
    for s in S:
        W.remove(s)
    S += W[0]
    print(*S, sep='')
else:
    s_last = S[-1]
    idx = -1
    for i in range(24, -1, -1):
        s = S[i]
        if s > s_last:
            s_last = s
        else:
            idx = i
            break
    if idx == -1:
        print(-1)
    else:
        res = []
        for s in S[idx+1:]:
            if s > S[idx]:
                res.append(s)
        res.sort()
        print(*(S[:idx] + [res[0]]), sep='')


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

using namespace std;
typedef long long ll;

bitset<10> bts[10];
int p[10];

int main(){
    int N,M;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        int k;
        cin >> k;
        bts[i] = 0;
        for(int j=0;j<k;j++){
            int b;
            cin >> b;
            bts[i].set(b-1);
        }
    }
    for(int i=0;i<M;i++){
        cin >> p[i];
    }
    ll c = 0;
    for(int i=0;i<(1<<N);i++){
        bitset<10> n(i);
        bool f = true;
        for(int j=0;j<M;j++){
            bitset<10> btt = n & bts[j];
            if(btt.count()%2 != p[j]){
                f = false;
                break;
            }
        }
        if(f) c++;
    }
    cout << c << endl;
    return 0;
}

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

A = [list(map(int, input().split())) for i in range(3)]

B = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
N = int(input())

# print(A)
for i in range(N):
    num = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == num:
                B[j][k] = 1

# print(B)
flag = 0
for i in range(3):
    if B[0][i] == 1 and B[1][i] == 1 and B[2][i] == 1:
        flag = 1

for i in range(3):
    if B[i][0] == 1 and B[i][1] == 1 and B[i][2] == 1:
        flag = 1

if B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    flag = 1

if B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    flag = 1

if flag == 0:
    print("No")
else:
    print("Yes")


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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
ll dp[100100][3];
int main()
{
	cout << setprecision(10);
	int n;
	cin >> n;
	int a[100100][3];
	rep(i,n){
		cin >> a[i][0] >> a[i][1] >> a[i][2] ;
	}
	rep(i,n){
		rep(j,3){
			rep(k,3){
				if(j != k){
					chmax(dp[i+1][k], dp[i][j] + a[i][k] );
				}
			}
		}
	}
	ll ans = 0;
	rep(i,3){
		chmax( ans, dp[n][i] );
	}
	cout << ans << endl;


}


Measured memory_bytes: 3712
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int A, B;
    cin >> A >> B;

    if (A > B) swap(A, B);

    if (A == 1 && B == 2) {
        print(3);
    } else if (A == 1 && B == 3) {
        print(2);
    } else {
        print(1);
    }
    
}


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

int main() {
  string N; cin>>N;
  int K; cin>>K;
  int n=N.size();
  ll dp[105][2][105]; //1th:桁(上からi個目), 2th:未満(0)or一致(1), 3th:0が何個入ってる？
  for (int i=0; i<=n; i++) {
    for (int j=0; j<2; j++) {
      for (int k=0; k<105; k++) {
        dp[i][j][k]=0;
      }
    }
  }
  dp[0][0][0]=1;
  for (int i=0; i<n; i++) {
    int D=N[i]-'0';
    for (int j=0; j<2; j++) {
      for (int k=0; k<101; k++) {
        for (int l=0; l<=(j ? 9 : D); l++) {
          if (l==0) dp[i+1][j||(l<D)][k+1]+=dp[i][j][k];
          else dp[i+1][j||(l<D)][k]+=dp[i][j][k];
        }
      }
    }
  }
  ll res=dp[n][0][n-K]+dp[n][1][n-K];
  cout<<res<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,l;
int f[300];
int tot;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>l;
	for(int i=1;i<=n;i++){
		f[i]=i+l-1;
		tot+=f[i];
	}
	int mmin=1e9;
	int res=0;
	for(int i=1;i<=n;i++){
		if(abs(f[i])<mmin){
			mmin=abs(f[i]);
			res=tot-f[i];
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n;
    cin >> n;
    int u=1;
    rep(i,n){
        int f;
        cin >> f;
        if (u==f) u++;
    }
    if (u!=1) cout << n-u+1 << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <utility>
using namespace std;

typedef struct pp {
	char name[100];
	int time;
} P;

P Q[100010];
int head, tail;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail+1) % 100010;
}

P dequeue() {
	P x = Q[head];
	head = (head+1) % 100010;
	return x;
}

int main() {
	int n, q;
	scanf("%d %d", &n, &q);
	char name;
	int time;
	int T = 0;
	for (int i=1; i <= n; i++) {
		scanf("%s %d", Q[i].name, &Q[i].time);
	}
	head =1;
	tail = n+1;
	while (head != tail) {
		P X = dequeue();
		if (X.time > q) {
			X.time -= q;
			T += q;
			enqueue(X);
		} else {
			T += X.time;
			printf("%s %d\n", X.name, T);
		}
	}
	
	return 0;
}


Measured memory_bytes: 12748
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val s = sc.next()
  var count = 0
  var a = 0
  for (c <- s) {
    if (c == '(') {
      count += 1
    } else {
      count -= 1
      if (count < 0) {
        a = a.max(count.abs)
      }
    }
  }
  val b = count + a
  println(s"${"("*a}$s${")"*b}")
}


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



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

#define long long int

const int D = 365;
vector<int> C(26), ans(D, 0), last(26,-1);
vector<vector<int>> S(D, vector<int>(26));

void debug1()
{
    //rep(i,26) cout << C[i] << " "; cout << endl;
    rep(i,D){
        rep(j,26) cout << S[i][j] << " "; cout << endl;
    }
}

void rand_init()
{
    rep(i,26) C[i] = rand() % 100;
    rep(i,D) rep(j,26) S[i][j] = rand() % 20000;
}
  

void input()
{
    int tmp;
    cin >> tmp;
    if(tmp == 0)
    {
      rand_init();
      return;
    }
    rep(i,26) cin >> C[i];
    rep(i,D)rep(j,26) cin >> S[i][j];
    //rep(i,D) cin >> ans[i]; rep(i,D) ans[i]--; //B,C問題用
}

void output()
{
    for(auto x : ans)
        cout << x+1 << "\n";
}

int calc(vector<int> &vec)
{
    int score = 0;
    rep(i,D)
    {
        int cur = vec[i];
        score += S[i][cur];
        last[cur] = i;
        rep(j,26)
        {
            score -= C[j] * (i - last[j]);
        }
        //cout << score << endl;
    }
    return score;
}

void greedy()
{
    rep(i,D)
    {
        rep(j,26)
        {
            if(S[i][j] > S[i][ans[i]])
            {
                ans[i] = j;
            }
        }
    }

}

void incremental()
{
    rep(t, 10000)
    {
        int d = rand() % D, q = rand() % 26;
        vector<int> old = ans;
        ans[d] = q;
        if(calc(ans) < calc(old))
        {
            ans = old;
        }
    }
}



void rand_test(int r)
{
    rep(q,r)
    {
        rand_init();
        //debug1();
        greedy();
        cout << calc(ans) << endl;
    }
}

int main()
{
    input();
    //rand_test(10);
    greedy();
    incremental();
    output();
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll k;
    cin >> k;
    bool flag=0;
    ll r=7;
    ll cnt=1;
    rep(i,k) {
        if (r%k==0) {
            flag=1;
            break;
        }
        r=(10*r+7)%k;
        ++cnt;
    } 
    if (flag) cout << cnt << endl;
    else cout << -1 << endl;
    return 0;   
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int length = (s.length() - 1)/2;
    //cout << length << endl;
    string s1,s2;
    for(int i = 0; i<s.length(); i++){
        if(s[i]!=s[s.length()-i-1]){
            //cout << s[i] << s[s.length()-i-1] << endl;
            cout << "No" << endl;
            return 0;
        }
        if(i<length){
            if(s[i]!=s[length-i-1]){
                //cout << s[i] << s[length-i-1] <<endl;
                cout << "No" << endl;
                return 0;
            }
            if(s[s.length()-length+i]!=s[s.length()-i-1]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout <<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

using ll = long long;
using P = std::pair<ll, ll>;

const ll INF = 1ll<<60;

ll n, m, s, t;
std::vector<std::vector<P>> G1, G2;
std::vector<ll> d1, d2;

ll Y = 1000000000000000ll;

void dijkstra( ll src, std::vector<std::vector<P>> &G, std::vector<ll> &d )
{
  std::priority_queue<P, std::vector<P>, std::greater<P>> pque;

  d.assign( n+10, INF );
  d[src] = 0;

  pque.emplace( d[src], src );

  while( !pque.empty() )
  {
    P p = pque.top(); pque.pop();
    ll dist = p.first, v = p.second;

    for( auto u : G[v] )
    {
      if( chmin( d[u.first], d[v]+u.second ) )
        pque.emplace( d[u.first], u.first );
    }
  }

  return;
}

int main()
{
  std::cin >> n >> m >> s >> t;
  --s; --t;

  G1.resize( n+10 );
  G2.resize( n+10 );

  rep( i, m )
  {
    ll u, v, a, b;
    std::cin >> u >> v >> a >> b;
    --u; --v;

    G1[u].emplace_back( v, a );
    G1[v].emplace_back( u, a );
    G2[u].emplace_back( v, b );
    G2[v].emplace_back( u, b );
  }

  dijkstra( s, G1, d1 );
  dijkstra( t, G2, d2 );

  ll mi = INF;
  std::vector<ll> ans;

  repd( i, n )
  {
    chmin( mi, d1[i]+d2[i] );

    ans.emplace_back( mi );
  }

  repd( i, n )
    std::cout << Y-ans[i] << std::endl;

  return 0;
}

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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  
  int gcd = min(a, b);
  
  for(int i = gcd; i > 0; i--){
  	if(a==a/i*i && b==b/i*i){
    	break;
    }
  	else{
    	gcd--;
    }
  }
  int ans = gcd;
  int count = 0;
  while(count < k){
  	if(gcd/ans*ans== gcd){
    count++;
    }
  ans--;
  }
  cout << ans+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#define mod 1000000007
using namespace std;



int main()
{
    int m,n,o=0,i,j,k;
    int sum=0,range=0;
    //long long int m,n,o,i,j,k=0;
    //vector <int> v;
    //float f,g,h;
    //char c,d;
    //string a;
    cin>>m>>n>>o;
    do
    {
        if(abs(m)%2==1||abs(n)%2==1||abs(o)%2==1)
        {
            cout<<sum;
            return 0;
        }
        n-=m;
        o-=m;
        m-=m;
        i=(n+o)/2;
        j=(m+o)/2;
        k=(m+n)/2;
        sum++;
        m=i;
        n=j;
        o=k;
    }while(m!=0&&n!=0&&o!=0);
    cout<<-1;
    return 0;
}





Measured memory_bytes: 256
#define LOCAL0
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    #ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int k,a,b;
    cin>>k>>a>>b;
    if(a%k&&b%k&&(a/k==b/k)){
        cout<<"NG\n";
    }
    else cout<<"OK\n";
    return 0;
}

Measured memory_bytes: 3640
n,k = map(int,input().split())
s = input()
s_list = list(s)
if s_list[k-1] == 'A':
    s_list[k-1] = 'a'
elif s_list[k-1] == 'B':
    s_list[k-1] = 'b'
elif s_list[k-1] == 'C':
    s_list[k-1] = 'c'
print("".join(s_list))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,x,ans=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++){
        int count=0;
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                count=500*i+100*j+50*k;
                if(count==x)ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    map<ll,vector<pll>> Y;
    REP(i,0,M) {
        ll p, y;
        cin >> p >> y;
        Y[p].pb({y, i});
    }

    vector<pll> Z(M);
    FORR(y,Y) ASC(Y[y.first]);
    FORR(y,Y) {
        REP(i,0,SZ(y.second)) {
            ll k = y.second[i].second;
            Z[k].first = y.first;
            Z[k].second = i + 1;
        }
    }

    REP(i,0,M) {
        cout << setfill('0') << setw(6) << Z[i].first;
        cout << setfill('0') << setw(6) << Z[i].second << endl;
    }

    return 0;
}

/*



*/

Measured memory_bytes: 15488
#include <iostream>
#include <algorithm>
using namespace std;
int n;
 
 
int main() {
 
  cin >> n;
 
  int k;
  cin >> k;
 
  int a,b;
  int ans;
  for(int q=0;q<k;q++) {
 
    cin >> a >> b;
 
    ans =  n - a;
    //cout << ans << endl;
     ans = min (ans , n - (n - a+1));
     //cout << ans << endl;
    ans = min(ans, n - b);
    //cout << ans << endl;
    ans =  min(ans, n - (n - b+1));
    //    cout << ans << endl;
  
    cout << (ans)%3 +1<< endl;
 
  }
 
  return 0;
 
}

Measured memory_bytes: 1160
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
bool is_atgc(string s) {
	for (int i = 0; i < s.size(); ++i) {
		if (string("ATGC").find(s[i]) == string::npos) {
			return false;
		}
	}
	return true;
}
int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); ++i) {
		for (int j = i + 1; j <= s.size(); ++j) {
			if (is_atgc(s.substr(i, j - i))) {
				ans = max(ans, j - i);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int N; cin >> N;
	int A[100010];
	A[0]=A[N+1]=0;
	int sum=0;
	for(int i=1; i<=N; ++i){
	    cin >> A[i];
	    sum += abs(A[i]-A[i-1]);
	}
	sum += abs(A[N]);
	int ans;
	for(int i=1; i<=N; ++i){
	    ans=sum-(abs(A[i+1]-A[i])+abs(A[i]-A[i-1]))+abs(A[i+1]-A[i-1]);
	    cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n, m, a, b;
int res[50];

int main(int argc, char **argv) {
	cin >> n >> m;
	CLEAR(res);
	REP(i, m) {
		cin >> a >> b;
		--a; --b;
		++res[a]; ++res[b];
	}
	REP(i, n) cout << res[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  
  	for (int i = 0; i <= 1009; ++i) {
        int aa = i * 0.08;
        int bb = i * 0.1;
 
        if ( b == bb && a == aa) {
            cout << i << endl;
            return 0;
        }
    }
  
   cout << -1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
/*
 * 17-07-01_ARC077_D.cpp
 *
 *  Created on: 2017/07/01
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

typedef long long Int;
const Int MOD = 1e9 + 7;

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
Int extgcd(Int a, Int b, Int &x, Int &y) {
	Int g = a;
	x = 1;
	y = 0;
	if (b != 0)
		g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}
Int invMod(Int a, Int m) {
	Int x, y;
	if (extgcd(a, m, x, y) == 1)
		return (x + m) % m;
	else
		return 0; // unsolvable
}

Int memo[100010];
Int modFuct(Int a, Int m) {
	if (a == 0) {
		return 1;
	}
	if (memo[a] > 0) {
		return memo[a];
	}
	return memo[a] = modFuct(a - 1, m) * a % m;
}

Int C(Int n, Int r, Int m) {
	if (n < 2 * r)
		return C(n, n - r, m);
	Int res = 1;
	for (int i = 0; i < r; i++) {
		res = res * (n - i) % m;
	}
	res = res * invMod(modFuct(r, m), m) % m;
	return res;
}

int n;
int a[100010];
int ischeck[100010];
int L, R;
int main() {
	cin >> n;
	for (int i = 1; i <= n + 1; i++) {
		cin >> a[i - 1];
		if (ischeck[a[i - 1]] > 0) {
			L = ischeck[a[i - 1]] - 1;
			R = i - 1;
		}
		ischeck[a[i - 1]] = i;
	}
	Int Com=1,C2=1;
	for (int k = 1; k <= n + 1; k++) {
		Com = Com * (n-k+2)%MOD;
		Com = Com*invMod(k,MOD)%MOD;
		Int ans = Com;
		if (L + n - R >= k - 1) {
			C2 = C2*(L + n - R+2-k)%MOD;
			C2 = C2*invMod(k-1,MOD)%MOD;
			if(k==1){
				C2 = 1;
			}
			ans = (ans - C2 + MOD) % MOD;
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
#define MOD 1000000007
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = 2147493647;
const double pi = acos(-1);
const double EPS = 1e-9;

int main()
{
    int n;
    cin >> n;
    vector<double> A(n);
    rep(i,0,n) cin >> A[i];
    sort(A.begin(),A.end());
    double o = A[0];
    rep(i,1,n){
        o = (o+A[i])/2;
    }
    cout << fixed << setprecision(12) << o << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n = s=list(input())
li = list(map(int,input().split()))

ans = 1
for i in li:
    if(i == 0):
        ans = 0

for i in li:
    ans *= i
    if(ans > 1000000000000000000):
        ans = -1
        break
    
print(ans)

Measured memory_bytes: 21632
s = input()
n = len(s)

for i in range(n // 2):
    if s[i] != s[-i-1]:
        print('No')
        exit()
t = s[0:(n-1)//2]
n = len(t)
#print(t)
for i in range(n//2):
    if t[i] != t[-i-1]:
        print('No')
        exit()
t = s[(len(s)+3)//2-1:len(s)]
n = len(t)
#print(t)
for i in range(n//2):
    if t[i] != t[-i-1]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
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());
    string ans = "";
    for(int i = 0; i < n; i ++) ans += s[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        
        while (true) {
            int a = scanner.nextInt();
            String op = scanner.next();
            int b = scanner.nextInt();
            
            if ("?".equals(op)) {
                break;
            }
            
            switch(op) {
                case "+":
                    System.out.println(a + b);
                    break;
                case "-":
                    System.out.println(a - b);
                    break;
                case "*":
                    System.out.println(a * b);
                    break;
                case "/":
                    System.out.println(a / b);
                    break;
            }
        }
        
        
    }
}


Measured memory_bytes: 26332
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n;
    cin>>n;
    queue<int>q;
    vi ans;
    for(int i=1;i<10;i++)
    {
        q.push(i);
        ans.pb(i);
    }
    f(i,n)
    {
        int x=q.front();
        q.pop();
        int r=x%10;
        int y=x*10+r;
        if(r!=0)
        {
            q.push(y-1);
            ans.pb(y-1);
            
        }
        q.push(y);
        ans.pb(y);
        if(r!=9)
        {
            q.push(y+1);
            ans.pb(y+1);
        }
        
    }
    cout<<ans[n-1]<<endl;
    
    
    
    
    
    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll A, B;
    cin >> A >> B;
    if(A >= 13) _PR(B);
    else if(A >= 6) _PR(B/2);
    else _PR(0);

    return 0;
}

/*



*/

Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int n;
   double a[110];
   cin >> n;
   rep(i,n) cin >> a[i];


   double denom = 0;
   rep(i,n) denom += 1/a[i];

   double ans = 1/denom;

   cout << fixed << setprecision(6)  << ans << endl;


   return 0;
}

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

using namespace std;

int main(void)
{
    int n, u, k, v;
    cin >> n;
    vector<vector<int>> vec(n, vector<int>(n));
    
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            vec[u-1][v-1] = 1;
        }
    }
    
    for (auto& i : vec) {
        int cnt = 0;
        for (auto& j : i) {
            cout << j;
            cnt++;
            if (cnt != n) cout << " ";
        }
        cout << endl;
    }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
const int N = 110 , mz = 1e9+7;
char s[N],t[N];

int main(){
    cin>>s>>t;
    int n = strlen(s);
    for(int i = 0 ; i < n ; i++){
        bool can = 1;
        for(int j = 0 ; j < n ; j++){
            if( s[(i+j)%n] != t[j] ){
                can = 0;
                break;
            }
        }
        if( can )   return 0*puts("Yes");
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int L[N*2];
    rep(i,2*N){
        cin>>L[i];
    }
    sort(L,L+2*N);

    int ans=0;
    for(int i=0;i<2*N;i+=2){
        ans+=L[i];
    }
    cout << ans << endl;

    



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k,d,m,s,f;
    cin>>n>>k;
    d=n/k;
    m=n-(k*d);
    s=abs(k-m);
   f=min(m,s);
   cout<<f<<"\n";
   return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "1000 15 80" ].solve == "Yes" );
	assert( [ "2000 20 100" ].solve == "Yes" );
	assert( [ "10000 1 1" ].solve == "No" );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto d = 0L;
	auto t = 0L;
	auto s = 0L;
	input.front.formattedRead!"%s %s %s"( d, t, s );
	
	return ( ( d + s - 1 ) / s <= t ) ? "Yes" : "No";
}


Measured memory_bytes: 2920
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

struct Counter {
	int radix;
	vector<int> value;
	vector<int> base;

	Counter(int radix) {
		this->radix = radix;
		value.push_back(0);
		base.push_back(0);
	}

	void offset(int b) {
		if (b > base.back()) {
			base.push_back(b);
			value.push_back(0);
			return;
		}
		while (b < base.back()) {
			base.pop_back();
			value.pop_back();
		}
		if (base.back() != b) {
			base.push_back(b);
			value.push_back(0);
		}
		inc();
	}

	void inc() {
		if (radix == 1) {
			value[0]++;
			return;
		}

		while (++value.back() == radix && value.size() > 1) {
			int carried_base = base.back();
			base.pop_back();
			value.pop_back();

			if (carried_base - 1 != base.back()) {
				base.push_back(carried_base - 1);
				value.push_back(0);
			}
		}
	}

	bool is_valid() const {
		return value[0] == 0;
	}
};

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

	vector<int> a(n);
	for (int &v : a) {
		cin >> v;
	}

	auto ok = [&a](int mid){
		Counter counter(mid);
		for (int v : a) {
			counter.offset(v);
		}
		return counter.is_valid();
	};

	int low = 0, high = n;
	while (high - low > 1) {
		int mid = (low + high) / 2;

		(ok(mid) ? high : low) = mid;
	}

	cout << high << endl;

	return 0;
}


Measured memory_bytes: 4012
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		int m = sc.nextInt();

		double theta1 = 2*Math.PI*(h*60 + m)/720;
		double theta2 = 2*Math.PI*m/60;

//		System.out.println(theta1+ " "+theta2);

		double x1 = a*Math.cos(theta1);
		double y1 = a*Math.sin(theta1);
		double x2 = b*Math.cos(theta2);
		double y2 = b*Math.sin(theta2);

		System.out.println(Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)));
	}

}

Measured memory_bytes: 27196
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MAX 100007
#define MAXN 1007
#define MAXM 1007
#define INF  0x3f3f3f3f
#define NINF 0xc0c0c0c0
#define MOD 1000000007
const double EXP=1e-10;
using namespace std;
typedef long long ll;
typedef vector<ll> Vec;
typedef vector<Vec> Mat;
//================================================================================================
ll n,c;
ll x[MAX];
ll mx[MAX]; 
ll v[MAX];
ll ans,t,maxs;
int main(){
	scanf("%lld%lld",&n,&c);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",x+i,v+i);
	}
	t=0;
	for(int i=1;i<=n;i++) {
		t+=v[i];
		if(t-x[i]>mx[i-1]) 
			mx[i]=t-x[i];
		else
			mx[i]=mx[i-1];
	}
	ans=max(ans,mx[n]);
	t=0;
	for(int i=n;i>=1;i--) {
		t+=v[i];
		ans=max(ans,t-2*(c-x[i])+mx[i-1]);
	}
	t=0;
	for(int i=n;i>=1;i--) {
		t+=v[i];
		if(t-c+x[i]>mx[i+1]) 
			mx[i]=t-c+x[i];
		else
			mx[i]=mx[i+1];
	}
	t=0;
	ans=max(ans,mx[1]);
	for(int i=1;i<=n;i++) {
		t+=v[i];
		ans=max(ans,t-2*x[i]+mx[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int a[105];
int sum1[105],sum2[105];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int sum=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
            sum1[i]=sum;

        }
        sum=0;
        for(int i=n-1; i>=0; i--)
        {
            sum+=a[i];
            sum2[i]=sum;
        }
        int i,j;
        int Min=10000;
        for(i=0; i<n; i++)
        {
            int ans=abs(sum1[i]-sum2[i]-a[i]);
            if(ans<Min) Min=ans;
        }
        printf("%d\n",Min);






    }




    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;cin>>n>>m;
  ll in=1000000000000000;
  ll a[m],b[m],c[m];
  vector<pair<ll,ll>>list[n+1];
  for(ll i=0;i<m;i++){
    cin>>a[i]>>b[i]>>c[i];
    list[a[i]].push_back(make_pair(b[i],c[i]));
    c[i]=-c[i];
  }
  ll score[n+1];
  //cout<<list[1][1].first<<list[1][1].second<<endl;return 0;
  for(ll i=0;i<=n;i++)score[i]=in;
  score[1]=0;
  ll ans;
  for(ll i=0;i<n-1;i++){
    for(ll j=0;j<m;j++){
      if(score[a[j]]!=in){
          if(score[b[j]]>score[a[j]]+c[j]){
            score[b[j]]=score[a[j]]+c[j];
          }
      }
    }
    if(i==n-2)ans=score[n];
    
  }
  bool update[n+1];
  for(ll i=0;i<=n;i++)update[i]=false;
  for(ll i=0;i<n;i++){
    for(ll j=0;j<m;j++){
      if(score[a[j]]!=in){
          if(score[b[j]]>score[a[j]]+c[j]){
            score[b[j]]=score[a[j]]+c[j];
            update[b[j]]=true;
          }
        if(update[a[j]])update[b[j]]=true;
      }
    }
  }
  if(update[n])cout<<"inf";
  else cout<<-ans<<endl;
}


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

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

  ll N; cin >> N;
  vector<ll> X(N), Y(N), P(N);
  for (ll i = 0; i < N; i++) {
    cin >> X[i] >> Y[i] >> P[i];
  }

  ll MAX = (1 << N);
  vector<vector<ll>> dX(MAX, vector<ll>(N));
  vector<vector<ll>> dY(MAX, vector<ll>(N));

  for (ll i = 0; i < MAX; i++) {
    for (ll j = 0; j < N; j++) {
      dX[i][j] = abs(X[j]);
      dY[i][j] = abs(Y[j]);

      for (ll k = 0; k < N; k++) {
        if ((i >> k) & 1) {
          dX[i][j] = min(dX[i][j], abs(X[j] - X[k]));
          dY[i][j] = min(dY[i][j], abs(Y[j] - Y[k]));
        }
      }
    }
  }

  ll INF = 1e18;
  vector<ll> ans(N + 1, INF);
  for (ll i = 0; i < MAX; i++) {
    ll cnt = 0;
    for (ll k = 0; k < N; k++) if ((i >> k) & 1) cnt++;

    for (ll j = i; j >= 0; j--) {
      j &= i;
      ll cost = 0;
      for (ll k = 0; k < N; k++) {
        cost += min(dX[j][k], dY[i - j][k]) * P[k];
      }
      ans[cnt] = min(ans[cnt], cost);
    }
  }

  for (ll i = 0; i < N + 1; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 12968
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=100010;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}
int n,num[maxn],book[21],s;
int f[(1<<17)+10],ans;
int dp(int s)
{
	if(!s)
		return 0;
	if(f[s])
		return f[s];
	f[s]=INF;
	for(int i=1;i<=15;i++)
	{
		if(!(s&(1<<i)))
			continue;
		for(int j=1;j<=15;j++)
		{
			if(i==j||!(s&(1<<j)))
				continue;
			int k=i^j;
			int t=s^(1<<i)^(1<<j)^(1<<k);
			if(s&(1<<k))
				f[s]=min(f[s],dp(t)+2);
			else
				f[s]=min(f[s],dp(t)+1);
		}
	}
	return f[s];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		num[a]^=c;
		num[b]^=c;
	}
	for(int i=0;i<n;i++)
		book[num[i]]++;
	for(int i=1;i<=15;i++)
	{
		ans+=(book[i]>>1);
		s|=((book[i]&1)<<i);//奇数最后剩下
	}
	printf("%d",ans+dp(s));
	return 0;
}

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

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

int main() {
    int a[4];
    rep(i,4)cin>>a[i];
    int s,t;
    s = max(a[0],a[2]);
    t = min(a[1],a[3]);
    
    int ans = max(t - s, 0);
    cout<<ans<<endl;
	return 0;
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rrep(i,n) for(ll i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
#define rrep1(i,n) for(ll i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  vector<ll>count(n+1);
  rep1(i, n){
    ll c = i;
    while(c<=n){
      count[c]++;
      c+=i;
    }
  }

  ll sum=0;
  rep(i, n+1)sum += i*count[i];

  cout<<sum<<endl;

  return 0;
}

Measured memory_bytes: 81412
n,k=map(int,input().split())
l=[list(map(int, input().split())) for i in range(n)]
r=[0]*(10**5+1)
for i in range(n):
    r[l[i][0]]+=l[i][1]
#print(r[:10])
c=0
for i in range(1,10**5+1):
    c+=r[i]
    if k<=c:
        print(i)
        break

Measured memory_bytes: 30164
import math
def scanf(scanstr,data_format):
    scanstr=scanstr.split(" ")
    if(type(data_format) is not list):
        print("data_format error")
    if(len(scanstr)!=len(data_format)):
        print("Error")
        return -1
    j=0
    for kata in data_format:
        if(kata=="str"):
            scanstr[j]=str(scanstr[j])
        if(kata=="int"):
            scanstr[j]=int(scanstr[j])
        j=j+1
    return scanstr
d=scanf(input(),["int","int","int"])
if (d[2]-d[0]-d[1]>0)and(4*d[0]*d[1]<(d[2]-d[0]-d[1])*(d[2]-d[0]-d[1])):
    print("Yes")
else :
    print("No")


Measured memory_bytes: 3064
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  //cout<<fixed<<setprecision(10);
  ll n,ans=MOD;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll sum=a+b+c+d;
  ans=min(ans,abs(sum-2*(a+b)));
  ans=min(ans,abs(sum-2*(a+c)));
  ans=min(ans,abs(sum-2*(a+d)));
  ans=min(ans,abs(sum-2*(b+c)));
  ans=min(ans,abs(sum-2*(b+d)));
  ans=min(ans,abs(sum-2*(c+d)));
  cout<<ans<<endl;
}



Measured memory_bytes: 3112
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    ll n;
    cin>>n;
    vector<ll> d(n);
    rep(i,n){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    ll a=d[n/2]-d[(n/2)-1];
    cout<<a<<endl;
}


Measured memory_bytes: 1024
while True:

    h, w = map(int, input().split())
    sharp = "#"
    cnt = 1

    if h == 0 and w == 0:
        break

    for i in range(h):

        if cnt == 1 or cnt == h:
            linesharp = sharp * w
            print(linesharp)
        else:
            dot = "." * (w - 2)
            print(f"{sharp}{dot}{sharp}")
        cnt+=1

    print("")




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

int main(){
  int i,j,a,b,c,_1000,_500,_100;
  while(1){
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    c = b - a;
    _1000 = _500 = _100 = 0;
    while(c >= 1000){
      _1000++;
      c -= 1000;
    }
    while(c >= 500){
      _500++;
      c -= 500;
    }
    while(c >= 100){
      _100++;
      c -= 100;
    }

    cout << _100 << " "<< _500 << " "<< _1000 << endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,M=1e9+7;
string s;
int dp[5002][5003];
int calc(int i,int p){
	if(p==n)return (i==s.size())?1:0;
	int &ret=dp[i][p];
	if(ret!=-1)return ret;
	ret=(2ll*calc(i+1,p+1)+calc(max(0,i-1),p+1))%M;
	return ret;
}
ll pp(ll n,ll p ){
	if(!p)return 1;
	ll ret=pp(n,p/2);
	if(p&1)return ((ret*ret)%M*n)%M;
	return (ret*ret)%M;
}
int main() {
	cin>>n>>s;
	memset(dp,-1,sizeof dp);
	ll ans=calc(0,0);
	ll inv=pp(2,s.size());
	ans=(ans*pp(inv,M-2))%M;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 98304
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element


signed main()
{
	int A, B, C;
	cin >> A >> B >> C;
	YesNo((A == B && A != C) || (A == C && B != C) || (B == C && A != C));
}




Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

vector<int>E[200005];
int goal[200005];

int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	int i,j;

	for(i=0;i<M;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		E[a].push_back(b);
		E[b].push_back(a);
		if(a==N){goal[b]=1;}
		if(b==N){goal[a]=1;}
	}
	int flag=0;
	for(i=0;i<E[1].size();i++){
		if(goal[E[1][i]]==1){flag=1;}
	}

	if(flag==1){printf("POSSIBLE\n");}
	else{printf("IMPOSSIBLE\n");}


	return 0;
}

Measured memory_bytes: 12784
n = int(input())
h = list(map(int, input().split()))

dp = [0]*(n+1)

for i in range(1,n):
  if i<2:
    dp[i] = abs(h[i]-h[i-1])
  else:
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13980