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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    const int N = 3;
    vvi c(N+1, vi(N+1));
    REP1(i, N)
    {
        REP1(j, N)
        {
            cin >> c[i][j];    
            if(j > 1) c[i][j] -= c[i][1];
        }
    }

    for(int j = 2; j <= N; j++)
    {
        for(int i = 1; i < N; i++)
        {
            if(c[i][j] != c[i+1][j])
            {
                cout << "No" << endl;
                return;
            }
        }
    }
    cout << "Yes" << endl;
}

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

    solve();

    return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split(' ');
            if (int.Parse(a[0]) % 2 == 0 || int.Parse(a[1]) % 2 == 0)
            {
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");

            };



        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;

void solve(void){
  llint ret = 0;

  int n;
  std::cin >> n;

  llint now_takasa = 0;
  llint prev = -1;
  for(int i=0; i<n; i++){
    llint tmp;
    std::cin >> tmp;
    now_takasa += prev-tmp;
    now_takasa = std::max(0LL, now_takasa);
    
    ret += now_takasa;
    prev = tmp;
  }
  std::cout << ret << std::endl;
  return;
}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 3600
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e13
var mod = 1000000007

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	W := next.Int()
	a := next.Int()
	b := next.Int()
	r := inf
	if in(b, a, a+W+1) || in(b+W, a, a+W+1) {
		r = 0
	}
	fmt.Println(min(abs(a+W-b), abs(a-b-W), r))
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a []int) int {
	r := 0
	for i := 0; i < len(a); i++ {
		r += a[i]
	}
	return r
}

func pow(a []int) int {
	r := 1
	for i := 0; i < len(a); i++ {
		r *= a[i]
	}
	return r
}

func fill(a []int, n int) []int {
	for i := 0; i < len(a); i++ {
		a[i] = n
	}
	return a
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

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

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) String() string {
	return s.next()
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Ints(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = s.Int()
	}
	return r
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <stdio.h>

const int bit[17] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536};
int N, a[17][17];
long long dp[65536], sum[65536];

long long recursion(int n)
{
	if (dp[n] >= 0) return dp[n];
	else dp[n] = sum[n];
	
	int i, j, k, m, b[17];
	long long tmp;
	for (i = 0, m = 0; i < N; i++) if ((n & bit[i]) == bit[i]) b[m++] = i;
	k = bit[b[0]];
	while (k < bit[b[m-1]]) {
		tmp = recursion(k) + recursion(n ^ k);
		if (tmp > dp[n]) dp[n] = tmp;
		for (i = 0; (k & bit[b[i]]) != 0; i++);
		for (k ^= bit[b[i--]]; i >= 0; k ^= bit[b[i--]]);
	}
	return dp[n];
}
 
int main()
{
	int i, j, k;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) scanf("%d", &(a[i][j]));
	}
	for (i = 1, dp[0] = 0; i < bit[N]; i++) dp[i] = -1;
	for (k = 0; k < bit[N]; k++) {
		for (i = 0, sum[k] = 0; i < N; i++) {
			if ((k & bit[i]) == 0) continue;
			for (j = i + 1; j < N; j++) if ((k & bit[j]) != 0) sum[k] += a[i][j];
		}
	}
	printf("%lld\n", recursion(bit[N] - 1));
	fflush(stdout);
	return 0;
}

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

bool check(int L,int R,int i,int j)
{
    int x=L+(i-L%2019);
    if(x<L) x+=2019;
    int y=R-(R%2019-j);
    if(y>R) y-=2019;
    return x<y;
}

int main()
{
    int L,R; cin>>L>>R;
    int ans=1e9;
    for(int i=0;i<2019;i++) for(int j=0;j<2019;j++){
        if(check(L,R,i,j)){
            ans=min(ans,(i*j)%2019);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void change(int *x, int *y);

int n,m,x;
int a[101];

int rec;

int main(void){
	scanf("%d %d %d", &n, &m, &x);
	for(int i=0;i<m;i++)	scanf("%d", &a[i]);

	for(int i=0;i<=m-1;i++){
		if(a[i]>x){
          	rec=i;break;
        }
		if(i==m-1){
			printf("0");
			return 0;
		}
	}

	if(rec > m-rec)	printf("%d", m-rec);
	else	printf("%d", rec);

	return 0;
}

void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (size_t i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};


const static int MAX = 200;
llong d[MAX + 1][MAX + 1];

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, q;
    cin >> a >> b >> q;
    vector<llong> shrine(a + 2), temple(b + 2);
    shrine[0] = -INF, temple[0] = -INF;
    shrine[a + 1] = INF, temple[b + 1] = INF;
    rep(i, a) cin >> shrine[i + 1];
    rep(i, b) cin >> temple[i + 1];

    rep(i, q) {
        llong x;
        cin >> x;

        auto itrs = lower_bound(all(shrine), x);
        auto itrt = lower_bound(all(temple), x);

        llong ans = INF;
        ans = min(ans, max(*itrs, *itrt) - x);
        ans = min(ans, x - min(*(itrs - 1), *(itrt - 1)));
        ans = min(ans, *itrt - x + *itrt - *(itrs - 1));
        ans = min(ans, *itrs - x + *itrs - *(itrt - 1));
        ans = min(ans, x - *(itrt -1)+ *itrs - *(itrt - 1));
        ans = min(ans, x - *(itrs - 1) + *itrt - *(itrs - 1));

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
	vector<int> a(MAX);
	vector<int> box(MAX);
	int n,sum,k=0,l,r,mid;
	for(int i=0;i<MAX;i++)
	a[i]=1;
	a[0]=0;a[1]=0;
	for(int i=0;i*i<MAX;i++)
	if(a[i]){
		for(int j=i*2;j<MAX;j+=i)
		a[j]=0;
	}
	for(int i=0;i<MAX;i++)
	if(a[i])
	box[k++]=i;
	while(cin>>n,n){
		sum=0;
		for(int i=0;box[i]<n;i++){
			if(box[i]*2<n)
			continue;
				l=0;r=i;
				while(r-l>1){
					mid=(r+l)/2;
					if(box[mid]>=n-box[i]){
						r=mid;
					}else {
						l=mid;
					}
				}
			if(box[r]+box[i]==n){
				sum++;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

int i, rs;
long long A, B, C;

int main() {
  ios_base::sync_with_stdio(0);

  cin >> A >> B >> C;

  while(1) {
    if(rs > 1e8) return cout << "-1\n", 0;
    if(A % 2 || B % 2 || C % 2) break;

    long long a = A / 2, b = B / 2, c = C / 2;

    A = b + c; B = a + c; C = a + b; ++rs;
  }

  cout << rs << '\n';

  return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    w, v = map(int, input().split())
    for j in range(1, W+1):
        if j-w >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
print(dp[N][W])


Measured memory_bytes: 119916
n = int(input())
a = list(map(int,input().split()))
b = []
c = []
cnt = 1
for i in range(n):
    b.append([a[i]+1,a[i],a[i]-1])
for i in range(n):
    cnt *= len(b[i])
for i in range(n):
    cnt2 = 0
    for j in range(len(b[i])):
        if b[i][j]%2 == 1:
            cnt2 += 1
    c.append(cnt2)
cnt3 = 1
for i in range(n):
    cnt3 *= c[i]
print(cnt-cnt3)


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

using namespace std;

const int N=1e5+10;
int n,t[N],a[N][2];
int main(){
        cin>>n;
        for(int i=1;i<=n;i++)
                cin>>t[i]>>a[i][0]>>a[i][1];
        for(int i=1;i<=n;i++){
                int dist=abs(a[i][0]-a[i-1][0])+abs(a[i][1]-a[i-1][1]);
                int len=t[i]-t[i-1];
                if (dist%2!=len%2||dist>len) {
                        cout<<"No";
                        return 0;
                }
        }
        cout<<"Yes";
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
    }

    ll cnt = 0;
    for (ll i = N - 1; i >= 0; i--) {
        A[i] += cnt;
        if (A[i] % B[i]) cnt += B[i] - (A[i] % B[i]);
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

set<int> s;

int main(){
	int x, n; scanf("%d%d", &x, &n);
	REP(i, n){
		int a; scanf("%d", &a);
		s.emplace(a);
	}
	REP(i, 100000){
		int a = i%2==0 ? x-i/2 : x+i/2;
		DEBUG(" %d\n", a);
		if(s.find(a) != s.end()) continue;
		printf("%d\n", a);
		return 0;
	}
}


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

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll sum=a*c;
    sum=max(sum,a*d);
    sum=max(sum,b*c);
    sum=max(sum,b*d);
    cout<<sum<<endl;
    return 0;
}


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

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    
    double mean = 0;
    for (int i = 0; i < A; i++) mean += v[i];
    mean /= A;
    ll com = 0;
    if (A < N && v[A] == v[A-1]) {
        int l = N;
        int r = 0;
        for (int i = 0; i < N; i++) {
            if (v[i] == v[A]) {
                l = min(l, i);
                r = max(r, i+1);
            }
        }
        if (v[0] != v[A]) {
            com = 1;
            for (int i = 1; i <= A-l; i++) {
                com = com * (r-l+1-i) / i;
            }
        } else {
            com = 0;
            for (int i = A; i <= min(r, B); i++) {
                ll c = 1;
                for (int j = 1; j <= i; j++) {
                    c = c * (r+1-j) / j;
                }
                com += c;
            }
        }
    } else {
        com = 1;
    }
    printf("%.10lf\n", mean);
    printf("%lld\n", com);
    
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto A = aryread();
    long s = A.sum();
    long cnt;
    foreach (a; A)
    {
        cnt += s <= 4 * a * M;
    }
    writeln(M <= cnt ? "Yes" : "No");

}


Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
	int n,m;
	scanf("%d",&n);
	vector<long long int>a(n);
	for(long long int &i:a){
		scanf("%lld",&i);
		}
	cin>>m;
	//cout<<"M"<<m<<endl;
	int sum=0;
	long long int x,y;
	while(m--){
		sum=0;
		cin>>x;
		cin>>y;
		for(int i=0;i<n;i++){
		if(i==(x-1)){
		  sum+=y;
		}
		else{
			sum+=a[i];
		}
	 }
	 cout<<sum<<endl;
  }
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int i = kb.nextInt();
		if (i % 2 == 0) {
			System.out.println(i / 2);
		} else {
			System.out.println(i / 2 + 1);
		}
		kb.close();
	}

}


Measured memory_bytes: 21844
import copy
N=int(input())
ans=[]
S=[int(input()) for i in range(N)]
W=copy.copy(S)
W.sort()
for i in range(N):
  if W[-1]==S[i]:
    ans.append(W[-2])
  else:
    ans.append(W[-1])
for j in range(N):
  print(ans[j])

Measured memory_bytes: 20956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dep(ll a, ll b){
	if(b==0){
		return a;
	}
	return dep(b,a%b);
}
int main() {
	ll n;
	cin>>n;
	ll ch[200010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	ll ans=0;
	ll now=1;
	for(ll i=0;i<n;i++){
		if(ch[i]!=now){
			ans++;
		}
		else{
			now++;
		}
	}
	if(ans==n){
		cout << -1;
		return 0;
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 5192
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 479001599;
const int maxn = 5e5 + 111;
        
using namespace std;          

int a[maxn], cnt[maxn], ans;
string s;

void solve(){
	cin >> s;

	int x = 0, k = 1;

	for (int i = sz(s) - 1; i >= 0; i--){
		x = ((k % 2019) * (s[i] - '0')) % 2019 + x;
		x %= 2019;
		a[i] = x;
		k *= 10;
		k %= 2019;
	}

	for (int i = 0; i < sz(s); i++)
		cnt[a[i]]++;

	ans += cnt[0] * (cnt[0] + 1) / 2;	

	for (int i = 1; i < 2019; i++){
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}

	cout << ans;
}   
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;

    //cin >> q;

    while (q--){
        solve();
    }
}

Measured memory_bytes: 5296
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A+1):
    ta = a * 500
    for b in range(B+1):
        tb = b * 100
        for c in range(C+1):
            if X == ta + tb + c*50:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>

void Frog(int &size, int stones[])
{
  int cost[size];
  cost[0] = 0;
  cost[1] = abs(stones[1] - stones[0]);
  
  for (int i = 2; i < size; i++)
  {
    cost[i] = std::min(abs(stones[i-2] - stones[i]) + cost[i-2], abs(stones[i-1] - stones[i]) + cost[i-1]);
  }
  
  printf("%d\n", cost[size-1]);
}
 
int main()
{
  int size;
  
  scanf("%d", &size);
  
  int stones[size];
  
  for (int i = 0; i < size; i++) scanf("%d", &stones[i]);
  
  Frog(size, stones);
  
  return 0;
}

Measured memory_bytes: 896
//#define _GLIBCXX_DEBUG //(compiler options)
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
using namespace std;
using ll = long long; using ull = unsigned ll; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> T mind(T &x, const T &y) {if (y < x) {T d = y-x; x = y; return d;} else return 0;} //RETURNS A NON-POSITIVE VALUE
template<typename T> T maxd(T &x, const T &y) {if (y > x) {T d = y-x; x = y; return d;} else return 0;}
template<typename C> int uniq(C &a) {a.erase(unique(all(a)), end(a)); return sz(a);}
template<typename C, typename F> int uniq(C &a, F cmp) {a.erase(unique(all(a), cmp), end(a)); return sz(a);}
const int mod = 1e9+7, infi = 1e9; const ll infl = 1e18; const ld infd = INFINITY;

#define x(a) real(a)
#define y(a) imag(a)
using G = ll; using point = complex<G>;
istream& operator>>(istream &is, point &p){G x, y; is >> x >> y; p = {x, y}; return is;}
ostream& operator<<(ostream &os, const point &p){os << p.x() << ' ' << p.y(); return os;}
G dot(const point &a, const point &b) {return (conj(a)*b).x();}
G crs(const point &a, const point &b) {return (conj(a)*b).y();}
G ori(const point &a, const point &b, const point &c) {return crs(b-a, c-b);};
bool cmpyx(const point &a, const point &b) {return a.y()<b.y() || (a.y()==b.y()&&a.x()<b.x());};

int main()
{
    #ifndef LOCAL
    //ifstream cin("hull.in"); ofstream cout("hull.out");
    #endif // LOCAL
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << setprecision(15);
    int n, m; cin >> n >> m;
    int c[10][10], d[10][10];
    for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j) cin >> c[i][j], d[i][j] = c[i][j];
    for(int k = 0; k < 10; ++k) for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j) {
        mind(d[i][j], d[i][k] + d[k][j]);
    }
    int ans = 0;
    for(int i = 0; i < n*m; ++i) {
        int x; cin >> x;
        if (x != -1) ans += d[x][1];
    }
    cout << ans;
}



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

int main() {
	int n,i;
	cin >> n;
	int box[100000];
	for (i = 0; i < n; i++) {
		cin >> box[i];
	}
	for (i = (n-1); i >= 0; i--) {
		cout << box[i];
		if (i != 0) {
			cout << " ";
		}
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3100
! 2019.12.8
!
      program answer
      implicit none
      character(len=100) :: S
      integer :: S_N
      integer :: ans
      integer :: i
      intrinsic len_trim
!
      read(*,*) S
      S_N = len_trim(S)
!
      ans = 0
      do i=1,S_N/2
        if(S(i:i) == S(S_N-i+1:S_N-i+1)) then
        else
          ans = ans+1
        end if
      end do
      write(*,*) ans
      end program answer

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s,ss;
    cin>>s>>ss;

    string S = s+ss;
    //cout<<S<<endl;
    ll n=0;
    for(ll i=0;i<S.size();i++)
    {
        S[i]-=48;
        n = n*10+S[i];
       // cout<<n<<endl;
    }
    ll sq = sqrt(n);
    if(sq*sq==n) cout<<"Yes\n";
    else cout<<"No\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
#define int long long
int H,W;
int32_t main() {
    cin >> H >> W;
    if(H < W)
        for(int j = 0; j < W;++j)
            cout<<H;
    else
        for(int j = 0; j < H;++j)
            cout<<W;
    return 0;
}

Measured memory_bytes: 256
# W
# N K
# A1 B1
# A2 B2
# :
# AN BN

n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))



dp = list(range(n + 1))

for ci in range(3):
    for wi in range(a_list[ci], n + 1):
        dp[wi] = max(dp[wi - a_list[ci]] + b_list[ci], dp[wi])



n = dp[-1]
dp = list(range(n + 1))


for ci in range(3):
    for wi in range(b_list[ci], n + 1):
        dp[wi] = max(dp[wi - b_list[ci]] + a_list[ci], dp[wi])




print(dp[-1])

Measured memory_bytes: 230424
#include <bits/stdc++.h>
using namespace std;
#define int long long



int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int K;
	int A , B;
	cin >> K >> A >> B;
	int in = K;
	while (K <= 1000)
	{
		if (A <= K && K <= B)
		{
			cout<<"OK"<<endl;
			exit(0);
		}
		K += in;
	}
	cout<<"NG"<<endl;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] num = new int[100010];
        for(int i = 0; i < n; i++) num[scan.nextInt()]++;
        int out = 0;
        for(int i = 1; i < 100009; i++){
            out = Math.max(num[i - 1] + num[i] + num[i + 1], out);
        }
        System.out.println(out);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 59388
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string s[100];
int cur;
int dfs(int d){
    int ret;
    if(isdigit(s[cur][d])) return s[cur++][d]-'0';
    else{
        if(s[cur][d]=='+'){
            ret=0;
            ++cur;
            while(s[cur].size()==d+2)ret+=dfs(d+1);
        }
        else if(s[cur][d]=='*'){
            ret=1;
            ++cur;
            while(s[cur].size()==d+2)ret*=dfs(d+1);
        }
    }
    return ret;
}
int main(){
    int n;
    while(cin>>n,n){
        cur=0;
        rep(i,100) s[i].clear();
        rep(i,n) cin>>s[i];
        cout<<dfs(0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {

	public static long MOD = 998_244_353;
	public static void main (String[] args)  {
	
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (sc.nextInt()!=0) {
			System.out.println(0);
			return;
		}
		long[]count = new long[n];
		count[0]=1;
		for (int i=1;i<n;i++) {
			int d =sc.nextInt();
			if (d==0 || d>=n) {
				System.out.println(0);
				return;
			} else {
				count[d]++;
			}
		}
		
		long ans = 1;
		for (int i=0;i<n-1;i++) {
			ans=ans*pow(count[i],count[i+1])%MOD;
			
		}
		System.out.println(ans);


	}
	static long pow(long a, long b) {
		if (b==0) {
			return 1;
		} else if (b%2==0) {
			long tmp = pow(a,b/2);
			return tmp*tmp%MOD;
		} else {
			long tmp = pow(a,b/2);
			return tmp*tmp%MOD*a%MOD;
		}
	}

}


Measured memory_bytes: 50640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    
    for(int i = 1; i <= N;i++){
        if(i%3 == 0 || i%5 == 0) continue;
        res += i;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
  char str[31000];
  int in1,in2,dist = 0,cnt = 1;
  gets(str, sizeof(str), stdin);
  sscanf(str, "%d %d",&in1,&in2);
  
  int i,dis[in1];
  
  gets(str, sizeof(str), stdin);
  dis[0] = atoi(strtok(str," "));
  for(i = 1;i < in1;i++){
    dis[i] = atoi(strtok(NULL," "));
   
  }
  
  for(i = 0;i < in1;i++){
   dist += dis[i];
    if(dist <= in2){
      cnt++;
    }else{
      break;
    }
  }
  
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
int a, b, c, d;
int main()
{
	ios::sync_with_stdio(false);
	cin >> a >> b >> c >> d;
	if( d >= abs( c -a ) || ( d >= abs( b - a ) && d >= abs( c - b )))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

string s;
vector<string> ss;
void f(int i, int k, int N) {
	if(i==N) {
		ss.PB(s);
		return;
	}
	REP(j, k+1) {
		s[i]='a'+j;
		f(i+1, max<int>(k, j+1), N);
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		s = string(N, ' ');
		ss.clear();
		f(0, 0, N);
//		sort(ALL(ss));
		REP(i, ss.size()) {
			cout<<ss[i]<<endl;
		}
//		break;
	}
	
	return 0;
}


Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#define N 100010
using namespace std;
vector<int> v[N]; //2次元配列  隣接リスト
int n, m, a, b;
int q[N * 2]={}, head, tail;
bool pd[N]={}; //既に訪れているか否か

void find(int now, bool front)
{
    int to;
    for (int i = 0; i < v[now].size(); i++)
    {
        to = v[now][i];
        if (!pd[to])
        {
            pd[to] = true;
            if (front)
                q[++tail] = to;
            else
                q[--head] = to;
            find(to, front);
            break;
        }
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++) //連結リストの作成
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    head = N;
    tail = N;
    q[head] = 1;
    pd[1] = true;
    find(1, true);
    find(1, false);
    cout << tail - head + 1 << endl;
    for (int i = head; i <= tail; i++)
    {
        cout << q[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 6784
def rec(a, b):
    if b == 0:
        return a
    return rec(b, a % b)

def main():
    while True:
        try:
            i, j = map(int, input().split())

            gcd = rec(i, j)
            lcm = i * j // gcd

            print(gcd, lcm)
        except:
            break

if __name__ == '__main__':
    main()

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

int main(void) {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    // レートを400で割った値で判定
    // 0=灰, 1=茶, ..., 8=自由
    int color[9] = {0};
    for (int i = 0; i < N; i++) {
        if (a[i] < 3200) {
            color[a[i]/400]++;
        } else {
            color[8]++;
        }
    }
    int max = 0, min = 0;
    for (int i = 0; i < 9; i++) {
        if (i == 8) {
            max += color[8];
        } else if (color[i] != 0) {
            max++;
            min++;
        }
    }
    if (min == 0) {
        min = 1;
    }

    cout << min << " " << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N;


int main(int argc, char const *argv[]) {
  std::cin >> N;
  std::vector<int> v;
  std::vector<int> before;

  for (size_t i = 0; i < N; i++) {
    int c;
    std::cin >> c;
    v.push_back(c);
    before.push_back(c);
  }

  std::sort(v.begin(), v.end());
  for (size_t i = 0; i < N; i++) {
    int idx = before[i];
    for (size_t j = N-1; j > 0; j--) {
      // std::cout << "here" << '\n';
      if (idx != v[j]) {
        std::cout << v[j] << '\n';
        break;
      } else {
        std::cout << v[j-1] << '\n';
        break;
      }
    }
  }


  return 0;
}


Measured memory_bytes: 3436
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 233333;
int n,a[N],b[N]; ll ans;
int main() {
	read(n); rep(i,1,n)read(a[i]),read(b[i]);
	bool flag=1; rep(i,1,n) flag&=a[i]==b[i]; if (flag) {puts("0"); return 0;}
	ll mn=1e10;
	rep(i,1,n) if (a[i]<=b[i]) ans+=a[i]; else ans+=a[i],mn=min(mn,1LL*b[i]);
	if (mn<1e10) ans-=mn;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int gcd(int a,int b){
	while(a){
		b%=a;swap(a,b);
	}
	return b;
}
int main(){
	int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
	int A=ABS(a-c);
	int B=ABS(b-d);
	int G=gcd(A,B);
	A/=G;
	B/=G;
	int ret=A+B-1;

	ret*=G;
	printf("%d\n",ret);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int cnt=0;
string s;
int main(){
	cin >> s;
	for (int i=1;i<s.length();i++){
		if (s[i-1]!=s[i]){
			cnt++;
		}
	}
	cout << cnt << "\n";
	return 0;
}

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

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

	string ans = "No";
	int n = 2 * N - 1;
	vector<int> v( n );
	if( 1 < x && x < n ) {
		ans = "Yes";
		int n2 = n / 2;
		v[n2 - 1] = x - 1;
		v[n2] = x;
		v[n2 + 1] = x + 1;
		int j = 1;
		for( int i = 0; i < n2 - 1; i++ ) {
			if( j == x - 1 ) j = x + 2;
			v[i] = j;
			j++;
		}
		for( int i = n2 + 2; i < n; i++ ) {
			if( j == x - 1 ) j = x + 2;
			v[i] = j;
			j++;
		}
	}

	cout << ans << endl;
	if( ans == "Yes" ) {
		for( int i = 0; i < n; i++ ) {
			cout << v[i] << endl;
		}
	}
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
char st[10];
int n;
map <string,int> mp;
int main(){
//	freopen("x.txt","r",stdin);
	scanf("%d\n",&n);
	for(int i=1;i<=n;++i){
		cin>>st;
//		cout<<st<<endl;
		mp[st]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
	return 0;
}

Measured memory_bytes: 3684
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

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

int main() {
    
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i,N) cin >> d[i];

    long long ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll n, m;
ll a, b, c;

struct Triple {
  ll a, b, c;
};

vector<Triple> v;

inline ll val(Triple x) {
  return x.a*a+x.b*b+x.c*c;
}

bool cmp(Triple x, Triple y) {
  return  val(x) < val(y);
}

ll anw = 0;
void solve(ll aa, ll bb, ll cc) {
  a = aa;
  b = bb;
  c = cc;
  sort(v.rbegin(), v.rend(), cmp);

  ll cur = 0;
  for (int i = 0; i < m; i++) {
      cur += val(v[i]);
  }
  anw = max(anw, cur);
}

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n >> m;
  v.resize(n);

  for (int i = 0; i < n; i++) {
    cin >> v[i].a >> v[i].b >> v[i].c;
  }

  solve(1, 1, 1);
  solve(1, 1, -1);
  solve(1, -1, 1);
  solve(1, -1, -1);
  solve(-1, 1, 1);
  solve(-1, 1, -1);
  solve(-1, -1, 1);
  solve(-1, -1, -1);

  cout << anw << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
int v[MAXN];
char s[MAXN];
int main(){
    cin>>n;
    int a,b;
    cin>>a>>b;
    int flag=0;
    REP(i,a,b)if(i%n==0)flag=1;
    if(flag)cout<<"OK";
    else cout<<"NG";
}

Measured memory_bytes: 3108
N, M = map(int, input().split())
parent = [i for i in range(N + M)]
rank = [1] * (N + M)
def find(x):
    if x == parent[x]:
        return x
    parent[x] = find(parent[x])
    return parent[x]

def unite(x, y):
    x, y = find(x), find(y)
    if x == y:
        return
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
    parent[y] = x
for i in range(N):
    for l in list(map(int, input().split()))[1:]:
        # 言語はparentの後半
        unite(i, N + l - 1)
if all(find(0) == find(i) for i in range(N)):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 12592
#include <stdio.h>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, i;
    cin >> n;
    vi a(n), b(n), c(n);
    for (i=0;i<n;i++) cin >> a[i];
    for (i=0;i<n;i++) cin >> b[i];
    for (i=0;i<n-1;i++) cin >> c[i];
    
    for (i=0;i<n;i++) a[i]--;
   
    int preb_i = -2;
    int score = 0;
    for (i=0;i<n;i++){
        score += b[a[i]];
        if (preb_i+1 == a[i])
            score += c[preb_i];
        preb_i = a[i];
    }
    cout << score << endl;
}




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

using namespace std;

typedef pair<int, int> P;

int main() {
    int n, m, a, b, c;
    int days[400];
    int count[400];
    vector<P> path[400];
    queue<int> q;
    cin >> n >> m;
    for (int i=0; i<n ;i++) {
        count[i] = 0;
    }
    for (int i=0; i<m; i++) {
        cin >> a >> b >> c;
        path[a].push_back(P(b, c));
        count[b]++;
    }
    for (int i=0; i<n; i++) {
        days[i] = 0;
    }
    q.push(0);
    while (!q.empty()) {
        int a = q.front();
        q.pop();
        for (int i=0; i<(int)path[a].size(); i++) {
            int b = path[a][i].first;
            int c = path[a][i].second;
            days[b] = max(days[b], days[a]+c);
            count[b]--;
            if (count[b] == 0) {
                if (b == n-1) {
                    cout << days[n-1] << endl;
                    return 0;
                }
                q.push(b);
            }
        }
    }
    return 1;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
	ll a,b;
	cin >> a >> b;
	a=a%b;
	cout << min(a,b-a) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string.h>
#include<algorithm>
using namespace std;

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

	if(d==25)cout << "Christmas" << endl;
	if (d == 24)cout << "Christmas Eve" << endl;
	if (d == 23)cout << "Christmas Eve Eve" << endl;
	if (d == 22)cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
# n, k = (2*10**5, 10)


ranges = []
for i in range(k):
    l, r = map(int, input().split())
    # f = (2 * 10 ** 5) // k
    # l, r = (f * i, f*(i+1))
    ranges.append((l, r))

mod = 998244353
counts = [0]*(n+1)
sum_dp = [0]*(n+2)
counts[0] = 1
sum_dp[1] = 1
for i in range(1, n+1):
    for r in ranges:
        left = max(0, i - r[1])
        right = max(0, i - r[0] + 1)
        counts[i] += (sum_dp[right] - sum_dp[left])
        counts[i] = counts[i] % mod
    sum_dp[i+1] = sum_dp[i] + counts[i]


print(counts[n-1] % mod)

Measured memory_bytes: 27772
N = int(input())
if N%10 == 2 or N%10 == 4 or N%10 == 5 or N%10 == 7 or N%10 == 9:
  print("hon")

elif N%10 == 0 or N%10 == 1 or N%10 == 6 or N%10 == 8:
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9028
from subprocess import *
call(('pypy3','-c',"""
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    n,q=map(int,input().split())
    P=[[] for _ in range(n)]
    for i in range(n-1):
        a,b=map(int,input().split())
        P[a-1].append(b-1)
        P[b-1].append(a-1)
    X=[0]*n
    for i in range(q):
        p,x=map(int,input().split())
        X[p-1]+=x
    deq=deque([0])
    visited=[False]*n 
    while deq:
        node=deq.popleft()
        if not(visited[node]):
            visited[node]=True
            for p in P[node]:
                if not(visited[p]):
                    X[p]+=X[node]
                    deq.append(p)
    print(*X)

if __name__=='__main__':
    main()
"""))


Measured memory_bytes: 98428
#include <iostream>
#include <map>

int main() {
    using namespace std;
    
    map<int, int> num2student{};
    int n, student, num;
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> num;
        num2student[num] = i+1;
    }
    for (int j=0; j<n; j++) {
        cout << num2student.at(j+1) << " ";
    }
}

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

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char c) {
  if (c == 'A')
    return 1;
  else if (c == 'C')
    return 2;
  else if (c == 'G')
    return 3;
  else if (c == 'T')
    return 4;
  else
    return 0;
}

int h1(int key) { return int(key % M); }

int h2(int key) { return 1 + int(key % (M - 1)); }

int h(int key, int i) { return (h1(key) + i * h2(key)) % M; }

int convert_key(char k_str[]) {
  int k = 0, p = 1;
  rep(i, strlen(k_str)) {
    k += p * getChar(k_str[i]);
    p *= 5;
  }
  return k;
}

void insert(char k_str[]) {
  int k = convert_key(k_str);
  int i = 0;
  while (true) {
    int h_k = h(k, i);
    if (strlen(H[h_k]) == 0) {
      strcpy(H[h_k], k_str);
      break;
    } else if (strcmp(H[h_k], k_str) == 0) {
      break;
    }
    i++;
  }
}

bool find(char k_str[]) {
  int k = convert_key(k_str);
  int i = 0;
  while (true) {
    int h_k = h(k, i);
    if (h_k >= M) {
      return false;
    } else if (strlen(H[h_k]) == 0) {
      return false;
    } else if (strcmp(H[h_k], k_str) == 0) {
      return true;
    }
    i++;
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, M) H[i][0] = '\0';
  rep(i, n) {
    char comm[9], key[L];
    scanf("%s %s", comm, key);
    if (comm[0] == 'i') {
      insert(key);
    } else {
      if (find(key))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 17528