akhauriyash/Code-Regression huggingface dataset:
dice = gets.split.map(&:to_i)
n = gets(chomp: true).to_i
order = [].tap{|a|n.times{a << gets.split.map(&:to_i)}}

def vertical_roll(new_dice, upper)
  while new_dice[0] != upper
    new_dice[0], new_dice[1], new_dice[4], new_dice[5] = new_dice[1], new_dice[5], new_dice[0], new_dice[4]
  end
  new_dice
end

def horizontal_roll(new_dice, front)
  while new_dice[1] != front
    new_dice[1], new_dice[2], new_dice[4], new_dice[3] = new_dice[2], new_dice[4], new_dice[3], new_dice[1]
  end
  new_dice
end

order.each do |odr|
  new_dice = dice.dup
  idx1 = dice.index(odr[0])
  idx2 = dice.index(odr[1])
  case idx1
  when 0,1,4,5
    vertical_roll(new_dice, odr[0])
    horizontal_roll(new_dice, odr[1])
  else
    horizontal_roll(new_dice, odr[0])
    vertical_roll(new_dice, odr[0])
    horizontal_roll(new_dice, odr[1])
  end
  puts new_dice[2]
end


Measured memory_bytes: 6880
import sys
sys.setrecursionlimit(4100000)

n,x = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
temp = 0
counter = 1
for index, value in enumerate(l):
    temp += value
    if temp <= x:
        counter += 1
print(counter)

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S;
    cin >> S;
    int month = (S[5] - '0') * 10 + (S[6] - '0');
    printf("%s\n", (month > 4) ? "TBD" : "Heisei");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String utu = scanner.next();
        while (!utu.equals("0")) {
            int A = 0;
            int B = 0;
            int len = utu.length();

            for (int i = 1; i < len; i++) {
                char ch = utu.charAt(i);
                if (ch == 'A') {
                    B++;
                } else {
                    A++;
                }
            }
            if (A < B) {
                B++;
            } else {
                A++;
            }

            System.out.println(B + " " + A);
            utu = scanner.next();

        }
    }
}



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

dp = [float('inf') for _ in range(n)]

dp[0] = 0

for i in range(1,n):
    lb = max(k-i,0)
    for j in range(lb,k):
        dp[i] = min(dp[i],dp[i-k+j]+abs(h[i]-h[i-k+j]))

print(dp[n-1])

Measured memory_bytes: 56800
import java.util.Scanner;
public class Main{
     
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int cnt=0;
        while(cnt<7){
           int a=sc.nextInt();
           int b=sc.nextInt();
            System.out.println(a-b);
            cnt++;
        }
            }
     
    public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17172
#include <iostream>

using namespace std;

int main() {
  int D, G, p[11], c[11];
  cin >> D >> G;
  for (int i = 0; i < D; ++i) {
    cin >> p[i] >> c[i];
  }

  int ans = 1e9;
  for (int mask = 0; mask < (1 << D); ++mask) {
    int score = 0, count = 0, rest_max = -1;
    for (int i = 0; i < D; ++i) {
      if (mask >> i & 1) {
        score += 100 * (i+1) * p[i] + c[i];
        count += p[i];
      } else {
        rest_max = i;
      }
    }
    if (score < G) {
      int diff = G - score;
      int rest_score = 100 * (rest_max + 1);
      int supple = (diff + rest_score - 1) / rest_score;
      if (supple >= p[rest_max]) {
        continue;
      }
      count += supple;
    }
    ans = min(ans, count);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <complex>
#include <cmath>
#include <stdio.h>
#include <iostream>
using namespace std;
typedef complex<double> xy_t;
const double eps = 1e-11;
double x[4], y[4];
int N;

double cross_product(xy_t a,xy_t b) {
  return (conj(a)*b).imag()/2.0;
}

int main() {
  cin >> N; //????????°
  for (int t=0; t<N; ++t) {
    for (int i=0; i<4; ++i)
      cin >> x[i] >> y[i]; //x0,y0,...,x3,y3
    xy_t a[2] = {
      xy_t(x[0],y[0]) - xy_t(x[1],y[1]),
      xy_t(x[2],y[2]) - xy_t(x[3],y[3])
    };
    bool p = abs(cross_product(a[0],a[1])) < eps;
    cout << (p ? "YES" : "NO") << endl;
  }
}
    

Measured memory_bytes: 1224
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N, P = map(int, input().split())

l = Counter(prime_factorize(P))

ans = 1

for i, v in l.items():
    if v >= N:
        ans *= i**(v//N)
#     print(ans)
# print(l)
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <sstream> 
using namespace std;
int main() {
  long long n,m;
  cin >> n;
  cin >> m;
  if (n % m > m-(n % m))
   { cout << m - (n%m);}
 else {
  cout << n % m;
 }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans1 = max(A)
    ans2 = 0
    diff = ans1
    for a in A:
        if a == ans1:
            continue
        d1 = abs(ans1/2 - a)
        if d1 < diff:
            diff = d1
            ans2 = a
        d2 = abs(a - ans1/2)
        if d2 < diff:
            diff = d2
            ans2 = a

    print(ans1, ans2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14056
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    if(s=="SAT"){
        cout<<"1";
        return 0;
    }
    if(s=="FRI"){
        cout<<"2";
        return 0;
    }
    if(s=="THU"){
        cout<<"3";
        return 0;
    }
    if(s=="WED"){
        cout<<"4";
        return 0;
    }
    if(s=="TUE"){
        cout<<"5";
        return 0;
    }
    if(s=="SUN"){
        cout<<"7";
        return 0;
    }
    cout<<"6";
	exit(0);
}


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

int main() {
	int N, K;	//N...操作の回数 K...今の電工掲示板にKを加える
	int min = 1;	//最小値
	cin >> N >> K;
  	
  	for (int i = 0; i < N; i++) {
     	 if(min * 2 < min + K)
          	min *= 2; 
      	else
          min += K;
    }
  	cout << min << endl;
}

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

vector<pair<int,int> > v;

long long int N,M;
int main () {
    cin >> N >> M;
    for(int i=0; i<N; i++) {
        int a,b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    long long int ans = 0;
    for(int i=0; M>0; i++) {
        if( v[i].second <= M) {
            M -= v[i].second;
            ans += (double)v[i].first * v[i].second;
        } else {
            cout << ans + v[i].first * M << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1528
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int n,ver,cur=0;
vi g[200005];
bool vis[200005];

void dfs(int u){
    if (vis[u]) return;
    cur++; vis[u] = true;
    for (auto &it: g[u]){
        if (!vis[it]) dfs(it);
    }
}

signed main()
{
    cin>>n>>ver;
    for (int i=1;i<=ver;i++){
        int a,b;
        cin >> a >> b ; 
        g[a].pb(b); 
        g[b].pb(a); 
    }
    int ans=0;
    for (int i=1;i<=n;i++){
        dfs(i);
        ans = max(ans,cur);
        cur = 0; 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20880
# include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int c=0;
	for(int i=0;i<n;i+=2)
	{
		if(a[i]%2!=0) c++;
	}
	cout<<c<<endl;
	return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 10000

int main(){

    ll n,k;

    cin >> n >> k;

    vector<ll> a;
    ll i,a1;

    for(i=0;i<n;i++){
        cin >> a1;
        a.push_back(a1);
    }

    ll dp[n];

    for(i=0;i<n;i++){
        dp[i]=0;
    }

    for(i=1;i<n;i++){
        dp[i] = dp[i-1] + abs(a[i]-a[i-1]);
        for(ll j=2;j<=k;j++){
            if(j<=i){
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
        }
    }
/*
    for(i=0;i<n;i++){
        cout << dp[i] << " ";
    }
    cout << endl;
*/
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	char a,b; cin>>a>>b;
	if(a<b) cout<<'<';
	else if(a==b) cout<<'=';
	else cout<<'>';
	
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if i == j:
            continue
        ans += bisect_left(l, l[i] + l[j], lo=j + 1) - j - 1
print(ans)

Measured memory_bytes: 45344
S = input()
flag = True
while flag:
    if S[-5:]=="dream":
        S = S[:-5]
    elif S[-5:]=="erase": 
        S = S[:-5]
    elif S[-7:]=="dreamer": 
        S = S[:-7]
    elif S[-6:]=="eraser": 
        S = S[:-6]
    elif len(S)==0:
        break
    else:
        flag = False
 
if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include"bits/stdc++.h"
using namespace std;
int main()
{
	int f=0,a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(abs(a-c)<=d)
		f=1;
	if(abs(a-b)<=d&&abs(b-c)<=d)
		f=1;
	printf("%s",f?"Yes":"No");
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define lint long long
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
#define N 1010
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
struct P{
	int x,y,k;
}p[N];int v[N];
inline bool pcmp(const P &p1,const P &p2)
{	return p1.y>p2.y;	}
inline int findv(int a,int b)
{
	for(int i=a;i<=b;i++)
		if(v[i]) return --v[i],1;
	return 0;
}
int main()
{
	int n=inn(),ans=0;
	for(int i=1;i<=n;i++)
		p[i].x=inn(),p[i].y=inn(),p[i].k=0;
	for(int i=n+1;i<=2*n;i++)
		p[i].x=inn(),p[i].y=inn(),p[i].k=1;
	sort(p+1,p+2*n+1,pcmp);
//	for(int i=1;i<=2*n;i++)
//		debug(i)sp,debug(p[i].k)sp,debug(p[i].x)sp,debug(p[i].y)ln;
	for(int i=1;i<=2*n;i++)
		if(p[i].k) v[p[i].x]++;
		else ans+=findv(p[i].x,2*n);
	return !printf("%d\n",ans);
}

Measured memory_bytes: 256
N, M = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
for e in edges[0]:
    if any(c == N - 1 for c in edges[e]):
        print("POSSIBLE")
        quit()
print("IMPOSSIBLE")


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

int main(){
    ll mod = 1000000007;
    string s;
    cin >> s;
    int n = (int)s.size();
    vector<ll> dp_u(n, 0);
    vector<ll> dp_l(n, 0);
    dp_u[0] = 2;
    dp_l[0] = 1;
    for (int i = 1; i < n; i++) {
        if (s[i] == '1'){
            dp_u[i] = dp_u[i-1] * 2 % mod;
            dp_l[i] = (dp_u[i-1] + dp_l[i-1] * 3) % mod;
        }
        else{
            dp_u[i] = dp_u[i-1];
            dp_l[i] = dp_l[i-1] * 3 % mod;
        }
    }
    cout << (dp_u[n-1] + dp_l[n-1]) % mod << endl;
    return 0;
}

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

int main() {
  int a = 0,b = 0,c = 0,d = 0;
  
  cin >> a >> b >> c >> d;
  
  if((a + b) == (c + d)){
    cout << "Balanced" << endl;
  }
  else if((a + b) > (c + d)){
    cout << "Left" << endl;
  }
  else{
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int a, b;
    scan(a, b);

    int t = 1;
    int ans;
    while (t < b) {
        t += a - 1;
        ans++;
    }
    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define lli long long int
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define se second;
#define fi first;
#define endl '\n';
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define REP(i,n) for (int i = 1; i <= n; i++)
template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
typedef long long ll;
typedef vector<vector<ll> > matrix;
const ll MOD = 1000000007;
const int K = 9;
const lli mod = 1e9 + 7;
const lli INF = 1e9 + 7;
const lli N=2*1e5;
int main(){
  _
  lli n,h,w;
  cin>>n>>h>>w;
  lli ans=0;
  for(lli i=0;i<n;i++){
    for(lli j=0;j<n;j++){
      if(i+h<=n and j+w<=n){
        // cout<<i<<" "<<j<<endl;
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())

buttons = [int(input()) for _ in range(N)]
m_dict = {}
index = 1
flag = True

while True:
    if index-1 in m_dict:
        flag = False
        break
    elif index == 2:
        break
    m_dict[index-1] = 1
    index = buttons[index-1]

if flag is True:
    print(len(m_dict))
else:
    print(-1)

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

int main() {

    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    double R;
    cin >> R;
    cout << setprecision(20) << R*2*M_PI << endl;
    
}


Measured memory_bytes: 3780
s = input()

t = s.replace('BC', 'X')

# parts = []
# i_prev = 0
# for i in range(1, len(t) + 1):
#     if t[i] in 'BC':
#         parts.append(t[i_prev : i])
#         i_prev = i + 1
#     else:
#         continue
# else:
#     if i_prev < N: parts.append(t[i_prev : N])
parts = t.replace('B', 'C').split('C')

ans = 0
for part in parts:
    cnt_A = 0
    for i in range(len(part)):
        if part[i] == 'A':
            cnt_A += 1
        else:
            ans += cnt_A

print(ans)

Measured memory_bytes: 5860
#include<stdio.h>

int main(){
	
	int N, M, X, Y;
	
	scanf("%d %d %d %d", &N, &M, &X, &Y);
	
	int kotaX[100000];
	int kotaY[100000];
	int maxX = -123456;
	int minY = 2 << 29;
//	printf("%d\n", minY);
	for(int i = 0; i < N; i++){
		scanf("%d", &kotaX[i]);
		if(kotaX[i] > maxX){
			maxX = kotaX[i];
		}
	}
	for(int i = 0; i < M; i++){
		scanf("%d", &kotaY[i]);
		if(kotaY[i] < minY){
			minY = kotaY[i];
		}
	}
	
	bool isFalse = false;
	
	if(minY <= X || minY > Y){
		isFalse = true;
	}
	for(int i = 0; i < N; i++){
		if(kotaX[i] >= minY){
			isFalse = true;
		}
	}
	
	if(isFalse == true){
		printf("War\n");
	}
	else{
		printf("No War\n");
	}
	
//	printf("%d %d", maxX, minY);
	
	
	
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  char a, b, c, d, e, f;
  cin >> a >> b >> c;
  cin >> d >> e >> f;
  int ans = 0;
  if (a == d){
    ans++;
  }
  if (b == e){
    ans++;
  }
  if (c == f){
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;

vector<ll> G[200050];
bool seen[200050];

ll cnt[200050];
ll cost[200050];

void dfs(ll v) {
    seen[v] = true;
    for(auto nv: G[v]) {
        if(seen[nv]) continue;
        cost[nv] = cost[v] + cnt[nv];
        dfs(nv);
    }
}


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

int N,Q; cin >> N >> Q;
rep(i,N-1) {
    ll a,b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
}

rep(i,N) cnt[i] = 0;
rep(i,Q) {
    ll p,x; cin >> p >> x;
    p--;
    cnt[p] += x;
}

rep(i,N) cost[i] = 0;
cost[0] = cnt[0];

rep(i,N) seen[i] = false;
dfs(0);

rep(i,N) cout << cost[i] << ' ';
cout << endl;

return 0;
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
typedef long long ll;
const int MAXN = 1e6+10;
const int mod = 1e9+7;
using namespace std;


map<int,int>mp; // 1 sheep ,2 wolf

map<int,char>::iterator it;


int main()
{
    int n;
    cin>>n;
    vector<char>ans(n+1);
    string s;
    cin>>s;
    for (int i = 0; i < 4; i++)
    {
        if (i == 0)
        {
            ans[0] = 'S'; ans[1] = 'S';
        }
        else if (i == 1)
        {
            ans[0] = 'S'; ans[1] = 'W';
        }
        else if (i == 2)
        {
            ans[0] = 'W'; ans[1] = 'S';
        }
        else
        {
            ans[0] = 'W'; ans[1] = 'W';
        }
        for (int j = 1; j < n; j++)
        {
            if (ans[j] == 'S')
            {
                if (s[j] == 'o')
                {
                    ans[j + 1] = ans[j - 1];
                }
                else
                {
                    if (ans[j - 1] == 'S')
                    {
                        ans[j + 1] = 'W';
                    }
                    else
                    {
                        ans[j + 1] = 'S';
                    }
                }
            }
            else
            {
                if (s[j] == 'x')
                {
                  ans[j + 1] = ans[j - 1];
                }
                else
                {
                  if (ans[j - 1] == 'S')
                  {
                    ans[j + 1] = 'W';
                  }
                  else
                  {
                    ans[j + 1] = 'S';
                  }
                }
            }
        }

        if (ans[0] != ans[n])
        {
            continue;
        }

        if (ans[0] == 'S')
        {
            if (s[0] == 'o')
            {
                if (ans[n - 1] != ans[1])
                {
                    continue;
                }
            }
            else
            {
                if (ans[n - 1] == ans[1])
                {
                    continue;
                }
            }
        }
        else
        {
            if (s[0] == 'x')
            {
                if (ans[n - 1] != ans[1])
                {
                    continue;
                }
            }
            else
            {
                if (ans[n - 1] == ans[1])
                {
                    continue;
                }
            }
        }

    for (int k = 0; k < n; k++)
    {
      cout << ans[k];
    }
    cout << endl;
    return 0;

  }

  cout<<-1<<endl;

  return 0;

}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

int main() {
	char a[11], b[11];
	int x = 0;
	int lena, lenb;
	scanf("%s %s", &a, &b);
	lena = strlen(a) - 1;
	lenb = strlen(b) - 1;
	if (a[0] == '-') x++;
	if (b[0] == '-') x++;

	if (x % 2 == 1) printf("Zero");
	else if (x == 0) printf("Positive");
	else if ((a[lena] - b[lenb]) % 2 == 0) printf("Negative");
	else printf("Positive");

	return 0;
}

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

// @author: pashka

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

    int n, k, s, t;
    cin >> n >> k >> s >> t;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<long>> cc(n + 1, vector<long>(n + 1));
    for (int i = 0; i <= n; i++) {
        cc[i][0] = cc[i][i] = 1;
        for (int j = 1; j < i; j++) {
            cc[i][j] = cc[i - 1][j] + cc[i - 1][j - 1];
        }
    }
    for (int i = 0; i <= n; i++) {
//        cout << cc[i][0];
        for (int j = 1; j <= n; j++) {
            cc[i][j] += cc[i][j - 1];
//            cout << " " << cc[i][j];
        }
//        cout << "\n";
    }

    vector<int> aa;
    for (int x : a) {
        if ((x & s) == s && (x | t) == t) {
            aa.push_back(x);
        }
    }
    a = aa;
    n = a.size();

    long res = 0;
    for (int x = 0; x < (1 << 18); x++) {
        if ((s & x) != 0 || (t & x) != x) {
            continue;
        }
        long s = 0;
        for (int i = 0; i < n; i++) {
            int q = a[i] & x;
            int c = 0;
            for (int j = i + 1; j < n; j++) {
                if ((a[j] & x) == q) {
                    c++;
                }
            }
            s += cc[c][k - 1];
        }
//        cout << x << " " << s << "\n";
        if (__builtin_popcount(x) % 2 == 0) {
            res += s;
        } else {
            res -= s;
        }
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>

int main(void) {
	unsigned long long num;
	unsigned long long nownum;
	unsigned long long i;
	unsigned long long sum;
	scanf("%lld",&num);
	sum=0;
	for(i=0;i<num;i++) {
		scanf("%lld",&nownum);
		sum+=nownum;
	}
	printf("%lld\n",sum/num);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll s(n);
    bool zero = 1;
    rep(i, n){
        cin >> s[i];
        if(s[i] % 10) zero = 0;
    }
    if(zero){
        cout << 0 << endl;
        return 0;
    }
    sort(ALL(s));
    ll ans = accumulate(ALL(s), 0ll);
    if(ans % 10){
        cout << ans << endl;
    }else{
        rep(i, n){
            if(s[i] % 10){
                cout << ans-s[i] << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int M = 1e5+7;

double mul(double a , int b){
    double ans = a;
    for(int i = 2 ; i <= b ; i++)   ans *= a;
    return ans;
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    double x = 1.0 / mul(2,m) , y = (mul(2,m)-1.0)/mul(2,m);
    //cout<< x << ' ' << y << endl;
    x = (1900.0 * m + 100.0 * (n-m)) * x;
    double ans = 0;
    //cout<< ans << ' ' << x << ' ' << y << endl;
    //printf("ans = %f , x = %f , y = %f\n",ans,x,y);
    for(int i = 1 ; i < M ; i++)    ans += x*i , x *= y;
    printf("%.0f\n",ans);
    return 0;
}


Measured memory_bytes: 256
import sys

MOD = 10**9 + 7

N = int(input())
As = list(map(int, input().split()))

sumA = 0
for A in As:
    sumA += A
    sumA %= MOD
#print('# sumA:', sumA, file=sys.stderr)

ans = sumA * sumA % MOD
for A in As:
    ans -= A * A % MOD
    ans %= MOD
#print('# ans:', ans, file=sys.stderr)

inv2 = pow(2, MOD-2, MOD)
ans *= inv2
ans %= MOD

print(ans)


Measured memory_bytes: 30996
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		
		Scanner sc = new Scanner(System.in);
		
		Integer A = sc.nextInt();
		Integer B = sc.nextInt();
		Integer K = sc.nextInt();
		
		List<Integer>e=new ArrayList<>();
		
		
		for(int i= 1; i<=Math.max(A, B); i++){
			if(A%i==0&&B%i==0){
				e.add(i);
			}
		}
		
		System.out.println(e.get(e.size()-K));

	}


}


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

const int MOD = 1000000007;
const int SMAX = 2001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int S;
  cin >> S;
  vector<long long> dp(SMAX);
  dp[3] = 1;
  for(int i = 4; i <= S; i++){  
    dp[i] = dp[i-1] + dp[i-3];
    dp[i] %= MOD;
  }
  cout << dp[S] <<endl;
}


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


int main()
{
    char s[105], t[105], s1[105],t1[105];
    int ss[105], tt[105];

    scanf("%s",s);
    scanf("%s",t);


    int a = strlen(s);
    int b = strlen(t);

    for(int i=0; i<a; i++) ss[i] = s[i];
    for(int i=0; i<b; i++) tt[i] = t[i];

    sort(ss,ss+a);
    sort(tt,tt+b);

    int i=0;
    for(i=0; i<a; i++) s1[i] = ss[i];
    s1[i] = '\0';
    for( i=0; i<b; i++) t1[i] = tt[b-1-i];
    t1[i] = '\0';

    //printf("%s\n%s\n",s1,t1);

    if(strcmp(s1,t1)<0) puts("Yes");
    else puts("No");


   // main();

    return 0;
}


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

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

//C++14 (GCC 5.4.1)
int main() {
    string S;
    cin >>S;
    
    //-----------------------------------
    bool is;
    int leng=S.size();
    int ans=15-leng;
    rep(i,leng){
        if(S[i]=='o') ans++;
    }
    is=(ans>=8);

    cout << ((is) ? "YES" : "NO") <<endl;
    return (0);
}

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

int main() {
  int *values = new int[200];

  int count;
  int index;
  bool isEven = true;

  int testCount = 0;
  
  cin >> count;
  
  for(index = 0; index < count; index++)
  {
    cin >> values[index];
    if (values[index] % 2 > 0)
    {
      isEven = false;
      break;
    }
  }

  while(isEven)
  {
    testCount++;
    for(index = 0; index < count; index++)
    {
      values[index] /= 2;
      if (values[index] % 2 > 0)
      {
        isEven = false;
        break;
      }
    }
  }
  
  cout << testCount << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int long long
int hmt() {int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';if(n) x=-x;return x;}
#define in hmt()
#define ins ({string x;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c!=' '&&c!='\n';c=getchar()) x+=c;x;})
#define forinc(i,a,b) for(int i=a,_b=b;i<=_b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forb(i,BS) for(int i=BS._Find_first();i< BS.size();i = BS._Find_next(i))
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
const int N=1000010,mod=1e9+7;
int f[N];
main()
{
    //freopen("FF.inp","r",stdin);
	int n=in;
	f[1]=n;
	f[2]=n*n%mod;
	int s=(f[1]+f[2])%mod;
	forinc(i,3,n)
	{
	    f[i]=(n*(n-1)-(i-3)+s-f[i-2])%mod;
	    s=(s+f[i])%mod;
	}
	cout<<(f[n]+mod)%mod<<endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)
int main(){
    int n; cin>>n;
    vector<int> a(n);
    int nneg = 0;
    int minabs = 1e9+1;
    REP(i, n){
        cin >> a[i];
        if(a[i]<0) nneg++;
        a[i] = abs(a[i]);
        if(minabs>a[i]) minabs = a[i];
    }
    unsigned long long sum = 0;
    REP(i, n){
        sum+=a[i];
    }
    if(nneg%2==1){
        cout << sum-2*minabs<<endl;
    } else {
        cout << sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
a,b = map(int, input().split())

allitem = []
for i in range(b):
    allitem.append(i+1)

for i in range(a):
    item = []
    ans = [int(iz) for iz in input().split()]
    for j in range(ans[0]):
        item.append(ans[j+1])

    allitem = list(set(allitem) & set(item))

    
print(len(allitem))

Measured memory_bytes: 3060
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(0, A+1):
    xi = X - 500 * i
    if xi < 0: break
    for j in range(0, B+1):
        xj = xi - 100 * j
        if xj < 0: break
        for k in range(0, C+1):
            xk = xj - 50 * k
            # print('{} {} {} {}'.format(i,j,k,xk))
            if xk == 0: ans += 1
            if xk < 0: break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    map<int, int>mp;
    for(int i=0; i<N; i++){
        int ai;
        cin >> ai;
        mp[ai]++;
        mp[ai+1]++;
        mp[ai-1]++;
    }
    int nax =0;

    for (int i=0; i<pow(10,5); i++){
        chmax(nax, mp[i]);
    }
    cout << nax << endl;
}

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

using namespace std;

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

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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll x, y;
    cin >> x >> y;
    cout << (abs(x - y) <= 1 ? "Brown" : "Alice") << EOL;
}


Measured memory_bytes: 256
import itertools
n=int(input())
x=[]
y=[]
for i in range(n):
    x0, y0 = map(int,input().split())
    x.append(x0)
    y.append(y0)
    
ls = list(itertools.permutations(range(1,n+1)))

dist = 0
for i in ls:

    p0 = i[0]-1
    for j in range(1,len(i)):
        p1 = i[j]-1
        dist += ((x[p0]-x[p1])**2 + (y[p0]-y[p1])**2)**0.5
        p0=p1
        # print(dist)
    # print( )
        

print(dist/(len(ls)))


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

int main(){
    int N;
    int A[111111];
    int i,count;
    count  = 0;
    cin >> N;
    for(i=0;i<=N-1;i++)
        cin >> A[i];
    for(i=0;i<=N-1;i++)
        if(A[i]%2==1) count++;
    if(count%2==0) cout << "YES" << endl;
    if(count%2==1) cout << "NO" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define db double
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=1e7+10,M=3e4+10;
const ll inf=INT_MAX,mod=1e9+7;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
ll lcm(ll a,ll b) {return a/__gcd(a,b)*b; }
int read()
{
    int s=0,f=1; char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}

unordered_set<ll> st;

int main()
{
    iosks;
    ll n;
    cin>>n;
    ll ans=1,j=7;
    while(1){
        while(j<n) j=j*10+7, ans++;
        ll k=j%n;j=j%n;
        if(k==0) {cout<<ans<<endl;return 0;}
        if(st.count(k)==1) {cout<<-1<<endl; return 0;}
        st.insert(k);

    }
    return 0;
}
/**
23
3 2 1
3 2 1

*/

Measured memory_bytes: 39444
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
    {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
    {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
    #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
    #define dump(...)
    #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
    int m, d; cin >> m >> d;
    int ans = 0;
    REPI (a, 2, 10) {
        REPI (b, 2, 10) {
            if (a * 10 + b <= d) {
                if (a * b <= m) ans++;
            }
        }
    }
    cout << ans << endl;
}


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

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		int[] c = new int[m];
		for (int i = 0; i < m; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
			--a[i];
			--b[i];
		}
		solve(n, m, a, b, c);
	}

	void solve(int n, int m, int[] a, int[] b, int[] c) {
		int[] C = new int[1 << n];
		int[][] adj = new int[n][n];
		for (int i = 0; i < m; ++i) {
			adj[a[i]][b[i]] = c[i];
			adj[b[i]][a[i]] = c[i];
		}
		for (int s = 0; s < (1 << n); ++s) {
			for (int i = 0; i < n; ++i) {
				for (int j = i + 1; j < n; ++j) {
					if (((1 << i) & s) > 0 && ((1 << j) & s) > 0) {
						C[s] += adj[i][j];
					}
				}
			}
		}

		int[][] f = new int[1 << n][n];// 最大化
		for (int i = 0; i < f.length; ++i) {
			for (int j = 0; j < f[i].length; ++j) {
				f[i][j] = -Integer.MAX_VALUE / 8;
			}
		}
		f[1][0] = 0;

		for (int s = 1; s < (1 << n); ++s) {
			for (int src = 0; src < n; ++src) {
				if (((1 << src) & s) == 0)
					continue;
				for (int dst = 0; dst < n; ++dst) {
					if (((1 << dst) & s) > 0 || adj[src][dst] == 0)
						continue;
					f[s | 1 << dst][dst] = Math.max(f[s | 1 << dst][dst], f[s][src] + adj[src][dst]);
				}

				int _s = (1 << n) - 1 - s;
				for (int t = ((1 << n) - 1) & _s; t > 0; t = (t - 1) & _s) {
					f[s | t][src] = Math.max(f[s | t][src], f[s][src] + C[t | 1 << src]);
				}
			}
		}

		int ans = C[(1 << n) - 1] - f[(1 << n) - 1][n - 1];
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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

// Union find
int par[50];
void init(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
	}
}

int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}

void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	par[x]=y;
}
bool same(int x, int y){
	return find(x)==find(y);
}

int main(){
	int N,M;
	cin>>N>>M;
	vector<pair<int,int>>v;
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		a--; b--;
		v.push_back(make_pair(a,b));
	}
	int cnt=0;
	for(int i=0;i<v.size();i++){
		init(N);
		for(int j=0;j<v.size();j++){
			if(i==j)continue;
			unite(v[j].first,v[j].second);
		}
		if(!same(v[i].first,v[i].second))cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

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

using namespace std;

#define FOR( i, k, n ) for ( int i = ( k ); i <= ( int )( n ); ++i )
#define REP( i, n ) FOR( i, 1, n )

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

void DecodeJ( string& );
void DecodeC( string& );
void DecodeE( string& );
void DecodeA( string& );
void DecodeP( string& );
void DecodeM( string& );

int main()
{
	int n;  cin >> n;
	while( n-- ) {
		char order[ 7 ];
		stack< char > stc;
		string message;
		cin >> order;
		cin >> message;
		for( int i = 0; order[ i ] != '\0'; ++i ) stc.push( order[ i ] );
		while( !stc.empty() ) {
			char fool = stc.top();  stc.pop();
			switch( fool ) {
			case 'J' : DecodeJ( message ); break;
			case 'C' : DecodeC( message ); break;
			case 'E' : DecodeE( message ); break;
			case 'A' : DecodeA( message ); break;
			case 'P' : DecodeP( message ); break;
			case 'M' : DecodeM( message ); break;
			};
		}
		cout << message << endl;
	}
	return 0;
}

void DecodeJ( string& message ) {
	int size = message.size();
	string tmp;
	tmp += message[ size - 1 ];
	tmp += message.substr( 0, size - 1 );
	message = tmp;
}

void DecodeC( string& message ) {
	int size = message.size();
	string tmp;
	tmp += message.substr( 1, size - 1 );
	tmp += message[ 0 ];
	message = tmp;
}

void DecodeE( string& message ) {
	int size = message.size();
	string tmp;
	if( size % 2 ) {
		tmp += message.substr( size / 2 + 1, size / 2 );
		tmp += message[ size / 2 ];
		tmp += message.substr( 0, size / 2 );
	}
	else {
		tmp += message.substr( size / 2, size / 2 );
		tmp += message.substr( 0, size / 2 );
	}
	message = tmp;
}

void DecodeA( string& message ) {
	string tmp;
	string::reverse_iterator rit = message.rbegin();
	for( ; rit != message.rend(); ++rit ) tmp += *rit;
	message = tmp;
}

void DecodeP( string& message ) {
	string tmp;
	string::iterator it = message.begin();
	for( ; it != message.end(); ++it ) {
		char ch = *it;
		if( ch == '0' ) tmp += '9';
		else if( '1' <= ch && ch <= '9' ) tmp += ( char )( ch - 1 );
		else tmp += ch;
	}
	message = tmp;
}

void DecodeM( string& message ) {
	string tmp;
	string::iterator it = message.begin();
	for( ; it != message.end(); ++it ) {
		char ch = *it;
		if( ch == '9' ) tmp += '0';
		else if( '0' <= ch && ch <= '8' ) tmp += ( char )( ch + 1 );
		else tmp += ch;
	}
	message = tmp;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll l,r;
  cin >> l >>r;
  if(r-l>=2019)cout << 0 << endl;
  else{
    ll m=inf;
    for(ll i=l;i<r;i++){
      for(ll j=i+1;j<=r;j++)m=min(m,i*j%2019);
    }
    cout << m << endl;
  }


}

Measured memory_bytes: 3600
package main

import (
	"fmt"
	"sort"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}
func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		A[i] = a
	}
	sort.Ints(A)
	sum := float64(A[0])
	for i := 1; i < N; i++ {
		sum = (sum + float64(A[i])) / 2
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
program main
implicit none
integer :: n
integer , allocatable :: b(:), c(:,:), res(:)
integer :: i, j

read(*,*) n
allocate(b(n))
allocate(c(n,n))
allocate(res(n))
read(*,*) b(1:n)

c(1,:) = b(:)
do i = 1, n
   if(b(i) > i ) then
      write(*,'(i0)') -1
      stop
   end if
   do j = 1, n-i+1
      if(c(i,j) == j) then
         c(i+1, 1:j-1) = c(i,1:j-1)
         c(i+1, j:n-i)   = c(i,j+1:n-i+1)
         res(i)        = j
      end if
   end do
end do

do i = 1 ,n
    write(*,'(i0)') res(n-i+1)
end do

end program main


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
 int a,b;
 cin>>a>>b;
 if(a>b){
     cout<<"1"<<endl;
 }
else {
		if (b % a == 0){
		 cout << b / a << endl;
		}
		else if (b % a != 0){
		cout << (b / a) + 1 << endl;
		}
}

        return 0;
    
}



Measured memory_bytes: 3104
N,H = map(int, raw_input().split())
x = [None]*(N*2)
for i in range(N):
  a,b = map(int, raw_input().split())
  x[2*i] = (a, 0)
  x[2*i+1] = (b, 1)
x = sorted(x)[::-1]
ans = 0
for t in x:
  if t[1]==0:
    print ans+(H+t[0]-1)/t[0]
    break
  H -= t[0]
  ans += 1
  if H<=0:
    print ans
    break


Measured memory_bytes: 29428