akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    exawizards2019b()
}

fun exawizards2019b() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val answer = if (s.count { it == 'R' } > n / 2) "Yes" else "No"

    println(answer)
}


Measured memory_bytes: 33668
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int main()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    for(int ctr1=0;ctr1<n;ctr1++){
        bool ok=true;
        for(int ctr2=ctr1;ctr2<n;ctr2++){
            if(a[ctr2]!=b[ctr2-ctr1])
                ok=false;
        }
        if(ok){
            cout<<ctr1+n;
            return 0;
        }
    }
    cout<<2*n;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;

int main() {
    ll N, K, Q;
    cin >> N >> K >> Q;

    vector<ll> points(N, K - Q);
    REP(i, Q) {
        ll Ai;
        cin >> Ai;
        ++points[Ai - 1];
    }

    REP(i, N) {
        if(points[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4016
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, K, Q;

long long int num[10000];

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++)cin >> num[i];
	sort(num, num + N);
	cout << num[N - 1] - num[0] << endl;
	return 0;
}

Measured memory_bytes: 256
win = [[0,1,2,],[3,4,5,],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

while line = gets
s = line.chomp.split("")
flag = "d"
win.each do |a,b,c|
  if s[a] != "s" && s[a] == s[b] && s[b] == s[c]
    flag = s[a]
  end
end
puts flag
end


Measured memory_bytes: 6868
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

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

    int n, k;
    cin >> n >> k;
    V<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    V<bool> mi(n - k + 1), ma(n - k + 1);
    set<int> st;
    for (int i = 0; i < k; i++) st.insert(a[i]);
    for (int l = 0; l <= n - k; l++) {
        mi[l] = (a[l] == *st.begin());
        ma[l] = (a[l + k - 1] == *st.rbegin());
        if (l == n - k) break;
        st.erase(a[l]);
        st.insert(a[l + k]);
    }
    dbg(mi);
    dbg(ma);
    int ans = n - k + 1;
    bool same = false;
    int cnt = 0;
    for (int i = 0; i < k - 1; i++) {
        if (a[i] > a[i + 1]) cnt++;
    }
    for (int l = 0; l <= n - k; l++) {
        if (cnt == 0) {
            //sorted
            dbg(l);
            if (mi[l] && ma[l]) {
                same = true;
                ans--;
                mi[l] = ma[l] = false;
            }
        }
        if (l == n - k) break;
        if (a[l] > a[l + 1]) cnt--;
        if (a[l + k - 1] > a[l + k]) cnt++;
    }
    if (same) ans++;
    for (int l = 0; l < n - k; l++) {
        if (mi[l] && ma[l + 1]) ans--;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

    int n;
    cin >> n;

    if(n <= 999)
        cout << "ABC";
    else
        cout << "ABD";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int>pii;
int main()
{
	int num;
	scanf("%d", &num);
	int ban = num;
	if (num % 2 == 0)ban++;
	vector<pii>v;
	for (int i = 1; i <= num; i++)for (int j = i + 1; j <= num; j++)if (i + j != ban)v.push_back(make_pair(i, j));
	printf("%d\n", v.size());
	for (int i = 0; i < v.size(); i++)printf("%d %d\n", v[i].first, v[i].second);
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
//        long readhp = long.Parse(ReadLine());
        string[] reader = ReadLine().Split(' ');
        int monsterhp = int.Parse(reader[0]);
        int magicnum = int.Parse(reader[1]);
//        string[] readerhp = ReadLine().Split(' ');
//        long total = 0;
//        int leng = readerhp.Length;
        int[,] map = new int[magicnum+10,monsterhp+10];
        for(int i=0;i<=monsterhp;i++){
            map[0,i] = 1000000000;
        }
        for(int i=1;i<=magicnum;i++){
            string[] reader2 = ReadLine().Split(' ');
            int magicdam = int.Parse(reader2[0]);
            int magicuse = int.Parse(reader2[1]);
            
            for(int j=1;j<=monsterhp;j++){
                if(j <= magicdam){
                    map[i,j] = Min(map[i-1,j],magicuse);
                }else{
                    map[i,j] = Min(map[i-1,j],map[i,j-magicdam]+magicuse);
                }
            }
        }
        /*for(int i=0;i<=magicnum;i++){
            for(int j=0;j<=monsterhp;j++){
                Write(map[i,j]);
                Write(" ");
            }
            WriteLine();
        }*/
        WriteLine(map[magicnum,monsterhp]);
    }
}

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

using namespace std;

#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;

const int mn=1e5+5;
const int mm=1e6+5;

int n,m;
int cnt;

struct edge{
    int to,dist;
};

vector<edge> g[mm];
int d[mm];
unordered_map<int,int> h[mn];

struct node{
    int id,dist;
    bool operator < (const node &p) const{
        return dist>p.dist;
    }
};

priority_queue<node> q;
void dijk(){
    memset(d,0x3c,sizeof d);
    q.push(node{1,d[1]=0});
    while(!q.empty()){
        node u=q.top();q.pop();
        if (d[u.id]<u.dist) continue;
        for(auto &e:g[u.id]){
            if (d[e.to]>u.dist+e.dist){
                q.push(node{e.to,d[e.to]=u.dist+e.dist});
            }
        }
    }
}

int main() {
#ifdef LOCAL
    freopen("../1.txt","r",stdin);
#endif
    scanf("%d%d",&n,&m);
    cnt=n;
    for(int i=1;i<=m;i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        if (h[u].find(w)==h[u].end()){
            h[u][w]=++cnt;
            g[u].pb(edge{cnt,1});
            g[cnt].pb(edge{u,1});
        }
        u=h[u][w];
        if (h[v].find(w)==h[v].end()){
            h[v][w]=++cnt;
            g[v].pb(edge{cnt,1});
            g[cnt].pb(edge{v,1});
        };
        v=h[v][w];
        g[u].pb(edge{v,0});
        g[v].pb(edge{u,0});
    }
    dijk();
    if (d[n]>1e9) d[n]=-2;
    printf("%d\n",d[n]/2);
    return 0;
}

Measured memory_bytes: 71292
#include <stdio.h>

int Month(int);
void Printng(int);

main(){
  int month, day, daymonth, allday, week;

  while(1){
    scanf("%d %d", &month, &day);
    if(month == 0) break;
    daymonth = Month(month);
    allday = daymonth + day;
    week = allday % 7;

    Printng(week);
  }
  return 0;
}

int Month(int n){
  int i, day, sum=0;

  for(i=1; i<n; i++){
    switch (i) {
    case 2:
      day = 29;
      break;
    case 4:
    case 6:
    case 9:
    case 11:
      day = 30;
      break;
    default:
      day = 31;
      break;
    }
    sum += day;
  }
  return sum;
}

void Printng(int n){
  switch (n) {
  case 1:
    printf("Thursday\n");
    break;
  case 2:
    printf("Friday\n");
    break;
  case 3:
    printf("Saturday\n");
    break;
  case 4:
    printf("Sunday\n");
    break;
  case 5:
    printf("Monday\n");
    break;
  case 6:
    printf("Tuesday\n");
    break;
  default:
    printf("Wednesday\n");
    break;
  }
}

Measured memory_bytes: 0
import copy
H, W, K = map(int,input().split())
ls = [list(input()) for i in range(H)]
ans = 0
for i in range(2**H):
  for j in range(2**W):
    A = copy.deepcopy(ls)
    B = 0
    for a in range(H):
      if (i >> a) & 1 == 1:
        for b in range(W):
          A[a][b] = "$"
    for c in range(W):
      if (j >> c) & 1 == 1:
        for d in range(H):
          A[d][c] = "$"
    for k in range(H):
      for l in range(W):
        if A[k][l] == "#":
          B += 1
    if B == K:
      ans += 1
print(ans) 

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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

int n;
char s[1000005];
char t[1000005];

bool can(int h) {
    int j = 0;
    deque<int> kk;
    int delta = 0;
    for (int i = 0; i < n; ) {
        int ei = i;
        while (ei < n && t[ei] == t[i]) ei++;
        while (j <= i) {
            if (s[j] != t[i]) {
                j++; continue;
            }
            if (sz(kk) && kk.front()+delta < j) {
                kk.pop_front();
                continue;
            }
            if (sz(kk) >= h) {
                j++; continue;
            }
            break;
        }
        if (j > i) return false;
        delta++;
        kk.push_back(ei-1-delta);
        i = ei;
    }
    return true;
}

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

    if (strcmp(s,t) == 0) {
        printf("0\n");
        return 0;
    }

    int st = 1, en = 1000005, bst = -1;
    while (st <= en) {
        int m = (st+en)/2;
        if (can(m)) {
            bst = m;
            en = m-1;
        } else {
            st = m+1;
        }
    }
    printf("%d\n", bst);
}



Measured memory_bytes: 6280
#include<stdio.h>
int i,j,ans;
int main(){
  for (i=1; i<10; i+=1) {
    for (j=1; j<10; j+=1) {
      ans = i*j;
      printf("%dx%d=%d\n", i, j, ans);
    }
  }
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define N 200005

int factorial[N];
  int modexp(int x, int y)
{
	int mod = MOD,res = 1;
    x = (x % mod + mod) % mod;
    while(y)
    {
        if(y & 1)res = (res*x) % mod;
        y >>= 1;
        x = ((x%mod)*(x%mod)) % mod;
    }
    return res; 
}
int modInverse(int x)
{
	return modexp(x,MOD-2)%MOD;
}
 
int choose(int n,int r)
{
	int ans = factorial[n]%MOD;
  	ans = ((ans%MOD)*(modInverse(factorial[r])%MOD))%MOD;
  ans = ((ans%MOD)*(modInverse(factorial[n-r])%MOD))%MOD;
  return ans;
}


int32_t main()
{
  
  factorial[0] = 1;
  
  for(int i = 1; i < N; i++)
  {
   factorial[i] = ((factorial[i-1]%MOD)*(i%MOD))%MOD;
  }
  
	int n,k;
  	cin >> n >> k;
  k = min(n-1,k);
  
  int ans = 0;
  
  for(int i = 0; i <=k; i++)
  {
 	ans =( ans%MOD +  ((choose(n,i)%MOD)*(choose(n-1,i)%MOD))%MOD)%MOD;
    
  }
  
  cout << ans;
  
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	reverse(v.begin(), v.end());
	for (int i = 0; i < n; i++)
		if (i != n - 1)
			cout << v[i] << " ";
		else
			cout << v[i] << endl;
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

    priority_queue<int> aque;
    for (int i = 0; i < n; i++) {
        aque.push(a[i]);
    }

    for (int i = 0; i < m; i++) {
        int p = aque.top();
        p /= 2;
        aque.pop();
        aque.push(p);
    }

    long s = 0;
    for (int i = 0; i < n; i++) {
        s += aque.top();
        aque.pop();
    }

    cout << s << endl;
}


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

#define IO  ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define endl '\n'
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int M=1e5+5;

int main()
{
    IO
    int n;
    cin>>n;
    int a[n+5],b[n+5],c[n+5];
    ll ans=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>c[i];
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    for(int i=0;i<n;i++) {
        int l=0,h=n-1,mid;
        ll pos=-1,pos2=-1;
        while(l<=h){
            mid=(l+h)/2;
            if(a[mid]<b[i]){
                pos=mid;
                l=mid+1;
            }
            else h=mid-1;
        }
        pos2=upper_bound(c,c+n,b[i])-c;
        if(pos!=-1&&pos2!=n){
            ans+=((pos+1)*(n-pos2));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
#define INF 105

int sx,sy,tx,ty;

char side(int x)
{
    if(x==1) return 'R';
    if(x==2) return 'U';
    if(x==3) return 'L';
    if(x==4) return 'D';
}

void output(int a,int b,int c,int d)
{
    for(int i=0;i<abs(tx-sx);i++)
    {
        cout << side(a);
    }
    for(int i=0;i<abs(ty-sy);i++)
    {
        cout << side(b);
    }
    for(int i=0;i<abs(tx-sx);i++)
    {
        cout << side(c);
    }
    for(int i=0;i<abs(ty-sy);i++)
    {
        cout << side(d);
    }
    cout << side(d);
    for(int i=0;i<abs(tx-sx)+1;i++)
    {
        cout << side(a);
    }
    for(int i=0;i<abs(ty-sy)+1;i++)
    {
        cout << side(b);
    }
    cout << side(c);
    cout << side(b);
    for(int i=0;i<abs(tx-sx)+1;i++)
    {
        cout << side(c);
    }
    for(int i=0;i<abs(ty-sy)+1;i++)
    {
        cout << side(d);
    }
    cout << side(a) << endl;
}

void output2(int a,int b,int c,int d)
{
    for(int i=0;i<abs(tx-sx);i++)
    {
        cout << side(a);
    }
    cout << side(b);
    for(int i=0;i<abs(tx-sx);i++)
    {
        cout << side(c);
    }
    cout << side(d);
    cout << side(d);
    for(int i=0;i<abs(tx-sx);i++)
    {
        cout << side(a);
    }
    cout << side(b) << side(a) << side(b) << side(b);
    for(int i=0;i<abs(tx-sx)+2;i++)
    {
        cout << side(c);
    }
    cout << side(d) << side(d) << side(a) << endl;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	if(sx<tx && sy<ty)
	{
        output(1,2,3,4);
	}else
	if(sx<tx && sy>ty)
	{
        output(1,4,3,2);
	}else
	if(sx>tx && sy<ty)
	{
        output(3,2,1,4);
	}else
	if(sx>tx && sy>ty)
	{
        output(3,4,1,2);
	}else
	if(sx<tx && sy==ty)
	{
        output2(1,2,3,4);
	}else
	if(sx>tx && sy==ty)
	{
        output2(3,2,1,4);
	}else
	if(sx==tx && sy<ty)
	{
        sx=sy;
        tx=ty;
        output2(2,3,4,1);
	}else
	if(sx==tx && sy>ty)
	{
        sx=sy;
        tx=ty;
        output2(4,3,2,1);
	}
}


Measured memory_bytes: 384
from heapq import heapify, heappush as hpush, heappop as hpop
def dijkstra(n, E, i0=0):
    h = [[0, i0]]
    D = [-1] * n
    done = [0] * n
    D[i0] = 0
    
    while h:
        d, i = hpop(h)
        done[i] = 1
        for j, w in E[i]:
            nd = d + w
            if D[j] < 0 or D[j] >= nd:
                if done[j] == 0:
                    hpush(h, [nd, j])
                    D[j] = nd
    return D

N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]

M = 51
X = [[] for _ in range(M)]
for i in range(1, M):
    for j in range(1, i+1):
        X[i].append([i%j, 2**j])

def chk(S):
    M = 51
    X = [[] for _ in range(M)]
    for j in S:
        for i in range(j, M):
            X[i].append([i%j, 2**j])
    DI = []
    for i in range(M):
        DI.append(dijkstra(M, X, i))
    for i in range(N):
        if DI[A[i]][B[i]] < 0:
            return 0
    return 1

L1 = [i for i in range(1, 51)]
L2 = []
if chk(L1) == 0:
    print(-1)
else:
    while L1:
        while True:
            if chk(L1 + L2):
                if len(L1) == 0:
                    break
                L1.pop()
            else:
                L2.append(L1[-1]+1 if L1 else 1)
                L1 = [i for i in range(1, L2[-1])]
                break
        if len(L1) == 0:
            break

    print(sum([1<<l for l in L2]))


Measured memory_bytes: 3572
x1, y1, x2, y2 = map(int, input().split())
dx = x2 - x1
dy = y2 - y1
x3 = x2 - dy
y3 = y2 + dx
x4 = x1 - dy
y4 = y1 + dx
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll H,W,l;
	cin >> H >> W;
	vector<vector<int>> a(H,vector<int>(W));
	for (ll i = 0;i < H;i++){
		for(ll j= 0;j < W;j++){
			cin >> l;
			a[i][j] = l;
		}
	}
	ll counter = 0;
	vector<P> in;
	vector<P> out;
	for (ll i = 0;i < H;i++){
		for(ll j = 0;j < W - 1;j++){
			if (a[i][j] % 2 == 1){
				a[i][j]--;
				a[i][j+1]++;
				in.pb(mp(i,j));
				out.pb(mp(i,j+1));
				counter++;
			}
		}
	}
	for (ll i = 0;i < H - 1;i++){
		if (a[i][W - 1] % 2 == 1){
				a[i][W - 1]--;
				a[i + 1][W - 1]++;
				in.pb(mp(i,W - 1));
				out.pb(mp(i+1,W - 1));
				counter++;
		}
	}
	cout << counter <<endl;
	for (ll i = 0;i < counter;i++){
		cout << in[i].fs + 1 << ' ' << in[i].sc + 1 << ' ' <<out[i].fs + 1 << ' ' << out[i].sc + 1 <<endl;
	}
	return 0;
}

Measured memory_bytes: 7268
mod = 10**9 + 7
def C():
    N = int(input())
    ans = 10**N - 2*9**N + 8**N
    print(ans%mod)
def A():
    N = int(input())
    if( N == 0):
        print(1)
    else:
        print(0)
def B():
    a,b,c,d = map(int,input().split())
    print(max(a*c,a*d,b*c,b*d))

def func(x,y):
    return [x-y,x+y]
def E():
    N = int(input())
    points = [list(map(int,input().split())) for _ in range(N)]
    #print(points)
    d0list = [func(*p)[0] for p in points]
    d1list = [func(*p)[1] for p in points]
    d0Max = max(d0list) - min(d0list)
    d1Max = max(d1list) - min(d1list)
    print(max(d0Max,d1Max))
E()


Measured memory_bytes: 61416
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY =1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra() {
	int minv;
	int d[MAX], color[MAX];
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;
	while (1) {
		minv = INFTY;
		int u = -1;
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK&&M[u][v] != INFTY) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = INFTY;
		}
	}

	int k, c, u, v;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}

	dijkstra();

    return 0;
}

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

int dist[500][500],n;
long long ans;
queue<int>q;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>dist[i][j];
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			int f=1;
			for(int k=0;k<n;k++)
			{
				if(k==i || k==j)
					continue;
				if(dist[i][k]+dist[k][j]<dist[i][j])
				{
					cout<<-1;
					return 0;
				}
				if(dist[i][k]+dist[k][j]==dist[i][j])
				{
					f=0;
					break;
				}
			}
			if(f)
				ans+=dist[i][j];
		}
	cout<<ans;
}

Measured memory_bytes: 896
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<char, ll> ump;
typedef pair<ll, ll> P;

ump mp;

void solve() {
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        string w;
        cin >> w;
        rep(i, w.size()) mp[w[i]]++;
        each(m, mp) {
            if (m.second % 2 != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int n;
  cin >> n;
  string s;
  cin >> s;
  long int r = 0;
  long int g = 0;
  long int b = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R') r++;
    if(s[i] == 'G') g++;
    if(s[i] == 'B') b++;
  }
  long int sum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 1; i+j+j < n; j++){
      if((s[i]^s[i+j]^s[i+j+j])==('R'^'G'^'B'))sum++;
    }
  }
  long int ans = r*g*b - sum;
  cout << ans << endl;
}

Measured memory_bytes: 3636
using System;
using System.Linq;

namespace ABC127
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] n = s.Select(x => int.Parse(x)).ToArray();

            if (n[0] >= 13) Console.WriteLine(n[1]);
            if (6 <= n[0] && n[0] <= 12) Console.WriteLine(n[1] * 0.5);
            if (n[0] <= 5) Console.WriteLine(0);
        }
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if (S.at(K-1) == 'A') S.at(K-1) = 'a';
  if (S.at(K-1) == 'B') S.at(K-1) = 'b';
  if (S.at(K-1) == 'C') S.at(K-1) = 'c';
  cout << S << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  auto isOk = [&] (int kinds) {
    int len = 0;
    vector<pair<int, int>> s;
    for (int i = 0; i < n; i++) {
      if (a[i] > len) {
        s.emplace_back(0, a[i] - len);
        len = a[i];
        continue;
      }
      while (len > a[i]) {
        int pop = min(s.back().second, len - a[i]);
        s.back().second -= pop;
        if (s.back().second == 0) s.pop_back();
        len -= pop;
      }
      while (!s.empty() && s.back().first == kinds - 1) {
        len -= s.back().second;
        s.pop_back();
      }
      if (len == 0) {
        return false;
      }
      if (s.back().second == 1) {
        int k = s.back().first;
        s.pop_back();
        s.emplace_back(k + 1, 1);
      } else {
        int k = s.back().first;
        int l = s.back().second;
        s.pop_back();
        s.emplace_back(k, l - 1);
        s.emplace_back(k + 1, 1);
      }
      if (len < a[i]) s.emplace_back(0, a[i] - len);
      len = a[i];
    }
    return true;
  };
  int low = 0, high = n;
  while (high - low > 1) {
    int middle = (low + high) >> 1;
    if (isOk(middle)) high = middle;
    else low = middle;
  }
  cout << high << endl;
  return 0;
}

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

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        public static void swap(ref long x, ref long y)
        {
            var tmp = x;
            x = y;
            y = tmp;
        }


        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var input = Reads();
            var h = input[0];
            var w = input[1];
            var ch = new char[h][];
            long ans = 0;
            for (int l = 0; l < h; l++)
            {
                ch[l] = Console.ReadLine().ToCharArray();
                for (int i = 0; i < w; i++)
                {
                    if (ch[l][i] == '#') ans++;
                }
                
            }
            
            

            Console.WriteLine(ans==h+w-1 ? "Possible" : "Impossible");

        Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
X, Y = map(int, input().split())

def f(n):
  if n == 3:
    return 100000
  elif n == 2:
    return 200000
  elif n == 1:
    return 300000
  else:
    return 0

result = f(X) + f(Y)
if X == 1 and Y == 1:
  result += 400000
print(result)


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

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

  vector<int> ans(n);
  rep(ri, 2) {
    int cnt = 0;
    rep(i, n) {
      if (s[i] == 'R')
        cnt++;
      else {
        ans[i] += cnt / 2;
        ans[i - 1] += (cnt + 1) / 2;
        cnt = 0;
      }
    }

    reverse(ans.begin(), ans.end());
    reverse(s.begin(), s.end());
    rep(i, n) s[i] = (s[i] == 'L' ? 'R' : 'L');
  }

  rep(i, n) printf("%d%c", ans[i], (i == n - 1 ? '\n' : ' '));
  return 0;
}


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

using namespace std;

using Graph = vector<vector<int>>;

int TravelingSalesman(const Graph &g) {
    const int n = g.size(), INF = n * n * n;
    vector<vector<int>> dp(1 << n, vector<int>(n, INF));
    dp[1][0] = 0;

    for (int s = 1; s < 1 << n; ++s) {
        for (int cur = 0; cur < n; ++cur) {
            if (!(s >> cur & 1) || INF <= dp[s][cur]) continue;

            for (int dst = 0; dst < n; ++dst) {
                if (dst != cur && !(s >> dst & 1))
                    dp[s | 1 << dst][dst] = min(dp[s | 1 << dst][dst], dp[s][cur] + g[cur][dst]);
            }
        }
    }

    return *min_element(dp[(1 << n) - 1].begin(), dp[(1 << n) - 1].end());
}

const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};

int Distance(const auto &src, const auto &dst, const int h, const int w, const vector<string> &c) {
    vector<vector<int>> d(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    que.push(src);
    d[src.first][src.second] = 0;

    while (!que.empty()) {
        auto cur = que.front(); que.pop();

        for (int dir = 0; dir < 4; ++dir) {
            pair<int, int> nxt(cur.first + dr[dir], cur.second + dc[dir]);
            if (nxt.first < 0 || nxt.second < 0 || h <= nxt.first || w <= nxt.second
                || d[nxt.first][nxt.second] != -1 || c[nxt.first][nxt.second] == 'x')
                continue;
            d[nxt.first][nxt.second] = d[cur.first][cur.second] + 1;
            que.push(nxt);
        }
    }

    return d[dst.first][dst.second];
}

pair<bool, Graph> MakeGraph(const int w, const int h, const vector<string> &c) {
    vector<pair<int, int>> pos(1);
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j) {
            if (c[i][j] == 'o') pos[0] = make_pair(i, j);
            else if (c[i][j] == '*') pos.emplace_back(make_pair(i, j));
        }

    const int n = pos.size();
    Graph d(n, vector<int>(n));
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j) {
            int d_ij = Distance(pos[i], pos[j], h, w, c);
            if (d_ij == -1) return make_pair(true, d);
            d[i][j] = d[j][i] = d_ij;
        }

    return make_pair(false, d);
}

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

    int w, h;

    while (cin >> w >> h, (w != 0 || h != 0)) {
        vector<string> c(h);
        for (auto &x : c) cin >> x;

        auto res = MakeGraph(w, h, c);
        if (res.first) cout << -1 << '\n';
        else cout << TravelingSalesman(res.second) << '\n';
    }

    return 0;
}



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

int main() {
	int n; cin >> n;
	vector<int> x(n), y(n);
	REP(i, n) cin >> x[i] >> y[i];

	int maxi = 0;
	map<pair<int, int>, int> cnt;
	REP(i, n) REP(j, n) {
		if (i == j) continue ;
		int dx = x[i] - x[j];
		int dy = y[i] - y[j];
		maxi = max(maxi, ++cnt[make_pair(dx, dy)]);
	}
	cout << n - maxi << '\n';
	return 0;
}

Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<math.h>
using namespace std;

void a()
{
    string s,t;
    cin >> s >> t;
    if (t.substr(0,t.length()-1)==s)
    cout << "Yes";
    else cout << "No"; 

    return;
}
void b()
{
    return;
}
void c()
{
    return;
}
void d()
{
    return;
}
void e()
{
    return;
}
void f()
{
    return;
}
int main(void){
    a();
    //b();
    //c();
    //d();
    //e();
    //f();

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 2007, mod = 1e9 + 7;
int n, k;
int fac[N * N], invfac[N * N], inv[N * N], f[N][N];
int C(int n, int m) {
	return (LL) fac[n] * invfac[n - m] % mod * invfac[m] % mod;
}
void add(int &a, int b) { a += b; if(a >= mod) a -= mod;}
int main() {
#ifndef ONLINE_JUDGE
#endif
	n = gi(), k = gi();
	if(k == 1) return puts("1"), 0;
	inv[1] = fac[0] = invfac[0] = 1;
	rep(i, 1, n * k) {
		if(i ^ 1) inv[i] = (LL) (mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (LL) fac[i - 1] * i % mod;
		invfac[i] = (LL) invfac[i - 1] * inv[i] % mod;
	}
	rep(i, 1, n) {
		f[i][0] = 1;
		rep(j, 1, i) {
			add(f[i][j] ,f[i - 1][j]);
			add(f[i][j], (LL) f[i][j - 1] * C((n - i) + (n - j + 1) * (k - 1) - 1, k - 2) % mod * (n - j + 1) % mod);
		}
	}
	printf("%d\n", f[n][n]);
	return 0;
}

Measured memory_bytes: 62208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
#define MN 1600
struct P{int a,b,c,d;}p[MN+5];
ll z[MN+5];int s[MN+5],zn;
inline ll cal(const P&p){return 1LL*p.a*int(1e9)+p.b*int(1e6)+p.c*int(1e3)+p.d;}
inline int&find(const P&p)
{
	ll x=cal(p),t;
	t=lower_bound(z+1,z+zn+1,x)-z;
	return z[t]==x?s[t]:s[0];
}
inline void inc(P p,int x)
{
	find((P){p.a,p.b,p.c,p.d})+=x;
	find((P){p.d,p.a,p.b,p.c})+=x;
	find((P){p.c,p.d,p.a,p.b})+=x;
	find((P){p.b,p.c,p.d,p.a})+=x;
}
int main()
{
	int n,i,j;long long ss,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d%d%d%d",&p[i].a,&p[i].b,&p[i].c,&p[i].d);
		p[i+n]=(P){p[i].d,p[i].a,p[i].b,p[i].c};
		p[i+2*n]=(P){p[i].c,p[i].d,p[i].a,p[i].b};
		p[i+3*n]=(P){p[i].b,p[i].c,p[i].d,p[i].a};
	}
	for(i=1;i<=4*n;++i)z[i]=cal(p[i]);
	sort(z+1,z+4*n+1);zn=unique(z+1,z+4*n+1)-z-1;
	for(i=1;i<=n;++i)inc(p[i],1);
	for(i=1;i<=4*n;++i)for(j=i;j<=4*n;++j)if(i%n!=j%n)
	{
		inc(p[i],-1);inc(p[j],-1);
		P A=(P){p[j].b,p[i].a,p[i].d,p[j].c},
		  B=(P){p[j].b,p[j].a,p[i].b,p[i].a},
		  C=(P){p[i].b,p[j].a,p[j].d,p[i].c},
		  D=(P){p[j].d,p[j].c,p[i].d,p[i].c};
		ss=find(A);inc(A,-1);ss*=find(B);inc(B,-1);ss*=find(C);inc(C,-1);ans+=ss*find(D);
		inc(A,1);inc(B,1);inc(C,1);inc(p[i],1);inc(p[j],1);
	}
	printf("%lld",ans/12);
}

Measured memory_bytes: 256
//---------- begin union_find ----------
pub struct DSU {
    parent: Vec<u32>,
    size: Vec<u32>,
    stack: Vec<Option<(u32, u32)>>,
}

impl DSU {
    pub fn new(n: usize) -> DSU {
        assert!(n < std::u32::MAX as usize);
        let mut res = DSU {
            parent: vec![0; n],
            size: vec![1; n],
            stack: vec![],
        };
        res.init();
        res
    }
    pub fn init(&mut self) {
        self.stack.clear();
        for (i, (parent, size)) in self.parent.iter_mut().zip(self.size.iter_mut()).enumerate() {
            *parent = i as u32;
            *size = 1;
        }
    }
    pub fn root(&self, mut x: usize) -> usize {
        assert!(x < self.parent.len());
        while self.parent[x] != x as u32 {
            x = self.parent[x] as usize;
        }
        x
    }
    pub fn same(&self, x: usize, y: usize) -> bool {
        assert!(x < self.parent.len());
        assert!(y < self.parent.len());
        self.root(x) == self.root(y)
    }
    pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> {
        assert!(x < self.parent.len());
        assert!(y < self.parent.len());
        let mut x = self.root(x);
        let mut y = self.root(y);
        if x == y {
            self.stack.push(None);
            return None;
        }
        if (self.size[x], x) < (self.size[y], y) {
            std::mem::swap(&mut x, &mut y);
        }
        self.size[x] += self.size[y];
        self.parent[y] = x as u32;
        self.stack.push(Some((x as u32, y as u32)));
        Some((x, y))
    }
    pub fn parent(&self, x: usize) -> Option<usize> {
        assert!(x < self.parent.len());
        let p = self.parent[x];
        if p != x as u32 {
            Some(p as usize)
        } else {
            None
        }
    }
    pub fn size(&self, x: usize) -> usize {
        assert!(x < self.parent.len());
        let r = self.root(x);
        self.size[r] as usize
    }
    pub fn undo(&mut self) -> Option<(usize, usize)> {
        self.stack.pop().unwrap().map(|(x, y)| {
            let x = x as usize;
            let y = y as usize;
            self.size[x] -= self.size[y];
            self.parent[y] = y as u32;
            (x, y)
        })
    }
}
//---------- end union_find ----------

use proconio::*;
use proconio::marker::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        mut e: [(Usize1, Usize1, i64); n - 1],
    }
    e.sort_by_key(|e| -e.2);
    let mut u = DSU::new(n);
    let mut dp = vec![0; n];
    for (a, b, c) in e {
        let (a, b) = u.unite(a, b).unwrap();
        u.undo();
        dp[a] += u.size(b) as i64 * c;
        dp[b] += u.size(a) as i64 * c;
        dp[b] -= dp[a];
        u.unite(a, b);
    }
    for i in 0..n {
        let mut ans = dp[i];
        let mut pos = i;
        while let Some(p) = u.parent(pos) {
            ans += dp[p];
            pos = p;
        }
        println!("{}", ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 10120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	auto f = [&](ll a,ll b,ll n){
		return a + (b-a+1)/2;
	};
	ll n,a,b; cin >> n >> a >> b; a--,b--;
	if((b-a)%2==0){
		cout << (b-a)/2 << endl;
	}else{
		cout << min(f(a,b,n),f(n-1-b,n-1-a,n)) << endl;
	}
}


Measured memory_bytes: 256
import sys
import math
import itertools


# \n


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, WW = map(int, input().split())
    W = []
    V = []
    for i in range(N):
        w, v = map(int, input().split())
        W.append(w)
        V.append(v)

    dp = [[0] * (WW+1) for _ in range(N)]

    for i in range(N):
        w = W[i]
        v = V[i]
        for j in range(WW+1):
            if w<=j:
                dp[i][j] =max(dp[i-1][j],dp[i-1][j-w]+v)
            else:
                dp[i][j] =dp[i-1][j]

    print(max(dp[N-1]))


if __name__ == "__main__":
    main()


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    vector<ll> a;
    ll mini = numeric_limits<ll>::max();
    cin >> N;
    a.resize(N);
    rep(i, N) {
        ll temp;
        cin >> temp;
        a[i] = (i != 0LL ? a[i - 1] : 0LL) + temp; 
    }
    rep(i, N - 1) {
        ll sunuke = a[i];
        ll arai = a[N - 1] - sunuke;
        mini = min(mini, abs(sunuke - arai));
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(){
        int l = 0, s[11];
        while((s[l]=getchar()-'0')!='\n'-'0') l++;
        l--;

        long int ans = 0;
        for(int i=0; i<(1<<l); i++){
                long int opr = s[0];
                for(int j=0; j<l; j++){
                        if((i>>j)&1){
                                ans += opr;
                                opr = s[j+1];
                        }else{
                                opr *= 10;
                                opr += s[j+1];
                        }
                }
                ans += opr;
        }

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

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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int dp[101][101];
bool b[101][101];

int calc(int i, int j, int x, int y){
    if (b[i][j] && b[x][y]) return dp[x][y];
    return dp[x][y] + b[i][j];
}

void solve(){
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            char c;
            cin >> c;
            b[i][j] = (c == '#');
            if (i == 1) dp[i][j] = calc(i, j, i, j-1);
            else if (j == 1) dp[i][j] = calc(i, j, i-1, j);
            else {
                dp[i][j] = min(calc(i, j, i, j-1), calc(i, j, i-1, j));
            }
        }
    }
    cout << dp[n][m];
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
   // cin >> t;
    while (t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    a, b, c, d = map(int, readline().split())

    print(max(a * c, a * d, b * c, b * d))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61852
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll n;
  cin >> n;
  ll a[n], b[n], c[n];
  ll ans = 0;
  REP(i, n){
    cin >> a[i] >> b[i];
    ans += b[i];
    c[i] = a[i] + b[i];
  }
  SORT(c, n);
  REP(i, n){
    if(i % 2 == 0) ans -= c[n - 1 - i];
  }
  cout << -ans << endl;
  return 0;
}


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

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

int main()
{
    long long K, N;
    cin >> K >> N;
    vector<long long> A(N + 1);
    rep(i, N){
        cin >> A.at(i);
    }
    A.at(N) = K + A.at(0);
    long long sum = 0;
    long long max = -1;
    for (int i = 0; i < N;i++){
        long long len = A.at(i + 1) - A.at(i);
        sum += len;
        if(max < len){
            max = len;
        }
    }
    sum -= max;
    cout << sum << endl;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>

#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int r;
    cin >> r;
    cout << r*r;
}


Measured memory_bytes: 256
n = gets.to_i * 2

k = 1
k += 1 while k * (k - 1) < n

if k * (k - 1) != n
    puts "No"
    exit
end

puts "Yes", k

x = []
i = 0
k.times do |j|
    y = []
    (k-j-1).times {y << i += 1}
    puts "#{k-1} " + (x.map{|e| e.shift} + y) * " "
    x << y
end

Measured memory_bytes: 4604
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	double r, g;

	cin >> r >> g;


	cout << 2 * g - r << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A;
  int B, C, D = 0, E = 0;
  cin >> A;
  
  for(int YUNI =0;YUNI < A;YUNI++){
    cin >> B >> C;
    if(B == C){
      D ++;
    }
    else{
      D = 0;
    }
    if(D == 3){
      E = 1;
      break;
    }
  }
  if(E == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  //cout << D << endl;
}

Measured memory_bytes: 3588
# 今日の曜日を表す文字列 Sが与えられます。
# Sは SUN,MON,TUE,WED,THU,FRI,SAT のいずれかであり、
# それぞれ日曜日、月曜日、火曜日、水曜日、木曜日、金曜日、土曜日を表します。
# 次の日曜日 (あす以降) が何日後か求めてください。

# 標準入力から曜日（S）を取得する
input_weekday = input()

# 次の日曜日はあと何日後かを計算して出力する
result = 0
if input_weekday == 'SUN':
    result = 7
elif input_weekday == 'MON':
    result = 6
elif input_weekday == 'TUE':
    result = 5
elif input_weekday == 'WED':
    result = 4
elif input_weekday == 'THU':
    result = 3
elif input_weekday == 'FRI':
    result = 2
elif input_weekday == 'SAT':
    result = 1

print(result)


Measured memory_bytes: 8912