akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){

    ll n;
    cin>>n;
    double arr[n];
    for(ll i = 0;i<n;i++){
        cin>>arr[i];
    }
    double dp[n+1][n+1];
    dp[0][0] = 1.0;

    for(ll i = 1;i<=n;i++){
        dp[i][0] = dp[i-1][0]*(1-arr[i-1]);
    }
    for(ll i = 1;i<=n;i++){
        dp[0][i] = 0;
    }

    for(ll i = 1;i<=n;i++){
        for(ll j =1;j<=n;j++){

            dp[i][j] = arr[i-1]*dp[i-1][j-1] + (1-arr[i-1])*dp[i-1][j];

        }
    }

    double ans = 0;
    for(ll i = n/2+1;i<=n;i++){
        ans+=dp[n][i];
    }

    std::cout << std::setprecision(15);
    cout<<ans<<endl;

}


Measured memory_bytes: 70528
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

int main()
{
	io
	#ifdef CODE
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	ll n, k;
	cin >> n >> k;
	ll r, s, p;
	cin >> r >> s >> p;
	string str;
	cin >> str;
	ll profit = 0; 
	fr(i, 0, k) {
		int count = 1;
		int pos = i;
		for (ll j = i + k; j < n; j += k) {
			// cout << str[i] << ' ' << str[i - k] << " " << 
			if (str[j] == str[j - k]) {
				count++;
			} else {
				if (str[j - k] == 'r') {
					profit += ((count + 1) / 2) * p;
				} else if (str[j - k] == 's') {
					profit += ((count + 1) / 2) * r;
				} else if (str[j - k] == 'p') {
					profit += ((count + 1) / 2) * s;
				}
				count = 1;
			}
			pos += k;
		}
		if (count) {
			if (str[pos] == 'r') {
				profit += ((count + 1) / 2) * p;
			} else if (str[pos] == 's') {
				profit += ((count + 1) / 2) * r;
			} else if (str[pos] == 'p') {
				profit += ((count + 1) / 2) * s;
			}
		}
	}
	cout << profit;

	#ifdef CODE
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  int b[20];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    int sum = 0;
    for (int j = 0; j < m; j++) {
      cin >> tmp;
      sum += tmp * b[j];
    }
    if (sum + c > 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int A,B;
  cin>>A>>B;
  A--;
  B--;
  cout<<100<<" "<<100<<endl;
  	rep(i,50){
      rep(j,100){
            if(i*j%2==1&&A!=0){
              cout<<".";
              A--;
            }
        else{
          cout<<"#";
        }
      }
      cout<<endl;
    }
  rep(i,50){
      rep(j,100){
            if(i*j%2==1&&B!=0){
              cout<<"#";
              B--;
            }
        else{
          cout<<".";
        }
      }
      cout<<endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var T = Scanner.Scan<int>();
            var answer = new long[T];
            for (var i = 0; i < T; i++)
            {
                var (N, M, A, B) = Scanner.Scan<int, int, int, int>();
                answer[i] = FloorSum(N, M, A, B);
            }
            foreach (var ans in answer)
            {
                Console.WriteLine(ans);
            }
        }

        public static long FloorSum(long n, long m, long a, long b)
        {
            var ret = 0L;
            if (a >= m)
            {
                ret += (n - 1) * n * (a / m) / 2;
                a %= m;
            }

            if (b >= m)
            {
                ret += n * (b / m);
                b %= m;
            }

            var yMax = (a * n + b) / m;
            var xMax = yMax * m - b;
            if (yMax == 0) return ret;
            ret += (n - (xMax + a - 1) / a) * yMax;
            ret += FloorSum(yMax, a, m, (a - xMax % a) % a);
            return ret;
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 41908
#include <iostream>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <vector>
#include <climits>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <stdio.h>
using namespace std; 
#define Endl '\n'
int main()
{
    string s;
    cin>>s;
    int t=s.size()-1;
    if (s[t]=='3')
    {
        cout<<"bon";
    }
    else
        if (s[t]=='0' || s[t]=='1' || s[t]=='6' || s[t]=='8')
        {
            cout<<"pon";
        }
        else
            cout<<"hon";
}   

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct check{
	int i,j,k;
	check(int x,int y,int z){
		i = x;
		j = y;
		k = z;
	}
};
int main(){
	int res[301], a, i, j, k, r, n;
	for(; cin >> a >> i >> j >> n; ){
		a += i + j;
		fill( res, res + 301, 2 );
		vector<check> fails;
		for(; n--; ){
			cin >> i >> j >> k >> r;
			if( r )	res[i] = res[j] = res[k] = 1;
			else	fails.push_back( check( i, j, k ) );
		}
		vector<check>::iterator it;
		for( it = fails.begin(); it != fails.end(); ++it ){
			k = (res[it->i]==1) + (res[it->j]==1) + (res[it->k]==1);
			if( k == 2 ){
				if( res[it->i] != 1 )	res[it->i] = 0;
				if( res[it->j] != 1 )	res[it->j] = 0;
				if( res[it->k] != 1 )	res[it->k] = 0;
			}
		}
		for( i = 0; i++ < a; ) cout << res[i] << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, Q, A, B;
template <typename T>
class ST {
 public:
  vector<T> tree;
  int n;

  ST() = default;
  ST(const vector<T> &arr) : n(arr.size()) {
    tree = vector<T>(2 * n + 1);
    for (int i = 0; i < n; ++i) {
      update(i, arr[i]);
    }
  }
  void update(int p, T val) {
    int i = n + p + 1;
    tree[i] = val;
    i /= 2;
    while (i) {
      tree[i] = tree[i * 2];
      if (i * 2 + 1 < tree.size()) {
        tree[i] = min(tree[i], tree[i * 2 + 1]);
      }
      i /= 2;
    }
  }

  T query(int start, int end) {  // start index - end index
    int l = n + start + 1;
    int r = n + end;
    T ret = INT_MAX;
    while (l <= r) {
      if (l & 1) {
        ret = min(ret, tree[l]);
        l++;
      }

      if ((r & 1) == 0) {
        ret = min(ret, tree[r]);
        r--;
      }

      l /= 2;
      r /= 2;
    }

    return ret;
  }

};

ST<ll> st1, st2;

ll base = 0;

ll getAug(int x) {
  ll r1 = st1.query(x, N) - x;
  ll r2 = st2.query(0, x) + x;
  return min(r1, r2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> N >> Q >> A >> B;

  vector<ll> pos(Q);
  for (int i = 0; i < Q; ++i) {
    int x;
    cin >> x;
    pos[i] = x - 1;
  }

  ll p1 = A - 1;
  ll p2 = B - 1;

  vector<ll> dp(N, INT_MAX);

  ll lp = p1;
  dp[p2] = 0;
  st1 = ST<ll>(dp);
  for (int i = 0; i < N; ++i) {
    st1.update(i, dp[i] + i);
  }


  st2 = ST<ll>(dp);

  for (int i = 0; i < N; ++i) {
    st2.update(i, dp[i] - i);
  }

  for (int i = 0; i < Q; ++i) {
    auto cp = pos[i];
    auto aug = getAug(cp);

    ll real1 = dp[lp] + abs(cp - lp) + base;
    ll real2 = aug + base;
    ll rreal = min(real1, real2);

    dp[lp] = rreal - base - abs(cp -lp);

    st1.update(lp, dp[lp] + lp);
    st2.update(lp, dp[lp] - lp);
    base += abs(cp - lp);
    lp = cp;
  }

  ll ret = 1LL << 62;

  for (int i = 0; i < N; ++i) {
    ret = min(ret, dp[i] + base);
  }

  cout << ret << endl;
}

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

#define ll long long
#define ar array

#

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

	string s, t;
	cin >> s >> t;
	int c = 0;
	for(int i=0; i<s.size() ;i++){
        if(s[i] != t[i])c++;

	}
	cout << c << endl;
}

Measured memory_bytes: 3824
N, M, Q = map(int, input().split())
num4 = [[(int(i)) for i in input().split()] for _ in range(Q)]
A = [[i]for i in range(M,0,-1)]
Aseq = []
while len(A)!=0: # 全数列が長さNになるまで続ける
  tmp = A.pop(-1)
  if len(tmp)==N: # 長さNの数列は、リストAseqに追加
    Aseq.append(tmp)
    continue
  for i in range(M, tmp[-1]-1,-1): A.append(tmp + [i])
pmax = 0
for A in Aseq:
  p = 0
  for a,b,c,d in num4:
    if int(A[b-1])-int(A[a-1])==c: p += d
  pmax = max(pmax, p)
print(pmax)

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

int main()
{
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N, L; cin >> N >> L;
    vector<int> vec(N);
    int ans = 0;
    for(int i = 0; i < N; ++i){
        vec[i] = L + i;
        ans += L + i;
    }
    int offset = INF32;
    for(int i = 0; i < N; ++i){
        if(abs(offset) > abs(vec[i])){
            offset = vec[i];
        }
    }
    ans -= offset;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b, c, k) = readInputLine().split(" ").map { it.toLong() }
    
    if (k % 2L == 0L) {
        println(a - b)
    } else {
        println(b - a)
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37744
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

int main(){
	//問題文は理解できないが，
	//fは　Sが何個の木で構成されてるかっぽい
	// ⇒ f = (Sの頂点数) - (Sの辺の数) (∵ 木は閉路がない) 
	//そのため，求める答えΣΣfは
	//   ΣΣf = ΣΣ(Sの頂点数) - ΣΣ(Sの辺の数)  かな

	int N;
	cin >> N;
	//vec[i]: 頂点iの辺の先のの頂点の列(頂点iとくっついている頂点達)
	//今回はiより小さい頂点は格納しないことにする
	vector<vector<int>> vec(N, vector<int>());
	for(int i=0; i<N-1; i++){
		int u, v;
		cin >> u >> v;
		u--; v--;
		// vec[u].push_back(v);
		// vec[v].push_back(u);
		if(u<v) vec[u].push_back(v);
		else vec[v].push_back(u);
	}
	// vertex: 頂点, edge: 辺
	// num_vertex: ΣΣ(Sの頂点数), num_edge: ΣΣ(Sの辺の数)
	ll num_vertex = 0, num_edge = 0;
	for(ll i=1; i<=N; i++){
		num_vertex += i*(N-i+1);
		//例 N=3のとき　 num_vertex = 1*3 + 2*2 + 3*1
		//N=4のとき num_vertex = 1*4 + 2*3 + 3*2 + 4*1
	}

	for(ll i=0; i<N; i++){
		for(ll j=0; j<vec[i].size(); j++){
			num_edge += (i+1) * (N-1 - vec[i][j] +1);
		// LとRを ΣΣで　0~N-1までずらしていくとき 
		//　頂点iと頂点vec[i][j]を結ぶ辺が何回使われるかを数える
		// 例: 頂点2と頂点5を結ぶ辺の場合 
		//     Lの候補は0,1,2 Rの候補は5,6,...,N-1
		// Lの候補とRの候補はそれぞれ独立しているので 
		//  (2+1)  *  {(N-1)-5 + 1} 
		}
	}
	//cout << " num_vertex: " << num_vertex << " num_edge: " << num_edge << endl; 
	ll ans = num_vertex - num_edge;
	cout << ans << endl;

}


Measured memory_bytes: 14004
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> T ceil(T a, T b) { return a / b + !!(a % b); }

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    cout << 1 + ceil(n - k, k - 1) << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){ 
  long long int a,b=0;cin>>a;
  vector<pair<int,int>>c(a);
  rep(i,a){
    cin>>c[i].second>>c[i].first;
  }
  sort(c.begin(),c.end());
  rep(i,a){
    b+=c[i].second;
    if(b>c[i].first){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  
  }


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#define N 36

typedef struct{
    char c;
    int value;
}sort;


int main()
{
  int i,j,n,flag=0,minj;
  sort C1[N],C2[N],a;
  char emp;

  scanf("%d\n",&n);
  for(i=0;i<n;i++){
      scanf("%c%d%c",&C1[i].c, &C1[i].value,&emp);
      C2[i]=C1[i];
}


//bubble sort
    for(i=0;i<n;i++){
        for(j=n-1;j>i;j--){
             if(C1[j].value < C1[j-1].value){
               a=C1[j];
             C1[j] = C1[j-1];
            C1[j-1] =a;

            }
        }
    }
// bubble fin


//selection sort
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(C2[j].value <C2[minj].value ) minj=j;
        }
        if(minj != j){
                a=C2[i];
                C2[i]=C2[minj];
                C2[minj]=a;
        }
        }
  // selection fin


    for(j=0;j<n-1;j++){
        printf("%c%d ",C1[j].c,C1[j].value);
    }
    printf("%c%d\n",C1[n-1].c,C1[n-1].value);
    printf("Stable\n");

for(j=0;j<n-1;j++){
    printf("%c%d ",C2[j].c,C2[j].value );
    if(C1[j].c!=C2[j].c) flag=1;
}
printf("%c%d\n",C2[n-1].c,C2[n-1].value);
  if(C1[n-1].c!=C2[n-1].c) flag=1;

    if(flag==1) printf("Not stable\n");
    else printf("Stable\n");

    return 0;

}



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

typedef long long ll;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ONLINE_JUDGE

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif

  int N, K;
  vector<int> a;
  const int MOD = 1000000007;

  cin >> N >> K;
  // indexを1からはじまるようにする
  a.push_back(0);
  REP(i, N) {
    int n;
    cin >> n;
    a.push_back(n);
  }
  // dp[i][j]
  // i番目の子供までにj個の飴を与えた場合の組み合わせの数
  // 答えはdp[N][K]
  int dp[N + 1][K + 1];

  REP(i, N + 1) {
    REP(j, K + 1) {
      dp[i][j] = 0;
    }
  }

  dp[0][0] = 1;
  // dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + ... + dp[i - 1][j - a(i)]
  // 素朴な方法 O(NK^2)
  // FOR(i, 1, N + 1)REP(j, K + 1) {
  //   FOR(k, 0, a[i] + 1) {
  //     if (j - k >= 0) {
  //       dp[i][j] += dp[i - 1][j - k] % MOD;
  //     }
  //   }
  // }

  // 累積和を使う
  // dp[i][j] = Σ[k=j-a[i]...j]dp[i-1][k]
  // dp[i][j] = Σ[k=0...j]dp[i-1][k] - Σ[k=0...(j -a[i] - 1)]dp[i-1][k]
  FOR(i, 1, N + 1) {
    int cum[K + 2];

    // cum[j] = dp[i - 1][0] + ... + dp[i - 1][j - 1]

    // cum[1] = dp[i - 1][0]
    // cum[2] = dp[i - 1][0] + dp[i - 1][i]
    // :
    // cum[j + 1] = dp[i - 1][0] + dp[i - 1][1] + ... + dp[i - 1][j]
    // :
    // cum[K] = dp[i - 1][0] + ... + dp[i - 1][K - 1]
    // cum[K + 1] = dp[i - 1][0] + ... + dp[i - 1][K]
    cum[0] = 0;
    FOR(j, 1, K + 1 + 1) {
      cum[j] = (cum[j - 1] + dp[i - 1][j - 1]) % MOD;
    }

    FOR(j, 0, K + 1) {
      // cum[j - a[i]] = dp[i - 1][0] + dp[i - 1][1] + .... + dp[i - 1][j - a[i] - 1]
      dp[i][j] = (cum[j + 1] - cum[max(0, j - a[i])] + MOD) % MOD;
    }
  }

  // REP(i, N + 1) {
  //   REP(j, K + 1) {
  //     cout << dp[i][j] << ' ';
  //   }
  //   cout << endl;
  // }

  cout << dp[N][K];
}


Measured memory_bytes: 40064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), max = 0, ans = 0;
        List<Integer> l = new ArrayList<>();
        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
            max = Math.max(max, t[i]);
        }
        for (int i = 1; i <= max; i++) {
            if (max % i == 0) {
                l.add(i);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l.size(); j++) {
                if (l.get(j) >= t[i]) {
                    ans += l.get(j) - t[i];
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 70364
#include<stdio.h>

int fib( int);
int F[45];
int main() {
	int n,i;
	
	scanf("%d",&n);

	printf("%d\n",fib(n));

	return 0;
}
	
	
	
	int fib(int n) {
		int t;
		
	if(t=F[n]) return t;	
else	if(n==0 || n==1) t=1; 
	else t= fib(n-2) + fib(n-1);
F[n]=t;
return t;
			}


Measured memory_bytes: 2048
n = int(input())
h = list(map(int, input().split()))

cnt = 1

for i in range(n-1):
    cnt_min = 0
    for j in range(i+1):
        if h[i+1] >= h[j]:
            cnt_min += 1
    if cnt_min == i+1:
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
(let* ((n (read))
       (m (read))
       (lst1 (loop repeat n
                   collect (cons (read) (read))))
       (lst2 (loop repeat m
                   collect (cons (read) (read)))))

  (defun f (p q)
    (+ (abs (- (car p) (car q))) (abs (- (cdr p) (cdr q)))))


  (setq lst3
        (loop for i from 0 to (1- (length lst1))
              collect (loop for j from 0 to (1- (length lst2))
                            collect (f (nth i lst1) (nth j lst2)))))

  (format t "~{~A~%~}"
          (loop for i in lst3
                collect (1+ (position (apply #'min i) i)))))



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;
    cin >> a >> b;
    ll ans = 0;
    ans = a*3;
    ans += b;
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

long[1000] XS, IXS, YS, IYS, ZS, IZS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    foreach (i; 0..N) {
        auto xyz = readln.split.to!(long[]);
        XS[i] = xyz[0];
        IXS[i] = -xyz[0];
        YS[i] = xyz[1];
        IYS[i] = -xyz[1];
        ZS[i] = xyz[2];
        IZS[i] = -xyz[2];
    }

    long res = long.min;
    foreach (xs; [XS, IXS]) {
        foreach (ys; [YS, IYS]) {
            foreach (zs; [ZS, IZS]) {
                long[int][1000] memo;
                long solve(int i, int r) {
                    if (r == 0) return 0;
                    if (i == N) return long.min / 2;

                    if (r in memo[i]) return memo[i][r];

                    auto r1 = solve(i+1, r);
                    auto r2 = solve(i+1, r-1) + xs[i] + ys[i] + zs[i];

                    return memo[i][r] = max(r1, r2);
                }
                res = max(res, solve(0, M));
            }
        }
    }

    writeln(res);
}

Measured memory_bytes: 78084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s,t;
  cin>>s>>t;
  vector<int> ok[26],ok2[26];
  int n=s.size();
  rep(i,n){
    ok[s[i]-'a'].push_back(i);
    }
  rep(i,26){
    if(ok[i].empty())continue;
    for(auto e:ok[i]){
      if(t[ok[i][0]]!=t[e]){
        cout<<"No"<<endl;
        return 0;
        }
      }
    }
   rep(i,n){
    ok2[t[i]-'a'].push_back(i);
    }
  rep(i,26){
    if(ok2[i].empty())continue;
    for(auto e:ok2[i]){
      if(s[ok2[i][0]]!=s[e]){
        cout<<"No"<<endl;
        return 0;
        }
      }
    }
  cout<<"Yes"<<endl;
    
    return 0;
}


Measured memory_bytes: 2824
import java.util.Scanner;

/**
 * TITLE : Station and Bus
 * URL : https://atcoder.jp/contests/abc158/tasks/abc158_a
 */
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        if ("AAA".equals(S) || "BBB".equals(S)) {
            System.out.println("No");
        }
        else {
            System.out.println("Yes");
        }
        sc.close();
    }
}


Measured memory_bytes: 23764
def main():
    import sys
    input = sys.stdin.buffer.readline
    X, Y, A, B, C = (int(i) for i in input().split())
    P = [-int(i) for i in input().split()]
    Q = [-int(i) for i in input().split()]
    R = [-int(i) for i in input().split()]
    from heapq import heapify, heappop
    heapify(P)
    heapify(Q)
    heapify(R)
    eatP = 0
    eatQ = 0
    eatR = 0
    ans = 0
    while X != eatP and Y != eatQ and eatP + eatQ + eatR < X + Y:
        if P and Q and R:
            cur = min(P[0], Q[0], R[0])
        elif P and Q:
            cur = min(P[0], Q[0])
        elif Q and R:
            cur = min(Q[0], R[0])
        elif R and P:
            cur = min(R[0], P[0])
        elif P:
            cur = P[0]
        elif Q:
            cur = Q[0]
        elif R:
            cur = R[0]
        else:
            break
        ans -= cur
        if R and R[0] == cur:
            heappop(R)
            eatR += 1
        elif P and P[0] == cur:
            heappop(P)
            eatP += 1
        elif Q and Q[0] == cur:
            heappop(Q)
            eatQ += 1

    if eatP + eatQ + eatR == X + Y:
        return print(ans)
    if X != eatP:
        while X != eatP and eatP + eatQ + eatR < X + Y:
            if R and P:
                cur = min(R[0], P[0])
            elif R:
                cur = R[0]
            elif P:
                cur = P[0]
            else:
                break
            ans -= cur
            if R and R[0] == cur:
                heappop(R)
                eatR += 1
            elif P and P[0] == cur:
                heappop(P)
                eatP += 1
    elif Y != eatQ:
        while Y != eatQ and eatP + eatQ + eatR < X + Y:
            if R and Q:
                cur = min(R[0], Q[0])
            elif R:
                cur = R[0]
            elif Q:
                cur = Q[0]
            else:
                break
            ans -= cur
            if R and R[0] == cur:
                heappop(R)
                eatR += 1
            elif Q and Q[0] == cur:
                heappop(Q)
                eatQ += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 87500
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"


template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef cc_hash_table<int, int, hash<int > > ht;


#define int long long 
#define  st first
#define  nd second

const int M = 1000000007;
const int  maxn = 100001;
const int  inf =  1e16;

void run_tests(){
  int n ; 
  cin >> n ; 
  vector<pair<int,int> > v(n) ; 
  for(int i = 0 ;i < n ; i++){
    cin >> v[i].st >> v[i].nd;
  }
  bool ok =false;
  for(int i = 2 ; i<n ; i++){
    if(v[i].st==v[i].nd and v[i-1].st==v[i-1].nd and v[i-2].st==v[i-2].nd){
      ok = true;
    }
  }
  if(ok){
    cout <<"Yes";
  }
  else{
    cout <<"No";
  }
  


}
int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);

  int te=1 ; 
  //cin >> te ; 
  while(te--){
    run_tests();
  }
  
  }

  
  

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, K,sum = 0;
    cin >> A >> B >> C >> K;
    while (K)
    {
        if (A > 0)
        {
            K--;
            A--;
            sum++;
        }
        else if (B > 0)
        {
            K--;
            B--;
        }
        else if (C > 0)
        {
            C--;
            sum--;
            K--;
        }
        else
            break;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;

void main() {
  int a, b;
  readf("%d %d\n", &a, &b);
  writeln( a>9 || b>9 ? -1 : a*b);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vvl black(4 * k, vl(4 * k, 0));
    vvl white(4 * k, vl(4 * k, 0));
    ll k2 = 2 * k;
    for (int i = 0; i < n; ++i) {
        ll x, y;
        char c;
        cin >> x >> y >> c;
        x %= k2;
        y %= k2;
        if (c == 'W') {
            white[y][x]++;
            white[y + k2][x]++;
            white[y][x + k2]++;
            white[y + k2][x + k2]++;
        } else {
            black[y][x]++;
            black[y + k2][x]++;
            black[y][x + k2]++;
            black[y + k2][x + k2]++;
        }
    }
    for (int i = 1; i < 4 * k; ++i) {
        for (int j = 0; j < 4 * k; ++j) {
            black[i][j] += black[i - 1][j];
            white[i][j] += white[i - 1][j];
        }
    }
    for (int i = 1; i < 4 * k; ++i) {
        for (int j = 0; j < 4 * k; ++j) {
            black[j][i] += black[j][i - 1];
            white[j][i] += white[j][i - 1];
        }
    }
    ll ret   = 0;
    auto sum = [](int y2, int x2, int y1, int x1, vvl &arr) {
        return arr[y2][x2] - arr[y2][x1] - arr[y1][x2] + arr[y1][x1];
    };
    for (int i = 0; i < 2 * k; ++i) {
        for (int j = 0; j < 2 * k; ++j) {
            ll temp = 0;
            temp += sum(i + k2, j + k2, i + k, j + k, black);
            temp += sum(i + k, j + k, i, j, black);
            temp += sum(i + k2, j + k, i + k, j, white);
            temp += sum(i + k, j + k2, i, j + k, white);
            chmax(ret, temp);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 250624
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\0536-input.txt"));

		while (scan.hasNext()) {

			int d = scan.nextInt();
			if (d == 0)
				break;
			int n = scan.nextInt();
			int m = scan.nextInt();
			Piza p = new Piza(d);
			for (int i = 1; i < n; i++)
				p.addStore(scan.nextInt());
			p.sort();
			int result = 0;
			for (int i = 0; i < m; i++)
				result += p.addDeliver(scan.nextInt());

			System.out.println(result);
		}

		scan.close();
		System.exit(0);
	}
}

class Piza {
	public Piza(int d) {
		store.add(0);
		store.add(d);
	}

	public void sort() {
		store.sort(null);
	}

	public int addDeliver(int k) {
		int i = store.size() / 2;
		int s = i / 2;
		while (true) {
			if (store.get(i) == k)
				break;
			else if (store.get(i) > k)
				i -= s;
			else if (store.get(i + 1) >= k)
				break;
			else
				i += s;
			if (s > 1)
				s /= 2;
		}
		return (Math.min(k - store.get(i), store.get(i + 1) - k));
	}

	public void addStore(int d) {
		store.add(d);
	}

	List<Integer> store = new ArrayList<Integer>();

}

Measured memory_bytes: 71488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll i,j,k,a,b,c,n,x,l,h,y,s=0,p=0,q=0;
	cin>>n;
	vector<ll> vv;
	for(i=0;i<n;i++)
	{
		cin>>a;
		vv.push_back(a);
	}
	l=0;
	
	while(l<n)
	{
		p=p+1;q=0;
		for(i=l;i<n;i++)
		{
			if(vv[i]==p)
			{l=i;
				q=1;
				s=s+1;
				break;
			}
		
		}
		if(q==0 )
		{break;
		}
		
		
	}
	if(q==0 && s>0) cout<<n-s;
	else cout<<-1;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  int amari=7%k;
  for(int i=1;i<=k;i++){
    if(amari==0){
      cout<<i<<endl;
      return 0;
    }
    amari=(amari*10+7)%k;
  }
  cout<<-1<<endl;
  return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	vector<vector<int> > u(n, vector<int>(3));
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	u[0][0] = a[0];
	u[0][1] = b[0];
	u[0][2] = c[0];
	for (int i = 1; i < n; i++) {
		u[i][0] = a[i] + max(u[i - 1][1], u[i - 1][2]);
		u[i][1] = b[i] + max(u[i - 1][0], u[i - 1][2]);
		u[i][2] = c[i] + max(u[i - 1][0], u[i - 1][1]);
	}
	cout << max(u[n - 1][0], max(u[n - 1][1], u[n - 1][2]));
}


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

int main(){
int A, B;
cin >> A >> B;
if (A == 1) {
    A = 14; 
}
if (B == 1) {
    B = 14;
}
if (A == B) {
    cout << "Draw" << endl;
}
else if (A > B) {
    cout << "Alice" << endl;
}
else if (A < B) {
    cout << "Bob" << endl;
}
}

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

int main(){
  int n;
  cin >> n;
  int u[n],v[n],w[n],flag[n];
  vector<vector<int>> vec(n),wei(n);
  rep(i,n-1){
    cin >> u[i] >> v[i] >> w[i];
    u[i]--;v[i]--;
    vec[u[i]].push_back(v[i]);
    vec[v[i]].push_back(u[i]);
    wei[u[i]].push_back(w[i]);
    wei[v[i]].push_back(w[i]);
    flag[i] = -1;
  }
  flag[n-1] = -1;
  queue<int> que;
  que.push(0);
  flag[0] = 0;
  while(!que.empty()){
    int now = que.front();
    que.pop();
    rep(i,int(vec[now].size())){
      if(flag[vec[now][i]]==-1){
        que.push(vec[now][i]);
        flag[vec[now][i]] = (wei[now][i]%2 ? !flag[now]:flag[now]);
      }
    }
  }
  rep(i,n)cout << flag[i] << endl;
  return 0;
}

Measured memory_bytes: 15680
#include <iostream>

using namespace std;

char s[100][100];

int main() {
    int i,j,H,W;
    cin >> H >> W;
    for(i=0;i<H;i++)for(j=0;j<W;j++)cin >> s[i][j];
    for(j=0;j<W+2;j++)cout << '#';
    cout << endl;
    for(i=0;i<H;i++){
      cout << '#';
      for(j=0;j<W;j++)cout << s[i][j];
      cout << '#' << endl;
    }
    for(j=0;j<W+2;j++)cout << '#';
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std ;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 100005
#define inf 2e18
// choices for each , states
// a + b = a^b + 2*(a&b)
#define Nitro ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) ;
int main()
{
    Nitro ;
    string s ,t ;
    cin >> s >> t; 
    int cnt = 0 ;
    for(int i = 0; i < s.length() ;i++){
        if(s[i] != t[i]){
            cnt ++ ;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3764
#include <cstdio>

bool is_uruu(int y) {
  if (y % 400 == 0) return true;
  if (y % 100 == 0) return false;
  if (y % 4 == 0) return true;
  return false;
}

int testcase_ends(bool first) {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a == 0 && b == 0) return 1;

  if (!first) puts("");

  bool na = true;
  for (int i = a; i <= b; ++i)
    if (is_uruu(i)) {
      printf("%d\n", i);
      na = false;
    }

  if (na) puts("NA");
  return 0;
}

int main() {
  bool first = true;
  while (!testcase_ends(first)) {
    first = false;
  }
}



Measured memory_bytes: 2592
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M,X = inpl()
aa = inpl()
ind = bisect.bisect_left(aa,X)
print(min(ind,M-ind))


Measured memory_bytes: 4204
not_delicious_antidote, delicious_antidote, delicious_poison = [int(i) for i in input().split()]

if delicious_antidote >= delicious_poison - 1:
    print(delicious_antidote + delicious_poison)
elif not_delicious_antidote >= delicious_poison - delicious_antidote - 1:
    print(delicious_antidote + delicious_poison)
else:
    print(delicious_antidote * 2 + not_delicious_antidote + 1)

Measured memory_bytes: 2940
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int n, m;
        cin >> n >> m;
        vector<int> a(n);
        for (auto &x : a)
            cin >> x;
        int sum = accumulate(all(a), 0LL);
        int cnt = 0;
        for (auto &x : a)
        {
            cnt += x / (sum * 1.0) >= 1 / (4.0 * m);
        }
        if (cnt >= m)
            cout << "Yes";
        else
            cout << "No";
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back

const int N = 1e5 + 10;

typedef pair<int, int> ii;

string s;
int n, m;
int a[N], pr[N], sum[N];
ii t[N];

int findn(int i) {
    return (pr[i] == i) ? i : (pr[i] = findn(pr[i]));
}

void uni(int u, int v)  {
    if(findn(u) != findn(v))    {
        int pu = findn(u), pv = findn(v);
        sum[pu] = (sum[pu] + sum[pv]) % 26;
        pr[pv] = pu;
    }
}

signed main()
{
    //freopen("test.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> s >> m;
    FOR(i, 1, m) cin >> t[i].fi >> t[i].se, t[i].se ++;
    n = s.length() + 1;
    for(int i = 0; i < s.length(); ++i) {
        a[i + 2] = s[i] - 'a';
        //cout << a[i + 2] << ' ';
    }
    //cout << '\n';
    FOR(i, 1, n) a[i] = (a[i] - a[i + 1]) % 26;
    //FOR(i, 1, n) cout << a[i] << ' ';
    FOR(i, 1, n) pr[i] = i, sum[i] = a[i];
    FOR(i, 1, m)    uni(t[i].fi, t[i].se);
    FOR(i, 1, n / 2) uni(i, n - i + 1);
    FOR(i, 1, n) if(sum[findn(i)] != 0) {
        cout << "NO";
        return 0;
    }
    cout << "YES"; return 0;
}


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

int main() {
  string s;
  cin >> s;
  vector<int> a(4);
  int r = 0;
  for (a[0] = 1; a[0] <= 3; a[0]++) {
    for (a[1] = 1; a[1] <= 3; a[1]++) {
      for (a[2] = 1; a[2] <= 3; a[2]++) {
        for (a[3] = 1; a[3] <= 3; a[3]++) {
          if (a[0] + a[1] + a[2] + a[3] != s.size()) {
            continue;
          }
          bool ok = true;
          int k = 0;
          for (auto l : a) {
            int m = 0;
            for (int i = k; i < k + l; i++) {
              m *= 10;
              m += s[i] - '0';
            }
            if (256 <= m) {
              ok = false;
            }
            if (m == 0 && l != 1) {
              ok = false;
            }
            if (m != 0 && s[k] == '0') {
              ok = false;
            }

            k += l;
            // cerr << m << " ";
          }
          // cerr << endl;
          r += ok;
          // if (ok) {
          //   for (auto e : a) {
          //     cerr << e << " ";
          //   }
          //   cerr << endl;
          // }
        }
      }
    }
  }
  cout << r << endl;
}



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

using namespace std;

int N;
int Cards[200][3];
int Total[200];
map<int, int> ColInfo[3];

void solve() {
	int curNum;

	for (int j = 0; j < 3; ++j) {
		for (int i = 0; i < N; ++i) {
			curNum = Cards[i][j];
			if (ColInfo[j][curNum] != 1) {
				continue;
			}
			Total[i] += curNum;
		}
	}

	for (int i = 0; i < N; ++i) {
		cout << Total[i] << endl;
	}
}

int main() {
	int num;

	memset(Total, 0, sizeof(Total));
	cin >> N;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> num;
			Cards[i][j] = num;
			++ColInfo[j][num];
		}
	}
	solve();

	return 0;
}


Measured memory_bytes: 3104
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
const char nl = '\n';
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
//The following debugging code was taken from Benjamin Qi's template :) 
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef LOCAL 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
//CODE STARTS HERE-----------------------------------------------------------------------------------------// 
const int N = 3001;
int n; ll a[N], dp[N][N][2];
ll solve(int l, int r, int t){
    dbg(l, r, t);
    if(dp[l][r][t] != -1)
        return dp[l][r][t];
    if(r == l){
        return dp[l][r][t] = a[r]*(t==0?1:-1);
    }
    if(t == 0){
        dp[l][r][t] = max(solve(l, r-1, t^1)+a[r], solve(l+1, r, t^1)+a[l]);
        dbg(dp[l][r][t],l,r,t);
        return dp[l][r][t];
    }
    else{
        dp[l][r][t] = min(solve(l, r-1, t^1)-a[r], solve(l+1, r, t^1)-a[l]);
        dbg(dp[l][r][t],l,r,t);
        return dp[l][r][t];
    }
}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i =0; i < n; i++){
        cin >> a[i];
    }
    cout << solve(0, n-1, 0) << nl;
}

Measured memory_bytes: 144656
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> X(N);
  for(int i=0;i<N;i++) cin >> A[i];
  for(int i=0;i<N;i++){
    if(i==0){
      ll sub=2*A[N-1];
      for(int j=N-2;j>=0;j--){
        sub=2*A[j]-sub;
      }
      X[0]=sub/2;
    }else{
      X[i]=2*A[i-1]-X[i-1];
    }
  }
  for(int i=0;i<N;i++){
    cout << X[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 2944
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Exception;
import java.lang.Integer;
import java.lang.String;
import java.lang.System;
import java.util.Arrays;

class Main {
    public static void main(String[] a) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int [] mountains = new int[10];
        int i = 0;
        while (true) {
            String s = r.readLine();
            mountains[i++] = Integer.valueOf(s);
            if(i >= 10) break;
        }
        Arrays.sort(mountains);
        for(i = 9; i > 6; i--) {
            System.out.println(mountains[i]);
        }
    }
}

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

int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    int x;
    cin >> x;
    int now;
    int cnt = 0;
    for (int i = 0; i < a + 1; i++) {
        for (int j = 0; j < b + 1; j++) {
            now = x - (500 * i + 100 * j);
            
            if (now  > 0) {
                if (now / 50 <= c) {
                    if (now - now / 50 * 50 == 0) cnt++;
                }
            }
            else if (now == 0) cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define pb push_back


///Input/Output macros!
#define gi(x) scanf("%d", &x)
#define gi2(x, y) scanf("%d%d", &x, &y)
#define gi3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define gill(x) scanf("%lld", &x)
#define gill2(x, y) scanf("%lld%lld", &x, &y)
#define gill3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define pi(x) printf("%d\n", x)
#define pill(x) printf("%lld\n", x)


///Basic Debugging macros!
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(ll __i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(ll __i__=0;__i__<r;__i__++){for(ll __j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

using namespace std;

///Power of 2 till 2^31!
ll pow2[32] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648};

///Power function!
ll power(ll x,ll y)
{
        ll res = 1;
        while(y>0){
            if(y&1)
                res *= x;
            y>>=1;
            x*=x;
        }
        return res;
}

///Basic Sieve of Eratosthenes!
void Sieve(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
        cout<<p<<' ';
          //cout <<  << " ";
}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool isPerfectSquare(ll x){ ll s = sqrt(x); return (s*s == x);}

bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

bool isPrime(int n){if (n <= 1)return false;if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0)return false;
    return true;
}

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;


const int MOD = 1000000007;
const long double PI = 4*atan((long double)1);
const ll INF = 1e18;

int main()
{
    cout.precision(8);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> x,y,a;
    for(int i=0;i<n;++i){
        int val;
        cin>>val;
        x.push_back(val);
        cin>>val;
        y.push_back(val);
        a.push_back(i);
    }
    double ans = 0;
    do{
        double dis = 0;
        for(int i=1;i<n;++i){
            dis += sqrt((x[a[i]]-x[a[i-1]])*(x[a[i]]-x[a[i-1]]) + (y[a[i]]-y[a[i-1]])*(y[a[i]]-y[a[i-1]]));
        }
        ans += dis;
    }
    while(next_permutation(a.begin(),a.end()));
    ll fact = 1;
    for(int i=2;i<=n;++i) fact *= i;
    ans /= fact;
    cout<<fixed<<ans<<'\n';
}


Measured memory_bytes: 256
#include<stdio.h>
int main (void)
{
   int a,b,c,d,x,y,s;
   scanf("%d%d%d%d",&a,&b,&c,&d);
   if(a>b)
     x=b;
   else x = a;
   if(c>d)
     y=d;
   else y = c;
   s=x+y;
   printf("%d\n",s);
   return 0;
}


Measured memory_bytes: 256