akhauriyash/Code-Regression huggingface dataset:
# Acceptance of input

import sys

file_input = sys.stdin

v_num, e_num = map(int, file_input.readline().split())

E = []
for line in file_input:
    s, t, w = map(int, line.split())
    E.append((w, s, t))


# Disjoint Set: Union Find Tree

# Implementation of disjoint sets by tree
# Compression of the path
# merge smaller tree to large tree

class DisjointSets:
    def __init__(self, size):
        # negative values are roots(representatives of each tree)
        # positive values represent the parent element
        self.table = [-1 for _ in range(size)]

    def _find(self, x):
        if self.table[x] < 0:
            return x
        else:
            # compression of the path
            self.table[x] = self._find(self.table[x])
            return self.table[x]

    def uniteSets(self, x, y):
        s1 = self._find(x)
        s2 = self._find(y)
        if s1 != s2:
            if self.table[s1] < self.table[s2]: # the smaller has more elements
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2

    def isDisjoint(self, x, y):
        if self._find(x) != self._find(y):
            return True
        else:
            return False


# Kruskal's algorithm

def kruskal(vertices_num, edges):
    edges.sort(reverse = True)
    S = DisjointSets(vertices_num)
    weight = 0

    while edges:
        w, s, t = edges.pop()
        if S.isDisjoint(s, t):
            S.uniteSets(s, t)
            weight += w

    print(weight)


# Output

kruskal(v_num, E)

Measured memory_bytes: 25316
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N = int(input())
A = list(map(int, input().split()))


r = 0  # index
cnt = 0
xorv = 0
sumv = 0
for l in range(0, N):
    while r < N and xorv ^ A[r] == sumv + A[r]:
        sumv += A[r]
        xorv ^= A[r]
        r += 1
    # print(l, r)
    cnt += r - l
    if l == r:
        r += 1
    else:
        sumv -= A[l]
        xorv = sumv
print(cnt)


Measured memory_bytes: 102856
N=int(input())
X=list(map(int,input().split()))
X.sort()
x_min=X[0]
x_max=X[N-1]
Min=10**10
for i in range(x_min,x_max+1):
    p=0
    for j in range(N):
        p+=(X[j]-i)**2
    if Min>p:
        Min=p
print(Min)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		// 標準入力
		Scanner scanner = new Scanner(System.in);
		String n = scanner.nextLine();
		String a = scanner.nextLine();
		String b = scanner.nextLine();
		String c = scanner.nextLine();

		int nInt = Integer.parseInt(n);

		int count = 0;

		for (int i=0; i<nInt; i++) {
			char charA = a.charAt(i);
			char charB = b.charAt(i);
			char charC = c.charAt(i);

			List<Character> listA = new ArrayList<Character>(Arrays.asList(charA, charB, charC));
	        List<Character> listB = new ArrayList<Character>(new HashSet<>(listA));

	        count += listB.size();
		}

		count -= nInt;

		System.out.println(count);

	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int N;
    ll W;
    cin >> N >> W;
    int vMax = 1000;
    ll dp[N + 1][N * vMax + 1];
    REP(i, N + 1) REP(j, N * vMax + 1) dp[i][j] = -1;

    REP(i, N + 1) dp[i][0] = 0;

    FOR(i, 1, N + 1) {
        ll w, v;
        cin >> w >> v;
        FOR(j, 1, N * vMax + 1) {
            ll t = 10000000000000;
            if (dp[i - 1][j] != -1) t = dp[i - 1][j];
            if (j - v >= 0) {
                if (dp[i - 1][j - v] != -1)
                    t = min(t, dp[i - 1][j - v] + w);
            }
            if (v >= j) t = min(t, w);
            if (t == 10000000000000) t = -1;
            dp[i][j] = t;
        }
    }

    ll ans = 0;
    REP(i, N + 1) {
        REP(j, N * vMax + 1) {
            if (dp[i][j] != -1) {
                if (dp[i][j] <= W && j > ans) ans = j;
            }
        }
    }

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


Measured memory_bytes: 79104
import sys
n, *CSF = list(map(int, sys.stdin.buffer.read().split()))
C = CSF[::3]
S = CSF[1::3]
F = CSF[2::3]


def solve(x):
    cur = 0
    for i in range(x, n - 1):
        y = cur % F[i]
        if S[i] > cur:
            cur = S[i] + C[i]
        elif y == 0:
            cur += C[i]
        else:
            cur += (F[i] - y) + C[i]
    return cur


for i in range(n - 1):
    print(solve(i))
print(0)


Measured memory_bytes: 69440
#include <iostream>
using namespace std;
int main( )
{
    int x,y;
     cin>>x>>y;
     if(x==2 || y==2)
     {
         cout<<"No";
     }
   else if(x==6 || x==4 || x==9 || x==11)
   {
       if(y==9 || y==11 || y==6 || y==4)
       {
           cout<<"Yes";
       }
       else
       {
           cout<<"No";
       }
   }
  else if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12)
   {
       if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12)
       {
           cout<<"Yes";
       }
       else
       {
           cout<<"No";
       }
   }
return 0;
}

Measured memory_bytes: 256
// AOJ DPL_4_A Coin Combination Problem
// 2018.5.9 bal4u
 
#include <stdio.h>
 
// 数値のハッシュ関数
#define HASHSIZ 5000011  //3456781
typedef struct { long long v; int f; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(long long n)
{
	HASH *p = hash + (int)(n % HASHSIZ);
	while (p->v) {
		if (p->v == n) return p->f;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(long long n)
{
	HASH *p = hash + (int)(n % HASHSIZ);
	while (p->v) {
		if (p->v == n) { p->f++; return; }
		if (++p == hashend) p = hash;
	}
	p->v = n, p->f = 1;
}

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

long long inLL()
{
    long long n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

long long a[1002], b[1002], c[1002], d[1002];

int main()
{
	int N, i, j;
	long long V, t, ans;

	N = in(), V = inLL();
	for (i = 0; i < N; i++) a[i] = inLL();
	for (i = 0; i < N; i++) b[i] = inLL();
	for (i = 0; i < N; i++) c[i] = inLL();
	for (i = 0; i < N; i++) d[i] = inLL();

	for (i = 0; i < N; i++) {
		if (a[i]+3 > V) continue;
		for (j = 0; j < N; j++) {
			t = a[i] + b[j];
			if (t+2 <= V) insert(t);
		}
	}

	ans = 0;
	for (i = 0; i < N; i++) {
		if (c[i]+3 > V) continue;
		for (j = 0; j < N; j++) {
			t = c[i] + d[j];
			if (t+2 <= V) ans += lookup(V-t);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 79888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

void solve(){
    ll n;
    cin>>n;
    vector<ll> a(n),b;
    rep(i,n) cin>>a[i];
    string s;
    cin>>s;
    for(int i=n-1;i>=0;i--){
        ll v=a[i];
        for(auto e:b) chmin(v,v^e);
        if(v){
            if(s[i]=='1'){
                cout<<1<<endl;
                return ;
            }
            b.push_back(v);
        }
    }
    cout<<0<<endl;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 3572
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		int c=0;
		int j=1;
		for(int i=0;i<n;i++) {
			if(j==a[i]) {
				j++;
			}else {
				c++;
			}
		}
		if(n==c)
			System.out.println(-1);
		else
			System.out.println(c);



	}

}


Measured memory_bytes: 85616
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, AB):
    g = defaultdict(set)

    for a, b in AB:
        g[a].add(b)
        g[b].add(a)

    ans = 0
    for ns in permutations(range(2, N+1), N-1):
        ns = list(ns)
        ns.insert(0, 1)
        for i in range(N-1):
            if ns[i+1] not in g[ns[i]]:
                break
        else:
            ans += 1
    return ans


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6084
n = int(input())
w = list(map(int, input().split()))

s1, s2 = 0, sum(w)
for i in range(n):
    s1 += w[i]
    s2 -= w[i]
    if s1 >= s2:
        ans = abs(s2 - s1)
        print(min(ans, 2 * w[i] - ans))
        break


Measured memory_bytes: 2940
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int a = reader.nextInt();
		int b = reader.nextInt();
		int c = reader.nextInt();
		int d = reader.nextInt();
		if (Math.abs(a-c) <= d || (Math.abs(a-b) <= d && Math.abs(b-c) <= d)) System.out.println("Yes");
		else System.out.println("No");
	}
	
	public static void solver() {
		// write logic
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


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

int main()
{
    int x;
    cin >> x;
    for(int a = 0; a <= 120; a++) {
        for(int b = -120; b <= 120; b++) {
            if(pow(a, 5) - pow(b, 5) == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4068
#include<stdio.h>

int main() {
	int N;
	scanf("%d", &N);
	long long zero = 2;
	long long one = 1;
	long long Returnval = 0;

	if (N == 1) {
		Returnval = 1;
	}
	for (int i = 2; i <= N; i++) {
		Returnval = zero + one;
		if (i == N) {
			break;
		}
		zero = one;
		one = Returnval;
	}
	printf("%lld\n", Returnval);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Item {
  string name;
  double value;
  Item() {;}
  Item(string name, double p, double a, double b, double c, double d, double e, double f, double s, double m) : name(name) {
    value = (m * s * f - p) / (a + b + c + (d + e) * m);
  }
  bool operator<(const Item &rhs) const {
    if (fabs(value - rhs.value) > EPS) { return value > rhs.value; }
    return name < rhs.name;
  }
};

int n;
Item item[100];

int main() {
  while (scanf("%d", &n), n) {
    REP(i, n) {
      string name;
      double p, a, b, c, d, e, f, s, m;
      cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      item[i] = Item(name, p, a, b, c, d, e, f, s, m);
    }
    sort(item, item + n);
    REP(i, n) {
      cout << item[i].name << endl;
    }
    puts("#");
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long               ll;
const int mod = 1e9+7;
#ifndef M_PI
#define M_PI acos(-1.0)
#endif

bool res = true;

struct node{
	ll stones;
	vector<ll> below;
	set<node *> con;
	bool vis=false;
	void dfs(){
		if(res && con.size()<=1 && !vis){
			vis = true;
			sort(below.begin(), below.end());
			ll below_tot=0;
			for(int i = 0; i<(int)below.size() -1; ++i){
				below_tot += below[i];
			}
			ll min_above=0;
			if(!below.empty()){
				min_above = max(0LL, below.back()-below_tot);
				below_tot += below.back();
			}
			if(stones > below_tot){
				res = false;
				return;
			}
			ll above = 2*stones-below_tot;
			if(above < min_above){
				res = false;
				return;
			}
			if(con.size() == 1){
				(*con.begin())->below.push_back(above);
				(*con.begin())->con.erase(this);
				(*con.begin())->dfs();
			}
			else if(above != 0){
				res = false;
				return;
			}
		}
	}
};


int main(){
	int n;
	cin>>n;
	vector<node> tree(n+1);
	for(int i=1; i<=n; ++i){
		scanf("%lld", &tree[i].stones);
	}
	for(int i=1; i<n; ++i){
		int a, b;
		scanf("%d %d", &a, &b);
		tree[a].con.insert(&tree[b]);
		tree[b].con.insert(&tree[a]);
	}
	for(int i=1; i<=n; ++i){
		if(tree[i].con.size() <= 1){
			tree[i].below.push_back(tree[i].stones);
		}
	}
	for(int i=1; i<=n; ++i){
		tree[i].dfs();
	}
	if(res){
		cout<<"YES\n";
	}
	else{
		cout<<"NO\n";
	}
	return 0;
}


Measured memory_bytes: 24576
#include<bits/stdc++.h>
using namespace std;
char mapn[10][10];
int main()
{
	int n,m,h;
	cin>>n>>m>>h;
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	{
		cin>>mapn[i][j];
	}
	int ans=0;
	for(int i=0;i<=(1<<n)-1;i++)
	for(int j=0;j<=(1<<m)-1;j++)
	{
		int black=0;
	    for(int f=0;f<n;f++)
	    for(int w=0;w<m;w++)
	    {
	    	int e=(i>>f)&1;
	    	int g=(j>>w)&1;
	    	if(!e&&!g&&mapn[f][w]=='#')black++;
		}
		if(black==h)ans++;
	}	
	cout<<ans<<endl;
}

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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		int a, b, c;
		cin >> a >> b >> c;
		if(c > b) swap(b, c);
		if(b > a) swap(a, b);
		if(a * a == b * b + c * c){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main(){
	unsigned long long int a,b,c,d;
	
	cin>>a>>b;
	if(a*2>=b){
	d=b/2;
	cout<<d;			
	}
	else {
	c = b-a*2;
	d = a+c/4;
	cout<<d;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000000000

int main(){
	
	long long N,A,B;
	cin>>N>>A>>B;
	
	vector<long long> X(N);
	for(int i=0;i<N;i++)cin>>X[i];
	long long ans = 0;
	
	for(int i=0;i<N-1;i++){
		long long k = A * (X[i+1]-X[i]);
		ans += min(k,B);
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 1024
using System;

namespace DPL_1_D_Longest_Increasing_Subsequence
{
	class Program
	{
		static void Main ( string[] args )
		{
			int inputCount = int.Parse (Console.ReadLine ());
			int[] elements = new int[inputCount];

			for (int lp = 0; lp < inputCount; lp++)
			{
				elements[lp] = int.Parse (Console.ReadLine ());
			}

			var result = LongestIncreasingSubsequence (elements);
			Console.WriteLine (result);
		}

		static int LongestIncreasingSubsequence ( int[] numArray )
		{
			int[] temporaryArray = new int[numArray.Length];
			temporaryArray[0] = numArray[0];
			int length = 1;

			for (int lp = 1; lp < numArray.Length; lp++)
			{
				if (temporaryArray[length - 1] < numArray[lp])
				{
					temporaryArray[length++] = numArray[lp];
				}
				else
				{
					int index = LowerBound (temporaryArray, 0, length, numArray[lp]);
					temporaryArray[index] = numArray[lp];
				}
			}

			return length;
		}

		static int LowerBound ( int[] numArray, int lowerIndex, int upperIndex, int element )
		{
			while (1 < upperIndex - lowerIndex)
			{
				int middleIndex = (lowerIndex + upperIndex) / 2;

				if (numArray[middleIndex] < element)
				{
					lowerIndex = middleIndex;
				}
				else
				{
					upperIndex = middleIndex;
				}
			}

			if (numArray[lowerIndex] < element)
			{
				return upperIndex;
			}
			else
			{
				return lowerIndex;
			}
		}
	}
}



Measured memory_bytes: 10276
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <bitset>
#include <math.h>
using namespace std;
int main(){
  int N, M, X, ans = 1000000000, cost, jyou = 1;
  bitset<13> b;
  bool flag;
  cin >> N >> M >> X;
  int C[N], A[N][M], rikai[M];
  for (int i = 0; i < N; i++){
    cin >> C[i];
    for (int j = 0; j< M; j++){
      cin >> A[i][j];
    }
  }
  for (int i = 0; i<N; i++) jyou *= 2;
  for (int i = 1; i < jyou; i++){
    b = i;
    for (int k = 0; k < M; k++) rikai[k] = 0;
    flag = true;
    cost = 0;
    for (int j = 0; j < N; j++){
      if (b[j]==1){
        cost += C[j];
        for (int k = 0; k < M; k++) rikai[k] += A[j][k];
      }
    }
    for (int k = 0; k < M; k++) {
      if (rikai[k] < X) flag = false;
    }
    if (flag){
      if (ans > cost) ans = cost;
    }
  }
  if (ans != 1000000000) cout << ans << endl;
  else cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
using namespace std;

int main(){
    string str;
    int st,ed;
    cin >> str;
    for(int i=0;i<str.size();i++){
        if(str[i]=='A'){
             st=i;
             break;
        }
    }
    for(int i=str.size()-1;i>0;i--){
        if(str[i]=='Z'){
             ed=i;
             break;
        }
    }
    cout << ed-st+1 << endl;
    return 0;
}


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

using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int  ll;
typedef unsigned long long int llu;

int main(void){

    int n,m;
    cin >> n >>m;

    vector<int> ar(n);
    int sum =0;
    for(int i=0;i<n;i++)
    {cin >> ar[i];
        sum+=ar[i];
    }

    double ck = (double)sum/(4*m*1.0);
    int cnt=0;
    for(int i=0;i<n;i++){
        if(ar[i]>=ck){
            cnt++;
        }
    }

    if(cnt>=m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int N, K;
    int di;
    cin >> N >> K;
    vector<int> d(K);
    vector<vector<int>> A(K,vector<int>(100));
    for(int i=0; i<K; i++){
        cin >> d.at(i);
        for(int j=0; j<d.at(i); j++){
            cin >> A.at(i).at(j);
        }
    }
    int count=0;
    vector<int> memory;
    int judge=0;
    for(int i=0; i<K; i++){
        for(int j=0; j<d.at(i); j++){
            for(int k=0; k<memory.size(); k++){
                if(A.at(i).at(j)==memory.at(k)){
                    judge=1;
                }
            }
            if(judge==0){
                memory.push_back(A.at(i).at(j));
            }
            judge=0;
        }
    }
    cout << N-memory.size() << endl;
}

Measured memory_bytes: 3676
using System;

namespace ConsoleApp8
{
	class Program
	{
		
		static void Main(string[] args)
		{
			var count = int.Parse(Console.ReadLine());
			int time;
			int ptime = 0;
			int x;
			int px = 0;
			int y;
			int py = 0;
			var flg = true;
			for (int i = 0; i < count; i++)
			{
				var arr = Console.ReadLine().Split(' ');
				time = int.Parse(arr[0]);
				x = int.Parse(arr[1]);
				y = int.Parse(arr[2]);

				// 移動可能両
				var val = time - ptime;
				// 移動量の合計
				// まとめてX移動させた後にY移動させても結果一緒
				var hoge = Math.Abs(x - px) + Math.Abs(y - py);			
				if (val < hoge || val % 2 != hoge % 2)
				{
					flg = false;
					break;
				}
				px = x;
				py = y;
				ptime = time;
			}
			Console.WriteLine(flg ? "Yes" : "No");
		}
	}
}

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

int main(){
  int N; cin >> N;
  vector<double> v(N);
  for(int i=0; i<N; i++) cin >> v[i];
  sort(v.begin(),v.end());
  
  double result=v[0];
  for(int i=1; i<N; i++){
    result+=v[i];
    result/=2;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll a;
    string s;
    cin>>a>>s;
    cout<<(a>=3200?s:"red")<<endl;
    return 0;
}

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = [2]
        for j in range(4, m, 2):
            a[j] = False
        for i in range(3, m, 2):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False
        self.ds_memo = {}
        self.ds_memo[1] = set([1])

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    # memo
    def divisions(self, n):
        if n in self.ds_memo:
            return self.ds_memo[n]

        for c in self.T:
            if n % c == 0:
                rs = set([c])
                for cc in self.divisions(n // c):
                    rs.add(cc)
                    rs.add(cc * c)
                self.ds_memo[n] = rs
                return rs

        rs = set([n])
        self.ds_memo[n] = rs
        return rs


def main():
    n = I()

    pr = Prime(10**12)
    d = list(pr.division(n))
    r = 0
    l = len(d)
    for i in range(1, 2**l):
        t = [d[j] for j in range(l) if 2**j & i]
        m = min(map(lambda x: x[1], t))
        ok = True
        for k,v in t:
            if v % m > 0:
                ok = False
                break
        if not ok:
            continue
        for j in range(1,m+1):
            if m % j > 0:
                continue
            mk = m // j
            u = 1
            for k,v in t:
                u *= k**((v//m)*mk)
            nn = n
            while nn % u == 0:
                nn //= u
            if nn % u == 1:
                r += 1
            # print("u",u,j,nn,r)

    d = pr.division(n-1)
    # print("d",d)
    k = 1
    for _,v in d:
        k *= v + 1
    r += k - 1

    return r

print(main())





Measured memory_bytes: 17724
/**
*    author:  souzai32
*    created: 14.08.2020 14:53:26
**/

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

int main() {

    int n;
    cin >> n;
    vector<long long> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());

    int count=1;
    rep(i,n-1){
        if(a.at(i)*2>=a.at(i+1)) count++;
        else count=1;
        a.at(i+1)+=a.at(i);
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3960
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i] << " "; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif
   

   int n;
   cin >> n;
   map<string,int>mp;
   string s;
   for(int i = 0 ; i < n ; i++){
    cin >> s;
    mp[s]++;
   }
cout << "AC x " << mp["AC"] << "\n";
cout << "WA x " << mp["WA"] << "\n";
cout << "TLE x " << mp["TLE"] << "\n";
cout << "RE x " << mp["RE"] ;

}


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

using namespace std;

int main()
{
    int kind,a,b;
    while(cin >> kind){
        if(kind == 1){
            cout << "Hello World" << endl;
        } else {
            cin >> a >> b;
            cout << (a+b) << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int A[10000] = {};
    int n = 0;
    std::cin >> n;
    int input_value;
    int max_value = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> input_value;
        A[input_value]++;
        if (input_value > max_value) {
            max_value = input_value;
        }
    }

    for (int i = 0; i < 10000; i++) {
        for (int j = 0; j < A[i]; j++) {
            std::cout << i;
            if (j != A[i] - 1) {
                std::cout << " ";
            } else if (i == max_value) {
                std::cout << std::endl;
            } else {
                std::cout << " ";
            }
        }
    }
}



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

int main(){
    char s;
    cin >> s;
    if(s >= 65 && s < 91){
        cout << 'A' << endl;
    }else{
        cout << 'a' << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll N,K;
  ll p[11111];
  ll i;
  cin >> N >> K;
  for(i=0;i<=N-1;i++)
    cin >> p[i];
  sort(p,p+N);
  ll ans = 0;
  for(i=0;i<=K-1;i++)
    ans += p[i];
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
    int A,B,K,i;
    int count = 0;
    scanf("%d %d %d",&A,&B,&K);
    
    for(i = B ; i > 0 ; i--){
        if(A%i == 0 && B%i == 0){
            count++;
        }
        if(count == K)
            break;
    }
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() throws IOException{
		String str;
		while ((str = br.readLine()) != null) {
			String[] s = str.split(",");
			int[] a = new int[10];
			int sum = 0;
			for (int i=0; i<10; i++) {
				a[i] = Integer.parseInt(s[i]);
				sum += a[i];
			}

			int v1 = Integer.parseInt(s[10]);
			int v2 = Integer.parseInt(s[11]);

			double r = (double)sum*v1/(v1+v2);

			sum = 0;
			for (int i=0; i<10; i++) {
				sum += a[i];
				if (r <= sum) {
					out.println((i+1));
					break;
				}
			}
		}
	}

	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		br.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 24276
import { readFileSync } from 'fs'

function main(input: string) {
  const rains = input.split(/S+/g)
  const days = (rains.map(s => s.length))
  const result = Math.max(...days)

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 29604
#include <stdio.h>
#include <math.h>

#include <iostream>
#include <vector>
#include <algorithm>

int H, W;
std::vector<std::string> S;

std::vector<std::vector<int>> H_light, W_light;
int max = 0;

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

	for( int i = 0; i <= H; i++ )
	{
		if( i < H )
		{
			char s[2002];
			scanf("%s", s);
			S.push_back(s);
		}

		std::vector<int> L;
		for( int j = 0; j <= W; j++ )
		{
			L.push_back(0);
		}
		H_light.push_back(L);
		W_light.push_back(L);
	}

	int w_tmp = 0, h_tmp = 0;
	int w_sta = -1;

	std::vector<int> h_sta;
	for( int j = 0; j <= W; j++ )
	{
		h_sta.push_back(-1);
	}

	for( int i = 0; i <= H; i++ )
	{
		for( int j = 0; j <= W; j++ )
		{
			if( i == H || j == W || S[i][j] == '#' )
			{
				w_tmp = j - w_sta - 1;
				h_tmp = i - h_sta[j] - 1;

				if( w_tmp > 0 )
				{
					for( int w = w_sta + 1; w < j; w++ )
					{
						W_light[i][w] = w_tmp;
						//printf("W_light[%d][%d]:%d\n", i, w, w_tmp);
					}
				}

				if( h_tmp > 0 )
				{
					for( int h = h_sta[j] + 1; h < i; h++ )
					{
						H_light[h][j] = h_tmp;
						//printf("H_light[%d][%d]:%d\n", h, j, h_tmp);
					}
				}

				w_sta = j;
				h_sta[j] = i;
			}
		}
		w_sta = -1;
	}

	int max = 0, tmp = 0;
	for( int i = 0; i < H; i++ )
	{
		for( int j = 0; j < W; j++ )
		{
			if( W_light[i][j] > 0 && H_light[i][j] > 0 )
			{
				//printf("W_light[%d][%d]:%d H_light[%d][%d]:%d\n", i, j, W_light[i][j], i, j, H_light[i][j]);
				
				tmp = W_light[i][j] + H_light[i][j];
				if( max < tmp ) max = tmp;
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 35968
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    vector<int> cp = A;
    sort(all(cp));
    int a = cp[N-1];
    int b = cp[N-2];

    for (int i = 0; i < N; i++) {
        if (A[i] == a) cout << b << endl;
        else cout << a << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int a, b;
  cin >> a >> b;
  cout << a-1 + (a <= b) << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

template <std::uint_fast64_t Modulus>
class modint {
  using u64 = std::uint_fast64_t;

 public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  using mint = modint<MOD>;

  cin >> x >> y;
  if ((x + y) % 3 != 0)
    Cout(0);
  else {
    sum = (x + y) / 3;
    k = -1;
    rep(i, sum + 1) {
      //+2をi回
      if (2 * i + (sum - i) == x) {
        k = i;
        break;
      }
    }
    if (k + (sum - k) * 2 != y) {
      Cout(0);
      return 0;
    }
    if (k == -1) {
      Cout(0);
      return 0;
    }
    mint ans = mint(1);
    rrep(i, 1, sum + 1) ans *= i;
    mint hiku1 = mint(1), hiku2 = mint(1);
    rrep(i, 1, k + 1) hiku1 *= i;
    rrep(i, 1, sum - k + 1) hiku2 *= i;
    ans = (ans / hiku1) / hiku2;
    Cout(ans.value());
  }
  return 0;
}


Measured memory_bytes: 256
"use strict"
function Main(stdin){
stdin = stdin.trim().split("\n").reverse();
let stdout = [];
function input(){return stdin.pop()};
function maput(){return input().split(" ").map(n=>parseInt(n))};
function print(x){stdout.push(x)};
function exist(x, xs){return new Set(xs).has(x)}
function max(x){return x.reduce(function(a,b){ return Math.max(a,b) }) }
function min(x){return x.reduce(function(a,b){ return Math.min(a,b) }) }
function sum(x){return x.reduce(function(a,b){ return a+b }) }
function sorting(x, index){x.sort((a, b) => a[index] - b[index])}
function all(x){return x.reduce(function(a,b){ return a && b }) }
function any(x){return x.reduce(function(a,b){ return a || b }) }
function list(iterable){return Array.from(iterable)}
function vint(iterable){return Array.from(iterable, x => parseInt(x))}
function tile(val, len){return Array(len).fill(val)}
const range = (start, stop, step) => Array.from(
    { length: (stop - start) / step }, (_, i) => start + (i * step));
/*START*/


let n = parseInt(input())
let a = maput()
let amax = max(a)
let asum = sum(a)
if (asum - amax > amax){
    print("Yes")
}else{
    print("No")
}




/*END*/
stdout = stdout.join("\n");
console.log(stdout);
return stdout
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    ll n,h,w;
    cin>>h>>w>>n;
    ll si,sj;
    cin>>si>>sj;
    string S,T;
    cin>>S>>T;

    //青木が勝てる開区間を考える
    bool a1=true;
    ll lw=0,up=h+1;
    for(int i=n-1;i>=0;i--){
        if(T[i]=='U'){
            if(up<=h) up++;
        }
        else if(T[i]=='D'){
            if(lw>0) lw--;
        }
        if(up-lw<=1){
            a1=false;break;
        }
        if(S[i]=='D'){
            up--;
        }
        else if(S[i]=='U'){
            lw++;
        }
        if(up-lw<=1){
            a1=false;break;
        }
    }
    if(lw<si&&si<up) a1=true;
    else a1=false;

    bool a2=true;
    lw=0,up=w+1;
    for(int i=n-1;i>=0;i--){
        if(T[i]=='L'){
            if(up<=w) up++;
        }
        else if(T[i]=='R'){
            if(lw>0) lw--;
        }
        if(up-lw<=1){
            a2=false;break;
        }
        if(S[i]=='R'){
            up--;
        }
        else if(S[i]=='L'){
            lw++;
        }
        if(up-lw<=1){
            a2=false;break;
        }
    }
    if(lw<sj&&sj<up) a2=true;
    else a2=false;


    if(a1&&a2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 776
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    ll mi=E;
    ll ans=-E;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        ans=max(ans,a-mi);
        mi=min(mi,a);
    }
    cout<<ans<<endl;
    
    
    return 0;
}



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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    ans+=(n-k)*(n-k+1)/2;
    if(k==0){
        ans-=n;
    }
    for(ll i=k+1;i<=n;i++){
        ll md=i-k;//余りが何種存在するか
        ans+=md*(n/i-1);//mdを何サイクルするか
        if(n%i>=k){
            ans+=(n%i)-k+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
bool g[125][121];

bool vstd[125];
int dfs(int p){
  int ret = 1;
  vstd[p] = true;
  REP(to,n)if(!vstd[to] && g[p][to]){
    ret += dfs(to);
  }
  return ret;
}

int main(){
  scanf("%d",&n);
  // FOR(_n,3,101){
    // n = _n;
    REP(i,125)REP(j,121)g[i][j] = false;
    g[0][2] = g[2][0] = true;
    g[1][2] = g[2][1] = true;
    FOR(x,4,n+1){
      if(x%2==0){
        FORR(i,0,x-1)FORR(j,0,x-1){
          g[i+1][j+1] = g[i][j];
          g[i][j] = false;
        }
        FOR(i,1,x-1)g[0][i] = g[i][0] = true;
      }else{
        REP(i,x-1)g[i][x-1] = g[x-1][i] = true;
      }
    }
    // puts("#####");
    // printf("n:%d\n",n);
    // REP(i,n){
    //   REP(j,n)printf("%c",g[i][j] ? 'o' : ' ');puts("");
    // }
    // puts("#####");
    // puts("");
    bool ok = true;
    fill(vstd, vstd+n, false);
    if(dfs(0) != n){
      ok = false;
    }
    int x = -1;
    if(ok)REP(i,n){
      int s = 0;
      REP(j,n)if(g[i][j])s += j+1;
      if(x==-1){
        x = s;
      }else if(x != s){
        ok = false; break;
      }
    }
    if(!ok){
      printf("n%d : failed\n",n);
    }else{
      int m = 0;
      REP(i,n)REP(j,i)if(g[i][j])m++;
      printf("%d\n",m);
      REP(i,n)REP(j,i)if(g[i][j])printf("%d %d\n",i+1,j+1);
    }
  // }
  // int m = n*(n-1)/2;
  // REP(msk,1<<m){
  //   int it = 0;
  //   REP(i,n)REP(j,i){
  //     bool o = (msk>>it&1)==1;
  //     it++;
  //     g[i][j] = g[j][i] = o;
  //   }
  //   int x = -1;
  //   bool ok = true;
  //   fill(vstd, vstd+n, false);
  //   if(dfs(0) != n){
  //     ok = false;
  //   }
  //   if(ok)REP(i,n){
  //     int s = 0;
  //     REP(j,n)if(g[i][j])s += j+1;
  //     if(x==-1){
  //       x = s;
  //     }else if(x != s){
  //       ok = false; break;
  //     }
  //   }
  //   if(ok){
  //     puts("#####");
  //     REP(i,n){
  //       REP(j,n)printf("%c",g[i][j] ? 'o' : ' ');puts("");
  //     }
  //     puts("#####");
  //     puts("");
  //   }
  // }
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}
int freq[10];
bool check(int n){
    while(n!=0){
       if(freq[n%10])return false;
        n/=10;
    }
    return true;
}

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

    for (int i = 0; i < m; ++i) {
        int a;
        cin >> a;
        freq[a]++;
    }
    for (int j = n; j <=1000000 ; ++j) {
        if(check(j))return cout<<j,0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(a<b)return gcd(b,a);
  else if(a%b)return gcd(b,a%b);
  else return b;
}
int main(){
  int n;
  cin>>n;
  int a;
  cin>>a;
  int x=a;
  for(int i=0; i<n-1; i++){
    cin>>a;
    x=gcd(a,x);
  }
  cout<<x<<endl;

}


Measured memory_bytes: 256