akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <set>
using namespace std;
const set<set<string>> correct={
	{"lu","ru"},{"ld","rd"}
};
int main(){
	int n,i,r;
	string x,y;
	for(;cin>>n,n;cout<<r<<endl){
		for(r=i=0;i<n/2;i++){
			set<string>se;
			cin>>x>>y;
			se.insert(x);
			se.insert(y);
			if(correct.find(se)!=correct.end())r++;
		}
		if(n&1)cin>>x;
	}
}

Measured memory_bytes: 1220
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;

public class Main{

	 static int array[][];
	 static int gi=0,gj=0;
     static	int h,w;
	static int wall_yoko[][];
	static int wall_tate[][];

	 public static void main(String[] args)throws Exception{

	 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


	 while(true){

    String readLine = br.readLine();
    readLine = readLine.trim();
    String[] num = readLine.split("[\\s]+");

    w = Integer.parseInt(num[0]);
    h = Integer.parseInt(num[1]);

    if(w==0 && h==0)
    	return;


    wall_yoko = new int[h][w-1];
    wall_tate = new int[h-1][w];

    array = new int[h][w];

    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    			array[i][j]=Integer.MAX_VALUE;
    	}}

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

    	//?¨?????£????????????????
    	readLine= br.readLine();
    	readLine = readLine.trim();
    	String[] yoko = readLine.split("[\\s]+");
    	for(int j=0;j<w-1;j++)
    		wall_yoko[i][j]=Integer.parseInt(yoko[j]);

    	//???????£????????????????
    	if(i<h-1){
    	readLine= br.readLine();
    	readLine = readLine.trim();
    	String[] tate = readLine.split("[\\s]+");
    	for(int j=0;j<w;j++)
    		wall_tate[i][j]=Integer.parseInt(tate[j]);
    	}
    }

    	//?????????????????¢?´¢????§?
        gi=h;
        gj=w;

    	search(0,0,0);

    	if(array[h-1][w-1] == Integer.MAX_VALUE)
    		System.out.println(0);
    	else
    		System.out.println(array[h-1][w-1]);



    	/* array??????????¢????
        for(int i=0;i<h;i++){
	    	for(int j=0;j<w;j++){
	        	System.out.print(" "+array[i][j] );


	    	}System.out.println("");
        }
*/


	 }//while1??????

}

	 public static void search(int i,int j,int count){

		 count++;

		 //??¢?´¢???????????????????????°????????????
		 if(array[i][j] <= count)
			 return;
		 //????????????????????????????????????????????????????????????????°????????????°??????????????´??°
		 if(array[i][j]>count)
			 array[i][j]=count;

		 PriorityQueue<Integer> queue = new PriorityQueue<Integer>();



		 //????????¢?´¢
		 try{
		 if(j+1<w && wall_yoko[i][j]==0)
			 search(i,j+1,count);
		 }catch(Exception e){}

		 //????????¢?´¢

		 try{
		 if(j-1>=0 && wall_yoko[i][j-1]==0)
			 search(i,j-1,count);
		 }catch(Exception e){}

		 //????????¢?´¢
		 try{
		 if(i+1<h && wall_tate[i][j]==0)
			 search(i+1,j,count);
		 }catch(Exception e){}
		 //????????¢?´¢
		 try{
		 if(i-1>=0 &&wall_tate[i-1][j]==0)
				 search(i-1,j,count);
		 }catch(Exception e){}



	 }

}

Measured memory_bytes: 96084
# coding: utf-8
from collections import defaultdict

INF = 10 ** 20
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    edges = defaultdict(list)
    for __ in range(N - 1):
        a, b, c = ILI()
        edges[a - 1].append((a - 1, b - 1, c)) # from, to, weight
        edges[b - 1].append((b - 1, a - 1, c))
    Q, K = ILI()
    query = [ILI() for __ in range(Q)]
    return N, edges, Q, K, query


def solve(N, edges, Q, K, query):
    K -= 1
    weight_from_k = [None] * N
    weight_from_k[K] = 0
    used = [False] * N
    used[K] = True
    queue = edges[K]
    while len(queue) != 0:
        next_queue = []
        for fro, to, weight in queue:
            if used[to]:
                continue
            weight_from_k[to] = weight_from_k[fro] + weight
            used[to] = True
            for e in edges[to]:
                next_queue.append(e)
        queue = next_queue

    ans = []
    for x, y in query:
        ans.append(weight_from_k[x - 1] + weight_from_k[y - 1])

    ans = "\n".join(map(str, ans))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 102120
/*input
*/
#define debug 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
const int N = 2e5 + 5, M = 1e9 + 7; const db eps = 1e-8;
typedef vector<ll> vi; typedef vector<vi> vii;
void solve();
void print(){cout<<'\n';}template<class T,class ...U>void print(T x, U ...y){cout<<x<<' ';print(y...);}
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cout << setprecision(3) << fixed;
  if(debug){freopen("main.cpp","r",stdin);string x;cin>>x;}
  solve();
}
//

//ll cnt[10];
//void solve(int n) {
//  int s = 1 << n;
//  for (int i = 0; i < s; i++) {
//    for (int j = 0; j < s; j++) {
//      if (i != j) {
//        int tmp = 0;
//        for (int k = 0; k < n; k++) {
//          if ((i >> k & 1) != (j >> k & 1)) cnt[k] += ++tmp;
//        }
//      }
//    }
//  }
//  for (int i = 0; i < n; i++) cout << cnt[i] << ' ';
//  cout << endl;
//}
//void solve() {
//  for (int i = 2; i <= 8; i++) {
//    memset(cnt, 0, sizeof cnt);
//    solve(i);
//  }
//}

ll qpow(ll x, ll n) {
  ll res = 1;
  for (; n; n >>= 1, x = x * x % M) if (n & 1) res = res * x % M;
  return res;
}
ll a[N];
void solve() {
  int n; cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  ll x = qpow(4, n - 1), ans = 0;
  sort(a + 1, a + n + 1);
  for (int i = n, j = 2; i; i--, j++) {
    a[i] %= M;
    ans = (ans + j * x % M * a[i] % M) % M;
  }
  cout << ans << endl;
}


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

int main (){
        int H, W;
        cin >> H >> W;
        string ans = "Yes";
        char arr[52][52];

        for (int i = 1; i <= H; i++) {
                for (int j = 1; j <= W; j++) {
                        cin >>arr[i][j];
                }
        }

        for (int i = 1; i <= H; i++) {
                for (int j = 1; j <= W; j++) {
                        if (arr[i][j]=='#' && arr[i-1][j]!='#' && arr[i+1][j]!='#' && arr[i][j+1]!='#' &&arr[i][j-1]!='#' ) {
                                ans = "No";
                                break;
                        }
                }
        }

        cout << ans << endl;

        return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {
  string s, t;
  int a, b, c, x, y, z, N;
    
  cin >> N;
  vector<int> vs(N + 1);

  REP(i, 1, N + 1) { cin >> vs[i]; }

  int ans = 0;

//  REP(i, 1, N + 1) {    cout << vs[i] << ", " << vs[vs[i]] << endl;  }cout << endl;

  REP(i, 1, N + 1) {
    ans += i == vs[vs[i]];
  }

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

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

l = r = tot = xor = cnt = 0
while l <= r < N:
    a = A[r]
    if xor & a == 0:
        tot += a
        xor ^= a
        r += 1
        cnt += r-l
    else:
        while xor & a:
            tot -= A[l]
            xor ^= A[l]
            l += 1
print(cnt)


Measured memory_bytes: 32040
d = [[0] * 10 for i in range(10)]

def b(x, y):
    for i in range(x - 2, x + 3):
        a = 3 - abs(x - i)
        for a in range(y - a + 1, y + a):
            if 0 <= i < 10 and 0 <= a < 10:
                d[a][i] += 1


def m(x, y):
    for i in range(x - 1, x + 2):
        for j in range(y - 1, y + 2):
            if 0 <= i < 10 and 0 <= j < 10:
                d[j][i] += 1


def s(x, y):
    r = (1, 0)
    for i in range(x - 1, x + 2):
        a = abs(x - i)
        for j in range(y - r[a], y + r[a] + 1):
            if 0 <= i < 10 and 0 <= j < 10:
                d[j][i] += 1

while 1:
    try:
        f = (None, s, m, b)
        x, y, size = list(map(int, input().split(',')))
        f[size](x, y)
    except:
        break


r1 = r2 = 0
for i in range(10):
    for j in range(10):
        r1 += 1 if d[i][j] == 0 else 0
        r2 = max(r2, d[i][j])

print(r1)
print(r2)

Measured memory_bytes: 7664
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
void solve() {
    int n;
    cin >> n;
    int now = 1;
    int ans = n;
    REP(i, n) {
        int a;
        cin >> a;
        if (now == a) {
            now++;
            ans--;
        }
    }
    if (ans == n) ans = -1;
    cout << ans << endl;
}

int main() {
    init();
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int main(int argc, char* argv[]) {

	int N,T;
	int ans = 0;
	int cnt = 0;

	cin >> N >> T;

	vector< pair < int,int > > ct(N);

	for (int i = 0; i < N; i++) {
		cin >> ct[i].first >> ct[i].second;
	}

	sort(ct.begin(),ct.end());


	while(ct[cnt].second > T){
		cnt++;
	}

	if(cnt==N){
		cout << "TLE" << endl;
	}else{
		cout << ct[cnt].first << endl;
    }

	return 0;

}






Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    int n;
    cin>>n;
    vector <int> ans(n+1);
    for (int i=0;i<n-1;i++)
    {
        int x;
        cin>>x;
        ans[x]++;
    }
    for (int i=1;i<=n;i++)
        cout<<ans[i]<<"\n";





}

Measured memory_bytes: 3988
#include <stdio.h>
int a[100001];
int main(void){
	int N;
	scanf("%d",&N);
	int i,temp;
	for(i=1;i<=N;i++){
		scanf("%d",&a[i]);
	}
	//a[1]から開始して、値が2になったら終了する
	//a[1]に入っている値を添え字にして飛んでいく
	int count = 0;
	int current = 1;
	int next = a[current];
	while(count<=N){
		count++;
		next = a[current];
		current = next;
		if(current == 2)break;
	}
	if(count<=N)printf("%d",count);
	else printf("-1");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
int a[2222];
int b[2222];
int c[2222];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n; 
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<n;i++)cin>>c[i];
	int ans = 0;
	for(int i=1;i<=n;i++)ans+=b[i];
	for(int i=1;i<n;i++){
		if(a[i]+1==a[i+1]){
			ans+=c[a[i]];
		}
		
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = input()
S = input()

cnt = 0
ans = S

for c in S:
    if c == '(':
         cnt += 1
    elif c == ')':
        cnt -= 1

    if cnt < 0:
        ans = '(' + ans
        cnt += 1

if cnt > 0:
    for i in range(cnt):
        ans = ans + ')'

print(ans)


Measured memory_bytes: 2940
#include<stdio.h>

int main(){
  int a[3];
  int k;
  int i,j;
  int tmp;

  for(i=0;i<3;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&k);

  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(a[i]>a[j]){
        tmp=a[i];
        a[i]=a[j];
        a[j]=tmp;
      }
    }
  }

  for(i=0;i<k;i++){
    a[2]*=2;
  }

  printf("%d",a[0]+a[1]+a[2]);

  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    int L[10010];
    L[0] = 0;
    rep(i, N) cin >> L[i + 1];
    int ans = 0;
    int now = 0;
    rep(i, N + 1) {
        now += L[i];
        if (now <= X) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// Aizu 2199: Differential Pulse Code Modulation
// 2017.9.21 bal4u@uu
// 2017.12.10

#include <stdio.h>
#include <string.h>

#define INF   0x1fffffff
int code[16];				// code book
int dp[20001][257];			// Sum of Squares
int tbl[256][16];

char buf[15], *p;
int getsint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, k, x, s, t, ans;

	while (fgets(p=buf, 15, stdin) && *p != '0') {
		n = getint(), p++, m = getint();

		for (i = 0; i < m; i++) fgets(p=buf, 10, stdin), code[i] = getsint();

		for (i = 0; i < 256; i++) for (j = 0; j < m; j++) {
			t = i + code[j];
			if (t < 0) t = 0;
			else if (t >= 256) t = 255;
			tbl[i][j] = t;
		}

		memset(dp, 0x33, sizeof(dp));
		dp[0][128] = 0;

		for (k = 0; k < n; k++) {
			fgets(p=buf, 10, stdin), x = getint();
			for (i = 0; i < 256; i++) {
				if (dp[k][i] > INF) continue;
				for (j = 0; j < m; j++) {
					t = tbl[i][j], s = (t-x)*(t-x) + dp[k][i];
					if (s < dp[k+1][t]) dp[k+1][t] = s;
				}
			}
		}

		for (ans = INF, i = 0; i < 256; i++) if (dp[n][i] < ans) ans = dp[n][i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 21800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>

using namespace std;

int main(){
  int i=0;
  string s;
  stringstream ss;
  vector<int> A;
  cin >> s;
  for(char c:s){
    if(i%2 == 0){
      ss << c;
    }
    i++;
  }
  cout << ss.str() << endl;

  return 0;
}


Measured memory_bytes: 512
let read_int_array n = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x))

let x, y, a, b, z = Scanf.scanf "%d %d %d %d %d" (fun x y a b z -> x, y, a, b, z)

let p = read_int_array a
let q = read_int_array b
let r = read_int_array z

let cmp x y = y - x;;

Array.sort cmp p;
Array.sort cmp q;
Array.sort cmp r;

let rec f i (a, b, c) (ai, bi, ci) ret =
  if i = x + y then ret
  else if b <= a && c <= a then
    f (i+1) ((if ai = x-1 then -1 else p.(ai+1)), b, c) (ai+1, bi, ci) (ret + a)
  else if a <= b && c <= b then
    f (i+1) (a, (if bi = y-1 then -1 else q.(bi+1)), c) (ai, bi+1, ci) (ret + b)
  else
    f (i+1) (a, b, (if ci = z-1 then -1 else r.(ci+1))) (ai, bi, ci+1) (ret + c)
in print_int (f 0 (p.(0), q.(0), r.(0)) (0, 0, 0) 0)


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n;
    cin>>n;
    string r = "";
    while (n > 0)
    {
        r = (char)(97 + (n - 1) % 26) + r;
        n = (n - 1) / 26;
    }
    cout<<r;
}

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
void call(int n){
	for (int i = 1; i <= n; i++){
		if (i % 3 == 0){
			cout << " " << i;
		}
		else {
			int a = i;
			while (a > 0){
				if (a % 10 == 3){
					cout << " " << i;
					break;
				}
				a = a / 10;
			}
		}
	}
	cout << endl;
	return;
}

int main(){
	int n;
	cin >> n;
	call(n);
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define test(t) int t;cin>>t;while(t--)
#define lli long long int
#define pb push_back
#define MAX 1000000007
#define mod 1000000007
#include <iostream>
const lli infl=0x3f3f3f3f3f3f3f3fLL;

int main()
{  ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
  // test(t)
   {
       lli a,b,c,d,sum=0;

       string s;

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

       if(a-sum<0)
        cout<<"-1";
       else
        cout<<a-sum;

     cout<<endl;
   }


return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    string s;
    cin >> s;
    ll ans=0;
    ll n=s.size();
    for(ll i=0;i<(1<<(n-1));i++){
        ll res=0;
        ll now=s[0]-'0';
        for(ll j=0;j<n-1;j++){
            if(i>>j&1){
                res+=now;
                now=(ll)(s[j+1]-'0');
            }
            else{
                now=10*now+(ll)(s[j+1]-'0');
            }
        }
        res+=now;
        ans+=res;
    }
    cout << ans << endl;
}
    


Measured memory_bytes: 3612
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int loop = sc.nextInt();
        int[] array = new int[loop];
        long count = 0;
        for(int i = 0; i < loop; i++) {
            array[i] = sc.nextInt();
        }
        for(int i = 0; i < (loop - 1); i++) {
            int temp = array[i];
            int next = array[i+1];
            if(next < temp){
                count += (temp - next);
                array[i+1] = temp;
            }
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 60052
#include<iostream>
using namespace std;
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<math.h>

int main(){
    int N;
    cin >> N;
    int t[N],x[N],y[N];
    for(int i=1; i<=N;++i){
        cin >> t[i] >> x[i] >> y[i];
    }
    int res[N+1];
    int dif_x[N+1];
    int dif_y[N+1];
    int dif_t;
    int dif_xy;
    bool possib=true;
    x[0]=0;
    y[0]=0;
    t[0]=0;
    
    for(int i=0;i<N;++i){
        dif_t=t[i+1]-t[i];
        dif_xy=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if(dif_xy<=dif_t && dif_t%2==dif_xy%2){
            possib=true;
        }
        else{
            possib=false;
            break;
        }   
    }
    if(possib==true){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int r,g,b;
      cin >> r >> g >> b;
      if((10*g+b)%4==0) cout << "YES" << endl;
      else cout << "NO" << endl;
      return 0;}


Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
const int maxn=200010;
int n;
int a[maxn];
int ar[maxn],nm;
int In() {
    register char c;
    for(;c=getchar(),c!='-'&&!isdigit(c););
    register bool f=c=='-';
    register int s=f?0:c-'0';
    for(;c=getchar(),isdigit(c);)s=s*10+c-'0';
    return f?-s:s;
}
bool ck(register int ans) {
	nm=0;
	for(register int i=1;i<=n;++i) {
		if(!nm) ar[++nm]=a[i];
		else if(ar[nm]<a[i]) ar[nm]=a[i];
		else {
			if(ar[nm]>a[i]) {
				for(;nm&&ar[nm]>a[i];--nm);
				for(;nm>=ans&&ar[nm-ans+1]==ar[nm]&&ar[nm];--ar[nm-ans+1]);
				if(nm&&ar[nm]<=0) return 0;
				ar[++nm]=a[i];
			}
			for(;nm>=ans&&ar[nm-ans+1]==ar[nm]&&ar[nm];--ar[nm-=ans-1]);
			if(nm&&ar[nm]<=0) return 0;
			ar[++nm]=a[i];
		}
	}
	return 1;
}
int main() {
	n=In();
	for(register int i=1;i<=n;++i)a[i]=In();
	register int ll=1,rr=n;
	ck(2);
	for(register int mm;mm=(ll+rr)>>1,ll<rr;ck(mm)?rr=mm:ll=mm+1);
	printf("%d\n",ll);
	return 0;
}

Measured memory_bytes: 1664
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static class Pair implements Comparable<Pair> {
		int a, b;

		Pair(String[] tokens) {
			this.a = Integer.parseInt(tokens[0]);
			this.b = Integer.parseInt(tokens[1]);
		}

		@Override
		public int compareTo(Pair o) {
			// 報酬の降順
			int compB = Integer.compare(this.b, o.b);
			if (compB != 0) {
				return -1 * compB;
			}
			return -1 * Integer.compare(this.a, o.a);
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);

		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);
		List<Pair> pairs = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			pairs.add(new Pair(in.readLine().split(" ")));
		}
		Collections.sort(pairs, new Comparator<Pair>() {
			// 日数の昇順でソート
			@Override
			public int compare(Pair o1, Pair o2) {
				return Integer.compare(o1.a, o2.a);
			}
		});
		Deque<Pair> queue = new ArrayDeque<>(N);
		queue.addAll(pairs);
		long result = 0;
		Queue<Pair> pq = new PriorityQueue<>();
		for (int day = 1; day <= M; ++day) {
			// pq側に要素を移す
			while (!queue.isEmpty()) {
				if (queue.peekFirst().a <= day) {
					pq.add(queue.pollFirst());
				} else {
					break;
				}
			}
			// pqの先頭の要素を用いる
			Pair pair = pq.poll();
			if (pair != null) {
				result += (long) (pair.b);
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 50288
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
    int L,R,d;
    int cnt=0;
    scanf("%d %d %d",&L,&R,&d);
    for(int i=L;i<=R;i++){
        if(i%d==0){
            cnt++;
        }
    }
    printf("%d\n",cnt);
}

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

using namespace std;

typedef long long ll;

ll k;
ll in[51];

int main() {
  cin >> k;

  ll n = 50;
  ll c = k / 50;

  
  for(int i = 0; i < n; i++) in[i] = n-1 + c;

  for(int i = 0; i < k % 50 ; i++) {
    in[i] += n;
  for(int j = 0; j < n; j++) if(i != j) in[j] -= 1;
  }
  cout << n << endl;
  for(int i = 0; i < n - 1; i++) cout << in[i] <<" ";
  
  cout << in[n-1]<<endl;
  

}


Measured memory_bytes: 256
//package practice; 
import java.io.*;
import java.util.*;
import java.util.Stack;
import java.util.regex.Pattern;


public class Main {

	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	public static void main(String[] args) {
		 FastReader sc = new FastReader();
		 
		 char[] ch = sc.next().toCharArray();
		 boolean good = true;
		 for(int i=0;i+1<ch.length;++i) {
			 if(ch[i] == ch[i+1]) {
				 good = false;
			 }
		 }
		 if(good) out.println("Good");
		 else out.println("Bad");
		 out.close();
		 
	}

}		 





Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
static const int NMAX=100;
int N,T[NMAX],M,P[NMAX],X[NMAX],sum;

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>T[i];
        sum+=T[i];
    }    
    cin>>M;
    for(int i=0;i<M;i++)cin>>P[i]>>X[i];

    for(int i=0;i<M;i++)
        cout<<sum-(T[P[i]-1]-X[i])<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int x, y, z;
    while(cin>>x>>y>>z){
    	cout<<z<<" "<<x<<" "<<y<<endl;
    }
  return 0;
}




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

#define MOD 1000000007

using namespace std;

vector<int> v[22];

int n;

int men[22];

int ch;

long long zim;

int ans[22][1 << 22];

int main(){

	cin >> n;

	for (int i = 0; i < n; i++){		
		for (int j = 0; j < n; j++){
			cin >>	ch;
			if (ch == 1) 
				men[i] += 1 << j;
		}
	}

//	for (int i = 0; i < n; i++) cout << men[i] <<" ";
	
//	cout << endl;

	for (int i = 0; i <= ((1 << n) - 1); i++){ 
		for (int j = 0; j < n; j++)
//			ans[0][i] = (ans[0][i] + (((men[0] >> j) & 1) & ((i >> j) & 1))) % MOD;
			zim += (((men[0] >> j) & 1) & ((i >> j) & 1));
		ans[0][i] = zim % MOD;
		zim = 0;
	}

	for (int i = 0; i <= (1 << n) - 1; i++){
		for (int j = 0; j < n; j++){
			if ((i >> j) & 1 == 1){
				zim++;
			}
		}
		v[zim].push_back(i);
		zim = 0;
	}
		
//	for (int i = 0; i <= ((1 << n) - 1); i++)
//		cout << i << " " << ans[0][i] << endl;
//	cout << "!!" << endl;

	for (int i = 1; i < n; i++){
		for (int j: v[i + 1]){
			for (int o = 0; o < n; o++){
				if (((men[i] & j) >> o) & 1)
//					ans[i][j] = (ans[i][j] + ans[i - 1][j - (1 << o)]) % MOD; 
					zim += ans[i - 1][j - (1 << o)];
				
			}
//			cout << i << " " << j << " " << ans[i][j] << endl;
			ans[i][j] = zim % MOD;
			zim = 0;			
		}	
	}
			

	cout << ans[n - 1][(1 << n) - 1];


}

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

const long long MAX = 1e9;

int N;
vector<int> a_list;

int main() {
  cin >> N;
  a_list.resize(N);
  for(int i=0;i<N;i++) cin >> a_list[i];

  int all_or = a_list[0];
  for(int i=0;i<N;i++) {
    all_or |= a_list[i];
  }
  // cout << bitset<20>(all_or) << "\n";
  if (all_or==0) {
    cout << "0\n";
    return 0;
  }
  for (int i=0;i<MAX;i++){
    if (all_or & (1<<i)){
      cout << i << "\n";
      break;
    }
  }


#if 0
  cout << N << "\n";
  for(auto s: a_list) cout << s << " "; 
  cout << "\n";
#endif
  return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B;
    cin >> A >> B;
    cout << max(A + B, max(A - B, A * B)) << endl;
    return 0;
}

Measured memory_bytes: 256
def check(s):
    h = 0
    for p in s:
        b = h + p[0]
        if b < 0:
            return False
        h += p[1]
    return True


N = int(input())
S = []
left = []
right = []
total = 0
for i in range(N):
    last = 0
    bottom = 0
    s = input().strip()
    for c in s:
        if c == "(":
            last += 1
        else:
            last -= 1
        bottom = min(bottom, last)
    if last > 0:
        left.append((bottom, last))
    else:
        right.append((bottom-last, -last))
    total += last

left.sort(key=lambda x: -x[0])
right.sort(key=lambda x: -x[0])

if check(left) and check(right) and total == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 84280
import java.util.*;

public class Main {
  public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int hp = sc.nextInt();
    	int attack = sc.nextInt();
    	if(hp % attack == 0) {
          System.out.println(hp / attack);
        } else {
          System.out.println(hp / attack + 1);
        }
  }
}

Measured memory_bytes: 23764
# -*- coding: utf-8 -*-
W,a,b = map(int, raw_input().split())


if(b+W<a):
    print(a-b-W)
elif(b<=a and a<=b+W):
    print('0')
elif(a<=b and b<=a+W):
    print('0')
elif(a+W<b):
    print(b-a-W)

Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

int X, Y;
int field[50][50];

bool visit[50][50][50][50];

struct Node {
	int takx, taky;
	int kazx, kazy;
	int turn;
	Node(int takx, int taky, int kazx, int kazy) : takx(takx), taky(taky), kazx(kazx), kazy(kazy), turn(0) {}

	bool isOk() {
		return takx == kazx && taky == kazy;
	}

	// right, up, left, down
	Node move(int dir) {
		static int dx[4] = {1, 0, -1, 0};
		static int dy[4] = {0, 1, 0, -1};
		Node next = *this;

		int nx, ny;

		nx = takx + dx[dir];
		ny = taky + dy[dir];

		if(0 <= nx && nx < X && 0 <= ny && ny < Y) {
			if(field[nx][ny] == 0) next.takx = nx, next.taky = ny;
		}

		nx = kazx + dx[(dir + 2) % 4];
		ny = kazy + dy[(dir + 2) % 4];

		if(0 <= nx && nx < X && 0 <= ny && ny < Y) {
			if(field[nx][ny] == 0) next.kazx = nx, next.kazy = ny;
		}

		next.turn++;
		return next;
	}
};

int main() {
	for(; cin >> X >> Y, X || Y;) {
		int tx, ty;
		int kx, ky;
		cin >> tx >> ty >> kx >> ky;
		tx--, ty--, kx--, ky--;

		memset(visit, 0, sizeof visit);
		memset(field, 0, sizeof field);

		visit[tx][ty][kx][ky] = true;

		for(int y = 0; y < Y; y++) {
			for(int x = 0; x < X; x++) {
				cin >> field[x][y];
			}
		}

		queue<Node> Q;
		Q.push(Node(tx, ty, kx, ky));

		int ans = -1;
		while(!Q.empty()) {
			Node node = Q.front(); Q.pop();
			if(node.turn >= 100) continue;
			if(node.isOk()) {
				ans = node.turn;
				break;
			}
			for(int i = 0; i < 4; i++) {
				Node next = node.move(i);
				if(!visit[next.takx][next.taky][next.kazx][next.kazy]) {
					visit[next.takx][next.taky][next.kazx][next.kazy] = true;
					Q.push(next);
				}
			}
		}

		if(ans == -1) cout << "NA" << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 0
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  unordered_set<char> letters;
  for (const auto &c : S) {
    letters.insert(c);
  }
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  for (const auto &c : alphabet) {
    if (letters.count(c) == 0) {
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;cin >> n;
    vector<int> migi(n),hidari(n);
    int a[n];
    rep(i,n)cin >> a[i];
    int now = 0;
    rep(i,n){
        hidari[i] = max(now,a[i]);
        now = hidari[i];

    }
    now = 0;
    for(int i = n-1;i >=0;i--){
        migi[i]  = max(now,a[i]);
        now = migi[i];
    }
    
    rep(i,n){
        if(!i)cout << migi[i+1] << endl;
        else if(i ==n-1)cout << hidari[i-1] << endl;
        else cout << max(migi[i+1],hidari[i-1]) << endl;

    }
    return 0;
}

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

using namespace std;
#define endl "\n"

const int MOD = 1000000007;
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int t;
	double s1 = 0, s2 = 0;
	cin >> t;
	for(int i = 0 ; i < t; i++){
		double a;
		string x;
		cin >> a >> x;
		
		if(x == "BTC"){
			s1 += a;
		}
		else if(x == "JPY"){
			s2 += a;
		}
		
		
	}
	printf("%0.4lf\n",(s1*380000)+s2);
	return 0;
}

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

int main(){
  string S;
  cin>>S;
  while(1){
    int flag=0;
    if(S.length()==0){
      cout<<0<<endl;
      return 0;
    }
    for(int i=0;i<S.length()-1;i++){
      if(S.at(i)=='S' && S.at(i+1)=='T'){
        //cout<<i<<"#"<<endl;
        //cout<<S<<"before"<<endl;
        S.erase(i,1);
        S.erase(i,1);
        i--;
        i--;
        flag=1;
        //cout<<S<<"after"<<endl;
      }
    }


    if(flag==0) break;
  }
  //cout<<S<<endl;
  cout<<S.length()<<endl;
  return 0;
}

    
    

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,i,n,ans=0;
	scanf("%d",&n);
	scanf("%d%d%d",&a,&b,&c);
	for(i=4;i<=n;i++)
	{
		if((b>a&&c>b)||(a>b&&b>c))
			ans++;
		a=b;
		b=c;
		scanf("%d",&c);
	}
	if((b>a&&c>b)||(a>b&&b>c))
		ans++;
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
 
typedef long long ll;

class SumOf2DArray {
private:
  vector<vector<int> > a;
  vector<vector<ll> >  S;
  int N_, M_;
  
  void precalc() {
    for(int i=0; i<N_; i++)
      for(int j=0; j<M_; j++)
        S[i+1][j+1] = S[i+1][j] + a[i][j];
    
    for(int i=0; i<N_; i++)
      for(int j=0; j<M_; j++)
        S[i+1][j+1] += S[i][j+1];
  }
  
public:
  
  SumOf2DArray(const vector<vector<int> >& a) {
    N_ = a.size();
    M_ = a[0].size();
    this->a = a;
    this->S.assign(N_+1, vector<ll>(M_+1, 0));
    precalc();
  }
  
  /*
    a[i][j] -> a[k][l] の和を求める。
    戻り値：long long
   */
  ll sum(int i, int j, int k, int l) {
    return S[k+1][l+1]-S[k+1][j]-S[i][l+1]+S[i][j];
  }
  
  /*
    長方形区間の最大の和を求める。O(N^4)
   */
  ll maxSum() {
    ll res = LLONG_MIN;
    for(int i=0; i<N_; i++)
      for(int j=0; j<M_; j++)
        for(int k=i; k<N_; k++)
          for(int l=j; l<M_; l++)
            res = max(res, sum(i, j, k, l));
    return res;
  }
  
};

int main() {
   
  int N; cin >> N;
  vector<vector<int> > a; a.resize(N, vector<int>(N));
  for(int i=0; i<N; i++)
    for(int j=0; j<N; j++)
      cin >> a[i][j];
  
  SumOf2DArray s(a);
  cout << s.maxSum() << endl;
   
  return 0;
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << max({a,b,c}) - min({a,b,c}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
  string S;
  cin >> S;

  if(S == "AAA" || S == "BBB"){
    cout << "No" << endl;
  }
  
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    string a, b;
    cin >> a >> b;
    string n = a + b;
    ll N = stoi(n);
    bool can = false;
    REP(i, N) {
        if (N == i*i) can = true;
    }
    if (can) cout << "Yes\n";
    else cout << "No\n";
}


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

int main(){

    int n;
    cin >> n;

    int number[4][3][10];
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int l=0; l<10; l++){
                number[i][j][l] = 0;
            }
        }
    }

    int b, f, r, v;

    for(int i=0; i<n; i++){
    cin >> b >> f >> r >> v;
    number[b-1][f-1][r-1] += v;
    }

    for(int i=0; i<3; i++){
        for(int j=0; j<10; j++){
            cout << " " << number[0][i][j];
        }
        cout << endl;
    }
    for(int i=0; i<20; i++){
        cout << '#';
    }
    cout << endl;

    for(int i=0; i<3; i++){
        for(int j=0; j<10; j++){
            cout << " " << number[1][i][j];
        }
        cout << endl;
    }
    for(int i=0; i<20; i++){
        cout << '#';
    }
    cout << endl;

    for(int i=0; i<3; i++){
        for(int j=0; j<10; j++){
            cout << " " << number[2][i][j];
        }
        cout << endl;
    }
    for(int i=0; i<20; i++){
        cout << '#';
    }
    cout << endl;

    for(int i=0; i<3; i++){
        for(int j=0; j<10; j++){
            cout << " " << number[3][i][j];
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

int main(void) {
    int a, b;

    cin >> a >> b;

    for (int i = 1; i <= 1000; i++) {
        if (i * 8/100 == a && i * 10/100 == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
typedef long long ll;
const int N = 100005 , Mod = 998244353 , G = 3 , INF = 0x3f3f3f3f;
double PI = acos(-1);

struct Virt{
    double x , y;
    Virt(double _x = 0.0 , double _y = 0.0):x(_x) , y(_y){}
};

Virt operator + (Virt x , Virt y){return Virt(x.x + y.x , x.y + y.y);}
Virt operator - (Virt x , Virt y){return Virt(x.x - y.x , x.y - y.y);}
Virt operator * (Virt x , Virt y){return Virt(x.x * y.x - x.y * y.y , x.x * y.y + x.y * y.x);}

int read(){
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1 ; ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}

int a[N];

int main(){
	int ans = 0 , n = read();
	for(int i = 1 ; i <= n ; i++){
		a[i] = read();
		ans += abs(a[i] - a[i - 1]);
	}
	a[n + 1] = 0; ans += abs(a[n + 1] - a[n]);
	for(int i = 1 ; i <= n ; i++)
		printf("%d\n",ans-abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]));
	return 0;
}

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

using namespace std;

const int MaxN = 1e5 + 15;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);

    int n;
    cin >> n;

    deque <long long> q;

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

        q.push_back(x);

        while(q.size() > 2 && (q.back() <= q[q.size() - 2] && q[q.size() - 2] >= q[q.size() - 3]))
        {
            long long a = q.back() - q[q.size() - 2] + q[q.size() - 3];
            q.pop_back();
            q.pop_back();
            q.pop_back();
            q.push_back(a);
        }
    }

    long long p = 0;

    int i = 1;
    while(!q.empty())
    {
        if(q.front() >= q.back())
        {
            p += i * q.front();
            q.pop_front();
        }else
        {
            p += i * q.back();
            q.pop_back();
        }
        i = -i;
    }

    cout << p << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iterator>
#include <cstring>
#include <queue>
using namespace std;

int a, b, c, d, e, f;
int best_p, best_q = 1;

bool moze[3005][3005];

bool valid(pair<int, int> p) {
	if (p.first + p.second > f) {
		return false;
	}
	// p.first / p.second > e / 100
	if (p.first * 100 > p.second * e) {
		return false;
	}
	return true;
}

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

	cin >> a >> b >> c >> d >> e >> f;

	queue<pair<int, int>> q;

	q.push({0, 0});

	while (!q.empty()) {
		auto pr = q.front(); q.pop();

		// op1
		pair<int, int> p[4];
		p[0] = {pr.first, pr.second + 100*a};
		p[1] = {pr.first, pr.second + 100*b};
		p[2] = {pr.first + c, pr.second};
		p[3] = {pr.first + d, pr.second};

		for (int i=0; i<4; i++) {
			if (valid(p[i]) && !moze[p[i].first][p[i].second]) {
				q.push(p[i]);
				moze[p[i].first][p[i].second] = true;

				if (p[i].first * best_q >= best_p * p[i].second) {
					best_p = p[i].first;
					best_q = p[i].second;
				}
			}
		}
	}

	cout << best_p + best_q << ' ' << best_p << '\n';
}

Measured memory_bytes: 4224
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)


int as[60];
int bs[60];
int cs[60];
int ds[60];

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  REP(i, n) {
    scanf("%d%d", &as[i], &bs[i]);
  }
  REP(i, m) {
    scanf("%d%d", &cs[i], &ds[i]);
  }
  REP(i, n) {
    int mini = 1234567890;
    int res = -1;
    REP(j, m) {
      int d = abs(as[i] - cs[j]) + abs(bs[i] - ds[j]);
      if(d < mini) {
        mini = d;
        res = j + 1;
      }
    }
    printf("%d\n", res);
  }
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
    Int N,M;
    cin >> N >> M;
    using tp = tuple<Int,Int>;
    vector<vector<tp>>edge(N);
    for(Int v = 0; v + 1 < N; ++v){
        edge[v + 1].emplace_back(v,0LL);
    }
    for(int i = 0; i < M; ++i){
        Int u,v,c;
        cin >> u >> v >> c; --u; --v;
        edge[u].emplace_back(v,c);
        edge[v].emplace_back(u,c);
    }
    constexpr Int inf = (1LL << 60);
    vector<Int>d(N,inf);

    priority_queue<tp,vector<tp>,greater<>>que;
    que.emplace(0,0);
    d[0] = 0;
    while(not que.empty()) {
        auto p = que.top(); que.pop();
        Int crt,v;
        tie(crt,v) = p;
        if(crt > d[v]) continue;
        for(auto tup : edge[v]){
            
            Int nv,cost;
            tie(nv,cost) = tup;
            if(cost + crt >= d[nv]) continue;
            d[nv] = cost + crt;
            que.emplace(d[nv],nv);
        }
    }
    cout << (d.back() == inf ? -1 : d.back()) << endl;
}


Measured memory_bytes: 13048
from heapq import heappush, heappop

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

q = reads()
s = q[0] + q[1] * 1j
t = q[2] + q[3] * 1j

N = read()

p = []; r = []
for i in range(N):
  q = reads()
  p.append(q[0] + q[1] * 1j)
  r.append(q[2])

# Nがsource, N+1がtarget
E = [[0]*(N+2) for _ in range(N+2)]
for i in range(N):
  for j in range(N):
    E[i][j] = max(abs(p[i] - p[j]) - r[i] - r[j], 0)

for i in range(N):
  E[N][i]   = E[i][N]   = max(abs(p[i] - s) - r[i], 0)
  E[N+1][i] = E[i][N+1] = max(abs(p[i] - t) - r[i], 0)

E[N][N+1] = E[N+1][N] = abs(t - s)

INF = 10**15 * 1.0

dist = [E[N][i] for i in range(N+2)] + [INF]
stab = [False] * (N+2)

stab[N] = True

for _ in range(N+1):
  i = N+2
  for j in range(N+2):
    if not stab[j] and dist[j] < dist[i]:
      i = j
  stab[i] = True
  for j in range(N+2):
    dist[j] = min(dist[j], dist[i] + E[i][j])

print(dist[N+1])


Measured memory_bytes: 35060
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
#include <string>
using namespace std;
using ll=long long;

typedef pair<int, int> P;

const int MAX_H=50;
const int MAX_W=50;
const int inf=100000000;
char maze[MAX_H+1][MAX_W+1];
int H,W;
int sx,sy;
int gx,gy;
int d[MAX_H][MAX_W];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            d[i][j]=inf;
        }
    }
    int white=0;
    for(int i=0;i<H;i++){
        string s;
        cin>>s;
        for(int j=0;j<W;j++){
            maze[i][j]=s[j];
            if(s[j]=='.'){
                white++;
            }
        }
    }
    sx=sy=0;
    gx=H-1;
    gy=W-1;

    queue<P> q;
    q.push(P(sx,sy));
    d[sx][sy]=0;
    while(q.size()){
        P p=q.front();q.pop();
        if (p.first==gx&&p.second==gy){
            break;
        }
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if (0<=nx&&nx<H&&0<=ny&&ny<W&&maze[nx][ny]!='#'&&d[nx][ny]==inf){
                q.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    if(d[gx][gy]!=inf){
        return white-(d[gx][gy]+1);
    }
    else{
        return -1;
    }
}


const int N_MAX=(100001);


int main(){
    int ans=bfs();
    //    cout<<white-(ans+1)<<endl;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int l,r;
  cin>>l>>r;
  if(r-l>1e4){
    cout<<0<<endl;
    return 0;
  }
  Int ans=2019;
  for(Int i=l;i<r;i++)
    for(Int j=i+1;j<=r;j++)
      chmin(ans,i*j%2019);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256