akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// UnionFind
struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}

    // ある要素がどの集合に属しているかを返す
    int find(int x) {
      if (d[x] < 0) return x;
      return d[x] = find(d[x]);
    }

    // 集合をマージする、すでに同じ集合ならfalseが返る
    bool unite(int x, int y) {
      x = find(x); y = find(y);
      if (x == y) return false;
      if (d[x] > d[y]) swap(x,y);
      d[x] += d[y];
      d[y] = x;
      return true;
    }

    // 2つの要素が同じ集合か判定する
    bool same(int x, int y) { return find(x) == find(y);}
  
    // ある集合の大きさを答える
    int size(int x) { return -d[find(x)];}
};

int n, m;

int main() {
    cin >> n >> m;
    UnionFind uf(n+m);
    for(int i = 0; i < n; ++i) {
        int k; cin >> k;
        for(int j = 0; j < k; ++j) {
            int l; cin >> l;
            l--;
            uf.unite(i, n+l);
        }
    }

    bool flg = true;
    for(int i = 0; i < n; ++i) {
        if(!uf.same(i, (i+1)%n)) flg = false;
    }

    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main(){
  ll mod=1e9+7;
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  vector<ll> sa=a;
  sort(sa.begin(),sa.end());
  ll ans=0;
  ll cnt=0;
  for(ll i=1;i<=2000;i++){
    ll num=upper_bound(sa.begin(),sa.end(),i)-lower_bound(sa.begin(),sa.end(),i);
    if(num==0)continue;
    ll c=0;
    ll def=0;
    for(ll j=0;j<a.size();j++){
      if(a[j]==i)c++;
      if(a[j]<i)def+=c;
    }
    ll tmp=(k*(k-1)/2)%mod;
    ans+=def*k+num*cnt*tmp;
    ans=(ans+mod)%mod;
    cnt+=num;
  }
  cout<<(ans+mod)%mod<<endl;
}


Measured memory_bytes: 256
while 1:
    N = int(input())
    if not N:
        break
    S = []
    for i in range(N):
        h, r = map(int, input().split())
        S.append((h, r))
    M = int(input())
    for i in range(M):
        h, r = map(int, input().split())
        S.append((h, r))

    S.sort()
    memo = [-1]*(N+M)
    def dfs(i):
        if memo[i] != -1:
            return memo[i]
        hi, ri = S[i]
        r = 0
        for j in range(i+1, N+M):
            hj, rj = S[j]
            if hi < hj and ri < rj:
                r = max(r, dfs(j))
        memo[i] = r+1
        return r+1
    print(dfs(0))


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main()
{
  float D,T,S;
  cin >> D>>T>>S;
  if(D/S <=T)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

using namespace std;

long long L[90];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int a, b, c, d;
  a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
  int tmp;
  vector<char> op;
  for(int i=0; i<2; i++){
    int tmp1;
    if(i == 0) tmp1 = a + b, op.push_back('+');
    else tmp1 = a - b, op.push_back('-');
    for(int j=0; j<2; j++){
      int tmp2;
      if(j == 0) tmp2 = tmp1 + c, op.push_back('+');
      else tmp2 = tmp1 - c, op.push_back('-');
      for(int k=0; k<2; k++){
        int tmp3;
        if(k == 0) tmp3 = tmp2 + d, op.push_back('+');
        else tmp3 = tmp2 - d, op.push_back('-');
        if(tmp3 == 7){
          cout << a << op[0] << b << op[1] << c << op[2] << d << "=7" << endl;
          return 0;
        }
        op.pop_back();
      }
      op.pop_back();
    }
    op.pop_back();
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;

int f[100][11];
int p[100][12];

void solve()
{
	int N;
	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];
		}
	}
	int res = -1e9;
	for (int b = 1; b < (1 << 10); ++b)
	{
		int cc = 0;
		for (int i = 0; i < N; ++i)
		{
			int c = 0;
			for (int j = 0; j < 10; ++j)
			{
				if ((b >> j & 1) && f[i][j])
				{
					c++;
				}
			}
			cc += p[i][c];
		}
		if (res < cc)
		{
			res = cc;
		}
	}
	cout << res << endl;
}

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

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

vector<pair<pair<int, int>, pair<int, int>>> out;
signed main(void)
{
	int h, w;
	long long cnt;
	cin >> h >> w;
	int s[h][w];

	rep(i, h)rep(j, w) cin >> s[i][j];
	cnt = 0;
	rep(i, h)
	{
		if (i % 2 == 0)
		{
			rep(j, w)
			{
				if (s[i][j] % 2 != 0)
				{
					if (j + 1 < w)
					{
						s[i][j + 1] += s[i][j]; 
						out.push_back(make_pair(make_pair(i + 1, j + 1),\
									make_pair(i + 1 , j + 2)));
					cnt++;
					}
					else if (i + 1 < h)
					{
						s[i + 1][j] += s[i][j];
						out.push_back(make_pair(make_pair(i + 1, j + 1),\
									make_pair(i + 2, j + 1)));
					cnt++;
					}
				}
			}
		}
		else
		{
			for(int j = w - 1; j >= 0; j--)
			{
				if (s[i][j] % 2 != 0)
				{
					if (j - 1 >= 0)
					{
						s[i][j - 1] += s[i][j]; 
						out.push_back(make_pair(make_pair(i + 1, j + 1),\
									make_pair(i + 1 , j)));
					cnt++;
					}
					else if (i + 1 < h)
					{
						s[i + 1][j] += s[i][j];
						out.push_back(make_pair(make_pair(i + 1, j + 1),\
									make_pair(i + 2, j + 1)));
					cnt++;
					}
				}
			}
		}
	}
	cout << cnt << endl;
	rep(i, cnt)
	{
		cout << out[i].first.first << " " << out[i].first.second << " ";
		cout << out[i].second.first << " " << out[i].second.second << endl;
	}
	return 0;
}


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

int main(){
	cin >> S;
	int N = S.size();
	int count = 0,ans = 0;
	for(int i=0;i<N;i++){
		if(S[i]=='S') count++;
		else{
			if(count>=1) ans++;
			if(count>=1) count--;
		}
	}
	cout << N-2*ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int a,b;
      cin >> a >> b;
      if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
      else cout << "Impossible" << endl;
      return 0;}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cShaprTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var H = int.Parse(input[0]);
            var W = int.Parse(input[1]);

            var matrix = new bool[H, W];

            input = Console.ReadLine().Split(' ');
            var h = int.Parse(input[0]);
            var w = int.Parse(input[1]);

            for (var i = 0; i < W; i++)
            {
                for (var j = 0; j < h; j++)
                {
                    matrix[j, i] = true;

                }
            }

            for (var i = 0; i < H; i++)
            {
                for (var j = 0; j < w; j++)
                {
                    matrix[i, j] = true;
                }
            }

            int sum = 0;
            for (var i = 0; i < W; i++)
            {
                for (var j = 0; j < H; j++)
                {
                    if (matrix[j, i] == false)
                    {
                        sum++;
                    }
                }
            }

            Console.WriteLine(sum);
        }
    }
}


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

using namespace std;

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

  vector<int> h(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  // 1 2 2 1 ->  1 1 1 1 + 0 1 1 0
  // 3 1 2 3 1 -> 1 1 1 1 1 + 2 0 0 0 0 + 0 0 1 1 0 + 0 0 0 1 0
  // 2 0 1 2 0

  int ans = 0;
  int l, r;
  while (true) {
    l = N;

    for (int i = 0; i < N; i++) {
      if (h[i] != 0) {
        l = i;
        break;
      }
    }

    if (l == N) break;

    int min_h = h[l];

    for (int i = l; i < N; i++) {
      if (h[i] == 0) {
        break;
      }
      min_h = min(min_h, h[i]);
      r = i;
    }

    for (int i = l; i <= r; i++) {
      h[i] -= min_h;
    }
    ans += min_h;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MAX 1000000001

ll power(ll x,ll y,ll p){
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll modInverse(ll n,ll p){ 
    return power(n, p-2, p); 
}

ll nCrModP(ll n, ll r, ll p){
   if (r==0) 
      return 1;
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}

int main(){
	fast;
	int test=1;
	//cin >> test;
	while(test--){
	    ll s;
	    cin >> s;
	    ll ans=0;
	    for(ll i=1 ; i<=(s/3) ; i++){
	        ans+=nCrModP(s-2*i-1,i-1,mod);
	        ans%=mod;
	    }
	    cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3616
def resolve():
        n, k = map(int, input().split())
        a = list(map(int, input().split()))
        bn1 = [0] * n
        s = 0
        t = 0
        chec = 0
        for _ in range(k):
            for i in range(n):
                b1 = max(i - a[i], 0)
                b2 = min(i + a[i], n - 1)
                bn1[b1] += 1
                if b2<n-1:
                    bn1[b2+1] -= 1
            for i in range(n):
                s += bn1[i]
                a[i] = s
                if s==n:
                    chec+=1
            s = 0
            if chec == n:
                break
            chec = 0
            bn1 = [0] * n
        c = [str(x) for x in a]
        L = " ".join(c)
        print(L)
resolve()

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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 102
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

int dp[M][N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, k, i, j, cand;
    cin>>n>>k;
    dp[0][0] = 1;
    for(i=1; i<=n; i++){
        cin>>cand;
        for(j=0; j<=k; j++){
            dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
            if(j+cand+1 <= k){
                dp[i][j+cand+1] = (dp[i][j+cand+1] - dp[i-1][j] + MOD) % MOD;
            } 
        }
        for(j=1; j<=k; j++){
            dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
        }
    }
    cout<<dp[n][k];
    return 0;
}

Measured memory_bytes: 39296
#include<iostream>
using namespace std;
#define ll long long int
#define N 200000
ll n, a[N];
int main(){
    cin>>n;
    ll x=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        x^=a[i];
    }
    for(int i=0;i<n;i++){
        cout<<(a[i]^x)<<" ";
    }
    return 0;
}

Measured memory_bytes: 4632
#include<iostream>
#include<cstring>
#include<queue>


#define F first
#define S second
 
using namespace std;

struct State{
  int x1,y1,x2,y2;
  State(){}
  State(int a, int b, int c, int d):x1(a),y1(b),x2(c),y2(d){}
};
 
const int MAX = 55;
typedef pair<int,int> P;
char M[2][MAX][MAX];
bool come[MAX][MAX][MAX][MAX];
int W,H;
P s1,s2;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
 
void init(){
  memset(come,false,sizeof(come));
}
 
void print(){
  for(int x = 0; x < 2; x++){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++) cout << M[x][i][j];
      cout << endl;
    }
    cout << endl<< endl;
  }
}
 
void input(){
  for(int i = 0; i < H; i++)
    for(int x = 0; x < 2; x++)
      for(int j = 0; j < W; j++){
    cin >> M[x][i][j];
    if(M[x][i][j] == 'L' && !x) s1 = P(i,j);
    if(M[x][i][j] == 'R' && x) s2 = P(i,j);
    }
}
 
bool isInside(int x, int y){return 0<=x&&x<W&&0<=y&&y<H;}


bool dfs(){

  queue<State> Q;
  Q.push(State(s1.S,s1.F,s2.S,s2.F));
  
  while(!Q.empty()){
    State now = Q.front();
    Q.pop();

    if(come[now.x1][now.y1][now.x2][now.y2]) continue;
    come[now.x1][now.y1][now.x2][now.y2] = true;
    
    // cout << now.x1 << " " << now.y1 << " " << now.x2 << " " << now.y2 << endl;
    for(int i = 0; i < 4; i++){
      int nx1 = now.x1+dx[i];
      int ny1 = now.y1+dy[i];
      int nx2 = now.x2-dx[i];
      int ny2 = now.y2+dy[i];
      if(!isInside(nx1,ny1) || M[0][ny1][nx1] == '#'){
	nx1 = now.x1;
	ny1 = now.y1;
      }
      if(!isInside(nx2,ny2) || M[1][ny2][nx2] == '#'){
	nx2 = now.x2;
	ny2 = now.y2;
      }
      if(M[0][ny1][nx1] == '%' && M[1][ny2][nx2] == '%') return true;
      if(M[0][ny1][nx1] != '%' && M[1][ny2][nx2] != '%') Q.push(State(nx1,ny1,nx2,ny2));
    }
  }
  return false;
}

void solve(){
  if(dfs()) cout << "Yes" << endl;
  else cout << "No" << endl;
}
 
int main(){
  while(cin >> W >> H && W+H){
    init();
    input();
    //   print();
    solve();
  }
  return 0;
}

Measured memory_bytes: 13768
N = int(input())
x = [None for _ in range(N)]
y = [None for _ in range(N)]
h = [None for _ in range(N)]
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())
    if h[i] > 0:
        a = [x[i], y[i], h[i]]
for cx in range(0, 101):
    for cy in range(0, 101):
        hh = a[2] + abs(a[0] - cx) + abs(a[1] - cy)
        flag = True
        for i in range(N):
            h_i = max(hh - abs(x[i] - cx) - abs(y[i] - cy), 0)
            if h_i != h[i]:
                flag = False
        if flag:
            print(cx, cy, hh)
            exit()

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

int main() {
    int n;
    cin >> n;
    vector<int> bricks(n);
    for (int i = 0; i < n; ++i) cin >> bricks.at(i);
    int target = 1;
    for (int j : bricks) if (j == target) target++;
    cout << (target == 1 ? -1 : n - target + 1) << endl;
}


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

int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int disa_c, disa_b, disb_c;

	a < c ? disa_c = c - a : disa_c = a - c;
	a < b ? disa_b = b - a : disa_b = a - b;
	b < c ? disb_c = c - b : disb_c = b - c;

	//debug
	//cout << disa_c << endl;
	//cout << disa_b << endl;
	//cout << disb_c << endl;

	if (disa_c <= d) {
		cout << "Yes";
	}
	else if (disa_b <= d && disb_c <= d) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q,time,cnt_time = 0;
  string name;
  queue<pair<string,int> > que;
  cin >> n >> q;
  for(int i=0;i<n;i++){
    cin >> name >> time;
    que.push(make_pair(name,time));
  }
  while(!que.empty()){
    pair<string,int> top = que.front();
    que.pop();
    if(top.second <= q){
      cnt_time += top.second;
      cout << top.first << " " << cnt_time << endl;
    }else{
      cnt_time += q;
      que.push(make_pair(top.first,top.second-q));
    }
  }
}



Measured memory_bytes: 6192
def main(n,h):

    i = 0
    max, tmp = 0, 0
    while i <= n - 2:
        tmp = 0
        if n - i  <= max:
            break
        for j in range(n - 1 - i):
            if h[j + i] >= h[j + i + 1]:
                tmp += 1
            else:
                i += tmp
                if max < tmp:
                    max = tmp
                break
        i += 1
        if max < tmp:
            max = tmp
    print(max)


if __name__ == '__main__':
    n = int(input())
    h = list(map(int, input().split()))
    main(n,h)


Measured memory_bytes: 14252
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

bool graph[8][8];
const int nmax = 8;
ll res;
int dfs(int v, int N, bool visited[nmax]) {
		bool all_visited = true;
		for (int i = 0; i < N; ++i) {
		if (visited[i] == false)
		 all_visited = false;
		}
		if (all_visited) {
		return 1;
		}
		int ret = 0;
		for (int i = 0; i < N; ++i) {
		if (graph[v][i] == false) continue;
		if (visited[i]) continue;
			visited[i] = true;
			ret += dfs(i, N, visited);
			visited[i] = false;
		}
		return ret;
}
int main() {
	cin >> n >> m;
	res = 0;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a][b] = true;
		graph[b][a] = true;
	}
	bool seen[8];
	rep(i, n) {
		seen[i] = false;
	}
	seen[0] = true;
	cout << dfs(0,n,seen) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 17
int v[N][N],n,m,a,b,c,as;
int dp[67890][N],su[67890],s1;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d%d",&a,&b,&c),v[a][b]=v[b][a]=c,s1+=c;
	for(int i=1;i<1<<n;i++)
	for(int j=1;j<=n;j++)
	for(int k=j+1;k<=n;k++)
	if((i&(1<<j-1))&&(i&(1<<k-1)))su[i]+=v[j][k];
	for(int i=0;i<1<<n;i++)for(int j=1;j<=n;j++)dp[i][j]=-1e9;
	for(int i=1;i<1<<n;i+=2)dp[i][1]=su[i];
	for(int i=1;i<1<<n;i++)
	for(int j=1;j<=n;j++)
	if(i&(1<<j-1))
	for(int k=((1<<n)-1)^i;k;k=(k-1)&(((1<<n)-1)^i))
	for(int l=1;l<=n;l++)
	if(k&(1<<l-1))
	if(v[j][l])
	dp[i|k][l]=max(dp[i|k][l],dp[i][j]+su[k]+v[j][l]);
	int as=0;
	for(int i=1;i<1<<n;i++)as=max(as,dp[i][n]);
	printf("%d\n",s1-as);
}

Measured memory_bytes: 4096
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_num(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a[12];
int cnt[1010];
int main() {
	REP(i, 12)cin >> a[i];
	REP(i, 12)cnt[a[i]]++;
	REP(i, 12) {
		if (cnt[a[i]] != 4 && cnt[a[i]] != 8 && cnt[a[i]] != 12) {
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
}


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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector <int> arr(n + 1);
  for (int i = 1; i <= n; i++) cin >> arr[i];
  vector <int> left(n + 1);
  left[0] = 0;
  for (int i = 1; i <= n; i++) left[i] = max(left[i - 1], arr[i]);
  vector <int> right(n + 2);
  right[n + 1] = 0;
  for (int i = n; i >= 0; i--) right[i] = max(right[i + 1], arr[i]);
  for (int i = 1; i <= n; i++) cout << max(left[i - 1], right[i + 1]) << '\n';
  return (0);
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define All(x) x.begin() , x.end()
#define de(x,y) cout<<#x<<" "<<x<<y;
#define pray(a,i,n_thing) for(int x=i;x<=(i+n_thing);x++) cout<<#a<<"["<<x<<"] :"<<a[x]<<endl;
#define mem(aa,x) memset(aa,x,sizeof aa)
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
const int maxn=4e5+5;
int arr[maxn]={};

main(){
	ll n,num;
	bool find=0;
	map<ll,int> m;
	map<ll,int>::iterator it; 
	vector<ll> v;
	cin>>n;
	rep(i,0,n-1){
		cin>>num;
		m[num]++;
	}
	
	for(it=m.begin();it!=m.end();it++){
		if(it->Y>=4){
			v.push_back(it->X);
			v.push_back(it->X);
		} 
		else if(it->Y>=2) v.push_back(it->X);
	}
	
	sort(v.begin(),v.end());
	if(v.size()>=2){
		unsigned long long ans=v[v.size()-1]*v[v.size()-2];
		cout<<ans<<"\n";
	}
	else cout<<"0\n";
}

Measured memory_bytes: 6528
import math

D = int(input())
c = list(map(int, input().split()))
S = []
for i in range(D):
    S.append(list(map(int, input().split())))

nocontest = [1 for i in range(26)]

for i in range(D):
    s = S[i]
    contest = [0 for j in range(26)]
    for j in range(26):
        contest[j] = c[j] * nocontest[j] * s[j]
    #print(contest)
    max_contest = max(contest)
    ans = contest.index(max_contest)
    print(ans + 1)
    
    for j in range(26):
        if j == ans:
            nocontest[j] = 1
        else:
            nocontest[j] += 10
    #print(nocontest)

Measured memory_bytes: 9352
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll N;   cin >> N;
    ll *C, *S, *F;  
    C = new ll[N], S = new ll[N], F = new ll[N];
    
    for (ll i = 0; i < N-1; i++)
        cin >> C[i] >> S[i] >> F[i];

    for (ll i = 0; i < N; i++) {
        ll ans = S[i];
        ans += C[i];
        for (ll j = i+1; j < N-1; j++) {
            if (ans < S[j]) {
                ans += (S[j] - ans);
                ans += C[j];
            }
            else {
                ll x = (ans % F[j]);
                if (x > 0) {
                    ans += F[j] - x;
                }
                ans += C[j];
            }
        }

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

Measured memory_bytes: 256
#include<iostream>

using namespace std;

const long long mod=1000000007LL;

long long powmod(long long m,long long n){
	long long res=1;
	while(n>0){
		if(n&1)(res*=m)%=mod;
		n>>=1;
		(m*=m)%=mod;
	}
	return res;
}

int main()
{
    long long m,n;
    cin>>m>>n;
    cout<<powmod(m,n)<<endl;
}

Measured memory_bytes: 1156
n, m = map(int, input().split())
l = [0] * m
for i in range(n):
    a = list(map(int, input().split()))
    for j in range(1, a[0] + 1):
        l[a[j] - 1] += 1
c = 0
for i in range(m):
    if l[i] == n:
        c += 1
print(c)

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int n,k,r,s,p;
  cin >>n>>k>>r>>s>>p;
  string t;
  cin >>t;
  ll ans=0;
  vector<vector<int>> key(n,vector<int>(1,0));
  rep(i,k){
    if(t[i]=='r') ans+=p;
    if(t[i]=='s') ans+=r;
    if(t[i]=='p') ans+=s;
    key[i][0]=1;
  }
  rep2(i,k,n){
    if(key[i-k][0]==0||t[i]!=t[i-k]){
      if(t[i]=='r') ans+=p;
      if(t[i]=='s') ans+=r;
      if(t[i]=='p') ans+=s;
      key[i][0]=1;
    }
  }
  cout <<ans<<endl;
}
    

Measured memory_bytes: 8960
let rs, bs, xys = Scanf.(scanf "%d %d" @@ fun n m -> Array.(make n false, make n 1, init m @@ fun _ -> scanf " %d %d" @@ fun a b -> a - 1, b - 1))
let _ = rs.(0) <- true; Array.(iteri (fun i (x, y) -> rs.(y) <- rs.(y) || rs.(x); bs.(x) <- bs.(x) - 1; if bs.(x) = 0 then rs.(x) <- false; bs.(y) <- bs.(y) + 1) xys; Printf.printf "%d\n" @@ fold_left (fun c b -> c + if b then 1 else 0) 0 rs)

Measured memory_bytes: 8320
#include <stdio.h>
#include <cassert>
#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>
#include <iomanip>
 
#ifdef LOCAL_CODE
	#define DEBUG(x) cerr << "[" << #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;
const int MOD = 1000000007;
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.first >> p.second; 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.first << ' ' << p.second; 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; }

int n,m;
ll pow2[333333];
void solve(istream& cin, ostream& cout) {
	map<pair<ll,ll>,int> cnt;
	cin>>n;
	pow2[0] = 1;
	REP(j, 300000) pow2[j+1] = (pow2[j]*2)%MOD;
	int Z = 0;
	REP(i, n) {
		ll A, B;
		cin >> A >> B;
		ll G = gcd(A<0?-A:A, B<0?-B:B);
		if(!G) {
			Z++;
			continue;
		}
		if(A<0 && B < 0) {
			A*=-1; B*=-1;
		} else if(B < 0) {
			A*=-1; B*=-1;
		}

		A /= G; B /= G;
		DEBUG(A);
		DEBUG(B);
		cnt[mp(A,B)]++;
	}
	vector<pair<ll, ll>> cnts;
	set<pair<ll,ll>> vis;
	for(auto x : cnt) {
		if(vis.count(x.first))
			continue;
		DEBUG(x);
		vis.insert(x.first);
		vis.insert({x.first.second, -x.first.first});
		cnts.pb({x.second, cnt[mp(x.first.second, -x.first.first)]});
	}
	ll ans = 1;
	for(auto Q : cnts) {
		DEBUG(Q);
		ans = (ans*(pow2[Q.first]+pow2[Q.second]+MOD-1))%MOD;
	}
	cout <<(ans+Z+MOD-1)%MOD<<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: 58356
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

string make_burger(ll l){
    if(l==0) return "P";
    else{
        string bur;
        bur = "B" + make_burger(l-1) + "P" + make_burger(l-1) + "B";
        return bur;
    }
}


int main(){
    int a,b;
    cin >> a >> b;
    cout << a * b / 2 << endl;
    return 0;
}

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

const ll MOD = 1000000007;

int main(void) {
  string S;
  ll D;
  cin >> S >> D;

  ll N = S.length();
  vector<ll> A(N);
  REP(i, 0, N) {
    A[i] = S[i] - '0';
  }

  vector<vector<ll>> dp1(N, vector<ll>(D));
  vector<vector<ll>> dp2(N, vector<ll>(D));
  dp1[0][A[0] % D]++;
  dp1[0][A[0] % D] %= MOD;
  REP(i, 0, A[0]) {
    dp2[0][i % D]++;
    dp2[0][i % D] %= MOD;
  }

  REP(i, 0, N - 1) {
    REP(j, 0, D) {
      REP(k, 0, 10) {
        ll r = (j + k) % D;
        if (k < A[i + 1]) {
          dp2[i + 1][r] += dp1[i][j];
          dp2[i + 1][r] %= MOD;
        }
        if (k == A[i + 1]) {
          dp1[i + 1][r] += dp1[i][j];
          dp1[i + 1][r] %= MOD;
        }
        dp2[i + 1][r] += dp2[i][j];
        dp2[i + 1][r] %= MOD;
      }
    }
  }

  cout << (dp1[N - 1][0] + dp2[N - 1][0] + MOD - 1) % MOD << endl;
}

Measured memory_bytes: 16768
#include <stdio.h>

#define MAX_NUM	(10)

static void 
sort(int h[])
{
	for (int i = 0; i < MAX_NUM; i++) {
		for (int j = MAX_NUM - 1; j > i; j--) {
			if (h[j] > h[j-1]) {
				int tmp = h[j];
				h[j] = h[j-1];
				h[j-1] = tmp;
			}
		}
	}
}

int
main(void)
{
	char line[80];
	int h[MAX_NUM] = { 0 };

 	for (int i = 0 ; i < 10; i++) {
		if (gets(line)) {
			if (sscanf(line, "%d", &(h[i])) != 1) {
				break;
			}
		}
 	}

	sort(h);
	
 	for (int i = 0 ; i < 3; i++) {
 		printf("%d\n", h[i]);
 	}

	return 0;
}

Measured memory_bytes: 1036
import java.util.*;
	import java.io.*;
import java.lang.reflect.Array;
	public class Main {
		static int n,m;
		static ArrayList<ArrayList<Integer>> g;
		static int dp[],l1,l2;
		static boolean cj;
		public static void main(String[] args) throws IOException{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			int t=1;
	//		Integer.parseInt(br.readLine().trim());
			StringBuilder printans=new StringBuilder();
			while(t-->0)
			{
				StringTokenizer tok=new StringTokenizer(br.readLine()," ");
				n=Integer.parseInt(tok.nextToken());
				m=Integer.parseInt(tok.nextToken());
				g=new ArrayList<>();
				for(int i=0;i<=n;i++) {
					g.add(new ArrayList<>());
				}
				while(m-->0) {
					tok=new StringTokenizer(br.readLine()," ");
					int a=Integer.parseInt(tok.nextToken());
					int b=Integer.parseInt(tok.nextToken());
					addedge(a,b);
					
				}
				dp=new int[n+1];
				boolean vis[]=new boolean[n+1];
				int ans=0;
				for(int i=0;i<=n;i++) {
					cj=false;
						if(!vis[i]) {
							findans(i,0,vis);
						}
						
				}
				int ans2=0;
				for(int i:dp) {
					ans2=Math.max(ans2, i);
//					System.out.print(i+" ");
				}
				System.out.println(ans2);

			}
			
			
		}
		static void addedge(int a,int b) {
			g.get(a).add(b);
			
		}
		static void findans(int curr,int j,boolean vis[]) {
			vis[curr]=true;
			int ans=0;
			for(int i=0;i<g.get(curr).size();i++) {
				if(!vis[g.get(curr).get(i)]) {
//					
					findans(g.get(curr).get(i),j+1,vis);
					
				}
				dp[curr]=Math.max(dp[curr],dp[g.get(curr).get(i)]+1);
			}
			
				
				
			
			
		
		
		
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
//		static void memset() {
//			for(int a[]:dp) {
//				Arrays.fill(a,-1);
//			}
//		}
		
			
	}


Measured memory_bytes: 63952
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

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

	double ans=0;

	for(int i=1;i<=n;i++)
	{
		double ii=i;
		double count=0;
		for(int j=1;j<=k;j++)
		{
			if(ii>=k)
			{
				count=j;
				break;
			}
			ii*=2;
		}
		double tmp=1.0;
		for(int j=1;j<count;j++)
		{
			tmp/=2;
		}
		ans+=(tmp/n);
	}


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


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }



template<typename T>
struct BIT {
    vector<T> array;
    const int n;
public:
    BIT(int _n) : array(_n + 1, 0), n(_n) {}
    
    // 1番目からi番目までの累積和
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += array[i];
            i -= i & -i;
        }
        return s;
    }
    
    // [i, j]の要素の総和
    T sum(int i, int j) {
        T ret_i = sum(i - 1);
        T ret_j = sum(j);
        return ret_j - ret_i;
    }
    
    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

template<typename T>
struct twodimBIT {
    vector<vector<T> > array;
    const int n;
    const int m;
public:
    twodimBIT(int _n, int _m)
    : array(_n + 1, vector<T>(_m + 1, 0)), n(_n), m(_m) {}
    
    // [1, 1]から[x, y]までの累積和
    T sum(int x, int y) {
        T s = 0;
        for (int i = x; i > 0; i -= i & -i) {
            for (int j = y; j > 0; j -= j & -j) {
                s += array[i][j];
            }
        }
        return s;
    }
    
    T sum(int x1, int y1, int x2, int y2) {
        return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1);
    }
    
    void add(int x, int y, T k) {
        for (int i = x; i <= n; i += i & -i) {
            for (int j = y; j <= m; j += j & -j) {
                array[i][j] += k;
            }
        }
    }
    
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int m, n;
    cin >> m >> n;
    int k;
    cin >> k;
    twodimBIT<int> ju(m, n);
    twodimBIT<int> oc(m, n);
    twodimBIT<int> ic(m, n);
    
    rep(i, m) {
        string s;
        cin >> s;
        rep(j, n) {
            if (s[j] == 'J') ju.add(i + 1, j + 1, 1);
            else if (s[j] == 'O') oc.add(i + 1, j + 1, 1);
            else if (s[j] == 'I') ic.add(i + 1, j + 1, 1);
        }
    }
    
    rep(i, k) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        
        // 配列上, 左上が下で, 右下が上
        cout << ju.sum(x1, y1, x2, y2) << " ";
        cout << oc.sum(x1, y1, x2, y2) << " ";
        cout << ic.sum(x1, y1, x2, y2) << endl;
    }
    
}



Measured memory_bytes: 14456
def gcd(a,b):
  if b!=0:
    return gcd(b, a%b)
  else:
    return a
  
def lcm(a,b):
  return a//gcd(a,b)*b
  
def f(x, c, d):
  a = x
  a -= x//c
  a -= x//d
  a += x//lcm(c,d)
  return a
  
A,B,C,D = list(map(int, input().split()))

out = f(B, C, D) - f(A-1, C, D)
print(out)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) {
    if (B == 1) {
      cout << "Draw" << endl;
    }
    else {
      cout << "Alice" << endl;
    }
  }
  else if (B == 1) {
    cout << "Bob" << endl;
  }
  else if (A == B) {
    cout << "Draw" << endl;
  }
  else if (A > B) {
    cout << "Alice" << endl;
  }
  else {
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
using namespace std;
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 1e5 + 5;
int n, m;
vector<int> to[maxn], from[maxn];

bool vis[maxn];
vector<int> arr;
int pos[maxn];

int ans[maxn];

void ReadInput()
{
    cin >> n >> m;
    for(int i = 1; i < n + m; ++i)
    {
        int x, y;
        cin >> x >> y;
        from[x].push_back(y);
        to[y].push_back(x);
    }
}

void dfs(int u)
{
    vis[u] = true;
    for(int v: from[u])
        if(!vis[v]) dfs(v);
    arr.push_back(u);
}

void Solve()
{
    fill(begin(vis), end(vis), false);
    for(int i = 1; i <= n; ++i)
        if(!vis[i]) dfs(i);
    reverse(arr.begin(), arr.end());
    for(int i = 0; i < n; ++i)
        pos[arr[i]] = i;

    for(int i = 0; i < n; ++i)
    {
        int mx = -1;
        int id = 0;
        int u = arr[i];
        for(int v: to[u])
            if(pos[v] > mx)
            {
                mx = pos[v];
                id = v;
            }
        ans[u] = id;
    }

    for(int i = 1; i <= n; ++i)
        cout << ans[i] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 16380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int X; cin >> X;
  cout << 8-(X-400)/200 << endl;
  return 0;
}


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


int main() {
  
  int A,B;
  cin >> A >> B;

  if((A + B) % 2 == 0) {
      cout << (A + B) / 2 << endl;
  }else {
      cout << "IMPOSSIBLE" << endl;
  }

 
}


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

int main() {
  string S,T;
  cin >> S >> T;
  int beg = -5;
  bool exist = true;
  
  if(T.size() == 1){
    int s_s = S.size()-1;
    S.at(s_s) = T.at(0);
   for(int z=0; z<S.size(); z++){
    if(S.at(z) == '?'){
      S.at(z) = 'a';
    }
   }
    cout << S << endl;
  }
  
  else{
  for(int i=S.size()-1; i>=T.size()-1; i--){
    int x = i;
   if(exist){
    for(int j=T.size()-1; j>=0; j--){
      if(S.at(x) != T.at(j) && S.at(x) != '?'){
        break;
      }
      else{
        x--;
      }
      if(j == 0){
        beg = x+1;
        exist = false;
        break;
      }
    }
   }
  }
  
  int cnt = 0;
  if(beg >= 0){
   for(int k=beg; cnt<T.size(); k++){
    S.at(k) = T.at(cnt);
    cnt++;
   }
   for(int l=0; l<S.size(); l++){
    if(S.at(l) == '?'){
      S.at(l) = 'a';
    }
   }
  }
  else{
    S = "UNRESTORABLE";
  }
  cout << S << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 3005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,k,a[MAXN];
ll dp[MAXN][MAXN];
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1;i<=n;i++) dp[i][i]=a[i];
    for(ll l=2;l<=n;l++)
    {
        for(ll i=1;i+l-1<=n;i++)
        {
            ll j=i+l-1;
            dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
        }
    }
    printf("%lld\n",dp[1][n]);
    return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef vector<pi> vp;

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF 1e9
#define modulo 1000000007
#define forn(i, n) for(int i = 0; i < (n); i++)
#define FAST ios::sync_with_stdio(false); cin.tie(NULL);
#define end1 "\n" 
#define print(x) cout << x << end1
#define debug(x) cout<< #x <<" :: "<< x <<end1;
#define debug2(x, y) cout<< #x <<" :: "<< x << "\t" << #y <<" :: "<< y <<end1;



int main(){ 
FAST;
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif

////////
int n; cin >> n;

long double ans = 2*PI*n;

cout << fixed << setprecision(7) << ans << end1;

return 0;
}


Measured memory_bytes: 3788
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

vector<int>ans(200001,0);
vector<int>visited(200001,0);
vector<vector<int>>G(200001,vector<int>());
queue<int>que;
void bfs(){
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int nv : G[v]) {
			if(visited[nv]==1)continue;
			ans[nv]+=ans[v];
			que.push(nv);
			visited[nv]=1;
		}
	}

}

signed main(void) {
	int n,q;
	cin >> n >> q;
	ans.resize(n);
	visited.resize(n);
	rep(i,n-1){
		int a,b;
		cin >> a>>b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,q){
		int p,x;
		cin >> p>>x;
		p--;
		ans[p]+=x;
	}
	visited[0]=1;
	que.push(0);
	bfs();
	for(auto a:ans){
		print(a);
	}
}

Measured memory_bytes: 17368
a,b,x=map(int,input().split())
import math
if x<=a**2*b/2:
    #print("a")
    l=x/(a*b/2)
    #print(l)
    arg=math.atan2(l,b)
    #print(arg)
    print(90-math.degrees(arg))
else:
    l=(a*a*b-x)/(a*a/2)
    #print(l)
    arg=math.atan(l/a)
    print(math.degrees(arg))

Measured memory_bytes: 38256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.AbstractMap;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            TreeMap<Integer, Integer> counts = new TreeMap<>();
            for (int i = 0; i < a.length; ++i) {
                Integer old = counts.get(a[i]);
                counts.put(a[i], (old == null ? 1 : old + 1));
            }
            int res = 0;
            while (!counts.isEmpty()) {
                int cur = counts.lastKey();
                int cnt = counts.get(cur);
                if (cnt == 1) {
                    counts.remove(cur);
                } else {
                    counts.put(cur, cnt - 1);
                }
                int p2 = 1;
                while (p2 <= cur) p2 *= 2;
                int need = p2 - cur;
                Integer got = counts.get(need);
                if (got != null) {
                    ++res;
                    if (got == 1) {
                        counts.remove(need);
                    } else {
                        counts.put(need, got - 1);
                    }
                }
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 54804
from numba import njit

@njit("i8(i8)")
def solve(n):
    s = [1] * (n+1)
    ans = 1
    for i in range(2,n+1):
        for j in range(i,n+1,i):
            s[j] += 1
        ans += (i * s[i])
    return ans
n = int(input()) 
print(solve(n))


Measured memory_bytes: 188124
n, y = map(int, input().split())

a, b, c = -1, -1, -1

for i in range(n+1):
    for j in range(n+1):
        if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) & (n - i - j >= 0):
            a, b, c = i, j, n - i - j

print(a, b, c)


Measured memory_bytes: 3060