akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

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

	int N,M;
	cin>>N;
	vector<int> a(N);
	for(int i = 0;i < N;i++) cin>>a[i];
	cin>>M;
	vector<int> b(M);
	for(int i = 0;i < M;i++) cin>>b[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	int j = 0;
	for(int i = 0;i < N && j < M;i++) {
		if(a[i] == b[j]) {
			j++;
		}
	}
	cout<<(j>=M?"YES":"NO")<<'\n';
	return 0;
}


Measured memory_bytes: 1792
//============================================================================
// Name        : beginner079.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : atcorder ABC077 in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

inline int main002();

int main() {

	main002();

	return 0;
}

inline int main002() {

	int num;
	int i;
	long long int lucas[87];

	lucas[0] = 2;
	lucas[1] = 1;

	cin >> num;

	for (i = 2; i <= num; i++)
		lucas[i] = lucas[i - 1] + lucas[i - 2];

	cout << lucas[num];

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define repp(i,a,b) for(int i=a;i<b;i++)
#define mm(a,n) memset(a, n, sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define il inline
#define int long long
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define pi 3.14159265358979323
#define SZ(x) ((ll)(x).size())
#define debug(x) 		cout<<#x<<": "<<x<<endl;
#define debug2(x,y)     cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x,y,z)   cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
using namespace std;
const int N = 3e5 + 10;
struct Edge{
	int nex , to;
}edge[N << 1];
int head[N] , TOT;
void add_edge(int u , int v)
{
	edge[++ TOT].nex = head[u] ;
	edge[TOT].to = v;
	head[u] = TOT;
}
const long double eps = 1e-6;
signed main()
{
	ios;
	int a ;
	long double b;
	cin >> a >> b;
	b += eps;
	int d = b * 100;
	cout << (ll)(a * d / 100) << '\n';
	return 0;
}








Measured memory_bytes: 3728
import numpy as np
a, b, x = map(int, input().split())

if x <= a * a * (b / 2):
    c = 2 * x / (a * b)
    print(np.rad2deg(np.arctan(b / c)))
else:
    c = 2 * (a**2 * b - x) / a**2
    print(np.rad2deg(np.arctan(c / a)))

Measured memory_bytes: 12396
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){

    int N; cin >> N;

    int num = (N+999)/1000;

    cout << num*1000-N << endl;

}

    

Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <cmath>
#include <queue>
#include <utility>
#include <cstring>
#define MAX_N 1002
using namespace std;
int N;
double x[MAX_N];
double y[MAX_N];
double r[MAX_N];

double distTable[MAX_N][MAX_N];
double d[MAX_N];

double calcDist(double x1, double x2, double y1, double y2, double r1, double r2) {
    return max(0.0, sqrt((x1 - x2) * (x1 - x2) +
                (y1 - y2) * (y1 - y2)) - r1 - r2);
}


int main() {
    for(int i=0;i<MAX_N;i++) {
        d[i] = 1e20;
    }
    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    cin >> N;
    for(int i=1; i < N + 1; i++) {
        cin >> x[i] >> y[i] >> r[i];
        // scanf("%llf %llf %llf", x+i, y+i, r+i);
    }
    x[0] = xs;
    y[0] = ys;
    r[0] = 0;
    x[N+1] = xt;
    y[N+1] = yt;
    r[N+1] = 0;
    for(int i=0; i<N+2; i++) {
        for(int j=i+1; j<N+2; j++) {
            distTable[i][j] = calcDist(x[i], x[j], y[i], y[j], r[i], r[j]);
            distTable[j][i] = calcDist(x[i], x[j], y[i], y[j], r[i], r[j]);
            // if(x[i] <= x[j] && y[i] <= y[j])
            //     distTable[i][j] = calcDist(x[i], x[j], y[i], y[j], r[i], r[j]);
            // if(x[j] <= x[i] && y[j] <= y[i])
            //     distTable[j][i] = calcDist(x[i], x[j], y[i], y[j], r[i], r[j]);
            // printf("distTable[%d][%d]: %f\n", i, j, distTable[i][j]);
        }
    }
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
    q.push(make_pair(0, 0));
    while(!q.empty()){
        auto t = q.top();
        q.pop();
        double value = t.first;
        int index = t.second;
        for(int i=0;i<N+2;i++) {
            if(value + distTable[index][i] < d[i]) {
                d[i] = value + distTable[index][i];
                q.push(make_pair(d[i], i));
            }
        }
    }
    printf("%.10f\n", d[N+1]);
}


Measured memory_bytes: 13680
#include<stdio.h>
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
char*S="RDLU",c;
int main()
{
	int e[5][5][4]={};
	int i,j,x,y,a;
	for(i=0;i<9;++i)
	{
		if(i&1)
			for(j=0;j<5;++j)
				scanf(" %c",&c),e[i/2][j][1]=e[i/2+1][j][3]=c-'0';
		else
			for(j=0;j<4;++j)
				scanf(" %c",&c),e[i/2][j][0]=e[i/2][j+1][2]=c-'0';
	}
	for(x=y=a=0;;)
	{
		if(e[y][x][(a+3)%4])
		{
			a=(a+3)%4;
			putchar(S[a]);
			x+=dx[a];
			y+=dy[a];
		}
		else if(e[y][x][a])
		{
			putchar(S[a]);
			x+=dx[a];
			y+=dy[a];
		}
		else if(e[y][x][(a+1)%4])
		{
			a=(a+1)%4;
			putchar(S[a]);
			x+=dx[a];
			y+=dy[a];
		}
		else a=(a+2)%4;
		if(x+y+a==0)break;
	}
	puts("");
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	string s, t;
	cin >> s >> t;
	//cout << s[6] << endl;
	ll ans = s.size();
	for(ll i = s.size() - t.size(); i >= 0;i--) {
		//cout << i << endl;
		bool flag = true;
		for (ll j = 0; j < t.size(); j++) {
			ll k = j + i;
			//cout << k << endl;
			
			if (s[k] == '?') continue;
			if (s[k] == t[j]) continue;
			flag = false;
			break;
		}
		if (flag) {
			ans = i;
			break;
		}
	}

	if (ans == s.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	string ans_s=s;

	REP(i,s.size()) {
		if (ans_s[i] == '?') ans_s[i] = 'a';
	}
	REP(i, t.size()) {
		ans_s[ans + i] = t[i];
	}

	cout << ans_s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


//////////////////////////////////////
#define MAX_N 300000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
int par[MAX_N],dep[MAX_N];//depはrankのこと
//n要素で初期化//忘れないように！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
void init(int n){
    for(int i=0;i<=n-1;i++){//頂点番号は0~n-1
        par[i]=i;
        dep[i]=0;
    }
}
//木の根を求める
int find(int x){
    return par[x]==x?x:par[x]=find(par[x]);
}
//xとyの属する集合を併合
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(dep[x]<dep[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(dep[x]==dep[y])dep[x]++;
    }
}
//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}

//////////////////////////////////////

struct po{
    i_i da;
    int num;
};

bool comp(po a,po b){
    if(a.da<b.da)return true;
    else return false;
}


int main(){
    int n,k,l;cin>>n>>k>>l;
    po data[n];
    init(n);
    while(k--){
        int a,b;cin>>a>>b;a--;b--;
        unite(a,b);
    }
    rep(i,0,n-1){
        data[i].da.first=find(i);
    }
    init(n);
    while(l--){
        int a,b;cin>>a>>b;a--;b--;
        unite(a,b);
    }
    rep(i,0,n-1){
        data[i].da.second=find(i);
    }
    rep(i,0,n-1)data[i].num=i;
    sort(data,data+n,comp);
    
    int ans[n];
    int pos=0;
    while(pos<=n-1){
        vector<int>v;
        v.push_back(data[pos].num);
        while(pos<=n-2&&data[pos].da==data[pos+1].da){
            pos++;
            v.push_back(data[pos].num);
        }
        int size=v.size();
        for(auto x:v){
            ans[x]=size;
        }
        pos++;
    }
    rep(i,0,n-1){
        cout<<ans[i]<<" ";
    }
    
    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
	ll a, b, c, k, t;
	
	scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
	
	k &= 1;
	
	if(k) t = b - a;
	else t = a - b;
	
	if(t >= 1e18 || t <= -1e18) printf("Unfair\n");
	else printf("%lld\n", t);
	
	return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    import copy
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = copy.deepcopy(a)
    b.sort(reverse=True)
    for v in a:
        if v == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 88544
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n;
    cin >> n;
    bool sg_n = n<0;
    n = abs(n);
    string ans = (n>0)?"":"0";
    bool sg_bit = 0;
    while (n) {
        if ((n&1) && (sg_bit != sg_n)) n += 2;
        ans.pb((n&1)?'1':'0');
        n /= 2;
        sg_bit ^= 1;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  int A,B;
  cin >> A >> B;
  int ans = 0;
  if (A > B) {
    ans += A;
    A--;
  } else {
    ans += B;
    B--;
  }
  if (A > B) {
    ans += A;
    A--;
  } else {
    ans += B;
    B--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> x(M);
    rep(i, M){
        cin >> x[i];
    }
	if(N >= M){
    	cout << 0 << endl;
    	return 0;
	}
    sort(x.begin(), x.end());
    vector<int> dif(M-1);
    for(int i = 0; i < M-1; i++){
        dif[i] = x[i+1] - x[i];
    }
    sort(dif.begin(), dif.end(), greater<int>());
    int ans = 0;
    for(int i = N-1; i < M-1; i++){
        ans += dif[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d(ll m,ll n){
	if(n%m==0)
		return m;
	return d(n%m,m);
}
int main(){
	ll m,n;
	cin>>m>>n;
	if(m>n){
		int t;
		t=m;
		m=n;
		n=t;
	}
	ll  b=d(m,n);
	//cout<<b<<endl<<m*n;
	long long s=m*n/b;
	cout<<s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// 解説AC
int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    rep (i, 0, n) cin >> a[i];
    bool dp[k + 1] = {}; // dp[i]：i個残りの時先手が勝てるか
    rep (i, 1, k + 1) {
        rep (j, 0, n) {
            if (i >= a[j]) dp[i] |= !dp[i - a[j]];
        }
    }
    cout << (dp[k] ? "First" : "Second") << "\n";
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 998244353;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll res = 1, maxi = 0;
    cin >> n;
    map<ll, ll> mp;
    rep (i, n) {
        ll d;
        cin >> d;
        if (i == 0 && d != 0) {
            cout << 0 << endl;
            return 0;
        }
        mp[d]++;
        maxi = max(maxi, d);
    }
    if (mp[0] > 1) {
        cout << 0 << endl;
        return 0;
    }
    FOR (i, 1, maxi + 1) {
        if (mp[i - 1] == 0) {
            cout << 0 << endl;
            return 0;
        }
        ll prev = mp[i - 1];
        ll t = mp[i];
        rep (j, t) {
            res *= prev;
            res %= MOD;
        }
    }
    res %= MOD;
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 6528
n = int(input())
a = []
for i in range(0,n):
    a.append(int(input()))
for i in range(0,n-1):
    for j in range(i+1,n):
        if a[i] == a[j]:
            a[j] = None
count = a.count(None)
print(n-count)

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

int n;
long double p[3000], ans, dp[3000][3000];
int main() {
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>p[i];
        
    dp[0][0]=1;
    //cout<<dp[0][-1]+dp[0][0];
    //for(int i=1;i<=n;++i)
    {
        //dp[i][0]=dp[i-1][0]*(1-p[i]);
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<=i;++j)
        {  
            dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
        }
   }
    for(int i=(n/2)+1;i<=n;++i)
        ans+=dp[n][i];
        cout<<setprecision(10)<<ans;
    return 0;
}

Measured memory_bytes: 139136
n = int(input())
flag = "ng"
for i in range(1,10):
  dum1,dum2 = divmod(n,i)
  if dum2 == 0 and dum1 < 10:
    flag = "ok"
    break
if flag == "ok":
  print("Yes")
else:
  print("No")

Measured memory_bytes: 2940
N, Q = map(int, input().split())
S = input()
l, r = [], []
t = [0] * (N+1)
for i in range(N):
    t[i + 1] = t[i] +(1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 9540
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = int.Parse(Console.ReadLine());
            int[] cuisine = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] satisfaction = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] bonus = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int result = 0;
            int beforeCuisine = -1;

            for(int i = 0;i < number;i++)
            {
                int currentCuisineIndex = cuisine[i] - 1;

                result += satisfaction[currentCuisineIndex];

                if (beforeCuisine + 1 == cuisine[i])
                {
                    result += bonus[beforeCuisine - 1];
                }

                beforeCuisine = cuisine[i];
            }

            Console.WriteLine(result.ToString());
        }
    }
}


Measured memory_bytes: 13396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    static void swap(int[] A, int i, int j) {
        int tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
    }

    static int partition(int[] A, int p, int r) {
        int x = A[r];
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (A[j] <= x) {
                i++;
                swap(A, i, j);
            }
        }
        swap(A, i + 1, r);
        return i + 1;
    }

    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(in.readLine());
            int[] A = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

            int q = partition(A, 0, n - 1);
            StringBuilder out = new StringBuilder();
            for (int i = 0; i < n; i++) {
                if (i != 0) out.append(" ");

                if (i == q) out.append("[").append(A[i]).append("]");
                else out.append(A[i]);
            }
            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 44624
def count(k, cycle):
    k += 1
    tans = (k // cycle) * (cycle // 2)
    res = k % cycle
    if res >= cycle // 2:
        tans += res % (cycle // 2)
    return tans

def solve(A, B):
    if A == B:
        return A
    Abin = "{:040b}".format(A)
    cycle = 2
    ans = ""
    for i, b in enumerate(Abin[::-1]):
        acount = count(A - 1, cycle)
        bcount = count(B, cycle)
        ans = str((bcount - acount) % 2) + ans
        cycle *= 2

    return int(ans, base=2)


if __name__ == "__main__":
    A, B = tuple(map(int, input().split(" ")))
    print(solve(A, B))


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int toInt(const vector<int>& a)
{
    int ret = 0;
    for(int i=0; i<4; ++i){
        ret *= 51;
        ret += a[i];
    }
    return ret;
}

vector<int> fromInt(int a)
{
    vector<int> ret(4);
    for(int i=0; i<4; ++i){
        ret[3-i] = a % 51;
        a /= 51;
    }
    return ret;
}

const int MOD = 1000000007;

int main()
{
    vector<int> n(4);
    for(int i=0; i<4; ++i)
        cin >> n[i];
    int nSum = accumulate(n.begin(), n.end(), 0);

    int m;
    cin >> m;
    vector<string> parts(m);
    map<string, int> index;
    for(int i=0; i<m; ++i){
        string name;
        cin >> name;
        name.resize(name.size()-1);
        getline(cin, parts[i]);
        index[name] = i;
    }

    vector<vector<bitset<4> > > terminal(m);
    for(int i=m-1; i>=0; --i){
        istringstream iss(parts[i]);
        for(;;){
            string s;
            if(!(iss >> s))
                break;

            if(s[0] == '['){
                bitset<4> bs;
                for(unsigned j=1; j<s.size()-1; ++j){
                    if(s[j] == 'A')
                        bs[0] = true;
                    else if(s[j] == 'T')
                        bs[1] = true;
                    else if(s[j] == 'G')
                        bs[2] = true;
                    else
                        bs[3] = true;
                }
                terminal[i].push_back(bs);
            }else{
                int j = index[s];
                for(unsigned k=0; k<terminal[j].size(); ++k)
                    terminal[i].push_back(terminal[j][k]);
            }
        }

        if(terminal[i].size() > 200){
            cout << 0 << endl;
            return 0;
        }
    }

    if(nSum != terminal[0].size()){
        cout << 0 << endl;
        return 0;
    }

    vector<int> dp(51*51*51*51, 0);
    dp[0] = 1;
    for(int i=0; i<51*51*51*51; ++i){
        vector<int> a = fromInt(i);
        int b = accumulate(a.begin(), a.end(), 0);
        if(b >= nSum)
            continue;

        for(int j=0; j<4; ++j){
            if(terminal[0][b][j] && a[j] < 50){
                ++ a[j];
                int c = toInt(a);
                dp[c] += dp[i];
                dp[c] %= MOD;
                -- a[j];
            }
        }
    }

    cout << dp[toInt(n)] << endl;

    return 0;
}

Measured memory_bytes: 27656
N = int(input())
color = ["w" for _ in range(N)]
d = [float("inf") for _ in range(N)]
p = [-1 for _ in range(N)]

# Make M
M = [list(map(int, input().split())) for _ in range(N)]

d[0] = 0
while True:
    mincost = float("inf")
    for i in range(N):
        if color[i] != "b" and d[i] < mincost:
            mincost = d[i]
            u = i
    
    if mincost == float("inf"):
        break
    color[u] = "b"

    for v in range(N):
        if color[v] != "b" and M[u][v] != -1:
            if d[v] > M[u][v]:
                d[v] = M[u][v]
                p[v] = u

s = 0 
for i in range(1, N):
    s += M[i][p[i]]
print(s)


Measured memory_bytes: 5724
#include<stdio.h>
int main(void){
	int n,a,b,c,i;
	long d=0;
	b=-1000000;
	c=1000000;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		scanf("%d",&i);
		if(b<i){
			b=i;
		}
		if(c>i){
			c=i;
		}
		d+=i;
	}
	printf("%d %d %ld\n",c,b,d);
			
return 0;

}

Measured memory_bytes: 600
import java.awt.geom.*;
import java.io.*;
import java.util.*;


public class Main {
	String cap = "12121414";
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int [] data = new int[8];
			for(int i = 0; i < 8; i++){
				data[i] = sc.nextInt();
			}
			
			int min = 1 << 24;
			StringBuilder ans = new StringBuilder();
			for(int i = 0; i < 8;i++){
				int count = 0;
				for(int j = 0; j < 8; j++){
					int v = data[j] - Math.min(data[j], cap.charAt((i+j) % 8) - '0');
					count += v;
				}
				if(count < min){
					min = count;
					ans = new StringBuilder();
					for(int j = 0; j < 8;j++){
						ans.append(cap.charAt((i+j) % 8));
					}
				}
				else if(count == min){
					StringBuilder sb = new StringBuilder();
					for(int j = 0; j < 8; j++){
						sb.append(cap.charAt((i+j) % 8));
					}
					if(ans.toString().compareTo(sb.toString()) > 0){
						ans = sb;
					}
				}
			}
			for(int i = 0; i < 7; i++){
				System.out.print(ans.charAt(i) + " ");
			}
			System.out.println(ans.charAt(7));
		}
	}

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

Measured memory_bytes: 12000
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d;
    cin>>n>>d;
    int x[10][10] = {0};
    REP(i,n)REP(j,d)cin>>x[i][j];
    int ans = 0;
    REP(i,n)for(int j = i+1; j < n; j++){
        LL d2 = 0;
        REP(k,d){
            d2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        LL z = 0;
        bool seisuu = false;
        while(z * z <= d2){
            if(z * z == d2){
                seisuu = true;
                break;
            }
            z++;
        }
        if(seisuu)ans++;
    }
    PUTS(ans);
}

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

using namespace std;

int main(void) {
    int N, L, i;
    string str_tmp, ans;
    vector<string> S;
    // get input --------------------------------
    cin >> N >> L;
    for(i = 0; i < N; i++) {
        cin >> str_tmp;
        S.push_back(str_tmp);
    }
    // sort -------------------------------------
    sort(S.begin(), S.end());
    // join -------------------------------------
    ans = "";
    for(i = 0 ; i < N; i++) {
        ans += S[i];
    }
    // disp answer ------------------------------
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pdiff = 0
ndiff = []
for i, j in zip(a, b):
    if i-j>0:
        pdiff += i-j
    elif i-j<0:
        ndiff.append(j-i)

while ndiff:
    tmp = ndiff.pop()
    pdiff -= tmp//2
if pdiff<=0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4596
import java.io.BufferedReader
import java.io.BufferedWriter

fun solve(c: Case) {
    val n = c.long().toInt()
    val aList = c.longList().map { ModInt(it) }
    val total = aList.drop(1).reduce { acc, modInt -> acc + modInt }
    val sum = ModInt(0)
    (0 until (n - 1)).forEach { i ->
        sum += aList[i] * total
        total -= aList[i + 1]
    }
    c.println(sum.toString())
}

class ModInt(var v: Long) {
    companion object {
        const val MOD = 1000000007L
    }

    override operator fun equals(other: Any?) = other != null && other is ModInt && v == other.v
    override fun hashCode() = v.hashCode()
    override fun toString() = v.toString()

    operator fun plus(o: ModInt): ModInt = ModInt(v).also { it += o }
    operator fun minus(o: ModInt): ModInt = ModInt(v).also { it -= o }
    operator fun times(o: ModInt): ModInt = ModInt(v).also { it *= o }
    operator fun div(o: ModInt): ModInt = ModInt(v).also { it /= o }

    operator fun plusAssign(o: ModInt) {
        v += o.v; if (v > MOD) v -= MOD
    }

    operator fun minusAssign(o: ModInt) {
        v -= o.v; if (v < 0) v += MOD
    }

    operator fun timesAssign(o: ModInt) {
        v = v * o.v % MOD
    }

    operator fun divAssign(o: ModInt) {
        v += o.v; if (v > MOD) v -= MOD
    }
}

class Case(
    private val input: BufferedReader = System.`in`.bufferedReader(),
    private val out: BufferedWriter = System.out.bufferedWriter()
) {
    fun exec(fn: (Case) -> Unit) =
        input.use { out.use { Thread(null, { fn(this) }, "solve", 64 * 1024 * 1024).also { it.start() }.join() } }

    fun println(c: CharSequence?) = out.appendln(c)
    fun string(): String = input.readLine().trimEnd()
    fun long(): Long = input.readLine().toLong()
    fun intList(): List<Int> = input.readLine().split(" ").map { it.toInt() }
    fun longList(): List<Long> = input.readLine().split(" ").map { it.toLong() }
}

fun main() = Case().exec(::solve)

Measured memory_bytes: 75068
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;

void WeLoveABC() {
	string s;
	cin >> s;
	int si = s.size();
	ll res = 0;
	dp[0][0] = 1;
	dp[1][0] = 1;
	for (int i = 0; i < si; i++)
	{
		int nex = (now + 1) % 2;
		for (int j = 0; j <= 3; j++)
		{
			if (s[i] == '?') dp[nex][j] = dp[now][j] * 3 % INF;
			else dp[nex][j] = dp[now][j];
		}
		
		if (s[i] == 'A' || s[i] == '?') dp[nex][1] += dp[now][0] % INF;
		if (s[i] == 'B' || s[i] == '?') dp[nex][2] += dp[now][1] % INF;
		if (s[i] == 'C' || s[i] == '?') dp[nex][3] += dp[now][2] % INF;

		now = (now + 1) % 2;
	}
	cout << (dp[now][3] % INF) << endl;
}

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



Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
using namespace std;

int main(){
    int n;
    while(1){
        scanf("%d",&n);
        if(n==0)break;
        int sum=0,max=0,min=1000,point;
        for(int i=1;i<=n;i++){
            scanf("%d",&point);
            if(point>max) max=point;
            if(point<min) min=point;
            sum+=point;
        }
        printf("%d\n",(sum-max-min)/(n-2));
    }
    return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double

using namespace std;

int main()
{
    fastio;

    string a, b;
    cin >> a;

    for(ll i=0;i<a.length();i++){
        if(a[i]=='0') b.push_back('0');
        else if(a[i]=='1') b.push_back('1');
        else if(a[i]=='B') if(b.size()!=0) b.pop_back();
    }

    cout << b;

    return 0;
}

Measured memory_bytes: 256
N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort()

dp = [0]*(T)
ans = 0
for i in range(N):
    a,b = AB[i]
    ans = max(ans,dp[-1]+b)
    for j in range(T-1,-1,-1):
        if j - a >= 0:
            dp[j] = max(dp[j],dp[j-a]+b)
print(ans)

Measured memory_bytes: 75256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

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

  int *a;
  a = (int *)malloc(sizeof(int) * n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int j = 0;
  int dis = k;
  for (int i = 0; i < n - 1; i++) {
    int mi = min(k - a[i + 1] + a[i], a[n - 1] - a[0]);
    dis = min(mi, dis);
  }

  cout << dis;
}


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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> veca(a);
    vector<int> vecb(b);
    int minia = INF;
    int minib = INF;
    rep(i, a) {
        cin >> veca.at(i);
        minia = min(minia, veca.at(i));
    }
    rep(i, b) {
        cin >> vecb.at(i);
        minib = min(minib, vecb.at(i));
    }
    int mini = minia + minib;
    int dismini = INF;
    vector<vector<int> > dis(m, vector<int> (3));
    rep(i, m) {
        rep(j, 3) {
            cin >> dis.at(i).at(j);
        }
        dismini = min(dismini, veca.at(dis.at(i).at(0) - 1) + vecb.at(dis.at(i).at(1) - 1) - dis.at(i).at(2));
    }
    cout << min(dismini, mini) << endl;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, m; cin>>n>>m;
    int ans = (n*(n-1))/2 + (m*(m-1))/2;
    cout<<ans;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define INF (1<<29)
using namespace std;
typedef pair<int,int>pii;
int n,m;
int fx;
vector<int>G[100010];
inline int read_int(){
	int t=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')t=-1,ch=getchar();
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*t;
}
//vector<int>ord;
deque<int>ord;
int tp;
void dfs(int from,int to,int h[],bool d){        //d==0?#--- :---#
	int t=-1;
	for(int i:G[to]){
		if(h[i]==0){
			t=i;
			break;
		}
	}
	if(t==-1){
		tp++;
		if(tp==2){
			printf("%d\n",ord.size());
			while(ord.size()>1){
				printf("%d ",ord.front());
				ord.pop_front();
			}
//			for(int i=0;i<ord.size()-1;i++)printf("%d ",ord[i]);
			printf("%d\n",ord.front());
			exit(0);
		}
		dfs(to,from,h,1^d);
	}else{
		tp=0;
		h[t]=1;
		if(d)ord.push_back(t);
		else ord.push_front(t);
		dfs(t,from,h,1^d);
	}
}
int h[100010];
int main(){
//	freopen("produce/Hamiltonish.txt","r",stdin);
//	freopen("result.log","w",stdout);
	n=read_int(),m=read_int();
	for(int i=1;i<=m;i++){
		int x=read_int(),y=read_int();
		G[x].pb(y),G[y].pb(x);
	}
	dfs(1,G[1][0],h,1);
	puts("-1");
	return 0;
}


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

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

#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz size()
#define endl "\n"
#define pb push_back
#define pp pop_back
#define mp make_pair
#define REP(I,n) for(int I = 0; I < n; I++)
#define REP_1(I,n) for(int I = 1; I <= n; I++)
#define w(t) int t; cin>>t; while(t--)

#define MOD 1000000007
#define INF 1e9 + 7

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef set<int> si;
typedef set<string> ss;

typedef long long ll;

template<class T>
istream &operator>>(istream &in,vector<T> &arr) {
	for(auto &x : arr)
		in >> x ;
	return in;
}

template<class T>
ostream &operator<<(ostream &out,vector<T> &arr) {
	for(auto &x : arr)
		out << x << ' ';
	return out;
}
void solve() {
	int k,a,b;
	cin>>k>>a>>b;
	for(int i = a; i <=b; i++) {
		if(i%k==0) {
			cout<<"OK";
			return;
		}
	}
	cout<<"NG";
}				
	
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	solve();		
}


Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int[][] xs = new int[n][];
		int[][] ys = new int[n][];
		for (int i = 0; i < n; i++) {
			xs[i] = new int[] { cin.nextInt(), i };
			ys[i] = new int[] { cin.nextInt(), i };
		}

		PriorityQueue<int[]> edges = new PriorityQueue<>(Comparator.comparingInt((edge) -> edge[0]));

		Arrays.sort(xs, Comparator.comparingInt((vi) -> vi[0]));
		for (int i = 1; i < n; i++)
			edges.add(new int[] { Math.abs(xs[i - 1][0] - xs[i][0]), xs[i - 1][1], xs[i][1] });
		xs = null;

		Arrays.sort(ys, Comparator.comparingInt((vi) -> vi[0]));
		for (int i = 1; i < n; i++)
			edges.add(new int[] { Math.abs(ys[i - 1][0] - ys[i][0]), ys[i - 1][1], ys[i][1] });
		ys = null;

		long ans = 0;

		rt = new int[n];
		Arrays.fill(rt, -1);

		while (!edges.isEmpty()) {
			int[] edge = edges.remove();
			if (!unite(edge[1], edge[2]))
				continue;
			ans += edge[0];
		}

		cout.println(ans);
	};

	private static int[] rt;

	private static int root(int operand) {
		if (rt[operand] < 0)
			return operand;
		return rt[operand] = root(rt[operand]);
	}

	private static boolean unite(int fr, int to) {
		int a = root(fr);
		int b = root(to);
		if (a == b)
			return false;
		if (rt[a] > rt[b]) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		rt[a] += rt[b];
		rt[b] = a;
		return true;
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


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

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

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

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

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

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

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


/*FUNCs=================================================*/
vec<vll> dp;

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

    int n,weight; cin >> n >> weight;
    vi w(n), v(n); rep(i,n) cin >> w[i] >> v[i];

    dp.resize(n+1, vll(weight+1, 0));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= weight; ++j) {
            if(j-w[i] >= 0) chmax(dp[i+1][j], dp[i][j-w[i]] + v[i]);
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[n][weight] << '\n';
}

Measured memory_bytes: 80256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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




int main(){
    int N; std::cin >> N;
    std::vector<int> A(N), pt0(N), pt1(N);
    for(int i(0); i < N; ++i){
        std::cin >> A[i];
        int a(2), sgn((i%2)*2-1);
        if(i == 0 || i == N-1) a = 1;
        pt0[i] = a * sgn;
        pt1[i] = -pt0[i];
    }
    std::sort(A.rbegin(), A.rend());
    std::sort(pt0.rbegin(), pt0.rend());
    std::sort(pt1.rbegin(), pt1.rend());
    long long sum0(0), sum1(0);
    for(int i(0); i < N; ++i){
        sum0 += A[i] * pt0[i];
        sum1 += A[i] * pt1[i];
    }
    std::cout << std::max(sum0, sum1) << std::endl;
    return 0;
}


Measured memory_bytes: 1408
//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int differ(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	return 1;
}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,n,m,r,R;
	for(;scanf("%d%d",&n,&m),n;printf("%d\n",R)){
		for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),node[i].second=i,a[i]--,b[i]--;
		sort(node,node+m);
		for(R=-1,i=0;i<m;i++){
			for(r=j=0;j<n;j++)parent[j]=j;
for(j=i;j<m;j++)if(unite(a[node[j].second],b[node[j].second]))r=node[j].first-node[i].first;
			for(j=1;j<n&&!differ(0,j);j++);
			if(j==n&&(R==-1||R>r))R=r;
		}
	}
}

Measured memory_bytes: 1152
N=int(input())
A=[list(map(int,input().split())) for _ in range(2)]

ans=0
for i in range(N):
  val=0
  for j in range(N):
    if j<i:
      val+=A[0][j]
    elif j==i:
      val+=A[0][j]
      val+=A[1][j]
    else:
      val+=A[1][j]
  ans=max(ans,val)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S;
    cin >> S;
    int cnt = 0;
    rep(i, S.size() - 1) {
        if(S.at(i) != S.at(i + 1)) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
import math
N, K = map(int, input().split())

M = []
x = 1
while x < (10 ** 5) * 2:
    M.append(1 / x)
    x <<= 1

p1 = max((N - K + 1) / N, 0)
p = 0
for i in range(1, min(N + 1, K)):
    t = int(math.log2(K / i)) + 1
    if K % i == 0 and  (K // i) & (K // i - 1) == 0:
        t -= 1
    p += M[t]
ans = p / N + p1
print('{0:.10f}'.format(ans))

Measured memory_bytes: 3064
import sys
 
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

import bisect

n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

def hand(x):
  cnt=0
  for i in range(n):
    p=x-A[i]
    cnt+=n-bisect.bisect_left(A,p)
  return cnt

def main():
  l=0
  h=10**15+3
  mid=(l+h)//2
  
  while l+1<h:
    mid=(l+h)//2
    if hand(mid)<m:
      h=mid
    else:
      l=mid
  
  B=A[::-1]
  
  for i in range(n-1):
    B[i+1]+=B[i]
  
  B=B[::-1]
  
  ans=0
  cnt=0
  
  
  for i in range(n):
    y=l-A[i]+1
    index=bisect.bisect_left(A,y)
    if n==index:
      continue
    else:
      ans+=(n-index)*A[i]+B[index]
      cnt+=(n-index)
  
  ans+=(m-cnt)*l
  print(ans)

if __name__ == "__main__":
	main()
  

  
  

Measured memory_bytes: 53232
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009
using P = pair<int,int>;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " "<< a <<" "<< b;
}

Measured memory_bytes: 256