akhauriyash/Code-Regression huggingface dataset:
#h=int(input())
n,m=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

dic={}
ans=0
for i in range(n):
    templ=list(map(int,input().split()))
    k=templ[0]
    for j in range(k):
        a=templ[1+j]
        dic[a]=dic.get(a,0)+1
for k in dic.keys():
    if dic[k]==n:
        ans+=1
print(ans)


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

int main() {

	int64_t N;
	cin >> N;
	int64_t sum = 0;

	for (int64_t i = 1; i < N+1;i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			sum = sum + i; 
		}

	}
	cout << sum << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void) {
	int N;
	if (scanf("%d", &N) != 1) return 1;
	if (N == 1) {
		puts("Hello World");
	} else if (N == 2) {
		int A, B;
		if (scanf("%d", &A) != 1) return 1;
		if (scanf("%d", &B) != 1) return 1;
		printf("%d\n", A + B);
	} else {
		puts("You are an idiot!");
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int N,A[18],x[18][18],y[18][18],two[25]={1},res=0,tmp;
int main() {
	cout << fixed << setprecision(18);
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		for(int j=0;j<A[i];j++){
			cin>>x[i][j]>>y[i][j];
			x[i][j]--;
			
		}
	}
	for(int i=1;i<20;i++){
		two[i]=2*two[i-1];
	}
	for(int i=0;i<two[N];i++){
		bool key=false;
		tmp=0;
		for(int j=0;j<N;j++){
			if((two[j]&i)==0){continue;}
			tmp++;
			for(int k=0;k<A[j];k++){
				//j番目の人のｋ番目の意見が異なる時
				if((two[x[j][k]]&i)!=y[j][k]*two[x[j][k]]){
					key=true;
					break;
				}
			}
			if(key){break;}
		}
		if(!key){
			res=max(tmp,res);
			//cout<<"DEBUG "<<i<<endl;
		}
	}
	cout<<res;
} 

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

using namespace std;

int main() {

    int A, B;
    cin >> A >> B;
    int ans = 0;
    int have = 1;

    while (have < B) {
        have = have + A - 1;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=n1;i<(int)(n2);i++)
using namespace std;

signed main()
{
  int N;
  cin >> N;
  std::vector<long double> H(N);
  Rep(i, N) cin >> H[i];
  sort(H.begin(), H.end());

  long double S;
  S = H[0]/std::pow(2, N-1);
  For(i, 1, N) S += H[i]/std::pow(2, N-i);

  cout << S;
  return 0;
}


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

buy_count = (x//105) + 1
over_cost = 105 - x%105
can_buy = False

while buy_count>=0:
    if over_cost == 105:
        can_buy = True
        break
    
    if over_cost >= 5:
        over_cost -= 5
        buy_count -= 1
    elif over_cost >= 4:
        over_cost -= 4
        buy_count -= 1
    elif over_cost >= 3:
        over_cost -= 3
        buy_count -= 1
    elif over_cost >= 2:
        over_cost -= 2
        buy_count -= 1
    elif over_cost >= 1:
        over_cost -= 1
        buy_count -= 1
    elif over_cost == 0:
        can_buy = True
        break
        
if can_buy:
    print('1')
else:
    print('0')

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    AB=[list(map(int,input().split())) for _ in range(n)]
    CD=[list(map(int,input().split())) for _ in range(n)]
    AB.sort(lambda x:x[1],reverse=1)
    CD.sort()

    ans=0
    for i in range(n):
        c,d=CD[i]
        for j in range(n):
            a,b=AB[j]
            if(a<c and b<d):
                AB[j]=[INF,INF]
                CD[i]=[-INF,-INF]
                ans+=1
                break
    print(ans)
resolve()

Measured memory_bytes: 39280
#include<stdio.h>
int main()
{
	int A,B;
	do
	{
	scanf("%d %d",&A,&B);
    }while(A+B>16);
    if(A>8||B>8)
	printf(":(");
	if(A<=8&&B<=8)
	printf("Yay!");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	int INF = 1 << 24;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			sc.nextLine();
			int [][] pass = new int[n + 1][n + 1];
			for(int i = 0; i <= n; i++){
				Arrays.fill(pass[i], INF);
				pass[i][i] = 0;
			}
			HashMap<String, Integer> label = new HashMap<String, Integer>();
			ArrayList<String> gotostr = new ArrayList<String>();
			ArrayList<Integer> gotoind = new ArrayList<Integer>();
			for(int i = 0; i < n; i++){
				String s = sc.nextLine();
				if(s.contains(":")){
					String key = s.split(":")[0];
					label.put(key, i);
					pass[i][i+1] = 0;
				}
				else{
					//goto
					String key = s.split("[ ;]")[1];
					gotostr.add(key);
					gotoind.add(i);
					pass[i][i+1] = 1;
				}
			}
			
			for(int i = 0; i < gotoind.size(); i++){
				int ind = gotoind.get(i);
				String key = gotostr.get(i);
				int to = label.get(key);
				pass[ind][to] = 0;
			}
			
			n = pass.length;
			for(int j = 0; j < n; j++){
				for(int i = 0; i < n; i++){
					for(int k = 0; k < n; k++){
						pass[i][k] = Math.min(pass[i][k], pass[i][j] + pass[j][k]);
					}
				}
			}
			System.out.println(pass[0][n-1]);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 20440
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll r,s,p;
    cin>>r>>s>>p;
    string si;
    cin>>si;
    vector<ll> dp_r(n);
    vector<ll> dp_p(n);
    vector<ll> dp_s(n);
    FOR(i,0,k){
        if(si[i] == 'r') dp_p[i] = p;
        if(si[i] == 'p') dp_s[i] = s;
        if(si[i] == 's') dp_r[i] = r;        
    }
    FOR(i,k,n){
        if(si[i] == 'r'){
            dp_r[i] = max(dp_p[i-k],dp_s[i-k]);
            dp_p[i] = max(dp_s[i-k],dp_r[i-k]) + p;
            dp_s[i] = max(dp_r[i-k],dp_p[i-k]);
        }
        if(si[i] == 'p'){
            dp_r[i] = max(dp_p[i-k],dp_s[i-k]);
            dp_p[i] = max(dp_s[i-k],dp_r[i-k]);
            dp_s[i] = max(dp_r[i-k],dp_p[i-k]) + s;
        }
        if(si[i] == 's'){
            dp_r[i] = max(dp_p[i-k],dp_s[i-k]) + r;
            dp_p[i] = max(dp_s[i-k],dp_r[i-k]);
            dp_s[i] = max(dp_r[i-k],dp_p[i-k]);
        }
        
    }
    ll ans = 0;
    FOR(i,n-k,n){
        ans += max(dp_p[i],max(dp_r[i],dp_s[i]));
    }
    cout<<ans<<endl;
}

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

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

using namespace std;


int a[1010];

int main(void){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		rep(i,n) cin >> a[i];
		cout << (accumulate(a,a+n,0)-*max_element(a,a+n)-*min_element(a,a+n))/(n-2) << endl;
	}
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int N = scan.nextInt();
        int[] ls = new int[N];
        for (int i = 0; i < N-1; i++) {
            int boss = scan.nextInt();
            ls[boss-1] ++;
        }
        for (int i:ls) {
            System.out.println(i);
        }
    }
}



Measured memory_bytes: 60140
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ls = []
    cnt = 1
    for i in range(1, n):
        if s[i] != s[i-1]:
            ls.append(cnt-1)
            cnt = 1
        else:
            cnt += 1
    ls.append(cnt-1)
    print(min(n-1, sum(ls) + k * 2))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 45296
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int i, s;
	int a[10000], b[10000];
	int at, bt;

	scanf("%d", &s);

	while (s != 0)
	{	at = 0;
		bt = 0;

		for (i = 0; i < s; i++)
		{
			scanf("%d %d", &a[i], &b[i]);

			if (a[i] < b[i])
			{
				at += a[i] + b[i];
			}
			else if (a[i] > b[i])
			{
				bt += a[i] + b[i];
			}
			else if (a[i] == b[i])
			{
				at += a[i];
				bt += b[i];
			}

		}
		printf("%d %d\n", bt, at);
		scanf("%d", &s);
		if (s == 0)
		{
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 676
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
 
int main(){
    int d, e;
    cin >> d >> e;
    while(d > 0){
        double ans = 1000000000;
        for(int x=0; x<=d; x++){
            int y = d-x;
            ans = min(ans, abs(sqrt(x*x+y*y)-e));
        }
        cout << fixed << setprecision(20) << ans << endl;
        cin >> d >> e;
    }
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

int N;
char mp[310][310];
char mpt[310][310];
bool check(int k)
{
  REP(i, N) {
    REP(j, N) {
      if (mp[i][(j + k) % N] != mpt[(i + k) % N][j]) return false;
    }
  }
  return true;
}

int main()
{
  cin >> N;
  REP(i, N) {
    REP(j, N) {
      cin >> mp[i][j];
      mpt[j][i] = mp[i][j];
    }
  }
  int ans = 0;
  REP(i, N) {
    if (check(i)) ans += N;
  }
  cout << ans << endl;
  return 0;
}

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

//solution:
#define block(i) (i / B)
constexpr int N = 500001, A = 500'001, Q = 500'001;
int f[A], a[N], ans[Q], B = 707, answer;

struct query {
    int lo, hi, idx;
    query() {}
    query(int lo, int hi, int idx): lo(lo), hi(hi), idx(idx) {}
    bool operator < (const query& q) {
        if(block(lo) != block(q.lo)) return block(lo) < block(q.lo);
        return (block(lo) & 1) ? (hi < q.hi) : (hi > q.hi);
    }
} q[Q];

void hike() {
    int n, m; cin >> n >> m;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < m; ++i) {
        cin >> q[i].lo >> q[i].hi;
        --q[i].lo; --q[i].hi; q[i].idx = i;
    }
    sort(q, q + m);
    auto insert = [&](int i) {
        f[a[i]]++;
        if(f[a[i]] == 1) ++answer;
    };
    auto remove = [&](int i) {
        f[a[i]]--;
        if(f[a[i]] == 0) --answer;
    };
    int l = 0, r = -1;
    for(int i = 0; i < m; ++i) {
        int lo = q[i].lo, hi = q[i].hi;
        while(lo < l) insert(--l);
        while(hi > r) insert(++r);
        while(lo > l) remove(l++);
        while(hi < r) remove(r--);
        ans[q[i].idx] = answer;
    }
    for(int i = 0; i < m; ++i) cout << ans[i] << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) hike();
    return 0;
} //farewell, until we meet again..


Measured memory_bytes: 15488
N,M,q= map(int,input().split())
s=[list(map(int,input().split())) for _ in range(q)]


V = [[] for _ in range(N+1)]

# 初期値として長さ1のものを入れる
for i in range(1, M+1):
    V[1].append([i])

# V[k] から V[k+1] を作る
for i in range(1, N):
    for v in V[i]:
        # 単調増加なので、末尾の値以上であるものを全て試す
        b = v[-1]
        for a in range(b, M+1):
            v2 = v + [a]
            V[i+1].append(v2)
#print(V)
maxi=0
for w in V[N]:
    total=0
    for i in s:
        if w[i[1]-1]-w[i[0]-1]==i[2]:
            total+=i[3]
        if maxi<total:
            maxi=total
        #print(i)
print(maxi)

Measured memory_bytes: 108156
#include<algorithm>
#include<chrono>
#include<climits>
#include<functional>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
// #include<bits/stdc++.h>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

const int MAXN = 1e5 + 20;


int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;
 	
    int n;
    vector<pair<int, int>> a;
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; i++) {
    	cin >>a[i].first;
    	a[i].second = i + 1;
    }
    sort(all(a), [](const pair<int, int> & x, const pair<int, int> & y) {
    	return x.first < y.first;
    });

    for(int i = 0; i < n; i++) 
    	cout << a[i].second << ' ';
    cout << endl;
    return 0;
}























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

using namespace std;

#define INF 2147483647
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

signed main()
{
    Int(n);
    vp data(n);
    rep(i, n) {
        cin >> data[i].fir;
        data[i].sec = i+1;
    }
    sort(all(data));

    set<int> st;
    st.insert(0);
    st.insert(n+1);
    int ans = 0;
    rep(i, n) {
        int num = data[i].fir, pos = data[i].sec;
//        cout << pos << endl;
        st.insert(pos);
        auto ptr = st.find(pos);
        auto l = --ptr;
        ptr++; auto r = ++ptr;
        ptr--;
        ans += (pos - *l) * num * (*r - pos);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 12800
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int y1, m1, d1, y2, m2, d2;
	cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;

	if (y1 == y2) {
		if (m2 < m1) {
			swap(m2, m1);
			swap(d1, d2);
		}
		if (m2 == m1) {
			if (d2 < d1)swap(d2, d1);
		}
	}
	if (y1 > y2) {
		swap(y1, y2);
		swap(m2, m1);
		swap(d1, d2);
	}

	int ans = 0, ageA = 0, ageB = 0;
	eFOR(i, y1, y2 + 6) {
		eFOR(j, 1, 12) {
			int k;
			if (j == 2) {
				k = 28;
				if (i % 4 == 0 && i % 100 != 0)k++;
				else if (i % 400 == 0)k++;
			}
			if (j == 4 || j == 6 || j == 9 || j == 11)k = 30;
			else k = 31;

			eFOR(d, 1, k) {
				if (j == m1 && d == d1 && i>=y1) {
					ageA++;
				}
				if (j == m2 && d == d2 && i>=y2) {
					ageB++;
				}
				if (m1 == 2 && d1 == 29 && k == 28 && j == 3 && d == 1 && i >= y1) {
					ageA++;
				}
				if (m2 == 2 && d2 == 29 && k != 29 && j == 3 && d == 1 && i >= y2)ageB++;

				ans = max(ans, abs(ageA - ageB));
			}
		}
	}
	cout << ans << endl;

	return 0;
}




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

void solve()
{        
    int n,x,t;
    cin >> n >> x >> t;
    cout << (n/x)*t + (n%x!=0?t:0) << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);     
    int t;
    //cin >> t;
    t=1;
    for (int tt=1;tt<=t;tt++)
        {
            solve();
        }
        return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>

int main()
{
        int N;
        long L[101];
        int i;
        int j;
        int k;
        long count=0;
        scanf("%d",&N);
        for(i=0;i<N;i++) scanf("%ld",&L[i]);
        for(i=0;i<N;i++)
        {
                for(j=i+1;j<N;j++)
                {
                        for(k=j+1;k<N;k++)
                        {
                                if( L[i] != L[j] & L[i] != L[k] & L[j] != L[k] )
                                {
                                        if( L[i] + L[j] > L[k] & L[i] < L[k] & L[j] < L[k] )
                                        {
                                                count++;
                                        }else if( L[j] + L[k] > L[i] & L[j] < L[i] & L[k] < L[i] )
                                        {
                                                count++;
                                        }else if( L[k] + L[i] > L[j] & L[k] < L[j] & L[i] < L[j] )
                                        {
                                                count++;
                                        }
                                }
                        }
                }
        }
        printf("%ld\n",count);
        return 0;
}


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

#define int long long

const int N = 1e5 + 10;
int n, ar[N], ans[N], tmp[N];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i], tmp[i] = ar[i];
	
	int mn = (int)1e9 + 10, indx = 0;
	for (int i = 0; i < n; i++)
		if (ar[i] < mn)
			mn = ar[i], indx = i;
	
	for (int i = (indx + 1) % n; i != indx; i = (i + 1) % n) {
		int nxt = (i + 1) % n;
		tmp[nxt] -= tmp[i];
		tmp[i] = 0;
	}
	
	int rem = abs(tmp[indx]) / 2;
	ans[(indx + 1) % n] += 2 * rem;
	ar[indx] -= rem;
	ar[(indx + 1) % n] -= rem;
	for (int i = (indx + 1) % n; i != indx; i = (i + 1) % n) {
		int nxt = (i + 1) % n;
		ans[nxt] += 2 * ar[i];
		ar[nxt] -= ar[i];
		ar[i] = 0;
	}
	
	for (int i = 0; i < n; i++)
		cout << ans[i] << ' ';
	cout << endl;
}

Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int main()
{
    int A;
    int B;
    int C;
    
    cin >> A >> B >> C;
    
    int max;
    int x;
    int y;
    int z;
    int temp;
    
    x = A;
    y = B;
    z = C;
    if (B > x){
        x = B;
        y = A;
    }
    if (C > x){
        temp = x;
        x = C;
        z = y;
        y = temp;
    }
    
    max = x * 10 + y + z;
    
    cout << max << endl;
    
    return 0;
}

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


#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
typedef long long int lli;
typedef long long ll;
typedef long double ld;


signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        int x,y;
        cin>>x>>y;
        if(y%2!=0)
            cout<<"No";
        else if(y<2*x)
            cout<<"No";
        else if(y>4*x)
            cout<<"No";
        else 
            cout<<"Yes";
    }   
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
int main(){
	int n,k,cont =0;
	scanf("%d %d\n",&n,&k);
	int a[n];
	for (int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if (a[i]>=k){
			cont+=1;
		}
	}
	printf("%d\n",cont);
	return 0;
}


Measured memory_bytes: 512
from sys import stdin

def main():
    from collections import deque
    input = stdin.readline
    n, q = map(int, input().split())
    a = [[] for _ in range(n)]
    for i in range(n - 1):
        x, y = map(int, input().split())
        a[x - 1].append(y - 1)
        a[y - 1].append(x - 1)
    p = [0] * n
    for i in range(q):
        x, y = map(int, input().split())
        p[x - 1] += y
    c = [0] * n
    c[0] = 1
    que = deque([])
    que.append(0)
    while len(que) > 0:
        e = que.popleft()
        for i in a[e]:
            if c[i] > 0:
                continue
            c[i] = 1
            p[i] += p[e]
            que.append(i)
    for i in range(n):
        print(p[i])
main()

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

int main(){
    cin>>A>>B;
    if((B-1)%(A-1)){
    cout<<((B-1)/(A-1)+1)<<endl;
    }else{
        cout<<((B-1)/(A-1))<<endl;
    }
    return 0;
}

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

void fnInput(vector<string>& rvsBoard)
{
  int nHigh, nWide;
  cin >> nHigh >> nWide;

  rvsBoard.resize(nHigh);
  for (int i = 0; i < nHigh; i++)
    cin >> rvsBoard[i];
}

int fnCountBomb(int nx, int ny, const vector<string>& cnrvsBoad)
{
  if (   nx >= 0  && nx < cnrvsBoad.size()
      && ny >= 0  && ny < cnrvsBoad[nx].size())
    if (cnrvsBoad[nx][ny] == '#')  return 1;
    else;

  return 0;
}

void fnMinesweeper(vector<string>& rvsBoard)
{
  const vector<int> cnvnDx = {-1, -1, -1,  0,  0,  1,  1,  1};
  const vector<int> cnvnDy = {-1,  0,  1, -1,  1, -1,  0,  1};
  for (int nx = 0; nx < rvsBoard.size(); nx++)
  {
    for (int ny = 0; ny < rvsBoard[nx].size(); ny++)
    {
      if (rvsBoard[nx][ny] == '.')
      {
        int nCount = 0;
        for (int i = 0; i < cnvnDx.size(); i++)
          nCount += fnCountBomb(nx + cnvnDx[i], ny + cnvnDy[i], rvsBoard);

        rvsBoard[nx][ny] = '0' + nCount;
      }
    }
  }
}

void fnResult(const vector<string>& cnrvsBoard)
{
  for (string sBoard : cnrvsBoard)
    cout << sBoard << endl;
}

int main()
{
  vector<string> vsBoard;

  fnInput(vsBoard);
  fnMinesweeper(vsBoard);
  fnResult(vsBoard);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 100005;
int n,m;
vector<int> Graph[n_max];
int saisyoku[n_max];



void dfs(int v,int color){
    saisyoku[v] = color;
    itrfor(itr,Graph[v]){
        if( saisyoku[*itr] == -1){
            dfs(*itr, (color + 1) % 2);
        }
    }
}

signed main(){
    cin >> n >> m;
    REP(i,m){
        int a,b;
        cin >> a >> b;
        a --;
        b --;
        Graph[a].push_back(b);
        Graph[b].push_back(a);
    }
    REP(i,n) saisyoku[i] = - 1;
    dfs(0,0);
    bool flag = false;
    REP(i,n){
        itrfor(itr,Graph[i]){
            if( saisyoku[*itr] == saisyoku[i]){
                flag = true;
                break;
            }
        }
        if(flag) break;
    }

    if(flag){
        cout << n *(n- 1) / 2 - m << endl;
    }
    else{
        int ki = 0;
        REP(i,n){
            if(saisyoku[i] == 0) ki ++;
        }

        cout << ki * (n - ki) - m << endl;
    }

}

Measured memory_bytes: 7552
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BPickingUp {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> x(N), y(N);
        REP(i, N) cin >> x[i] >> y[i];

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

        vector<int> p, q;
        REP(i, N) {
            FOR(j, i+1, N-1) {
                p.push_back(x[j] - x[i]);
                q.push_back(y[j] - y[i]);
            }
        }

        int res = INF;
        REP(i, p.size()) {

            int tmp = 0;
            map<pair<int, int>, bool> used;
            REP(j, N) {
                used[{x[j], y[j]}] = false;
            }
            REP(j, N) {
                if (used[{x[j], y[j]}]) continue;

                tmp++;
                int cur_x = x[j];
                int cur_y = y[j];
                used[{cur_x, cur_y}] = true;
                while (used.count({cur_x - p[i], cur_y - q[i]}) > 0)  {
                    cur_x -= p[i];
                    cur_y -= q[i];
                    used[{cur_x, cur_y}] = true;
                }
                while (used.count({cur_x + p[i], cur_y + q[i]}) > 0)  {
                    cur_x += p[i];
                    cur_y += q[i];
                    used[{cur_x, cur_y}] = true;
                }
            }
            res = min(res, tmp);
        }
        cout << res << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BPickingUp solver;
    solver.solve(in, out);
    return 0;
}


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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main(){
    int n; cin>>n;
    vector<string> w(n+10);
    for(int i=0; i<n; i++) cin>>w[i];
    
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i == j) continue;
            if(w[i] == w[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    for(int i=1; i<n; i++){
        int last=w[i-1].size()-1;
        if(w[i-1][last] != w[i][0]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
	string s;
	cin>>s;
	int len = s.length();
	for(int i=0;i<len;i++) {
		if(s[i] == '?')
			s[i] = 'D';
	}
	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 3748
void main() {
    string s = readln.chomp;
    string s1 = s[0..2], s2 = s[2..$];
    bool yymm, mmyy;
    if ("01" <= s1 && s1 <= "12") mmyy = true;
    if ("01" <= s2 && s2 <= "12") yymm = true;
    if (yymm && mmyy) {
        writeln("AMBIGUOUS");
    } else if (yymm && !mmyy) {
        writeln("YYMM");
    } else if (!yymm && mmyy) {
        writeln("MMYY");
    } else {
        writeln("NA");
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.typecons;

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template <unsigned long long mod> class modint {
  public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) { ret *= a; }
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;

class Solution {
public:
	void solve() {
		long long n;
		mint k;
		cin >> n >> k;
		vector<int> a(n, 0);
		for(int i=0; i<n; i++)cin >> a[i];
		mint ret = 0;
		for(int i=0; i < n; i++){
			for(int j=i+1; j < n; j++){
				if(a[i] > a[j])ret += 1;
			}
		}
		ret *= k;
		sort(a.begin(), a.end());
		int x = 0;
		for(int i = 1; i <n; i++){
			if(a[i] != a[i-1]){
				x = i;
			}
			ret += ((k * (k-1))/2) * x;
		}
		cout << ret << endl;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main (){
  int n,i,j,c,a,minj,count;
  int b[N];  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    b[i]=a;
    //printf("%d",b[i]);
  }

  for(i=0;i<=n-1;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(b[j]<b[minj]){
	minj = j;
      }
    }
    if(b[minj]!=b[i]){
    c = b[i];
    b[i]=b[minj];
    b[minj]=c;
    count++;
    }
  }

  for(i=0;i<n-1;i++){
    printf("%d ",b[i]);
  }
  printf("%d\n",b[i]);
  printf("%d\n",count);
  
  return 0;
}



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

using namespace std;

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

typedef long long ll;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main()
{
    while(true){
        int N;cin>>N;
        if(!N)break;
        int nx=0,ny=0;
        vector<pair<int,int>>squs;
        squs.emplace_back(0,0);
        for(int i=0;i<N-1;++i){
            int n,d;cin>>n>>d;
            auto from=squs[n];
            from.first+=dx[d];
            from.second+=dy[d];
            squs.push_back(from);
        }
        int minx=0,miny=0,maxx=0,maxy=0;
        for(int i=0;i<N;++i){
            auto squ(squs[i]);
            minx=min(minx,squ.first);
            miny=min(miny,squ.second);
            maxx=max(maxx,squ.first);
            maxy=max(maxy,squ.second);

        }
        int H=maxy-miny+1;
        int W=maxx-minx+1;
        cout<<W<<" "<<H<<endl;
    }
    return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N; cin >> N;
  ll ans = 0;

  for(ll i = 0; i < N; i++){
    ans += (i+1) * (N-i);
  }
  for(int i = 0; i < N-1; i++){
    ll x,y; cin >> x >> y;
    x--; y--;
    if(x>y) swap(x,y);
    ans -= (x+1) * (N-y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int H,W,i,j,count=0;
  cin >> H >> W;
  vector<vector<char>> a(H,vector<char>(W));
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      cin >> a.at(i).at(j);
    }
  }
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      if(a.at(i).at(j)=='.')
        count++;
    }
    if(count==W)
      for(j=0; j<W; j++)
        a.at(i).at(j)='%';
    count=0;
  }
  count=0;
  for(i=0; i<W; i++){
    for(j=0; j<H; j++){
      if(a.at(j).at(i)=='.' || a.at(j).at(i)=='%')
        count++;
    }
    if(count==H)
      for(j=0; j<H; j++)
        a.at(j).at(i)='%';
    count=0;
  }
  count=0;
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      if(a.at(i).at(j)!='%')
        cout << a.at(i).at(j);
    }
    for(j=0; j<W; j++){
      if(a.at(i).at(j)=='%')
        count++;
    }
    if(count!=W)
      cout << endl;
    count=0;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int H,h,m,s,ansup,ansdown,x,jy,ansm,ansh;
void gx(int up,int down)
{
    //cout<<h<<" "<<m<<" "<<up<<" "<<down<<"cs"<<endl;
    if(up<0||up/down<s)return ;
    if(up/down>=60)
        return;
    if(m*H!=h*60||(up/down)!=m%60)
    {
        if(up>0)
        {
            x=gcd(up,down);
            ansup=up/x;
            ansdown=down/x;
        }
        else
        {
            ansup=0;
            ansdown=1;
        }
        ansm=m;
        ansh=h;
    }
}
int main()
{
    while(scanf("%d%d%d%d",&H,&h,&m,&s)&&H)
    {
        //1  m>h  s>m
        ansup=-1;
            int ansdown1=119*H-1;
            int ansup1=3600*(H+h)+60*m*H+60*m;
            gx(ansup1,ansdown1);
            //2 m>h  s<m

            ansup1=3600*h+60*m*H+60*m;
            gx(ansup1,ansdown1);

            ansup1=3600*(h-H)+60*m*H+60*m;
            gx(ansup1,ansdown1);
        if(ansup>=0)
        printf("%d %d %d %d\n",ansh,ansm,ansup,ansdown);
        else
        {
            m++;
            s=0;
            if(m==60)m=0,h=(h+1)%H;
            ansdown1=119*H-1;
            ansup1=3600*(H+h)+60*m*H+60*m;
            gx(ansup1,ansdown1);
            //2 m>h  s<m
            ansup1=3600*h+60*m*H+60*m;
            gx(ansup1,ansdown1);
            ansup1=3600*(h-H)+60*m*H+60*m;
            gx(ansup1,ansdown1);
            printf("%d %d %d %d\n",ansh,ansm,ansup,ansdown);
        }
    }
    return 0;
}

Measured memory_bytes: 1188
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())

    s = int(sqrt(N))
    ans = INF
    for a in range(1, s + 1):
        b = N // a
        if a * b == N:
            ans = min(ans, max(len(str(a)), len(str(b))))
    print(ans)

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main(){
  int n;
  while(cin >> n, n!=0){
    vector<pair<int, char>> v;

    for(int i=0; i<n; ++i){
      char tmp;
      cin >> tmp;
      v.push_back(make_pair(0, tmp));
      
      for(int j=0; j<n-1; ++j){
	int scr;
	cin >> scr;
	
	if(scr==0){
	  v[i].first = v[i].first + 10;
	}else if(scr==2){
	  v[i].first = v[i].first + 1;
	}
      }
      
    }
    //sort(v.begin(), v.end(), greater<pair<int, char>>());
    //reverse(v.begin(), v.end());
    for(int i=0; i<n; ++i){
      for(int j=0; j<n-1; ++j){
	if(v[j].first < v[j+1].first){
	  pair<int, char> pr;
	  pr = v[j];
	  v[j] = v[j+1];
	  v[j+1] = pr;
	}
      }
    }
    
    for(auto i: v){
      cout << i.second << endl;
    }
  }
  return 0;
}
	 



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

int main(){
    int n,a=0,b=0;
    cin>>n;
    int x[n];
    for(int i=0;i<n;i++){
    cin>>x[i];
    a+=x[i];
    }
    if(a%n>n/2)
    a=a/n+1;
    else
    a=a/n;
    for(int i=0;i<n;i++){
        b+=(x[i]-a)*(x[i]-a);
    }
    cout<<b<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp(x,y) make_pair(y,x)
#define inf 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
const ll up=1e18;
ll n,a,b,c,d,ans;
unordered_map<ll,ll>vis;
ll mul(ll a,ll n)
{
    ll ans=0;
    while(n)
    {
        if(n&1) ans=min(inf,ans+a);
        a=min(inf,a+a);
        n>>=1;
    }
    return ans;
}
vector<pair<ll,ll>>v;
ll dfs(ll n)
{
    if(n==0) return 0;
    if(n==1) return d;
    if(vis[n]) return vis[n];
    ll ans=mul(d,n);
    for(pair<ll,ll>x:v)
    {
        ans=min(ans,dfs(n/x.fi)+x.se+n%x.fi*d);
        if(n%x.fi!=0) ans=min(ans,dfs(n/x.fi+1)+x.se+(x.fi-n%x.fi)*d);
    }
    return vis[n]=ans;
}
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
        v.clear();vis.clear();
        v.push_back({2,a});
        v.push_back({3,b});
        v.push_back({5,c});
        printf("%lld\n",dfs(n));
    }

}


Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

int main(){
  int N, M;cin>>N>>M;
  vll x,y,z;
  for (int i=0;i<N;++i){
    ll x_,y_,z_;cin>>x_>>y_>>z_;
    x.push_back(x_);y.push_back(y_);z.push_back(z_);
  }

  vi sign={-1,1};

  ll best_score=0;

  for (int j=0;j<2;++j){
    for (int k=0;k<2;++k){
      for (int l=0;l<2;++l){
        vll v;
        for (int i=0;i<N;++i){
          ll raw=sign[j]*x[i]+sign[k]*y[i]+sign[l]*z[i];
          v.push_back(raw);
        }
        sort(v.begin(), v.end(), greater<ll>());
        ll tmp=0;
        for (int i=0;i<M;++i){
          tmp+=v[i];
        }
        best_score=max(best_score, tmp);
      }
    }
  }

  cout << best_score << endl;
  return 0;
}

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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll c = a+b;
  ll ans = a * (n/c);
  ans += min(n%c, a);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }

        
  int main(){
     long double a,b,c;
      cin>>a>>b>>c;
      lint x=a+b+2*sqrtl(a*b);
      if(x<c)cout<<"Yes";
      else cout<<"No";
  }

  
     
  

Measured memory_bytes: 256
N = gets.to_i
0.upto(N.div(4) + 1) do |i|
    0.upto((N-i*4).div(7) + 1) do |j|
        sum = i*4 + j*7
        if sum <= N && sum > 0 && N % sum == 0
            puts 'Yes'
            exit
        end
    end
end
puts 'No'

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }


int main(){
    int N;
    cin >> N;
    vector<pair<long long, long long>> xy(N);
    REP(i, N) cin >> xy[i].first >> xy[i].second;
    vector<pair<long long, long long>> v;
    REP(i, N){
        long long x = xy[i].first;
        long long y = xy[i].second;
        v.push_back(make_pair(x, y));
        v.push_back(make_pair(-y, x));
        v.push_back(make_pair(-x, -y));
        v.push_back(make_pair(y, -x));
        v.push_back(make_pair(x-y, x+y));
        v.push_back(make_pair(-x-y, x-y));
        v.push_back(make_pair(-x+y, -x-y));
        v.push_back(make_pair(x+y, -x+y));
    }
    REP(i, N) REP(j, N){
        v.push_back(make_pair(v[i].first+v[j].first, v[i].second+v[j].second));
    }

    long long ans = 0;
    for(auto zz : v){
        long long a = zz.first;
        long long b = zz.second;
        long long x = 0, y = 0;
        for(auto z : xy){
            long long xx = z.first;
            long long yy = z.second;
            if(a*xx+b*yy > 0){
                x += xx;
                y += yy;
            }
        }
        ans = max(ans, x*x+y*y);
    }
    cout << fixed << setprecision(32) << sqrt(ans) << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
		StringBuffer S = new StringBuffer(sc.next());
		int v[]=new int[100];
		for(int i=0;i<S.length();i++) {
			v[S.charAt(i)]++;
		}
		boolean x=true;
		int s=v[83];
		int n=v[78];
		int e=v[69];
		int w=v[87];
		
		if(s>0&&n==0)x=false;
		if(n>0&&s==0)x=false;
		if(e>0&&w==0)x=false;
		if(w>0&&e==0)x=false;
		
		
		if(x)p("Yes");
		else p("No");
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 23892