akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)

int n;
int m;

int s[100];
int t[100];

int main()
{
    while (cin >> n >> m, n)
    {
        rep(i, 0, n - 1) cin >> s[i];
        rep(i, 0, m - 1) cin >> t[i];
        int a = 0;
        int b = 0;
        rep(i, 0, n - 1) a += s[i];
        rep(i, 0, m - 1) b += t[i];
        using P2 = pair<int, P>;
        priority_queue<P2, vector<P2>, greater<P2>> que;

        rep(i, 0, n - 1) rep(j, 0, m - 1)
        {
            int c = a - s[i] + t[j];
            int d = b - t[j] + s[i];
            if (c == d)
            {
                que.push({s[i] + t[j], {s[i], t[j]}});
            }
        }

        if (que.empty())
        {
            cout << -1 << endl;
        }
        else
        {
            cout << que.top().second.first << " " << que.top().second.second << endl;
        }
    }
}


Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  if(a == 25){
    cout << "Christmas" << endl;
  }
  else if(a == 24){
    cout << "Christmas Eve" << endl;
  }
  else if(a == 23){
    cout << "Christmas Eve Eve" << endl;
  }
  else{
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

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

int main()
{
	int a, b, c, d;

	cin >> a >> b;

	c = a / b;
	
	d = a % b;

	double e;

	e = (double) a / b;

	cout << c << " " << d << " ";
		
	printf("%.5f", e);

        return 0;

}

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

#define ll long long

using namespace std;

const int m = 1003;
int n, a[m][m], lp[m], idx[m];
map<int, set<int>> days;

void put(int player, int day) {
    if (lp[player])
        days[lp[player]].erase(player);
    if (!days.count(day))
        days[day] = set<int>();
    days[day].insert(player);
    lp[player] = day;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n - 1; ++j)
            cin >> a[i][j];
        put(i, 0);
        idx[i] = 1;
    }

    int matches = 0;
    while (true) {
        bool move = false;
        for (auto &kv : days) {
            int day = kv.first;
            set<int>& players = kv.second;

            for (auto& player : players) {
                int op = a[player][idx[player]];

                //cout << day << " " << player << " vs " << idx[player] << endl;
                if (a[op][idx[op]] == player) {
                    move = true;
                    idx[op]++;
                    idx[player]++;
                    int tmp = max(lp[player], lp[op]) + 1;
                    put(player, tmp);
                    put(op, tmp);
                    matches +=2;
                    break;
                }
            }
        }
        if (!move) {
            if (matches == n * (n - 1))
                break;
            cout << -1;
            exit(0);
        }
    }
    int sol = 0;
    for (int i = 1; i <= n; ++i)
        sol = max(sol, lp[i]);
    cout << sol;
    return 0;
}


Measured memory_bytes: 51072
import java.util.*;

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

        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[h.length];

        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < h.length; i++) {
            int v1 = Math.abs(h[i] - h[i-2]) + dp[i-2];
            int v2 = Math.abs(h[i] - h[i-1]) + dp[i-1];
            dp[i] = Math.min(v1, v2);
        }

        System.out.println(dp[dp.length - 1]);

  }
}

Measured memory_bytes: 51292
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;
int main(){
  ll n;
  string s;
  cin >> n >> s;

  queue<int> w,r;
  for(int i=0;i<n;i++){
    if(s[i] == 'W'){
      w.push(i);
    }
  }

  for(int i=n-1;i>=0;i--){
    if(s[i] == 'R'){
      r.push(i);
    }
  }

  int nw,nr;
  int cnt = 0;
  if(w.empty() || r.empty()){
    cnt = 0;
  }else{
    nw = w.front();
    nr = r.front();

    while(nw < nr){
      cnt++;
      w.pop();
      r.pop();
      if(w.empty() || r.empty())
        break;
      nw = w.front();
      nr = r.front();
      if(nw >= nr)
        break;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 4408
#include <algorithm>
#include <list>
#include <iostream>
#include <sstream>

int main()
{
    int n;
    std::cin >> n;
    std::list<int> l{};

    std::string command;
    int num;

    for (int i = 0; i < n; i++) {

        std::cin >> command;
        if (command == "insert") {
            std::cin >> num;
            l.push_front(num);
        } else if (command == "delete") {
            std::cin >> num;
            auto itr = std::find_if(l.begin(), l.end(), [&num] (int a) { return num == a; });
            if (itr != l.end()) {
                l.erase(itr);
            }
        } else if (command == "deleteFirst") {
            l.pop_front();
        } else if (command == "deleteLast") {
            l.pop_back();
        }
    }

    for (auto itr = l.begin(); itr != l.end(); ++itr) {
        std::cout << *itr;
        if (itr != std::prev(l.end())) {
            std::cout << " ";
        }
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 34296
module Main where
 
import Control.Applicative
import Numeric
import Data.Char
import Data.List
import Data.Ord
import Control.Monad
 
solve :: [String] -> String
solve [s,p] =
    if (isInfixOf p $ s ++ s) then
        "Yes"
    else
        "No"
         
main = putStrLn =<< solve . lines <$> getContents
     
--
getIntegers :: IO [Integer]
getIntegers = map read . words <$> getLine
 
getInts :: IO[Int]
getInts = map read . words <$> getLine
 
putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show
 
getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine
 
putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble
 
showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""


Measured memory_bytes: 3780
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    if(a.size() == b.size()){
        if(a > b)
            cout << "GREATER" << endl;
        else if(a < b)
            cout << "LESS" << endl;
        else
            cout << "EQUAL" << endl;
    }
    else{
        if(a.size() > b.size())
            cout << "GREATER" << endl;
        else
            cout << "LESS" << endl;
    }

    return 0;
}


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

int main()
{

    string s;
    cin >> s;

    int count = 0;

    if (s[0] == '1')
        count++;
    if (s[1] == '1')
        count++;
    if (s[2] == '1')
        count++;

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};


int main() {
	while (true) {
		int N, M;
		cin >> N >> M;
		if (N == 0)break;
		vs pat(N);
		string text = "";
		rep(i, N) {
			cin >> pat[i];
		}
		rep(i, M) {
			string str;
			cin >> str;
			text += str;
		}
		int L = text.size();
		vvb dp(1 << N, vb(L, false));

		rep(j, N) {
			rep(k, L - pat[j].size() + 1) {
				bool flag = true;
				rep(l, pat[j].size()) {
					if (text[k + l] != pat[j][l]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					dp[1 << j][k + pat[j].size() - 1] = true;
				}
			}
		}

		repl(i, 1, 1 << N) {
			rep(j, N) {
				if ((i&(1 << j)) != 0) {
					if ((i ^ (1 << j)) == 0)continue;

					repl(k, 1, L - pat[j].size() + 1) {
						if (dp[(i ^ (1 << j))][k - 1]) {
							if (dp[1 << j][k + pat[j].size() - 1]) {
								dp[i][k + pat[j].size() - 1] = true;
							}
						}
					}

				}
			}
		}
		int ans = 0;
		rep(i, L) {
			if (dp[(1 << N) - 1][i])ans++;
		}
		/*
		rep(i, 1 << N) {
			rep(j, L) {
				cout << "xo"[dp[i][j]];
			}
			cout << static_cast<std::bitset<3>>(i) << endl;
		}
		*/
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
#define umap unordered_map
#define all(x) x.begin(), x.end()
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M ;
    }
    return res%M;
}
const lli N = 1e5 + 2;
lli dp[102][N];
lli calc(vll& w, vll& v, lli index, lli cap){
    lli n = v.size();
    if(cap < 0)
        return -1e16;
    else if(index >= n)
        return 0;
    else if(cap == 0)
        return 0;
    else if(dp[index][cap] != -1)
        return dp[index][cap];
    lli ans = 0;
    ans = max(calc(w, v, index+1, cap-w[index]) + v[index], calc(w, v, index+1, cap));
    ans = max(ans, 0ll);
    dp[index][cap] = ans;
    return ans;
}
lli solve(){
    memset(dp, -1, sizeof(dp));
    lli n, cap;
    cin>>n>>cap;
    vll w(n), v(n);
    loop(i, 0, n)
        cin>>w[i]>>v[i];
    cout<<calc(w, v, 0, cap)<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
	// cin>>t;
    t = 1;
    while(t>0){ 
        t--;
        solve();
    }
}

Measured memory_bytes: 83336
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll dp[5001][5001];

ll modpow(ll a, ll t) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD;
        }
        a *= a;
        a %= MOD;
        t >>= 1;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int m = s.length();

    dp[0][0] = 1;
    for(int i=0;i<n;++i) {
        for(int j=0;j<=i;++j) {
            dp[i+1][j+1] += (dp[i][j] * 2) % MOD;
            dp[i+1][j+1] %= MOD;
            dp[i+1][j?(j-1):0] += dp[i][j];
            dp[i+1][j?(j-1):0] %= MOD;
        }
    }

    ll patterns = modpow(2LL, m);
    ll ans = (dp[n][m] * modpow(patterns, MOD-2)) % MOD;

    cout << ans << endl;
}

Measured memory_bytes: 193792
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new TEST().doIt();
    }
    class TEST{
        void doIt(){
        	int n = sc.nextInt();
        	int m = sc.nextInt();
        	int a[][] = new int [n][m];
        	int b[] = new int [m];
        	for(int i = 0;i < n;i++){
        		for(int j = 0;j < m;j++){
        			a[i][j] = sc.nextInt();
        		}
        	}
        	for(int i = 0;i < m;i++){
        		b[i] = sc.nextInt();
        	}
        	for(int i = 0;i < n;i++){
        		int sum = 0;
        		for(int j = 0;j < m;j++){
        			sum = sum + a[i][j] * b[j];
        		}
        		System.out.println(sum);
        	}
        }
    }
}

Measured memory_bytes: 40180
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
const int MAXN = 2e5 + 10;
LL nums[MAXN], dp[2][MAXN];

void solve(int n) {
    LL sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += nums[i];
        dp[0][i] = sum;
        if (nums[i] == 0) {
            dp[0][i] = min(dp[0][i], dp[0][i-1] + 2);
        } else if (nums[i] % 2 == 0) {
            dp[0][i] = min(dp[0][i], dp[0][i-1]);
        } else {
            dp[0][i] = min(dp[0][i], dp[0][i-1] + 1);
        }
    }
    sum = 0;
    for (int i = n; i > 0; i--) {
        sum += nums[i];
        dp[1][i] = sum;
        if (nums[i] == 0) {
            dp[1][i] = min(dp[1][i], dp[1][i+1] + 2);
        } else if (nums[i] % 2 == 0) {
            dp[1][i] = min(dp[1][i], dp[1][i+1]);
        } else {
            dp[1][i] = min(dp[1][i], dp[1][i+1] + 1);
        }
    }
}



int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL
    freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
    }
    solve(n);
    for (int i = 1; i <= n; i++) {
        if (nums[i] % 2 == 1) dp[0][i] = min(dp[0][i], dp[0][i-1]);
        else dp[0][i] = min(dp[0][i], dp[0][i-1]+1);
    }
    LL ret = LLONG_MAX;
    for (int i = 0; i <= n; i++) {
        ret = min(ret, dp[0][i] + dp[1][i+1]);
    }
    cout << ret << endl;







/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int n;
vi adj[100050];
int p[100050];
int s[100050];
bool vis[100050];

int dfs(int here) {
	vis[here] = true;
	s[here] = 1;
	for(auto there : adj[here]) {
		if(!vis[there]) {
			p[there] = here;
			s[here] += dfs(there);
		}
	}
	return s[here];
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	rep(i,0,n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	memset(vis, false, sizeof(vis));
	p[0] = 0;
	dfs(0);
	vi ret;
	int here = n-1;
	while(here != 0) {
		if(here != n-1){
			ret.pb(here);
		}
		here = p[here];
	}
	here = (sz(ret) > 0 ? ret.back() : n-1);
	int a = n - s[here] - 1;
	int b = s[n-1] - 1;
	int m = sz(ret);
	per(i,0,m) {
		int j = (i == 0 ? n-1 : ret[i-1]);
		s[ret[i]] -= s[j];
	}
	rep(i,0,m/2) {
		b += s[ret[i]];
	}
	rep(i,m/2,m) {
		a += s[ret[i]];
	}
	if(a>b) {
		cout << "Fennec" << '\n';
	} else {
		cout << "Snuke" << '\n';
	}
	return 0;
}


Measured memory_bytes: 11900
// abc109_a
// #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void) {
	int A, B;
	cin >> A >> B;
	for (int i = 1; i <= 3; i++) {
		int num = A * B * i;
		if (num % 2 == 1) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[111];

void MAIN() {
    scanf("%s", S);
    S[3] = 0;
    puts(S);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 3684
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    int ret = 0;
    std::set<int> a, b, c;
    for (int i = 0; i < n; i++) {
        std::string in;
        std::cin >> in;
        for (int j = 1; j < in.size(); j++) {
            if (in[j - 1] == 'A' && in[j] == 'B') ret++;
        }
        if (in.back() == 'A' && in.front() == 'B') c.insert(i);
        else if (in.back() == 'A') a.insert(i);
        else if (in.front() == 'B') b.insert(i);
    }
    int aa = a.size(), bb = b.size(), cc = c.size();
    ret += std::max(cc - 1, 0);
    if (cc > 0 && aa > 0) { ret++; aa--; }
    if (cc > 0 && bb > 0) { ret++; bb--; }
    ret += std::min(aa, bb);
    std::cout << ret << std::endl;

    return 0;
}


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

int main() {
    string n;
    cin >> n;
    long long int sum = 0;
    for (int i = 0; i < n.size(); i++) {
        sum += n[i] - '0';
    }

    if (sum % 9 == 0) cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3716
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong)
    val bList = readLine()!!.split(' ').map(String::toLong)
    val abList = (0 until n).map { Pair(aList[it], bList[it]) }.sortedBy { it.second }

    val aSorted = aList.sorted()
    val bSorted = bList.sorted()

    if ((0 until n).any { aSorted[it] > bSorted[it] }) {
        println("No")
        return
    }

    val aStart =  (0 until n).map {abList[it].first }
    val aStartWithIndex =  (0 until n).map {Pair(aStart[it],it) }.sortedBy { it.first }
    val visited = Array(n){false}
    var visitedCount = 1
    var cur = 0
    while(!visited[cur]){
        visited[cur] = true
        visitedCount++
        cur = aStartWithIndex[cur].second
    }

    if(visitedCount<n){
        println("Yes")
        return
    }

    if ((0 until n-1).any { bSorted[it] > aSorted[it+1] }) {
        println("Yes")
    }else{
        println("No")
    }
}


Measured memory_bytes: 126156
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int next_int(){
    int i;
    cin >> i;
    return i;
}

long next_long(){
    long l;
    cin >> l;
    return l;
}

string next_line(){
    string s;
    cin >> s;
    return s;
}

int main(){
    const int n=next_int();
    vector<int> p(n);
    for(int i=0;i<n;i++){
        p[i]=next_int()-1;
    }

    vector<int> a(n);
    for(int i=0;i<n;i++){
        a[p[i]]=i;
    }

    int max=0;
    int i=0;
    while(i<n){
        int c=1;
        while(i<n-1 && a[i]<a[i+1]){
            c++;
            i++;
        }
        i++;
        max=std::max(max,c);
    }

    cout << n-max << endl;

    return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long k = sc.nextLong();
			
			long point = 0;
			
			if ( k <= a ) {
				point = k;
			}
			else if ( k <= a + b ) {
				point = a;
			}
			else if ( k <= a + b + c) {
				point = a - (k - a - b);
			}
			
			System.out.println(point);
		}
	}

}

Measured memory_bytes: 35516
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}


ll check(ll x, ll y, ll d) {
    return (d*d >= x*x + y*y) ;
}

int main() {
  ll n,d;
  cin >> n >> d;
  ll ans = 0;
  for(int i = 1; i <= n; i++) {
     ll x,y;
     cin >> x >> y;
     ans = ans + check(x,y,d);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

//問題文より、入力されるデータの最大個数
#define MAXCOUNT 100

//ソートの結果と交換回数を出力する関数
void print(int array[], int size, int count);

int main(void)
{
	//i、jは繰り返し変数、countはループの回数を、tempは交換するデータを格納、min_indexは交換するデータの添字
	int i, j, count, temp, min_index;
	//sizeは配列の要素数を、arrayは入力される数値を格納
	int size;
	int array[MAXCOUNT];

	//データの個数を入力
	scanf("%d", &size);

	//データを入力
	for(i = 0; i < size; i++){
		scanf("%d", &array[i]);
	}

	count = 0;
	//配列の終端の一つ前まで走査
	for(i = 0; i < (size - 1); i++){
		min_index = i;
		//比較元の一つ後ろから比較開始
		for(j = (i + 1); j < size; j++){
			//小さい値から確定する
			if(array[j] < array[min_index]){
				min_index = j;
			}
		}
		//昇順に並び替える
		if(min_index != i){
			temp = array[min_index];
			array[min_index] = array[i];
			array[i] = temp;

			//交換回数を加算
			count++;
		}
	}

	//結果を出力
	print(array, size, count);

	return 0;
}

void print(int array[], int size, int count)
{
	int i;

	//配列の中身を1行で表示し、最後に改行する
	for(i = 0; i < (size - 1); i++){
		printf("%d ", array[i]);
	}

	printf("%d\n", array[i]);
	//交換回数を表示
	printf("%d\n", count);
}


Measured memory_bytes: 2108
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型
        int[] w = new int[n+1];

        w[0] = 0;
        for (int i = 0; i < n; i++) {
            w[i+1] = w[i]+Integer.parseInt(sc.next());
        }
        sc.close();

        int ans = 10000000;
        int r;
        int l;
        for (int i = 1; i < n; i++) {
            r = w[i];
            l = w[n] - w[i];
            ans = Math.min(Math.abs(l-r),ans);
        }

        System.out.println(ans);
    }
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int N, x;
	cin >> N >> x;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (x >= a[i]) {
			if (i == N - 1 && x != a[i]) {
				break;
			}
			x -= a[i];
			++cnt;
		} else {
			break;
		}
	}
	cout << cnt << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    ll range, array_size, diff;
    cin >> range >> array_size >> diff;

    
    double ans = 0;
    if (diff == 0)
        ans = (double) 1/ range * (array_size - 1);
    else
        ans = (double) 2 * (range - diff) / (range * range) * (array_size - 1);

    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 256
/**
 *   author: Shubham Srivastava
 *   created: 07 September 2019  18:27:48
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;cin>>n;
    vector <int> arr(n);
    for(int i=0;i<n-1;i++)
        cin>>arr[i];
    vector <int> arr1(n);
    arr1[0] = arr[0];
    arr1[1] = arr[0];
    for(int i=1;i<n-1;i++){
        if(arr1[i] > arr[i])
            arr1[i] = arr[i];
        arr1[i+1] = arr[i]; 
    }
    int sum=0;
    for(int i=0;i<n;i++){
        sum += arr1[i];
    }
    cout<<sum;
return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;


int main(){
  int N,M; cin >> N >> M;
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> B(M);
  vector<int> R(N);
  rep(i,N) {
    rep(j,M) {
      cin >> A[i][j];
    }
  }
  rep(i,M) {
    cin >> B[i];
  }
  
  rep(i,N) {
    rep(j,M) {
      R[i] += A[i][j]*B[j];
    }
    cout << R[i] << endl;
  }
}



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

int main(){
    int n;
    int tanka[]={5,7,5,7,7};
    while(cin>>n,n){
        vector<string> w(n);
        for(int i=0;i<n;i++)cin>>w[i];

        for(int i=0;i<n;i++){
            int inde=0;
            int cnt=0;
            for(int j=i;j<n;j++){
                cnt+=w[j].size();
                if(cnt==tanka[inde]){
                    inde++;
                    cnt=0;
                }
                if(inde==5) break;
            }
            if(inde==5){
                cout<<i+1<<endl;
                break;
            }

        }

    }

    return 0;
}

Measured memory_bytes: 3120
#include<stdio.h>
    #include<stdlib.h>
      int compare(const void *a, const void *b){
        return *(int*)a - *(int*)b;
          }
      int main(){
        int N,median,i;
        int A[200000];
        long long int mixsum = 0;
        scanf("%d",&N);
        for(i = 0; i < N;i++){
          scanf("%d",&A[i]);
          A[i] += -i;
        }
        qsort(A,N,sizeof(int),compare);
     
        median = A[N/2];
        for(i = 0;i < N;i++)mixsum += abs(A[i] - median);
        printf("%lld\n",mixsum);
        return 0;
      }

Measured memory_bytes: 1788
local n,x=io.read("n","n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end

local counter=0
for i=1,n-1 do
    local sum=a[i]+a[i+1]
    if sum>x then
        local diff=sum-x
        counter=counter+diff
        if diff<a[i+1] then
            a[i+1]=a[i+1]-diff
        else
            diff=diff-a[i+1]
            a[i+1]=0
            a[i]=a[i]-diff
        end
    end
end
print(string.format("%d",counter))

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin>>n>>k;
  vector<char> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  int g=0;
  if(s[0]=='L') g+=1;
  if(s[n-1]=='R') g+=1;
  int h=0;
  for(int i=0;i<n-1;i++){
    if(s[i]=='R' && s[i+1]=='L'){
      h+=2;
    }
    
  }

  if(h/2>=k){
    h-=2*k;
  }
  else{
    h=0;
    g=1;
  }
  cout<<n-h-g<<endl;
}
    


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main implements Runnable {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;


	static int[][][] directedGraph(int n, int[] from, int[] to, int[] cost) {
		int[] cnt = new int[n];
		for (int i : from) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<from.length; i++) {
			int s = from[i];
			int t = to[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];
		}

		return g;
	}

	static int[][][] g;
	static boolean[] f;

	static void rec(int cur, int time) {
		f[cur] = true;
		for (int[] to : g[cur]) {
			if (to[1] <= time) continue;
			rec(to[0], to[1]);
		}
	}

	static boolean solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		if (n + m == 0) return false;

		int[] s = new int[m];
		int[] t = new int[m];
		int[] c = new int[m];
		for (int i=0; i<m; i++) {
			c[i] = in.nextInt();
			s[i] = in.nextInt() - 1;
			t[i] = in.nextInt() - 1;
		}

		g = directedGraph(n, s, t, c);
		f = new boolean[n];
		rec(0, -1);
		int ans = 0;
		for (int i=0; i<n; i++) {
			if (f[i]) ans++;
		}
		out.println(ans);

		return true;
	}


	public void run() {
		while(solve());

		out.flush();
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 165352
nums = [int(e) for e in input().split()]

if nums[0]>100 or nums[1]>100:
  print('入力値が違います')
elif nums[0]<1 or nums[1]<1:
  print('入力値が違います')
elif nums[0]>2*nums[1]:
  print(nums[0]-2*nums[1])
else:
  print(0)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e9+7;

int main(){
	int n=0;
	cin >> n;
	map<int,int> a;
	for(int i=0;i<n;i++){
		int t;
		cin >> t;
		a[t]++;
	}

	ll ans = 1;
	if(n%2==1){
		int pre = 0;
		for(auto i:a){
			if(i.first == 0 && i.second!=1) {
				cout << 0;
				return 0;
			}
			if(i.first!=0&&(i.first %2==1||i.second!=2)){
				cout << 0;
				return 0;
			}
			if(pre != i.first){
				cout << 0;
				return 0;
			}
			if(i.first == 0){
				ans *=1;	
			}else{
				ans =ans*2%INF;
			}
			pre +=2;
		}
	}else{
		int pre = 1;
		for(auto i:a){
			if(i.first%2 == 0 || i.second!=2) {
				cout << 0;
				return 0;
			}

			ans =ans*2%INF;
			pre +=2;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3200
A,B,C = [int(x) for x in input().split()]
if(A==B==C and A%2==0):
    print(-1)
else:
    cnt=0
    a,b,c=A,B,C
    while(a%2==b%2==c%2==0):
        cnt+=1
        a_=(b+c)//2
        b_=(a+c)//2
        c_=(a+b)//2
        a,b,c=a_,b_,c_
    print(cnt)    
    

Measured memory_bytes: 3060
#include<stdio.h>
struct Card{
	char s, v;
};
void bubbleSort(struct Card A[], int N) {
        int i,j;
        struct Card t;
	for (i = 0; i < N; i++) {
		for ( j = N - 1; j > i; j--) {
			if (A[j-1].v > A[j].v) {
				t=A[j-1];
				A[j-1]=A[j];
				A[j]=t;
			}
		}
	}
}
void selectSort(struct Card A[], int N) {
	int minj,i,j;
	struct Card t;
	for (i = 0; i < N; i++) {
		minj = i;
		for (j = i; j < N; j++) {
			if (A[j].v < A[minj].v) {
				minj = j;
			}
		}
		t=A[minj];
                A[minj]=A[i];
                A[i]=t;
	}
}

void print(struct Card A[], int N) {
        int i;
	for (i = 0; i < N; i++) {
		if (i != 0) printf(" ");
		printf("%c%c",A[i].s,A[i].v);
	}
}
int isstable(struct Card C1[], struct Card C2[], int N) {
	int tag = 1,i;
	for (i = 0; i < N; i++) {
		if (C1[i].s != C2[i].s||C1[i].v!=C2[i].v) {
			tag = 0;
		}
	}
	return tag;
}
int main() {
	struct Card C1[100],C2[100];
	int N,i;
	char ch;

	scanf("%d",&N);
	for (i = 0; i < N; i++) {
		scanf(" %c%c",&C1[i].s,&C1[i].v);
	}
	for (i = 0; i < N; i++) {
		C2[i] = C1[i];
	}
	bubbleSort(C1, N);
	selectSort(C2, N);
	print(C1, N);
	printf("\n");
	printf("Stable\n");
	print(C2, N);
	if (isstable(C1,C2,N)){
                        printf("\n");
		printf("Stable\n");
	}
	else {
	         printf("\n");
		printf("Not stable\n");
	}
	return 0;
}



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

ll GCD(ll x,ll y) {return y ? GCD(y, x%y) : x;}
ll num(ll n, ll c, ll d){
  ll g = GCD(c, d);
  ll l = c/g*d;
  return n-(n/c)-(n/d)+n/l;  
}

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout << num(b,c,d) - num(a-1,c,d)<< endl; 
}

Measured memory_bytes: 256
def main():
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))
    ans = 0
    for n in range(N):
        A = list(map(int, input().split()))
        if sum([A[m] * B[m] for m in range(M)]) + C > 0:
            ans += 1
    print(ans)


main()            


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

using namespace std;
using ll = long long;
const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        int d;
        cin >> d;
        if(i==0&&d!=0){
            cout << 0 << endl;
            return 0;
        }
        A[d]++;
    }
    if(A[0]!=1){
        cout << 0 << endl;
        return 0;
    }
    mint cnt = 0, prev = 1;
    mint ans = 1;
    for (int i = 0; i < n; ++i) {
        if (cnt.x < n && A[i] == 0) {
            cout << 0 << endl;
            return 0;
        } else if (cnt.x == n) {
            break;
        }
        cnt += A[i];
        mint x = 1;
        for (int j = 0; j < A[i]; ++j) {
            x *= prev;
        }
        ans *= x;
        prev = A[i];
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int m, n;
 
  cin >> m >> n;
  int t[m][n];
 
  for(int i = 0; i < m; i++) {
    for(int j = 0; j < n; j++) {
      cin >>t[i][j];
    }
  }
 
  int ans = 0;
  for(int i = 0; i < m; i++) {
    int cnt = 0;
    for(int j = 0; j < n; j++) {
      if(t[i][j] == 1) cnt++;
    }
    if(ans < cnt) ans = cnt;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

set<ll> st;

int main(void){
	ll n,k,m;
	cin >> n;
	st.insert(n);
	for(k=2ll; k*k<=n; ++k){
		m = n;
		while(!(m%k)){
			m /= k;
		}
		m %= k;
		if(m==1){
			st.insert(k);
		}
	}
	--n;
	for(k=1ll; k*k<=n; ++k){
		if(!(n%k)){
			st.insert(k);
			st.insert(n/k);
		}
	}
	cout << (st.l_ength()-1) << endl;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC137
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int K = int.Parse(input[0]);
            int X = int.Parse(input[1]);

            for (int i = (K - 1) * (-1); i < K; i++)
            {
                Console.Write(X + i);
                if (i < K - 1) Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define numOfOnes(n) __builtin_popcount(n)
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y
//</DEFINE>
int h, w;
vector<vector<char>>v;
//<FUNCTIONS>
bool valid(int i, int j) {
	return i >= 0 && i < h && j >= 0 && j < w;
}
int res[1000][1000];
ll solve(int i=0,int j=0) {
	if (!valid(i, j) || v[i][j]=='#')return 0;
	if (i == h - 1 && j == w - 1)return 1;
	if (~res[i][j])return res[i][j];
	return res[i][j] = ((solve(i + 1, j) % mod) + (solve(i, j + 1) % mod)) % mod;
}
//</FUNCTIONS>		
int main() {
	Fast();
	cin >> h >> w;
	v = vector<vector<char>>(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)cin >> v[i][j];
	}
	memset(res, -1, sizeof(res));
	cout << solve() << endl;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
//#include "util.h"

#define ll long long
using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  constexpr char nl = '\n';
  const int mod = 1e9 + 7;

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

  vector<vector<ll>> dp(N, vector<ll>(N, 0));
  for (int i = 1; i <= N; ++i) {
    for (int l = 0; l <= N - i; ++l) {
      int r = l + i - 1;
      ll choose_left = (l < N - 1 ? arr[l] - dp[l + 1][r] : arr[l]);
      ll choose_right = (r > 0 ? arr[r] - dp[l][r - 1] : arr[r]);
      dp[l][r] = max(choose_left, choose_right);
    }
  }

  cout << dp[0][N - 1] << nl;

  return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define ll long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define endl '\n'
ll dist(ll x1,ll x2,ll y1,ll y2){
    return abs(x2-x1)+abs(y2-y1);
}
int main(){
    int N;cin>>N;
    vector<ll> X(N),Y(N),P(N),Q(N);
    rep(i,0,N)cin>>X[i]>>Y[i];
    rep(i,0,N){
        P[i]=X[i]-Y[i];
        Q[i]=X[i]+Y[i];
    }
    sort(P.begin(),P.end());
    sort(Q.begin(),Q.end());
    ll ans=max(abs(P.back()-P.front()),abs(Q.back()-Q.front()));
    cout<<ans<<endl;
}

Measured memory_bytes: 9524
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    vl a(n);
    multiset<ll> se;
    rep(i,n){
        cin >> a[i]; 
        a[i] = -a[i];
        if(se.upper_bound(a[i]) == se.end()){
            se.insert(a[i]);
            //cout << "#" << endl;
        }else{
            auto it = se.upper_bound(a[i]);
            se.erase(it);
            //cout << ((*it));
            se.insert(a[i]);
            /*for(auto it = se.begin(); it != se.end(); it++){
                cout << (*it) << " ";
            }
            cout << endl;*/
        }
    } 
    cout << se.size() << endl;
}

Measured memory_bytes: 5760
from collections import Counter
s = list(input())
n = len(s)
count = Counter(s[2:-1])
lower = [i for i in s if ord('a')<=ord(i)<=ord('z')]

if count.get('C'):
    if count['C']==1 and s[0]=='A' and len(lower)==n-2:
        print('AC')
        exit()
print('WA')

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

int main()
{
    int n;
    set<string>s;
    string t;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>t;
        s.insert(t);
    }
    printf("%d\n",s.size());
}


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

//*
//プラキュー（二分ヒープ）（最低限バージョン）
//int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
int PQhikaku(ll*heap,int i,int j){return heap[i]<heap[j];}
void heap_utod(ll*heap,int n){
	if(2*n>heap[0])return;
	int rflag=(2*n+1<=heap[0])&&(PQhikaku(heap,2*n,2*n+1));
	if(PQhikaku(heap,n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heap_utod(heap,2*n+rflag);
	}
}
void heap_dtou(ll*heap,int n){
	if(n==1||PQhikaku(heap,n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heap_dtou(heap,n/2);
}
ll PQpop(ll*heap){
	ll rr=heap[1];
	heap[1]=heap[heap[0]--];
	heap_utod(heap,1);
	return rr;
}
void PQpush(ll*heap,ll n){
	heap[++heap[0]]=n;
	heap_dtou(heap,heap[0]);
}
//*/

ll h[100010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,0,n){
		int t;
		scanf("%d",&t);
		PQpush(h,t);
	}
	rep(i,0,m){
		ll t=PQpop(h);
		PQpush(h,t/2);
	}
	ll ans=0;
	rep(i,0,n)ans+=PQpop(h);
	printf("%lld",ans);
}

Measured memory_bytes: 896
#N = gets.to_i               # 単一整数
#a = gets.split.map(&:to_i)  # スペースで区切られた複数の整数
#a = N.times.map{gets.to_i}  # 縦に並んだ複数の整数。たまにある
#S = gets.chomp              # 文字列。chompを付けないと改行文字がついてくる

=begin
def solveABC177A
  D,T,S = gets.split.map(&:to_f)
  if D/S <= T 
    puts "Yes"
  else
    puts "No"
  end
end

def solveABC177B
  S = gets.chomp
  T = gets.chomp
  s_len = S.length
  t_len = T.length
  max_count = 0
  for i in 0..(s_len - t_len)
    match_count = 0
    extracted_str = S[i,t_len]
    for i2 in 0..(t_len-1)
      if extracted_str[i2] == T[i2]
        match_count += 1
      end
    end
    max_count = [match_count,max_count].max
  end
  puts t_len - max_count
end
=end


N = gets.to_i
An = gets.split.map(&:to_i)
Sn = [An[0]]
ans = 0
for i in 1..(An.length-1)
  Sn.push Sn[i-1] + An[i]
end

for i in 0..(An.length-1-1)
  ans += (An[i] * (Sn[N-1] - Sn[i])) % (10**9 + 7)
  ans %= (10**9 + 7)
end

puts ans

Measured memory_bytes: 35256
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
*/
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt(), q = sc.nextInt();
        UF.Init(n);
        for (int i = 0; i < q; i++) {
            int com=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt();
            if(com==0)UF.unite(x,y);
            else out.println(UF.same(x,y)?1:0);
        }
    }

    static class UF {//0-indexed
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

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

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    }
}


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

	cin >> n >>k;

	int ans=0;
	while(n){
		n=n/k;
		ans++;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256