akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
//↓,→,↑,←


#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
    int64_t start;
    const int64_t CYCLES_PER_SEC = 2800000000;
    Timer() { reset(); }
    void reset() { start = getCycle(); }
    inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
    inline int64_t getCycle() {
        uint32_t low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((int64_t)low) | ((int64_t)high << 32);
    }
};


bool multicase = false;

ll n, m, k, w, num, a, b, c, d, e, h, q, ans, sum, l;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
string s, t;

void solve() {
    ll ans = 0;
    cin >> n;
    ll last = 0;
    for(int i=0;i<n;i++){
        cin >> a;

        if (a < last && i != 0) ans += last - a;    
        last = max(a, last);
    
    }
    p(ans);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
// typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<vector<int>> F(n, vector<int>(10));
    rep(i, n) {
        rep(j, 10) {
            cin >> F[i][j];
        }
    }

    vector<vector<int>> P(n, vector<int>(11));
    rep(i, n) {
        rep(j, 11) {
            cin >> P[i][j];
        }
    }

    int res = -1 * INF;
    for (int bit = 1; bit < (1 << 10); ++bit) {
        int sum = 0;
        rep(i, n) {
            int t = 0;
            rep(j, 10) {
                if ((bit >> j) & F[i][j]) ++t;
            }
            sum += P[i][t];
        }
        chmax(res, sum);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  auto n=scanElem;
  (n*(n+1)/2).end();
}


Measured memory_bytes: 256
def show_building_information( notice ):
    building_num = 4
    floor_num = 3
    room_num = 10

    information = [0 for a in range(building_num * floor_num * room_num)]

    for n in notice:
        information[ (n[0] - 1 ) * floor_num * room_num + (n[1] - 1) * room_num + (n[2] - 1) ] +=  n[3]


    for b in range(building_num) :
        for f in range(floor_num):
            for r in range(room_num):
                print( " " + str( information[ b * floor_num * room_num + f * room_num + r ] ), end="")

            print()

        if b != building_num - 1:
            print("####################")
        else:
            print("", end="")


if __name__ == "__main__":

    n  = int(input())
    notice_list = list()

   

    while( n > 0 ):

        notice = input().split(" ")
        notice_list.append([int(notice[0]), int(notice[1]), int(notice[2]), int(notice[3])])

        n = n - 1

    # dummy = [
    # [1, 1, 3, 8],
    # [3, 2, 2, 7],
    # [4, 3, 8, 1],
    # ]

    show_building_information(notice_list)



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

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

	set<int> st;
	while(q--){
		int query,y;cin>>query>>y;
		if(query==0){
			// insert
			st.insert(y);
			cout<<st.size()<<endl;
		}else if(query==1){
			cout<<(st.find(y)!=st.end()?1:0)<<endl;
		}else{
			st.erase(y);
		}
	}
  return 0;
}



Measured memory_bytes: 12412
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
//#define MOD 10000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int 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;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

signed main() {
	int h, w, n;
	int ans[10];
	map<P, int>mp;
	map<P, int>kouho;
	cin >> h >> w >> n;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		mp[{a, b}]++;
		for (int j = -2; j <= 0; j++) {
			for (int k = -2; k <= 0; k++) {
				kouho[{ a + j, b + k }]++;
			}
		}
	}

	rep(i, 10) ans[i] = 0;
	for (auto i : kouho) {
		int ny = i.first.first, nx = i.first.second;
		if (ny >= 1 && ny + 2 <= h && nx >= 1 && nx + 2 <= w) {
			int cnt = 0;
			rep(k, 3) {
				rep(l, 3) {
					if (mp[{ny + k, nx + l}] > 0) {
						cnt++;
					}
				}
			}
			ans[cnt]++;
		}
	}

	int sum = 0;
	for (int i = 1; i < 10; i++) {
		sum += ans[i];
	}
	ans[0] = (h - 2) * (w - 2) - sum;
	rep(i, 10) {
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 212736
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = l[0], B = l[1], C = l[2], D = l[3];
            var max = A * B;
            Console.WriteLine(Math.Max(max, C * D));
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
using namespace std;
int arr[1005];
long long s[2];
vector<int> v;
int main()
{
	int n,mx=0;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
		s[i%2]+=max(arr[i],0);
		if (arr[i]>arr[mx])
		mx=i;
	}
	int st=0;
	if (s[1]>s[0])
	st++;
	n--;
	if (arr[mx]<=0)
	{
		printf("%d\n%d",arr[mx],n);
		while (n!=mx)
		printf("\n%d",(n--)+1);
		while (mx--)
		printf("\n1");
		return 0;
	}
	printf("%lld\n",s[st]);
	while (n%2!=st || arr[n]<=0)
	{
		v.push_back(n);
		n--;
	}
	for (;n!=st;n-=2)
	{
		if (arr[n-2]<=0)
		{
			v.push_back(n-2);
			if (n==2)
			v.push_back(0);
		}
		else
		v.push_back(n-1);
	}
	if (st==1)
	v.push_back(0);
	printf("%d",v.size());
	for (int i:v)
	printf("\n%d",i+1);
}

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

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

using namespace std;

int main() {
  double L;
  cin >> L;
  double l = L / 3;
  cout << setprecision(20) << (l * l * l) << endl;
}


Measured memory_bytes: 256
// AOJ ITP1_1_D
#include<cstdio>

int main()
{
	int S;
	scanf( "%d", &S );

	int h = S/3600, s = S%60;
	printf( "%d:%d:%d\n", h, (S-h*3600)/60, s );

	return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back 
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod 1000000007
#define mod2 998244353
#define INT_MAX1 900000000
//////////////////////////////////////////////////////////////////////////////////////////////

int n;
int arr[3001];
int dp[401][401];
bool v[401][401];

int s1(int i, int j)
{
    if(i==j)
        return 0;
    if(v[i][j])
        return dp[i][j];
    v[i][j] = 1;
    int &x = dp[i][j];
    x = ll_MAX;
    int tot = 0;
    rep(k,i,j)
        tot += arr[k];
    rep(k,i+1,j)
    {
        x = min(x,tot+s1(i,k-1)+s1(k,j));
    }

    return x;
}

void solve()
{
    cin >> n;
    inp(arr,n);
    cout << s1(0,n-1);
}

 
int32_t main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

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

int main() {
	int N;
	cin >> N;
	int64_t ans = 0;
	for (int i = 1;i <= N;++i) {
		if (i % 5 != 0 && i % 3 != 0) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace trival
{
    class Program
    {
        static void Main(string[] args)
        {
            int pointNum = int.Parse(Console.ReadLine());
            List<int> points = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToList();
           // points.Insert(0, 0);
            //points.Add(0);
            int[] costs = new int[pointNum];
            long sum = sumAll(points, pointNum, ref costs);
 
            for (int i = 0; i < pointNum; i++)
            {
 
                Console.WriteLine(sum - costs[i]);
            }
 
 
        }
        static long sumAll(List<int> points, int pointNum, ref int[] costs)
        {
            long sum = 0;
            int zero = 0;
            int currentPos = 0;
            for (int i = 0; i < pointNum; i++)
            {
                if (i == pointNum-1)
                {
                    costs[i] = Math.Abs((currentPos - points[i])) + Math.Abs((points[i] - zero)) - Math.Abs(currentPos - zero);
                    sum += Math.Abs(currentPos - points[i]);
                    currentPos = points[i];
                    continue;
                }
                costs[i] = Math.Abs((currentPos - points[i])) + Math.Abs((points[i] - points[i + 1])) - Math.Abs(currentPos - points[i + 1]);
                sum += Math.Abs(currentPos - points[i]);
                currentPos = points[i];
            }

            sum += Math.Abs(currentPos - zero);
            return sum;
        }
 
    }
}

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


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

class BEasyLinearProgramming {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll a,b,c,k;
	    in >> a >> b >> c >> k;
	    if(k<=a){
	        out << k << endl;
	    }else{
	        ll t = k-a;
	        out << a-max(t-b,(ll)0) << endl;
	    }
	}
};


int main() {
	BEasyLinearProgramming solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

const int N = 22;
int h, w, dist[N][N];
bool vis[N][N];
pair<int, int> mov[4];
string arr[N];

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

    mov[0] = {1, 0};
    mov[1] = {0, 1};
    mov[2] = {-1, 0};
    mov[3] = {0, -1};
    
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        cin >> arr[i];
    }
    vector<pair<int, int>> open;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(arr[i][j] == '.'){
                open.push_back({i, j});
            }
        }
    }

    int siz = open.size();
    queue<pair<int, int>> q;

    int ans = -1;
    for(int i = 0; i < siz; i++){
        for(int j = i + 1; j < siz; j++){
            pair<int, int> start = open[i];
            pair<int, int> target = open[j];

            for(int a = 0; a < h; a++){
                for(int b = 0; b < w; b++){
                    vis[a][b] = 0;
                    dist[a][b] = 0;
                }
            }   
            vis[start.first][start.second] = 1;
            dist[start.first][start.second] = 0;
            q.push(start);

            while(!q.empty()){
                auto fr = q.front();
                q.pop();

                for(int e = 0; e < 4; e++){
                    int nextr = fr.first + mov[e].first;
                    int nextc = fr.second + mov[e].second;

                    if(nextr >= 0 && nextr < h && nextc >= 0 && nextc < w && arr[nextr][nextc] == '.'){
                        if(!vis[nextr][nextc]){
                            vis[nextr][nextc] = 1;
                            dist[nextr][nextc] = 1 + dist[fr.first][fr.second];
                            q.push({nextr, nextc});
                        }
                    }
                }
            }

            ans = max(ans, dist[target.first][target.second]);
        }
    }
    cout << ans << '\n';
    return 0;
}

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

enum P = 10L^^9+7;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

void main()
{
    auto nk = readln.split.to!(long[]);
    auto N = nk[0];
    auto K = nk[1];

    auto cs = new long[](K+1);
    foreach_reverse (k; 1..K+1) {
        auto x = K / k;
        cs[k] = pow(x, N);
        auto kk = k;
        for (;;) {
            kk += k;
            if (kk > K) break;
            cs[k] = (cs[k] - cs[kk] + P) % P;
        }
    }
    long r;
    foreach (i, c; cs) r = (r + c * i.to!long % P) % P;
    writeln(r);
}

Measured memory_bytes: 3380
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> s(n);
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		s.at(i) = make_pair(t, i + 1);
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++) {
		cout << s.at(i).second;
		if (i != n - 1) {
			cout << ' ';
		}
	}
}

Measured memory_bytes: 1536
N,A = map(int,input().split())
x = list(map(int,input().split()))
X = N*50
dp = [[[0 for i in range(X+1)] for j in range(N+1)] for k in range(N+1)]
dp[0][0][0] = 1
for k in range(1,N+1):
    for j in range(k+1):
        for i in range(j*50+1):
            if i - x[k-1] < 0:
                dp[k][j][i] = dp[k-1][j][i]
            elif k >= 1:
                dp[k][j][i] = dp[k-1][j-1][i-x[k-1]] + dp[k-1][j][i]
ans = 0
for j in range(1,N+1):
    ans += dp[-1][j][j*A]
print(ans)

Measured memory_bytes: 65392
#include <iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n+1];
  for (int i=1;i<=n;i++){
    int s;
    cin>>s;
    a[s]=i;
  }
  for(int i=1;i<n;i++){
    cout<<a[i]<<" ";
  }
  cout<<a[n]<<endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

int h, w;
char a[1001][1001];
ll dp[1001][1001];

ll solve(int i, int j) {

	if (i == h or j == w)
		return 0;

	if (i == h - 1 and j == w - 1)
		return 1;

	if (a[i][j] == '#')
		return 0;

	if (dp[i][j] != -1)
		return dp[i][j];

	dp[i][j] = (solve(i + 1, j) + solve(i, j + 1)) % mod;
	return dp[i][j];
}

int main() {

	cin >> h >> w;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> a[i][j];
		}
	}

	memset(dp, -1, sizeof(dp));
	cout << solve(0, 0);

	return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>

using namespace std;

//AOJ IOI

int main(){
	while(true){
		string S;
		cin >> S;
		if(cin.eof()) break;

		int JOI = 0, IOI = 0;
		for(int i=0; i<S.size(); i++){
			if(S[i] == 'J'){
				if(S[i+1] == 'O'){
					if(S[i+2] == 'I'){
						JOI++;
						i++;
					}
				}
			}
			else if(S[i] == 'I'){
				if(S[i+1] == 'O'){
					if(S[i+2] == 'I'){
						IOI++;
						i++;
					}
				}
			}
		}

		cout << JOI << endl << IOI << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

void add_self(int &a,int b)
{
	a+=b;
	a%=MOD;
}
void solve() {
string s;
string t;
cin>>s>>t;
ll ans=INT_MAX;
for(int i=0;i+t.length()-1<s.length();i++)
{ll cnt=0;
	for(int j=0;j<t.length();j++)
	{
		if(s[i+j]!=t[j])
		cnt++;
	}
	ans=min(cnt,ans);
}
cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc=1; //cin >> tc;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}


Measured memory_bytes: 3652
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    
    int count = 0;
    
    if (0 < n && n < 10) {
      count = n;
    } else if (n < 100) {
      count = 9;
    } else if (n < 1000) {
      count = 9 + n - 99;
    } else if (n < 10000) {
      count = 909;
    } else if (n < 100000) {
      count = 9 + 900 + n - 9999;
    } else if (n < 1000000) {
      count = 90909;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23636
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vvll a(n,vll(10)) ;
	vvll b(n,vll(11)) ;
	for(int i=0;i<n;i++) for(int j=0;j<10;j++) cin >> a.at(i).at(j) ;
	for(int i=0;i<n;i++) for(int j=0;j<11;j++) cin >> b.at(i).at(j) ;
	ll ans = -100000000000 ;
	for(int i=1;i<(1<<10);i++){
		bitset<15> bit(i) ;
		ll sub = 0 ;
		for(int j=0;j<n;j++){
			ll cnt = 0 ;
			for(int k=0;k<10;k++) cnt += (bit[k]&&a.at(j).at(k)) ;
			sub += b.at(j).at(cnt) ;
		}
		if(ans<sub) ans = sub ;
	}
	cout << ans << endl ;
}


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

int main()
{	
	ll N,M;
	cin>>N>>M;
	
	if(N==M)
	{
	cout<<"Yes"<<endl;
	}
	else
	{
	cout<<"No"<<endl;
	}
	return 0;
}

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

int main(){
	char a[4];
	int ans = 0;
	cin >> a;
	for (int i=0; i<4; i++){
		if (a[i]=='+') {
			ans += 1;
		}
		else {
			ans -= 1;
		}
	}
	cout << ans;
	}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int x;
    cin >> x;
    bool arr[200000];
    int money;

    reps(i,1,1010){
        money = 100*i;
        rep(j,5*i+1){
            money = 100*i+j;
            arr[money] = true;
        }
    }

    if(arr[x]) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 384
(defun d (k x)
  (* (min x (- k x)) 2))

(defun solve (k xs &optional (ans 0))
  (cond
    ((null xs) ans)
    (t         (solve k (rest xs) (+ ans (d k (first xs)))))))



(let ((n (read))
      (k (read))
      (xs (read-from-string
          (concatenate 'string "(" (read-line) ")"))))
     (princ (solve k xs)))


Measured memory_bytes: 5092
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 998244353
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int ka[2145140],inv[2145140];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int p2[55],res=1;
	p2[0]=1;p2[1]=x%inf;
	for(int i=2;i<=50;i++){
		p2[i]=p2[i-1]*p2[i-1];
		p2[i] %= inf;
	}
	for(int i=1;i<=50;i++){
		if(k%2==1){
			res *= p2[i];
			res %= inf;
		}
		k /= 2;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
signed main(){
	int n,m;
	cin>>n>>m;
	setkaijo(2000000);
	setinv(2000000);
	int ans = 0, sub = 0;
	for(int i=0; i<=m ; i++){
		if( i <= n && ( 3*m-i ) % 2 == 0 ){
			int tmp = 1;
			int tms = ( 3 * m - i ) / 2;
			tmp = comb( tms + n - 1, tms );
			tmp *= comb( n, i );
			tmp %= inf;
			ans += tmp;
			ans %= inf;
		}
	}
	for(int i=2*m+1;i<=3*m;i++){
		int amari = 3*m-i;
		int tmp = n;
		tmp *= comb( amari + n - 2, amari );
		tmp %= inf;
		sub += tmp;
		sub %= inf;
	}
	int res = ( ans + inf - sub ) % inf;
	cout<<res<<endl;
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  int sum = 0;
  vector<int> t(n);
  rep(i, n) {
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  rep(i, m) {
    int p, x;
    cin >> p >> x;
    int ans = 0;
    ans = sum - t[p-1] + x;
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n, w;
    scanf("%d %d", &n, &w);

    vector<pair<int, int>> bg(n);
    REP(i,n){
        scanf("%d %d", &bg[i].first, &bg[i].second);
    }

    vector<int> dp(w + 1, -1);
    dp[0] = 0;
    REP(i,n){
        FOR(j,bg[i].second,w+1){
            dp[j] = max(dp[j], dp[j - bg[i].second] + bg[i].first);
        }
    }
    int result = 0;
    DEFOR(i,w+1,0){
        result = max(result, dp[i]);
    }
    cout << result << endl;



    return 0;
}



Measured memory_bytes: 3268
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.root(x)]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def members(self, x):
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    
    N = int(input())
    
    x, y = [[0, 0] for _ in range(N)], [[0, 0] for _ in range(N)]
    for i in range(N):
        x[i][0], y[i][0] = map(int, input().split())
        x[i][1], y[i][1] = i, i
    x, y = sorted(x), sorted(y)
    
    L = [[0, 0, 0] for _ in range((N - 1) * 2)]
    for i in range(N - 1):
        L[i * 2][0] = x[i + 1][0] - x[i][0]
        L[i * 2][1] = x[i][1]
        L[i * 2][2] = x[i + 1][1]
        L[i * 2 + 1][0] = y[i + 1][0] - y[i][0]
        L[i * 2 + 1][1] = y[i][1]
        L[i * 2 + 1][2] = y[i + 1][1]
    L = sorted(L)

    tree = UnionFind(N)
    ans = 0
    for i in range((N - 1) * 2):
        if not tree.same(L[i][1], L[i][2]):
            ans += L[i][0]
            tree.unite(L[i][1], L[i][2])
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 63248
#include <stdio.h>

int main()
{
    int A, B;

    scanf("%d %d", &A, &B);
    if (A > B)
    {
        printf("%d", (A + (A - 1)));
    }
    else if (B > A)
    {
        printf("%d", (B + (B - 1)));
    }
    else if (A == B)
    {
        printf("%d", (A + B));
    }

    return 0;
}

Measured memory_bytes: 128
from collections import Counter
S = input()
nums = list(set(S))
ans=pow(10,9)
for num in nums:
    s=S
    ans2=0
    while len(Counter(s)) > 1:
        list_s=list(s)
        new_s=[]
        for n in range(len(list_s)-1):
            if list_s[n] == num or list_s[n+1] == num:
                new_s.append(num)
            else:
                new_s.append(list_s[n])
        s = new_s
        ans2 += 1
    ans =  min(ans, ans2)
print(ans)


Measured memory_bytes: 69608
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  vector<int>v1,v2,v3;
  int i,j,k,l=0,m,a,b,c;
  for(i=0;i<n;i++)
  {
    cin>>a;
    v1.push_back(a);
  }
  for(i=0;i<n;i++)
  {
    cin>>b;
    v2.push_back(b);
  }
  for(i=0;i<n-1;i++)
  {
    cin>>c;
    v3.push_back(c);
  }
  for(i=0;i<n;i++)
  {
      l=l+v2[(v1[i]-1)];
  }
  for(i=0;i<n-1;i++)
  {
     if((v1[i+1]-v1[i])==1)
       l=l+v3[(v1[i]-1)];
  }
  cout<<l;
}
      
   

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	int cnt = 0;
	rep(i,n){
		int t;
		cin>>t;
		if(t%2) cnt++;
	}
	if(cnt%2==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

        vector<int> a(5);
        int k;
        REP(i, 5) {
            std::cin >> a[i];
        }
        std::cin >> k;

        std::cout << ((k < a.back() - a.front()) ? ":(" : "Yay!") << std::endl;

    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef set <int> se;
#define endl "\n"
#define for(i,a,b) for(auto i = a;i<b;i++)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int MOD = 1e9+7;
ll mod(ll x){
return ((x%MOD+MOD)%MOD);
}
ll add(ll a,ll b){
return mod(mod(a)+mod(b));
}
ll mul(ll a,ll b){
return mod(mod(a)*mod(b));
}
ll sub(ll a,ll b){
return mod(mod(a)-mod(b));
}

ll dp[2001];

int rec(ll s){
    if(s==0) return 1ll;
    if(s==1 or s==2) return 0ll;
    if(s>=3 and s<=5) return 1ll;
    if(dp[s]!=-1) return dp[s];
    ll total = 0;
    for(i,3,s+1)
        if(s-i>=0) 
            total = add(total,rec(s-i));
    return dp[s] = total;
    
}

void solve(){
ll n;
cin>>n;
memset(dp,-1,sizeof(dp));
dp[0] = 1;
cout<<rec(n)<<endl;

}
 
 
int main()
{

solve();
 
return 0;
}

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

using namespace std;

double const PI = acos(-1);

int r;

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	cin >> r;

	cout << setprecision(10) << 2 * PI * r << endl;
}


Measured memory_bytes: 3784
x, n = gets.split(" ").map(&:to_i)
array = gets.split(" ").map(&:to_i)
if !array.include?(x)
  puts x
  exit
end
nums = []
for i in (x + 1)..101
  if !array.include?(i)
    nums << [i, (x - i).abs]
  end
end
i = 0
while i < x
  if !array.include?(x - 1 - i)
    nums << [(x - 1 - i), (x - 1 - i - x).abs]
  end
  i += 1
end
puts nums.sort_by{|item| [item[1], item[0]]}[0][0]

Measured memory_bytes: 14328
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]

def equal(a, b, i,j,m):
    for k in range(m):
        for l in range(m):
            if a[i+k][j+l] != b[k][l]:
                return False
    return True


#n = ["abc","cde","xzy"]
#m = ["abc","cde","jzy"]
a = []
b = []
n,m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

temp = n - m + 1


for i in range(temp):
    for j in range(temp):
        #[i][j]を起点として比較
        for k in range(m):
            for l in range(m):
                if equal(a,b,i,j,m):
                    print("Yes")
                    exit()
print("No")





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

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

const int MOD = 1e+9 + 7;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> a(N+1);
    REP(i, N) cin >> a[i+1];

    // dp[i][j]: 0~i 人に計 k 個の飴を配る配り方 
    vector<vector<long long>> dp(N+1, vector<long long>(K+1));
    REP(i, N+1) dp[i][0] = 1;
    FOR(i, 1, N+1){
        FOR(j, 1, K+1){
            dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;
            if(j > a[i]) dp[i][j] -= dp[i-1][j-a[i]-1];
            dp[i][j] %= MOD;
        }
    }
    cout << (dp[N][K]+MOD)%MOD << endl;

    return 0;
}

Measured memory_bytes: 80256
N, Q = map(int, input().split())
edge = [[] for i in range(N)]
q = [0 for i in range(N)]
 
for i in range(N-1):
  a, b = map(int, input().split())
  edge[a-1].append(b)
for i in range(Q):
  a, v = map(int, input().split())
  q[a-1] += v
 
for i, v in enumerate(q):
  #print(i, v)
  for j in edge[i]:
    #print(j)
    q[j-1] += v
print(*q)

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n;
  cin >> n;
  vector<int> v(n, 0);
  rep(i,n-1) {
    int a;
    cin >> a;
    v[a-1]++;
  }
  rep(i,n) {
    cout << v[i] << endl;
  }
  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000LL
#define MOD 1000000009
#define EPS 1E-9

typedef ll Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void Dijkstra(const Graph &g, int s, vector<Weight> &dist)
{
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    vrep(f, g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

int V, E, r;
int s, t;
Weight d;

int main()
{
  cin >> V >> E >> r;
  Graph g(V);
  vector<Weight> dist;
  rep(i, E){
    cin >> s >> t >> d;
    g[s].pb(Edge(s, t, d));
  }

  Dijkstra(g, r, dist);

  rep(i, V) if(dist[i] >= INF) puts("INF"); else printf("%d\n", dist[i]);

  return 0;
}

Measured memory_bytes: 17636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define M 32768
#define N 20
inline int read(){
	int x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0'; ch = getchar();}
	return x*f;
}

int n,m,c[N][N];
int p[M],dp[M][N];
int sum;

inline void init(){
	memset(p,0,sizeof p);
	memset(dp,-1,sizeof dp);
	for(int i = 0;i < (1<<n);i++)
		for(int j = 0;j < n;j++){
			if(!((i>>j)&1)) continue;
			for(int k = j+1;k < n;k++){
				if(!((i>>k)&1)) continue;
				p[i] += c[j][k];
			}
		}
}

int main(){
	memset(c,0,sizeof c);
	n = read(); m = read(); sum = 0;
	for(int i = 1;i <= m;i++){
		int u = read()-1,v = read()-1,w = read();
		c[u][v] = c[v][u] = w;
		sum += w;
	}
	init();
	dp[1][0] = 0;
	for(int i = 0;i < (1<<n);i++){
		for(int j = 0;j < n;j++){
			if(dp[i][j] == -1) continue;
			int x = (((1<<n)-1)^i)|(1<<j);
			for(int y = x;y >= 0;y--){
				y &= x;
				dp[i|y][j] = max(dp[i|y][j],dp[i][j]+p[y]);
			}
			for(int k = 0;k < n;k++){
				if((i>>k)&1) continue;
				if(c[j][k] == 0) continue;
				dp[i|(1<<k)][k] = max(dp[i|(1<<k)][k],dp[i][j]+c[j][k]);
			}
		}
	}
	int ans = 1e9;
	for(int i = 0;i < (1<<n);i++)
		ans = min(ans,sum-dp[i][n-1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2944
from collections import Counter

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

C = Counter(A)
tmp = 0
for key in C.keys():
    if C[key] >= 2:
        tmp += (C[key] * (C[key]-1))//2

for a in A:
    if C[a] <= 1:
        print(tmp)
    else:
        print(tmp - (C[a] * (C[a]-1))//2 + ((C[a]-1) * (C[a]-2))//2)

Measured memory_bytes: 90060
import math

N = int(input())

Z = [int(input()) for i in range(N)]

ctr = 0

for j in range(N):
	if Z[j] == 2:
		ctr += 1
	elif Z[j] < 2 or (Z[j] % 2) == 0:
		pass
	else:
		Up = math.sqrt(Z[j])
		k = 3
		while k<= Up:
			if (Z[j] % k) == 0:
				break
			else:
				k += 1
		else:
			ctr += 1

print(ctr)

Measured memory_bytes: 7960
def MD(a1, a2):
    return abs(a1[0]-a2[0]) + abs(a1[1]-a2[1])
N, M = map(int, input().split())
a = []
b = []
for i in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
c = []
d = []
for i in range(M):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)

for A, B in zip(a, b):
    min_d = 10 ** 10
    for i, (C, D) in enumerate(zip(c, d)):
        md = MD((A, B), (C, D))
        if md < min_d:
            ans = i + 1
            min_d = md
    print(ans)



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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

struct edge{
    int to, cost;
    edge(int to, int cost): to(to), cost(cost){}
};

struct State{
    int v, t;
    double c;
    State(int v, int t, double c): v(v), t(t), c(c){}
    bool operator<(const State& right ) const {
        return c == right.c ? t < right.t : c > right.c;
    }
};

int main(){
    double minDist[30][(1<<8)];
    while(1){
        int n, m, p, a, b;
        cin >> n >> m >> p >> a >> b;
        if(n == 0) break;
        a--; b--;

        vec ticket(n);
        for(int i=0;i<n;i++){
            cin >> ticket[i];
        }

        vector<vector<edge>> E(m);
        for(int i=0;i<p;i++){
            int x, y, z;
            cin >> x >> y >> z;
            x--; y--;
            E[x].emplace_back(y, z);
            E[y].emplace_back(x, z);
        }

        for(int i=0;i<(1<<n);i++){
            for(int j=0;j<m;j++){
                minDist[j][i] = 300000;
            }
        }
        minDist[a][0] = 0;

        priority_queue<State> que;
        que.emplace(a, 0, 0);

        double ans = -1;
        while(que.size()){
            State s = que.top(); que.pop();
            if(minDist[s.v][s.t] < s.c) continue;
            if(s.v == b){
                ans = s.c;
                break;
            }
            for(int i=0;i<n;i++){
                if(((s.t>>i)&1) == 1) continue;
                for(edge& e: E[s.v]){
                    double nc = s.c + (double)e.cost / ticket[i];
                    int nt = s.t | (1<<i);
                    if(minDist[e.to][nt] > nc){
                        minDist[e.to][nt] = nc;
                        que.emplace(e.to, nt, nc);
                    }
                }
            }
        }
        if(ans < 0) cout << "Impossible" << endl;
        else printf("%.5f\n", ans);
    }
    return 0;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
vll a;
vll b;
lli ans = LONG_MAX;

bool check(){
  for(lli i = 0;i < n;i++){
    if(a[i] != b[i]) return false;
  }
  return true;
}

int main(){
  cin >> n;
  a = vll(n);
  b = vll(n);
  for(lli i = 0;i < n;i++) cin >> a[i] >> b[i];
  if(check()){
    cout << 0 << endl;
    return 0;
  }
  for(lli i = 0;i < n;i++){
    if(a[i] > b[i]) ans = min(ans,b[i]);
  }
  cout << accumulate(a.begin(),a.end(),0ll)-ans << endl;
  return 0;
}


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

int main()
{
	const int ab_from=-127;
	const int ab_to=127;

	map<int64_t,pair<int,int>> m;

	for (int64_t i=ab_from;i<=ab_to;++i)
	{
		for (int64_t j=ab_from;j<=ab_to;++j)
		{
			m[i*i*i*i*i-j*j*j*j*j]=make_pair(i,j);
		}
	}

	int x;
	cin >> x;
	if (m.count(x)>0)
	{
		cout << m[x].first << " " << m[x].second << endl;
	}
	else
	{
		cout << "not found..." << endl;
	}
}





Measured memory_bytes: 5664