akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class UnionFindTree {
	int n;
	vector<int> par;
	vector<int> rank;
	vector<set<int>> dec_set;
public:
	UnionFindTree(int N) {
		n = N;
		par.resize(n);
		rank.resize(n);
		dec_set.resize(n);
		REP(i, n) par[i] = i;
	}

	int root(int i) {
		if (par[i] == i) return i;
		par[i] = root(par[i]);
		return par[i];
	}

	bool same(int i, int j) {
		return root(i) == root(j);
	}

	void unite(int i, int j) {
		dec_set[i].insert(j);
		dec_set[j].insert(i);
		if (same(i, j)) return;
		i = root(i);
		j = root(j);
		if (rank[i] < rank[j]) {
			rank[i] = rank[j];
			par[i] = root(j);
		}
		else if (rank[i] > rank[j]) {
			rank[j] = rank[i];
			par[j] = root(i);
		}
		else {
			rank[i] += 1;
			par[i] = root(j);
		}
	}

	void block(int i, int j) {
		if (same(i, j)) {
			dec_set[i].insert(j);
			dec_set[j].insert(i);
		}
	}

	int dec(int i) {
		return dec_set[i].size();
	}
};

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

	int N, M, K;
	cin >> N >> M >> K;
	UnionFindTree uft(N + 1);
	REP(i, M) {
		int A, B;
		cin >> A >> B;
		uft.unite(A, B);
	}
	REP(i, K) {
		int C, D;
		cin >> C >> D;
		uft.block(C, D);
	}
	
	vector<int> par_same(N + 1, -1);
	FOR(i, 1, N + 1) par_same[uft.root(i)] += 1;
	FOR(i, 1, N + 1) {
		cout << par_same[uft.root(i)] - uft.dec(i) << " ";
	}
	
	return 0;
}


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

int main(){
  int ans;
  vector<int> trabel(3);
  for(int i = 0;i < 3;i++){
     cin >> trabel.at(i);
  }
  ans = 0;
  sort(trabel.begin(),trabel.end());
  ans = trabel.at(0) + trabel.at(1);
  cout << ans << endl;
  return 0;
}

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

namespace ConsoleApplication2
{
    class Program
    {

        const int diceUpDownSum = 7;

        static void Main(string[] args)
        {
            int id = 0;
            var diceList = Console.ReadLine().Split(' ').Select(n => new Dice(++id, int.Parse(n))).ToList();
            var commandItem = Console.ReadLine().ToArray();

            int top = 1;
            int s = 2;
            int e = 3;

            foreach (var command in commandItem)
            {
                int work = 0;
                work = top;
                switch (command)
                {
                    case 'S':
                        top = diceUpDownSum - s;
                        s = work;
                        break;
                    case 'E':
                        top = diceUpDownSum - e;
                        e = work;
                        break;
                    case 'W':
                        top = e;
                        e = diceUpDownSum - work;
                        break;
                    case 'N':
                        top = s;
                        s = diceUpDownSum - work;
                        break;
                }
            }

            Console.WriteLine(diceList.SingleOrDefault(n => n.Id == top).Number);

            Console.ReadKey();
        }
    }

    class Dice
    {
        public int Id { get; set; }
        public int Number { get; set; }

        public Dice(int id, int number)
        {
            Id = id;
            Number = number;
        }
    }
}

Measured memory_bytes: 20356
S = input()

n = len(S) -1 

for i in range(2**n):
    loc = []
    S2 = []
    for j in range(n):
        if (i>>j) & 1:
            loc.append('+')
        else:
            loc.append('-')
    loc.reverse()
    
    for k in range(n):
        S2.append(S[k])
        S2.append(loc[k])
    S2.append(S[-1])
    St = ''.join(S2)
    if eval(St) == 7:
        print(St+'=7')
        break


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

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;
static long long INF = (1LL<<62);
using LLPair = pair<LL, LL>;

const LL MAXT = 100000;
//区間の配列が時刻tを含むか
int contain(vector<pair<LL, LL>> &v, LL t){
	if(v.size() == 0) return 0;

	int ret = 0;
	pair<LL, LL> p = make_pair(t, t);
	LL l1 = -1, r1 = -1, l0 = -1, r0 = -1;
	auto itr = lower_bound(v.begin(), v.end(), p);
	if(itr == v.end()){
		itr--;
	}
	l1 = itr->first;
	r1 = itr->second;
	if(t >= l1 && t <= r1){
		ret = 1;
	}
	if(t < l1){
		if(itr == v.begin()){
			ret = 0;
		}
		else{
			itr--;
			l0 = itr->first;
			r0 = itr->second;
			if(l0 <= t && t <= r0){
				ret = 1;
			}
			else{
				ret = 0;
			}
		}
	}
	return ret;
}
int main(int argc, char* argv[]){

	LL N, C; cin >> N >> C;
	LL S = MAXT, T = 0;
	vector<vector<pair<LL, LL>>> V(C);
	for(int i=0; i<N; i++){
		LL s, t, c; cin >> s >> t >> c;
		c--;
		V[c].push_back(make_pair(s, t));
		if(S > s) S = s;
		if(T < t) T = t;
	}
	for(int c=0; c<C; c++){
		sort(V[c].begin(), V[c].end());
	}
	int ans = 0;
	for(int t=1; t<=T; t++){
		int rec = 0;
		for(int c=0; c<C; c++){
			int r = contain(V[c], t);
			rec += r;
		}
		if(ans < rec) ans = rec;
	}
	printf("%d\n", ans);
	return 0;
}



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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;


int main( void ){
	// initialize();
	int N;
	cin >> N;
	vector <edge> tree( N );
	rep( i, 1, N ){
		int input; cin >> input;
		input--;
		tree[ input ].to.push_back( i );
	}
	rep( i, 0, N ){
		cout << tree[i].to.size() << endl;
	}
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 15512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
//#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)

void printVec(std::vector<int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec1(std::vector<string> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

void printVec2(std::vector<Int> &vec) {
//    std::cout << "";
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        std::cout << *it << " ";
    }
    cout << '\n';
}

Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

bool ispositive(Int num,int i) {
    if (num > 0) return true;
    if (num < 0) return false;
    else if(i==0) return false;
    else return true;
}

int main() {
    IOS;
    //std::ifstream in("01-04.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    Int sum1 = 0, sum2 = 0;
    Int cnt1=0,cnt2=0;
    for (int i = 0; i < n; i++) {
        Int temp;cin>>temp;
        sum1+=temp;
        sum2+=temp;
        if(i%2==0&&!ispositive(sum1,0)){
            cnt1+=1-sum1;
            sum1=1;
        }
        if(i%2==1&&ispositive(sum1,1)){
            cnt1+=sum1+1;
            sum1=-1;
        }
        if(i%2==1&&!ispositive(sum2,0)){
            cnt2+=1-sum2;
            sum2=1;
        }
        if(i%2==0&&ispositive(sum2,1)){
            cnt2+=sum2+1;
            sum2=-1;
        }
        //cout<<sum2<<" ";
    }
    //if(sum1==0)cnt1++;
    //if(sum2==0)cnt2++;

    //cout<<cnt1<<" "<<cnt2;
    cout<<min(cnt2,cnt1);


    cout << endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


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


int main() {
    int a, b;
    cin >> a >> b;

    if(a > b){
        int temp = b;
        b = a;
        a = temp;
    }
    for(int i = 0; i < b; i++){
        cout << a;
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,q;
	int box[100000];
	int i;
	int x;
	cin>>n;
	for(i=0;i<n;i++)	cin>>box[i];
	cin>>q;
	for(i=0;i<q;i++){
		cin>>x;
		cout<<lower_bound(box,box+n,x)-box<<endl;
	}
	return 0;
}


Measured memory_bytes: 3508
class UnionFind:
    def __init__(self, n):
        self.data=[-1 for i in range(n)]

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

    def uni(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if(x==y):
            return
        if self.data[y]<self.data[x]:
            x,y=y,x
        self.data[x]+= self.data[y]
        self.data[y] = x

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

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

n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
    x,y,z=map(int,input().split())
    uf.uni(x-1,y-1)
count=0
for i in range(n):
    if uf.data[i]<0:
        count+=1
print(count)

Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

string s;

ll dp[N][3]; // 0-P, 1-D
ll nxt[N][3];
ll recur(ll pos, ll val) {

  if (pos == s.length())
    return 0;
  ll &ans = dp[pos][val];
  if (ans != -1)
    return ans;

  ll &nxt1 = nxt[pos][val];
  ans = 0;
  // P
  if (s[pos] == '?' or s[pos] == 'P') {
    ans = max(ans, recur(pos + 1, 0));

    nxt1 = 0;
  }

  // D
  if (s[pos] == '?' or s[pos] == 'D') {

    ans = max(ans, 1 + (val == 0) + recur(pos + 1, 1));
    if (ans == (1 + (val == 0) + recur(pos + 1, 1)))
      nxt1 = 1;
  }
  return ans;
}

string res = "";
void solve(ll pos, ll val) {
  if (pos == s.length())
    return;
  ll &nxt1 = nxt[pos][val];
  res += ((nxt1 == 0) ? 'P' : 'D');
  solve(pos + 1, nxt1);
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> s;
  memset(dp, -1, sizeof(dp));
  recur(0, 2);
  solve(0, 2);
  cout << res << en;
  return 0;
}

Measured memory_bytes: 28768
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  string a,b,c;
  cin>>a>>b>>c;

  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


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

using namespace std;

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


int main()
{
    int a[100];
    int N, t;
    cin >> N;

    int plus = 1;
    int minus = 1;

    REP(i, N)
    {
        cin >> t;
        plus *= 3;
        if(t % 2 == 0)
        {
            minus *= 2;
        }
        else{
            minus *= 1;
        }
    }
    cout << plus - minus << endl;


}

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

int main(){

  int n, m;
  int p[111];
  int q[111];
  int ans[111] = {};

  cin >> n;
  cin >> m;

  for(int i=0;i<m;i++) cin >> p[i];

  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++) cin >> q[j];

    int cnt = 0;
    for(int j=0;j<n;j++){
      if(p[i] != q[j]) cnt++;
      else ans[j]++;
    }

    ans[p[i]-1] += cnt;

  }

  for(int i=0;i<n;i++) cout << ans[i] << endl;

}

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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int n;
        cin >> n;
        cout << fixed << setprecision(9);
        cout << acos(-1) * 2 * n;
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


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

const int MAXN = 13;
typedef unsigned long long ull;
const ull bas = 19260817;

int n, m;
char str[MAXN][MAXN];
int p[MAXN], q[MAXN], px, qx;
int a[MAXN];

map<ull, int> mp;

ull h[MAXN], hinv[MAXN];
int ans = 0;

void solve()
{
	mp.clear();
	int top = 0;
	for (register int j = 1; j <= px; j++) a[++top] = p[j];
	int qxt = qx;
	if (px != qx) a[++top] = q[qx--];
	for (register int j = qx; j >= 1; j--) a[++top] = q[j];
	qx = qxt;
	for (register int j = 1; j <= m; j++) {
		h[j] = 0;
		for (register int i = 1; i <= n; i++) 
			h[j] = h[j]*bas+str[a[i]][j];
		mp[h[j]]++;
		hinv[j] = 0;
		for (register int i = n; i >= 1; i--)
			hinv[j] = hinv[j]*bas+str[a[i]][j];
	}
	int flag = 1, ct = 0;
	ull cur = 0;
	for (register int j = 1; j <= m; j++) {
		if (mp[hinv[j]] != mp[h[j]])
			flag = 0;
		// cerr << h[j] << " " << hinv[j] << " " << mp[h[j]] << endl;
		if (h[j] == hinv[j] && (mp[h[j]]&1)) {
			if (!ct) {
				cur = h[j];
				ct = 1;
			} else if (cur != h[j])
				flag = 0;
		}
	}
	if (flag && ct <= 1) ans = 1;
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%s", str[i]+1);
	int c = 0;
	for (register int i = 0; i < (1<<n) && !ans; i++) {
		int cnt = 0;
		for (register int j = 0; j < n; j++)
			if (i&(1<<j))
				cnt++;
		if (cnt != n/2) continue;
		px = 0, qx = 0;
		for (register int j = 0; j < n; j++) {
			if (i&(1<<j)) p[++px] = j+1;
			else q[++qx] = j+1;
		}
		do {
			int flag = 1;
			for (register int j = 1; j <= px; j++)
				if (p[j] > q[j]) {
					flag = 0;
					break;
				}
			if (flag) {
				solve();
				/*if (ans == 1) {
					for (int j = 1; j <= n; j++)
						cerr << a[j] << " ";
					cerr << endl;
					}*/
			}
		} while (next_permutation(q+1, q+qx+1) && !ans);
	}
	if (ans == 1) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

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

	int n;
	cin >> n;
	vector< pair<int, pair<int,int> > > a(n);
	for(int i=0; i<n; ++i)
	{
		cin >> a[i].first >> a[i].second.first >> a[i].second.second;
	}
	a.push_back( make_pair(0, make_pair(0,0) ) );
	++n;
	sort(a.begin(), a.end());

	for(int i=1; i<n; ++i)
	{
		int t1 = a[i-1].first;
		int t2 = a[i].first;
		int x1 = a[i-1].second.first;
		int y1 = a[i-1].second.second;
		int x2 = a[i].second.first;
		int y2 = a[i].second.second;
		int d = abs(x1-x2) + abs(y1-y2);
		
		if((t2-t1)%2 != d%2 || (t2-t1) < d)
		{
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";

	return 0;
}


Measured memory_bytes: 2560
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())))[::-1]
q = sorted(list(map(int, input().split())))[::-1]
r = sorted(list(map(int, input().split())))[::-1]

u = sorted(p[:x] + q[:y] + r)[::-1]
print(sum(u[:x + y]))


Measured memory_bytes: 29468
#include<bits/stdc++.h>
#define loop(vals,times) for(vals=0;vals<times;vals++)
#define reg(time) for(int val=0;val<time;val++)
#define space <<" "<<
using namespace std;

int main()
{
    int q,c,x;
    string key;
    map<string,int> M;
    
    cin>>q;
    reg(q){
    cin>>c>>key;
        if(c==0){
            cin>>x;
            M[key]=x;
        }
        if(c==1)cout<<M[key]<<endl;
        if(c==2)M.erase(key);
    }
}


Measured memory_bytes: 27856
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  
 // var NX = input[0];
  var NX = input[0].split(" ");
  var n= parseInt(NX[0], 10);
  var x= parseInt(NX[1], 10);
  
   //var Ln= input[1];
   var Ln = input[1].split(" ");
  
  //var d = 0;
  var a = [];
for (var f = 0; f < n; f++) {
  var r= parseInt(Ln[f], 10);
     //  = d + 
  a[f] = r;
} 
//console.log(NX);
//console.log(n,x);
//console.log(a);
  
  
  var d = 0;
  
  for (var f = 0; f <= n-1;f++){ 
           var c  = d + a[f];
           var d = c;
           if (c > x){break;}
  }
  console.log(f+1);         
  
  
   }
     
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));    
  
 

Measured memory_bytes: 8008
#include<stdio.h>
#include<vector>
#include<bitset>
int main()
{
	int i,j,k,d[1121][15]={0};
	std::bitset<1121>p;
	std::vector<int>v;
	for(i=2;i<1121;++i)if(!p[i])for(v.push_back(i),j=i*i;j<1121;j+=i)p[j]=1;
	for(i=0;i<v.size();++i)
	{
		for(j=13;j>=0;--j)for(k=0;k+v[i]<1121;++k)d[k+v[i]][j+1]+=d[k][j];
		++d[v[i]][1];
	}
	while(scanf("%d%d",&i,&j),i)printf("%d\n",d[i][j]);
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <inttypes.h>

uint64_t isihasu(uint64_t a, uint64_t b) {
	return a <= b ? b - a : a - b;
}

int N;
uint64_t A[271828];

int main(void) {
	int i;
	uint64_t zensum = 0, sum = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu64, &A[i]) != 1) return 1;
		zensum += A[i];
	}
	for (i = 0; i < N; i++) {
		sum += A[i];
		if (sum * 2 == zensum) {
			puts("0");
			return 0;
		} else if (sum * 2 > zensum) {
			uint64_t left = sum - A[i];
			uint64_t right = zensum - sum;
			uint64_t middle = A[i];
			uint64_t c1 = isihasu(left + middle, right);
			uint64_t c2 = isihasu(left, middle + right);
			printf("%" PRIu64 "\n", c1 <= c2 ? c1 : c2);
			return 0;
		}
	}
	puts("error!");
	return 0;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll 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 main(void)
{
    ll n;
    ll a,b;
    cin >> n >> a >> b;

    ll ki = n / (a + b);
    ll ans = ki * a + min(a, (n % (a + b)));
    cout << ans << endl;
    return 0;
}

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

int main() {
int N,K ;
    cin >> N >> K ;
  int A[100];
      for (int i = 0; i < N; ++i) cin >> A[i];
  sort (A,A+N,greater<int>()) ;
  
 int length=0;
  for (int i=0; i<K; i++){
  length +=A[i] ;
  }
  cout << length << endl;  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i,S=0;cin>>N;ll A[N+2];A[0]=0;A[1]=0;
  REP(i,N){cin>>A[i+2];S+=A[i+2];A[i+2]+=A[i];}
  REP(i,N-1)cout<<2*(A[i+1]+A[N+1-i%2]-A[i])-S<<" ";
  cout<<2*(A[i+1]+A[N+1-i%2]-A[i])-S<<endl;
  return 0;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 5e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    int n,m;
    cin >> n >> m;
    int sum = 0;
    vector < int > v(n);
    for( auto &x : v ){
        cin >> x;
        sum += x;
    }
    sort( v.rbegin() , v.rend() );
    for( int i = 0; i < m; i++ ){
        if( v[i] * 4 * m < sum ){
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>

using namespace std;

int main(void){
	int n,m,a,b,c,d,max=0;
	vector <int> h,p,q;
	for(;;){
		scanf("%d%d%d",&n,&m,&a);
		if(n==0&&m==0&&a==0)break;
		h.clear();
		p.clear();
		q.clear();
		max=0;
		for(int i=0;i<m;i++){
			scanf("%d%d%d",&b,&c,&d);
			max=max>b?max:b;
			h.push_back(b);
			p.push_back(c);
			q.push_back(d);
		}
		for(int i=max;i>=0;i--){
			for(int j=0;j<h.size();j++){
				if(i==h[j]){
					if(p[j]==a){
						a=q[j];
						break;
					}else if(q[j]==a){
						a=p[j];
						break;
					}
				}
			}
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  cin >> N;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  long long j = 1;
  long long count =0;
  long long ans =0;
  
  vector<int> jvec(N);
  for(int i = 0; i < N; i++){
    if(j == vec.at(i)){
      //count++;
      // cout << i << endl;
      // cout << j<< endl;
      j++;
    // }else{
    //   // jvec.push_back(j);
    //   // j = 1;
    }
  }

  count = j-1;
  ans = N-count;
  if(count == 0){
    ans = -1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
const int inf = (int)1e8;

int main() {
	int N, M, R;
	cin >> N >> M >> R;
	vector<int> r(R), A(M), B(M), C(M);
	rep(i, R)cin >> r[i];
	rep(i, M)cin >> A[i] >> B[i] >> C[i];

	vector<vector<int>> d(N, vector<int>(N, inf));
	rep(i, N)d[i][i] = 0;
	rep(i, M) { d[A[i] - 1][B[i] - 1] = C[i]; d[B[i] - 1][A[i] - 1] = C[i]; }
	rep(i, N)rep(j, N)rep(k, N) {
		d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
	}

	int ans = inf;

	sort(r.begin(), r.end());
	do {
		int cnt = 0;
		rep(i, R - 1) {
			cnt += d[r[i] - 1][r[i + 1] - 1];
		}
		ans = min(ans, cnt);
	} while (next_permutation(r.begin(), r.end()));

	cout << ans << endl;
}

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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;

signed main(){
  str s;
  cin>>s;
  int n;
  cin>>n;
  vector<str> sv;
  int sl=s.length();
  rep(i,sl){
    for(int j=1;j<sl-i+1;++j){
      sv.pb(s.substr(i,j));
      if(j>5)break;
    }
  }
  sort(all(sv));
  //for(auto i:sv)cout<<i<<" ";cout<<endl;
  n--;
  for(int i=0;i<n;++i){
    if(sv[i]==sv[i+1])n++;
    if(i==sv.size()-1)break;
  }
  cout<<sv[n];
  return 0;
}


Measured memory_bytes: 1916
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;
int a[10];
main(){
	REP(i, 10) cin >> a[i];
	sort(a, a+10);
	printf("%d\n%d\n%d\n", a[9], a[8], a[7]);
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int a, b, c;
  int inc_a, inc_b, inc_c;

  cin >> a >> b >> c;
  inc_a = a;
  inc_b = b;
  inc_c = c;

  int a_count, b_count, c_count;
  a_count = b_count = c_count = 0;

  int before_max = max(a, max(b, c));
  a_count += (before_max - a) / 2;
  b_count += (before_max - b) / 2;
  c_count += (before_max - c ) / 2;
  inc_a += a_count * 2;
  inc_b += b_count * 2;
  inc_c += c_count * 2;

  int after_max = max(inc_a, max(inc_b, inc_c));
  int after_min = min(inc_a, min(inc_b, inc_c));
  int ans = a_count + b_count + c_count;

  if(after_min != after_max) {
    int min_count = 0;
    if(inc_a == after_min) {
      min_count++;
    }
    if(inc_b == after_min) {
      min_count++;
    }
    if(inc_c == after_min) {
      min_count++;
    }
    if(min_count == 1) {
      ans += 2;
    } else if(min_count == 2) {
      ans += 1;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define ll long long int
#define loop(s, n) for(int i=s; i<n; i++)
#define rloop(s, n) for(int j=s-1; i>=n; j--)
using namespace std;

int main() {
    int n;
    cin>>n;
    int h[n], dp[n];
    loop(0,n)
        cin>>h[i];
    dp[0] = 0; dp[1] = abs(h[1] - h[0]);
    loop(2,n)
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4380
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

LL a,b,c,k;

int main()
{
  scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
  if (k % 2 == 0) printf("%lld\n",a-b);
  else printf("%lld\n",b-a);
  return 0;
}











Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,a[3005],dp[3005][3005];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		dp[i][i]=a[i];
	}
	for(int i=n;i>=1;i--)
	{
		for(int j=i+1;j<=n;j++)
		{
			dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
		}
	}
	printf("%lld\n",dp[1][n]);
}

Measured memory_bytes: 69888
#include <bits/stdc++.h>
using namespace std;
int main (){cin.tie(0);
cin.sync_with_stdio(0);

int n,x,a;
long long sum=0;
cin>>x>>n;
for(int i=1;i<=n;i++){
    cin>>a;
  sum+=a;}
  if(sum<=x)
    cout<<x-sum;
  else
    cout<<"-1";}


Measured memory_bytes: 3656
from collections import Counter

S = raw_input()
ok1 =  S[0] == 'A'
c = Counter(S[2:len(S)-1])
ok2 = ('C' in c) and (c['C'] == 1)
c = Counter(S[1:])
ok3 = True
if 'C' in c and c['C'] > 1:
    ok3 = False
for cc in c.keys():
    if cc != 'C' and cc.isupper():
        ok3 = False
print "AC" if ok1 and ok2 and ok3 else "WA"


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;

    if (b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;

    ll N,M;
    ll A,B,C;
    std::string S,T;
    bool F=false;
    ll ans=0;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,26){
        REP(j,15)
        if(i*4+j*7==N){F=true;break;}
    }
    cout<<(F?"Yes":"No")<<endl;
    return 0;
}


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

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

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length();
	int ans=0;
	rep(i,n/2) if(s[i]!=s[n-i-1]) ans++;
	cout<<ans;
	return 0;
}


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

typedef long long ll;

struct Node{
  int k;
  Node *r, *l, *p;
};

set<int> d_s;

Node *T;
Node *NIL;

void insert(int k){

  Node *x = T;
  Node *y = NIL;
  Node *z;
  z = new Node;
  z->k = k;
  z->l = z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->k > x->k){
      x = x->r;
    }else if(z->k < x->k){
      x = x->l;
    }

  }
  z->p = y;

  if(y == NIL){
    T = z;
  }else if(z->k < y->k){
    y->l = z;
  }else if(z->k > y->k){
    y->r = z;
  }
}



void in_print(Node *r){
  if(r == NIL) return;
  set<int>::iterator iti = d_s.find(r->k);
  in_print(r->l);
  cout << " " << r->k;
  in_print(r->r);
}

void pre_print(Node *r){
  if(r == NIL) return;
  cout << " " << r->k;
  pre_print(r->l);
  pre_print(r->r);
}


Node* treeMinimum(Node *x) {
  while(x->l!=NIL) x=x->l;
  return x;
}

Node* treeSuccessor(Node *x) {
  if(x->r!=NIL) return treeMinimum(x->r);
  Node *y=x->p;
  while(y!=NIL && x==y->r) {
    x=y;
    y=y->p;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *y;
  Node *x;

  if(z->l==NIL||z->r==NIL) y=z;
  else y=treeSuccessor(z);

  if(y->l!=NIL) {
    x=y->l;
  }
  else {
    x=y->r;
  }
  if(x!=NIL) x->p=y->p;

  if(y->p==NIL) {
    T=x;
  }
  else {
    if(y==y->p->l) y->p->l=x;
    else y->p->r=x;
  }

  if(y!=z) z->k=y->k;

  delete y;
}

Node* find(Node *u,int k) {
  while(u!=NIL&&k!=u->k) {
    if(k<u->k) u=u->l;
    else u=u->r;

  }
  return u;
}


int main(){

  int n;
  set<int> s;
  cin >> n;

  for(int i = 0; i < n; i++){
    string str;
    int k;
    cin >> str;

    if(str == "insert"){
      cin >> k;
      s.insert(k);
      insert(k);
    }else if(str == "print"){
      in_print(T);
      cout << endl;
      pre_print(T);
      cout << endl;
    }else if(str == "find"){
      cin >> k;
      set<int>::iterator iti = s.find(k);
      if(iti == s.end()) cout << "no" << endl;
      else cout << "yes" << endl;
    }else if(str == "delete"){
      cin >> k;
      set<int>::iterator iti = s.find(k);
      if(iti != s.end()) treeDelete(find(T,k));
      s.erase(k);
    }
  }



}

Measured memory_bytes: 38712
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

vector<long double> v;
int N;

int main(void) {

	cin >> N;
	int tmp;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		v.push_back(tmp);
	}

	sort(v.rbegin(), v.rend());

	long double ans = 0.0;

	for (int i = N - 1; i > 0; i--) {
		long double x;
		x = 0.5L*v[i] + 0.5L*v[i - 1];
		v[i - 1] = x;
	}

	cout <<setprecision(12)<<fixed<< v[0] << endl;
	return 0;
}

Measured memory_bytes: 256
//ABC 176 D--Wizard in Maze 
//ÌâÄ¿µØÖ·£ºhttps://atcoder.jp/contests/abc176/tasks/abc176_d
//Ìâ½âµØÖ·£ºhttps://atcoder.jp/contests/abc176/editorial/79
 
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;

//ËÄ·½Ïò¤Ø¤ÎÒÆ„Ó¥Ù¥¯¥È¥ë
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//¥°¥é¥Õ¤ËÊ¹¤¦¥ä¥Ä
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll h,w,cx,cy,dx,dy;
    cin >> h >> w >> cx >> cy >> dx >> dy;
    cx--;
    cy--;
    dx--;
    dy--;
    string s[h];
    for (ll i=0;i<h;i++)cin >> s[i];
    deque<P> que;

    que.push_back(P(cx,cy));
    bool visited[h][w];
    ll d[h][w];
    for (ll i=0;i<h;i++){
        fill(visited[i],visited[i]+w,false);
        fill(d[i],d[i]+w,INF);
    }
    d[cx][cy]=0;
    visited[cx][cy]=true;

    while(!que.empty()){
        P p=que.front();
        ll X=p.first,Y=p.second;
        if (X==dx and Y==dy){
            cout << d[X][Y] << endl;
            return 0;
        }
        visited[X][Y]=true;
        que.pop_front();
        for (ll i=-2;i<3;i++){
            for (ll j=-2;j<3;j++){
                ll x=X+i,y=Y+j;
                if (x<h and x>=0 and y<w and y>=0 and s[x][y]=='.'){
                    if (visited[x][y])continue;
                    if (abs(i)+abs(j)<2){
                        que.push_front(P(x,y));
                        d[x][y]=d[X][Y];
                        visited[i][j]=true;
                    }else{
                        if (d[X][Y]+1<d[x][y]){
                            d[x][y]=d[X][Y]+1;
                            que.push_back(P(x,y));
                        }
                    }
                }
            }
        }

    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 14480
import sys
from copy import deepcopy
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row_list(N): return [i_list() for _ in range(N)]
sys.setrecursionlimit(10 ** 6)
INF = float('inf')

def main():
    d = i_input()
    c_list = i_list()
    s_list = i_row_list(d)

    output_list = []

    last_list = [0] * 26

    for day in range(1,d+1):
        result = 0
        max_point = -INF
        for i in range(26):
            plus_point = s_list[day-1][i]
            minus_point = 0
            for j in range(26):
                if i == j:
                    continue
                minus_point += c_list[j] * (day - last_list[j])
            sum_point = plus_point - minus_point

            if day != d:
                last_list2 = deepcopy(last_list)
                last_list2[i] = day
                result2 = 0
                max_point2 = -INF
                for k in range(26):
                    plus_point2 = s_list[day][k]
                    minus_point2 = 0
                    for h in range(26):
                        if k == h:
                            continue
                        minus_point2 = c_list[h] * (day+1 - last_list2[h])
                    sum_point2 = plus_point2 - minus_point2

                    if day != d-1:
                        last_list3 = deepcopy(last_list2)
                        last_list3[k] = day + 1
                        result3 = 0
                        max_point3 = -INF
                        for l in range(10):
                            plus_point3 = s_list[day+1][l]
                            minus_point3 = 0
                            for m in range(26):
                                if l == m:
                                    continue
                                minus_point3 = c_list[m] * (day+2 - last_list3[m])
                            sum_point3 = plus_point3 - minus_point3
                        if sum_point3 > max_point3:
                            result3 = l + 1
                            max_point3 = sum_point3
                        last_list3[result3-1] = day + 2
                    else:
                        max_point3 = 0

                    if sum_point2 + max_point3 > max_point2:
                        result2 = k + 1
                        max_point2 = sum_point2 + max_point3
                    last_list2[result2-1] = day + 1
            else:
                max_point2 = 0

            if sum_point + max_point2 > max_point:
                result = i + 1
                max_point = sum_point + max_point2
        output_list.append(result)
        last_list[result-1] = day

    for out in output_list:
        print(out)

if __name__ == '__main__':
    main()


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

int main(){
  int N,Y;
  int ireturn=-1,jreturn=-1,kreturn=-1;
  cin>>N>>Y;
  for(int i=0;i<=N;++i){
    for(int j=0;i+j<=N;++j){
      int k=N-i-j;
      int sum=10000*i+5000*j+1000*k;
      if(sum==Y){
        ireturn=i;
        jreturn=j;
        kreturn=k;
      }
    }
  }
  cout<<ireturn<<" "<<jreturn<<" "<<kreturn<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

#define errp(...) fprintf(stderr, __VA_ARGS__)

const int N = 100010;
int a[N], n, x;

int main () { 
	scanf("%d%d", &n, &x);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int r;
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		r = a[i - 1] + a[i] - x;
		if (r <= 0) continue;
		a[i] -= min(a[i], r);
		ans += min(a[i], r);
		r -= min(a[i], r);
		a[i - 1] -= r;
		ans += r; 
	}
	printf("%lld\n", ans);
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  vector<ll> ans(4);
  ans[0] = a * c;
  ans[1] = a * d;
  ans[2] = b * c;
  ans[3] = b * d;

  sort(ans.rbegin(), ans.rend());

  cout << ans[0] << endl;

}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static int[] max = new int[11];
	static String[] name = new String[11];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		initialize();

		while ((line = br.readLine()) != null) {
			float weight = Float.parseFloat(line);
			System.out.println(classfy(weight));
		}
	}

	static String classfy(float weight) {
		weight = (int) Math.ceil(weight);
		for (int i = 0; i < 11; i++) {
			if (weight <= max[i])
				return name[i];
		}
		return null;
	}

	static void initialize() {
		//
		max[0] = 48;
		max[1] = 51;
		max[2] = 54;
		max[3] = 57;
		max[4] = 60;
		max[5] = 64;
		max[6] = 69;
		max[7] = 75;
		max[8] = 81;
		max[9] = 91;
		max[10] = Integer.MAX_VALUE;
		//
		name[0] = "light fly";
		name[1] = "fly";
		name[2] = "bantam";
		name[3] = "feather";
		name[4] = "light";
		name[5] = "light welter";
		name[6] = "welter";
		name[7] = "light middle";
		name[8] = "middle";
		name[9] = "light heavy";
		name[10] = "heavy";
	}

}

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

using namespace std;

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

int main(){
    int i;
    //入力
    int k,x;
    cin>>k>>x;
    //処理
    //出力
    for(int i=0;i<2000001;i++ ){
        if((i-1000000)>=(x-k+1)&&(i-1000000)<=(x+k-1))cout<<(i-1000000)<<' ';
    }
}

Measured memory_bytes: 256
import numpy as np

h, w, k = list(map(int, input().split()))
data = []
for i in range(h):
    data.append(list(input()))
data = np.array(data)

count = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        target = data.copy()
        row = list(bin(i)[2:].zfill(h))
        for p in range(h):
            if row[p] == '1':
                target[p, :] = '.'
        col = list(bin(j)[2:].zfill(w))
        for q in range(w):
            if col[q] == '1':
                target[:, q] = '.'

        if np.count_nonzero(target == '#') == k:
            count += 1
print(count)

Measured memory_bytes: 26632
from scipy.misc import comb

N = input()
K = int(input())

L = len(N)

if N.count("0") > L - K:
    integer = int(N)
    N = str(integer - integer % 10 - 1)

L = len(N)

if L < K or N[0] == "-":
    print(0)
    quit()

M = ["0"] * L
count = 0
for i in range(L):
    count += bool(int(N[i]))
    M[i] = N[i]
    if count == K:
        M = "".join(M)
        break

index = 0
ans = 0
count = 0
while index < L:
    if int(M[index]):
        count += 1
        n = L - index - 1
        k = K - count + 1
        digit = int(M[index]) - (count != K)
        ans += comb(n, k, exact=True) * 9 ** k + \
               digit * comb(n, k - 1, exact=True) * 9 ** (k - 1)
    index += 1

print(int(ans))

Measured memory_bytes: 20744