akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

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

    if (a < b)
    {
        cout << "a < b\n";
    }
    else if (a == b) {
        cout << "a == b\n";
    }
    else {
        cout << "a > b\n";
    }

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, x, y;
    int xmax, ymin;
    xmax = -1e9;
    ymin = 1e9;
    cin >> n >> m >> x >> y;
    for (int i = 0; i < n; i++)
    {
        int data;
        cin >> data;
        xmax = max(xmax, data);
    }
    for (int i = 0; i < m; i++)
    {
        int data;
        cin >> data;
        ymin = min(ymin, data);
    }
    int z;
    if (ymin > xmax)
    {
        z = xmax + 1;
    }
    else
    {
        cout << "War" << endl;
        return 0;
    }
    if (z > x && z <= y)
    {
        cout << "No War" << endl;
        return 0;
    }
    else
    {
        cout << "War" << endl;
        return 0;
    }
    system("pause");
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	long a = rlong, b = rlong, c = rlong;
	if(c - a - b <= 0) "No".writeln;
	else if(4 * a * b < (c - a - b) * (c - a - b)) "Yes".writeln;
	else "No".writeln;
}

/*
sqa + sqb < sqc
a + b + 2 sqa sqb < c
2 sqa sqb < c - a - b
4 a b < (c - a - b)**2
*/


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    uint64_t N, A[5];
    uint64_t min = UINT64_MAX;

    scanf("%"PRIu64"\n%"PRIu64"\n%"PRIu64"\n%"PRIu64"\n%"PRIu64"\n%"PRIu64, &N, &A[0], &A[1], &A[2], &A[3], &A[4]);

    for (size_t i = 0; i < 5; i++) {
        if (A[i] < min) {
            min = A[i];
        }
    }

    printf("%"PRIu64"\n", (N + min - 1) / min + 4);

    return 0;
}


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

using ll = long long;

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

int main() {
    ll MOD = 1e9 + 7;
    vector<ll> f(1000001, 1);
    rep(i, 1000000) {
        f[i + 1] = (f[i] * (i + 1)) % MOD;
    }
    int X, Y;
    cin >> X >> Y;
    int N = (X + Y) / 3;
    rep(i, N + 1) {
        if (N + i == X && N * 2 - i == Y) {
            ll ans = (f[N] * mod_pow(f[i], MOD - 2, MOD)) % MOD;
            ans = (ans * mod_pow(f[N - i], MOD - 2, MOD)) % MOD;
            cout << ans << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
using namespace std;
int map[101][101];
int h,w;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

void REC(int y,int x,int type){
	map[y][x]=0;
	for(int i=0;i<4;i++){
		if(y+dy[i]>=0&&y+dy[i]<h&&x+dx[i]>=0&&x+dx[i]<w){
		if(map[y+dy[i]][x+dx[i]]==type)
			REC(y+dy[i],x+dx[i],type);
		}
	}
}
int main(){
	while(true){
	cin>>h>>w;
	if(h==0&&w==0)
		break;
	char z;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>z;
			if(z=='#')
				map[i][j]=1;
			if(z=='@')
				map[i][j]=2;
			if(z=='*')
				map[i][j]=3;
		}
	}
	int count=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(map[i][j]!=0){
				count++;
				REC(i,j,map[i][j]);
			}
		}
	}
	cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 1668
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

struct UnionFind {
    
    vector < int > node;
    UnionFind(int n) : node(n, -1) {}
    
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (node[y] < node[x]) swap(x, y);
            node[x] += node[y];
            node[y] = x;
        }
        return x != y;
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    int root(int x) {
        return node[x] < 0 ? x : node[x] = root(node[x]);
    }
    
    int size(int x) {
        return -node[root(x)];
    }
    
};
/*
 usage:
 
 初期化:
 UnionFind  UF(N);//ノードの数
 unite(x,y);// xとyノード連結
 same(a,b);// aとbが同じ所属かどうかを判別
 root(a); //aのルートのノードを計算
 */

ll ans[200005];
map<pair<ll,ll>, vector<ll> > cnt;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N ,K, L ; cin >> N >> K >> L;
    UnionFind RK(N);
    UnionFind RL(N);
    
    rep(i,K){
        ll a,b ; cin >> a >> b;
        a--, b--;
        RK.unite(a,b);
    }
    rep(i,L){
        ll a,b; cin>> a >> b;
        a--, b--;
        RL.unite(a,b);
    }
    
    vector<ll> ar;
    vector<ll> br;

    vector<pair<ll,ll> > lst;
    rep(i,N){
        ll a = RK.root(i);
        ll b = RL.root(i);
        lst.pb(mp(a,b));
        cnt[mp(a,b)].pb(i);
    }
    

    rmsame(lst);
    rep(i, lst.size()){
        pair<ll,ll> now = lst[i];
        ll si = cnt[now].size();
        rep(j,cnt[now].size()){
            ll num = cnt[now][j];
            ans[num] = si;
        }
    }
    
    rep(i,N){
        cout << ans[i] << " ";
    }
    cout << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 26732
n, m = map(int, input().split())

card = [[] for _ in range(n)]

for _ in range(m):
    x, y, _ = map(int, input().split())
    card[x-1].append(y-1)
    card[y-1].append(x-1)

checked = [False] * n

count = 0
from collections import deque
for i in range(n):
    if checked[i]:
        continue
    count += 1
    q = deque([i])
    while q:
        j = q.popleft()
        checked[j] = True
        for k in card[j]:
            if not checked[k]:
                q.append(k)
print (count) 



Measured memory_bytes: 93264
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    PY = [tuple([i] + list(map(int, input().split()))) for i in range(M)]
    result = []
    p_city = defaultdict(int)
    for py in sorted(PY, key = lambda x: x[2]):
        p_city[py[1]] += 1
        code = str(py[1]).zfill(6) + str(p_city[py[1]]).zfill(6)
        result.append((py[0], code))
    print("\n".join([r[1] for r in sorted(result, key = lambda x: x[0])]))


if __name__ == '__main__':
    main()


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

const int mxN = 1e5 + 5;
vector<int> adj[mxN];
int a[mxN];

int main() {
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	while(k--) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		bool ok = true;
		for(int x : adj[i])
			if(ok)
				ok = a[i] > a[x];
		ans += ok;
	}
	cout << ans;
}


Measured memory_bytes: 8668
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int G[60][60];
struct node
{
	int u,v;
}e[100];
int vis[100];
int viss[100];
int to[200],beg[200],nex[200];
int ee;
void add(int x,int y)
{
	to[++ee]=y;
	nex[ee]=beg[x];
	beg[x]=ee;
}
void dfs(int x,int fa,int edge)
{
	for(int i=beg[x];i;i=nex[i])
	{
		int y=to[i];
		if(x==e[edge].u&&y==e[edge].v)continue;
		if(x==e[edge].v&&y==e[edge].u)continue;
		if(!vis[y]&&y!=fa)
		{
			vis[y]=1;
			viss[y]=1;
			dfs(y,x,edge);
			vis[y]=0;
		}
	}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".in","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b);add(b,a);
		e[i].u=a;e[i].v=b;
	}
	int cnt=0;
	for(int i=1;i<=m;i++)
	{
		memset(vis,0,sizeof(vis));
		memset(viss,0,sizeof(viss));
		vis[1]=1;
		viss[1]=1;
		dfs(1,0,i);
		int flag=0;
		for(int j=1;j<=n;j++)
		{
			if(!viss[j]){flag=1;break;}
		}
		if(flag)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
struct edge {
  int to,w;
};
#define MAX 1000000005
vector<vector<edge> > g;
vector<int> min_d;
priority_queue <edge, vector<edge>,greater<edge>> que;
bool operator > (const edge a,const edge b){return a.w>b.w;};

void dfs(int v,int n){
  edge this_p;
  for(int i = 0; i<n; i++)min_d[i] = MAX;
  min_d[v] = 0;
  for(auto e : g[v]){
    que.push(e);
    min_d[e.to] = e.w;
  }

  while(!que.empty()){
    this_p = que.top();
    que.pop();
    for(auto e : g[this_p.to]){
      if(min_d[e.to] > min_d[this_p.to]+e.w){
        min_d[e.to] = min_d[this_p.to]+e.w;
        que.push(e);
      }
    }
  }
}
int main(){
  int v,e,s,t,r,w;
  edge tmp;
  cin>>v>>e>>r;
  g.resize(v);
  min_d.resize(v);
  tmp.to=r;
  tmp.w=0;
  g[r].push_back(tmp);
  for(int i=0;i<e;i++){
    cin>>s>>t>>w;
    tmp.to=t;
    tmp.w=w;
    g[s].push_back(tmp);
  }
  dfs(r,v);
  for(auto i : min_d){
    if(i==MAX)cout<<"INF"<<endl;
    else cout<<i<<endl;
  }
  return 0;
}



Measured memory_bytes: 16044
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
 
int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	
 
const ll mod=1e9+7;
const int INF=INT_MAX/2;

int main(){
	string s;
	cin>>s;
	REP(i,2){
		if(s[i]!=s[i+1]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
const int inf=1001001001; const long long INF=1001001001001001001;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int to, from, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
//
//
//
//          ∧ ∧  ／￣￣￣￣￣￣￣￣￣￣￣￣￣
// ～′￣￣( ˚д˚)＜  Let's start coding!!
//  UU￣￣  U U  ＼
//                 ￣￣￣￣￣￣￣￣￣￣￣￣￣

ll a, b, c;
int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> a >> b >> c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    cout << 0 << endl;
    return 0;
  } 
  cout << min({a * b, b * c, c * a}) << endl;
  return 0;
}



Measured memory_bytes: 256
WITH ADA.TEXT_IO; USE ADA.TEXT_IO;
WITH ADA.INTEGER_TEXT_IO; USE ADA.INTEGER_TEXT_IO;
PROCEDURE ABC170A IS
   X : INTEGER;
BEGIN
   FOR I IN 1 .. 5 LOOP
      GET(X);
      IF X /= I THEN
         PUT(INTEGER'IMAGE(I));
      END IF;
   END LOOP;
END ABC170A;

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,max = -1 , sum = 0;
  int p;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> p;
    if(max < p) max = p;
    sum += p;
  }
  sum -= max;
  sum += (max / 2);
  cout << sum << endl;
  return 0;
}


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

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    long long int k,n=7,t=1;
    unordered_set<int> s;
    cin>>k;
    n%=k;
    while(s.find(n)==s.end())
    {
        s.insert(n);
        if(n%k==0)
        {
            cout<<t;
            return 0;
        }
        n=(n*10+7)%k;
        t++;
    }
    cout<<"-1";
    return 0;
}

Measured memory_bytes: 42664
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
short map[600][600];
signed main() {
	int h, w; cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> map[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans += map[i][j] * ((i + 1)*(j + 1)*(h - i)*(w - j));
		}
	}
	cout << ans << endl;
}


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

count=0

while True:
    index = h.index(max(h))
    if max(h)==0:
        print(count)
        break

    lindex = 0
    for i in range(index):
        if h[index-(i+1)]==0:
            lindex = index-(i+1)+1
            break

    rindex = n
    for i in range(n-index-1):
        if h[index+(i+1)]==0:
            rindex = index+(i+1)-1
            break

    for i in range(len(h)):
        if i>=lindex and i<=rindex:
            h[i]-=1
    
    #print(h)
    
    count+=1

Measured memory_bytes: 42840
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> A(100001);
    for (int64_t i = 0; i < N; i++) {
        int64_t a, b;
        cin >> a >> b;
        A.at(a) += b;
    }
    int64_t sum = 0;
    for (int64_t i = 0; i < 100001; i++) {
        sum += A.at(i);
        if (sum >= K) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


int main(int argc, char* argv[]){
	long long A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	//ABピザを2k枚買うとする
	//Aピザ k枚、Bピザk枚できる。
	//のこりAピザ (X-k)枚、Bピザ(Y-k)枚買う必要がある。
	long long k;
	long long ans = (1LL<<62);

	for(k = 0; k <= max(X, Y); k++){
		long long v = C * 2 * k;
		v += A * max(X - k, 0LL);
		v += B * max(Y - k, 0LL);
		if(ans > v){
			ans = v;
		}

	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int N=1e6+5;
const long long INF = 1e6;
const int mod=998244353;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<a*b;
   




}


Measured memory_bytes: 3632
=begin
－－－－－－－－－－－－－－
S = 文字列で表した数値
N = S の文字数
ans = 合計値
res = '+'ごとのに区切った数値の合計を格納
tmp = '+'ごとに区切った数値を格納
－－－－－－－－－－－－－－

1: '+' が挿入される箇所をbit全探索(N-1)する(フラグが立っている場合 + が挿入されるとする)
  1.1: S をループし、+ が挿入されるまで S[i] を区切って tmp に代入していく
    1.1.1: bit の i番目 にフラグが立っている場合、 現時点での tmp を ans に 加算して tmp を 0 に戻す
2: ans を出力する
=end

S = gets.chomp.chars;
N = S.size() - 1;
ans = 0;

bit = 0;
while bit < (1<<N) do
  res = tmp = 0;
  S.each_with_index do |v,i|
    tmp *= 10;
    tmp += v.to_i;
    if bit[i] != 0
      res += tmp;
      tmp = 0;
    end
  end
  ans += res + tmp;
  bit += 1;
end

puts ans


Measured memory_bytes: 1788
#include <cstdio>
#include <algorithm>

using namespace std;

using llint = long long;

const llint MAXNUM = 1e15;
const int MAXN = 4e2+4;

llint mem[MAXN][MAXN];
bool solved[MAXN][MAXN];
int n;
int a[MAXN];
llint pre[MAXN];

llint dp(int l, int r) {
  if (l == r) return 0;

  llint &ret = mem[l][r];
  if (solved[l][r]) return ret;
  solved[l][r] = 1;

  ret = MAXNUM;
  for (int i = l; i < r; ++i) {
    ret = min(ret, dp(l, i) + dp(i+1, r));
  }
  ret += pre[r];
  if (l > 0) ret -= pre[l-1];

  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }

  pre[0] = a[0];
  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i-1] + a[i];
  }

  printf("%lld\n", dp(0, n-1));
  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define fi first
#define se second
#define inf 0x3f3f3f3f
using namespace std;
const int N=305;
int n,m,q,l,dis[N][N],dp[N][N];
int main()
{
    scanf("%d%d%d",&n,&m,&l);
    memset(dis,inf,sizeof(dis));memset(dp,inf,sizeof(dp));
    for(int i=1;i<=m;i++)
    {
        int u,v,w;scanf("%d%d%d",&u,&v,&w);
        dis[u][v]=dis[v][u]=min(w,dis[u][v]);
    }
    for(int i=1;i<=n;i++) dp[i][i]=dis[i][i]=0;
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        if(i!=j&&dis[i][j]<=l) dp[i][j]=1;
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    scanf("%d",&q);
    while(q--)
    {
        int s,t;scanf("%d%d",&s,&t);
        int ans=dp[s][t]-1;if(ans==inf-1) ans=-1;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

using namespace std;

int main() {
	int n;
	int a;
	cin >> n;

	map<long long, int> nums;
	for (int i = 0; i < n; i++) {
		cin >> a;

		nums[a]++;
	}

	vector<long long> v_nums;
	for (auto p: nums) {
		v_nums.emplace_back(p.first);
	}
	sort(v_nums.begin(), v_nums.end());
	reverse(v_nums.begin(), v_nums.end());

	int ans = 0;
	for (auto x: v_nums) {
		if (nums[x] == 0) {
			continue;
		}
		for (int i = 31; i >= 0; i--) {
			long long tmp = (1LL << i) - x;
			if (tmp < 0) {
				continue;
			}

			if (nums.count(tmp) == 0) {
				continue;
			}

			if (x == tmp) {
				auto add = nums[x] / 2;
				ans += add;
				nums[x] -= add * 2;
			} else {
				auto add = min(nums[x], nums[tmp]);
				ans += add;
				nums[x] -= add;
				nums[tmp] -= add;
			}

			// printf("i %d, tmp %lld: %d %d\n", i, tmp, nums[x], nums[tmp]);

			if (nums[x] == 0) {
				break;
			}
		}
	}

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


Measured memory_bytes: 15988
#include<iostream>
using namespace std;
int main(void){
  int n,m;
  cin>>n>>m;
  string*A=new string[n];
  string*B=new string[m];
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  for(int i=0;i<m;i++){
    cin>>B[i];
  }
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
      bool check=true;
      for(int k=0;k<m;k++){
        for(int l=0;l<m;l++){
          if(A[i+k][j+l]!=B[k][l]){
            check=false;
            break;
          }
        }
        if(!check){
          break;
        }
      }
      if(check){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdint.h>
#include<stdbool.h>
#include<limits.h>
#include<inttypes.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdint.h>
#include<stdbool.h>

int compare(const void * a, const void * b){
	return *(int *)b - *(int *)a;
}
int main(){
  int n;
  scanf("%d\n", &n);
  int *a = (int *)calloc(n, sizeof(int));
  char buff[400] = {0};
  fgets(buff, 401, stdin);
  a[0] = atoi(strtok(buff, " "));
  for(int i =1; i < n; ++i)
	  a[i] = atoi(strtok(NULL, " "));
  qsort(a, n, sizeof(int),compare);
  int alice=0;int bob=0;
  for(int i = 0; i< n; ++i){
	  if(i%2)
		  bob += a[i];
	  else
		  alice += a[i];
  }
  printf("%d", alice - bob);
  free(a);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
D = sorted(list(map(int,input().split())))
M = int(input())
T = sorted(list(map(int,input().split())))
for x in T[::-1]:
    while 1:
        if len(D)==0:
            print('NO')
            exit()
        temp = D.pop()
        if temp==x:
            break
print('YES')


Measured memory_bytes: 35164
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int p,q;
   while(cin>>p>>q)
   {
     string s="";
     int count=2000;
     int qin;
     while(count--)
     {
       int kk=(10*p)/q;
       qin=(10*p)%q;
       s+=('0'+kk);
       p=qin;
       if(qin==0) break;
     }
     if(qin==0) cout<<s<<endl;
     else
     {
       //cout<<s<<endl;
       bool flag=false;
       int i,j;
       string ss,sss;
       for(i=0;i<100;i++)
       {
         for(j=1;j<100;j++)
         {
           ss=s.substr(i,j);
           int k;
           for(k=1;k<=10;k++)
           {
             sss=s.substr(i+k*j,j);
             if(ss==sss) continue;
             else break;       
           }
           if(k==11) 
           {
             flag=true;
             break;          
           }      
         }   
         if(flag) break;     
       }           
       if(i==0)
       { 
         cout<<ss<<endl;
         int kk=ss.length();
         while(kk--) cout<<"^";
         cout<<endl;
       }
       else
       { 
         cout<<s.substr(0,i)<<ss<<endl;
         for(int k=0;k<i;k++) cout<<" ";
         for(int k=i;k<i+j;k++) cout<<"^";
         cout<<endl;
       }
     }     
   }
   //while(1);
   return 0;
 }

 
 

Measured memory_bytes: 3116
#include<stdio.h>
#define mil 1000000
int main(void){
  int prim[mil],i,j,n,a,b,count;

  for(i=0;i<mil;i++)prim[i]=0;
  prim[0]=prim[1]=1;  

  for(i=2;i*i<mil;i++)
    if(prim[i]==0)
      for(j=2*i;j<mil;j+=i)
	prim[j]=1;

  while(scanf("%d %d %d",&a,&b,&n),a,b,n){

    count=0;
    for(;;){
      if(prim[a]==0){
	count++;
	if(count==n)break;
      }
      a+=b;
    }
    printf("%d\n",a);
  }
  return 0;
}

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

int mod;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

ll b, ten;

mint pow_(mint x, ll t) {
  if (t == 0) return 1;
  if (t%2 == 1) {
    return pow_(x,t-1)*x;
  } else {
    mint y = pow_(x,t/2);
    return y*y;
  }
}

mint f(ll l) {
  if (l == 0) return 0;
  if (l%2 == 1) {
    ll pl = l-1;
    mint x = f(pl);
    return x*ten + 1;
  } else {
    ll pl = l/2;
    mint x = f(pl);
    return x*pow_(ten, pl) + x;
  }
}
mint g(ll l) {
  if (l == 0) return 0;
  if (l%2 == 1) {
    ll pl = l-1;
    mint x = g(pl);
    return x*ten + mint(b)*pl;
  } else {
    ll pl = l/2;
    mint x = g(pl);
    return x*pow_(ten, pl) + x + mint(b)*pl*f(pl);
  }
}

int main() {
  ll L, a;
  cin >> L >> a >> b >> mod;
  ll last = a+b*(L-1);
  mint ans = 0;
  ten = 10;
  for (int i = 1; i <= 18; ++i, ten *= 10) {
    ll l = ten/10, r = ten-1;
    if (last < l) continue;
    if (a > r) continue;
    ll na = 0; // 初項
    ll nl = 0; // 長さ
    {
      if (a >= l) na = a;
      else {
        na = ((l-a)+(b-1))/b*b+a;
        na = min(na, last);
      }
    }
    {
      ll nlast = 0;
      if (last <= r) nlast = last;
      else {
        nlast = (r-a)/b*b+a;
      }
      nl = (nlast-na)/b+1;
    }
    ans *= pow_(ten, nl);
    ans += f(nl)*na;
    ans += g(nl);
  }
  cout << ans.x << endl;
  return 0;
}    

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

int main(void){
    char data[101] = {};
    int az[26] = {};
    scanf("%s",data);
    int size = strlen(data);
    int a = 'a';
    int i;
    for(i = 0;i<size;i++){
        az[data[i] - a]++;
    }
    for(i = 0;i<26;i++){
        if(az[i] % 2 != 0){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
#print(graph)
for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1
    point[a] += b
# dfsを用いて累積和を計算する
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now , prev = -1):
    for next in graph[now]:
        # 次のノードが前に参照した値の時はcontinue
        if next == prev:
            continue
        # 現在の値を次のポイントに加算することで累積和をとる
        point[next] += point[now]
        # 次のノードと現在のノードを引数にdfsを継続する
        dfs(next , now)

dfs(0)
print(*point)

Measured memory_bytes: 282860
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();int time=0;
        boolean flag = true;
            while(flag&&time<n){
                int m = sc.nextInt();
                if(m%2==0){
                    if(!(m%3==0||m%5==0)) {
                        System.out.println("DENIED");
                        flag = false;
                    }
                }
                time++;
            }
        if(flag)
            System.out.println("APPROVED");
}}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int N;
    cin >> N;
    vector<int> v(N);
    REP(i,N)  cin >> v[i];

    int cnt = 0;
    while (true) {
        bool ok = true;
        REP(i,N-1) {
            if(v[i] > v[i+1]) {
                iter_swap(v.begin()+i,v.begin()+1+i);
                cnt++;
                ok = false;
            }
        }
        if(ok) break;
    }

    REP(i,N-1) cout << v[i] << " ";
    cout << v[N-1] << endl;
    cout << cnt << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

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

  int red = 0;
  int blue = 0;
  for(char c : s){
    if(c == '0') red++;
    if(c == '1') blue++;
  }
  
  cout << 2 * min(red, blue) << endl;

  return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    cout << k*(int)pow(k-1,n-1) << endl;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<ll, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int d, n;
  n = 26;
  cin >> d;
  vi c(n);
  rep(i, n) cin >> c[i];
  vvi s(d, vi(n));
  rep(i, d) rep(j, n) cin >> s[i][j];
  vi l(n, -1);
  vector<vector<P>> g(d, vector<P>(n));
  vi ans(d);
  rep(i, d) {
    rep(j, n) {
      g[i][j].first = s[i][j];
      g[i][j].second = j;
      rep(k, n) {
        if (j != k) g[i][j].first -= (ll)c[k] * (i - l[k]);
      }
    }
    sort(g[i].rbegin(), g[i].rend());
    // dump(g[i]);
    int mi = g[i][0].second;
    l[mi] = i;
    ans[i] = mi;
  }
  auto score = [&] (vi& sel) {
    ll sc = 0;
    l.assign(n, -1);
    rep(i, d) {
      sc += s[i][sel[i]];
      l[sel[i]] = i;
      rep(k, n) sc -= (ll)c[k] * (i - l[k]);
    }
    return sc;
  };
  ll msc = score(ans);
  dump(msc, ans);
  rep(i, d) {
    for (int j = 1; j < 5; j++) {
      vi sel = ans;
      sel[i] = g[i][j].second;
      ll ss = score(sel);
      dump(i, ss, sel);
      if (msc < ss) {
        ans = sel;
        msc = ss;
      }
    }
  }
  rep(i, d) cout << ans[i] + 1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

struct UnionFind {
  vector<ll> data;

  UnionFind(ll sz) { data.assign(sz, -1); }

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

  ll find(ll k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  ll size(ll k) { return (-data[find(k)]); }

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

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  auto uf = UnionFind(200010);

  ll N, Q;
  scanf("%lld %lld", &N, &Q);

  for (ll i = 0; i < Q; i++) {
    ll t, u, v;
    scanf("%lld %lld %lld", &t, &u, &v);

    if (t == 0) {
      uf.unite(u, v);
    }
    if (t == 1) {
      cout << (uf.same(u, v)) << endl;
    }
  }
}


Measured memory_bytes: 4668
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  string T;
  cin>>S>>T;
  vector<vector<int>> A(26);
  for(int i=0;i<S.size();i++)
    A[S[i]-'a'].push_back(i);
  int ans=0,n=-1;
  for(int i=0;i<T.size();i++){
    if(A[T[i]-'a'].size()==0){
      puts("-1");
      return 0;
    }
    int it=upper_bound(A[T[i]-'a'].begin(),A[T[i]-'a'].end(),n)-A[T[i]-'a'].begin();
    if(it==A[T[i]-'a'].size())ans++,n=A[T[i]-'a'][0];
    else n=A[T[i]-'a'][it];
  }
  cout<<ans*S.size()+n+1<<endl;
}

Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
//#pragma gcc optimize("O3")
//#pragma gcc optimize("unroll-loops")
#ifdef EVAH
    #define _WIN32_WINNT 0x0500
    //#include<windows.h>
#endif
#define openFile(n) ShellExecute(nullptr,"open",n,nullptr,nullptr,SW_SHOWNORMAL);
#define closeP(n) system((string("taskkill /im ")+n+" /f").c_str());
#define closeConsole PostMessage(GetConsoleWindow(), WM_CLOSE, 0, 0);
#define opf "output.txt"
#define ipf "input.txt"
#define mem(n,x) memset(n,x,sizeof(n));
#define sf scanf
#define pf printf
#define ff first
#define ss second
#define pb push_back
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define For(x,n) for(int i=x; i<n; i++)
#define stv v+2*(mid-tl+1)
#define LL long long int
#define N 100001

LL dp1[N],dp2[N],dp3[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    #ifdef EVAH
        //freopen(ipf,"r",stdin);
        //openFile(ipf);
        //closeConsole;
        //freopen(opf,"w",stdout);
    #endif

    LL n;
    cin >> n;
    vector<LL> one(n),two(n),three(n);
    For(0,n) cin >> one[i] >> two[i] >> three[i];
    dp1[0]=one[0],dp2[0]=two[0],dp3[0]=three[0];
    For(1,n) {
        dp1[i] = one[i]+max(dp2[i-1],dp3[i-1]);
        dp2[i] = two[i]+max(dp1[i-1],dp3[i-1]);
        dp3[i] = three[i]+max(dp1[i-1],dp2[i-1]);
    }
    cout << max(dp1[n-1],max(dp2[n-1],dp3[n-1])) << "\n";

    #ifdef EVAH
        //openFile(opf);
        //Sleep(3000);
        //closeP("notepad.exe");
        //closeConsole;
    #endif
}


Measured memory_bytes: 7916
#include<iostream>
#include<cmath>

using namespace std;

int main () {

    int n;          // 学生の人数
    int s[1000];    // 得点, Score

    double m;       // 得点の平均

    double a2;      // 分散 a^2
    double a;       // 標準偏差 a

    while (1) {

        cin >> n;
        if (n == 0) {
            break;
        }

        m = 0;

        for (int i = 0; i < n; i++) {
            cin >> s[i];
            m += s[i];
        }

        m /= n;

        a2 = 0;

        for (int i = 0; i < n; i++) {
            a2 += pow(s[i] - m, 2) / n;
        }

        a = sqrt(a2);

        cout << a << endl;

    }    

    return 0;
}


Measured memory_bytes: 3296
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sstream> //C++
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)

//scanf("%d",&x);
//printf("%d",x);
//for(i=0;i<N;i++){  }
//if( == ){  }else{  }
//while( ){  }

/*
int N, i;
int H[100];
scanf("%d", &N);
for (i = 0; i < N; i++) scanf("%s", &H[i]);
*/




int main()
{
	int n, m;
	cin >> n >> m;

	vector <int> a;

	int x,i;

	rep(i, 0, m) {
		cin >> x;
		a.push_back(x);
	}


	int sum = 0;
	for (i = 0; i < m; i++) {
		sum += a[i];
	}

	if (sum > n) {
		cout << "-1";
		return 0;
	}

	else cout << n - sum;

}




Measured memory_bytes: 3660
import itertools
N = int(input())
data_xy = [[ int(x) for x in input().split(" ")] for z in range(N)]
data_road = list(itertools.permutations(range(1,N+1), N))
sum_dis = float(0)
for i in data_road:
    for j in range(N-1):
        sum_dis += ((data_xy[i[j+1]-1][0] - data_xy[i[j]-1][0])**2 + (data_xy[i[j+1]-1][1] - data_xy[i[j]-1][1])**2)**0.5
mean_sum = sum_dis / len(data_road)
print('{:.10f}'.format(mean_sum))

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

d = 2
ans = 0
while d * d <= n:
    if (n % d != 0):
        d += 1
        continue
    z = d
    while n % z == 0:
        n //= z
        z *= d
        ans += 1

    while n % d == 0:
        # 残りかすを除去
        n //= d

if (n != 1):
    ans += 1

print(ans)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
struct node
{
	int t;
	int x;
	int y;
}a[100005];
int main()
{
	int n;
	cin>>n;
	a[0].t=0;
	a[0].x=0;
	a[0].y=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].t>>a[i].x>>a[i].y;
	}
	for(int i=1;i<=n;i++)
	{
		if((fabs(a[i].x-a[i-1].x)+fabs(a[i].y-a[i-1].y))>fabs(a[i].t-a[i-1].t))
		{
			cout<<"No";
			return 0;
		}
		if(int(fabs(a[i].x-a[i-1].x)+fabs(a[i].y-a[i-1].y))%2!=int(fabs(a[i].t-a[i-1].t))%2)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int t;
    cin>>t;
    int ac=0,wa=0,tle=0,re=0;
    while(t--){
    string s;
    cin>>s;
    if(s=="AC")
    {
    ac++;
    }
    else if(s=="WA"){
        wa++;
    
        }
    else if(s=="TLE"){
        tle++;
        }
    else if(s=="RE")
        {
        re++;
        }
        
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;


    
}


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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H, W;
    cin >> H >> W;

    char c[H][W];
    REP(i, H) REP(j, W) cin >> c[i][j];

    vi dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
    REP(i, H) REP(j, W) {
        if (c[i][j] == '.') continue;
        bool f = false;
        REP(k, 4) {
            int y = i + dy[k], x = j + dx[k];
            if (x < 0 || x >= W || y < 0 || y >= H) continue;
            if (c[i][j] == c[y][x]) {
                f = true;
            }
        }

        if (!f) {
            print("No");
            return 0;
        }
    }

    print("Yes");



}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  for(int i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for(int i = 0; i < M-1; i++) {
    a.at(i+1) = max(a.at(i),a.at(i+1));
    b.at(i+1) = min(b.at(i),b.at(i+1));
  }
  
  int ans = b.at(M-1) - a.at(M-1) +1;
  if (ans <= 0) {
    ans = 0;
  }
  
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;
const int N=2e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0) continue;
        ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
};
typedef struct node *Node;
Node root;
void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}
void inorder(Node x){
  if(x!=NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}
void preorder(Node x){
  if(x!=NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}
int main(){
  int n,i,x;
  char c[20];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(c[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
char s[20];
int main() {
    scanf("%s",s);
    int n=strlen(s),flg=0;
    for(int i=1;i<n;i++) if(s[i]!='9') flg=1;
    cout<<s[0]-'0'-flg+9*(n-1);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

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

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10,mod = 1e9 + 7;

int a[N],b[N],Hasha[N],Hashb[N],dp[N];

struct node {
	int x,y;
	bool operator < (const node &rhs) const {
		return x == rhs.x ? y < rhs.y : x < rhs.x;
	}
	bool operator == (const node &rhs) const {
		return x == rhs.x && y == rhs.y;
	}
}Point[N];

struct BIT {
	int Sum[N];
	inline int lowbit(int x) { return x & (-x); }
	inline void Modify(int pos,int val) {
		for(;pos <= N - 5;pos += lowbit(pos)) Sum[pos] = (Sum[pos] + val) % mod;
	}
	inline int Query(int pos) {
		int ans = 0;
		for(;pos;pos -= lowbit(pos)) ans = (ans + Sum[pos]) % mod;
		return ans;
	}
}T;

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

int main() {

	int n = read(),m = read(),cnt = 0;
	For(i,1,n) a[i] = read();
	For(i,1,m) b[i] = read();
	For(i,1,n) {
		int val = lower_bound(b + 1,b + m + 1,a[i]) - b;
		int L = b[val - 1],R = b[val];
		if(!L || !R) continue;
		Point[++cnt] = (node){a[i] - L,R - a[i]};
		Hasha[cnt] = a[i] - L,Hashb[cnt] = R - a[i];
	}

	Point[++cnt] = (node){0,0};
	Hasha[cnt] = Hashb[cnt] = 0;
	Point[++cnt] = (node){INF,INF};
	Hasha[cnt] = Hashb[cnt] = INF;

	sort(Point + 1,Point + cnt + 1);
	sort(Hasha + 1,Hasha + cnt + 1);
	sort(Hashb + 1,Hashb + cnt + 1);
	int tota = unique(Hasha + 1,Hasha + cnt + 1) - Hasha - 1;
	int totb = unique(Hashb + 1,Hashb + cnt + 1) - Hashb - 1;

	For(i,1,cnt) {
		Point[i].x = lower_bound(Hasha + 1,Hasha + tota + 1,Point[i].x) - Hasha;
		Point[i].y = lower_bound(Hashb + 1,Hashb + totb + 1,Point[i].y) - Hashb;
	}

	dp[1] = 1,T.Modify(1,1);
	int L = 2;
	For(i,2,tota) {
		int R = L - 1;
		while(R < cnt && Point[R + 1].x == i) R++;
		For(j,L,R) dp[j] = T.Query(Point[j].y - 1);
		For(j,L,R) {
			if(Point[j] == Point[j - 1]) continue;
			T.Modify(Point[j].y,dp[j]);
		}
		L = R + 1;
	}

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

Measured memory_bytes: 3072
n = int(input())
a,b,c = [0]*n,[0]*n,[0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())

dp = [[0]*3 for _ in range(n)] #dp[i][j] i~n j~2
dp[0] = [a[0],b[0],c[0]] #初期値代入
for i in range(n-1):
    #print()
    dp[i+1][0] = max(dp[i+1][0], dp[i][1]+a[i+1], dp[i][2]+a[i+1])
    dp[i+1][1] = max(dp[i+1][1], dp[i][0]+b[i+1], dp[i][2]+b[i+1])
    dp[i+1][2] = max(dp[i+1][2], dp[i][0]+c[i+1], dp[i][1]+c[i+1])
    
    #for day in dp:
        #print(*day)
print(max(dp[-1]))

Measured memory_bytes: 34616
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var N int
var M int

type Shop struct {
	price  int64
	volume int64
}

type Shops []Shop

func (s Shops) Len() int { return len(s) }
func (s Shops) Less(i, j int) bool {
	return s[i].price < s[j].price
}

func (s Shops) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

func main() {
	N = nextInt()
	M = nextInt()
	var shops Shops
	for i := 0; i < N; i++ {
		s := new(Shop)
		s.price = nextInt64()
		s.volume = nextInt64()
		shops = append(shops, *s)
	}
	// sort.Slice(Shops[:], func(i, j int) bool {
	// 	return Shops[i].price < Shops[j].price
	// })
	sort.Sort(&shops)
	total := int64(0)
	more := int64(M)
	for i := 0; i < N; i++ {
		if shops[i].volume >= more {
			total += more * shops[i].price
			break
		} else {
			total += shops[i].volume * shops[i].price
			more -= shops[i].volume
		}
	}
	fmt.Printf("%v", total)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextInts64(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;

int main()
{
    fastio;
  	int n,k,sum=0;
  	cin>>n>>k;
  	int a[n];
  	for(int i=0;i<n;i++)
      cin>>a[i];
  	sort(a,a+n);
     for(int i=0;i<k;i++)
       sum+=a[i];
 	cout<<sum;
}

Measured memory_bytes: 3688