akhauriyash/Code-Regression huggingface dataset:
#coding: utf-8
n, k = map(int, input().split())
pkt = list()
for i in range(n):
    pkt.append(int(input()))
lenpkt = len(pkt)

def maxPkt(payload):
    maxPnum = 0
    for i in range(k):
        tempPL = 0
        while tempPL + pkt[maxPnum] <= payload:
            tempPL += pkt[maxPnum]
            maxPnum += 1
            if maxPnum == lenpkt:
                return True
    return False

lft = 0
mid = 0
rgt = 100000 * 10000

while lft < rgt:
    mid = (lft + rgt) // 2
    if maxPkt(mid):
        rgt = mid
    else:
        lft = mid + 1

print(rgt)


Measured memory_bytes: 9560
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

sum = 0
for i in range(N):
    sum += B[A[i]-1]
    if(i != N-1):
        if(A[i]+1 == A[i+1]):
            sum += C[A[i]-1]
print(sum)

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

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >>a[i];
  }
  sort(a,a+n);
  int maxa=a[n-1];
  int maxj=0;
  int tempj=0;
  for(int i=0;i<n-1;i++){
    if(min(a[i],maxa-a[i])>=maxj){
      maxj=a[i];
      tempj=a[i];
    }
  }
  cout<<maxa<<" "<<tempj<<endl;
  return 0;
}


Measured memory_bytes: 3976
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int x[] = new int[5];
    int ans = 0;
    
    for(int i = 0 ; i < 5 ; ++i){
      x[i] = sc.nextInt();
      if(x[i]==0){
        ans = i+1;
      }
    }
    
    System.out.println(ans);
    
  }
}


Measured memory_bytes: 35204
let s = read_line ()
let t = "AKIHABARA"
let rec f u i = if i >= String.length t then u = s
  else if t.[i] = 'A' then f (u ^ "A") (i + 1) || f u (i + 1) else f (u ^ String.make 1 t.[i]) (i + 1)
let _ = print_endline @@ if f "" 0 then "YES" else "NO"

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

set<string> st;

string s;

void solve(){
	int k;
	cin >> s >> k;
	REP(i, 0, (int)s.length()){
		string tmp = "";
		for(int j = i, k = 1; j < (int)s.length() && k <= 5; j++, k++){
			tmp = tmp + s[j];
			st.insert(tmp);
		}
	}
	FA(it, st){
		k--;
		if (k == 0){
			cout << *it << endl;
			break;
		}
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;

//?§??????°??????????????°?????¶????????????????????°
int n,m,h,k;

//???????§???????????§????1day???????????°
int s,t,p;

typedef pair<int,int> P;
typedef pair<P,int> PP;
struct edge{
	int to,cost,time,corp;
	
	edge(int to_,int cost_,int time_,int corp_){
		to=to_; cost=cost_; time=time_; corp=corp_;
	}
	
};
vector<edge> G[100];

const int BIT=1<<8;

// i????????????????????????????????????
int pass_corps[BIT];

// pass_cost[bit] bit?????¨?????????????????????????????????
int pass_cost[BIT];

//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
int corps_cost[BIT];

// d[time][pos]
int d[25][100];


const int INF=1e8;

inline int solve(int use){
	

	for(int i=0;i<=h;i++){
		for(int j=0;j<n;j++) d[i][j]=INF;
	}
	
	d[0][s]=corps_cost[use];
	
	priority_queue<PP,vector<PP>,greater<PP> > q;

	// cost,time,pos
	q.push(PP(P(corps_cost[use],0),s));
	while(!q.empty()){
		
		PP pp=q.top(); q.pop();
		
		int cost=pp.first.first,time=pp.first.second,pos=pp.second;
		
		//printf("cost %d, time %d, pos %d\n",cost,time,pos);
		
		if(pos==t){
			while(!q.empty()) q.pop();
			return cost;
		}
		if(d[time][pos]<cost) continue;
		
		for(int i=0;i<G[pos].size();i++){
			edge e=G[pos][i];
			int to=e.to,ncost=cost+e.cost,nt=time+e.time,ncorp=e.corp;
			
			//printf("to %d, ncost %d, nt %d ncorp %d\n",to,ncost,nt,ncorp);
			
			if(nt>h) continue;
			
			if(use&(1<<ncorp)) ncost=cost;
			if(ncost<d[nt][to]){
				d[nt][to]=ncost;
				q.push(PP(P(ncost,nt),to));
			}
			
		}
		
	}
	
	return INF;
	
}

int main(){
	
	while(scanf("%d %d %d %d",&n,&m,&h,&k),n){
		
		for(int i=0;i<n;i++) G[i].clear();
		for(int i=0;i<(1<<k);i++){
			pass_corps[i]=0;
			pass_cost[i]=corps_cost[i]=INF;
		}
		for(int i=0;i<m;i++){
			int a,b,c,h,r;
			scanf("%d %d %d %d %d",&a,&b,&c,&h,&r);
			a--; b--; r--;
			
			G[a].push_back(edge(b,c,h,r));
			G[b].push_back(edge(a,c,h,r));
		}
		
		scanf("%d %d %d",&s,&t,&p);
		s--; t--;
		
		int l,d,corp,corps;
		for(int i=0;i<p;i++){
			
			scanf("%d %d",&l,&d);
			
			corps=0;
			while(l--){
				scanf("%d",&corp);
				corp--;
				corps|=(1<<corp);
			}
			
			pass_corps[i]=corps;
			pass_cost[pass_corps[i]]=d;
		}
				
		//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
		corps_cost[0]=0;
		for(int i=0;i<(1<<k);i++){
			if(corps_cost[i]==INF) continue;
			for(int j=0;j<p;j++){
				corps_cost[i|pass_corps[j]]=min(corps_cost[i|pass_corps[j]],corps_cost[i]+pass_cost[pass_corps[j]]);
			}
		}
		
		int res=INF;
		for(int use=0;use<(1<<k);use++){
			if(corps_cost[use]==INF) continue;
			res=min(res,solve(use));
		}
		if(res==INF) res=-1;
		cout<<res<<endl;	
	}
}

Measured memory_bytes: 1400
n = int(input())
ans = []
for i in range(n):
  ans.append(int(input()))
nm = 0
ans.sort()
for i in ans:
  if i %10 != 0:
    nm = i
    break
if sum(ans) % 10 != 0:
  print(sum(ans))
elif nm !=0:
  print(sum(ans)-i)
else:
  print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
vector<string> zip(vector<string> vec){
    vector<string> res;
    REP(i,vec.size()){
        if(vec[i]!=string(vec[0].size(),'.')){
            res.push_back(vec[i]);
        }
    }
    return res;
}
vector<string> rotate(vector<string> vec){
    vector<string> res(vec[0].size());
    REP(i,vec.size()){
        REP(j,vec[0].size()){
            res[j]+=vec[i][j];
        }
    }
    return res;
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<string> vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    vec=zip(vec);
    vec=rotate(vec);
    vec=zip(vec);
    vec=rotate(vec);
    vec=rotate(vec);
    vec=rotate(vec);
    REP(i,vec.size()){
        cout<<vec[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	long long N;
	cin >> N;

	vector<long long> t(5, 0);
	for (int i = 0; i < t.size(); i++) {
		cin >> t[i];
	}

	auto itr_min = min_element(t.begin(), t.end());
	long long t_min = *min_element(t.begin(), t.end());

	long long ans = N / t_min;

	if (N % t_min > 0) {
		ans += 1;
	}

	ans += distance(t.begin(), itr_min);
	ans += distance(itr_min, t.end()) - 1;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W

S = set()

for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
    R[h-1] += 1
    C[w-1] += 1

r = max(R)
c = max(C)

HL = [i for i in range(H) if R[i] == r]
WL = [i for i in range(W) if C[i] == c]

for h in HL:
    for w in WL:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)

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

int main()
{
  int a, b;
  cin >> a >> b;
  if(a + b == 15)
  {
    cout << "+" << endl;
  }
  else if(a * b == 15)
  {
    cout << "*" << endl;
  }
  else
  {
    cout << "x" << endl;
  }
}

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

int main()
{
  int a,b,c,d,e,f;
  cin >> a;
  cin >> b;
  c=(a+b);
  d=((c+1)/2);
  e=(c%2);
  f=(c/2);
  if (e==0)
  {
    cout << f<< endl;
  }
  else 
  {
    cout << d<< endl;
  }
  return 0;
 }

Measured memory_bytes: 3560
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 998244353;

ll dp[6060];

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


	int A, B, C, D;
	cin >> A >> B >> C >> D;

	C -= A;
	D -= B;

	dp[C + 2] = 1;
	for (int i = C + 2; i < C + D + 2; i++) dp[i + 1] = dp[i] * A % mod;

	for (int i = A; i < A + C; i++) {
		auto t = dp + C - i + A - B + 2;

		for (int j = B; j <= B + D; j++) {
			t[j - 1] = t[j - 2] * (i + 1) + t[j] * j - t[j - 1] * i * (j - 1);
			t[j - 1] %= mod;
		}
	}
	co((dp[D + 2] + mod) % mod);

	Would you please return 0;
}

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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, begin, end) for(int (i) = (begin); (i) < (end); (i)++)

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int x = 0;
    for(auto c: s) x += (c == 'p');
    cout << n/2 - x << endl;
}


Measured memory_bytes: 512
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int query; cin >> query;
    if(query == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int A, B; cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
int p,l,r;
};
struct Node T[MAX];
int n;

void preParse(int s){
if(s==NIL)
return;
printf(" %d",s);
preParse(T[s].l);
preParse(T[s].r);
}

void inParse(int s){
if(s==NIL)
return;
inParse(T[s].l);
printf(" %d",s);
inParse(T[s].r);
}

void postParse(int s){
if(s==NIL)
return;
postParse(T[s].l);
postParse(T[s].r);
printf(" %d",s);
}


int main(){
int i,v,l,r,root;
scanf("%d",&n);
for(i=0;i<n;i++){
T[i].p=NIL;
}

for(i=0;i<n;i++){
scanf("%d %d %d",&v,&l,&r);
T[v].l=l;
T[v].r=r;
if(l!=NIL) T[l].p = v;
if(r!=NIL) T[r].p = v;
}

for(i=0;i<n;i++)
if(T[i].p==NIL) 
root = i;
printf("Preorder\n");
preParse(root);
printf("\n");
printf("Inorder\n");
inParse(root);
printf("\n");
printf("Postorder\n");
postParse(root);
printf("\n");
return 0;
}

Measured memory_bytes: 1856
a,b=map(int,input().split())
s=input()
f=1
for i in range(a):
   if s[i]=='-':
      f=0
if s[a]!='-':
   f=0
for j in range(b):
   if s[a+1+j]=='-':
      f=0
if f:
   print('Yes')
else:
   print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)


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

    int n,k; cin >> n >> k;
    vector<ll> a(n+1, 0);
    for(int i=1; i<=n; ++i) cin >> a[i];

    vector<vector<ll>> dp(110, vector<ll>(100005, 0));
    vector<ll> cum(100005, 0);

    dp[0][0] = 1;
    for(int i=1; i<=n; ++i){
        cum[0] = 0;
        for(int j=1; j<=k+1; ++j) cum[j] = (cum[j-1]+dp[i-1][j-1])%mod;
        for(int j=0; j<=k; ++j) dp[i][j] = (cum[j+1]-cum[max(0LL, j-a[i])]+mod)%mod;
    }

    cout << dp[n][k] << endl;

    return 0;
}

Measured memory_bytes: 87424
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
 
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 
 
using namespace std;
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(15);
    solve();  	
}

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	int ans = 0;
	for (int i = -1; i < n; ++i) {
		for (int j = n; j > i; --j) {
			vector<int> tmp;
			for (int k = 0; k <= i; ++k) {
				tmp.push_back(a[k]);
			}
			for (int k = j; k < n; ++k) {
				tmp.push_back(a[k]);
			}
			int cur = len(tmp), sum = accumulate(tmp.begin(), tmp.end(), 0);
			sort(tmp.begin(), tmp.end());
			if (cur <= m) {
				ans = max(sum, ans);
			}
			for (int k = 0; k < len(tmp); ++k) {
				sum -= tmp[k];
				cur++;
				if (cur <= m) {
					ans = max(ans, sum);
				}
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
def factorial(n):
    if (n==0) or (n==1):
        return 1
    ret = 1
    for i in range(2, n+1):
        ret *= i
    return ret
def combination(n, k):
    return factorial(n)//factorial(k)//factorial(n-k)
sys.setrecursionlimit(1000000)
INF = float("inf")
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, W = LI()
wv = LIR(N)
V = sum(list(map(lambda x: x[1], wv)))

dp = [[INF]*(V+1) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    w, v = wv[i]
    for j in range(V+1):
        if (j < v):
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i][j-v] + w)

for i in range(V+1)[::-1]:
    if (dp[N][i] <= W):
        print(i)
        break

Measured memory_bytes: 310048
def solve():
    from collections import deque
    from sys import stdin
    f_i = stdin
    
    H, W = map(int, f_i.readline().split())
    
    grid = ['W'] * (W + 2)
    for i in range(H):
        grid += ['W'] + list(f_i.readline().rstrip()) + ['W']
    grid += ['W'] * (W + 2)
    
    q = deque()
    for i, cell in enumerate(grid):
        if cell == '#':
            q.append((i, 0)) # (pos, operation count)
    move = (1, -1, W + 2, -W - 2)
    
    while q:
        pos, count = q.popleft()
        for mv in move:
            next_pos = pos + mv
            if grid[next_pos] == '.':
                grid[next_pos] = '#'
                q.append((next_pos, count + 1))
    
    print(count)
    
solve()

Measured memory_bytes: 114760
#include<iostream>
#include<math.h>

using namespace std;

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

int main(){
    int d;
    cin >> d;
    REP(i, d){
        int m, n;
        cin >> m >> n;

        int count = 0;
        for(int j = -sqrt(m*m+n*n); j<=sqrt(m*m+n*n); j++){
            for(int k = -sqrt(m*m+n*n); k<=sqrt(m*m+n*n); k++){
                if(j*j+k*k>0){
                    if((j*m+k*n)%(j*j+k*k)==0 && (j*n-k*m)%(j*j+k*k)==0){
                        count += 1;
                    }
                }
            }
        }

        if(count == 8){
            cout << 'P' << endl;
        } else {
            cout << 'C' << endl;
        }
    }
}

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

int main() {
  string S;
  int K,i,l;
  cin >> K ;
  cin >> S ;
  if(S.size() <= K) cout << S ;
  else{
    for(i=0; i<K; i++){
      cout << S.at(i);
    }
    cout << "..." ;
  }
}

Measured memory_bytes: 3572
import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())

    uf = UnionFindTree(N)
    for _ in range(M):
        x,y,z=map(int, input().split())
        uf.union(x-1,y-1)
    c=set([uf.find(i) for i in range(N)])
    print(len(c))


class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x

    def same(self, x, y): return self.find(x) == self.find(y)
    def size(self, x): return -self.parent[self.find(x)]


if __name__ == '__main__':
    main()

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

int main() {
	int n, q;
	cin >> n >> q;
	vector<tuple<int, int, int>> events; // time, coord (res), in or out
	rep(i, n) {
		int s, t, x;
		cin >> s >> t >> x;
		events.emplace_back(s - x, x, 1);
		events.emplace_back(t - x, x, 0);
	}
	vector<P> queries(q);
	rep(i, q) {
		cin >> queries[i].first;
		queries[i].second = i;
	}
	sort(events.begin(), events.end());
	sort(queries.begin(), queries.end());
	set<int> s;
	int now = 0;
	vector<int> ans(q);
	for(auto p: queries) {
		int i, d;
		tie(d, i) = p;
		while(now < events.size() && get<0>(events[now]) <= d) {
			int t, x, op;
			tie(t, x, op) = events[now++];
			if (op == 1) s.insert(x);
			else s.erase(x);
		}
		ans[i] = s.empty() ? -1 : *s.begin();
	}
	rep(i, q) cout << ans[i] << endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    ll sum = 0;
    rep(i, N) sum += a[i];
    set<ll> candidates;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            candidates.insert(i);
            candidates.insert(sum / i);
        }
    }
    ll ans = 1;
    for (ll x : candidates) {
        ll need;
        { // calc need
            vector<ll> r(N);
            rep(i, N) r[i] = a[i] % x;
            sort(r.begin(), r.end());
            ll B = 0; // 正にする回数
            rep(i, N) B += x - r[i];
            ll A = 0; // 負にする回数
            need = 1e18;
            rep(i, N) {
                // 正負の区切り位置を全部試す
                A += r[i];
                B -= x - r[i];
                if(A == B) need = min(need, max(A, B));
            }
        }
        if (need <= K) ans = max(ans, x);
    }
    cout << ans << endl;
}


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

#include<stack>

using namespace std;


int main() {

	int N;
	cin >> N;

	vector<int> vBuyValue(N, 0);
	vector<int> vSellValue(N, 0);

	for (int i = 0; i < N; i++)
	{
		cin >> vSellValue[i];
	}
	for (int i = 0; i < N; i++)
	{
		cin >> vBuyValue[i];
	}

	vector<int> vDiff(N, 0);
	for (int i = 0; i < N; i++)
	{
		vDiff[i] = vSellValue[i] - vBuyValue[i];
	}
	sort(vDiff.begin(), vDiff.end());

	int retValue = 0;
	for (int i = 0; i < N; i++)
	{
		if (vDiff[i] > 0)
		{
			retValue += vDiff[i];
		}
	}

	cout << retValue << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	int n,k;
	cin>>n>>k;
	int ans=0;
	for(int i=0;i<n;i++){
		int b;
		cin>>b;
		ans+=min(b,k-b);
	}
	cout<<ans*2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N, K; cin >> N >> K;
    if(N%K==0) {
        print(0);
    } else {
        print(1);
    }
    
    return 0;
}

Measured memory_bytes: 256
// Aizu 2271: KUPC
// 2017.9.22 bal4u@uu

#include <stdio.h>

int f[128];
int k[4] = { 'K','U','P','C' };

int main()
{
	int i, ans;
	char s[303], *p;

	scanf("%s", s), p = s;
	while (*p)  f[*p++]++;
	ans = 301; for (i = 0; i < 4; i++) if (f[k[i]] < ans) ans = f[k[i]];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1800
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9
 
 struct Puzzle {
  int f[N2];
  int space;
  string path;
 
  bool operator < (const Puzzle &p) const {
    for(int i=0;i<N2;i++) {
      if(f[i]==p.f[i])continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};
 
static const char dir[4] = {'u','l','d','r'};
static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
 
bool isTarget(Puzzle p) {
  for(int i=0;i<N2;i++)
  if(p.f[i] != (i+1)) return false;
  return true;
}
 
string bfs(Puzzle s ) {
queue<Puzzle> Q;
map<Puzzle,bool> V;
Puzzle u,v;
s.path = "";
Q.push(s);
V[s] = true;
 
while(!Q.empty()) {
  u = Q.front();Q.pop();
  if(isTarget(u)) return u.path;
  int sx = u.space / N;
  int sy = u.space % N;
  for(int r = 0;r<4 ; r++) {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx < 0 || ty < 0|| tx>=N || ty >= N) continue;
    v = u;
    swap(v.f[u.space], v.f[tx *N+ty]);
    v.space = tx * N + ty;
    if(!V[v]) {
      V[v] = true;
      v.path  += dir[r];
      Q.push(v);
    }
  }
}
return "unsolvable";
}
 
int main() {
  Puzzle in;
 
  for(int i=0;i<N2;i++) {
    cin >> in.f[i];
    if(in.f[i]==0) {
      in.f[i]=N2;
      in.space = i;
    }
  }
 
  string ans = bfs(in);
  cout << ans.size()<<endl;
 
  return 0;
}

Measured memory_bytes: 30648
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll L; std::cin >> L;
  double a = L/3.;
  std::cout << std::fixed << std::setprecision(15) << a*a*a << std::endl;
  return 0;
}



Measured memory_bytes: 256
main(c,t){double*p=t,v;for(;~scanf("%s%c",&t,&c);c&2&&printf("%f\n",v))v=t&4112?*++p=atoi(&t):(*--p=t&1?t&2?t&4?*p/v:*p+v:*p-v:*p*v);}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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 (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    set<ll> A;
    bool fail = false;
    REP(i,N){
        ll a;
        cin >> a;
        if(A.find(a) != A.end())
            fail = true;
        A.insert(a);
    }

    if(fail)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


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

#define fastIO                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);                   \
	cout.tie(0);
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef long double ld;

unsigned long long power(unsigned long long x, unsigned long long y) 
{ 
    unsigned long long res = 1;
	x = x % MOD;
    while (y > 0) 
    { 
        if (y & 1) res = (res * x) % MOD;
        y = y >> 1;
        x = (x * x) % MOD;
    } 
    return res;
}

int main()
{
	fastIO;
	unsigned long long int N;
	cin >> N;
	cout << (((power(10ULL, N) + power(8ULL, N)) % MOD) - ((2 * power(9ULL, N)) % MOD) + MOD) % MOD;
}

Measured memory_bytes: 3504
// In the name of Allah the Lord of the Worlds.

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

typedef long long ll;

vector<pair<int , int> > edges[100005];
int color[100005];

void dfs(int u , int dis = 0 , int par = -1)
{
    color[u] = dis;
    for(auto v:edges[u]){
        if(par!=v.first){
            dfs(v.first , (v.second+dis)%2 , u);
        }
    }
}

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

    int n;
    cin >> n;
    for(int i=0;i<n-1;i++){
        int in1 , in2 , in3;
        cin >> in1 >> in2 >> in3;
        edges[in1].push_back({in2 , in3});
        edges[in2].push_back({in1 , in3});
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        cout << color[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 8448
#coding:utf-8

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

A_lis = sorted(A)
c = 1
score = 0

for i in range(N):
    n = A_lis.pop()
    if c%2 == 0:
        score -= n
    elif c%2 == 1:
        score += n
    c += 1

print(score)


Measured memory_bytes: 3060
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

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

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }
ll power(ll n , ll k) { if(k == 0) return 1 ; if(k&1) return n*sqr(power(n,k/2)) ; else return sqr(power(n,k/2)); }

const   int  N   =   2e6+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;
const   int dx[] =   {+1,+2,+2,+1,-1,-2,-2,-1};
const   int dy[] =   {-2,-1,+1,+2,+2,+1,-1,-2};

ll a[N];

int main() {//ikarus_101

    ll n,m,i,j,k,x;

    ll s = 0;
    a[0] = 0;
    cin>>n>>k;
    rep1(i,n)
    {
        cin>>x;
        s += x;
        a[i]=s;
    }

    for(i=k+1;i<=n;i++)
    {
        ll lft = a[i-1] - a[i-k-1];
        ll rgt = a[i] - a[i-k];
        if(rgt > lft) puts("Yes");
        else puts("No");
    }










    return 0;
}


Measured memory_bytes: 5108
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

from collections import deque

def bfs(graph, queue, dist, prev):
    while queue:
        current = queue.popleft()

        for _next in graph[current]:
            if dist[_next] != -1:
                continue
            else:
                dist[_next] = dist[current] + 1
                prev[_next] = current
                queue.append(_next)

queue = deque([1])
dist = [0] + [-1] * n
prev = [0] + [-1] * n
dist[1] = 0
bfs(graph, queue, dist, prev)

if -1 in dist:
    print('No')
else:
    print('Yes')
    for v in prev[2:]:
        print(v)


Measured memory_bytes: 95392
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)

struct Point {
  int y, x, index;
  Point(): y(0), x(0), index(0) {}
  Point(int y, int x, int index): y(y), x(x), index(index) {}
};

struct LessY {
  bool operator()(const Point& lhs, const Point& rhs) const { return lhs.y < rhs.y; }
};

struct LessX {
  bool operator()(const Point& lhs, const Point& rhs) const { return lhs.x < rhs.x; }
};

vector<Point> slimes, ysorted, xsorted;
vector<bool> visit;

int dfs(int i) {
  if (visit[i]) { return 0; }
  visit[i] = true;

  int ret = 1;
  auto range1 = equal_range(ALL(ysorted), Point(slimes[i].y, 0, 0), LessY());
  for (auto it = range1.first; it != range1.second; ++it) { ret += dfs(it->index); }
  auto range2 = equal_range(ALL(xsorted), Point(0, slimes[i].x, 0), LessX());
  for (auto it = range2.first; it != range2.second; ++it) { ret += dfs(it->index); }
  return ret;
}

int main() {
  int N, W, H;
  while (scanf("%d%d%d", &N, &W, &H) != EOF) {
    slimes.resize(N);
    ysorted.resize(N);
    xsorted.resize(N);
    visit.assign(N, false);

    int wallside = 0;
    REP(i, N) {
      int y, x; scanf("%d%d", &x, &y);
      slimes[i] = Point(y, x, i);
      ysorted[i] = xsorted[i] = slimes[i];
      if (y == 1 || y == H || x == 1 || x == W) { wallside = 1; }
    }
    sort(ALL(ysorted), LessY());
    sort(ALL(xsorted), LessX());

    int ans = 0, n_cc = 0;
    REP(i, N) {
      if (!visit[i]) {
        ans += dfs(i)-1;
        n_cc += 1;
      }
    }
    if (n_cc > 1) { ans += 2*n_cc - wallside - 1; }

    printf("%d\n", ans);
  }
}

Measured memory_bytes: 2588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll x;cin>>x;
  ll ra,rb;
  for(ll a=-119;a<=120;a++)
  {
    for(ll b=-119;b<=120;b++)
    {
      ll ta=a*a*a*a*a,tb=b*b*b*b*b;
      if(ta-tb==x)
      {
        ra=a;
        rb=b;
        goto label;
      }
    }
  }
  label:
  cout<<ra<<" "<<rb<<endl;
}

Measured memory_bytes: 3644
///Bismillahir Rahmanir Rahim
///ALLAH HU AKBAR
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i;
    for(i=0;i<s.size();i++)
    {
        if(s[i]+n<=90)
            s[i]+=n;
        else
        {
           int a= s[i]+n-90;
           s[i]=64+a;
        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
from math import gcd


def eratosthenes(n):
    prime = []
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if n <= p ** 2:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return data


def factorize(N):  # 素因数分解
    for p in prime_list:
        if p * p > N:
            break
        if N % p == 0 and (p in num):
            print('setwise coprime')
            exit()
        while N % p == 0:
            N //= p
            num.add(p)
    if N > 1:
        if N in num:
            print('setwise coprime')
            exit()
        num.add(N)


n = int(input())
a = list(map(int, input().split()))

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print('not coprime')
    exit()

prime_list = eratosthenes(10 ** 6)
num = set()
for ai in a:
    factorize(ai)
else:
    print('pairwise coprime')


Measured memory_bytes: 250504
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;

ll l[100005];
int n;
ll k;
ll delta[40];

ll dp[41][2];
bool seen[41][2];

ll get(int bit, bool pinned) {
	if(bit < 0) return 0;
	if(seen[bit][pinned]) return dp[bit][pinned];
	seen[bit][pinned] = true;
	dp[bit][pinned] = get(bit-1, pinned && (k&(1LL<<bit)) == 0);
	if(!pinned || (k&(1LL<<bit))) {
		dp[bit][pinned] = max(dp[bit][pinned], delta[bit] + get(bit-1, pinned));
	}
	return dp[bit][pinned];
}

void solve() {
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> l[i];
	}
	ll baseSum = 0;
	for(int i = 0; i < n; i++) {
		baseSum += l[i];
		for(int d = 0; d < 40; d++) {
			delta[d] += (l[i] ^ (1LL << d));
			delta[d] -= l[i];
		}
	}
	cout << baseSum + get(40, true) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
	/*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
	*/
	solve();
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int n;
    cin >> n;
    lli a[300005];
    rep(i, 3 * n) cin >> a[i];
    sort(a, a + 3 * n);
    //小さいn人を犠牲にする
    //残り2*nで小さい方の和を最大化する
    lli ans = 0;
    rep(i, n)
    {
        ans += a[3 * n - 2 * i - 2];
        //        cout << a[3 * n - 2 * i - 2] << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<int>())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    vector<int> v(5);
    int min_digit = 10;
    int min_id = 0;
    for (int i = 0; i < 5; i++) {
        cin >> v[i];
        int tmp = v[i] % 10;
        if(tmp != 0 && tmp < min_digit){
            min_digit = tmp;
            min_id = i;
        }
    }

    int ans = 0;
    REP(i, 5){
        if(i != min_id && v[i] % 10 != 0){
            ans += v[i] + (10 - v[i] % 10);
        }else{
            ans += v[i];
        }
    }
    pr(ans);
}

Measured memory_bytes: 256
n,k = [int(i) for i in input().split()]
td = [[int(i) for i in input().split()] for _ in range(n)]

###dが大きい順にソート
td.sort(key = lambda x: x[1],reverse=True)

###各tでdが最大のものを格納
fix_eated_d=[]
###各tでdが最大でないものを格納。tの種類を増やす際の削除候補
change_eated_d=[]

eated_t = set()
d_point = 0

###まずdを最大化
for t,d in td[:k]:
  
  ###すでにtが選ばれているなら最大のdではないのでchangeへ
  if t in eated_t:
    change_eated_d.append(d)
    
  ###まだtが選ばれていないなら最大のdだからfixへ
  else:
    fix_eated_d.append(d)
    eated_t.add(t)
    
  d_point += d
  
point = len(eated_t)**2 + d_point

###tの種類を増やす
for t,d in td[k:]:
  ###削除候補がなくなれば終了
  if not change_eated_d:
    break
  
  ###すでにtが選ばれているならskip
  if t in eated_t:
    continue
    
  ###まだtが選ばれていないなら追加、change中dが最小のものを削除
  eated_t.add(t)
  d_point += d - change_eated_d.pop()
  point = max(point, len(eated_t)**2 + d_point)
  
print(point)




Measured memory_bytes: 24716
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

n = gi #10**5
as = gsmi #10**9

desc as
cnt = as.size - 2
ans = as.shift
as.each do |a|
  2.times do
    break if cnt==0
    ans += a
    cnt -= 1
  end
end

puts ans


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

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 7654321
#define IINF 87654321987654321LL
#define MAXV 200500

ll mod = 1e9 + 7;


int dp[301][301][301];
string s;
int N,K;

int solve(int l, int r, int k){

	if( l == r ) return 1;
	if( l > r ) return 0;

	int& res = dp[l][r][k];
	if( res != -1 ) return res;
	res = 0;
	if( s[l] == s[r] ){
		res = max(res, 2 + solve(l+1,r-1,k) );
	}
	else{
		if( k > 0 ){
			res = max(res, 2 + solve(l+1,r-1,k-1) );
		}
		res = max(res, solve(l+1,r,k) );
		res = max(res, solve(l,r-1,k) );
	}


	return res;
}	

int main(){
	memset(dp,-1,sizeof dp);
	cin >> s >> K;
	N = sz(s);

	cout << solve(0,N-1,K);

}

Measured memory_bytes: 106880
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	var n int
	fmt.Scan(&n)
	xs, ys, hs := make([]int, n), make([]int, n), make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i], &ys[i], &hs[i])
	}

	for i := 0; i <= 100; i++ {
		for j := 0; j <= 100; j++ {
			var H int
			for k := range xs {
				if hs[k] > 0 {
					H = hs[k] + abs(i-xs[k]) + abs(j-ys[k])
					break
				}
			}
			for k := range xs {
				if newH := max(H-abs(i-xs[k])-abs(j-ys[k]), 0); hs[k] != newH {
					break
				} else if k == len(xs)-1 {
					fmt.Println(i, j, H)
					return
				}
			}
		}
	}
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,S;
  cin>>N>>S;
  ll A[N];
  REP(i,N) cin>>A[i];
  
  ll DP[N+1][S+1];
  REP(i,N+1){
    REP(j,S+1){
      DP[i][j]=0;
    }
  }
  DP[0][0]=1;
  
  REP(i,N){
    REP(j,S+1){
      DP[i+1][j]+=DP[i][j]*2;
      DP[i+1][j]%=MMOD;
      if(j+A[i]<=S){
        DP[i+1][j+A[i]]+=DP[i][j];
        DP[i+1][j+A[i]]%=MMOD;
      }
    }
  }
  
  co(DP[N][S]);
  return 0;
}

Measured memory_bytes: 73904
#include"iostream"
#include<math.h>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
 
    
        if ((a + b) % 2 == 0) {
            cout << (b + a) / 2 << endl;
        }
        else {
            cout << "IMPOSSIBLE" << endl;
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
    
ll dp[N+5];
int main(){
	int n,k;
    cin>>n>>k;
    vector<int> h(n);
    REP(i,n){
        cin>>h.at(i);
    }
     REP(i,N+5){
        dp[i]=100000000000000000;
    }
    dp[0]=0;
    REP(i,n){
        for(int j=1;j<=k;j++){
            if((i+j)>=n) break;
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    OUT(dp[n-1]);
	return 0;
}

Measured memory_bytes: 1408