akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;
typedef long double ld;
typedef vector<ld> vd;

const ld EPS = 10e-10;

ld solve();
bool search(const ld t, const ld r, vd& s);

int main(void) {
	
	while(true){
		ld ans = solve();
		if( ans < 0.0 ) { break; }
		cout << fixed << setprecision(5) << ans << endl;
	}

	return 0;
}


bool search( const ld t, const ld r, vd& s ) {

	for( int i = -20; i < 20; i++ ) {

		ld d[2]={(ld)i,(ld)i+1.0};

		for(int j = 0; j < 2; j++)
			if(d[j]>=-r+EPS&&d[j]+EPS<=r)
				if(sqrt(r*r-d[j]*d[j])+t>r+s[i+20]+EPS) 
					return false;
	
	}

	return true;
}

ld solve() {

	ld r, low=0.0, high=21.0, mid;
	int n, m;
	vd v(40,0.0);
	
	cin >> m >> n;
	r = (ld)m;
	
	if( m == 0 && n == 0 ) { return -1.0; }

	for( int i = 0; i < n; i++ ) {

		int xl, xr;
		ld h;
		cin >> xl >> xr >> h;

		for( int j = xl+20; j < xr+20; j++ )
			if( v[j] < h ) 
				v[j] = h;
	}
	
	for( int i = 0; i < 1000; i++ ) {
		mid = (high+low)/2.0;
		if( search(mid,r,v) )
			low = mid;
		else 
			high = mid;
	}

	return mid;
}

Measured memory_bytes: 3152
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cctype>
using namespace std;
 
#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

int W,N;
const int MAX_N = 1001;
const int MAX_W = 1001;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_N][MAX_W];

void solve() {
	memset(dp, 0, sizeof(dp));
	repa(i,1,N) {
		repa(j,0,W) {
			if(j - w[i] >= 0) {
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}

	int maxval = -1;
	int weight = 0;
	repa(i,0,W) {
		if(maxval < dp[N][i]) {
			maxval = dp[N][i];
			weight = i;
		}
	}
	cout <<	maxval << endl;
	cout << weight << endl;
}

int main() {
	int c = 0;
	while(cin>>W, W) {
		cin >> N;
		repa(i,1,N) {
			scanf("%d,%d", &v[i], &w[i]);
		}

		printf("Case %d:\n", ++c);
		solve();
	}
}

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

int N;
char S[305][305];

bool check(int k){
    bool res = true;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i-k<0) 
            if((i-k+N)%N == j) continue;
            if(S[i][j] != S[(j+k)%N][(i-k+N)%N]) res = false;
        }
    }

    return res;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++) cin >> S[i][j];

    int ans = 0;
    for(int i=0;i<N;i++)
        if(check(i)) ans++;

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


Measured memory_bytes: 384
import sys

n, m = map(int, sys.stdin.readline().split())
graph = [[] for _ in range(n+1)]
for l, r, d in zip(*[map(int, sys.stdin.read().split())] * 3):
    graph[l].append((r, d))
    graph[r].append((l, -d))

root = list(range(n+1))
height = [0] * (n + 1)

def find_root(v):
    u = root[v]
    if u == v:
        return u
    w = find_root(u)
    root[v] = w
    return w

def merge(v, u):
    rv = find_root(v)
    ru = find_root(u)
    if rv != ru:
        if height[v] >= height[u]:
            root[ru] = rv
            height[v] = max(height[v], height[v] + 1)
        else:
            root[rv] = ru

def main():
    for v in range(1, n+1):
        for u, d in graph[v]:
            merge(v, u)

    for v in range(1, n+1):
        find_root(v)
        
    dist = [None] * (n + 1)
    for v in set(root[1:]):
        dist[v] = 0
        stack = [v]
        while stack:
            x = stack.pop()
            for y, d in graph[x]:
                if dist[y] is None:
                    dist[y] = dist[x] + d
                    stack.append(y)
                elif dist[y] != dist[x] + d:
                    return 'No'
    return 'Yes'
      
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 99192
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S;
int num[3010];


signed main(){
	cin>>S;
	int N=S.size();
	int e=1;
	int sum=0;
	num[0]++;
	for(int i=N-1;0<=i;i--){
		int r=S[i]-'0';
		r*=e;
		r%=2019;
		sum+=r;
		sum%=2019;
		DEB(sum)END
		num[sum]++;
		e*=10;
		e%=2019;
		DEB(r)DEB(e)END
	}
	int ans=0;
	for(int i=0;i<2019;i++){
		ans+=num[i]*(num[i]-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define amen exit(0)

#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef long double ld;

const ll D = 100007;
const ll Inf = 1000000007;


int main() 
{
    string s;
    cin >> s;
    ll res = 0;
    for (ll i = 0; i < s.size(); i++)
        res += (s[i] == '+'),  res -= (s[i] == '-');
    cout << res << endl;
    amen;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    INF = 10 ** 18

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

    G = [[] for _ in range(N + 1)]
    for _ in range(M):
        L, R, C = map(int, input().split())
        G[L].append([C, R])
        G[R].append([C, L])

    for i in range(1, N):
        G[i + 1].append([0, i])

    d = [INF] * (N + 1)

    def dijkstra(s):
        from heapq import heappop, heappush
        d[s] = 0
        pque = []
        heappush(pque, [0, s])
        
        while pque:
            p = heappop(pque)
            v = p[1]
            if d[v] < p[0]:
                continue
            for i in range(len(G[v])):
                e = G[v][i]
                if d[e[1]] > d[v] + e[0]:
                    d[e[1]] = d[v] + e[0]
                    heappush(pque, [d[e[1]], e[1]])

    dijkstra(1)

    print (-1 if d[-1] == INF else d[-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 65104
#include <iostream>
#include <cmath>
using namespace std;
#define REP(i,n)    for(int i = 0; i < (int)n; i++)

int main(){
    int ans = 0;
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    REP(i,n)
        cin >> a[i];
    REP(i,n){
        cin >> b[i];
        ans += b[i];
    }
    REP(i,n - 1)
        cin >> c[i];
    REP(i,n - 1){
        if(a[i] + 1 == a[i + 1])
            ans += c[a[i] - 1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define INF 1e+9
#define EPS 1e-9
using namespace std;

int main(){
	int n,b[100];
	double x[100],y[100];
	double cost[100][100];
	int next[100][100];
	while(cin >> n,n){
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++) {
				cost[i][j] = INF;
				next[i][j] = j;
			}
			cost[i][i] = 0;
		}
		for(int i = 0;i < n;i++) cin >> b[i] >> x[i] >> y[i];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				double d = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
				if(i != j && d <= 2500.0){
					cost[i][j] = sqrt(d);
					cost[j][i] = sqrt(d);
				}
			}
		}
		for(int k = 0;k < n;k++){
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					if(cost[i][j] > cost[i][k] + cost[k][j]){
						cost[i][j] = cost[i][k] + cost[k][j];
						next[i][j] = next[i][k];
					}
				}
			}
		}
		int m;
		cin >> m;
		for(int i = 0;i < m;i++){
			int s,g,S,G;
			cin >> s >> g;
			for(int j = 0;j < n;j++){
				if(b[j] == s) S = j;
				if(b[j] == g) G = j;
			}
			if(cost[S][G] == INF){
				cout << "NA" << endl;
				continue;
			}
			while(S != G){
				cout << b[S] << " ";
				S = next[S][G];
			}
			cout << b[G] << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using ll = long long;

int main() {
    using namespace std;
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i];
    for (int i = 0; i < c; i++) cin >> r[i];

    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    sort(r.rbegin(), r.rend());

    int xi = 1, yi = 1;
    for (int i = 0; i < c; i++) {
        if (x < xi && y < yi) break;
        if (x < xi) {
            if (q[y - yi] < r[i]) {
                q[y - yi] = r[i];
                yi++;
            } else {
                break;
            }
            continue;
        }
        if (y < yi) {
            if (p[x - xi] < r[i]) {
                p[x - xi] = r[i];
                xi++;
            } else {
                break;
            }
            continue;
        }

        if (p[x - xi] < q[y - yi]) {
            if (p[x - xi] < r[i]) {
                p[x - xi] = r[i];
                xi++;
            } else {
                break;
            }
        } else {
            if (q[y - yi] < r[i]) {
                q[y - yi] = r[i];
                yi++;
            } else {
                break;
            }
        }
    }

    ll ans = 0LL;
    for (int i = 0; i < x; i++) ans += (long long)p[i];
    for (int i = 0; i < y; i++) ans += (long long)q[i];

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

Measured memory_bytes: 1408
# https://atcoder.jp/contests/abc140/tasks/abc140_c
n = int(input())
bx = [float("inf")] + list(map(float, input().split())) + [float("inf")]
out = 0
for i in range(n):
    out += int(min(bx[i], bx[i+1]))
print(out)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
     int N;
     cin >> N;
     vector<int> B(N-1);
     cin >> B;
     int ret = 0;
     REP(i,N) {
         if(i == 0) {
             ret += B[0];
         }else if(i == N-1){
             ret += B[N-2];//size is N-1;
         }else
         {
             ret += min(B[i-1],B[i]);
         }
     }
     cout<<ret<<endl;
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

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

	int Y = 1;

	for (int i = 2; i <= X; i++) {

		int k = 2;
		while(pow(i,k)<=X) {
			int R = pow(i,k);

				if (Y < R) {
					Y = R;
				}
				k++;

		}
	}



	cout << Y << endl;

	return 0;
}


Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N;
    cin >> N;
    bool ok = false;
    for (int i = 0; i <= N/4; i++){
        for (int k = 0; k <= N/7; k++){
            if (4*i + 7*k == N){
                ok = true;
            }
        }
    }
    if (ok){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;

bool sortbysec(const pair<lli,lli> &a,
              const pair<lli,lli> &b)
{
    return (a.second < b.second);
}

lli modulo(string num, lli a)
{
    lli res = 0;
    for (lli i = 0; i < num.length(); i++)
         res = (res*10 + (int)num[i] - '0') %a;

    return res;
}

lli SieveOfEratosthenes(lli n,vector<lli> &v)
{
    lli ans=0,p1,p2,p3;
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (lli p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (lli i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (lli p=2; p<=n; p++)
    {
       if (prime[p])
          v.pb(p);
    }
}

int main()
{
//cout.precision(9);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
        lli n,z,i,j,k,l,a,b;
        cin>>n>>a>>b;
        vector<lli> v;
        vector<lli>::iterator itr;
        cout<<min(n*a,b)<<endl;
    }
}
/*
5 4
1 2 3 4 5
1 2 10 5
*/


Measured memory_bytes: 256
# Generated by AtcoderGreedy on 2018-04-21
# ARC096 C
# Your code here

A, B, C, X, Y = gets.chomp.split(' ').map(&:to_i)

if A + B <= C * 2
  puts(A * X + B * Y)
  exit 0
end

needed_and_price = [[X, A], [Y, B]].sort

ret = 0
ret += needed_and_price[0][0] * C * 2


the_price = needed_and_price[1][1]
the_amount = needed_and_price[1][0] - needed_and_price[0][0]

ret += [C*2, the_price].min * the_amount

puts ret


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll A,B;
  cin >> A >> B;
  ll gcd(ll a, ll b);
  ll lcm = A*B/gcd(A,B);
  cout << lcm;
}

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

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NT = Sarray();
            var N = NT[0];
            var T = NT[1];
            var Ai = Sarray();
            var min = Ai[0];
            var def = new List<long>();
            for (var i = 0; i < N; ++i)
            {
                min = Min(min, Ai[i]);
                def.Add(Ai[i] - min);
            }
            var max = def.Max();
            var ans = def.Count(d => d == max);
            if (max == 0) ans = 0;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 24800
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),M=in();
	vector<int> K(M);
	vector<vector<int>> S(M);
	vector<int> P(M);
	REP(i,M){
		K[i]=in();
		S[i].resize(K[i]);
		REP(j,K[i]) S[i][j]=in();
	}
	REP(i,M) P[i]=in();

	vector<int> E(1<<N,0);
	REP(i,E.size()){
		int c=0;
		REP(j,M){
			int b=0;
			REP(k,K[j]){
				b += i&(1<<(S[j][k]-1))?1:0;
			}
			if(b%2==P[j]) c++;
		}
		if(c==M) E[i]=1;
	}
	cout << count(ALL(E),1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> c(h, vector<char>(w));
    int count = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            char a;
            cin >> a;
            c[i][j] = a;
            if(a == '.') count++;
        }
    }

    int INF = 100000000;
    vector<vector<int>> d(h, vector<int>(w));
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            d[i][j] = INF;
        }
    }

    using P = pair<int, int>;
    queue<P> que;
    que.push(P(0, 0));
    d[0][0] = 1;
    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, -1, 0, 1};
    while(!que.empty())
    {
        P p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        if(x == h-1 && y == w-1) break;
        for(int i = 0; i <= 3; i++)
        { 
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx >= 0 && nx <= h-1 && ny >= 0 && ny <= w-1 && d[nx][ny] == INF && c[nx][ny] == '.')
            {
                que.push(P(nx, ny));
                d[nx][ny] = d[x][y] + 1;
            }
        }
    }
    if(d[h-1][w-1] == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << count - d[h-1][w-1] << endl;
    }
}



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

vector<int> vec;
string S;

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

    int N;
    cin >> N >> S;
    int count = 0;
    char prev = '#';
    int i = 0;
    for (; i < N; ++i) {
        if (S[i] == '#') {
            count++;
            prev = S[i];
            break;
        }
    }
    i++;

    for (; i < N; ++i) {
        if (prev == S[i]) {
            count++;
        } else {
            vec.push_back(count);
            prev = S[i];
            count = 1;
        }
        if (i == N - 1) {
            vec.push_back(count);
        }
    }
    int black = 0;
    int white = 0;
    for (int i = 0; i < vec.size(); i += 2) {
        if (i < vec.size() - 1) {
            // black += vec[i];
            white += vec[i + 1];
            // res += min(vec[i], vec[i + 1]);
        }
    }

    int res;
    if (vec.size() >= 2) {
        res = white;
    } else {
        res = 0;
    }
    for (int i = 0; i < vec.size(); i += 2) {
        if (i < vec.size() - 1) {
            black += vec[i];
            white -= vec[i + 1];
            res = min(black + white, res);
        }
    }

    cout << res << '\n';

    return 0;
}


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

int main(void){
    int h,w;

    while(1){    
        cin >> h >> w;
        if((h == 0) && (w == 0)) break;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3080
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int dp[401];
int path[401][401];

void dfs(int pos,int cost,int node_num){
  for(int to=0;to<=node_num;to++){
    if(path[pos][to] == 0) continue;
    if(dp[to] >= cost + path[pos][to]) continue;

    dp[to] = cost + path[pos][to];

    dfs(to,cost+path[pos][to],node_num);
  }
}

int main(){
  int node_num,work_num;
  while(~scanf("%d %d",&node_num,&work_num)){
    memset(dp,0,sizeof(dp));
    memset(path,0,sizeof(path));

    for(int i=0;i<work_num;i++){
      int from,to,cost;
      scanf("%d %d %d",&from,&to,&cost);
      path[from][to] = max(path[from][to],cost);
    }

    dfs(0,0,node_num);
    printf("%d\n",dp[node_num-1]);
  }
}

Measured memory_bytes: 1824
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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




int main(){
  char b;
  cin >> b;
  if(b == 'A') cout << 'T' << endl;
  if(b == 'T') cout << 'A' << endl;
  if(b == 'G') cout << 'C' << endl;
  if(b == 'C') cout << 'G' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int H,W;
    cin>>H>>W;

    string S[H][W];

    rep(i,H){
        rep(j,W){
            cin>>S[i][j];
            if(S[i][j]=="snuke"){
                char ans='A'+j;
                cout << ans << i+1 << endl;
            }
        }
    }

    



}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        char[] s = sc.next().toCharArray();
        int w = sc.nextInt();

        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < s.length; i += w) {
            pw.print(s[i]);
        }

        pw.flush();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

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

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

Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int a, p;
	cin >> a >> p;
	cout << ((a * 3 + p) / 2) << endl;
	return 0;
}
 

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static char[] moji = "atcoder@".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {
        //var N = long.Parse(Console.ReadLine());
        var WHN = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var RightX = WHN[0];
        var UpY    = WHN[1];
        long DownY  = 0;
        long LeftX  = 0;

        for (int i = 0; i < WHN[2]; i++)
        {
            var xya = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var x = xya[0];
            var y = xya[1];
            var a = xya[2];
            
            if(a == 1)
            {
                LeftX = Math.Max(LeftX, x);
            }else if (a == 2)
            {
                RightX = Math.Min(RightX, x);
            }
            else if (a == 3)
            {
                DownY = Math.Max(DownY, y);
            }
            else
            {
                 UpY = Math.Min(UpY, y);
            }
        }

        if(UpY < DownY || RightX < LeftX)
        {
            Console.WriteLine(0);
        }
        else
        {
            Console.WriteLine(Math.Abs(UpY - DownY) * Math.Abs(RightX - LeftX));
        }
        

    }
        

    
}


Measured memory_bytes: 28060
/*
    @uthor: Amit Kumar
    user: CodeChef: dr_virus_ ; Codeforces,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll long long
#define ld double
#define pp pair<ll,ll>
#define endl "\n"
#define nfrep(a) for(size_t i=0;i<a;i++)
#define fnrep(a,b) for(size_t i=a;i<=b;i++)
#define nbrep(a) for(size_t i=a;i>=0;i--)
#define bnrep(a,b) for(size_t i=a;i>=b;i--)
 
const ll mod = 1e9+7;
const ll inf = 1e18;
 
 
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
 /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif */
 
    ll t;
    cin>>t;
    cout<<fixed<<setprecision(2)<<2*3.14*t;
    //cerr<<"Time Elapsed: "<<clock()/(double)CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define s(v) ((int)v.size())
using namespace std;

int n, k, c;
string s;
vector<int> v, fp;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k >> c >> s;
	s = " " + s;
	for(int i = 1; i <= n; ++i) {
		if(s[i] == 'x') continue;
		if(v.size() == 0) v.push_back(i);
		else if(i - v[s(v) - 1] > c) v.push_back(i);
	}
	int wi = n + c + 1, p = 0;
	for(int i = n; i >= 1; --i) {
		if(s[i] == 'x') continue;
		if(v[s(v) - 1] == i) v.pop_back();
		if(p < k && (s(v) <= k - p - 1 || wi - v[k - p - 1] <= c)) fp.push_back(i);
		if(wi - i > c) wi = i, ++p;
	}
	reverse(fp.begin(), fp.end());
	for(int i : fp) cout << i << "\n";
	return 0;
}


Measured memory_bytes: 3404
s=gets.chop.bytes.map{|e| e-97}
k=gets.to_i
s.size.times{|i|
    x=26-s[i]
    (s[i]=0; k-=x) if s[i]>0 and k>=x
}
s[-1]=(s[-1]+k%26)%26
puts s.map{|e| (e+97).chr}*''


Measured memory_bytes: 7788
#include <iostream>
using namespace std;
int main (){
    int a,b,x;
    cin>>a;
    cin>>b;
    cin>>x;
    if (a>x){
        cout<<"NO";}
    else if (a==x){
        cout<<"YES";}
    else if ((a+b)>=x){
        cout<<"YES";}
    else{
        cout<<"NO";}
    return 0;
}

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

int main(){
  int N; cin >> N;
  int p[1000]={};
  int div=2;
  long long result=1;
  for(int j=1; j<=N; j++){
    div=2;
    int k=j;
    while(k>1){
      if(k%div==0){
        k/=div;
        p[div]++;
      }else{
        div++;
      }
    }
  }
  for(int i=0; i<1000; i++){
    result*=(p[i]+1);
    result%=(1000000007);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
const int INF = 1e9;
const int MAXN = 100005;
vector<int> adjList[MAXN];
int level[2][MAXN];

void dfs(int u, int par, int lvl, bool f) {
    level[f][u] = lvl;
    for (int v : adjList[u]) {
        if (v == par)
            continue;
        dfs(v, u, lvl + 1, f);
    }
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n, a, b;
    cin >> n >> a  >> b;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }

    if (a == b) {
        cout << 0 << '\n';
        return 0;
    }

    dfs(a, -1, 0, 0);
    dfs(b, -1, 0, 1);

    int ans = 0;
    for (int v = 1; v <= n; ++v) {
        if (level[0][v] < level[1][v])
            ans = max(ans, level[1][v] - 1);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 11648
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

using Graph = vector<vector<int>>;

vector<bool> seen;
void dfs(const Graph &G, int v) {
	seen[v] = true;
	for (auto next_v : G[v]) {
		if (seen[next_v]) continue;
		dfs(G, next_v); // 再帰的に探索
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// 頂点数と辺数
	int N, M; cin >> N >> M;

	// グラフ入力受取
	Graph G(N);
	for (int i = 0; i < M; ++i) {
		int a, b; int c;
		cin >> a >> b; cin >> c;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	// 全頂点が訪問済みになるまで探索
	int count = 0;
	seen.assign(N, false);
	for (int v = 0; v < N; ++v) {
		if (seen[v]) continue; // v が探索済みだったらスルー
		dfs(G, v); // v が未探索なら v を始点とした DFS を行う
		++count;
	}
	cout << count << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  int ans = 0;
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      ans += d.at(i)*d.at(j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e18;

int main()
{
   int n;
   scanf("%d",&n);
   int cnt=0;
   while(n)
   {
       if(n%10==2)cnt++;
       n/=10;
   }
   printf("%d\n",cnt);
   return 0;
}
/*
1²＋2²＋3²＋……＋n²＝1/6·n(n＋1)(2n＋1)
证明如下：
不妨设1²＋2²＋3²＋……＋n²＝S
利用恒等式(n＋1)³＝n³＋3n²＋3n＋1，得：
(n＋1)³－n³＝3n²＋3n＋1
n³－(n－1)³＝3(n－1)²＋3(n－1)＋1
………………………………
3³－2³＝3·2²＋3·2＋1
2³－1³＝3·1²＋3·1＋1
将这n个式子两端分别相加，得：
(n＋1)³－1＝3(1²＋2²＋3²＋……＋n²)＋3(1＋2＋3＋……＋n)＋n
由于1＋2＋3＋4＋……＋n＝n(n＋1)/2
代入上式，得：
n³＋3n²＋3n＝3S＋3/2×n(n＋1)＋n
整理后得S＝1/6·n(n＋1)(2n＋1)
即1²＋2²＋3²＋……＋n²＝1/6·n(n＋1)(2n＋1)
*/


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int W,H,x,y,r;
  
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if (x - r >= 0 && W >= x + r && y - r >= 0 && H >= y + r)
    printf("Yes\n");
  else if (x - r < 0 || x + r > W || y - r < 0 || y + r > H)
    printf("No\n");
  return 0;
}

Measured memory_bytes: 584
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>
#include <functional>
#include <cctype>
#include <sstream>

typedef long long lint;

using namespace std;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);++i)
#define all(x) (x).begin(),(x).end()
#define sl(c) (('a')<=(c)&&(c)<=('z'))
#define ll(c) (('A')<=(c)&&(c)<=('Z'))
#define PI 3.141592653589793
#define acout (cout<<fixed<<setprecision(15))
#define makeupper(t) (transform(all(t),t.begin(),::toupper))
#define makelower(t) (transform(all(t),t.begin(),::tolower))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
lint* arr1(lint x) {
	lint *array = new lint[x];
	rep(i, x)array[i] = 0;
	return array;
}
lint** arr2(lint x, lint y) {
	lint **array = new lint*[x];
	rep(i, x)array[i] = new lint[y];
	rep(i, x)rep(j, y)array[i][j] = 0;
	return array;
}
vector<string> split(const string &s, char delim) {
	vector<string> elems;
	stringstream ss(s);
	string item;
	while (getline(ss, item, delim)) {
		if (!item.empty()) {
			elems.push_back(item);
		}
	}
	return elems;
}

int main() {
	double a, b, c;
	cin >> a >> b >> c;
	acout << 0.5*a * b * sin(PI*c/180) << "\n" << a + b + pow(pow(a, 2) + pow(b, 2) - 2 * a*b*cos(PI*c/180), 0.5) << "\n" << b*sin(PI*c/180) << "\n";
}


Measured memory_bytes: 3544
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
using namespace std;
 

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

 
const int MAXN = 2e5 + 5;
const ll MOD = 998244353;
const ll INF = INT64_MAX;


random_device rd;
mt19937 rnd(rd());


signed main() {
	FAST_IO;
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			ans += j;
		}
	}
	cout << ans << "\n";
 	return 0;
}

Measured memory_bytes: 3620
from collections import defaultdict
def find(x, A): #unionfind
    p = A[x]
    if p == x:
        return x
    a = find(p, A)
    A[x] = a
    return a

N, K, L = map( int, input().split())
V = [ i for i in range(N)]
W = [ i for i in range(N)]
for _ in range(K):
    p, q = map( int, input().split())
    p, q = p-1, q-1
    bp, bq = find(p,V), find(q,V)
    V[q] = bp
    V[bq] = bp

for _ in range(L):
    r, s = map( int, input().split())
    r, s = r-1, s-1
    br, bs = find(r,W), find(s,W)
    W[s] = br
    W[bs] = br

d = defaultdict(int) #デフォルトで0を返す。
for i in range(N):
    d[(find(i,V), find(i, W))] += 1
ANS = [0]*N
for i in range(N):
    ANS[i] = d[(find(i,V), find(i, W))]

print(' '.join( map( str, ANS)))

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

int main() {
  int N, H;
  cin >> N >> H;
  int a[N], b[N];
  int maxa = 0;
  priority_queue<int> qb;
  
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    maxa = max(maxa, a[i]);
    qb.push(b[i]);
  }
  
  int h = H;
  int ans = 0;
  while (h > 0 && qb.top() > maxa && !qb.empty()) {
    int q = qb.top();
    h = h - q;
    qb.pop();
    ans++;
  }
  
  if (h > 0) {
    ans = ans + (h + maxa - 1)/maxa;
  }
  
  cout << ans << endl;
}
    

Measured memory_bytes: 1528
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, A, B, C, D;
    scan(N, A, B, C, D);
    A--, B--, C--, D--;
    auto S = sread();
    auto safe = new bool[](N);
    foreach (i; 0 .. N)
        safe[i] = (S[i] == '.');
    bool reachableA = true, reachableB = true, skippable;
    foreach (i; 0 .. N)
    {
        if (A < i && i <= C && S[i] == '#' && S[i - 1] == '#')
            reachableA = false;
        if (B < i && i <= D && S[i] == '#' && S[i - 1] == '#')
            reachableB = false;
        if (B <= i && i <= D && i + 1 < N && S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.')
            skippable = true;
    }
    if (!reachableA || !reachableB)
    {
        writeln("No");
        return;
    }
    if (C < D)
    {
        writeln("Yes");
        return;
    }
    writeln(skippable ? "Yes" : "No");
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	cout << min(A * N, B) << endl;

	return 0;
}


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

namespace Station_and_Bus
{
    class Program
    {
        static void Main(string[] args)
        {
            string stations = Console.ReadLine();
            bool znak = false;
            for (int i = 1; i < stations.Length; i++)
            {
                if (stations[i] != stations[i-1])
                {
                    znak = true;
                }
            }
            if (znak)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.ReadKey(true);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> ans;
    multiset<int> a;
    rep(i,n) {
        int x;
        cin >> x;
        a.insert(x);
    }
    int min_num = *a.begin();
    a.erase(a.begin());
    auto k = a.end();k--;
    int max_num = *k;
    a.erase(k);
    for(auto i = a.begin(); i != a.end(); i++){
        int num = (*i);
        if(num <= 0) {
            ans.push_back(make_pair(max_num, num));
            max_num -= num;
        } else {
            ans.push_back(make_pair(min_num, num));
            min_num -= num;
        }
    }
    ans.push_back(make_pair(max_num, min_num));
    cout << max_num - min_num << endl;
    for (auto i: ans) {
        cout << i.first <<" " << i.second << endl;
    }
}


Measured memory_bytes: 7544
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int x1[105],yi[105];
int main(){
	std::ios::sync_with_stdio(false);
	int n,m,x,y,i,j;
	cin>>n>>m>>x>>y;
	rep(i,n){
		cin>>x1[i];
	}
	rep(i,m){
		cin>>yi[i];
	}
	f(i,x+1,y+1){
		rep(j,n){
			if(i<=x1[j]){
				break;
			}
		}
		if(j!=n){
			continue;
		}
		rep(j,m){
			if(i>yi[j]){
				break;
			}
		}
		if(j!=m){
			continue;
		}
		cout<<"No War"<<endl;
		return 0;
	}
	cout<<"War"<<endl;
} 
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;


int main() {
  ll N,K; cin >> N >> K;

  ll count = 0;
  for (ll i = K+1; i <= N; i++) {
    ll n = N / i;
    count += (i - K) * n;
    count += max(ll(0),N - n * i - K + 1);
    if (K == 0) count--;
  }


  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int n,m,l;cin>>n>>m>>l;
    ll a[n][m],b[m][l],c[n][l];
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>a[i][j];
    for(int i=0;i<m;i++) for(int j=0;j<l;j++) cin>>b[i][j];
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            ll sum=0;
            for(int k=0;k<m;k++) sum+=a[i][k]*b[k][j];
            c[i][j]=sum;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j==0) cout<<c[i][j];
            else cout<<" "<<c[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3340
import itertools
import math
n = int(input())
XY = [tuple(map(int,input().split())) for i in range(n)]
ans = 0
for XYs in itertools.permutations(XY):
  for i in range(n-1):
    ans += math.sqrt((XYs[i][0] - XYs[i+1][0])**2 + 
              (XYs[i][1] - XYs[i+1][1])**2) 
ans /= math.factorial(n)
print(ans)

Measured memory_bytes: 9080
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#define N 505
using namespace std;
typedef long long ll;
int c[505];
int s[505]; 
int f[505]; 
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d %d %d",&c[i],&s[i],&f[i]);
    for(int i=1;i<=n;i++){
        int temp=0;
        for(int j=i;j<n;j++){
            if(temp<s[j])   //小于等待时间重新赋值
                temp=s[j];
            if(temp%f[j]!=0)    //是否处于间隔时间
                temp=temp+f[j]-temp%f[j];
            temp+=c[j];
        }
        printf("%d\n",temp);
    }
}




//#include <iostream>
//#include <vector>
//using namespace std;
//int main()
//{
//    int T;
//    cin>>T;
//    while(T--)
//    {
//        int j=0;
//        int price[5];
//        for(int i=0; i<5; i++)
//        {
//            cin>>price[i];
//        }
//        int N;
//        cin>>N;
//        int ID[110];
//        for(int i=0; i<N; i++)
//        {
//            cin>>ID[i];
//        }
//        int y=0;
//        //int len=ID.size();
//        for(int i=0; i<N; i++)
//        {
//            if(ID[i]<=48)
//            {
//                y+=price[0];
//            }
//            else if(ID[i]<=56)
//            {
//                y+=price[1];
//            }
//            else if(ID[i]<=60)
//            {
//                y+=price[2];
//            }
//            else if(ID[i]<=62)
//            {
//                y+=price[3];
//            }
//            else if(ID[i]==63)
//            {
//                y+=price[4];
//            }
//        }
//        cout<<"Case #"<<j+1<<": "<<y*10000<<endl;
//    }
//    return 0;
//}


Measured memory_bytes: 256