akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c,d,e;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>str;
	if(str<="2019/04/30"){cout<<"Heisei";}
	else{cout<<"TBD";}



	cout<<endl;
} 


Measured memory_bytes: 256
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

B = [-1]*(H*W)
bi = 0
for i in range(N):
    for _ in range(A[i]):
        B[bi] = i+1
        bi += 1

Ans = []
for h in range(H):
    Ans.append(B[h*W:(h+1)*W])

for h in range(H):
    if h%2==0:
        print(" ".join(map(str,Ans[h])))
    else:
        Ans[h].reverse()
        print(" ".join(map(str,Ans[h])))

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        // var num = Input.num;
        //var ws = Input.ar;
        var pqr = Input.ar;
        WriteLine(Min(pqr[0] + pqr[1], Min(pqr[1] + pqr[2], pqr[2] + pqr[0])));
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public static long numL => ToInt64(read);
    public static char[][] gred(int h)
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public static string[] Make<T1, T2>(out T1 v1, out T2 v2)
    {
        var r = read.Split(' ');
        v1 = getValue<T1>(r[0]);
        v2 = getValue<T2>(r[1]);
        return r;
    }
    public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3)
    {
        var r = Make(out v1, out v2);
        v3 = getValue<T3>(r[2]);
        return r;
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public const int MOD = 1000000007;
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
     
    using namespace std;
    long long int ara[100009];
    int main()
    {
        long long int n, k, now, tmp, rng, sum=0, i;
        cin >> n >> k;
        while(n--)
        {
            cin >> tmp >> rng;
            ara[tmp] += rng;
        }
        for(i=1;;i++)
        {
            sum += ara[i];
            if(sum>=k) cout<<i<<endl, exit(0);
        }
        return 0;
    }


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    string inS;
    cin >> inS;

    vector <int> result(inS.size());
    for(int i=0; i<inS.size(); i++)
    {
        result[i] = 0;
    }

    int leftTurnRight = 0;
    int rightTurnLeft = 0;
    for(int i=1; i<inS.size(); i++)
    {
        if((inS[i-1] == 'R') &&
           (inS[i]   == 'L'))
        {
            result[i]   += (i - leftTurnRight)/2 + 1;
            result[i-1] += (i - leftTurnRight + 1)/2;
            rightTurnLeft = i;
        }
        else if((inS[i-1] == 'L') &&
                (inS[i]   == 'R'))
        {
            result[rightTurnLeft]   += (i - rightTurnLeft - 1)/2;
            result[rightTurnLeft-1] += (i - rightTurnLeft)/2;
            leftTurnRight = i;
        }
        else if(i == inS.size() - 1)
        {
            result[rightTurnLeft]   += (i - rightTurnLeft)/2;
            result[rightTurnLeft-1] += (i - rightTurnLeft + 1)/2;
            leftTurnRight = i;
        }
    }

    for(int i=0; i<inS.size(); i++)
    {
        cout << result[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s,t;
    ll cnt=INF;
    cin>>s>>t;
    rep(i,s.size()){
        ll tmp=0;
        string x=s.substr(i,t.size());
        if(x.size()==t.size()){
            rep(j,t.size()){
                if(x[j]!=t[j]) tmp++;
            }
            cnt = min(cnt,tmp);
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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


int main() {
   
    int N; cin>>N;
    double sum=0;
    vector<pair<int,int>>data(N);
    rep(i,N)cin>>data[i].first>>data[i].second;

    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int a =data[i].first-data[j].first;
            int b =data[i].second-data[j].second;
            int c=pow(a,2)+pow(b,2);
            sum +=sqrt(c);
        }
    }
     cout << fixed << setprecision(10);
    double ans =2*sum/N;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>


using namespace std;
typedef long long ll;

int N = 0;

int main(){

    cin >> N;

    int loop = N;
    for(;;){
        if(loop % 2 == 0 && loop % N == 0){
            cout << loop << endl;
            return 0;
        }
        loop++;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,a[205],x;

ll mod=1e9+7,dp[205][100005],f[205],inv[205],ans;

ll pwr(ll a, ll p){
    if(!p) return 1;
    ll t=pwr(a,p/2);
    t*=t; t%=mod;
    if(p%2) t*=a,t%=mod;
    return t;
}

int32_t main(){
    /*seed_seq seq{
        (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
        (uint64_t) __builtin_ia32_rdtsc(),
        (uint64_t) (uintptr_t) make_unique<char>().get()
    };
    mt19937 rng(seq);*/
#ifdef LOCAL_DEFINE
    ifstream cin("input.in");
#endif
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    cin >> n >> x;
    for(int i=1;i<=n;i++) cin >> a[i];
    f[0]=inv[0]=1;
    for(int i=1;i<=n;i++) f[i]=f[i-1]*i%mod,inv[i]=pwr(i,mod-2);
    sort(a+1,a+n+1);
    dp[n+1][x]=1;
    for(int i=n;i>=1;i--){
        for(int j=0;j<=x;j++){
            dp[i][j%a[i]]+=inv[i]%mod*dp[i+1][j]%mod;
            dp[i][j%a[i]]%=mod;
            dp[i][j]+=inv[i]%mod*(i-1)%mod*dp[i+1][j]%mod;
            dp[i][j]%=mod;
        }
    }
    for(int j=0;j<=x;j++) ans+=dp[1][j]*j,ans%=mod;
    cout << ans*f[n]%mod;
}


Measured memory_bytes: 159232
#include <bits/stdc++.h>
 
using namespace std;
 
#define M 			50005
#define Fi			first
#define stop 		return
#define Se 			second
#define S(n) 		cin >> n
#define P(n) 	 	cout << n
#define mp 			make_pair
#define pb 			push_back
#define pp 			pop_back
#define pf 			pop_front
#define start 		int main()
#define sp   		cout << " "
#define nl      	cout << "\n"
#define	mem(n, a)	memset((n), (a), sizeof(n))
#define prec(n)		cout << fixed << setprecision(n)
#define F(i, n, r)  for(int i = (n); i < (r); i ++)
#define PI			3.14159265358979323846264338327951
#define fast 		ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
using ll = long long;
using ss = stringstream;
using ul = unsigned long long;
 
typedef set < int > 		st;
typedef vector < ll > 		vl;
typedef vector < int > 		vi;
typedef map < ll, ll > 		ml;
typedef pair <int, int> 	pr;
typedef vector < string > 	vs;
typedef map < string, ll > 	ms;
typedef map < string, int > mi;
typedef vector < pr > 		vp;
 
template < typename T > inline T LCM(T a, T b) 		 { return (a * b) / GCD(a, b); }
template < typename T > inline T GCD(T a, T b) 		 { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > inline T _max(T a, T b, T c) { return max( max( a, b ), c ); }
template < typename T > inline T _min(T a, T b, T c) { return min( min( a, b ), c ); }
 
const int inf 	  =  99999999;
const int neg_inf = -99999999;

start
{
    fast;
    map < char, int > m;
    int o = 0;
    for(char i = 'A'; i <= 'F'; i ++) {
        m[i] = o ++;
    } 
    char a, b;
    S(a),S(b);
    if(m[a] > m[b]) {
        P(">");
    }
    else if(m[a] < m[b]) {
        P("<");
    }
    else {
        P("=");
    }
    nl;
    stop 0;
}

Measured memory_bytes: 256
//

//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    bool state[3] = {};
    bool valid = false;
    rep(i, N)
    {
        //
        state[0] = state[1];
        state[1] = state[2];
        //
        ll D1, D2;
        cin >> D1 >> D2;
        state[2] = (D1 == D2);
        //
        if (state[0] && state[1] && state[2])
        {
            valid = true;
        }
    }
    yes(valid);
    return 0;
}

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

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

    int size(int x){
        return sz[find(x)];
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    UnionFind uf(N);
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
    }
    if(M == N-1){
        cout << 0 << endl;
        return 0;
    }

    map<int, vector<int64_t>> mp;
    for(int i=0; i<N; i++) mp[uf.find(i)].push_back(A[i]);
    vector<pair<int64_t, int>> vs;
    int64_t ans = 0;

    for(auto& p : mp){
        auto& v = p.second;
        sort(v.rbegin(), v.rend());
        ans += v.back();
        v.pop_back();
        for(int64_t a : v) vs.emplace_back(a, p.first);
    }
    sort(vs.begin(), vs.end());

    int need = 2*(N-1-M) - (N-M), lim = N-M-2;
    vector<int> cnt(N);
    for(auto& p : vs){
        if(need == 0) break;
        int64_t c = p.first, i = p.second;
        if(cnt[i] < lim){
            cnt[i]++;
            ans += c;
            need--;
        }
    }
    if(need > 0){
        cout << "Impossible" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 13184
N, K = map(int, input().split())
if K % 2 == 1:
    print(sum(1 for n in range(1, N + 1) if n % K == 0) ** 3)
else:
    print(sum(1 for n in range(1, N + 1) if n % K == 0) ** 3 + sum(1 for n in range(1, N + 1) if n % K == K // 2) ** 3)


Measured memory_bytes: 3316
#include<iostream>
using namespace std;
char a[101];
int main()
{
    int n,max=0,s=0;
    cin>>n;
    for(int i=1;i<=n;++i)
    cin>>a[i];
    for(int i=1;i<=n;++i)
    {
    	if(a[i]=='I')
    	s++;
    	else
    	s--;
    	if(s>max)
    	max=s;
	}
	cout<<max;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        // Arrayの中で指定された要素「以上」の値が現れる最初のインデックスを返す
        public static int LowerBound<T>(T[] a, T v) where T : IComparable<T>
        {
            int l = 0;
            int r = a.Length - 1;

            while (l <= r)
            {
                int mid = l + (r - l) / 2;
                if (a[mid].CompareTo(v) < 0)
                {
                    l = mid + 1;
                }
                else
                {
                    r = mid - 1;
                }
            }

            return l;
        }

        // Arrayの中で指定された要素「より大きい」値が現れる最初のインデックスを返す
        public static int UpperBound<T>(T[] a, T v) where T : IComparable<T>
        {
            int l = 0;
            int r = a.Length - 1;

            while (l <= r)
            {
                int mid = l + (r - l) / 2;

                if (a[mid].CompareTo(v) <= 0)
                {
                    l = mid + 1;
                }
                else
                {
                    r = mid - 1;
                }
            }

            return l;
        }




        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int[] v = new int[N];

            for (int i = 0; i < N; i++)
            {
                v[i] = int.Parse(s[i]);
            }
            Array.Sort(v);

            int ans = 0;
            for (int a = 0; a < N - 2; a++)
            {
                int va = v[a];

                for (int c = a + 2; c < N; c++)
                {
                    int vc = v[c];

                    int vb = vc - va;
                    int b = UpperBound(v,vb);

                    if (b <= a)
                    {
                        b = a + 1;
                    }

                    if (b < c)
                    {
                        ans += c - b;
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 13176
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 2e5 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

ll add(ll a, ll b) {
  a = ((a % MOD) + (b % MOD)) % MOD;
  return a;
}

ll sub(ll a, ll b) {
  a = (((((a % MOD) - (b % MOD)) % MOD) + MOD) % MOD);
  return a;
}

ll mul(ll a, ll b) {
  return (a * b) % MOD;
}

ll power(ll a, ll b) {
  ll ret = 1;
  while(b) {
    if(b & 1)
      ret = mul(ret, a);
     b /= 2;
     a = mul(a, a);
  }
  return ret;
}

string arr[M];
ll fact[N], inv[N], dp[N];

ll cmp(pair<int, int> a, pair<int, int> b) {
  return a.first + a.second < b.first + b.second;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  fact[0] = 1, inv[0] = 1;
  for (int i = 1; i < N; ++i)
    fact[i] = mul(i, fact[i - 1]), inv[i] = power(fact[i], MOD - 2);
  int n, m, k, x, y;
  cin >> n >> m >> k;
  vector<pair<int, int>> vec;
  for (int i = 0; i < k; ++i) {
    cin >> x >> y;
    vec.push_back({x, y});
//    dp[i] = mul(fact[(x - 1) + (y - 1)], mul(inv[(x - 1)],inv[y - 1])); // (x - 1) + (y - 1) - (y - 1) => (x-1)
    cerr << dp[i] << endl;
  }
  sort(vec.begin(), vec.end(), cmp);
  for (int i = 0; i < k; ++i) {
    x = vec[i].first, y = vec[i].second;
    ll tmp = mul(fact[(x - 1) + (y - 1)], mul(inv[(x - 1)],inv[y - 1]));
    for (int j = 0; j < i; ++j) {
      if(vec[j].first <= vec[i].first && vec[j].second <= vec[i].second) {
        ll temp = mul(fact[(vec[i].first - vec[j].first) + (vec[i].second - vec[j].second)], mul(inv[(vec[i].first - vec[j].first)],inv[(vec[i].second - vec[j].second)]));
        tmp = sub(tmp, mul(dp[j], temp));
//        cerr << dp[i] << endl;
      }
    }
    dp[i] = tmp;
  }
  dp[k] = mul(fact[(n - 1) + (m - 1)], mul(inv[(n - 1)],inv[m - 1]));
  for (int j = 0; j < k; ++j) {
    if(vec[j].first <= n && vec[j].second <= m) {
      ll temp = mul(fact[(n - vec[j].first) + (m - vec[j].second)], mul(inv[(n - vec[j].first)],inv[(m - vec[j].second)]));
      dp[k] = sub(dp[k], mul(dp[j], temp));
      cerr << dp[k] << endl;
    }
  }
  cout << dp[k];
//  for (int i = 1; i <= mm; ++i) {
//    int m = i;
//    memset(dp, 0, sizeof dp);
//    dp[0][0] = 1;
//    int a = n, b = m;
//    if(a < b)
//      swap(a, b);
//    ll ans = mul(fact[a+b-2], mul(inv[b - 1], inv[a - 1]));
//    cerr << ans << endl;
//    for (int i = 0; i < n; ++i) {
//      for (int j = 0; j < m; ++j) {
//        if(arr[i][j] == '#') continue;
//        if(i)
//          dp[i][j] = add(dp[i][j], dp[i-1][j]);
//        if(j)
//          dp[i][j] = add(dp[i][j], dp[i][j-1]);
//      }
//    }
//    cout << (dp[n-1][m-1] != ans) << endl;
//  }
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    string S, T;
	cin >> S >> T;

	if (T.length() == S.length() + 1)
	{
		string str = T.substr(0, S.length());
		if (str == S)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
using namespace std;
	int a,b,c,x;
int solve(){
	int ans=0;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++){
				int sum=500*i + 100*j + 50*k;
				if(sum==x) ans++;
			}
	return ans;
}
int main(){
	cin >> a >> b >> c >> x;
	cout << solve() << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        for (int i = 0 ; i < 3000 ; i++) {
            int n = x + i;
            boolean f = true;
            for (int j = 2 ; j <= Math.sqrt(n) ; j++) {
                if (n % j == 0) f = false;
            }
            if (f) {
                System.out.println(x + i);
                return;
            }
        }
    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};

signed main(){
	int a,b,n;
	cin>>n>>a>>b;
	if(n==1)cout<<"Hello World"<<endl;
	else cout<<a+b<<endl;
}

Measured memory_bytes: 256
from collections import Counter

N, *I = map(int, open(0).read().split())
A, Q, BC = I[:N], I[N], I[N + 1:]

C = Counter(A)
ans = sum(A)
for b, c in zip(*[iter(BC)] * 2):
    ans += (c - b) * C[b]
    C[c] += C[b]
    C[b] = 0
    print(ans)

Measured memory_bytes: 44116
n = input()
num = int(n)
ans = [0,0,0,0]
for i in range(num):
    a = input()
    if a =="AC":
        ans[0]+=1
    elif a == "WA":
        ans[1]+=1
    elif a == "TLE":
        ans[2]+=1
    else:
        ans[3]+=1
print("AC x " + str(ans[0]))
print("WA x " + str(ans[1]))
print("TLE x " + str(ans[2]))
print("RE x " + str(ans[3])) 

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  string t;
  cin >> t;
  set<int> s;
  rep(i,t.size()){
    if(t[i]=='N') s.insert(0);
    if(t[i]=='W') s.insert(1);
    if(t[i]=='S') s.insert(2);
    if(t[i]=='E') s.insert(3);
  }
  if(s.count(0)!=s.count(2) || s.count(1)!=s.count(3)){
    cout << "No" << endl;
  }
  else cout << "Yes" << endl;
  
  return 0;

}


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

int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    int res = 0, outlet = 1;
    while (outlet < b)
    {
        outlet--;
        outlet += a;
        res++;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int, int> p;

int t_x[] = {1, 1, 1, 0, -1, -1, -1, 0};
int t_y[] = {1, 0, -1, -1, -1, 0, 1, 1};

int field[52][52];  

int main()
{
  while (true) {
    memset(field, 0, sizeof field);
    int width, height;
    scanf("%d %d", &width, &height);
    
    if (width == 0 && height == 0) break;
    
    for (int i = 1; i <= height; i++) {
      for (int j = 1; j <= width; j++) {
	scanf(" %d", &field[i][j]);
      }
    }
    
    queue<p> que;
    int c = 0;

    for (int i = 1; i <= height; i++) {
      for (int j = 1; j <= width; j++) {
	if (field[i][j] == 1) {
	  c++;
	  que.push(p(i, j));
	  field[i][j] = 0;
	  while (!que.empty()) {
	    p tmp = que.front();
	    que.pop();
	    //field[tmp.second][tmp.first] = 0;
	    //cout << tmp.first << ", " << tmp.second << endl;
	    for (int k = 0; k < 8; k++) {
	      int tx = tmp.second + t_x[k];
	      int ty = tmp.first + t_y[k];
	      //cout << ty << ", "<< tx << " =  "<< field[ty][tx] << endl;
	      if (field[ty][tx] == 1) {
		field[ty][tx] = 0;
		que.push(p(ty, tx));
	      }
	    }
	    //cout << endl;
	    //cout << i << " " << j << endl;
	    for (int k = 1; k <= height; k++) {
	      for (int l = 1; l <= width; l++) {
		//cout << field[k][l] << " ";
	      }
	      //cout << endl;
	    }
	    //cout << endl;
	  }
	}
      }     
    }
    cout << c << endl;
  }
  return 0;
}

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

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
using ll = long long;

const int maxn = 2e5 + 10; 
const int INF = 0x3f3f3f3f;

deque<char>que;
int m,q[maxn],f[maxn];
char c[maxn];

int main()
{
	fastIO;
	string s; cin >> s;
	for(int i = 0; i < s.size(); ++i){
		que.push_back(s[i]);
	}
	cin >> m;
	int num_t = 0;
	for(int i = 0; i < m; ++i) {
		cin >> q[i];
		if(q[i] == 2) cin >> f[i] >> c[i];
		else num_t++;
	}
	if(num_t % 2) {
		reverse(que.begin(),que.end());
	}
	int now_t = 0;
	for(int i = 0; i < m; ++i){
		if(q[i] == 1) now_t++;
		else {
			if(f[i] == 1) {
				if((num_t - now_t) % 2 == 0) que.push_front(c[i]);
				else que.push_back(c[i]);
			}
			else {
				if((num_t - now_t) % 2 == 1) que.push_front(c[i]);
				else que.push_back(c[i]);
			}
		}
	}
	for(int i = 0; i < que.size(); ++i) {
		cout << que[i];
	}
	return 0;
}

Measured memory_bytes: 2768
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <algorithm>
#include <limits.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#define ll long long
#define MSET(x) memset((x), 0, sizeof((x)))
#define MMSET(x) memset((x), -1, sizeof((x)))
#define rep(i, a, b) for ( int (i) = a; (i) < (b) ; (i) ++ )
#define repA(i, a, b) for ( int (i) = a ;  (i) <= (b) ; (i) ++ )
#define repD(i, a, b) for ( int (i) = a; (i) >= (b) ; (i) -- )
#define fi first
#define se second
#define pb push_back
#define mfind(m, item) ((m).find((item)) != (m).end())
#define mp(a,b) make_pair((a),(b))
#define mt(a,b,c) make_pair(make_pair((a),(b)), (c))
#define tfi first.first
#define tse first.second
#define tth second
#define print cout << endl
#define tri pair<pair<int, int>, int>
using namespace std;

int n,m;
int fa[100005], cnt[100005];
void find(int x){
    if ( fa[x] == x ) return;
    find(fa[x]);
    cnt[x] += cnt[fa[x]]; fa[x] = fa[fa[x]];
}

int main(){
    while ( cin >> n >> m ) {
        bool has = false;
        MSET(fa); MSET(cnt);
        for ( int i = 0 ; i <= n ; ++ i ) fa[i] = i;
        for ( int i = 0, x, y, z ; i < m ; ++ i ) {
            scanf("%d %d %d", &x, &y, &z);
            find(x); find(y);
            if ( fa[x] == fa[y] ) {
                if ( cnt[y] != cnt[x] + z ) has = true;
            }
            else {
                cnt[fa[y]] = cnt[x] + z - cnt[y];
                fa[fa[y]] = fa[x];
            }
        }
        cout << (has ? "No" : "Yes" ) << endl;
    }
}


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

using namespace std;

int max(int a, int b) {
    return (a >= b) ? a : b;
}

/*int main() {
    vector<long long> value;
    long long A,B,C;
    int X,Y;

    cin >> A >> B >> C >> X >> Y;

    for ( int i = 0; i <= max(X,Y); ++i ) {
        value.push_back(2*C*i + A * max(0,X-i) + B * max(0,Y-i));
    }

    sort(value.begin(),value.end());
    cout << "sort completed!" << endl;

    cout << value[0] << endl;

    return 0;

}*/

int main() {
    long long A,B,C;
    int X,Y;

    cin >> A >> B >> C >> X >> Y;

    long long min;
    min = A * X + B * Y;
    for ( int i = 1; i <= max(X,Y); ++i ) {
        if ( (2*C*i + A * max(0,X-i) + B * max(0,Y-i)) < min ) min = (2*C*i + A * max(0,X-i) + B * max(0,Y-i));
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define eF(i,u) for(int i=h[u];i;i=nxt[i])
#define Mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;

int n,m,S,T;
ll Ans;
int U[200001],V[200001],D[200001];
int h[100001],nxt[400001],to[400001],w[400001],tot;
void ins(int x,int y,int z){nxt[++tot]=h[x];to[tot]=y;w[tot]=z;h[x]=tot;}

ll d1[100001],d2[100001],g1[100001],g2[100001];bool v1[100001],v2[100001];
priority_queue<pli,vector<pli>,greater<pli> > pq;

void Dij(ll*d,ll*g,bool*v,int s){
    d[s]=0ll;
    pq.push(pli(0ll,s));
    g[s]=1;
    while(!pq.empty()){
        pli P=pq.top(); pq.pop();
        int u=P.second; ll du=P.first;
        if(v[u]||d[u]<du) continue;
        v[u]=1;
        eF(i,u){
            if(d[to[i]]==du+w[i])
                g[to[i]]=(g[to[i]]+g[u])%Mod;
            if(d[to[i]]>du+w[i])
                g[to[i]]=g[u],
                        d[to[i]]=du+w[i], pq.push(pli(d[to[i]],to[i]));
        }
    }
}

int main(){
    int x,y,z;
    scanf("%d%d",&n,&m);
    scanf("%d%d",&S,&T);
    F(i,1,m) scanf("%d%d%d",&x,&y,&z), ins(x,y,z), ins(y,x,z), U[i]=x, V[i]=y, D[i]=z;
    memset(d1,0x3f,sizeof d1);
    Dij(d1,g1,v1,S);
    memset(d2,0x3f,sizeof d2);
    Dij(d2,g2,v2,T);
    ll Dist=d1[T];
    Ans=g1[T]*g1[T]%Mod;
    F(i,1,n){
        if(d1[i]+d2[i]==Dist&&d1[i]==d2[i])
            Ans=(Ans-g1[i]*g1[i]%Mod*g2[i]%Mod*g2[i]%Mod)%Mod;
    }
    int u,v,d;
    F(i,1,m){
        u=U[i], v=V[i], d=D[i];
        if(d1[u]+d+d2[v]==Dist && d1[u]+d>d2[v] && d2[v]+d>d1[u]){
            Ans=(Ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
        }
        u=V[i], v=U[i], d=D[i];
        if(d1[u]+d+d2[v]==Dist && d1[u]+d>d2[v] && d2[v]+d>d1[u]){
            Ans=(Ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
        }
    }
    printf("%lld",(Ans%Mod+Mod)%Mod);
    return 0;
}

Measured memory_bytes: 12656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template < typename T > using oset = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
// find_by_order(k) (k+1)th largest element
// order_of_key(k) no of elements <=k

typedef long long ll;
typedef long double ld;
#define endl '\n'
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
#define pb push_back
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpl;
const ld PI = 4*atan((ld)1);
const ll INF = LLONG_MAX;
const ll mod = 1e9+7;

const ll N = 2e5+5;
vector<ll> g[N];
vector<bool> vis(N,false);
ll cnt=0;
void dfs(ll u){
    vis[u] =1;
    cnt++;
    trav(v,g[u]){
        if(!vis[v]){
            // cnt++;
            dfs(v);
        }
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    repA(qq,1,tt){
        ll n,m; cin >> n >> m;
        rep(i,m){
            ll x,y; cin >> x >> y;
            g[x].pb(y);
            g[y].pb(x);
        }
        ll ans =0;
        vll len;
        repA(i,1,n){
            if(!vis[i]){
                cnt=0;
                dfs(i);
                len.pb(cnt);
            }
        }
        sort(all(len));
        ans = len[0];

        // cout<< len[0] <<" ";
        repA(i,1,sz(len)-1){
            // cout << len[i] << " ";
            ans += len[i]-len[i-1];
        }
        // cout << endl;
        cout << ans;
    }
}


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

sig = {0:0}
m = 0
for i in A:
    m += i
    if m not in sig:
        sig[m] = 0
    else:
        sig[m] += 1


ans = 0
for i in sig.values():
    ans += i*(i+1)//2

print(ans)


Measured memory_bytes: 38676
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;


int main(){
  ll n;cin>>n;
  vll l(n);
  ll ans=0;
  rep(i,0,n)cin>>l[i];
  rep(i,0,n){
    rep(j,i+1,n){
      rep(k,j+1,n){
        if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i])continue;
        if(l[i]+l[j]>l[k]&&l[i]+l[k]>l[j]&&l[j]+l[k]>l[i]){
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}





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

int main(void)
{
    int K, N, i, a, max;

    scanf("%d %d", &K, &N);
    int A[N];
    for(i=0; i<N; i++) {
        scanf("%d",&A[i]);
    }
    max = abs(K-A[N-1]);

    if(A[0] == 0) {
        max = K - A[N-1];         
    } else {
        max = K - A[N-1]  + A[0];
    }

    for(i=1; i<N; i++) {
        a = A[i-1];
        if(max < abs(a - A[i])){
            max = abs(a - A[i]);
        }
    }

    printf("%d\n", K-max);


    return 0;
}

Measured memory_bytes: 2476
import sys

input = sys.stdin.readline

inf = 300 * (10 ** 9) + 10

n, m, max_tank = map(int, input().split())

dist = [[inf] * n for _ in range(n)]
for i in range(n):
    dist[i][i] = 0

for _ in range(m):
    a, b, c = map(int, input().split())
    if c > max_tank:
        continue
    # 燃料不足で通過できない

    a -= 1
    b -= 1

    dist[a][b] = c
    dist[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

g = [[inf] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if dist[i][j] <= max_tank:
            g[i][j] = 0

for i in range(n):
    g[i][i] = 0

for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j] + 1)

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(-1 if g[s][t] == inf else g[s][t])


Measured memory_bytes: 57052
n = int(input())

c = 0
for i in range(n):
    i,j = list(map(int, input().split()))
    if i == j and c == 0:
        c += 1
    elif i == j and c == 1:
        c += 1
    elif i == j and c == 2:
        c += 1
        break
    else:
        c = 0
    
if c == 3:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout<<a[n-1]; 
	re 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
inline int $(){
	register int x = 0;register char ch = getchar();
	while(!isdigit(ch))ch = getchar();
	for(;isdigit(ch);ch = getchar())x = (x << 1) + (x << 3) + (ch ^ 48);
	return x;
}
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define MAXN 400
int head[MAXN], next[MAXN * MAXN], to[MAXN * MAXN], tot;
inline void $(int u, int v){
	next[tot] = head[u];to[tot] = v;head[u] = tot++;
}
int vis[MAXN], match[MAXN], timer;
inline bool $(int x){
	for(int i = head[x];~i;i = next[i]){
		if(vis[to[i]] == timer)continue;
		vis[to[i]] = timer;
		if(!~match[to[i]] || $(match[to[i]]))return match[to[i]] = x, 1;
	}
	return 0;
}
int a[MAXN], b[MAXN], c[MAXN], d[MAXN];
int main(){
	register int n = $();
	memset(head, -1, sizeof(head));tot = 0;
	memset(match, -1, sizeof(match));
	memset(vis, 0, sizeof(vis));
	for(int i = 1;i <= n;i++)scanf("%d%d", &a[i], &b[i]);
	for(int i = 1;i <= n;i++)scanf("%d%d", &c[i], &d[i]); 
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			if(a[i] < c[j] && b[i] < d[j])$(i, j);
		}
	}
	int ans = 0;
	for(timer = 1;timer <= n;timer++)if($(timer))ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


int main(void) {
   ll N;
   cin>>N;
   vector<ll> A(N,0);
   rep(i,0,N) cin>>A[i];

   ll now = 0;
   rep(i,0,N) {
      if (A[i]==now+1) now++;
   }
   if (!now) cout<<-1<<endl;
   else cout<<N-now<<endl;

   return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
 
using namespace std;
typedef unsigned long long int ll;
const ll hell = 100005; 
bool comp(const pair<string,ll> &a,const pair<string, ll> &b)
{
   return a.second>b.second;
}
ll binpow(ll a,ll b) 
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    cout<<ceil(n*1.0/2);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a1(n), a2(n, 0);//添え字ずれるよ
  cin >> a1[0];
  for (int i = 1; i < n; i++) {
    int a1i;
    cin >> a1i;
    a1[i] = a1[i-1] + a1i;
  }
  for (int i = 0; i < n; i++) {
    int a2i;
    cin >> a2i;
    for (int j = 0; j <= i; j++) a2[j] += a2i;
  }
  int candy = 0;
  for (int i = 0; i < n; i++) {//iで↓移動
    int sum = a1[i] + a2[i];
    candy = max(candy, sum);
  }
  cout << candy;
}

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

using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

int main(int argc, char *argv[])
{
    ll X, Y;
    cin >> X >> Y;
    if (abs(X-Y) <= 1)
        cout << "Brown\n";
    else
        cout << "Alice\n";
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int d,n;
    scanf("%d %d",&d,&n);

    if(d == 0)
    {
        if(n != 100)printf("%d",n);
        else printf("%d",n + 1);
    }
    else if(d == 1)
    {
        if(n != 100)printf("%d00",n);
        else printf("%d00",n + 1);
    }
    else
    {
        if(n != 100)printf("%d0000",n);
        else printf("%d0000",n + 1);
    }
    
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <strstream>
using namespace std;

int main()
{
	int w,n;
	cin >> w >> n;
	vector<int> line;
	for(int i=0; i<w; ++i)
	{
		line.push_back(i);
	}

	for(int i=0; i<n; ++i)
	{
		string str;
		cin >> str;
		int dot = str.find(',');
		string numa = str.substr( 0, dot );
		string numb = str.substr( dot+1, str.size()-1 );
		int A,B;
		istrstream( numa.data() ) >> A;
		istrstream( numb.data() ) >> B;
		--A;
		--B;
		int x = line[A];
		line[A] = line[B];
		line[B] = x;
	}

	for(int i=0; i<w; ++i)
	{
		cout << line[i]+1 << '\n';
	}
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
  int H,W,j,i;
  while(1){
    scanf("%d %d\n",&H,&W);
    if(H==0 && W==0)break;
    for(j=0;j<H;j++){
      for(i=0;i<W;i++){
	printf("#");
      }
      printf("\n");
    }  
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 576
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    cc = 'aeiou'
    c = S()
    if c in cc:
        return 'vowel'
    return 'consonant'


print(main())


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

using namespace std;

using i64 = long long;
constexpr i64 INF = 1e18;

class SegmentTree {
private:
    vector<i64> _mx;
    int _n;
    int lc(int node) { return 2 * node; }
    int rc(int node) { return 2 * node + 1; }
    int mid(int a, int b) { return (a + b) / 2; }
    int num(int a, int b) { return b - a + 1; }
    void update(int node) {
        _mx[node] = min(_mx[lc(node)], _mx[rc(node)]);
    }
    void update_range(int node, int l, int r, int i, i64 val) {
        if (l > r || l > i || r < i) {
            return;
        } else if (i == l && i == r) {
            _mx[node] = min(_mx[node], val);
            return;
        }
        update_range(lc(node), l, mid(l, r), i, val);
        update_range(rc(node), mid(l, r) + 1, r, i, val);
        update(node);
    }
    i64 query_range(int node, int l, int r, int i, int j) {
        if (l > r || l > j || r < i) {
            return INF;
        } else if (i <= l && r <= j) {
            return _mx[node];
        }
        i64 res = query_range(lc(node), l, mid(l, r), i, j);
        return min(res, query_range(rc(node), mid(l, r) + 1, r, i, j));
    }
public:
    SegmentTree(int n) : _n(n) {
        _mx.assign(4 * _n + 1, INF);
        //build(1, 0, _n - 1, a);
    }
    void update(int i, i64 val) {
        update_range(1, 0, _n - 1, i, val);
    }
    i64 query_range(int i, int j) {
        return query_range(1, 0, _n - 1, i, j);
    }
};

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

    int N, M;
    cin >> N >> M;
    SegmentTree st(N + 1);
    vector<tuple<int, int, int>> segs(M);
    for (int i = 0; i < M; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        segs[i] = tuple<int,int,int>{r, l, c};
    }
    sort(begin(segs), end(segs));
    st.update(1, 0);
    for (int i = 0; i < M; ++i) {
        int r, l, c;
        tie(r, l, c) = segs[i];
        i64 mn = st.query_range(l, r);
        st.update(r, mn + c);
    }
    i64 ans = st.query_range(N, N);
    if (ans < INF) {
        cout << ans << "\n";
    } else {
        cout << -1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 4480
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] a = new long[n];
        long[] x = new long[n];
        long[] b = new long[m];
        long[] y = new long[m];
        long MOD = (long) (Math.pow(10, 9) + 7);

        a[0] = sc.nextLong();
        for(int i = 1; i < n; i++){
            a[i] = sc.nextLong();
            x[i] = a[i] - a[i-1];
            x[i] %= MOD;
        }

        b[0] = sc.nextLong();
        for(int i = 1; i < m; i++){
            b[i] = sc.nextLong();
            y[i] = b[i] - b[i-1];
            y[i] %= MOD;
        }

        long ans = 0;

/*        long x_sum = 0;

        for(int i = 1; i < n; i++){
            long xx = (n - i) * ( i );    
            xx %= MOD;
            x[i] *= xx;
            x[i] %= MOD;
            x_sum += x[i];
            x_sum %= MOD;
        }

        long y_sum = 0;

        for(int i = 1; i < m; i++){
            long yy = (m - i) * ( i );    
            yy %= MOD;
            y[i] *= yy;
            y[i] %= MOD;
            y_sum += y[i];
            y_sum %= MOD;
        }*/

        long a_sum = 0;
        for(int i = 0; i < n; i++){
            a_sum += ( i * 2 - n + 1 ) * a[i];
            a_sum %= MOD;
        }

        long b_sum = 0;
        for(int i = 0; i < m; i++){
            b_sum += ( i * 2 - m + 1 ) * b[i];
            b_sum %= MOD;
        }

 //       ans = x_sum * y_sum;
        ans = a_sum * b_sum;
        ans %= MOD;
        System.out.println(ans);
    }
}

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

int a[101],b[101];
int main(){
    int n,m;
    while(cin>>n>>m,n|m){
        int s1=0,s2=0;
        rep(i,n){
            cin>>a[i];
            s1+=a[i];
        }
        rep(i,m){
            cin>>b[i];
            s2+=b[i];
        }
        int sub=s1-s2;
        int ans1=-1,ans2=-1,mn=1000100010;
        rep(i,n)rep(j,m){
            if(sub==(a[i]-b[j])*2){
                if(a[i]+b[j]<mn) mn=a[i]+b[j],ans1=a[i],ans2=b[j];
            }
        }
        if(mn==1000100010) cout<<-1<<endl;
        else cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}



Measured memory_bytes: 3000
import Data.List

main = do
    (_:_:x:y:_) <- map read . words <$> getLine :: IO [Int]
    xs <- map read . words <$> getLine
    ys <- map read . words <$> getLine
    if maximum (x:xs) < minimum (y:ys)
       then putStrLn "No War"
       else putStrLn "War"

Measured memory_bytes: 1020
/*  -*- coding: utf-8 -*-
 *
 * n.cc: N - Slimes
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 400;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

ll dp[MAX_N][MAX_N + 1], szs[MAX_N + 1];

/* subroutines */

inline void setmin(ll &a, ll b) { if (a > b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  szs[0] = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    szs[i + 1] = szs[i] + ai;
  }

  for (int l = 2; l <= n; l++)
    for (int i = 0, j = l; j <= n; i++, j++) {
      ll mind = LINF;
      ll szij = szs[j] - szs[i];
      for (int k = i + 1; k < j; k++)
	setmin(mind, dp[i][k] + dp[k][j] + szij);
      dp[i][j] = mind;
    }

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


Measured memory_bytes: 1536
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<int>> mat;
ll mod=pow(10,9)+7;

struct Combination{
    vec n,n_rev;

    Combination(int N){
        n.resize(N+1);
        n_rev.resize(N+1);
        n[0]=1;n_rev[1]=1;
        for(int i=1;i<=N;i++){
            n[i]=((ll)i*n[i-1])%mod;
        }
        for(int i=2;i<=N;i++){
            n_rev[i]=matpow(n[i],mod-2);
        }
    }

    //累乗(aのk乗)
    ll matpow(ll a,int k){
        ll dp=1,mt=a;
        while(k>0){
            if(k & 1)dp=(dp*mt)%mod;
            mt=(mt*mt)%mod;
            k/=2;
        }
        return dp;
    }

    ll comb(int N,int r){
        if(N<r)return 0; 
        if(r==0 || N==r)return 1;
        return (((n[N]*n_rev[r])%mod)*n_rev[N-r])%mod;
    }
};

int main(){
    int N,K;cin>>N>>K;
    Combination Comb(N);
    vec A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    ll ans=0,x;
    for(int i=0;i<N;i++){
        x=(Comb.comb(i,K-1)-Comb.comb(N-1-i,K-1)+mod)%mod;
        ans=(ans+(x*A[i])%mod+mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ans;
  if(a+b+1>=c){
    ans= b+c;
  }
  else{
    ans=a+2*b+1;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	char A;
	char B;
	char C;
	cin >> A >> B >> C;

	if (A == '1') {
		A = '9';
	}
	else {
		A = '1';
	}
	if (B == '1') {
		B = '9';
	}
	else {
		B = '1';
	}
	if ( C == '1') {
		C = '9';
	}
	else {
		C = '1';
	}



	cout << A << B << C << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

a, b, c = sorted(map(int, input().split()))

ans = 0
while not (a % 2 == b % 2 == c % 2):
    if a % 2 == b % 2:
        a += 1
        b += 1
    elif a % 2 == c % 2:
        a += 1
        c += 1
    elif b % 2 == c % 2:
        b += 1
        c += 1
    ans += 1

print(ans + (c - a) // 2 + (c - b) // 2)


Measured memory_bytes: 61608