akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_039
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            string s = Read();
            long k = ReadLong();

            List<long> blocks = new List<long>();
            blocks.Add(1);
            for(int i = 1; i < s.Length; i++)
            {
                if (s[i] == s[i - 1])
                {
                    blocks[blocks.Count - 1]++;
                }
                else
                {
                    blocks.Add(1);
                }
            }

            if (blocks.Count == 1)
            {
                WriteLine(blocks[0] * k / 2);
            }
            else if (s[s.Length - 1] == s[0])
            {
                long cnt = 0;
                cnt += blocks[0] / 2;
                for (int i = 1; i < blocks.Count - 1; i++) cnt += blocks[i] / 2 * k;
                cnt += (blocks[0] + blocks[blocks.Count - 1])/2 * (k - 1);
                cnt += blocks[blocks.Count - 1] / 2;
                WriteLine(cnt);
            }
            else
            {
                long cnt = 0;
                for (int i = 0; i < blocks.Count; i++) cnt += blocks[i] / 2 * k;
                WriteLine(cnt);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
import sys,math
price,amount=[],[]
for line in sys.stdin.readlines():
    line=map(int,line.strip().split(","))
    price.append(line[0])
    amount.append(line[1])
tp=sum([price[i]*amount[i] for i in xrange(len(price))])
ta=sum(amount)
print tp
print int(math.ceil((ta+0.0)/(len(amount)+0.0)))

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

int main(){
    int N;
    cin >> N;
    vector<int> h(N, 0);
    for(size_t i = 0; i < N; i++) {
        cin >> h[i];
    }

    int max=-1, min=0;
    for(size_t i = 0; i < N; i++){ 
        if (h[i] > max)
            max = h[i];
    }
    int ret = 0;
    while(min < max){
        bool last_h_is_max = false;
        for (auto & a: h){
            if (a == max){
                --a;
                if (!last_h_is_max)
                    ++ret;
                last_h_is_max = true;
            }
            else
                last_h_is_max = false;
        }
        --max;
    }
    cout << ret << endl;
    return 0;
}

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

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

const int N = 1e5 + 5, M = N << 1;

int n, m, ecnt, nxt[M], adj[N], go[M], dep[N], fa[N];
bool vis[N], res[N];
std::vector<int> son[N], out[N];

void add_edge(int u, int v)
{
	nxt[++ecnt] = adj[u]; adj[u] = ecnt; go[ecnt] = v;
	nxt[++ecnt] = adj[v]; adj[v] = ecnt; go[ecnt] = u;
}

void dfs(int u)
{
	vis[u] = 1;
	for (int e = adj[u], v = go[e]; e; e = nxt[e], v = go[e])
		if (!vis[v]) dep[v] = dep[fa[v] = u] + 1, dfs(v), son[u].push_back(v);
		else if (dep[v] < dep[u] && v != fa[u]) out[u].push_back(v);
}

void jiejuediao(int u)
{
	for (int i = 0; i < son[u].size(); i++)
		jiejuediao(son[u][i]);
	if (fa[u])
	{
		if (res[u]) res[u] ^= 1, printf("%d %d\n", u, fa[u]);
		else res[fa[u]] ^= 1, printf("%d %d\n", fa[u], u);
	}
	for (int i = 0; i < out[u].size(); i++)
		res[out[u][i]] ^= 1, printf("%d %d\n", out[u][i], u);
}

int main()
{
	int x, y;
	read(n); read(m); if (m & 1) return puts("-1"), 0;
	while (m--) read(x), read(y), add_edge(x, y);
	dfs(1); jiejuediao(1);
	return 0;
}

Measured memory_bytes: 25424
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e6;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2);
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
bool check(int x){

}
int binary(int x,int y){
    int s=x,e=y,mid;
    while(s<e){
        mid=ceil((s+e)/2.0);
        if(check(mid))
            s=mid;
        else
            e=mid-1;
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}



in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        int n,m;
        cin>>n>>m;
        cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    }
    RETURN;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){

  int n, target;
  ll k;
  cin >> n >> k;
  vector<int> transfar_target(n), route(n);
  vector<bool> loop_check(n,false);
  rep(i,n){
    cin >> target;
    target--;
    transfar_target[i] = target;
  }
  int loop_start, loop_end;
  int tp_count = 0;
  int pre = 0;
  int now = 0;
  while(true){
    route[tp_count] = now;
    loop_check[now] = true;
      pre = now;
      now = transfar_target[now];
    if (!loop_check[now]) {
      tp_count++;
    } else {
      loop_start = now;
      loop_end = pre;
      break;
    }
  }
  int pre_tp_count = 0;
  int loop_tp_count = 0;
  auto loop_start_itr = find(route.begin(), route.end(), loop_start);
  for(auto itr=route.begin(); itr != loop_start_itr; itr++){
    pre_tp_count++;
  }
  loop_tp_count = tp_count - pre_tp_count + 1;
  int ans;
  if (k < pre_tp_count) {
    ans = route[k];
  } else {
    k -= pre_tp_count;
    k = k % loop_tp_count;
    ans = route[pre_tp_count + k];
  }

  ans++;
  cout << ans << endl;


  return 0;
}

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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
List = list(map(int, input().split()))
List.sort()
cand = []
for _ in range(m):
  b,c = map(int,input().split())
  cand.append((b,c))
bc = sorted(cand, key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
    while b:
        if i < n and List[i] < c:
            List[i] = c
            b -= 1
        else:
            break
        i += 1
print(sum(List))

Measured memory_bytes: 29096
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

ll a,b;

int main(){
	cin>>a>>b;
	cout<<lcm(a,b)<<endl;
}

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

using namespace std;


int main() {
    int N;
    cin >> N;
    map<string, int> blueCards;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        if (blueCards.find(s) == blueCards.end()) {
            blueCards.insert(make_pair(s, 1));
        } else {
            blueCards[s]++;
        }
    }

    int M;
    cin >> M;
    map<string, int> redCards;
    for (int i = 0; i < M; ++i) {
        string s;
        cin >> s;
        if (redCards.find(s) == redCards.end()) {
            redCards.insert(make_pair(s, 1));
        } else {
            redCards[s]++;
        }
    }

    int ans = 0;
    for (auto itr = blueCards.begin(); itr != blueCards.end(); ++itr) {
        int tmp = itr->second;
        if (redCards.find(itr->first) != redCards.end()) {
            tmp -= redCards[itr->first];
        }
        ans = max(ans, tmp);
    }

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

Measured memory_bytes: 256
H,W=[int(s) for s in input().split()]
cam_ls=[ "." for _ in range(H+2)]
for j in range(W+1):
  cam_ls[0]=cam_ls[0]+"."
  cam_ls[H+1]=cam_ls[H+1]+"."
for i in range(1,H+1):
  cam_ls[i]=cam_ls[i]+input()+"."
  
def pos(h,w):
  if cam_ls[h][w]==".":
    return 1
  elif (cam_ls[h+1][w]=="." and
        cam_ls[h-1][w]=="." and
        cam_ls[h][w+1]=="." and
        cam_ls[h][w-1]=="."):
    return 0
  else:
    return 1

ans=1
for i in range(1,H+1):
  for j in range(1,W+1):
    ans*=pos(i,j)
if ans==1:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.Math;
import java.util.HashMap;
import java.util.Map;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int[] price = new int[5];
    for (int i = 0; i < 5; i++) {
      price[i] = Integer.parseInt(br.readLine());
    }
    
    int sum = 0;
    HashMap<Integer, Integer> tmp = new HashMap<Integer, Integer>();
    for (int i = 0; i < 5; i++) {
      if (price[i] % 10 == 0) {
        sum += price[i];
      } else {
        sum += price[i] + (10 - price[i] % 10);
        tmp.put(i, 10 - price[i] % 10);
      }
    }
    
    int max = 0;
    for (Map.Entry<Integer, Integer> entry : tmp.entrySet()) {
      max = Math.max(max, entry.getValue());
    }
    System.out.println(sum - max);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  ll n = s.size();
  string t = s;
  reverse(ALL(t));
  vector<ll> num(2019, 0);
  ll digit = 1;
  ll x = 0;
  num[0]++;
  REP(i, n){
    x =  (x+(t[i] - '0')*digit) % 2019;
    num[x]++;
    digit *= 10;
    digit %= 2019;
  }
  ll ans = 0;
  REP(i, 2019) ans += num[i]*(num[i]-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3924
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>

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

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int l,r;
    vector<int> vec,vec2(n);

    rep(i,n-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            vec.push_back(i);
            i++;
        }
    }
    
    for(auto e : vec){
        vec2[e+1] = 1;
    }
    rep(i,n-1){
        vec2[i+1] += vec2[i]; 
    }
    
    rep(i,q){
        cin >> l >> r;
        l--; r--;
        cout << vec2[r] - vec2[l] << endl;
    }

   
    return 0;
}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	int64_t ans=0;
	for(int i=1;i<n;++i){
		ans+=max(0,a.at(i-1)-a.at(i));
		a.at(i)+=max(0,a.at(i-1)-a.at(i));
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3972
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;
string S;

int main() {


	cin >> N>> S;

	for (auto &s : S) {
		s = (s - 'A' + N) % 26 + 'A';
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	double r;
	cin>>r;
	r=2*(M_PI)*r;
	cout<<r;
	
	
	
	
	
	
	
}

Measured memory_bytes: 3804
import sys
sys.setrecursionlimit(10**9)
n=int(input())
a=[]
for i in range(n):
    a.append(tuple(map(int,input().split())))
#print(a)

root=[[] for i in range(n*(n-1)//2)]
buf=0
for i in range(n):
    buf=0
    for j in range(n-1):
        if j==0:
            x=min(i,a[i][j]-1)
            y=max(i,a[i][j]-1)
            buf=x*(2*n-2-x+1)//2+(y-x)-1
            #print(x,y,buf)
            continue
        x=min(i,a[i][j]-1)
        y=max(i,a[i][j]-1)
        node=x*(2*n-2-x+1)//2+(y-x)-1
        #print(x,y,node)
        root[buf].append(node)
        buf=node
flag=[True]

#閉路☑
def dfs(node,par): 
    dp[node]=0
    for item in root[node]:
        if item==par:
            continue
        if dp[item]==0:
            flag[0]=False
            return
        if dp[item]==-1: 
            dfs(item,node)
    dp[node]=1#finish
dp=[-1]*(n*(n-1)//2)
for i in range(n*(n-1)//2):
    if dp[i]==-1:
        dfs(i,i)
        if flag[0]==False:
            break
if flag[0]==False:
    print(-1)
    sys.exit()
dp=[-1]*(n*(n-1)//2)
def dfs1(node,par): 
    buf=0
    for item in root[node]:
        if item==par:
            continue
        if dp[item]!=-1:
            buf=max(buf,dp[item])
            continue
        if dp[item]==-1: 
            buf=max([buf,dfs1(item,node)])
    dp[node]=buf+1#finish
    return buf+1

for i in range(n*(n-1)//2):
    if dp[i]==-1:
        dp[i]=dfs1(i,i)
print(max(dp))



Measured memory_bytes: 174300
#include <stdio.h>
#include <math.h>
int main(void){
  int n, x[100],y[100],i;
  scanf("%d",&n);
  double xy[100],max = -1,d1 = 0,d2 = 0,d3 = 0;
  for(i = 0;i < n;i++)scanf("%d",&x[i]);//scanf ha address sitei.
  for(i = 0;i < n;i++)scanf("%d",&y[i]);
  for (i = 0;i < n;i++){
    xy[i] = x[i] -y[i];
    if (xy[i] < 0)xy[i] *= -1;
    if (max < xy[i]) max = xy[i];
    d1 += xy[i];
    d2 += pow(xy[i],2);
    d3 += pow(xy[i],3);
  }
  printf("%.16lf\n%.16lf\n%.16lf\n%.16lf\n",d1,sqrt(d2),pow(d3,1.0/3.0),max);
  return 0;
  }

Measured memory_bytes: 700
#include <iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == b)cout << "Draw\n";
	else if(a==1)cout << "Alice\n";

	else if (b == 1 || a < b)cout << "Bob\n";
	else cout << "Alice\n";
	cin >> a;
	return 0;
}

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

struct data {
  long long x, y, z;
};
long long n, m;
vector<data> lst;

long long solve();
void dataset(int a, int b, int c);

bool asc(data l, data r) {
  return l.x + l.y + l.z > r.x + r.y + r.z;
}

int main() {
  cin >> n >> m;
  lst.resize(n);
  for(int i = 0; i < n; ++i)
    cin >> lst[i].x >> lst[i].y >> lst[i].z;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int a = -1; a <= 1; a += 2)
    for(int b = -1; b <= 1; b += 2)
      for(int c = -1; c <= 1; c += 2) {
        long long now = 0;
        dataset(a, b, c);
        sort(lst.begin(), lst.end(), asc);
        for(int i = 0; i < m; ++i)
          now += lst[i].x + lst[i].y + lst[i].z;
        ans = max(now, ans);
        dataset(a, b, c);
      }
  return ans;
}

void dataset(int a, int b, int c) {
  for(int i = 0; i < n; ++i) {
    lst[i].x *= a;
    lst[i].y *= b;
    lst[i].z *= c;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  int arr[m];
  for(int i=0; i<m; i++) {
    int a;
    cin >> a;
    n-=a;
  }
  if(n<0) cout << -1;
  else cout << n;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())
a = sorted([int(x) for x in input().split()])


def chk(x):
    for i in range(2*x, 2*n):
        if i != 2*n - 1 - (i - 2*x) and a[i] + a[2*n-1-(i-2*x)] < m:
            return False
    return True


bottom = -1
top = n

while top - bottom > 1:
    mid = (top + bottom)//2
    if chk(mid):
        top = mid
    else:
        bottom = mid

ans = -1

for i in range(2*top, 2*n):
    ans = max(ans, (a[i]+a[2*n-1-(i-2*top)]) % m)
for i in range(2*top):
    ans = max(ans, (a[i] + a[2*top-1-i]) % m)

print(ans)


Measured memory_bytes: 88404
a=gets.to_i
b=gets.to_i
c=gets.to_i
x=gets.to_i

aList=[*0..a]
bList=[*0..b]
cList=[*0..c]
ans=0
aList.each do|i|
  bList.each do|j|
    cList.each do|k|
      if i*500+j*100+k*50==x
        ans+=1
        break
      end 
    end
  end
end
puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  string s; cin >> s;
  int n = s.size();

  Vll c(n+1);
  rep(i, n) {
    int x = s[i] - 'a';
    c[i+1] = c[i]^(1ll<<x);
  }

  V dpmin(1ll<<26, INF);
  V dp(n+1, INF);
  dp[0] = 0;
  dpmin[0] = 0;
  rep2(i, 1, n+1) {
    chmin(dp[i], dpmin[c[i]]+1);
    chmin(dpmin[c[i]], dp[i]);
    rep(x, 26) {
      int y = c[i]^(1ll<<x);
      chmin(dp[i], dpmin[y]+1);
      chmin(dpmin[c[i]], dp[i]);
    }
  }

  int ans = dp[n];
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 265108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll n, k;
  cin >> n >> k;
  vl p, m, z;
  rep(i, n) {
    ll a;
    cin >> a;
    if(a > 0)
      p.push_back(a);
    else if(a < 0)
      m.push_back(a);
    else
      z.push_back(a);
  }
  sort(all(p), greater<ll>());
  sort(all(m));
  mint ans = 1;
  ll i = 0, j = 0;
  if(p.empty() && k % 2 == 1) {
    if(z.empty()) {
      reverse(all(m));
      rep(x, k) ans *= m[x];
    } else
      ans = 0;
  } else {
    if(k % 2) {
      ans *= p[i];
      i++;
    }
    while(i + j < k) {
      if(i + 1 >= ll(p.size()) && j + 1 >= ll(m.size())) {
        if(i + j + 1 == k && i < ll(p.size())) {
          ans *= p[i];
        } else if(!z.empty())
          ans = 0;
        else {
          if(i < ll(p.size())) ans *= p[i];
          if(j < ll(m.size())) ans *= m[j];
        }
        break;
      } else if(i + 1 >= ll(p.size())) {
        ans *= (m[j] * m[j + 1]);
        j += 2;
      } else if(j + 1 >= ll(m.size())) {
        ans *= (p[i] * p[i + 1]);
        i += 2;
      } else {
        ll now1 = p[i] * p[i + 1];
        ll now2 = m[j] * m[j + 1];
        if(now1 >= now2) {
          ans *= now1;
          i += 2;
        } else {
          ans *= now2;
          j += 2;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5668
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.trim_end().to_string();
    let mut iter = s.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    println!("{}", a * b);
}

Measured memory_bytes: 2164
#include <stdio.h>

int main()
{
  char s[3],t[3];
  scanf("%s%s",&s,&t);
  int i,cnt=0;
  for(i=0;i<3;++i)
  {
    if(s[i]==t[i])
        cnt++;
  }
 printf("%d",cnt); 
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if (a+b>=c) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>

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 all(a)		 begin(a), end(a)

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(ll N, vector <ll> a) {
	bool b[N + 1] = { };
	b[1] = true;
	int	 tmp	  = 1;
	int	 cnt	  = 0;
	while(1) {
		cnt++;
		tmp = a[tmp - 1];
		if(tmp == 2) {
			printf("%d", cnt);
			break;
		}
		else if(b[tmp] == true) {
			printf("-1");
			break;
		}
		else {
			b[tmp] = true;
		}
	}
}

int main() {
	ll N;
	scanf("%lld", &N);
	vector <ll> a(N - 1 + 1);
	for(int i = 0; i <= N - 1; i++) {
		scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 1920
#include<iostream>

using namespace std;

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

int main() {
  int n;
  cin >> n;
  while (n--) {
    int k = 0;
    string str;
    cin >> str;
    int m = 0;
    rep (i, str.size()) {
      m += str[i] - '0';
      ++k;
      if (m >= 10) {
	  m -= 9;
	  ++k;
      }
    }
    if (k % 2 == 0) {
      cout << "Fabre wins." << endl;
    } else {
      cout << "Audrey wins." << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {
	  public static void main(String[]args){
		    Scanner sc = new Scanner(System.in);
		    int ten[];
		    int i=0;
		    int sum;
		    double m=0.0;
		    double x=0.0;
		    double A=0.0;
		    ten = new int[1000];
		    while(true)
            {
		    	sum=0;
		    	m=0.0;
			    x=0.0;
			    A=0.0;
		    	int n=sc.nextInt();
                        if(n==0) break;
		    	for(i=0;i<n;++i)
		    	{
		    		ten[i]=sc.nextInt();
		    		sum=sum+ten[i];
		    	}
		    	m=(double)sum/(double)n;
		    	for(i=0;i<n;++i)
		    	{
		    		x=x+(ten[i]-m)*(ten[i]-m);
		    	}
		    	A=x/(double)n;
		    	double a=Math.sqrt(A);
		    	System.out.println(a);
            }
		    	sc.close();
		    }
}



Measured memory_bytes: 31600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int R;
  cin>>R;
  string ans="ARC";
  if(R<1200)
    ans="ABC";
  cout<<ans;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;int c=0,d=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='A')
            c++;
        else
            d++;
    }
    if(c==3||d==3)
        cout<<"No";
    else
        cout<<"Yes";
}


Measured memory_bytes: 256
n=int(input())
ans=0
nmcc=0
i=1
d=[]
while i*i<=n:
  if n%i==0:
    d.append(i)
    if i*i!=n:
      d.append(n//i)
  i+=1
for i in d:
  if i==1:
    continue
  tmp=n
  while tmp%i==0:
    tmp//=i
  tmp%=i
  if tmp==1:
    ans+=1

i=1
while i*i<=(n-1):
  if (n-1)%i==0:
    nmcc+=1
    if i*i!=n-1:
      nmcc+=1
  i+=1
nmcc-=1
print(ans+nmcc)
  

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

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
    ll N, L;
    cin >> N >> L;
    vector<P> ls, imos;
    for(int i=0;i<N;i++){
        ll l, r;
        cin >> l >> r;
        ls.push_back(P(l,r));
        imos.push_back(P(l,+1));
        imos.push_back(P(r,-1));
    }
    sort(ls.begin(), ls.end());
    sort(imos.begin(), imos.end());
    ll x = 0;
    for(ll rmax = 0, i=0; rmax < L;){
        ll tmp = rmax;
        while(i<N && ls[i].first <= rmax){
            tmp = max(tmp, ls[i].second);
            i++;
        }
        x++;
        rmax = tmp;
    }
    ll sum = 0, smin = INT_MAX;
    for(int i=0;i<N*2-1;i++){
        sum += imos[i].second;
        if(imos[i].first != imos[i+1].first){
            smin = min(sum, smin);
        }
    }
    ll y = N - smin + 1;
    cout << x << " " << y << endl;
    return 0;

}


Measured memory_bytes: 13284
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

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




Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
     
int main() {
     
int A, B;
  cin >> A >> B;
  if(A >= 13) {
    cout << B << endl;
  }
  else if(A < 6) {
    cout << 0 << endl;
  }
  else {
    cout << B / 2 << endl;
  }

}

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

#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define m(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=3e5+10;

int main(){
	IO;
	int a,b,k;
	while(cin>>a>>b>>k){
		if (k>=b){
			for(int i=a;i<=b;i++)
				cout<<i<<endl;
		}
		else{
			int t=b-a+1;
			if (2*k>t)
				for(int i=a;i<=b;i++)
					cout<<i<<endl;
			else{
				for(int i=1;i<=k;i++){
					cout<<a<<endl;
					a++;
				}
				for(int i=1;i<=k;i++){
					cout<<b-k+1<<endl;
					b++;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int a[2],x=0,y=0;
	cin >> a[0]>>a[1]>>a[2];
	for (int i = 0; i < 3; i++) {
		if (a[i] == 5)x += 1;
		else if(a[i] == 7)y += 1;
	}
	if (x == 2 && y == 1)cout << "YES" << endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 1000005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//vector<int> adj[mex];
//a+b=a^b+2*(a&b)
int K[512][100001];

int main(){
	fast
	int n;
	cin>>n;
	int val[n],wt[n];
	for(int i=0;i<n;i++)
	 cin>>val[i]>>wt[i];
	int W=100001;
	
	int n1=min((1<<9)-1,n);
	//vector<vector<int>> K(n+1,vector<int> (W+1));
	
	
	for (int i = 0; i <= n1; i++) { 
        for (int w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max(val[i - 1] + K[i/2][w - wt[i - 1]],K[i/2][w]); 
            else
                K[i][w] = K[i/2][w]; 
        } 
    }
    int q;
    cin>>q;
    while(q--){
		int v,l;
		cin>>v>>l;
		if(v<((1<<9)-1))
		 cout<<K[v][l]<<"\n";
		else{
			int l1=1,x1=2;
			while(x1<=v){
				x1=x1*2;
				l1+=1;
			}
			ll ans=0;
			for(int i=0;i<(1<<(l1-9));i++){
				int nn=v;
				ll s1=0,s2=0;
				for(int j=0;j<(l1-9);j++){
					if(i&(1LL<<j)){
						s1=s1+wt[nn-1];
						s2=s2+val[nn-1];
					}
					nn=nn/2;
				}
				if(s1>l)
				 continue;
				else
				 ans=max(ans,s2+K[nn][l-s1]);
			 }
			 cout<<ans<<"\n";
		 }
	 }
				   	 
}


Measured memory_bytes: 205712
#include<iostream>
#include<map>
using namespace std;
int main(){
  map<string, bool> mp;
  int n;
  scanf("%d", &n);
  string s;
  for(int i=0;i<n;i++){
    cin >> s;
    if(mp[s]){
      mp[s] = !mp[s];
    } else {
      mp[s] = true;
    }
  }
  int count = 0;
  for(map<string ,bool>::iterator it = mp.begin();it != mp.end();it++){
    if(it -> second){
      count ++;
    }
  }
  printf("%d", count);
  return 0; 
}

Measured memory_bytes: 12544
// 2011/10/16 Tazoe

#include <iostream>
using namespace std;

void prime(bool prm[], int n)
{
	if(n>=1)
		prm[0] = false;
	if(n>=2)
		prm[1] = false;

	for(int i=2; i<n; i++)
		prm[i] = true;

	for(int i=2; i<n; i++)
		if(prm[i])
			for(int j=i+i; j<n; j+=i)
				prm[j] = false;
}

int main()
{
	bool prm[1000001];
	prime(prm, 1000001);

	int prm2[1000001];
	int cnt = 0;
	for(int i=0; i<=1000000; i++){
		if(prm[i])
			cnt++;
		prm2[i] = cnt;
	}

	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int sum = 0;
		for(int i=0; i<n; i++){
			int p, m;
			cin >> p >> m;

			int bgn;
			if(p-m-1<0)
				bgn = 0;
			else
				bgn = p-m-1;

			int end;
			if(p+m>1000000)
				end = 1000000;
			else
				end = p+m;

			sum += (prm2[end]-prm2[bgn]);

			sum--;

//			cout << sum << endl;

		}

		cout << sum << endl;
	}

	return 0;
}

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

int main(){
    int N,M;
    int mod = 1e9 + 7;
    cin >> N>>M;
    vector<int> a(M);
    for(int i =0;i<M;i++){ cin >> a[i];}
    vector<int> k(N+1);
    k[0]=1;
    for(int i=1,j=0;i<=N;i++){
        if(j<M&&a[j]==i){
            j++;
            continue;
        }
        if(i==1){
            k[i] += k[i-1];
        }else{
            k[i] += k[i-1] + k[i-2];
        }
        k[i]%=mod;
    }
    
    cout<< k[N] << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>

using namespace std;

int main(void) {

	int a, b, k;

	cin >> a >> b >> k;

	for (int i = 1; i <= k; i++) {

		if (i % 2 == 1) {
			if (a % 2 == 1)a--;
			a /= 2;
			b += a;
		}
		else {
			if (b % 2 == 1)b--;
			b /= 2;
			a += b;
		}
	}

	printf("%d %d\n", a, b);

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
       System.out.println(a / gcd(a, b) * b);
    }
    
    static long gcd(long x, long y) {
        if (x % y == 0) {
            return y;
        } else {
            return gcd(y, x % y);
        }
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
vector<bool>used;
vi a(N);
vi q(N), w(N);
int pos=0, lp=0, rt=0;
int mx=0, len=1, ch=0;
void rec(int idx, int n){
    if(idx==n){
        bool s1=0, s2=0;
        pos++;
        for(int i = 0; i < n; i++){
            if(a[i]!=q[i]){
                s1=1;
                break;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i]!=w[i]){
                s2=1;
                break;
            }
        }
        if(!s1)lp=pos;
        if(!s2)rt=pos;
        if(pos==len)cout<<abs(rt-lp);
        return;
    }
    for(int i = 1; i <= n; i++){
        if(used[i])continue;
        a[idx]=i;
        used[i]=true;
        rec(idx+1, n);
        used[i]=false;
    }
}
int main(){
    speed;
    int n;
    cin>>n;
    for(int i = 0; i < n; i++)cin>>q[i];
    for(int i = 0; i < n; i++)cin>>w[i];
    ch=n;
    while (ch!=0)
    {
        len*=ch;
        ch--;
    }
    used=vector<bool>(n+1, false);
    rec(0, n);
}

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

int main() {
    int N;  cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i];
    for (int i = 0; i < N - 1; ++i) cin >> C[i];

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += B[A[i] - 1];
        if (A[i] + 1 == A[i + 1]) ans += C[A[i] - 1];
    }
    cout << ans << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b >= 10)
        OP("error");
    else
        OP(a + b);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int H, W;
    cin >> H >> W;

    vector<vector<int>> board(H, vector<int>(W));
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cin >> board[h][w];
        }
    }

    vector<pair<pair<int, int>, pair<int, int>>> cmds;

    for (int h = 0; h < H; h++) {
        if (h % 2 == 0) {
            for (int w = 0; w < W; w++) {
                int next_h, next_w;
                if (w != W - 1) {
                    next_h = h;
                    next_w = w + 1;
                } else {
                    next_h = h + 1;
                    next_w = w;
                }

                if (next_h >= H) {
                    continue;
                }

                if (board[h][w] % 2 != 0) {
                    board[h][w]--;
                    board[next_h][next_w]++;
                    cmds.push_back(make_pair(make_pair(h, w), make_pair(next_h, next_w)));
                }
            }
        } else {
            for (int w = W - 1; w >= 0; w--) {
                int next_h, next_w;
                if (w != 0) {
                    next_h = h;
                    next_w = w - 1;
                } else {
                    next_h = h + 1;
                    next_w = w;
                }

                if (next_h >= H) {
                    continue;
                }

                if (board[h][w] % 2 != 0) {
                    board[h][w]--;
                    board[next_h][next_w]++;
                    cmds.push_back(make_pair(make_pair(h, w), make_pair(next_h, next_w)));
                }
            }
        }
    }

    cout << cmds.size() << endl;
    for (auto cmd : cmds) {
        pair<int, int> src = cmd.first;
        pair<int, int> dst = cmd.second;
        printf("%d %d %d %d\n", src.first + 1, src.second + 1, dst.first + 1, dst.second + 1);
    }

    return 0;
}


Measured memory_bytes: 6308
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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>
#include <bitset>
using namespace std;

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

int A[30][30];
signed main() {
    int N, M, C; cin >> N >> M >> C;
    vector<int> B(M);
    for(int i=0; i<M; i++) {
        cin >> B[i];
    }
    for(int i=0; i<N; i++) {
        for(int j=0; j<M; j++) {
            cin >> A[i][j];
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++) {
        int sum = C;
        for(int j=0; j<M; j++) {
            sum += A[i][j] * B[j];
        }
        if(sum > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
"""
時間がかかる料理は、食べるとしたら最後に食べるのがベスト。
逆にいうと、その料理を食べるかどうかを検討する段階ではほかの料理は食べるかどうかの検討は終わっている状態。
なので、食べるのにかかる時間でソートしてナップサックすればよい。
"""

N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
dp = [0]*(T)
AB.sort()

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

Measured memory_bytes: 75040
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

ll AN(ll A, ll N){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0) return AN(A * A % nmax, N / 2) % nmax;
    else return A * AN(A * A % nmax, N / 2) % nmax;
  }
}

int main(){
  int N, K; cin >> N >> K;
  vector <ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());

  ll DP[N];
  for (int i = 0; i < K - 1; i++){
    DP[i] = 0;
  }
  DP[K - 1] = 1;
  for (ll i = K; i < N; i++){
    DP[i] = DP[i - 1];
    DP[i] *= AN(i - K + 1, nmax - 2); DP[i] %= nmax;
    DP[i] *= i; DP[i] %= nmax;
  }
  
  ll ans = 0;
  for (int i = 0; i < N; i++){
    ll now = A[i] * (DP[i] - DP[N - 1 - i]);
    now %= nmax;
    ans += now; ans %= nmax;
    ans += nmax; ans %= nmax;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
import math
import itertools

n = int(input())
x, y = [0]*n, [0]*n
for i in range(n):
    a, b = map(int, input().split())
    x[i], y[i] = a, b
l = list(itertools.permutations(range(n)))

tmp = 0
for p in l:
    for j in range(n-1):
        a = p[j]
        b = p[j+1]
        tmp += math.sqrt((x[a]-x[b])**2 + (y[a]-y[b])**2)

print(round(tmp/len(l), 10))



Measured memory_bytes: 8052
from itertools import product
N = int(input())
E = [3,5,7]
ans = 0

for i in range(3, len(str(N))+1) :
    L = product(E, repeat=i)
    for l in L :
        if (3 not in l) or (5 not in l) or (7 not in l) :
            continue
        number = int("".join(list(map(str,l))))
        if number <= N :
            ans += 1
print(ans)


Measured memory_bytes: 3060
/*
 * SwappingTwoNumbers.cpp
 *
 *  Created on: 2014/07/21
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

typedef struct {
	int x, y;
} DataSet;

void swap(int& a_x, int& a_y) {
	if (a_x > a_y) {
		int tmp = a_x;
		a_x = a_y;
		a_y = tmp;
	}
}

int main(void) {

	vector<DataSet> vecDataSet;
	while(1) {
		int x, y = 0;
		cin >> x >> y;
		if ((0 == x) && (0 == y)) {
			break;
		}
		DataSet data;
		data.x = x;
		data.y = y;
		vecDataSet.push_back(data);
	}

	for (unsigned int i = 0; i < vecDataSet.size(); i++) {
		DataSet data = vecDataSet.at(i);
		swap(data.x, data.y);
		cout << data.x << " " << data.y << endl;
	}

	return 0;
}

Measured memory_bytes: 1244
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest025-A
#  https://atcoder.jp/contests/agc025/tasks/agc025_a
def digitEachDigitSum(number):
	numberStr=str(number)
	numberLength = len(numberStr)
	numberRange = range(0,numberLength,1)
	numberDigitSum = 0
	for eachNumberPosition in numberRange:
		eachNumberInt = int(numberStr[eachNumberPosition])
		numberDigitSum = numberDigitSum+eachNumberInt
	return numberDigitSum

def minDigitSum(givenNumber):
	minSum = 100000000
	checkNumberRange = range(1,givenNumber,1)
	for nowNumber in checkNumberRange:
		anotherNumber = givenNumber-nowNumber
		twoNumberSum = digitEachDigitSum(nowNumber)+digitEachDigitSum(anotherNumber)
		if twoNumberSum < minSum:
			minSum = twoNumberSum
#           MinSum chenged OutPut
#			print("{} = {} + {} =>{}".format(givenNumber,nowNumber,anotherNumber,minSum))

	return minSum

if __name__ == '__main__':
	N = int(input())
	solution=minDigitSum(N)
	print("{}".format(solution))

Measured memory_bytes: 3064