akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node u, int k){
  while((u != NIL) && (k != u->key)){
    if(k < u->key){
      u = u->left;
    }
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
}

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 u){
if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
if(u != NIL){
    printf(" %d",u->key);
    if(u->left != NIL)preorder(u->left);
    if(u->right != NIL)preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<stdio.h>

int main() {

	char s[1001];
	int i, flag[4], result;

	scanf("%s", s);

	for (i = 0; i < 4; i++) flag[i] = 0;
	for (i = 0; i < s[i] != '\0'; i++) {
		if (s[i] == 'N') flag[0] = 1;
		if (s[i] == 'W') flag[1] = 1;
		if (s[i] == 'S') flag[2] = 1;
		if (s[i] == 'E') flag[3] = 1;
	}

	result = 1;
	if (flag[0] != flag[2] || flag[1] != flag[3]) result = 0;

	if (result) printf("Yes\n");
	if (!result) printf("No\n");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

//lli gcd(lli a,lli b){
//    if(b>a){
//        swap(a,b);
//    }
//    if(a%b==0){
//        return b;
//    }
//    else{
//        return gcd(b,a%b);
//    }
//}

struct domino{
    lli i,j;
    lli n;
    string s,t;
    vector<string> vec;
    vector<lli> check;
    domino(){
        cin>>n>>s>>t;
        vec.push_back(s);
        vec.push_back(t);
        rep(i,0,58){
            check.push_back(0);
        }
    }
    
    lli num(char a){
        if(a-'a'>=0){
            return a-'a';
        }
        else{
            return 27+a-'A';
        }
    }
    
    void search(){
        lli sum=3;
        rep(i,0,n){
//            cout<<i+1<<"番目の文字に注目"<<endl;
            if(i==0){
                if(vec[0][i]!=vec[1][i]){
                    sum*=2;
                    i++;
                }
            }
            else{
                if(vec[0][i-1]==vec[1][i-1]){
                    sum*=2;
                    if(vec[0][i]!=vec[1][i]){
                        i++;
                    }
                }
                else{
                    if(vec[0][i]!=vec[1][i]){
                        sum*=3;
                        i++;
                    }
                }
            }
            sum%=N;
        }
        cout<<sum<<endl;
    }
};

int main(){
    lli i,j;
    domino dom;
    dom.search();
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
using namespace std;
int ar[1001],i=0;
void  convert10tob(int N, int b);
int main()
{
    int N,b,ar[1001],p;
    cin>>N;
    cin>>b;
    if (N != 0)
    {
        convert10tob(N, b);

    }
    else
        cout<<"0"<<endl;
    cout<<i;
}

void  convert10tob(int N, int b)
{
    int count=0;
     if (N == 0)
       return ;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
   ar[i] =(x < 0 ? x + (b * -1) : x);
   i++;
   return ;
}



Measured memory_bytes: 888
import numpy as np
from collections import Counter
N = int(input())
A = np.array(list(map(int, input().split())))
counters = Counter(np.cumsum(A))
ans = 0
for k, v in counters.items():
    ans += v * (v - 1) // 2
    if k == 0:
        ans += v
print(ans)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
	ll n;
	cin >> n;
	vector<vector<int>> grid(n, vector<int>(n, 0));
	rep(i, n) {
		rep(j, n) {
			cin >> grid[i][j];
		}
	}
	vector<vector<ll>> dp(n, vector<ll>(1LL << n, 0));

	for (int i = 0; i < n; i++) {
		if (grid[0][i]) {
			dp[0][1LL << i] = 1;
		}
	}
	for (int i = 1; i < n; i++) {
		for (ll state = 0; state < 1LL << n; state++) {
			if (__builtin_popcountll(state) != i ) {
				continue;
			}
			for (int j = 0; j < n; j++) {
				if (state & (1LL << j)) continue;
				if (grid[i][j]) {
					(dp[i][(1LL << j) | state] += dp[i - 1][state]) %= mod;
				}
			}
		}
	}
	cout << dp[n - 1][(1LL << n) - 1] << endl;
	return 0;
}
	

Measured memory_bytes: 363884
from math import gcd

K = int(input())
ans = 0
for a in range(1, K + 1):
    for b in range(a, K + 1):
        for c in range(b, K + 1):
            if a == b == c:
                n = 1
            elif a == b or b == c or c == a:
                n = 3
            else:
                n = 6
            ans += n * gcd(gcd(a, b), c)
print(ans)


Measured memory_bytes: 70536
#include<bits/stdc++.h>
using namespace std;
int a[2][101];
int sum1[105],sum2[105];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<2;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	for(int i=1;i<n;i++) a[0][i]=a[0][i-1]+a[0][i];
	for(int i=n-2;i>=0;i--) a[1][i]=a[1][i+1]+a[1][i];
	int ans=-1;
	for(int i=0;i<n;i++) ans=max(ans,a[0][i]+a[1][i]);
	cout<<ans; 
	return 0;
}


Measured memory_bytes: 3636
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7

B = [0]*60

for a in A:
    for i in range(60):
        B[i] += (a >> i) % 2

ans = 0
for i in range(60):
    ans += (B[i]*(N-B[i])) * (1 << i)
    ans %= MOD
print(ans)


Measured memory_bytes: 122996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

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

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;
    vector<bool> lazyFlag;
 
public:
    LazySegmentTree() {
        int sz = 100050;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, inf);
        lazy.resize(2*n-1, inf);
        lazyFlag.resize(2*n-1, false);
 
        for(int i=0; i<sz; i++) node[i+n-1] = inf;
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
 
    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = min(lazy[k], node[k]);
            if(r - l > 1) {
                chmin(lazy[k*2+1], lazy[k]);
                chmin(lazy[k*2+2], lazy[k]);
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
            lazy[k] = inf;
        }
    }
 
    void update(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }
 
    ll query(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return inf;
        if(a <= l && r <= b) return node[k];
        ll vl = query(a, b, 2*k+1, l, (l+r)/2);
        ll vr = query(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

struct edge{int u,v,cost;};
 
bool comp(const edge& e1,const edge& e2){
	return e1.v<e2.v;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<edge> g(m);
  rep(i,m){
    int l,r,c;
    cin>>l>>r>>c;
    l--,r--;
    g[i]={l,r,c};
  }
  sort(begin(g),end(g),comp);
  LazySegmentTree seg;
  seg.update(0,1,0);
  vector<ll> dp(n,inf);
  dp[0]=0;
  rep(i,m){
    int l=g[i].u,r=g[i].v,c=g[i].cost;
    dp[r]=min(dp[r],c+seg.query(l,r+1));
    seg.update(r,r+1,dp[r]);
  }
  if(dp[n-1]==inf) cout<<-1<<endl;
  else cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 6272
while True:
    h, w = map(int, input().split())
    if h == 0 & h == 0:
        break
    if w % 2 == 0:
        for i in range(h):
            if i % 2 == 0:
                print('#.' * (w // 2))
            else:
                print( '.#' * (w // 2))
        
    else:
        for i in range(h):
            if i % 2 == 0:
                print('#.' * (w // 2) +   '#')
            else:
                print('.#' * ( w // 2) + '.')
    print()


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,k,ans=0;
    cin >> n >> k;
    vector<long long>a(n);
    for(long long i=0;i<n;i++)
    cin >> a[i];
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(long long i=0;i<n;i++){
        if(i<k){
        a[i]=0;
        }
     ans+=a[i];
    }
    cout << ans;
    
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int max(const void *a, const void *b){return *(int*)b - *(int*)a;}

uint64_t a[13] = {0};
uint64_t b[13] = {0};
int main(void)
{
    b[0] = 1;
    while(1){
        char c;
        uint64_t f;

        scanf("%c",&c);
        if(c=='\n') break;

        for(int i=0;i<13;i++) a[i] = 0;
        if(c!='?')
        {
            f = c - '0';
            for(int i=0;i<13;i++)
            {
                a[((i*10)+f) % 13] = b[i];
                a[((i*10)+f) % 13] %= 1000000007;
            }
        }else{
            for(int j=0;j<=9;j++) for(int i=0;i<13;i++)
            {
                a[((i*10)+j) % 13] += b[i];
                a[((i*10)+j) % 13]%= 1000000007;
            }
        }
//        for(int i=0;i<13;i++) printf("%d:%ld %ld\n",i,a[i],b[i]);
        for(int i=0;i<13;i++) b[i] = a[i];
    }
    printf("%ld\n", a[5]);

    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
modulo = 10 ** 9 + 7
 
S = input()
 
def nleft(S, c):
    """各位置について，それより左の文字列に含まれる文字 c の総数.
       左に'?'が含まれるときは，それらに文字を入れて得られるすべての
       文字列に渡って，文字 c の個数を合計する. """
 
    # c の個数
    n = [0 for c in S]
    for i in range(1, len(S)):
        n[i] = n[i-1] + (1 if S[i-1] == c else 0)
 
    q = 0      # '?'の個数
    pow3q = 1  # 3 ** q
    for i in range(len(n)):
        if q > 0:
            n[i] *= pow3q         # ?の埋め方の数だけ増やす
            n[i] += pow3q1 * q    # ?に入る'C'の個数
            n[i] %= modulo
        if S[i] == '?':
            q += 1
            pow3q1 = pow3q
            pow3q  = pow3q * 3 % modulo
    return n
 
def nright(S, c):
    # c の個数
    n = [0 for c in S]
    for i in range(len(S) - 1, 0, -1):
        n[i-1] = n[i] + (1 if S[i] == c else 0)
 
    q = 0      # '?'の個数
    pow3q = 1  # 3 ** q
    for i in range(len(n) - 1, -1, -1):
        if q > 0:
            n[i] *= pow3q         # ?の埋め方の数だけ増やす
            n[i] += pow3q1 * q    # ?に入る'C'の個数
            n[i] %= modulo
        if S[i] == '?':
            q += 1
            pow3q1 = pow3q
            pow3q  = pow3q * 3 % modulo
    return n
 
 
left  = nleft (S, 'A')
right = nright(S, 'C')
 
# 各文字が'B'のときのABC数を計算
abc = 0
for i in range(0, len(S)):
    if S[i] in 'B?':
        abc += left[i] * right[i]
 
abc = int(abc) % modulo
print(abc)

Measured memory_bytes: 11124
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int[] Array = new int[N];
        int count = 0;
        int flg = 0;
      
        for(int i=0; i<N; i++){
          Array[i] = sc.nextInt();
        }
      
      
      while(flg < 1){
      	for(int j=0; j<N; j++){
          if(Array[j]%2 == 0){
            Array[j] /= 2;
            if(j == N-1){
              count++;
            }
          }else{
         	flg = 100;
            break;
          }
        }
      }
      
        System.out.println(count);
    }
}


Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main()
{
	for(int n,m;cin>>n,n;){
		int cx=10,cy=10;
		int grid[21][21]={};
		grid[cy][cx]=1;
		
		int xs[20],ys[20];
		for(int i=0;i<n;i++)
			cin>>xs[i]>>ys[i];
		cin>>m;
		for(int i=0;i<m;i++){
			char d; int len;
			cin>>d>>len;
			int dx=0,dy=0;
			if(d=='N') dx=0,dy=1;
			if(d=='E') dx=1,dy=0;
			if(d=='S') dx=0,dy=-1;
			if(d=='W') dx=-1,dy=0;
			for(int j=0;j<len;j++){
				cx+=dx,cy+=dy;
				grid[cy][cx]=1;
			}
		}
		int res=0;
		for(int i=0;i<n;i++)
			res+=grid[ys[i]][xs[i]];
		cout<<(res==n?"Yes":"No")<<endl;
	}
	
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int R,G,B,N;
int r,g,b;
int t;
ll cnt;
int main() {
    cin >> R >> G >> B >> N;
    for (int r=0;r<3001;r++) {
        for (int g=0;g<3001;g++) {
            t = N-(R*r+G*g);
            if(t>=0 && t%B == 0) cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ca=0,cb=0,cc=0;
	while (n--){
		int x;
		cin>>x;
		if (x<=a) ca++;
		else if (x>b) cc++;
		else cb++;
	}
	cout<<min(min(ca,cb),cc);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int k;
	cin >> k;

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

	ll mx = 2, mn = 2;
	for (int i = k - 1; i >= 0; i--) {
		if (mn % a[i] != 0) {
			mn = (mn / a[i] + 1) * a[i];
		}
		mx = (mx / a[i] + 1) * a[i] - 1;
	}

	if (mx <= mn) {
		cout << -1 << endl;
	} else {
		cout << mn << " " << mx << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FASTIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, n) for(int (i) = 0; (i) < (int)(n); ++(i))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main() {
	FASTIO;
	int x;
	cin >> x;
	cout << (x ? 0 : 1) << endl;
}

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

int main() {

string S,H,S2;
  cin>>S>>H;
  for(int i=2;i>=0;i--){
    S2.push_back(S.at(i));}
  if(S2==H){cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}

}



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

int convert(int x, int y, int r, int c)
{
    if(y == 0)
        return x;
    else if(x == r)
        return r + y;
    else if(y == c)
        return 2 * r + c - x;
    else if(x == 0)
        return 2 * (r + c) - y;
    else
        return -1;
}

int main()
{
    int r, c, n;
    cin >> r >> c >> n;
    vector<pair<int, int> > v;
    for(int i=0; i<n; ++i){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int a = convert(x1, y1, r, c);
        int b = convert(x2, y2, r, c);
        if(a != -1 && b != -1){
            v.push_back(make_pair(a, i));
            v.push_back(make_pair(b, i));
        }
    }

    int m = v.size();
    sort(v.begin(), v.end());
    vector<bool> check(n, false);
    stack<int> stk;
    for(int i=0; i<m; ++i){
        int k = v[i].second;
        if(check[k]){
            if(stk.top() != k){
                cout << "NO" << endl;
                return 0;
            }
            stk.pop();
        }
        else{
            check[k] = true;
            stk.push(k);
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>
#include<cassert>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX=101;
const int INF=1<<25;
int n,m,c,s,g;

//??????????????????0???????????????????????¨
vector<vector<vector<int>>> G(21,vector<vector<int>>(MAX,vector<int>(MAX,INF)));
//????????¨
int p[50];
int q[21][50];
int r[21][51];

int cal(int dist,int cam){
	int money=0;
	if(dist==INF) return INF;
	rep(i,50){
		if(q[cam][i] >= dist){
			if(i==0) money+=r[cam][i]*dist;
			else money+=(dist-q[cam][i-1])*r[cam][i]; //?¶?????????´???
			break;
		}	
		if(q[cam][i] <= dist){
			if(i==0)money+=q[cam][i]*r[cam][i]; //?¶??????????????????´???
			else money+=(q[cam][i]-q[cam][i-1])*r[cam][i];
		}
	}
	return money;
}

int main() {

	while(1){
		cin >> n >> m >> c >> s >> g;
		if(n==0&&m==0&&c==0&&s==0&&g==0) break;
		s--;g--;
		G.clear();
		G.resize(21);
		rep(i,21){ G[i].resize(MAX); rep(j,MAX) G[i][j].resize(MAX,INF);}
		fill_n((int *)q,sizeof(q)/sizeof(int),INF);
		fill_n((int *)r,sizeof(r)/sizeof(int),INF);
		fill_n((int *)p,sizeof(p)/sizeof(int),INF);

		for(int i=1;i<=m;i++){
			int x,y,d,c;
			cin >> x >> y >> d >> c;
			x--;y--;
			G[c][x][y]=min(G[c][x][y],d);	
			G[c][y][x]=min(G[c][y][x],d);	
		}
		
		for(int i=1;i<=c;i++){
			cin >> p[i];
		}
		
		rep(i,c){
			rep(j,p[i+1]-1) cin >> q[i+1][j];
			rep(j,p[i+1]) cin >> r[i+1][j];
		}
		//?????????????????????????¨????
		for(int l = 1;l<=c;++l)
			for(int k = 0; k < n; ++k)
				for(int i = 0; i < n; ++i)
					for(int j = 0; j < n; ++j){
						G[l][i][j] = min(G[l][i][j], G[l][i][k] + G[l][k][j]);
						G[0][i][j] = min(cal(G[l][i][j],l),G[0][i][j]);
					}
		
		/*
		for(int i=0;i<=c;i++) rep(j,n) rep(k,n){
			G[0][j][k] = min(G[c][j][k],G[0][j][k]);	
		}*/
		
		//??????????¨????
		for(int k = 0; k < n; ++k)
			    for(int i = 0; i < n; ++i)
					      for(int j = 0; j < n; ++j) G[0][i][j] = min(G[0][i][j], G[0][i][k] + G[0][k][j]);
	
		if(G[0][s][g]==INF) cout << -1 << endl;
		else cout << G[0][s][g] << endl;
	}	
	
	return 0;
}

Measured memory_bytes: 2120
#include<iostream>
#include<map>
using namespace std;
typedef long long int ll;
int main()
{
    int n;
    cin>>n;
    map<int,int> mp;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int ele;
        cin>>ele;
        mp[ele]++;
        ans+=ele;
    }
    int q;
    cin>>q;
    while(q--)
    {
        ll old,nw;
        cin>>old>>nw;
        if(mp.count(old))
        {
            ans=ans-(old*mp[old]);
            ans=ans+(nw*mp[old]);
            mp[nw]+=mp[old];
            mp.erase(old);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 6512
def examD():
    St = S()
    N = len(St)
    ans = "Second"
    if St[0]==St[-1]:
        if N%2==0:
            ans = "First"
    else:
        if N%2==1:
            ans = "First"
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Measured memory_bytes: 3316
# AOJ 0278: Admission Fee
# Python3 2018.6.25 bal4u

n = int(input())
for i in range(n):
	x, y, b, p = map(int, input().split())
	sm = x*b + y*p
	if b < 5: b = 5
	if p < 2: p = 2
	print(min(sm, ((x*b+y*p)*4)//5))


Measured memory_bytes: 5600
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
string s;
long id;
long ev1(void);
long num(void){
long v=0;
while(isdigit(s[id])){v=v*10+(s[id]-48);id++;}
return v;
}
long ev3(void){
if(s[id]=='('){
id++;
long v=ev1();
id++;
return v;
}else return num();
}
long ev2(void){
long v=ev3();
while(1){
if(s[id]=='*'){id++;v*=ev3();}
else if(s[id]=='/'){id++;v/=ev3();}
else break;
}
return v;
}
long ev1(void){
long v=ev2();
while(1){
if(s[id]=='+'){id++;v+=ev2();}
else if(s[id]=='-'){id++;v-=ev2();}
else break;
}
return v;
}
int main(){
long n,i;
cin>>n;
for(i=0;i<n;i++){
cin>>s;
id=0;
cout<<ev1()<<endl;
}
return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
int time[24][60];
int main(void)
{
	int i,j,h,m,f;
	for (i=0; i<2; ++i) {
		scanf("%d",&j);
			for (;j>0;--j) {
				scanf("%d %d",&h,&m);
				time[h][m]=1;
				}
			}
			f=1;
			for(i=0;i<24;++i)
				for(j=0;j<60;++j)
					if(time[i][j]){
						if(!f)printf(" ");
						else f=0;
						printf("%d:%02d",i,j);
						}
					printf("\n");
					return 0;
}

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

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

    int t = 0, x = 0, y = 0;
    int tn, xn, yn;
    bool flg = true;
    for (int i = 0; i < n; i++) {
        cin >> tn >> xn >> yn;

        int dt = abs(tn - t), dx = abs(xn - x), dy = abs(yn - y);

        if (!(dx + dy <= dt && (dx + dy) % 2 == dt % 2)) {
            flg = false;
        }

        t = tn;
        x = xn;
        y = yn;
    }

    if (flg)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

typedef long long unsigned llu;
typedef long long lld;
typedef long ld;
typedef unsigned int ui;

#define ff 			first
#define ss 			second
#define pb 			push_back
#define pob 		pop_back
#define mp 			make_pair
#define gcd(a,b)    __gcd(a,b)
#define IOS 		ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define SET(a,val)  memset(a,val,sizeof(a))
#define PI          3.1415926535897932384626433832795

#define count1(n)   __builtin_popcount(n)   //count number of ones
#define trail0(n)   __builtin_ctz(n)        //count number of trailing zeros

#define imax 	INT_MAX
#define imin 	INT_MIN
#define ldmax	LONG_MAX
#define ldmin	LONG_MIN
#define lldmax  LLONG_MAX
#define lldmin  LLONG_MIN
#define llumax  ULLONG_MAX

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

//constants
const lld MOD=1000000007;
#define INF 	1<<57
#define MAX 	100000
#define gc 		getchar

int main()
{
    //freopen("input.txt", "r", stdin)
    //freopen("output.txt", "w", stdout)
    int r,g,ra;
    scanf("%d",&r);
    scanf("%d",&g);
    ra=(2*g)-r;
    printf("%d",ra);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct sushi{
	int t,d;
	bool operator < (const sushi &b)const
	{
		return d > b.d;
	}
}a[maxn];
int n,k;
bool app[maxn];
ll ans,res,cnt;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].t,&a[i].d);
	sort(a + 1,a + n + 1);
	vector <int> lis; int i;
	for(i=1;i<=k;i++){
		ans += a[i].d;
		if(!app[a[i].t]){
			app[a[i].t] = true;
			ans -= cnt * cnt;
			cnt++;
			ans += cnt * cnt;
		}else{
			lis.push_back(i);
		}
	}
	res = ans;
	for(int j=lis.size() - 1;j>=0;j--){
		while(i <= n && app[a[i].t]) i++;
		if(i > n) break;
		ans -= a[lis[j]].d;
		ans += a[i].d;
		app[a[i].t] = true;
		ans -= cnt * cnt;
		cnt++;
		ans += cnt * cnt;
		res = max(res,ans);
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 1536
/**
 *      ABC 112 A
 *      author  : kyomukyomupurin
 *      created : 
**/

#include <bits/stdc++.h>
#define int32 int_fast32_t
#define int64 int_fast64_t
using namespace std;

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

    if (N == 1){
        cout << "Hello World" << endl; return 0;
    }
    int32 A, B; cin >> A >> B;
    cout << A + B << endl; 
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef pair<double, int> PDI;
typedef vector<PDI> VD;

const int INF = 3e18;

int a[7], b[7], ans = 0, ans1 = 0, ans2 = 0;
signed main()
{
  for(int i = 0; i < 7; i++){
    cin >> a[i];
    b[i] = a[i];
  }

  ans += a[1];

  {
    if(a[0] && a[3] && a[4]){
      ans1 += 3;
      a[0]--;
      a[3]--;
      a[4]--;
    }
    ans1 += a[0] / 2 * 2 + a[3] / 2 * 2 + a[4] / 2 * 2;
  }
  {
    ans2 += b[0] / 2 * 2 + b[3] / 2 * 2 + b[4] / 2 * 2;
    
    if(b[0] % 2 && b[3] % 2 && b[4] % 2){
      ans2 += 3;
    }
  }
  cout << ans + max(ans1, ans2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 0) cout << "Positive" << endl;
    else if (b > 0) cout << "Zero" << endl;
    else cout << ((b - a) % 2 ? "Positive" : "Negative") << endl;
    return 0;
}


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

int main( )
{
    int x0, y0, x1, y1, n, i, j, k;
    int w, h;
    cin >> w >> h >> n;
    x0 = 0;
    y0 = 0;
    x1 = w;
    y1 = h;
    int x, y, a;
    while (n--) {
        cin >> x >> y >> a;
        if (a == 1) {
            x0 = max(x0, x);
        }
        else if (a == 2) {
            x1 = min(x1, x);
        }
        else if (a == 3) {
            y0 = max(y0, y);
        }
        else {
            y1 = min(y1, y);
        }
    }
    cout << max(x1 - x0, 0) * max(y1 - y0, 0) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N,M;
main()
{
	while(cin>>N>>M,N)
	{
		int ans=0;
		for(int i=0;i<N;i++)
		{
			int A;cin>>A;
			ans+=min(A,M/N);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3068
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String a = in.next();
        String b = in.next();
        a += b;
        int c = Integer.parseInt(a);
        if ((double)Math.sqrt(c) == (int) Math.sqrt(c) ){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21844
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
 
n = inp()
a = inpl()
ans = 0
a.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        tmp = a[i] + a[j] - 1
        tt = bisect.bisect_right(a[j+1:],tmp)
        if tt > 0 :
            ans += tt
print(ans)

Measured memory_bytes: 53032
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while max(a) != 0:
  # print(a,cnt)
  betweenZero = True
  for i in range(len(a)):
    if a[i] != 0:
      a[i] -= 1
      betweenZero = False
    elif betweenZero == False:
      cnt += 1
      betweenZero = True
  if betweenZero == False:
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;

namespace ABC124 {
  class ProblemA {
    static void Main(string[] args) {
      int[] nums = Input.nums;
      int a = nums[0], b = nums[1];

      int ans = 0;
      if (a > b) {
        ans += a;
        a--;
      } else {
        ans += b;
        b--;
      }

      if (a > b) {
        ans += a;
        a--;
      } else {
        ans += b;
        b--;
      }

      System.Console.WriteLine(ans);
    }
  }
  public class Input {
    public static string str => System.Console.ReadLine();
    public static string[] strs => str.Split(' ');
    public static char[] charArr => str.ToCharArray();
    public static int num => int.Parse(str);
    public static int[] nums => Array.ConvertAll(strs, int.Parse);
    public static long numL => long.Parse(str);
    public static long[] numLs => Array.ConvertAll(strs, long.Parse);
  }
}


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

int N[100002] = {};

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

	bool b=true;

	int s;
	for (int i = 0; i < str.length(); i++)
	{
		N[i+1] = str[i] - '0';
		if (i == 0)s = N[i + 1];
		if (N[i + 1] != s)b = false;
	}
	if (b)
	{
		cout << str.length() << endl;
		return 0;
	}
	int MINIMAM = 100000;
	int MIN_INDEX = -1;
	int state = N[1];
	for (int i = 2; i <= str.length(); i++)
	{
		if (state != N[i])
		{
			if (MINIMAM > max(i-1, int(str.length()) - i+1))
			{
				//cout <<i-1<<":"<< int(str.length()) + 1 - i << endl;
				MINIMAM = max(i-1, int(str.length()) - i +1);
				MIN_INDEX = i;
			}
			state = N[i];
		}
	}
	cout << MINIMAM << endl;
	return 0;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:


int f[110];
int p[110][11];

const int inf = 1 << 30;

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

	rep(i, n) {
		rep(j, 10) {
			int tmp;
			cin >> tmp;
			f[i] = 2 * f[i] + tmp;
		}
	}

	rep(i, n)rep(j, 11) cin >> p[i][j];


	int ans = -inf;

	rep(mask, 1 << 10) {
		if (mask == 0) continue;
		int cur = 0;
		rep(i, n) {
			const int num = __builtin_popcount(mask & f[i]);
			cur += p[i][num];
		}
		chmax(ans, cur);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int s;
    cin >> s;
    int tmp = -1;
    for (int i = 0; i < 4; ++i)
    {
        int n = s % 10;
        if (tmp == n)
        {
            cout << "Bad";
            return 0;
        }
        else
        {
            tmp = n;
            s /= 10;
        }
    }
    cout << "Good";
}

Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)


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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int W, a, b, ans;

	cin >> W >> a >> b;

	if (a + W < b) ans = b - (a + W);
	else if (b + W < a) ans = a - (b + W);
	else ans = 0;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 
int main(){
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	
	int is_reverse = 0;//リバースした回数
	for(int i=0; i<Q; i++){
		int t;
		cin >> t;
		if(t==1){
			//reverse(S.begin(), S.end());
			is_reverse++;
			continue;
		}
		int f; 
		char c;
		cin >> f >> c;
		if((f==1 && is_reverse%2==0)  || (f==2&&is_reverse%2==1)){//コンパイルエラー起きたので()を入れる &&と||を一緒に書くときは注意しなかんのかな?
			S = c + S;
		}
		else{
			S.push_back(c);
		}

	}

	if(is_reverse%2==0){
		cout << S << endl;
		return 0;
	}
	else for(int i=S.size()-1; i>=0; i--) cout << S[i];
	cout << endl;
}


Measured memory_bytes: 4748
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int n;
  cin>>n;

  vector<int> p(13);
  p[0]=1;
  rep(i,n){
    int x;
    cin>>x;
    p[x]++;
    if(p[0]==2||p[12]==2||p[x]==3){
      cout << 0 << endl;
      return 0;
    }
  }

  vector<int> ti={0};
  if(p[12]==1) ti.pb(12);

  int ans=0;
  //——————————————bit全探索——————————————
  rep(i, (1<<11)){
    auto t=ti;
    repo(j,12){
      if(p[j]==1){
        if(i & (1<<j)) t.pb(j);
        else t.pb(24-j);
      }
      if(p[j]==2){
        t.pb(j);
        t.pb(24-j);
      }
    }
    int mi=100;
    int m=t.size();
    rep(j,m){
      rep(k,m){
        if(j>=k) continue;
        int x=abs(t[j]-t[k]);
        int y=min(x,24-x);
        chmin(mi,y);
      }
    }
    chmax(ans,mi);
  }

  cout << ans << endl;

  //——————————————————————————————————————




}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, i, a, b, ans = 0;
    cin >> n;
    vector<pair<ll, ll>> edges;
    for(i = 0; i < n - 1; i++) {
    	cin >> a >> b;
    	if(a < b) {
    		swap(a, b);
    	}
    	edges.pb(mp(a, b));
    }
    for(i = 1; i <= n; i++) {
    	ans = ans + i * (n - i + 1);
    }
    for(auto u: edges) {
    	ans = ans - (u.ss * (n - u.ff + 1));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 7404
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
#define mp make_pair

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int> > PP;
const int MAX=2e5+10;

int main(){
	int N;
	cin>>N;
	ll A[MAX],B[MAX];
	rep(i,N)cin>>A[i]>>B[i];
	
	vector<P> v(N);
	rep(i,N) v[i]=mp(B[i], A[i]);
	sort(v.begin(), v.end());
	bool ans=true;
	ll now=0;
	rep(i,N){
		ll tmp=now+v[i].second;
		if(tmp>v[i].first){
			ans=false;
			break;
		}
		else{
			now=tmp;
		}
	}
	
	if(ans) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int sum=0,N,M,K;
DV(G,int,50,4,1);
Vec(Q,int,10,1);
void dfs(int C,vector<int>Q){
  if(!C)rep(i,1,M+1){
    Q[C]=i;
    dfs(C+1,Q);
  }
  else if(N>C){
    rep(i,Q[C-1],M+1){
      Q[C]=i;
      dfs(C+1,Q);
    }
  }
  else{
    int num=0;
    rep(i,0,K)if(Q[G[i][1]-1]-Q[G[i][0]-1]==G[i][2])num+=G[i][3];
    chmax(sum,num);
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,L,X,Y,Z,H,W,num=0,flag=0;string S,T;
  cin >> N >> M >> K;
  rep(i,0,K)rep(j,0,4)cin >> G[i][j];
  dfs(0,Q);
  Out(sum);
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()




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

    if (N == 1){
        cout << 1 << endl;
    }else if (N%2 == 0){
        cout << 0.5 << endl;
    }else{
        cout << 1.0*(N+1)/N/2 << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n,c[500],s[500],f[500],i,j;
	scanf("%d",&n);
	for(i=0;i<n-1;i++) scanf("%d%d%d",&c[i],&s[i],&f[i]);
	for(i=0;i<n-1;i++){
		int t=0;
		for(j=i;j<n-1;j++){
			if(t<s[j]) t=s[j];
			else if(t%f[j]==0);
			else t=t+f[j]-(t%f[j]);
			t+=c[j];
		}
		printf("%d\n",t);
	}
	printf("0\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int N;
    cin >> N;
    int T[N], A[N];
    for(int i = 0; i < N; i++)  cin >> T[i];
    for(int i = 0; i < N; i++)  cin >> A[i];
    
    int confirmT[N], confirmA[N];
    ll ans = 1;
    for(int i = 0; i < N; i++){
        confirmT[i] = -1;
        confirmA[i] = -1;
    }
    
    
    confirmT[0] = T[0], confirmA[N - 1] = A[N - 1];
    for(int i = 1; i < N; i++){
        if((T[i - 1] != T[i]) || T[i] == 1) confirmT[i] = T[i];
        if((A[N - 1 - i] != A[N - i]) || A[N - i] == 1) confirmA[N - 1 - i] = A[N - 1 - i];
    }
    
    for(int i = 0; i < N; i++)
        if(confirmT[i] != -1 && confirmA[i] == -1){
            if(confirmT[i] > A[i]){
                cout << 0 << "\n";
                return 0;
            }
        }
        else if(confirmT[i] == -1 && confirmA[i] != -1){
            if(T[i] < confirmA[i]){
                cout << 0 << "\n";
                return 0;
            }
            confirmT[i] = confirmA[i];
        }
        else if(confirmT[i] != confirmA[i]){
            cout << 0 << "\n";
            return 0;
        }

    for(int i = 1; i < N; i++){
        if(confirmT[i] == -1){
            ans *= ((ll)min(T[i], A[i]) % mod);
            ans %= mod;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = true;

ll ans = 0;
bool searched[400][400];
char grid[400][400];
int H;
int W;
int move_x[4] = {-1, 0, 1, 0};
int move_y[4] = {0, -1, 0, 1};
ll n_white;
ll n_black;

bool isRange(int x, int y){
    if(x <  0) return false;
    if(x >= H) return false;
    if(y <  0) return false;
    if(y >= W) return false;
    return true;
}

void dfs(int x, int y, char col){

    // 探索範囲外，探索済，色が同じであれば何もしない
    if(!isRange(x, y)) return ;
    if(searched[x][y]) return ;
    if(grid[x][y] == col) return;

    searched[x][y] = true;
    if(grid[x][y] == '#') n_black ++;
    else n_white ++;

    for(int i = 0; i < 4; i++){
        int nx = x + move_x[i];
        int ny = y + move_y[i];
        if( isRange(nx, ny) ){
            dfs(nx, ny, grid[x][y]);
        }
    }
}

int main(){

    cin >> H >> W;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> grid[i][j];
            searched[i][j] = false;
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(grid[i][j] == '#'){
                n_black = 0;
                n_white = 0;
                dfs(i, j, '.');
                ans += (n_white * n_black);
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 8064
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String[] str = new String[a];
        for(int loop = 0;loop < a;loop++)
        {
            str[loop] = sc.next();
        }
        HashMap<String, Integer> yoloooooooooooooooooooooooooooooooooooo = new HashMap<>();
        for(String s : str){
            yoloooooooooooooooooooooooooooooooooooo.put(s,666666);
        }
        System.out.println(yoloooooooooooooooooooooooooooooooooooo.size());
    }
}

Measured memory_bytes: 69680
N=int(input())
*A,=map(int,input().split())

Step=[0]
maxt=A[0]
i=0
while i<N-1:
  if maxt<A[i+1]:
    maxt=max(maxt,A[i+1])
    s=0
  else: 
    s=maxt-A[i+1]
  Step+=[s]
  i+=1
print(sum(Step))



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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin>>s;
    s[3] = '8';
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256