akhauriyash/Code-Regression huggingface dataset:
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

m = []
def dfs(depth, x, y, z, count):
  if depth == n:
    if min(x, y, z) > 0:
       return abs(a-x)+abs(b-y)+abs(c-z)+10*count-30
    else:
      return float('Inf')
  ret0 = dfs(depth+1, x, y, z, count)
  ret1 = dfs(depth+1, x+l[depth], y, z, count+1)
  ret2 = dfs(depth+1, x, y+l[depth], z, count+1)
  ret3 = dfs(depth+1, x, y, z+l[depth], count+1)
  return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0, 0))

Measured memory_bytes: 3188
/* 
 * ???????????§??????????´? PrintTestCases.java
 *
 * Copyright(C) 2016 Nagasaki Team All Rights Reserved.
 */
/**
 * ??°?????????????????????(ITP1_9-B)
 *
 * @author Yamashita
 * @version 1.00
 */

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;


class Main{
	/*
	 * ??°?????????????????????
	 */
	public static void main(String[] args) throws IOException{	//try????????\????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));	//?¨??????????
		String str = br.readLine();	//1???????????????
		int count= 1;	//???????????°
		
		while(!str.equals("0"))	//0?????\?????????????????????
		{
			System.out.println("Case "+count+": "+str);	//"Case 1:??\?????°???"?????¢?????§??????
			count++;	//?????°????????????????????????
			str=br.readLine();	//1???????????????
		}
	}
}

Measured memory_bytes: 32304
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)



//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int root(int x){return unicnt[x]<=0?-(unicnt[x]=-root(-unicnt[x])):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT

ll a[200010],b[200010],idx[200010];
int c(const void*p,const void*q){
	if(b[*(ll*)p]<b[*(ll*)q])return -1;
	return 1;
}

int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n){
		scanf("%lld%lld",a+i,b+i);
		idx[i]=i;
	}
	qsort(idx,n,sizeof(ll),c);
	ufinit(100010);
	rep(i,0,n-1){
		if(b[idx[i]]==b[idx[i+1]])uni(a[idx[i]],a[idx[i+1]]);
	}
	
	ll ans=0;
	rep(i,0,n){
		if(i==0||b[idx[i-1]]!=b[idx[i]])ans+=unicnt[root(a[idx[i]])];
	}
	printf("%lld",ans-n);
}


Measured memory_bytes: 4604
s = list(input())
t = list(input())

ss = set(s)
ts = set(t)

sc = [0]*len(s)
tc = [0]*len(t)

for i in ts:
  c = 1
  for j in range(len(t)):
    if t[j] == i:
      tc[j] += c
      c += 1
    
for i in ss:
  c = 1
  for j in range(len(s)):
    if s[j] == i:
      sc[j] += c
      c += 1
      
for i in range(len(t)):
  if sc[i] != tc[i]:     
    print('No')
    exit()
else:
  print('Yes')


Measured memory_bytes: 74696
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int M = -INF;
    int M_ID = 0;
    int m = INF;
    int m_ID = 0;
    int a[N];
    rep(i, N) {
        cin >> a[i];
        if (M < a[i]) {
            M = a[i];
            M_ID = i;
        }
        if (m > a[i]) {
            m = a[i];
            m_ID = i;
        }
    }
    int cnt = 0;
    if (M > abs(m)) {
        rep(i, N) if (a[i] < 0) cnt++;
        cout << cnt + N - 1 << endl;

        rep(i, N) {
            if (a[i] < 0) {
            cout << M_ID+1 << " " << i+1 << endl;
            }
        }
        rep(i, N-1) {
            cout << i+1 << " " << i+2 << endl;
        }
    } else {
                rep(i, N) if (a[i] > 0) cnt++;
        cout << cnt + N - 1 << endl;

        rep(i, N) {
            if (a[i] > 0) {
            cout << m_ID+1 << " " << i+1 << endl;
            }
        }
        for (int i = N; i > 1; i--) {
            cout << i << " " << i-1 << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(int j=0; j<2; j++){
			int[] a=new int[10];
			for(int i=0; i<10; i++){
				a[i]=sc.nextInt();
			}
			sort(a);
			print((a[9]+a[8]+a[7])+(j==0?" ":"\n"));
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

#define int long long

signed main() {
    int H, W, c[10][10] = {}, A_sum[10] = {};
    cin >> H >> W;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int A;
            cin >> A;
            if (A != -1) {
                A_sum[A]++;
            }
        }
    }
    for (int k = 0; k < 10; k++) {
        for (int j = 0; j < 10; j++) {
            for (int i = 0; i < 10; i++)
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
        }
    }
    int sum = c[0][1] * A_sum[0];
    for (int i = 2; i <= 9; i++) {
        sum += c[i][1] * A_sum[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int h,w;
    cin >> h >> w;
    char a[h][w];
    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
            if(a[i][j]=='#')count++;
        }
    }
    if(count==h+w-1){
        puts("Possible");
        return 0;
    }
    puts("Impossible");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  long long ans = 0;
  for(int i = 1; i < N; i++){
    int rest = a[i - 1] + a[i] - x;
    if(rest > 0){
      int temp = min(rest, a[i]);
      a[i] -= temp;
      rest -= temp;
      ans += temp;
      if(rest > 0){
	a[i - 1] -= rest;
	ans += rest;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int h = sc.NextInt();
        int m = sc.NextInt();

        double angle = Math.Abs((30d * h + 0.5d * m) - (6d * m));
        double rad = (double)(angle * Math.PI / 180);

        double c2 = a * a + b * b - 2 * a * b * Math.Cos(rad);

        double answer = Math.Sqrt(c2);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27940
#include <stdio.h>
#include <string.h>

int main(void) {
	const char* asumisu = "abcdefghijklmnopqrstuvwxyz";
	char* mizuhasu;
	char horieyui[4];
	if (scanf("%3s", horieyui) != 1) return 1;
	mizuhasu = strchr(asumisu, (unsigned char)horieyui[0]);
	if (mizuhasu == NULL) return 2;
	printf("%c\n", mizuhasu[1]);
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    bool t[26];

    int i;
    for(i = 0; i < 26; i++) {
        t[i] = false;
    }

    // 'a' == 97, 'z' == 122

    for(i = 0; i < (int)s.size(); i++) {
        t[(int)s[i] - 97] = true;
    }

    for(i = 0; i < 26; i++) {
        if (t[i] == false) {
            cout << (char)(i + 97) << endl;
            break;
        }
        if (i == 25 && t[i] == true) {
            cout << "None" << endl;
        }
    }
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace ABC154A
{
    class Program
    {
        static void Main(string[] args)
        {
            var ST = Console.ReadLine().Split();
            var S = ST[0];
            var T = ST[1];
            var AB = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var A = AB[0];
            var B = AB[1];
            var U = Console.ReadLine();

            Console.WriteLine(U == S
                ? (A - 1).ToString() + " " + B.ToString()
                : A.ToString() + " " + (B - 1).ToString());
        }
    }
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int A,B;
  cin>>A>>B;
  if(A>8||B>8)cout<<":("<<endl;
  else cout<<"Yay!"<<endl;
  return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    if (10 % p != 0) {
        vector<ll> cnt(p, 0);

        ll pw = 1;
        ll val = 0;
        ++cnt[0];
        for (int i = 0; i < n; ++i) {
            int d = s[i] - '0';
            (pw *= 10) %= p;
            val = (val * 10 + d) % p;
            ++cnt[val * modpow(pw, p - 2, p) % p];
        }

        ll ans = 0;
        for (int i = 0; i < p; ++i) {
            ans += cnt[i] * (cnt[i] - 1) / 2;
        }
        cout << ans << "\n";
    } else {
        ll val = 0;
        ll ans = 0;
        for (int i = 0; i < n; ++i) {
            int d = s[i] - '0';
            val = (val * 10 + d) % p;
            if (val == 0) ans += i + 1;
        }
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std ;
int main()
{
     int h, w, n;
     int arr[10005];
     int brr[105][105];

     while(cin >> h >> w >> n) {
        for(int i=1; i<=n; i++) {
            cin >> arr[i];
        }
        int v = arr[1];
        int col = 1;
        for(int i=1; i<=h; i++) {
            if(i&1){
                for(int j=1; j<=w; j++) {
                    brr[i][j] = col;
                    v--;
                    if(!v) {
                        col++;
                        v = arr[col];
                    }
                }
            }
            else {
                for(int j=w; j>=1; j--) {
                    brr[i][j] = col;
                    v--;
                    if(!v) {
                        col++;
                        v = arr[col];
                    }
                }
            }
        }
        for(int i=1; i<=h; i++) {
            cout << brr[i][1];
            for(int j=2; j<=w; j++) {
                cout << " " << brr[i][j];
            }
            cout << endl;
        }
     }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    double ans = 0;
    for(int i=0; i<n; i++){
        ans += 1.0/a[i];
    }
    cout << 1.0/ans << endl;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
points = gets.split.map(&:to_i)

sorted_points = points.sort

total_distance = sorted_points.last - sorted_points.first
distances = sorted_points.each_cons(2).map { |from, to| to - from }

answer =
  if n == 1
    total_distance
  elsif n > m
    0
  else
    total_distance - distances.sort.reverse[0...n - 1].inject(:+)
  end

puts answer


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

const long long mod=1e9+7;
int n,k,a[610],b[610],pd[610];
long long cnt[610][610],dp[610][610],g[2000],ans;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i)
	{
		scanf("%d%d",&a[i],&b[i]);
		pd[a[i]]=b[i];
		pd[b[i]]=a[i];
	}
	n<<=1;
	g[0]=1;
	for(int i=2;i<=n;i+=2)
	g[i]=(g[i-2]*(i-1))%mod;
	for(int i=1;i<=n;++i)
	{
		for(int j=i;j<=n;++j)
		cnt[i][j]=cnt[i][j-1]+(!pd[j]);
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=i;j<=n;++j)
		{
			int ji=0;
			for(int k=i;k<=j;++k)
			{
				if(pd[k]&&(pd[k]>j||pd[k]<i))
				ji=1;				
			}
			if(ji==1)
			continue;
			dp[i][j]=g[cnt[i][j]];
			for(int k=i+1;k<=j-1;++k)
			dp[i][j]=(dp[i][j]-1ll*dp[i][k]*g[cnt[k+1][j]]%mod+mod)%mod;
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=i;j<=n;++j)
		ans=(ans+dp[i][j]*g[(n/2-k)*2-cnt[i][j]]%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main()
{
    int A,B,C;
    cin>>A>>B>>C;
    if(A==0 && B==0 &&C==0)
        cout<<"No"<<endl;
    else if(A+B>=C)
    {
        cout<<"Yes"<<endl;
    }
    else if(A+B<C)
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int sum = 0;
		for(int i=0;i<5;i++){
			int t = sc.nextInt();
			if(t<40) t = 40;
			sum += t;
		}
		System.out.println(sum/5);
	}

}

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

using namespace std;
int dp[100001];
int main() {

       int x,ans=0;
       cin>>x;
       int h[x];
       for(int i=1;i<=x;i++)
        cin>>h[i];
       dp[1]=0;
       dp[2]=abs(h[1]-h[2]);
       for(int i=3;i<=x;i++)
       {
           dp[i]=min( (dp[i-1]+abs(h[i]-h[i-1])),( dp[i-2]+abs(h[i]-h[i-2])));

       }
       cout<<dp[x]<<endl;


}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))

cums = [0]
for a in A:
    cums.append(cums[-1] + a)

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

    def size(self):
        return len(self.hq)

pq = Heapq(A[:N], False)
ps = [sum(A[:N])]
for a in A[N:2*N]:
    pq.push(a)
    b = pq.pop()
    ps.append(ps[-1] + a - b)

mq = Heapq(A[2*N:], True)
ms = [sum(A[2*N:])]
for a in reversed(A[N:2*N]):
    mq.push(a)
    b = mq.pop()
    ms.append(ms[-1] + a - b)

ans = -float('inf')
for p,m in zip(ps,reversed(ms)):
    ans = max(ans, p-m)
print(ans)

Measured memory_bytes: 45476
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;

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

set<pair<int,int> > move(const string &s, int diff) {
  int x, y, mx, my;
  set<pair<int,int> > res;
  x = y = mx = my = 0;
  res.insert(make_pair(x,y));
  for(int i = 0; i < s.size(); ++i) {
    int d = (s[i]-'a'+diff)%6;
    x += dx[d];
    y += dy[d];
    res.insert(make_pair(x,y));
    mx = min(mx, x);
    my = min(my, y);
  }
  set<pair<int,int> > res2;
  for(set<pair<int,int> >::iterator it = res.begin();
      it != res.end(); ++it) {
    res2.insert(make_pair(it->first - mx, it->second - my));
  }
  return res2;
}

int main() {
  int Tc;
  cin >> Tc;
  cin.ignore();
  for(int tc = 0; tc < Tc; ++tc) {
    string s, t, dummy;
    getline(cin, s);
    getline(cin, t);
    getline(cin, dummy);
    set<pair<int,int> > ss = move(s, 0);
    bool res = false;
    for(int i = 0; i < 6; ++i) {
      if(move(t, i) == ss) {
	res = true;
	break;
      }
    }
    if(res) cout << "true" << endl;
    else cout << "false" << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <stdlib.h>

#define HMAX 500000
#define MAX 2000000000

void maxHeapify(int, int *, int);

int main() {
  int A[HMAX], H, i;

  scanf("%d", &H);
  if(H<1||HMAX<H) exit(8);
  for(i=1; i<=H; i++) {
    scanf("%d", &A[i]);
    if(A[i]<(-1)*MAX||MAX<A[i]) exit(8);
  }
  
  for(i=H/2; i>=1; i--)
    maxHeapify(H,A,i);

  for(i=1; i<=H; i++)
    printf(" %d", A[i]);
  printf("\n");
  
  return 0;
}

void maxHeapify(int H, int *A, int i) {
  int l, r, largest=i, tmp;

  l = 2*i;
  r = 2*i+1;
  
  if(l<=H&&A[largest]<A[l]) largest = l;
  if(r<=H&&A[largest]<A[r]) largest = r;
  if(largest!=i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(H,A,largest);
  }
}



Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll n, k, x, y, ans;

inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){ if(ch == '-') w = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

inline void print(ll x){
    if(x < 0) x = ~x + 1, putchar('-');
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int main(){
    n = read(); k = read();
    for(ll i = 0; i < k; i++) x += i;
    for(ll i = n; i > n - k; i--) y += i;
    ans = (ans + y - x + 1) % mod;
    for(ll i = k + 1; i <= n + 1; i++){
        x += i - 1; y += n - i + 1;
        ans = (ans + y - x + 1) % mod;
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))

ans = 1

a.sort(reverse=True)

if 0 not in a:
    for x in range(n):
        ans *= a[x]

        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0

print(ans)


Measured memory_bytes: 21640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
	int n;
	cin >> n;
	int xl = 0, yl = 0, tl = 0;
	bool is = true;
	cout << endl;
	for (int i = 0; i < n; ++i) {
		int x, y, t;
		cin >> t >> x >> y;
		if (abs(x - xl) + abs(y - yl) <= t - tl) {
			if ((abs(x - xl) + abs(y - yl)) % 2 != (t - tl) % 2) {
				is = false;
			}
		}
		else is = false;
		xl = x;
		yl = y;
		tl = t;
	}
	if (is) cout << "Yes";
	else cout << "No";
}
int main(){
	speed;
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'


constexpr ll MAXN = 1e6;
vector<int> smallest_factor;
vector<bool> prime;
vector<int> primes;
 
void sieve() {
    // (C: https://codeforces.com/contest/1366/standings/page/1, D, neal)
    ll maximum = max(MAXN, 2LL);
    smallest_factor.assign(maximum + 1, 0);
    prime.assign(maximum + 1, true);
    prime[0] = prime[1] = false;
    primes = {};
 
    for (int p = 2; p <= maximum; p++)
        if (prime[p]) {
            smallest_factor[p] = p;
            primes.push_back(p);
 
            for (int64_t i = int64_t(p) * p; i <= maximum; i += p)
                if (prime[i]) {
                    prime[i] = false;
                    smallest_factor[i] = p;
                }
        }
}    

// Prime factorizes n in worst case O(sqrt n / log n). Requires having run `sieve` up to at least sqrt(n).
// If we've run `sieve` up to at least n, takes O(log n) time.
vector<pair<int64_t, int>> prime_factorize(int64_t n) {
  int64_t sieve_max = int64_t(smallest_factor.size()) - 1;
  assert(1 <= n && n <= sieve_max * sieve_max);
  vector<pair<int64_t, int>> result;
 
  if (n <= sieve_max) {
    while (n != 1) {
      int64_t p = smallest_factor[n];
      int exponent = 0;
 
      do {
        n /= p;
        exponent++;
      } while (n % p == 0);
 
      result.emplace_back(p, exponent);
    }
 
    return result;
  }
 
  for (int64_t p : primes) {
    if (p * p > n)
      break;
 
    if (n % p == 0) {
      result.emplace_back(p, 0);
 
      do {
        n /= p;
        result.back().second++;
      } while (n % p == 0);
    }
  }
 
  if (n > 1)
    result.emplace_back(n, 1);
 
  return result;
}

 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  sieve();
 
  ll x;
  cin >> x;
  auto it = lower_bound(primes.begin(),primes.end(), x);
  cout << *it << endl;

}


Measured memory_bytes: 7804
h,n=gets.split.map(&:to_i)
INF=10**9+1
dp=[INF]*(h+1)
dp[0]=0
n.times do
    a,b=gets.split.map(&:to_i)
    (h+1).times do |i|
        j= i+a>h ? h:i+a
        dp[j]=dp[i]+b if dp[i]!=INF and dp[j]>dp[i]+b
    end
end
p dp[h]


Measured memory_bytes: 1916
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort(reverse = True)
res = 0
ind = 0
for i in range(1,n):
    res += a[ind]
    if i%2:
        ind += 1
print(res)

Measured memory_bytes: 32956
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    d.sort()

    val median1 = d[n/2]
    val median2 = d[n/2 - 1]

    if (median1 - median2 > 0) {
        println(median1 - median2)
    } else {
        println(0)
    }
}

Measured memory_bytes: 54732
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int a,b;
  cin>>a>>b;
  
  string ans="";
  if(a<=b&&b<0){
    int nub=(b-a+1)%2;
    if(nub==0)ans="Positive";
    if(nub==1)ans="Negative";
  }
  if(a>0&&b>=a)ans="Positive";
  if(a<=0&&b>=0)ans="Zero";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
import math

def InputData():
    
    data_len = int(input())
    # data = int(input().split())
    data = list(map(int, input().split()))

    searchdata_len = int(input())
    # searchdata = int(input().split())
    searchdata = list(map(int, input().split()))
    # print([i for i in data])
    # print([i for i in searchdata])
    # print()
    # print(data_len)
    # print(searchdata_len)
    # print()

    # data = int(data)
    # searchdata = int(searchdata)

    return data_len, data, searchdata_len, searchdata

def Binary_Search(Data, key):
    
    right = len(Data)
    left = 0
    while left < right:
        mid = (left + right) // 2
        # print(searchdata[i])
        if key == Data[mid]:
            # print(searchdata[i])
            return mid
        elif key < Data[mid]:
            right = mid
        elif key > Data[mid]:
            left = mid + 1
        

    return "NOT_FOUND"

def PrintOut(count):
    print(count)

def main():
    [data_len, data, searchdata_len, searchdata] = InputData()
    count = 0
    for i in searchdata:
        if Binary_Search(data, i) != "NOT_FOUND":
            count += 1

    PrintOut(count)

if __name__=='__main__':
    main()


Measured memory_bytes: 17008
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
    }

    let mut ans = 0;
    if h == 1 || w == 1 {
        ans = 1
    } else {
        ans += (h / 2) * w;
        ans += (w / 2 + w % 2) * (h % 2);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
#define int long long int
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll MOD = 1e9+7;
const ll inf = 1e18;
const ll p = 998244353;
int fac[200005];
double powe(double x,int y) 
{ 
    if (y == 0) 
        return 1.00;
    double p = powe(x, y/2);
    p = (p * p); 
    return (y%2 == 0)? p : (x * p); 
} 
int power(int x,int y, int m) 
{ 
    if (y == 0) 
        return 1;
    int p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
int mod(int x)
 {
	if(x<0)return -x;
	else return x;
 }
 int inverse(int a, int p)
{
    return power(a, p-2, p);
}
int ncr(int n, int r, int p)
{
    if (r==0)
        return 1;
    return (fac[n]*inverse(fac[r], p) % p *
            inverse(fac[n-r], p) % p) % p;
}
 int leaves=0;
 vector<int> visited;
 vector<vector<int> > adj;
 vector<int> color;
 vector<int> max_path;
 void dfs(int s)
{    
     
     if(visited[s])return;
     visited[s]=1;
     FOR(i,0,sz(adj[s])-1)
     {
     	if(!visited[adj[s][i]])
     	{
     	 dfs(adj[s][i]);	
		}
		max_path[s]=max(max_path[adj[s][i]]+1,max_path[s]);
	 }
 }
 //Don't forget to clear vectors>>;
 //i miss simpu;
 //work_hard();
signed main()
{
readb(n,m);
adj.resize(n+1);
visited.resize(n+1);
max_path.resize(n+1);
FOR(i,1,n)max_path[i]=0;
FOR(i,1,m)
{
	readb(x,y);
	adj[x].pb(y);
}
FOR(i,1,n)
{
	if(!visited[i])dfs(i);
}
int answer=0;
FOR(i,1,n)
{
 answer=max(answer,max_path[i]);
}
cout<<answer<<endl;
}

Measured memory_bytes: 12824
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int N = Integer.parseInt(sc.next());
    String String1 = sc.next();
    String Strong2 = sc.next();
    
    if (N == 1) {
      System.out.println(3);
      return;
    }
    
    char s1[] = new char[N];
    char s2[] = new char[N];
    for (int i = 0; i < N; i++) {
      s1[i] = String1.charAt(i);
      s2[i] = Strong2.charAt(i);
    }
    final long mod = 1000000007;
    
    long ans;
    boolean flag, prev;
    int i = 0;
    if (s1[0] == s2[0]) {
      prev = true;
      ans = 3;
      i += 1;
    } else {
      prev = false;
      ans = 3 * 2;
      i += 2;
    }
    while (i < N) {
      if (s1[i] == s2[i]) {
        flag = true;
        i += 1;
      } else {
        flag = false;
        i += 2;
      }
      
      if (prev && flag) {
        ans = ans * 2 % mod;
      } else if (prev && !flag) {
        ans = ans * 2 * 1 % mod;
      } else if (!prev && flag) {
      } else if (!prev && !flag) {
        ans = ans * 3 % mod;
      }
      
      prev = flag;
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

const long long MOD = 1000000007;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long COM(long long n, long long k) {
    long long ue = 1;
    long long shita = 1;
    rep(i, k) {
        ue *= (n - i);
        shita *= (i + 1);
        ue = ue % MOD;
        shita = shita % MOD;
    }
    return ue % MOD * modinv(shita, MOD) % MOD;
}

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    debug((modpow(2, n, MOD) - 1));
    debug(COM(n, a), COM(n, b));

    long long res = (modpow(2, n, MOD) - 1 - COM(n, a) - COM(n, b));
    while(res<0){
        res+=MOD;
    }
    cout << res % MOD << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int (i)=(a);(i)<(b);++(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;

void chmax(lint &a, lint b){
    a = max(a, b);
}

void chmin(lint &a, lint b){
    a = min(a, b);
}

class BUnplannedQueries {
public:
    int N, M;
    vi cnt;

    void input(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in>>N>>M;
        cnt = vi(N, 0);
        REP(i, M){
            int a, b;
            in>>a>>b;
            a--, b--;
            cnt[a]++, cnt[b]++;
        }
    }

    void solve(std::istream& in, std::ostream& out){
        input(in, out);
        REP(i, N){
            if(cnt[i]%2){
                out<<"NO\n";
                return;
            }
        }
        out<<"YES\n";
    }
};


int main() {
	BUnplannedQueries solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<int> cnt(3, 0);
  for (int i = 0; i < N; i++){
    cnt[S[i] - 'a']++;
  }
  sort(cnt.begin(), cnt.end());
  if (cnt[2] - cnt[0] <= 1){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 512
using System;
using System.Linq;

// https://atcoder.jp/contests/abc130/tasks/abc130_e
namespace ECommonSubsequence
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputs[0];
            var m = inputs[1];

            var sNumbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var tNumbers = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var dp = new ModNum[n + 1, m + 1];
            for (var i = 0; i < n + 1; i++) dp[i, 0] = 1;
            for (var i = 0; i < m + 1; i++) dp[0, i] = 1;

            for (var i = 1; i < n + 1; i++)
            {
                for (var j = 1; j < m + 1; j++)
                {
                    dp[i, j] = dp[i - 1, j] + dp[i, j - 1];
                    if (sNumbers[i - 1] != tNumbers[j - 1]) dp[i, j] -= dp[i - 1, j - 1];
                }
            }

            // 解答の出力
            Console.WriteLine(dp[n, m].X);
        }
    }

    public struct ModNum : IEquatable<ModNum>
    {
        const int Mod = 1000000007;
        public long X { get; }

        public ModNum(long x) { X = x % Mod; }
        public static implicit operator ModNum(long x) => new ModNum(x);

        public bool Equals(ModNum other) => X == other.X;
        public override bool Equals(object obj) => obj is ModNum && Equals((ModNum)obj);
        public override int GetHashCode() => X.GetHashCode();
        public static bool operator ==(ModNum a, ModNum b) => a.X == b.X;
        public static bool operator !=(ModNum a, ModNum b) => a.X != b.X;

        public static ModNum operator +(ModNum a, ModNum b) => a.X + b.X;
        public static ModNum operator -(ModNum a, ModNum b) => Mod + a.X - b.X;
        public static ModNum operator *(ModNum a, ModNum b) => a.X * b.X;
    }
}


Measured memory_bytes: 43360
// 1_abc133_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    if(a * n > b) cout << b << endl;
    else cout << a * n << endl;
    return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a[3];
    cin >> a[0]>>a[1]>>a[2];
    for(int i = 0; i < 2; i++){
        for(int j =i; j < 3; j++){
            if(a[i] < a[j]) swap(a[i],a[j]);
        }
    }
    if(a[0] == a[1]+a[2]){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
using namespace std;
const int N=1e5+5;
const int M=1e9+7;
const double eps=1e-6;
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
int n,k;
int x[N],y[N];
char c[N];
int cnt[1005*2],ans;
int main(){Accel
	cin>>n>>k;
	int K=k*2;
	REP(i,n){
		int a,b;
		cin>>a>>b>>c[i];
		x[i]=a%K;
		y[i]=b%K;
	}
	REP(i,K){
		Re(cnt,0);
		int r=0;
		REP(j,n){
			//int a=(x[j]-i+K)%K;
			//a=(a<k);
			int a=((x[j]-i<0?x[j]-i+K:x[j]-i)<k);
			if(a^(y[j]<k))r+=c[j]=='B';
			else r+=c[j]=='W';
			cnt[y[j]]+=(a^(c[j]=='W'))?1:-1;
		}
		REP(j,K){
			ans=max(ans,r);
			r+=cnt[j]-cnt[(j+k)%K];
		}
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1152
#include <map>
#include <cstdio>
using namespace std;
typedef map<pair<int,int>,int> mpiii;

void solve(int T){
	mpiii m;
	char cmd[2];
	int n;
	for(;T--;){
		scanf("%s%d",cmd,&n);
		if(*cmd=='D'){
			for(mpiii::iterator it=m.begin();it!=m.end();){
				if(it->second==n){
					mpiii::iterator it2=it;
					++it;
					m.erase(it2);
				}else{
					++it;
				}
			}
		}else if(*cmd=='R'){
			mpiii::iterator it=m.lower_bound(make_pair(n,2000000000));
			if(it==m.begin()){
				puts("-1");
			}else{
				--it;
				printf("%d\n",it->first.first<=n&&n<=it->first.second ? it->second : -1);
			}
		}else if(*cmd=='W'){
			int z;
			scanf("%d",&z);
			int cur=0;
			for(mpiii::iterator it=m.begin();it!=m.end();++it){
				int d=it->first.first-cur;
				if(d>z)d=z;
				if(d)m[make_pair(cur,cur+d-1)]=n;
				z-=d;
				if(z==0)break;
				cur=it->first.second+1;
			}
			if(z)m[make_pair(cur,cur+z-1)]=n;
		}
	}
}
int main(){for(int T;~scanf("%d",&T)&&T;puts(""))solve(T);}

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

int main(){
	int check = false;
	int n;
	cin >> n;
	for(int i=1;i < 10;i++){
		if(n % i ==0){
			if(n / i < 10)check = check || true;
		}
	}
	if(check) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
 
int main()
{
   char s[100], r[100];
   int n, c, d;
   gets(s);
 
   n = strlen(s);
 
   for (c = n - 1, d = 0; c >= 0; c--, d++)
      r[d] = s[c];
 
   r[d] = '\0';
 
   printf("%s\n", r);
 
   return 0;
}

Measured memory_bytes: 916
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <functional>
 
using namespace std;

using t = unsigned long long;

int main() {
    t x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<t> p,q,r;
    t z;
    for (t i=0;i<a;++i){
        cin>>z; p.push_back(z);
    }
    for (t i=0;i<b;++i){
        cin>>z; q.push_back(z);
    }
    for (t i=0;i<c;++i){
        cin>>z; r.push_back(z);
    }
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    copy(p.rbegin(),p.rbegin()+x, back_inserter(r));
    copy(q.rbegin(),q.rbegin()+y, back_inserter(r));
    sort(r.rbegin(),r.rend());
    t sum=0;
    for (t i=0;i<x+y;++i){
        sum += r[i];
    }
    cout<<sum;
}

Measured memory_bytes: 8048
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f("abc").
f("acb").
f("bac").
f("bca").
f("cab").
f("cba").

main :-
    get_string(S),
    f(S) -> writeln("Yes") ; writeln("No").


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

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

int main(){
  ll n;
  cin >> n;
  vector<ll> d(n);
  rep(i,n) cin >> d[i];
  
  ll ans = 0;
  vector<ll> r(n,0);
  r[n-1] = d[n-1];
  for(ll i = n-2;i>=0;i--) r[i] = r[i+1] + d[i];
 
  rep(i,n-1) ans += d[i] * r[i+1];

  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 9/18/2020
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int64_t INF = (int64_t)1e18;
const int mxN = 100, mxW = (int)1e5;

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

	int n, w;
	cin >> n >> w;
	vector<pair<int64_t, int64_t>> v(n);
	for(auto& el : v) cin >> el.first >> el.second;
	int64_t dp[n+1][w+1]; // dp[i][j] max value i can get starting from elem i and always ending at last elem with w weight still have to spend;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= w; j++)
			dp[i][j] = -INF;
	for(int i = 0; i < w; i++) dp[n][i] = 0;
	for(int i = 0; i <= n; i++) dp[i][0] = 0;
	for(int i = n-1; i >= 0; i--) {
		for(int j = 0; j <= w; j++) {
			dp[i][j] = dp[i+1][j]; // leave it;
			if(j >= v[i].first) {
				dp[i][j] = max(dp[i][j], dp[i+1][j-v[i].first] + v[i].second); // take it;
			}
		}
	}
	cout << dp[0][w] << "\n";

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        for(int j = i+1; j < n; ++j)
        {
            int r = lower_bound(v.begin(), v.end(), v[i]+v[j]) - v.begin();
            ans += r - (j+1);
        }
    }
    cout << ans << endl;
}

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

bool p[1000100];

void erato(){
	fill(p, p+1000100, true);
	p[0] = p[1] = false;

	for(int i=0; i < 1000100; i++){
		if(!p[i]) continue;
		for(int j=i+i; j < 1000100; j += i){
			p[j] = false;
		}
	}
}

int main(){
	erato();

	int n;
	while(cin >> n, n != 0){
		int count = 0;
		for(int i=0; i < n; i++){
			for(int j=i; j < n; j++){
				//if(i == j) continue;
				if(p[i] && p[j] && i+j== n) count++;
			}
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 2132
dp = Array.new(42){Array.new(412){Array.new(412)}}
n,ma,mb = gets.chomp.split(" ").map{|u|u.to_i}
dp[0][0][0] = 0
n.times do |i|
  a,b,c=gets.chomp.split(" ").map{|u|u.to_i}
    401.times do |bb|
      401.times do |aa|
        if (dp[i][aa][bb] != nil) 
          dr = dp[i][aa][bb] + c 
          dp[i+1][aa][bb] = dp[i][aa][bb] if(dp[i+1][aa][bb] == nil or dp[i][aa][bb] < dp[i+1][aa][bb])
          dp[i+1][aa+ a][bb + b] = dr if(dp[i+1][aa+ a][bb + b] == nil or dr < dp[i+1][aa+ a][bb + b] )
        end
      end
    end
end
ans = []
(1..400).each do |a|
  if((a%ma)==0)
    (1..400).each do |b|
      if((dp[n][a][b]!=nil) and (((a*(mb/(ma.to_f))-b).abs)< 0.00001))
        ans.push(dp[n][a][b])
      end
    end
  end
end
ans.delete(0)
if(ans != [])
 p ans.min 
else
  p -1
end

Measured memory_bytes: 60564
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 100000000000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

struct edge { int from, to, cost; };

signed main(){
  int n,m;cin>>n>>m;
  edge es[2000];int d[1100];d[1] = 0;for(int i=2;i<=n;i++)d[i] = -INF;
  for(int i=0;i<m;i++){
    int a,b,c;cin>>a>>b>>c;
    es[i] = {a,b,c};
  }
  int cnt = 0;
  while(true){
    cnt++;
    bool update = false;
    for(int i=0;i<m;i++){
      edge e = es[i];
      if(d[e.from] != -INF && d[e.to] < d[e.from]+e.cost){
        d[e.to] = d[e.from] + e.cost;
        update = true;
        if(cnt == 2*n){
          if(e.to == n){
            cout << "inf" << endl;
            return 0;           
          }else{
            update = false;
          }
        }
      }
    }
    if(!update){
      cout << d[n] << endl;
      return 0;
    }
  }
}



Measured memory_bytes: 256