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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

void solve(){

	ll n;cin>>n;
	vll A(n),B(n);for(int i=0;i<n;i++)cin>>A[i],B[i]=A[i];
	sort(rall(A));
	for(int i=0;i<n;i++)
		if(B[i]==A[0])
			cout<<A[1]<<"\n";
		else
			cout<<A[0]<<"\n";


}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
const int MAXN = 3e2+5;
const int MOD = 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}
 
int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    LL r; cin >> r;
    cout << 3*r*r << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
using ld = long double;
using ulli = unsigned long long int;
#define filein freopen ("in.txt", "r", stdin)
#define fileout freopen ("out.txt", "w", stdout)
#define dbg(x) cerr << #x << ": " << x << endl
#define all(v) ((v).begin()),((v).end())
#define PI 3.14159265 
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,n) for(int i=1;i<=n;i++)
#define mod 1000000007
void solve(){
	lli x;
	cin>>x;
	cout<<(x / 500) * 1000 + ((x % 500) / 5) * 5;
}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}


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

ll N, K, t, d, sum, ans;
vector<ll> F, S;
vector<pair<ll, ll>> v;
map<ll, ll> mp;

main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> t >> d;
        v.push_back(make_pair(t, d));
    }
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < v.size(); i++) {
        pair<ll, ll> p = v[i];
        if (mp[p.first] == 0) F.push_back(p.second);
        else S.push_back(p.second);
        mp[p.first]++;
    }
    sort(F.rbegin(), F.rend());
    sort(S.rbegin(), S.rend());
    ll L = F.size(), M = S.size();
    for (int i = 0; i < min(K, L); i++) sum += F[i];
    if (K > L) {
        int check = 0;
        for (ll i = 0; i < K - L; i++, check = i) sum += S[i];
        ans = sum + L * L;
        for (ll j = L - 1; j > 0 && check < M; check++, j--) {
            sum = sum - F[j] + S[check];
            ans = max(ans, sum + j * j);
        }
        cout << ans << endl;
    }
    else {
        ans = sum + K * K;
        for (ll i = 0; i < K - 1 && i < M; i++) {
            sum = sum - F[K - 1 - i] + S[i];
            ans = max(ans, sum + (K - i - 1) * (K - i - 1));
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 8816
import sys

sys.setrecursionlimit(200000)

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

convert=[]
for i in range(10):
    convert.append(list(map(int, input().split())))

paint=set([])
dicts={ i:0 for i in range(10)}
for i in range(N):
    input_temp = list(map(int, input().split()))
    temp=[]
    
    for j in input_temp:
        if j != -1:
            dicts[j] += 1
            temp.append(j)
    paint = paint | set(temp)


search_index = set([0,1,2,3,4,5,6,7,8,9])
def dfs(now_index, direct_distance, now_value, before_index, goal_index):
    
    if direct_distance < now_value:
        return direct_distance
    if now_index == goal_index:
        return now_value
    
    mins=[]
    temp_search_index = search_index - set([now_index, before_index])
    for i in temp_search_index:
        mins.append(dfs(i, 
                        direct_distance, 
                        now_value+convert[now_index][i], 
                        now_index, 
                        goal_index)
                   )
    return min(mins)

sums=0
for start in paint:
    if start != 1:
        sums += dicts[start] * dfs(start, convert[start][1], 0, -1, 1)

print(sums)

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

int main() {
    int r, w, c, d;
    while (cin >> r >> w >> c >> d, r||w||c||d) {
        if (r/w >= c) cout << 0 << endl;
        else {
            int x = 1;
            while ((r + d * x) / w < c) x++;
            cout << x << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	if (N == 25) {
		cout << "Christmas" << endl;
	}
	else if (N == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (N == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (N == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import  copy
h = w = 0
mymap =[]
const_mymap = []
qlist = []
ans = 0
def bfs(n):
    while True:
        if len(qlist) != 0:
            temp = qlist.pop(0)
            x = temp[0]
            y = temp[1]
            deep = temp[2]

            #print(temp)
            if mymap[y][x] == str(n):
                #print('get')
                return temp
            if mymap[y][x] != '*':
                mymap[y] = mymap[y][:x] + '*' + mymap[y][x + 1:]

                if x + 1 < w:
                    if mymap[y][x + 1] not in '*X':
                        qlist.append([x + 1, y, deep + 1])
                if x - 1 >= 0:
                    if mymap[y][x - 1] not in '*X':
                        qlist.append([x - 1, y, deep + 1])
                if y + 1 < h:
                    if mymap[y + 1][x] not in '*X':
                        qlist.append([x, y + 1, deep + 1])
                if y - 1 >= 0:
                    if mymap[y - 1][x] not in '*X':
                        qlist.append([x, y - 1, deep + 1])
        else:
            break
h, w, n = list(map(lambda x: int(x), input().split(" ")))
for i in range(0, h):
    const_mymap.append(input())

mymap = copy.deepcopy(const_mymap)

for i in range(0, h):
    for j in range(0, w):
        if mymap[i][j] == 'S':
            nstart = [j, i, 0]
#print(nstart)

qlist.append(nstart)
#print(qlist)
for i in range (n):
    #print(i)
    mymap = copy.deepcopy(const_mymap)
    xy = bfs(i+1)
    #print(xy)
    #print(const_mymap)
    ans = xy[2]
    qlist = []
    qlist.append(xy)
    #print(ans)

print(ans)

Measured memory_bytes: 10160
n,m = gets.split.map &:to_i

pairs = []
n.times do |i|
  pairs[i] = gets.split.map &:to_i
end

sorted = pairs.sort_by{|a|a[0]}
sum = 0
sorted.each do |a,b|
  if b <= m
    sum += (a * b)
    m -= b
  else
    sum += (a * m)
    m -= m
  end
  if m == 0
    puts sum
    exit
  end
end

Measured memory_bytes: 13944
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    string s;
    cin >> s;
    vector<int> x;
    for(auto c: s)
        x.push_back(c - '0');
    
    bool ok = false;
    for(int i=-1;i<=1;i+=2){
        for(int j=-1;j<=1;j+=2){
            for(int k=-1;k<=1;k+=2){
                int now = x[0] + i*x[1] + j*x[2] + k*x[3];
                if(now == 7){
                    char ci = (i==-1?'-':'+');
                    char cj = (j==-1?'-':'+');
                    char ck = (k==-1?'-':'+');
                    printf("%d%c%d%c%d%c%d=7\n", x[0], ci, x[1], cj, x[2], ck, x[3]);
                    ok = true;
                    break;
                }
            }
            if(ok)
                break;
        }
        if(ok)
            break;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int x;

    scanf("%d", &x);

    if (x >= 30) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;
typedef long long ll;

int main()
{
    FAST_IO;
    int n;
    cin >> n;
    int gr = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x >= gr) {
            gr = x;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
typedef struct{
	int *par,*rank;
}Union;
void init_union(Union *u,int size){
	int i;
	u->par = (int*)calloc(size,sizeof(int));
	u->rank = (int*)calloc(size,sizeof(int));
	FOR(i,0,size) u->par[i]=i;
	return;
}
int root(Union *u,int a){
 	if(u->par[a]==a) return a;
 	else{
 		u->par[a]=root(u,u->par[a]);
 		return u->par[a];
 	}
}
int is_same(Union *u,int a,int b){
 	return root(u,a)==root(u,b);
} 
void unite(Union *u,int a,int b){
	a=root(u,a);
	b=root(u,b);
	if(a==b) return;
	if(u->rank[a]>u->rank[b])
	    u->par[b]=a;
	else{
		u->par[a]=b;
		if(u->rank[a]==u->rank[b]) u->rank[b]++;
	}
	return;
}
void delete_union(Union *u){
	free(u->par);
	free(u->rank);
	return;
}
typedef struct{
	int x,y,num;
}City;
int comp(const void *a,const void *b){
	City s=*(City*)a,t=*(City*)b;
	return s.x!=t.x?s.x-t.x:s.y-t.y;
}
int lower_bound(City a[],int n,City k){
	int left=-1; int right=n;
	while(right-left>1){
		int mid=(left+right)/2;
		if(comp((void*)&a[mid],(void*)&k)<0) left=mid;
		else right=mid;
	}
	return right;
}
int upper_bound(City a[],int n,City k){
	int left=-1; int right=n;
	while(right-left>1){
		int mid=(left+right)/2;
		if(comp((void*)&a[mid],(void*)&k)<=0) left=mid;
		else right=mid;
	}
	return right;
}
City city[200000];
int main(void)
{
	int n,k,l,a,b,i;
	Union p,q;
	City c;
	scanf("%d%d%d",&n,&k,&l);
	init_union(&p,n);
	init_union(&q,n);
	while(k-->0){
		scanf("%d%d",&a,&b);
		unite(&p,--a,--b);
	}
	while(l-->0){
		scanf("%d%d",&a,&b);
		unite(&q,--a,--b);
	}
	FOR(i,0,n) city[i].x=root(&p,i),city[i].y=root(&q,i);
	qsort(city,n,sizeof(City),comp);
	FOR(i,0,n){
		//printf("%d %d\n",city[i].x,city[i].y);
		c.x=root(&p,i),c.y=root(&q,i);
		printf("%d%c",upper_bound(city,n,c)-lower_bound(city,n,c),i==n-1?'\n':' ');
	}
	delete_union(&p);
	delete_union(&q);
	return 0;
}

Measured memory_bytes: 6780
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main(){
    ll A,B,C,K;
    cin>>A>>B>>C>>K;
    if(A>=K){
        cout<<K<<endl;
    }
    else if(A<K&&(A+B)>=K){
        cout<<A<<endl;
    }
    else{
        cout<<2*A+B-K<<endl;
    }
}

Measured memory_bytes: 3592
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int N;
LL A[200000];

int main(void){
    GI(N);
    LL sum = 0;
    map<LL,LL> ma;
    ma[0]++;
    REP(i,N){
        LL a;
        GLL(a);
        sum += a;
        ma[sum]++;
    }
    LL ans = 0;
    for(auto i: ma){
        // printf("i.first = %lld i.second = %lld\n",i.first,i.second);
        ans += i.second*(i.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, K;
    cin >> N >> K;
    vl A(N);
    rep(i, N) cin >> A[i];

    rep(i, N - K){
        cout << (A[i + K] > A[i] ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 4780
#include<stdio.h>
int main(void)
{int S,h,m,s;
  scanf("%d",&S);

  h=S/3600;
  m=S%3600;
  s=m%60;
  m=m/60;

  printf("%d:%d:%d\n",h,m,s);

  return(0);

}

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

int main() {
  int N;
  
  cin >> N;
  
  int t=N,c=0;
  while(t>0){
    c += t%10;
    t /= 10;
  }
  
  if(N%c == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}


Measured memory_bytes: 256
from itertools import permutations, combinations
import math

def factorial(num):
    if num <= 1:
        return 1
    return num * factorial(num - 1)

n = int(input())
xy =[list(map(int, input().split())) for _ in range(n)]
ans = 0
for i, j in combinations(range(n), 2):
    l = math.sqrt((xy[i][0] -xy[j][0]) ** 2 + (xy[i][1] -xy[j][1]) ** 2)
    ans += 2 * factorial(n - 2) * (n - 1) * l
print(ans / factorial(n))

Measured memory_bytes: 62756
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  if s=='ABC':
    return 'ARC'
  return 'ABC'

# main()
print(main())


Measured memory_bytes: 10628
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, M;
vector<int> G[100100];
bool visited[100100];
deque<int> path;

int ok(int idx) {
    for (int v:G[idx]) {
        if (!visited[v])return v;
    }
    return 0;
}

signed main() {
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    visited[0] = true;
    visited[G[0][0]] = true;
    path.push_front(0);
    path.push_back(G[0][0]);
    int left = 0;
    while (left = ok(left)) {
        visited[left] = true;
        path.push_front(left);
    }
    int right = G[0][0];
    while (right = ok(right)) {
        visited[right] = true;
        path.push_back(right);
    }
    cout << path.size() << endl;
    while (!path.empty()) {
        cout << path.front() + 1 << " ";
        path.pop_front();
    }
    return 0;
}


Measured memory_bytes: 7168
from sys import stdin
from itertools import product

N, *xyh = map(int, stdin.read().split())

xyh = list(zip(*[iter(xyh)] * 3))
xyh.sort(key=lambda x: x[2], reverse=True)

x1, y1, h1 = xyh[0]
for X, Y in product(range(101), range(101)):
    H = h1 + abs(x1-X) + abs(y1-Y)
    if all(max(H-abs(x-X)-abs(y-Y), 0) == h for x, y, h in xyh[1:]):
        print(X, Y, H)
        break

Measured memory_bytes: 3064
'use strict'

function main(s) {

  const n = s.split('\n')[0];
  const digit_sum = n.split('').map(n => Number(n)).reduce((a, b) => a + b);

  const ans = (n % digit_sum === 0) ? 'Yes' : 'No';

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

ll a, b;

ll gcd(ll x, ll y)
{
    ll temp;
    while (x % y != 0)
    {
        temp = y;
        y = x % y;
        x = temp;
    }

    return y;
}

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

    cout << a * b / gcd(a, b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

ll n, x;
ll b[100000], l[100000], u[100000];
pl ho[100000], ge[100000];
ll eg[100000];
bool saw[100000];
ll target;

bool solve(ll mid) {
    ll p = mid / x, q = mid % x;
    rep(i,n) {
        ho[i] = pl(x * u[i] - (u[i]-l[i]) * b[i], i);
        if (b[i] >= q) {
            ge[i] = pl(q * l[i], i);
        } else {
            ge[i] = pl(q * u[i] - (u[i]-l[i]) * b[i], i);
        }
    }
    sort(ho, ho+n, greater<pl>());
    sort(ge, ge+n, greater<pl>());
    rep(i,n) eg[ge[i].second] = i;
    ll val = 0, add = 0;
    memset(saw, 0, sizeof(saw));
    rep(i,p) {
        val += ho[i].first;
        saw[ho[i].second] = true;
    }
    rep(i,n) {
        if (saw[ge[i].second]) continue;
        val += ge[i].first;
        add = ge[i].first;
        break;
    }
    ll ret = val;
    rep(i,p) {
        ll tmp = val;
        tmp -= ho[i].first;
        tmp += ge[eg[ho[i].second]].first;
        tmp -= add;
        tmp += ho[p].first;
        ret = max(ret, tmp);
    }
    return (ret >= target);
}

int main() {
    cin >> n >> x;
    rep(i,n) cin >> b[i] >> l[i] >> u[i];
    rep(i,n) target += l[i] * b[i];
    ll le = -1, ri = x*n;
    while (ri-le > 1) {
        ll mid = (ri + le) / 2;
        if (solve(mid)) ri = mid;
        else le = mid;
    }
    cout << ri << endl;
}


Measured memory_bytes: 6656
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

  int d, n;
  cin >> d >> n;
  if(d==0){
    if(n==100){
      cout << 101 << endl;
    } else {
      cout << n << endl;
    }
  } else if(d==1){
    if(n==100){
      cout << 10100 << endl;
    } else {
      cout << 100*n << endl;
    }
  } else{
    if(n==100){
      cout << 1010000 << endl;
    } else {
      cout << 10000*n << endl;
    }
  }

	return 0;
}


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

#define MAX_V 10000
#define INF 2000000001
int d[MAX_V][MAX_V]; //d[u][v]はe=(u,v)のコスト(存在しなければINF、u=vは0)

int V; //頂点数

void init(){
  for(int i=0;i<V;i++)
    for(int j=0;j<V;j++)
      if(i==j)d[i][j]=0;
      else d[i][j]=INF;
}

void warshall_floyd(){
  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++)
	if(d[i][k]!=INF&&d[k][j]!=INF)
	  d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

int main(){
  int m;
  cin>>V>>m;
  init();
  int a[1010],b[1010],c[1010];
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--,b[i]--;
    d[a[i]][b[i]]=c[i];
    d[b[i]][a[i]]=c[i];
  }
  warshall_floyd();
  int ans=0;
  for(int i=0;i<m;i++){
    if(d[a[i]][b[i]]==c[i])continue;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long a, b, c;
    scan(a, b, c);
    long max_x = max(a, b, c);
    long sum_x = a + b + c;
    long x, y;
    if (((max_x % 2 == 0) && (sum_x % 2 == 0)) || (max_x % 2 != 0) && (sum_x % 2 != 0))
    {
        x = (max_x * 3 - sum_x) / 2;
        writeln(x);
        return;
    }
    y = ((max_x * 3 + 3) - sum_x) / 2;
    writeln(y);
}
//https://rclone.org/

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    ll A,B;
    cin>>A>>B;
map<ll,ll> Ae,Be,Ce;
    
    ll x=2,y=2;
    while(A!=1){
        if(A%x==0){
            Ae[x]++;
            Ce[x]++;
            A/=x;
        }else{
            x++;
        }
    }
    
    while(B!=1){
        if(B%y==0){
            Be[y]++;
            Ce[y]++;
            B/=y;
        }else{
            y++;
        }
     }
    ll sum=1;
    for(auto p:Ce){
        auto k=p.first;
        Ae[k]=max(Ae[k],Be[k]);
    }
    for(auto p:Ae){
        auto k=p.first;
        auto v=p.second;
        sum*=pow(k,v);
    }
    cout<<sum<<endl;    
}




Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)



int main(){
    int n, m;
    cin >> n >> m;
    vector<int> p(m);
    vector<int> y(m);
    vector<pii> yp(m);
    for(int i = 0; i < m; i++){
        cin >> p[i] >> y[i];
        yp[i].first = y[i];
        yp[i].second = p[i];
    }

    sort(yp.begin(),yp.end());

    map<int,int> a;
    vector<int> pref(n+1,0);
    for(int i = 0; i < m; i++){
        pref[yp[i].second]++;
        a[yp[i].first] = pref[yp[i].second];
    }


    for(int i = 0; i < m; i++){
        printf("%06d%06d\n",p[i],a[y[i]]);
    }



    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
  string S;
  int N,c1=0,c2=0,c3=0,c4=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>> S;
    if(S=="AC")c1++;
    if(S=="WA")c2++;
    if(S=="TLE")c3++;
    if(S=="RE")c4++;

  }
  cout<<"AC x "<<c1<<endl;
  cout<<"WA x "<<c2<<endl;
  cout<<"TLE x "<<c3<<endl;
  cout<<"RE x "<<c4<<endl;
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int i=0;i<n;i++){
      arr[i]=s.nextInt();
    }
    int[] dp=new int[n];
    dp[0]=0;
    
    for(int i=1;i<n;i++){
      int a=Math.max(0,i-k);
      dp[i]=Integer.MAX_VALUE;
      for(int j=a;j<i;j++){
      dp[i]=Math.min(Math.abs(arr[i]-arr[j])+dp[j],dp[i]);
      }
    }
    System.out.println(dp[n-1]);
  }
    
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N, M;
    cin >> N >> M;

    vector<int> x(M), y(M);
    rep(i, M) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
    }

    set<int> s;
    s.insert(0);

    vector<int> v(N, 1);
    rep(i, M) {
        if (s.find(x[i]) != s.end()) {
            // 赤いボールが入っている
            if (v[ x[i] ] == 1) s.erase(x[i]);
            s.insert(y[i]);
        }
        v[ x[i] ]--;
        v[ y[i] ]++;
    }

    cout << s.size() << endl;
}

Measured memory_bytes: 6144
K,S = map(int,input().split())
one = 0
three = 0
six = 0
if S%3==0:
    one = 1
else:
    one = 0
for l in range(K+1):
    if (S-l)%2==0 and (S-l)//2 <= K and (S-l)>=0:
        three += 1
for m in range(K-1):
    for n in range(m+1,K):
        rest = S-(m+n)
        if rest>n and rest<=K:
          six += 1
print(one+3*(three-one)+6*six)

Measured memory_bytes: 3064
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int dp[20][65536];

int main(int argc, char **argv)
{
        int n, m;
        cin >> n >> m;
        vector<int> c(m);
        for (int i = 0; i < m; i++)
                cin >> c[i];
        sort(c.begin(), c.end());
        for (int i = 0; i < m; i++) {
                for (int j = 0; j <= n; j++) {
                        if (!i) {
                                dp[i][j] = j;
                        }
                        else if (j < c[i]) {
                                dp[i][j] = dp[i-1][j];
                        }
                        else {
                                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]] + 1);
                        }
                }
        }
        cout << dp[m-1][n] << endl;
        return 0;
}

Measured memory_bytes: 7112
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int S=scanner.nextInt();
        int W=scanner.nextInt();
        if(W>=S)
            System.out.println("unsafe");
        else
            System.out.println("safe");
    }
}


Measured memory_bytes: 35828
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int root = -1;
	for (int i = 0; i < N; ++i) {
		if (G[i].size() >= 3) {
			root = i;
			break;
		}
	}
	if (root == -1) {
		cout << 1 << endl;
	}
	else {
		vector<int> par(N, -1);
		vector<vector<int> > child(N);
		function<void(int, int)> make_order = [&](int pos, int pre) {
			par[pos] = pre;
			for (int i : G[pos]) {
				if (i == pre) continue;
				child[pos].push_back(i);
				make_order(i, pos);
			}
		};
		make_order(root, -1);
		vector<int> dp(N);
		function<void(int)> dfs1 = [&](int pos) {
			vector<int> res;
			for (int i : child[pos]) {
				dfs1(i);
				res.push_back(dp[i]);
			}
			if (!res.empty()) {
				sort(res.begin(), res.end(), greater<int>());
				for (int i = 0; i < int(res.size()) - 1; ++i) {
					dp[pos] += max(res[i], 1);
				}
				dp[pos] += res.back();
			}
		};
		dfs1(root);
		cout << dp[root] << endl;
	}
	return 0;
}

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

int main() {
  string strMxWC, strMxWL, str;
  map<string,int> mp;
  
  while(cin>>str) {
    mp[str]++;
    if(mp[strMxWC]<mp[str]) strMxWC=str;
    if(strMxWL.size()<str.size()) strMxWL=str;
  }
  cout << strMxWC << " " << strMxWL << endl;
  
  return 0;
}

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

long long int f(long long int n)
{
	long long int s=0;
	while(n!=0)
	{
		s+=(n%10);
		n/=10;
	}
	return s;
}

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

	long long int n,su;
	cin>>n;
	su=f(n);
	
	if(n%su==0)
		cout<<"Yes";
	else
		cout<<"No";
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        Integer[] nums = new Integer[N];
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            int a = scanner.nextInt();
            nums[i] = a;
            sum += a;
        }
        scanner.close();

        double limit = sum / (4.0 * M);

        Arrays.sort(nums, Collections.reverseOrder());

        if (nums[M - 1] < limit) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }
}


Measured memory_bytes: 23508
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
struct three{
	ll a,b,c;
};
void solve()
{
  ll n;cin>>n;
  std::vector<ll> v(n);
  // std::map<, value> map;
  rep(i,n)cin>>v[i];
  sort(entire(v));

  ll res=0;
  rep(i,n)
  	repe(j,1+i,n)
  		repe(k,j+1,n)
  			if(v[j]+v[i]>v[k] && v[i]!=v[k] && v[j]!=v[k] && v[i]!=v[j])
  				res++;
  	cout<<res<<endl;
}


int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast
  int T=1;
  // cin >> T;
  while (T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const long long llinf=9223372036854775807ll;
const int N=100005;
int n,m,q,tot,fst[N],pnt[N*2],nxt[N*2],ans[N],dp[N][11],a,b;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a>>b;
		pnt[++tot]=b;
		nxt[tot]=fst[a];
		fst[a]=tot;
		pnt[++tot]=a;
		nxt[tot]=fst[b];
		fst[b]=tot;
	}
	cin>>q;
	for(int i=1;i<=q;i++)
		cin>>a>>b>>ans[i],dp[a][b]=i;
	for(int i=9;i>=0;i--)
		for(int x=1;x<=n;x++)
		{
			dp[x][i]=max(dp[x][i],dp[x][i+1]);
			for(int j=fst[x];j;j=nxt[j])
				dp[x][i]=max(dp[x][i],dp[pnt[j]][i+1]);
		}
	for(int i=1;i<=n;i++)
		cout<<ans[dp[i][0]]<<'\n';
	return 0;
}

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

int main(){
    string a,b;
    int x=0;
    cin>>a;
    while(1){
        cin>>b;
        if(b=="END_OF_TEXT"){
            break;
        }
        for(int i=0;i<b.size();i++){
            if(isupper(b[i])){
                b[i]=tolower(b[i]);
            }
        }
        if(a==b){
            x+=1;
        }
    }
    cout<<x<<endl;
}


Measured memory_bytes: 3048
#include <iostream>
#include <climits>

void init_nums(int nums[])
{
	nums[0] = nums[1] = nums[2] = 0;
}

int cost(int nums[])
{
	int A = nums[0];
	int B = nums[1];
	int C = nums[2];
	
	int qA = A / 5;
	int rA = A % 5;
	int qB = B / 4;
	int rB = B % 4;
	int qC = C / 3;
	int rC = C % 3;
	
	return 1520 * qA + 380 * rA + 1870 * qB + 550 * rB + 2244 * qC + 850 * rC;
}

int minCost(int a, int nums[])
{
	if (a==0) return cost(nums);
	
	int res = INT_MAX;
	
	if (a>=500) {
		nums[2]++; 
		res = std::min(res, minCost(a-500, nums));
		nums[2]--;
	}
	if (a>=300) {
		nums[1]++;
		res = std::min(res, minCost(a-300, nums));
		nums[1]--;
	}
	if (a>=200) {
		nums[0]++;
		res = std::min(res, minCost(a-200, nums));
		nums[0]--;
	}
	
	return res;
}

int main()
{
	int a;
	int nums[3];
	while (true) {
		std::cin >> a;
		if (a == 0) break;
		init_nums(nums);
		std::cout << minCost(a, nums) << std::endl;
	}
	return 0;
}




Measured memory_bytes: 3100
#include<stdio.h>

int main(void){
  int n,m,i,j,a,b,upmax=0,downmax=0;
  int up[100], down[100];
  for(i=0;i<100;i++){
    up[i]=0;
    down[i]=0;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&m);
    scanf("%d",&a);
    for(j=0;j<m-1;j++){
      b=a;
      scanf("%d",&a);
      if(b>a){
	if(b-a>downmax) downmax=b-a;
      }else{
	if(a-b>upmax) upmax=a-b;
      }
    }
    up[i]=upmax;
    down[i]=downmax;
    downmax=0;
      upmax=0;
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",up[i],down[i]);
  }
  return 0;
}

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

    int n,ac=0,wa=0,tle=0,re=0;
    cin>>n;
    while(n--)
    {
        string s;cin>>s;
        if(s=="AC")
            ac++;
        if(s=="WA")
            wa++;
        if(s=="TLE")
            tle++;
        if(s=="RE")
            re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;

}



Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 100005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, k, f[MAXN], a[MAXN];

int main()
{
	scanf("%d%d", &n, &k);
	for(rint i=1; i<=n; ++i) scanf("%d", &a[i]);
	for(rint i=1; i<=k; ++i)
	{
		for(rint j=1; j<=n; ++j)
			if(a[j]<=i && !f[i-a[j]]) f[i]=1;
	}
	if(f[k]) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    int n, k; cin>>n>>k;
    set<int> s;
    For(i, 0, k){
        int a; cin>>a;
        For(j, 0, a){
            int b; cin>>b;
            s.insert(b);
        }
    }
    cout<<n-sz(s);
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}





Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int h,w;
string g[55];
bool memo[55][55];

void solve(int i,int j){
  rep(k,4){
    int x=i+dx[k];
    int y=j+dy[k];
    if(x<0||h<=x||y<0||w<=y||g[x][y]=='.'||memo[x][y]) continue;
    memo[i][j]=1;
    memo[x][y]=1;  
    solve(x,y);
  }
}

int main(){
  cin>>h>>w;
  rep(i,h){
    cin>>g[i];
  }
  rep(i,h){
    rep(j,w){
      if(!memo[i][j]&&g[i][j]=='#'){
        solve(i,j);
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if(g[i][j]=='#'&&!memo[i][j]){
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");

  return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N, M;
	set<P> s;
	P in;

	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> in.first >> in.second;
		s.insert(in);
	}
	cin >> M;
	for(int i = 0; i < M; i++){
		cin >> in.first >> in.second;
		s.insert(in);
	}

	for(auto it = s.begin(); it != s.end(); it++){
		auto next = it; next++;
		P now = *it;
		cout << now.first << ":";
		if(now.second/10)
			cout << now.second;
		else
			cout << 0 << now.second;
		if(next != s.end())
			cout << " ";
	}
	cout << endl;

	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    cout << n << ":";

    for (int i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            cout << " " << i;
            n /= i;
        }
    }
    if (n != 1) {
        cout << " " << n;
    }
    cout << endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------

void _main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h) * (W - w) << endl;
}

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

long long N,H,W,D,x[100009],y[100009],dp[1000009];

int main(){
	cin>>H>>W>>D;
	for(int i=1;i<=H*W;i++){
		int p;cin>>p;
		x[p]=(i-1)/W;y[p]=(i-1)%W;
	}
	N=H*W;
	
	for(int i=1;i<=N;i++){
		if(i<=D) dp[i]=0;
		else{
			dp[i]=dp[i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D]);
		}
	}
	int Q;cin>>Q;
	for(int i=1;i<=Q;i++){
		int L,R;cin>>L>>R;
		cout<<dp[R]-dp[L]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4864
from itertools import combinations
 
n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
 
fail = lambda x: not all(a[i][0].isdisjoint(x) and a[i][1] < x for i in x)
 
while all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)

Measured memory_bytes: 3064
import string

n = int(input())
s = input()
alp = list(string.ascii_lowercase)
ans = 0

for i in range(n):
    s1 = s[:i]
    s2 = s[i:]
    cnt = 0
    for c in alp:
        if c in s1 and c in s2:
            cnt += 1
    ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 9924
N = int(input())
As = [int(i) for i in input().split(" ")]
Bs = [0 for _ in range(N)]
for i in reversed(range(N)):
  s = 0
  for j in range(i, N, i+1):
    s += Bs[j] 
  Bs[i] = (s % 2) ^ As[i] 
print(len([b for b in Bs if b == 1]))
for i, b in enumerate(Bs):
    if b == 1:
       print(i + 1, end=" ")


Measured memory_bytes: 7792
if __name__ == "__main__":
    inputStrings = str(input())
    outputStrings = []
    isNextA = True
    for i in inputStrings:
        if isNextA == True and i == "A":
            outputStrings.append(i)
            isNextA = False
        elif isNextA == False and i == "Z":
            outputStrings.append(i)
            isNextA = True

    if outputStrings != []:
        if outputStrings[-1] == "A":
            outputStrings.pop(-1)

    output = str()
    for i in outputStrings:
        output += i
    
    if len(output) > 1:
        print(output)
    else:
        print("-1")
        



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

int n;
vector<int> x, y;

void input() {
    cin >> n;
    x = y = vector<int>(n);
    rep(i, n) cin >> x[i] >> y[i];
}

double distancexy(int i, int j) {
    double d = pow((x[i] - x[j]), 2);
    d += pow(y[i] - y[j], 2);
    return sqrt(d);
}

ll fact(int v) {
    ll m = v;
    for (int i = 2 ; i < v; i++) m *= i;
    return m;
}

int main() {
    input();
    double ans = 0;
    vector<int> v(n);
    rep(i, n) v[i] = i;
    do {
        rep(i, n-1) ans += distancexy(v[i], v[i+1]);
    } while (next_permutation(v.begin(), v.end()));
    ans /= fact(n);
    cout << fixed << setprecision(10) << ans << endl;
}


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

const int MAX_V = 1000000000;

int N, W;
int w1, ans;
int vs[4];
vector<int> V[4];

void input_data(void) {
	int wn, val;

	cin >> N >> W;
	for (int i = 0; i < 4; ++i) {
		V[i].clear();
		V[i].push_back(MAX_V);
	}
	cin >> w1 >> val;
	V[0].push_back(val);
	for (int i = 1; i < N; ++i) {
		cin >> wn >> val;
		V[wn - w1].push_back(val);
	}
	for (int i = 0; i < 4; ++i)
		sort(V[i].begin(), V[i].end(), greater<int>());
}

void calcu(void) {
	for (int i = 0; i < 4; ++i) {
		vs[i] = V[i].size() - 1;
		V[i][0] = 0;
		if (vs[i] == 0)
			continue;
		vs[i] = min(vs[i], W / (w1 + i));
		for (int j = 1; j <= vs[i]; ++j)
			V[i][j] += V[i][j - 1];
	}
}

void solve(void) {
	int w_sum, v_sum;
	for (int a = vs[0]; a >= 0; --a) {
		for (int b = vs[1]; b >= 0; --b) {
			w_sum = w1 * a + (w1 + 1) * b;
			if (w_sum > W)
				continue;
			for (int c = vs[2]; c >= 0; --c) {
				w_sum = w1 * a + (w1 + 1) * b + (w1 + 2) * c;
				if (w_sum > W)
					continue;
				for (int d = vs[3]; d >= 0; --d) {
					w_sum = w1 * a + (w1 + 1) * b + (w1 + 2) * c + (w1 + 3) * d;
					if (w_sum > W)
						continue;
					v_sum = V[0][a] + V[1][b] + V[2][c] + V[3][d];
					if (v_sum > ans) {
						ans = v_sum;
						break;
					}
				}
			}
		}
	}
}

int main(void) {
	input_data();
	calcu();
	ans = 0;
	solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,i;
	char c[11];
	scanf("%d",&a);
	getchar();
	scanf("%s",c);
	scanf("%d",&b);
	for(i=0;i<a;i++)
	{
		if(c[i]==c[b-1])
			printf("%c",c[i]);
		else
			printf("*");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char a,c;
    int n,b,i,j,k;
    int cards[4][13];
    for(i=0;i<4;i++){
        for(j=0;j<13;j++) cards[i][j]=0;
    }
    
    scanf("%d",&n);
    for(k=1;k<=n;k++){
        scanf("%c",&c);
        scanf("%c %d",&a,&b);
        if(a=='S') i=0;
        if(a=='H') i=1;
        if(a=='C') i=2;
        if(a=='D') i=3;
        
        cards[i][b-1]=1;
    }
    
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(cards[i][j]==0){
               if(i==0) printf("S %d\n",j+1);
               if(i==1) printf("H %d\n",j+1);
               if(i==2) printf("C %d\n",j+1);
               if(i==3) printf("D %d\n",j+1);
               
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2044
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64
    }

    let mut n2 = 0;
    for i in 0..3 {
        let k = (n / 10_u64.pow(i)) % 10;
        n2 += (10 - k) * 10_u64.pow(i);
    }
    println!("{}", n2);
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
	int N,M;
	char S[4001],T[4001];
	int dp[4000][4000][2];
int main() {

	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			dp[i][j][1] = -0x7ffffff;
			dp[i][j][0] = 0;
		}
	}
	scanf("%s", S + 1);
	scanf("%s", T + 1);
	int MAX = 0;
	for (int s = 0; s <= N; s++) {
		for (int t = 0; t <= M; t++) {
			if (s < N&&S[s + 1] == 'I') {
				dp[s + 1][t][1] = max(dp[s + 1][t][1], dp[s][t][0] + 1);
				MAX = max(MAX, dp[s+1][t][1]);
			}
			if (t < M&&T[t + 1] == 'I') { 
				dp[s][t + 1][1] = max(dp[s][t + 1][1], dp[s][t][0] + 1); 
				MAX = max(MAX, dp[s][t+1][1]);
			}
			if (s < N&&S[s + 1] == 'O') {
				dp[s + 1][t][0] = max(dp[s + 1][t][0], dp[s][t][1] + 1);
				//MAX = max(MAX, dp[s+1][t][0]);
			}
			if (t < M&&T[t + 1] == 'O') {
				dp[s][t + 1][0] = max(dp[s][t + 1][0], dp[s][t][1] + 1);
				//MAX = max(MAX, dp[s][t+1][0]);
			}
		}
	}
	cout << MAX << endl;
	return 0;
}



Measured memory_bytes: 42692