akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(vector<vector<int>>& A) {
        int n = A.size();
        int N = n * n;
        auto encode = [&](int x, int y) {
            if (x > y) {
                swap(x, y);
            }
            return x * n + y;
        };

        vector<vector<int>> graph(N);
        vector<int> indegrees(N, 0);
        for (int i = 0; i < n; ++i) {
            for (int j = 1; j + 1 < n; ++j) {
                int u = encode(i, A[i][j - 1]);
                int v = encode(i, A[i][j]);
                graph[u].push_back(v);        
                indegrees[v] += 1;
            }
        }

        vector<int> ord;
        for (int i = 0; i < N; ++i) {
            if (indegrees[i] == 0) {
                ord.push_back(i);
            }
        }

        for (int i = 0; i < ord.size(); ++i) {
            int u = ord[i];
            for (auto v : graph[u]) {
                if (--indegrees[v] == 0) {
                    ord.push_back(v);
                }
            }
        }
        for (int i = 0; i < N; ++i) {
            if (indegrees[i] != 0) {
                return -1;
            }
        }

        vector<int> dp(N, 0);
        reverse(ord.begin(), ord.end());

        for (auto u : ord) {
            int ans = 0;
            for (auto v : graph[u]) {
                ans = max(ans, dp[v]);
            }
            ans += 1;
            dp[u] = ans;
        }

        int res = *max_element(dp.begin(), dp.end());
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<vector<int>> A(N);
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j + 1 < N; ++j) {
            int x;
            cin >> x;
            --x;
            A[i].push_back(x);
        }
    }
    Solution sol;
    cout << sol.solve(A) << "\n";

    return 0;
}

Measured memory_bytes: 55148
#include<bits/stdc++.h>
using namespace std;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*ff;
}
void write(long long aa)
{
	if(aa<0) putchar('-'),aa=-aa;
	if(aa>9) write(aa/10);
	putchar('0'+aa%10);
	return;
}
long long n,now,ans;
char s[200005];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(long long i=0;i<n;++i)
	if(s[i]=='A') now++;
	else if(s[i]=='B')
	{
		if(s[i+1]=='C') ans+=now,i=i+1;
		else now=0;
	}
	else now=0;
	write(ans);
	return 0;
}

Measured memory_bytes: 384
import numpy as np
N = int(input())
A, B = [], []
Z = []
 
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
 
    Z.append(-a - b)
 
indexes = np.argsort(Z)
ans = 0
for cnt, i in enumerate(indexes):
    if cnt % 2 == 0:
        ans += A[i]
    else:
        ans -= B[i]
 
print(ans)


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

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

  int fx = 0;
  int num = N;
  while (num > 0) {
    fx += num % 10;
    num = num / 10;
  }

  if (N % fx == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int a, b, c; cin >> a >> b >> c;
    if(b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3560
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^8 -> 8回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b.at(i);
    vector<int> a(n);
    a.at(0) = b.at(0);
    for (int i = 1; i <= n - 2; i++) {
        a.at(i) = min(b.at(i - 1), b.at(i));
    }
    a.at(n - 1) = b.at(n - 2);
    ll ans = 0;
    rep(i, n) ans += a.at(i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1
#define true 1
#define false 0

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
int X[N][N];

void printBoard(void);
void recursive(int);

int main()
{
  int i, j, k, r, c;

  for(i=0;i<N;i++)
    {
      row[i] = FREE, col[i] = FREE;
    }
  
  for(i=0;i<2*N-1;i++)
    {
      dpos[i] = FREE, dneg[i] = FREE;
    }

  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  X[i][j] = false;
	}
    }

  scanf("%d", &k);
  for(i=0;i<k;i++)
    {
      scanf("%d%d", &r, &c);
      X[r][c] = true;
    }

  recursive(0);
  
  return 0;
}

void printBoard(void)
{
  int i, j;

  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  if(X[i][j])
	    {
	      if(row[i] != j)return;
	    }
	}
    }
  
  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  if(row[i] != j)printf(".");
	  else printf("Q");
	}
      printf("\n");
    }
}

void recursive(int i)
{
  int j;
  
  if(i == N)
    {
      printBoard();
      return;
    }

  for(j=0;j<N;j++)
    {
      if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE)continue;
      row[i] = j; col[j] = NOT_FREE; dpos[i+j] = NOT_FREE; dneg[i-j+N-1] = NOT_FREE;
      recursive(i+1);
      row[i] = FREE; col[j] = FREE; dpos[i+j] = FREE; dneg[i-j+N-1] = FREE;
    }
}



Measured memory_bytes: 2108
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
map<string,int> ma;
string str;
typedef pair<bool,string> p;
int main(){
	queue<p> que;
	cin>>n;
	bool flag = true;
	for(int i = 0;i < n;i++){
		cin>>str;
		ma[str]=1;
	}
	cin>>m;
	for(int i =0;i <m;i++){
		cin>>str;
		if(ma[str]==1){
			que.push(p(true,str));
		}else{
			que.push(p(false,str));
		}
	}
	while(!que.empty()){
		if(que.front().first){
			if(flag){
				cout <<"Opened by "<<que.front().second;
				flag =false;
			}
			else{
				cout <<"Closed by "<<que.front().second;
				flag =true;
			}
		}else{
			cout <<"Unknown "<<que.front().second;
		}
		que.pop();
		cout<<endl;
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H.at(i);
  }
  int mx = H.at(0);
  int ans = 1;
  for (int i = 1; i < N; ++i) {
    if (H.at(i) >= mx) {
      ++ans;
      mx = H.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>
#include <queue>
#include <assert.h>
#include <set>
#include <numeric>
#include <memory.h>

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

//#define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

int N, W;
int v[110], w[110];
ll dp[100][10001];

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N >> W;
    REP(i,N) cin >> v[i] >> w[i];

    REP(i,N) {
        REP(j,10001) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    dp[0][v[0]] = w[0];
    REP(i,N-1) REP(j,10001) {
        if (dp[i][j] != INF) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j+v[i+1]] = min(dp[i+1][j+v[i+1]], dp[i][j] + w[i+1]);
        }
    }

    /*
    REP(i,N) {
        REP(j,20) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
    */

    int ans = 0;
    REP(i,10001) {
        if (dp[N-1][i] <= W) ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10900
#pragma GCC optimize("O3") 

#include <bits/stdc++.h>
using namespace std;

typedef long long int           ll;
typedef unsigned long long int  ull;
typedef long double             ld;

typedef pair<int, int>          pii;
typedef pair<ll,ll>             pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<pii>             vpii;
typedef vector<pll>             vpll;

#define test(t)		        int t; cin >> t; while(t--)
#define f(i, a, b)	        for(int (i) = (a); (i) < (b); ++(i))
#define all(a)		        (a).begin(), (a).end()
#define endl 		        "\n"
#define maxvec(vec)             *max_element(all(vec))
#define minvec(vec)             *min_element(all(vec))
#define maxarr(arr)             *max_element(arr, arr + n)
#define minarr(arr)             *min_element(arr, arr + n)
#define deb(x)		        cout << #x << ": " << x << endl;
#define deb2(x,y)	        cout << #x << ": " << x << " ~ " <<  #y << ": " << y << endl;
#define deba(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast 		        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007
#define PI		3.141592653589793238462643383279502884L

void solve()
{
    ll x, k, d;
    cin >> x >> k >> d;
    ll temp = x / d;
/*    if(temp == 0)
    {
        if(k % 2 == 0)
            cout << abs(x) << endl;
        else
            cout << abs(abs(x) - d) << endl;
        return;
    }
*/
    if(abs(temp) > k)
    {
        cout << abs(abs(x) - (k * d)) << endl;
    }
    else
    {
        k = abs(k - abs(temp));
        x = abs(abs(x) - (abs(temp) * d));
        if(k % 2 == 0)
            cout << abs(x) << endl;
        else
            cout << abs(abs(x) - d) << endl;
    }
  
}

int main()
{
    fast;
    //test(t)
        solve();
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    s64 n;
    cin >> n;
    s64 k;
    cin >> k;

    vs32 g(n);
    rep (i, n)
    {
        int v;
        cin >> v;
        --v;
        g[i] = v;
    }

    vs32 cnt(n, 0);
    s64 from = 0;
    while (cnt[from] < 2)
    {
        ++cnt[from];
        from = g[from];
    }

    s64 s = 0;
    rep (i, n) if (cnt[i] == 2) ++s;

    s64 d = 0;
    from = 0;
    while (cnt[from] != 2)
    {
        from = g[from];
        ++d;
    }

    if (k < d)
    {
        from = 0;
    }
    else
    {
        k -= d;
        k %= s;
    }

    rep (i, k)
    {
        from = g[from];
    }

    cout << from + 1 << "\n";
    return 0;
}



Measured memory_bytes: 4784
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
//using namespace atcoder;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), B(1000001,0), memo(1000001,0), C;
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        memo[A[i]]++;
    }
    ll ans = 0;
    rep(i,N){
        if(memo[A[i]] > 1){
            memo[A[i]]--;
            B[A[i]]++;
            continue;
        }
        C.push_back(A[i]);
    }
    /*
    if(memo[1] > 1){
        rep(i,N){
            if(A[i] == 1) continue;
            C.push_back(A[i]);
        }
    }else{
        C = A;
    }*/
    N = C.size();
    rep(i,N){
        ll cur = C[i];
        while(cur <= 1000000){
            B[cur]++;
            cur += C[i];
        }
    }
    rep(i,N){
        if(B[C[i]] == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

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

typedef long long LL;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int N = 400;
const int M = 100000;
const int oo = 0x3f3f3f3f;

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n, m;
bool ban[N + 5];
int x[M + 5], y[M + 5];
bitset <N + 5> f[N + 5];

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i) f[i][i] = true;
    for(int i = 1; i <= m; ++i) {
        scanf("%d%d", x + i, y + i);
    }

    for(int i = m; i >= 1; --i) {
        for(int j = 1; j <= n; ++j) {
            if(f[j][x[i]] && f[j][y[i]]) { ban[j] = true; continue; }
            if(f[j][x[i]]) f[j][y[i]] = true;
            if(f[j][y[i]]) f[j][x[i]] = true;
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i) if(!ban[i])
        for(int j = i + 1; j <= n; ++j) if(!ban[j] && (f[i] & f[j]).none()) {
            ++ ans;
        }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var ans = 0;
            var kuti = 1;
            while(kuti < B)
            {
                ans++;
                kuti += A - 1;
            }
            WriteLine(ans);
        }



        public long C(int X, int Y)
        {

            if (Y == 0 || Y == X)
            {
                return 1;
            }
            if (X < Y)
            {
                return 0;
            }
            var Pascal = new long[X + 1, X + 1];
            for (int i = 0; i <= X; i++)
            {
                Pascal[i, 0] = 1L;
                Pascal[i, i] = 1L;
            }
            for (int i = 2; i <= X; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[X, Y];
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vsort_reverse(v) sort(v.begin(), v.end(), greater<int>());
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int count = 0;
	A = min(A, 40);

	for(int a = 0; a <= A; a++) {
		for(int b = 0; b <= B; b++) {
			for(int c = 0; c <= C; c++) {
				if(X == a * 500 + b * 100 + c * 50) count += 1;
			}
		}
	}
	cout << count << endl;
}


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


int main() {
  ll n; cin >> n;
  Vll a(3*n); cin >> a;
  Vll l(n+1), r(n+1);

  {
    priority_queue<int, vector<int>, greater<int>> pq;
    ll sum = 0;
    rep(i, n) {
      sum += a[i];
      pq.push(a[i]);
    }

    l[0] = sum;
    rep(i, n) {
      sum += a[n+i];
      pq.push(a[n+i]);
      sum -= pq.top(); pq.pop();
      l[i+1] = sum;
    }
  }
  
  {
    priority_queue<int> pq;
    ll sum = 0;
    drep(i, n) {
      sum += a[2*n+i];
      pq.push(a[2*n+i]);
    }

    r[n] = sum;
    drep(i, n) {
      sum += a[n+i];
      pq.push(a[n+i]);
      sum -= pq.top(); pq.pop();
      r[i] = sum;
    }
  }

  ll ans = -INFll;
  rep(i, n+1) chmax(ans, l[i] - r[i]);
  printf("%lld", ans);
  return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string x = "No";
    if(a==b && a!=c) x = "Yes";
    if(a==c && a!=b) x = "Yes";
    if(b==c && b!=a) x = "Yes";
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll cnt[3];

int main(){
	ll k,s;
	cin >> k >> s;

	//x<y<z  6倍
	rep(x,k+1){
		arep(x+1,y,k+1){
			arep(y+1,z,k+1){
				if(x+y+z==s)
					cnt[0]++;
			}
		}
	}


	//x=y<z  3倍
	rep(x,k+1){
		arep(x+1,z,k+1){
			if(x+x+z==s)
				cnt[1]++;
		}
	}


	//x<y=z  3倍
	rep(x,k+1){
		arep(x+1,y,k+1){
			if(x+y+y==s)
				cnt[2]++;
		}
	}


	//x=y=z  1倍
	rep(x,k+1){
		if(x+x+x==s)
			cnt[3]++;
	}

	cout << cnt[0]*6+cnt[1]*3+cnt[2]*3+cnt[3] << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;


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

    vector<long long> s(N+1, 0);
    map<long long, long long> nums;
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
    for (int i = 0; i < N+1; ++i) nums[s[i]]++;
    
    long long res = 0;
    for (auto it : nums) {
        long long num = it.second;
        res += num * (num - 1) / 2;
    }
    cout << res << endl;
} 

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e6+10;
int a[maxn],n,b[maxn],p[maxn];
bool check(int x){
	REP(i,1,2*n-1) b[i]=(a[i]>=x);
	memset(p,0,sizeof(p));
	for(int i=1,j;i<2*n;i=j+1){
		j=i;
		while(j<2*n-1 && b[j+1]==b[i]) ++j;
		if(j>i) REP(k,i,j) p[k]=1;
	}
	if(p[n]==1) return b[n];
	int L=n,R=n;
	while(L>1 && !p[L-1]) --L;
	while(R<2*n-1 && !p[R+1]) ++R;
	if(L==1 && R==2*n-1) return (b[n]^((n-1)&1));
	if(n-L>=R-n) return b[R+1];
	return b[L-1];
}
int main(){
	n=read();
	REP(i,1,2*n-1) a[i]=read();
	int L=1,R=2*n-1;
	while(L<=R){
		int Mid=(L+R)>>1;
		if(check(Mid)) L=Mid+1;
		else R=Mid-1;
	}
	printf("%d\n",L-1);
	return 0;
}


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

using namespace std;

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

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;


class Unionfind{
	public:
		void init(int n){
			parent.resize(n+1);
			rank.resize(n+1);
			rep(i,n+1) parent[i]=i,rank[i]=0;
		}

		int find(int x){
			return (parent[x]==x)?x:parent[x]=find(parent[x]);
		}

		void unite(int x,int y){
			x=find(x); y=find(y);
			if(x== y)return ;

			if(rank[x]<rank[y])
				parent[x]=y;
			else{
				parent[y]=x;
				if(rank[x] == rank[y])
					rank[x]++;
			}
		}

		bool same(int x, int y){
			return find(x) == find(y);
		}

	private:
		vi parent;
		vi rank;
};

typedef tuple<int,int,int> edge;

int main(void){
	Unionfind uf;
	int n,m;
	while(cin >> n >> m){
		vector<edge> edges;
		if(n==0)
			break;
		rep(i,m){
			int a,b,w;
			cin >> a >> b >> w;
			edges.emplace_back(make_tuple(w,a,b));
		}
		sort(edges.begin(),edges.end());
		int ans=inf;
		int cmin=0;
		rep(i,m){
			int cur,cmax;
			tie(cur,ignore,ignore)=edges[i];
			if(cur<=cmin)
				continue;
			cmax=cmin=cur;
			uf.init(n);
			for(int j=i;j<m;++j){
				int a,b,w;
				tie(w,a,b)=edges[j];
				if(!uf.same(a,b)){
					uf.unite(a,b);
					cmax=w;
				}
			}
			bool ok=true;
			for(int i=1;i<=n;++i)
				if(!uf.same(1,i))
					ok=false;
			if(ok)
				ans=min(ans,cmax-cmin);
		}
		if(ans==inf)
			cout << -1 << endl;
		else
			cout << ans << endl;
 	}
	return 0;
}

Measured memory_bytes: 1340
n = gets.to_i
n.times do
    p, q = gets.split.map(&:to_i)
    count = 0
    -145.upto(145) do |i|
        -145.upto(145) do |j|
            next if i == 0 && j == 0
            count += 1 if (i * p + j * q) % (i * i + j * j) == 0 && (i * q - j * p) % (i * i + j * j) == 0
        end
    end
    puts count == 8 ? "P" : "C"
end

Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,vector<int>> IV;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int n;cin >> n;
    vector<int> path[n+1];
    vector<P> side(n-1);
    for(int i=0; i<n-1; i++){
        int a,b;cin >> a >> b;
        path[a].push_back(b);
        path[b].push_back(a);
        side[i]={a,b};
    }
    queue<int> q;
    q.push(1);
    vector<bool> used(n+1,false);
    used[1]=true;
    map<P,int> mp;
    int k=0;
    while(!q.empty()){
        int now=q.front();q.pop();
        int cur=1,ng=0;
        if(path[now].size()>k) k=path[now].size();
        for(auto next: path[now]){
            if(used[next]) ng=mp[{now,next}];
        }
        for(auto next: path[now]){
            if(used[next]) continue;
            used[next]=true;
            if(cur==ng) cur++;
            mp[{now,next}]=mp[{next,now}]=cur;
            cur++;
            q.push(next);
        }
    }
    cout << k << endl;
    for(int i=0; i<n-1; i++){
        cout << mp[side[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 19328
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
string a;
signed main()
{
	cin>>a;
	rep(i,a.size()-1){
		if(a[i]=='A'&&a[i+1]=='C'){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int S=0;
	scanf("%d",&S);
	int h = S / 3600;
	int m = (S - h * 3600) / 60;
	int s = S - h * 60 * 60 - m * 60;
		printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}


Measured memory_bytes: 2044
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long LL;
typedef long double LD;

int n;
vector<LD> x, y;
vector<LD> angle;

double calc(LD r) {
	LD xs = 0, ys = 0;
	for (int i = 0; i < n; ++i) {
		if (r - M_PI/2 <= angle[i] && angle[i] <= r + M_PI/2) {
			xs += x[i], ys += y[i];
		}
	}
	return sqrt(xs * xs + ys * ys);
}


int main(int argc, char* argv[]) {
	cout.precision(12);

	cin >> n;
	x.resize(n);
	y.resize(n);
	angle.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
		angle[i] = atan2(y[i], x[i]);
		if (angle[i] < 0) {
			angle[i] += 2 * M_PI;
		}
	}
	LD left = 0, right = 2 * M_PI;

	for (int t = 0; t < 1000; ++t) {
		if (calc((left * 2 + right) / 3) > calc((left + right * 2) / 3)) {
			right = (left + right * 2) / 3;
		} else {
			left = (left * 2 + right) / 3;
		}
	}
	LD ans = calc(left);

	for (int i = 0; i < n; ++i) {
		angle[i] = atan2(x[i], y[i]);
		if (angle[i] < 0) {
			angle[i] += 2 * M_PI;
		}
	}
	left = 0, right = 2 * M_PI;

	for (int t = 0; t < 1000; ++t) {
		if (calc((left * 2 + right) / 3) > calc((left + right * 2) / 3)) {
			right = (left + right * 2) / 3;
		} else {
			left = (left * 2 + right) / 3;
		}
	}
	LD ans2 = calc(left);
	if (ans2 > ans) {
		ans = ans2;
	}

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


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int A[5],B,C,N,K,S,res=0,tmp=0;
pll ba[200200];

int main(){
    cout << fixed << setprecision(18);
    cin>>A[0]>>A[1]>>A[2];
    sort(A,A+3);
    if((2*A[2]-A[1]-A[0])%2==0){
        cout<<(2*A[2]-A[1]-A[0])/2<<endl;
    }else{
        cout<<(2*A[2]-A[1]-A[0])/2+2<<endl;
    }
}




Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail=(tail+1)%(LEN+1);
}

P dequeue(){
  P x=Q[head];
  head=(head+1)%(LEN+1);
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail){
    u=dequeue();
    if(q>u.t){ //小さい方を足す。
      elaps += u.t;
      u.t = 0;
    }
    else{
      u.t -= q;
      elaps += q;
    }
    if(u.t>0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  
  return 0;
}



Measured memory_bytes: 11868
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<iostream>
#include <stdlib.h>
#include<ctime>
#include <string>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
	int a;
	scanf("%d",&a);
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j < 10; j++)
		{
			if (i*j == a)
			{
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,s;
	int i,n,x;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		s=0;
		for(i=0;i<9;i++){
			scanf("%d",&a);
			s+=a;
		}	
		x=n-s;
		printf("%d\n",x);
	}
	return 0;
}	


Measured memory_bytes: 2036
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
 
using namespace std;

signed main()
{
    fast;
    string s;
    cin>>s;

    if ( s == "hi" )
    {
        cout<<"Yes"<<endl;
    }
    else if ( s == "hihi" )
    {
        cout<<"Yes"<<endl;
    }
    else if ( s == "hihihi" )
    {
        cout<<"Yes"<<endl;
    }
    else if ( s == "hihihihi" )
    {
        cout<<"Yes"<<endl;
    }
    else if ( s == "hihihihihi" )
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int pozc=-1, pozf=-1;
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++)
    {
        if(pozc == -1 && s[i] == 'C')
            pozc = i;
        if(s[i] == 'F')
            pozf = i;
    }

    if(pozc != -1 && pozf != -1 && pozc < pozf)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct N001 {
  std::vector<long> parents;
  std::vector<long> numbers;
  long n, q;
};
void init(N001& s, long n) {
  s.parents.resize(n+1, -1);
  s.numbers.resize(n+1, -1);
}
long find(N001& s, long x) {
  if( s.parents[x] == -1 ) return x;
  return s.parents[x] = find(s, s.parents[x]);
}
bool same(N001& s, long x, long y) {
  return find(s, x) == find(s, y);
}
void unite(N001& s, long x, long y) {
  long x2 = find(s, x);
  long y2 = find(s, y);
  if( x2 == y2 ) return;
  if( not ( s.numbers[x2] <= s.numbers[y2] ) )
    std::swap(x2, y2);
  s.parents[x2] = y2;
  s.numbers[y2] += s.numbers[x2];
}

struct Solver {
  Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
  ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
  N001 u;
  void solve() {
    long n, q;
    scan(n, q);
    // if( scanf("%ld %ld", &n, &q) < 0 ) exit(0);
    init(u, n);
    for(long i = 0; i < q; ++i) {
      long c, x, y;
      scan(c, x, y);
      // scanf("%ld %ld %ld", &c, &x, &y);
      if( c == 0 ) 
        unite(u, x, y);
      else
        puts(same(u, x, y) ? "1" : "0");
    }
  }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}  

Measured memory_bytes: 3328
line=input()
order=[]
for i in range(line):
	order.append(i+1)

time=input()
for n in range(time):
	inp=raw_input()
	num_pre=list(inp)
	num=[]
	if num_pre.index(",")==2:
		num.append(int(num_pre[0]+num_pre[1]))
	else:
		num.append(int(num_pre[0]))
	if len(num_pre)-num_pre.index(",")==3:
		num.append(int(num_pre[-2]+num_pre[-1]))
	else:
		num.append(int(num_pre[-1]))
	a=order[num[0]-1]
	b=order[num[1]-1]
	order[num[0]-1]=b
	order[num[1]-1]=a

for m in range(line):
	print order[m]

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

using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
    
 
    int A, B, C;
    int temp1, temp2=0;
    cin>>A>>B>>C;
    temp1 = B;
    B=A;
    A=temp1;
    temp2 = C;
    C=A;
    A=temp2;
    cout<<A<<" "<<B<<" "<<C<<"\n";
    
    return 0;
}


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

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

typedef long long ll;

const ll MAX_N=300,MAX_K=300;

ll N,K,M;

ll dp[MAX_N+1][MAX_K+1][MAX_N+1];

int main(){
	cin>>N>>K>>M;
	memset(dp,0,sizeof(dp));
	FOR(k,1,K+1){		
		FOR(n,1,N+1){
			for(ll m=n;m>0;m--){
				ll x;
				if (n==1){
					x=k%M;
				}else if (n==m){
					if (k==1){
						x=0;
					}else{
						x=(dp[n-1][k-1][1]*n+dp[n][k-1][1])%M;
					}
				}else{
					x=(dp[n-1][k][m]*m+dp[n][k][m+1])%M;
				}
				dp[n][k][m]=x;
			}
		}
	}
	cout<<dp[N][K][1]<<endl;
	return 0;
}

Measured memory_bytes: 213376
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0 ; i < n ; i++) {
            s[i] = sc.next();
        }
        boolean flg = true;
        for (int i = 0 ; i < n ; i++) {
            for (int j = i + 1 ; j < n ; j++) {
                if (s[i].equals(s[j])) flg = false;
            }
        }
        for (int i = 0 ; i < n - 1 ; i++) {
            if (s[i].charAt(s[i].length() - 1) != s[i + 1].charAt(0)) flg = false;
        }
        System.out.println(flg ? "Yes" : "No");
    }

}

Measured memory_bytes: 21844
//2020-04-12 17:29:15
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s;cin>>s;
    int n=s.length();
    bool yes=0;
    rep(i,0,n)
    if(s[i]=='7')yes=1;
    if(yes)cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3620
import math
def main():
    N=int(input())
    A=int(input())
    B=int(input())
    C=int(input())
    D=int(input())
    E=int(input())
    min_num=N+1
    for i in (A,B,C,D,E):
        min_num=min(i,min_num)
    print(math.ceil(N/min_num)+4)
    
if __name__=="__main__":
    main()

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

typedef long long ll;

#define W 100001
#define N 101
int n, weight;
ll w[N], v[N], dp[W][N];

signed main() {
        scanf("%d%d", &n, &weight);
        for (int i = 1; i <= n; i++)
                scanf("%lld%lld", &w[i], &v[i]);

        for (int j = 1; j <= n; j++)
                for (int i = 1; i <= weight; i++)
                        if (w[j] <= i)
                                dp[i][j] = max(dp[i-w[j]][j-1] + v[j], dp[i][j-1]);
                        else
                                dp[i][j] = dp[i][j-1];

        printf("%lld \n", dp[weight][n]);
}


Measured memory_bytes: 79104
S=list(input())
N=len(S)
ans=100

for s in S:
    i=0
    C=0
    count2=0
    while i<N:
        if s!=S[i]:
            count2+=1
        else:
            C=max(C,count2)
            count2=0
        i+=1
    C=max(C,count2)
    ans=min(C,ans)

print(ans)

Measured memory_bytes: 9156
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());
		
		int []a = new int [n];
		
		for(int i = 0 ;i < n-1 ;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		int []b = new int [n];
		
		for(int i= 0 ; i < n-1 ;i++) {
			b[a[i]-1]++;
		}
		
		for(int i = 0 ; i < n ;i++) {
			System.out.println(b[i]);
		}

	}

}


Measured memory_bytes: 51356
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int day;
		int num;
		int[] array;

		day = scan.nextInt();
		num = scan.nextInt();

		array = new int[num];

		int n = 0;
		while(n < array.length) {
			array[n] = scan.nextInt();
			n++;
		}

		int sum = 0;
		for(int i = 0; i < array.length; i++) {
			sum += array[i];
		}

		int minus = day - sum;
		if(minus < 0) {
			System.out.println(-1);
		} else {
			System.out.println(minus);
		}
	}
}


Measured memory_bytes: 46156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char ci[cm];
char *cn = ci + cm;
inline char getcha() {
	if (cn - ci == cm) { fread(ci, 1, cm, stdin); cn = ci; }
	return *cn++;
}

inline int getint() {
	char C = getcha();
	int A = C - '0';
	while ((C = getcha()) >= '0') A = A * 10 + C - '0';
	return A;
}

inline void putint(int X) {
	if (X == 0) putchar('0');
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) putchar(*(C + i));
	putchar('\n');
}

int oya;
int D[100001];
int P[100001];
pair<int, int> E[100001];
int EN[100002];
int sagasu(int A) {
	if (*(D + A)) return *(D + A);
	if (A == oya) return 1;
	for (int i = (*(EN + A)); i < (*(EN + A + 1)); i++) {
		int kari = sagasu((*(E + i)).second) + 1;
		if (*(D + A) < kari) {
			*(D + A) = kari;
			*(P + A) = (*(E + i)).second;
		}
	}
	return *(D + A);
}

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


	int N, M;
	N = getint();
	M = getint();
	bool kodomo[100001] = {};
	rep(i, N + M - 1) {
		int a, b;
		a = getint();
		b = getint();
		*(E + i) = mp(b, a);
		*(kodomo +b) = true;
	}

	rep1(i, N) {
		if (!(*(kodomo + i))) {
			oya = i;
			break;
		}
	}

	sort(E, E + N + M - 1);
	int k = 0;
	int mae = 0;
	EN[1] = 0;
	rep1(i, N) {
		while (k < N + M - 1 && E[k].first == i) k++;
		*(EN + i + 1) = k;
		mae = k;
	}

	rep1(i, N) {
		if (!(*(D + i))) sagasu(i);
		putint(*(P + i));
	}

	Would you please return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



ll divceil(ll x, ll y) {
    assert(y);
    return (x+y-1)/y;
}

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

    int n; cin>>n;
    ll l,r;
    for (int i=0; i<n; i++) {
	if (i==0) {
	    cin>>l>>r;
	} else {
	    ll a,b; cin>>a>>b;
	    ll alpha = max(divceil(l,a), divceil(r,b));
	    l=alpha*a;
	    r=alpha*b;
	}
    }

    ll ans = l+r;
    cout<<ans<<endl;    

    return 0;
}


Measured memory_bytes: 256