akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

long long n,m;

void solve(istream& cin, ostream& cout) {
	cin >> n >> m;
	cout << (n*(n-1)/2+m*(m-1)/2) << endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 764
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
int main(){
    int n;cin>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    VV dp(n+1,V(n+1));//[i,j)の範囲
    for(int i=1;i<=n;i++){//length小さいほうから
        for(int j=0;j+i<=n;j++){//左
            int k=i+j;//右
            if((n-i)%2==0){//先手 遷移するイメージ
                dp[j][k]=max(dp[j+1][k]+vec[j],dp[j][k-1]+vec[k-1]);
            }else{//後手
                dp[j][k]=min(dp[j+1][k]-vec[j],dp[j][k-1]-vec[k-1]);
            }
        }
    }
    cout<<dp[0][n]<<endl;
}


Measured memory_bytes: 70784
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  vector<int> counts(s.length());
  counts[0] = 0;
  for(int i=1;i<=s.length();i++) {
    if(s[i-1] == 'A' && s[i] == 'C') {
      counts[i] = counts[i-1] + 1;
    } else {
      counts[i] = counts[i-1];
    }
  }

  int l, r;
  REP(i, q) {
    cin >> l >> r;
    cout << counts[r-1] - counts[l-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 1488
#include <stdio.h>

  long long factorial(int a){
    int i;
  long long fac = 1;
  for(i=a; i>0; i--){
    fac = fac * i;
  }
  return fac;
}

int main(void)
{
  int n;

  scanf("%d",&n);

  printf("%lld\n",factorial(n)); 

  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,d;
	string s,t;
	cin>>n>>s>>d;
	t=s;
	rep(i,0,n){
		if(d==0) break;
		if(s[i]=='0'){
			t[i]='1';
			d--;
		}
	}
	for(int i=n-1;i>=0;i--){
		if(d==0) break;
		if(s[i]=='1'){
			t[i]='0';
			d--;
		}
	}
	o(t);
}

Measured memory_bytes: 1208
//
// Created by sark2 on 14-01-2020.
//

#include "bits/stdc++.h"

using namespace std;
#define pb push_back
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define CASES int t;cin>>t;while(t--)

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;

int main() {
    IOS
    string s;
    cin>>s;

    int n = s.length();

    for(int i = 0; i < n; i++)
        cout<<'x';


}


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

// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  //初期化子リストを用いた初期化
  //mint型が負にならないようにする
  mint(ll x=0):x((x%mod+mod)%mod){}
  
  //mintが負になったときの処理
  //constメンバ関数、メンバ変数の書き換えができなくなる
  mint operator-() const { return mint(-x);}//mint型にキャスト
  
  //代入演算子のオーバーロードは*thisを参照として返すようにする
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  //逆元
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint choose(ll n, ll r) {
  mint x = 1, y = 1;
  rep(i,r) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  mint ans = mint(2).pow(n);
  ans -= 1;
  ans -= choose(n,a);
  ans -= choose(n,b);
  cout << ans.x;
}


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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)


int main() {
  string a,b;
  cin >> a >> b;
  int ans = 0;
  REP(i,3) ans += a[i]==b[i]; 
  cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int H, W; cin >> H >> W;
  vector<string> board;
  REP(i, H) {
    string row; cin >> row;
    board.emplace_back(row);
  }

  vector<vector<int>> ans(H, vector<int>(W, 1));
  REP(r, H) {
    int now = 0, now_rev = 0;
    REP(c, W) {
      if (board[r][c] == '#') {
        now = 0;
      } else {
        ans[r][c] += now;
        now++;
      }

      if (board[r][W-c-1] == '#') {
        now_rev = 0;
      } else {
        ans[r][W-c-1] += now_rev;
        now_rev++;
      }
    }
  }

  REP(c, W) {
    int now = 0, now_rev = 0;
    REP(r, H) {
      if (board[r][c] == '#') {
        now = 0;
      } else {
        ans[r][c] += now;
        now++;
      }

      if (board[H-r-1][c] == '#') {
        now_rev = 0;
      } else {
        ans[H-r-1][c] += now_rev;
        now_rev++;
      }
    }
  }

  int ans_val = 0;
  REP(i, H) REP(j, W) ans_val = max(ans_val, ans[i][j]);
  cout << ans_val << endl;
  //REP(i, H) REP(j, W) cout << ans[i][j] << (j == W-1 ? '\n' : ' ');


  return 0;
}


Measured memory_bytes: 22272
n=gets.to_i
if n<105 then
  puts 0
elsif n>=105 && n<135 then
  puts 1
elsif n>=135 && n<165 then
  puts 2
elsif n>=165 && n<189 then
  puts 3
elsif n>=189 && n<195 then
  puts 4
elsif n>=195 then
  puts 5
end

Measured memory_bytes: 3836
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int N[1000],M[1000],hyo[1000]={0};
int n,m;
cin>>n>>m;
int tmp;
for(int i=0;i<n;i++)cin>>N[i];
for(int i=0;i<m;i++)cin>>M[i];

	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(M[i]>=N[j]){
			hyo[j]++;
			break;
			}
		}
	}
	//for(int i=0;i<10;i++)cout<<hyo[i]<<endl;
	int a=0;int ma=0;
	for(int i=0;i<n;i++){
		if(hyo[i]>ma)ma=hyo[i],a=i+1;
	}
	//if(a==0)cout<<1<<endl;
	cout<<a<<endl;


return 0;
}

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

int d;
ll pow2[64];
void dfs(int i, int num1, int num2, ll rem, vector<int> &v)
{
    if (i == d)
    {
        for (auto c : v)
            cout << c;
        cout << "\n";
        return;
    }
    if (num2 == -1)
    {
        for (int j = 0; j <= 9; j++)
        {
            if (j == num1)
            {
                ll t = (pow2[d - i - 1] - 1) * 9;
                if (rem <= t)
                {
                    v.emplace_back(j);
                    dfs(i + 1, num1, -1, rem, v);
                    return;
                }
                rem -= t;
            }
            else
            {
                ll t = pow2[d - i - 1];
                if (rem <= t)
                {
                    v.emplace_back(j);
                    dfs(i + 1, num1, j, rem, v);
                    return;
                }
                rem -= t;
            }
        }
        assert(0);
    }
    else
    {
        int Max = max(num1, num2);
        int Min = min(num1, num2);
        ll t = pow2[d - i - 1];
        if (rem <= t)
        {
            v.emplace_back(Min);
            dfs(i + 1, num1, num2, rem, v);
        }
        else
        {
            v.emplace_back(Max);
            dfs(i + 1, num1, num2, rem - t, v);
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i, 64)
    {
        pow2[i] = (1LL << i);
    }
    while (1)
    {
        ll n;
        cin >> n;
        if (n == 0)
            break;
        auto g = [](int t) {
            return (pow2[t - 1] - 1) * 9 * 9;
        };

        // 桁数
        for (int di = 2;; di++)
        {
            if (n - g(di) <= 0)
            {
                d = di;
                ll t = (pow2[d - 1] - 1) * 9;
                for (int i = 1; i <= 9; i++)
                {
                    if (n <= t)
                    {
                        vector<int> temp;
                        temp.emplace_back(i);
                        dfs(1, i, -1, n, temp);
                        break;
                    }
                    else
                    {
                        n -= t;
                    }
                    if (i == 9)
                        assert(0);
                }
                break;
            }
            else
            {
                n -= g(di);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3168
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    if a <= 9 && b <= 9 {
        println!("{}", a * b);
    } else {
        println!("{}", -1);
    }
}


Measured memory_bytes: 4352
import java.util.*
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d: String = " ") = str().split(d)
fun <T> list(d: String = " ", f: String.() -> T) = read(d).map { f(it) }
fun list() = list { toInt() }

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 1000000007L

fun main() {
    abc000X()
}

fun abc000X() {
    val n = int()
    (1..n).map { (n - 1L) / it }.sum().let { println(it) }
}


Measured memory_bytes: 50312
S = gets.chomp
a = (S[0]+S[1]).to_i
b = (S[2]+S[3]).to_i

if a >= 1 && a <= 12 then
    if b >= 1 && b <= 12 then
        print 'AMBIGUOUS'
    else
        print 'MMYY'
    end
else
    if b >= 1 && b <= 12 then
        print 'YYMM'
    else
        print 'NA'
    end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
const int N = 3000;
 
int a,b,c,d,e,f,ans,total;
int dp[N+10][N+10];
 
void dfs(int sugar,int water){
    if (dp[sugar][water]!=-1) return;
    dp[sugar][water] = 1;
    if (sugar*100>e*water) return;
    if (sugar+water>f) return;
    if (total==0 || sugar*total>ans*(sugar+water)){
        if (water>0){
            ans = sugar;
            total = sugar + water;
        }
    }
    dfs(sugar,water+100*a);
    dfs(sugar,water+100*b);
    dfs(sugar+c,water);
    dfs(sugar+d,water);
}
 
int main(){
    //freopen("F:\\rush.txt","r",stdin);
    memset(dp,255,sizeof dp);
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> a >> b >> c >> d >> e >> f;
    dfs(0,0);
    cout << total << ' '<< ans << endl;
    return 0;
}

Measured memory_bytes: 39044
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
//#define int long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const int maxn=190;
int n,m,sum[maxn][maxn],a[maxn][maxn],dp[maxn][maxn][maxn][15];
char ch[maxn][maxn];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		putchar('-');
		putchar('1');
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		scanf("%s",ch[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			if(ch[i][j]=='.')
				a[i][j]=1;
			else
				a[i][j]=0;
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
		}
	for(int shang=1;shang<=n;++shang)
		for(int zuo=1;zuo<=m;++zuo)
			for(int you=zuo;you<=m;++you)
			{
				int l=shang,r=n,xia=shang-1;
				while(l<=r)
				{
					int mid=(l+r)>>1;
					int geshu=sum[mid][you]-sum[mid][zuo-1]-sum[shang-1][you]+sum[shang-1][zuo-1];
					if(!geshu||geshu==(mid-shang+1)*(you-zuo+1))
						xia=mid,l=mid+1;
					else
						r=mid-1;
				}
				dp[shang][zuo][you][0]=xia;
//				cout<<shang<<' '<<zuo<<' '<<you<<' '<<xia<<endl;
			}
	int k;
	for(k=1;dp[1][1][m][k-1]<n;++k)
		for(int kuan=1;kuan<=m;++kuan)
			for(int shang=1;shang<=n;++shang)
				for(int zuo=1,you=zuo+kuan-1;you<=m;++zuo,++you)
				{
					if(dp[shang][zuo][you][k-1]==n)
					{
						dp[shang][zuo][you][k]=n;
						continue;
					}
					dp[shang][zuo][you][k]=dp[dp[shang][zuo][you][k-1]+1][zuo][you][k-1];
					if(dp[shang][zuo][you][k]==n)
						continue;
					int l=zuo,r=you-1,kotae=0;
					while(l<=r)
					{
						int mid=(l+r)>>1;
						int x=dp[shang][zuo][mid][k-1],y=dp[shang][mid+1][you][k-1];
						kotae=max(kotae,min(x,y));
						if(x<y)
							r=mid-1;
						else
							l=mid+1;
					}
					dp[shang][zuo][you][k]=max(dp[shang][zuo][you][k],kotae);
				}
	write(k-1);
    return 0;
}


Measured memory_bytes: 393856
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}


#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;


template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};
int n;
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
template< typename T >
vector< T > bellman_ford(Edges< T > &edges, int V, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(V, INF);
  dist[s] = 0;
  for(int i = 0; i < V - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.src] == INF) continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }
  for(auto &e : edges) {
    if(dist[e.src] == INF) continue;
    if(dist[e.src] + e.cost < dist[e.to]&&e.to==n) return vector< T >();
  }
  return dist;
}

main(){
    int n;
    cin>>n;
    vector<vector<char>> v;
    rep(i,n){
        string s;
        cin>>s;
        vector<char>c;
        rep(j,s.size()){
            c.pb(s[j]);
        }
        sort(all(c));
        v.pb(c);
    }
    sort(all(v));
    ll now=0;
    ll ans=0;
    while(now<n){
        int pre=now;
        while(v[pre]==v[now])now++;
        ans+=(now-pre)*(now-pre-1)/2;
    }
    cout<<ans;
}



Measured memory_bytes: 6708
while True:
    n = int(input())
    if n == 0: break

    totalp = 0
    P = list(map(int, input().split()))
    for p in P:
        totalp += p
    J = list(map(int, input().split()))

    maxv = 0
    J.sort(reverse=True)
    J.append(0); # nazo
    totalj = 0
    t = n
    j = 0
    while t >= 1:
        v = t*(totalj + totalp)
        totalj += J[j]
        maxv = max(v, maxv)
        t = t - 1
        j = j + 1

    print(maxv)


Measured memory_bytes: 8088
import java.util.Scanner;

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

        System.out.println(get(a, b) + get(a, b));
    }

    private static int get(final int[] a, final int[] b) {
        if (a[0] > b[0]) {
            return a[0]--;
        }

        return b[0]--;
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n,k;
    cin >> n;
    cin >> k;

    int ans = 0;
    rep(i,n){
        int tmp;
        cin >> tmp;
        
        ans += min(tmp, k - tmp) * 2;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int l = s.nextInt();
		int r = s.nextInt();
		int d = s.nextInt();
		
		System.out.println(r/d-(l-1)/d);
	}

}

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

int main(){
    ll A;
    long double B;
    cin >> A >> B;
    ll ans = A*B;
    cout << ans << endl;
}

Measured memory_bytes: 3656
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(n-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        count+=1
    if p[i]>p[i+1] and p[i+1]>p[i+2]:
        count+=1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
 int N;
 cin>>N;
 vector<int>A(N);
 int countk=0;
 for(int i=0;i<N;i++){
     cin>>A[i];
     if(A[i]%2!=0){countk++;}
 }
 if(countk%2!=0){cout<<"NO"<<endl;}
 else{cout<<"YES"<<endl;}

 return 0;}

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

int main(){
  ll n;
  cin >> n;
  vector<string> sx(n);
  rep(i,n,0){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    sx[i] = s;
  }
  sort(sx.begin(), sx.end());
  ll ans = 0, sum = 1;
  rep(i,n,1){
    if(sx[i] != sx[i-1]){
      ans += sum*(sum-1)/2;
      sum = 1;
    }
    else sum++;
  }
  ans += sum*(sum-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 5760
n=int(input())
a=0
w=0
t=0
r=0
for i in range(n):
    code=input()
    if code=='AC':
        a += 1
    elif code=='WA':
        w += 1
    elif code=='TLE':
        t += 1
    else:
        r += 1
print('AC x ',a)
print('WA x ',w)
print('TLE x ',t)
print('RE x ',r)

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

int main(void){
    int N; cin >> N;
    string S;
    ll CNT[5] = {0};
    for (int i = 0; i < N; i++)
    {
        cin >> S;
        if(S[0] == 'M') CNT[0]++;
        if(S[0] == 'A') CNT[1]++;
        if(S[0] == 'R') CNT[2]++;
        if(S[0] == 'C') CNT[3]++;
        if(S[0] == 'H') CNT[4]++;
    }

    ll ans = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = i+1; j < 4; j++)
        {
            for (int k = j+1; k < 5; k++)
            {
                ans += CNT[i]*CNT[j]*CNT[k];
            }
            
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int count = 0;
    int x,y;
    x = n/7;
    y = n/4;
    bool df =false;
    for(int a = 0;a <= x;a++){
        for(int b = 0;b <= y;b++){
            int jk = 7*a + 4*b;
            if(jk == n){
                df = true;
            }
        }
    }
    if(df){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  string s;
  cin >> s;
  int res = 0;
  FOR(i,0,SZ(s)-1)
    if (s[i] == '-') res--;
  else res++;
  cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
    fast;
    int n,k,temp=1;
  	cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=k;i<n;i++)
    {
        if(a[i]>a[i-k]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM 
                                  MMMM
                                   MM
*/


Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
#define rem 1000000007
long long fact[200003]={1}, inv[200003], factinv[200003];

long long comb(int h, int w){
    //cout<<fact[h+w-2]/(fact[h-1]*fact[w-1])<<endl;
    return fact[h+w-2]*factinv[h-1]%rem*factinv[w-1]%rem;
}

int main(){
    int h,w, a,b; 
    long long f=1, answer=0;
    for(int i =1;i<200003; i++){
        fact[i]=(fact[i-1]*i)%rem;
    }

    inv[1] = 1; for (int i = 2; i < 200003; i++) inv[i] = 1LL * inv[rem % i] * (rem - rem / i) % rem;
	factinv[0] = 1; for (int i = 1; i < 200003; i++) factinv[i] = 1LL * factinv[i - 1] * inv[i] % rem;

    cin>>h>>w>>a>>b;
    int w1 = b, w2 = w-b;
    int counter=2000;
    for(int i =1; i<=h-a; i++){
        answer+= comb(i, w1)*comb(h-i+1, w2)%rem;
        //if(i<10)
        //cout<<"comb of "<<i<<" and "<<w1<<" equals "<<comb(i, w1)<<"comb of "<<h-i+1<<" and "<<w2<<" equals "<<comb(h-i+1, w2)<<endl;
        answer%=rem;
    }

    cout<<answer;

    return 0;
}

Measured memory_bytes: 4992
import numpy as np

H, W, M = map(int, input().split())
row = np.zeros(W)
col = np.zeros(H)
memo = []
for _ in range(M):
    h, w = map(int, input().split())
    h -=1
    w -=1
    row[w] += 1
    col[h] += 1
    memo.append((h, w))

col_max = col.max()
row_max = row.max()

max_col_indexes = np.where(col == col_max)[0]
max_row_indexes = np.where(row == row_max)[0]

ans = col_max + row_max -1
memo = set(memo)
for c in max_col_indexes:
    for r in max_row_indexes:
        if (c, r) not in memo:
            ans = ans = col_max + row_max
            print(int(ans))
            exit()

print(int(ans))

Measured memory_bytes: 89104
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n,t,a,h,ha,hmin,hdiff,ans=0;
    cin>>n>>t>>a;
    ha=(t-a)/0.006;
    for(int i=1;i<=n;i++)
    {
        cin>>h;
        if(ha>=h)
            hdiff=ha-h;
        else
            hdiff=h-ha;
        if(i==1 || hmin>hdiff)
        {
            hmin=hdiff;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
mod = 998244353
N = int(input())
X = input()

d = []
for n in range(1,N+1):
    if N%n==0 and (N//n)%2==1:
        d.append(n)

p_d = {}

for n in d:
    p_d[n] = 0
    S = []
    for i in range(N):
        j = i//n
        if X[i%n]=='0':
            if j%2==0:
                S.append('0')
            else:
                S.append('1')
        else:
            if j%2==0:
                S.append('1')
            else:
                S.append('0')

    S = ''.join(S)
    s = X[:n][::-1]
    for i in range(n):
        if s[i]=='1':
            p_d[n] += pow(2,i,mod)
    if S<=X:
        p_d[n] += 1

ans = 0
for i in range(len(d)):
    n = d[i]
    for j in range(i):
        m = d[j]
        if n%m==0:
            p_d[n] -= p_d[m]
    ans += p_d[n]*2*n
ans %= mod
print(ans)


Measured memory_bytes: 123272
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    char s[(a+b+1)];
    cin>>s;
    int i;
    int ck1=0,ck2=0;

    if(s[a]=='-'){
        for(i=0;i<a;i++){
            if(s[i]>='0'&&s[i]<='9'){
                ck1++;
            }
            else{
                break;
            }
        }
        for(i=a+1;i<=a+b;i++){
            if(s[i]>='0'&&s[i]<='9'){
                ck2++;
            }
            else{
                break;
            }
        }
        if(ck1==a&&ck2==b){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }

    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 102
int n;
int f[MAXN][11], p[MAXN][11], ans = -1000000000;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10; j++){
            cin >> f[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 11; j++){
            cin >> p[i][j];
        }
    }
    for(int i = 1; i < 1024; i++){
        int rec = 0;
        for(int j = 0; j < n; j++){
            int joisino = 0;
            for(int k = 0; k < 10; k++){
                if(i >> k & 1){
                    if(f[j][k]){
                        joisino++;
                    }
                }
            }
            rec += p[j][joisino];
        }
        ans = ans < rec ? rec : ans;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0)  break;
        vector<string> S(n);
        vector<int> N(n);
        for(int i=0;i<n;i++){
                cin >> S.at(i);
                N.at(i) = S.at(i).size();
        }

        for(int i=0;i<n;i++){
            int j=i;
            int m=N.at(j);
            while(m<5){
                m += N.at(j+1);
                j++;
            }
            if(m>5) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;
            j++;
            
            m=N.at(j);
            while(m<5){
                m += N.at(j+1);
                j++;
            }
            if(m>5) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;

            cout << i+1 << endl;
            break;
        }


    }
}


Measured memory_bytes: 3180
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();
		String[] cut = input.split(" ");
		int a = Integer.parseInt(cut[0]);
		int b = Integer.parseInt(cut[1]);
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else if (a == b) {
			System.out.println("a == b");
			
		}

	}
}

Measured memory_bytes: 24188
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
war=[]
for i in range(m):
    start,end=map(int,input().split())
    war.append([start,end])
war=sorted(war,key=lambda x:x[1])
end=0
ans=0
for i in war:
    if i[0]>=end:
        ans+=1
        end=i[1]
print(ans)

Measured memory_bytes: 89568
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//---------------from here-----------------

int main(){
    int n; cin>>n;
    bool can=false;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            if(i*j==n){
                can=true;
                break;
            }

        }
        if(can==true) break;
    }
    cout<<(can==true ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int N;
  long A, B;
  long X[100000];
  int i;
  long val;
  long ans = 0;

  scanf("%d %ld %ld", &N, &A, &B);
  for(i = 0; i < N; i++) {
    scanf("%ld", &X[i]);
  }

  for(i = 0; i < N-1; i++) {
    val = (X[i+1]-X[i])*A;
    if(val < B) {
      ans += val;
    } else {
      ans += B;
    }
  }

  printf("%ld\n", ans);
  
  return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    vll j(10000000);
    j[0] = 1;
    for(int i = 1; i < 10000000; i++) {
        j[i] = j[i-1]*2;
    }

    ll h; cin  >> h;
    ll ans = 0;
    int i = 0;
    //debug(ans);
    while(h>0) {
        h /= 2;
        ans += j[i];
        i++;
        //debug(h);
        //debug(j[i]);
        //debug(ans);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 78336
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
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; }

int main()
{
	cout << fixed << setprecision(18);

	ll n, m, x;
	cin >> n >> m >> x;

	vector<ll> c(n);
	ll a[15][15];

	rep(i, n) {
		cin >> c[i];
		rep(j, m)
			cin >> a[i][j];
	}

	ll min = INF;

	ll cost = 0;
	rep(k, 1 << n) {
		cost = 0;
		vector<ll> u(m, 0);
		rep(i, n) {
			if ((1 << i) & k) {
				cost += c[i];
				rep(j, m)
					u[j] += a[i][j];
			}
		}
		ll f = true;
		rep(j, m)
		{
			if (u[j] < x) {
				f = false;
				break;
			}
		}
		if (f)
			chmin(min, cost);
	}

	if (min == INF)
		min = -1;

	cout << min << endl;

	return 0;
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){

		int[] a=new int[31];
		
		a[0]=0;
		a[1]=1;
		a[2]=2;
		a[3]=1+4;
		for(int i=4;i<=30;i++){
			a[i]=a[i-2]+3*(a[i-2]-a[i-4]);
		}
		String s="";
		while((s=Console.ReadLine())!=null){
			Console.WriteLine(a[int.Parse(s)]);
		}
	}
}

Measured memory_bytes: 5604
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
using namespace std;

#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair

ll ans=10000000;

void getans(vector<vector<ll> > books,ll n,ll m,ll x,ll book,vector<ll> my)
{
        
    bool flg=true;
    
    for(ll i=1;i<=m;i++)
    {
        if(my[i]<x)
        {
            flg=false;
            break;
        }
    }
    
    if(flg)
    {
        ans=min(ans,my[0]);
        return ;
    }
    
    if(book==n)
    {
        return ;
    }
    
    getans(books,n,m,x,book+1,my);
    
    for(ll i=0;i<=m;i++)
    {
        my[i]+=books[book][i];
    }
    
    getans(books,n,m,x,book+1,my);
    
}

int solve()
{
   ll n,m,x;
   cin>>n>>m>>x;
   
   vector<vector<ll> > books;
   
   for(ll i=0;i<n;i++)
   {
       vector<ll> b;
       
       for(ll j=0;j<=m;j++)
       {
           ll num;
           cin>>num;
           b.pb(num);
       }
       books.pb(b);
   }
   
   vector<ll> my(m+1,0);
 
 
   getans(books,n,m,x,0,my);
 
 
   if(ans!=10000000)
    cout<<ans<<endl;
else
    cout<<-1<<endl;

    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*ll t;
    cin>>t;
    while(t--)*/
        solve();

    return 0;
}


Measured memory_bytes: 3684
#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>

using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue



typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;
typedef pair<ll,int>pli;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9+9;
const double esp = 1e-8;
const double PI=acos(-1.0);
const double PHI=0.61803399;    //黄金分割点
const double tPHI=0.38196601;


template<typename T>
inline T 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*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
/*-----------------------showtime----------------------*/
            const int maxn = 1e5+9;

            int in[maxn],vis[maxn];
            int pa[maxn];
            queue<int>que;
            vector<int>mp[maxn];
int main(){
            int n,m;
            scanf("%d%d", &n, &m);
            for(int i=1; i<= n-1+m; i++){
                    int u,v;
                    scanf("%d%d", &u, &v);
                    mp[u].pb(v);
                    in[v]++;
            }
            int cnt = 0;
            for(int i=1; i<=n; i++){
                if(in[i] == 0) que.push(i),vis[i] = 1,cnt++;
            }
            if(que.size() != 1) {
                puts("0");
                return 0;
            }

            while(!que.empty()){
                int u = que.front();
                que.pop();
                for(int i=0; i<mp[u].size(); i++){
                    int v = mp[u][i];
                    in[v] --;
                    if(vis[v] == 0&&in[v] == 0) {
                        vis[v] = 1;
                        pa[v] = u;
                        que.push(v);
                        cnt++;
                    }
                }

            }
            if(cnt != n) puts("0");
            else {
                for(int i=1; i<=n; i++) cout<<pa[i]<<endl;
            }

            return 0;
}


Measured memory_bytes: 7424
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ull q,h,s,d,sum1,sum2;
	ull n,ans = 0;
	cin >> q >> h >> s >> d >> n;
	
	sum1 = min(s,min(h*2,min(q*4,h+q*2)));
	sum2 = min(d,min(s*2,min(h*4,min(q*8,sum1*2))));
	
	
	cout << (ull)(((n/2)*sum2)+((n%2)*sum1)) << endl;
	return 0;
}

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

using namespace std;

int A, B;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> A >> B;
    
    if ((A+B)%2 == 0) {
        cout << (A+B)/2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#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 << "\n";
}

#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 unsigned long long ull;
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;

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}

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

void SOE(ll N, vi & p) {
    int m = int(floor(sqrt(N))) + 1;
    int s[m];
    REP(i ,m) s[i] = i;

    FOR (i, 2, m) {
        if (s[i] != i) continue;

        p.pb(i);

        for (int j = i+i; j <= m; j += i) {
            s[j] = i;
        }
    }
}

void solve(int n, vll& a) {
    ll g = 0;
    REP(i, n) g = __gcd(g, a[i]);

    vector<int> prime;
    SOE(1e12, prime);

    vi c(1e6 + 10, 0);

    REP(i, n) c[a[i]]++;

    bool f = true;
    for(auto &e: prime) {
        int cnt = 0;
        for(int i = e; i <= 1e6; i += e) {
            cnt += c[i];
        }

        if (cnt > 1) f = false;
    }

    if (f) {
        print("pairwise coprime");
    } else {
        if (g == 1) {
            print("setwise coprime");
        }
        else print("not coprime");
    }
}

int tle(int n, vll &a) {
    ll g = a[0];
    REP(i, n) g = __gcd(g, a[i]);

    bool f = true;
    REP(i, n) FOR(j, i + 1, n) {
        f &= __gcd(a[i], a[j]) == 1;
//        debug(a[i], a[j], __gcd(a[i], a[j]))
    }

    if (f) {
        return  1;
    } else {
        if (g == 1) return 2;
        return 3;
    }
}

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


    int n;
    cin >> n;

    vll a(n); REP(i, n) cin >> a[i];

    solve(n, a);
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  int x,y;
  cin >> x >> y;
  set<int> S1;
  S1.insert(1);
  S1.insert(3);
  S1.insert(5);
  S1.insert(7);
  S1.insert(8);
  S1.insert(10);
  S1.insert(12);

  set<int> S2;
  S2.insert(4);
  S2.insert(6);
  S2.insert(9);
  S2.insert(11);

  if((S1.count(x) && S1.count(y)) || (S2.count(x) && S2.count(y))
  || (x == 2 && y == 2)) cout << "Yes" << endl;
  else cout << "No" << endl;
 }

Measured memory_bytes: 256