akhauriyash/Code-Regression huggingface dataset:
h, w, n = gets.split.map(&:to_i)
sr, sc = gets.split.map(&:to_i)
takahashi = gets.chomp
aoki = gets.chomp

aoki_win_left = 1
aoki_win_right = w
(n - 1).downto(0) do |i|
  case aoki[i]
  when "R"
    aoki_win_left -= 1 if aoki_win_left > 1
  when "L"
    aoki_win_right += 1 if aoki_win_right < w
  end
  case takahashi[i]
  when "R"
    aoki_win_right -= 1
  when "L"
    aoki_win_left += 1
  end
  if aoki_win_right < aoki_win_left
    puts "NO"
    exit
  end
end

aoki_win_up = 1
aoki_win_down = h
(n - 1).downto(0) do |i|
  case aoki[i]
  when "D"
    aoki_win_up -= 1 if aoki_win_up > 1
  when "U"
    aoki_win_down += 1 if aoki_win_down < h
  end
  case takahashi[i]
  when "D"
    aoki_win_down -= 1
  when "U"
    aoki_win_up += 1
  end
  if aoki_win_down < aoki_win_up
    puts "NO"
    exit
  end
end

if sr.between?(aoki_win_up, aoki_win_down) && sc.between?(aoki_win_left, aoki_win_right)
  puts "YES"
else
  puts "NO"
end


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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};

int main() {
	string s;
	cin >> s;
	int ans = 100000000;
	for (int i = 0;i < s.size() - 2;i++) {
		int x = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
		ans = min(ans,abs(x-753));
	}
	cout << ans << endl;
}

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

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<long long> m(n);

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

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            if (j % 2 == 0) {
                m[i] += a[(i+j)%n];
            } else {
                m[i] -= a[(i+j)%n];
            }
        }
    }

    for (int i = 2; i < n; i++) {
            m[i] = m[i-2];
            m[i] += 2 * a[(i-1)%n];
            m[i] -= 2 * a[(i-2)%n];
    }

    for (int i = 0; i < n; i++) {
        cout << m[i];
        if (i == n-1) cout << endl;
        else cout << ' ';
    }

    return 0;
}



Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

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;
}

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

ll solve(ll N,vector<P> cnt) {
    if(cnt.empty()) {
        return N;
    }
    if(cnt.size() == 1) {
        ll count = N / cnt.at(0).first;
        chmax(N,N - cnt.at(0).first * count + count * cnt.at(0).second);
    }
    else if(cnt.size() == 2) {
        ll ret = 0;
        for(int i = 0;i <= N / cnt.at(0).first;i++) {
            ll count1 = i;
            ll count2 = (N - count1 * cnt.at(0).first) / cnt.at(1).first;
            if(count2 < 0) {
                break;
            }
            chmax(ret,N - count1 * cnt.at(0).first - count2 * cnt.at(1).first + count1 * cnt.at(0).second + count2 * cnt.at(1).second);
        }
        N = ret;
    }
    else if(cnt.size() == 3) {
        ll ret = 0;
        for(int i = 0;i <= N / cnt.at(0).first;i++) {
            ll count1 = i;
            for(int j = 0;j <= (N - count1 * cnt.at(0).first) / cnt.at(1).first;j++) {
                ll count2 = j;
                ll count3 = (N - count1 * cnt.at(0).first - count2 * cnt.at(1).first) / cnt.at(2).first;
                if(count3 < 0) {
                    break;
                }
                chmax(ret,N - count1 * cnt.at(0).first - count2 * cnt.at(1).first - count3 * cnt.at(2).first + count1 * cnt.at(0).second + count2 * cnt.at(1).second + count3 * cnt.at(2).second);
            }
        }
        N = ret;
    }
    return N;
}

int main() {
    ll N;
    cin >> N;
    ll A,B,C;
    cin >> A >> B >> C;
    ll D,E,F;
    cin >> D >> E >> F;
    vector<P> First;
    vector<P> Second;
    if(A > D) {
        Second.push_back(P(D,A));
    }
    else if(A < D) {
        First.push_back(P(A,D));
    }
    if(B > E) {
        Second.push_back(P(E,B));
    }
    else if(B < E) {
        First.push_back(P(B,E));
    }
    if(C > F) {
        Second.push_back(P(F,C));
    }
    else if(C < F) {
        First.push_back(P(C,F));
    }
    N = solve(N,First);
    N = solve(N,Second);
    cout << N << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;



int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if(s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<vector<Int>> imos(30,vector<Int>(100010));

	Int N, C;
	cin >> N >> C;

	Int s, t, c;
	for (Int i = 0; i < N; i++) {
		cin >> s >> t >> c;
		
		//[s,t)であるが、録画開始に時間がかかることを考慮すると[s-1,t)にすればよい
		//しかし、上記手法だと開始時間がマイナスに振れる可能性があるので、時間を後ろに1だけずらして[s,t]であると考える（答えは同じになる）
		s--;
		c--;
		//tのみデクリメントしていないことに注意
		imos[c][s]++;
		imos[c][t]--;
	}

	for (Int c = 0; c < C; c++) {
		for (Int i = 1; i < 100010; i++) {
			imos[c][i] += imos[c][i - 1];
		}

		//同じチャンネル内で複数録画機が必要な状況は生じないため、2以上は1に戻す
		for (Int i = 0; i < 100010; i++) {
			if (imos[c][i])imos[c][i] = 1;
		}
	}

//各時間において使われている録画機の台数
	Int cnt;
	Int ans = 0;
	for (Int i = 0; i < 100010; i++) {
		cnt = 0;
		for (Int c = 0; c < C; c++) {
          	if (imos[c][i] != 0 && imos[c][i] != 1) exit(-1);
			if (imos[c][i])cnt++;
		}
		ans = max(ans, cnt);//最大値
	}

	cout << ans << "\n";

}


Measured memory_bytes: 24576
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;

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

const int MAX_N=1<<17; 
const int INF=INT_MAX;
int N,dat[2*MAX_N-1];

void init(int n)
{
    N=1; while(N<n) N*=2;
    REP(i,2*N-1) dat[i]=INF;
}

void print()
{
    int num=1,idx=0;
    while(num<=N){
	REP(i,num) cout<<dat[idx++]<<' ';
	cout<<endl;
	num*=2;
    }
}

void update(int k,int x)
{
    k+=N-1; dat[k]=x;
    while(k>0){
	k=(k-1)/2;
	dat[k]=min(dat[2*k+1],dat[2*k+2]);
    }
}

int find(int a,int b,int k,int l,int r)
{
    if(r<=a or b<=l) return INF;

    if(a<=l and r<=b) return dat[k];
    else{
	int vl=find(a,b,2*k+1,l,(l+r)/2);
	int vr=find(a,b,2*k+2,(l+r)/2,r);
	return min(vl,vr);
    }
}


signed main()
{
    int n,q; cin>>n>>q;
    init(n);

    REP(i,q){
	int com,x,y; cin>>com>>x>>y;
	if(com==0) update(x,y);
	else cout<<find(x,y+1,0,0,N)<<endl;
    }
    
}



Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
double x,nw=100.0;
int ans=0;
int main()
{
	cin>>x;
	while(nw<x)
	{
		ans++;
		nw+=(long long)(nw*0.01);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define foru(i,a,b) for (int i=int (a);i<=int(b);i++)

using namespace std;
const int N=5010;
int n,m,a[N],b[N],luu[1010],f[N],ma[N];

int main() {
    //freopen("cardgame.inp","r",stdin);
    //freopen("cardgame.out","w",stdout);
    cin >>n>>m;
    foru(i,1,n) cin >> a[i];
    foru(i,1,m) cin >> b[i];
    int res=0;
    foru(j,1,m) {
        foru(i,1,n){
            if (a[i]==b[j]) {
                f[i]=max(f[i],luu[b[j-1]]+1);
                res=max(res,f[i]);
            }
            luu[a[i]]=max(luu[a[i]],ma[i]);
        }
        foru(i,1,n) ma[i]=f[i];
        foru(i,1,n) luu[a[i]]=0,f[i]=0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;
public class Main
{
	public void solve()
	{
		Scanner cin = new Scanner(System.in);
		while(true)
		{
			int M = 256;
			int N = cin.nextInt();
			if(N == 0)break;
			int[] L = new int[N];
			for(int i = 0;i < N;i++)
			{
				L[i] = cin.nextInt();
			}
			int S = 0,A = 0,C = 0;
			double minH = Double.MAX_VALUE;
			for(int s = 0;s <= 15;s++)
			{
				for(int a = 0;a <= 15;a++)
				{
					for(int c = 0;c<=15;c++)
					{
						int[] R = new int[N];
						int[] O = new int[256];
						for(int i = 0;i < N;i++)
						{
							if(i == 0)
							{
								R[i] = (a * s + c) % M;
							}else
							{
								R[i] = (a * R[i - 1] + c)%M;
							}
						}
						for(int i = 0;i < N;i++)
						{
							O[(L[i] + R[i]) % M]++;
						}
						
						double h = 0.0;
						for(int i = 0;i < 256;i++)
						{
							if(O[i] == 0)continue;
							h -= (double)O[i] / N * Math.log((double)O[i] / N);
						}
						
						if(h + 1e-10 < minH)
						{
							minH = h;
							S = s;
							A = a;
							C = c;
						}
					}
				}
			}
			System.out.println(S + " " + A + " " + C);
		}
	}
	public static void main(String[] args)
	{
		new Main().solve();
	}
}

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

using namespace std;

int main(){
  int N, counter, sum;
  int j;
  bool ch;
  cin >> N;
  counter = N;
  sum = 0;
  ch = true;
  for(int i=0; i<6;i++){
    if(N == pow(10,i))sum = 10,ch=false;
  }
  for(int i=0; i<6;i++){
    if(ch){
      sum+=N%10;
      N/=10;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

x = int(input())
a = int(input())
b = int(input())

print( (x-a)%b )


Measured memory_bytes: 9040
n,m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))
    
ab = sorted(ab,key = lambda x:x[1])
del ab[-1]
cnt = 0
for asd in ab:
    if (asd[0]<n):
        cnt += (n-asd[0])
print(cnt)


Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';
ll pow2(ld x) {
  ll cnt=0;
  while(x>1) {x/=2; cnt++;}
  return cnt;
}

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

  cout << fixed << setprecision(30);
  
  ld n, k;
  cin >> n >> k;
  
  ld ans=0, one=1;
  rep2(i, n) ans+=one/(1LL << pow2(k/i));
  
  cout << ans/n << newl;
  return 0;
}

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

using ll = long long;
using Pi = pair < int, int >;

constexpr int INF = (1 << 30) - 1;
constexpr int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
constexpr int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

template < typename T > T gcd(T a, T b) { return ( b ? gcd(b, a % b) : a ); }
template < typename T > T lcm(T a, T b) { return ( a / gcd(a, b) * b ); }

int main()
{
	int rui[505][505] = {};
	
	int N, M, Q;
	
	cin >> N >> M >> Q;
	while ( M-- ) {
		int l, r;

		cin >> l >> r;

		rui[r][l]++;
	}

	for ( int i = 1; i <= N; i++ ) {
		for ( int j = N; j >= 1; j-- ) {
			rui[i][j] += rui[i - 1][j];
			rui[i][j] += rui[i][j + 1];
			rui[i][j] -= rui[i - 1][j + 1];
		}
	}

	while ( Q-- ) {
		int p, q;
		cin >> p >> q;
		cout << rui[q][p] << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 1920
var n,a,b,c:integer;
 
begin
  readln(n);
  a:=n div 100;n:=n - a*100;
  b:=n div 10; n:=n-b*10;
  c:=n ;
  if ((a=7)or(b=7)or(c=7))
  then write('Yes')
  else write('No');
end.

Measured memory_bytes: 1320
n,q = map(int,input().split())
s = input()
query = [list(map(str,input().split())) for _ in range(q)]
def sim(x):
    now = s[x]
    for i in range(q):
        t,d = query[i][0],query[i][1]
        if now != t:
            continue
        if d == "L":
            x -= 1
            if x == -1:
                return -1
        else:
            x += 1
            if x == n:
                return 1
        now = s[x]
    return 0

max_left = -1
min_right = n
min_safe = n
max_safe = -1
save = (max_left, min_right)
flag = 0
while (min_right-max_left) > 1:
    m = (max_left+min_right)//2
    j = sim(m)
    if j == -1:
        max_left = m
    if j == 0:
        max_safe = max(max_safe, m)
        min_safe = min(min_safe, m)
    if j == 1:
        min_right = m
    
    if (max_left, min_right) != save:
        save = (max_left, min_right)
    else:
        #left
        #print(max_left, min_safe, max_safe, min_right)
        l,r = max_left, min_safe
        while (r-l) > 1:
            m = (r+l)//2
            j = sim(m)
            if j == -1:
                l = m
            elif j == 0:
                r = m
        max_left, min_safe = l,r
        #right
        l,r = max_safe, min_right
        while (r-l) > 1:
            m = (r+l)//2
            j = sim(m)
            if j == 0:
                l = m
            elif j == 1:
                r = m
        max_safe, min_right = l,r

        flag = 1
        break
if flag:
    print(max_safe-min_safe+1)
else:
    print(0)

Measured memory_bytes: 93772
# coding: utf-8

def is_even(s):
    return s[:int(len(s)/2)] == s[int(len(s)/2):]

ss = input()
diff = 2
while True:
    if is_even(ss[:len(ss) - diff]):
        break
    else:
        diff += 2

print(len(ss) - diff)


Measured memory_bytes: 2940
n = int(input())
A = sorted([int(i) for i in input().split()], reverse = True)
if n == 1:
    print(0)
else:
    ans = A[0]
    ans += 2*sum(A[1:(n-1)//2+1])
    if n%2:
        ans -= A[(n-1)//2]
    print(ans)

Measured memory_bytes: 105072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[10010],v[10010];
ll n,k,res=-0x3f3f3f3f3f3f3f3f;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i],a[i]--;
	for(int i=0;i<n;i++) cin>>v[i];
	for(int i=0;i<n;i++){
		int x=i,l=0;
		ll s=0,num=0;
		bool f=1;
		while(x!=i||f){
			f=0;
			l++;
			x=a[x];
			s+=v[x];
			num+=v[x];
			if(l<=k)res=max(res,num);
		}
		num=0;
		if(k>=l&&s>0){
			for(int j=1;j<=l;j++){
				x=a[x];
				num+=v[x];
				res=max(res,num+s*((k-j)/l));
			}
		}
	}
	cout<<res;
	return 0;
}



Measured memory_bytes: 3668
#include<stdio.h>
int main(void)
{
    int n,i;
    double total=0;
    scanf("%d",&n);

    for(i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0 && i%15!=0){
            total=total+i;
        }
    }
    printf("%.f\n",total);
    return 0;
}


Measured memory_bytes: 1744
class UnionFind:
    def __init__(self, n): 
        self.par = [-1]*n
        
    def __repr__(self):
        return "union_find({0})".format(self.par)
        
    def unite(self, x, y):
        if self.root(x) != self.root(y):
            self.par[self.root(x)] = y
        
    def root(self, x):
        if self.par[x] == -1:
            return x
        else:
            self.par[x] = self.root(self.par[x])
        return self.par[x]
        
    def same(self, x, y):
        return self.root(x) == self.root(y)
        
        
from sys import stdin
def readLine_int_list():return list(map(int, stdin.readline().split()))
from collections import defaultdict

def main():
    n,k,l = readLine_int_list()
    
    rail = UnionFind(n)
    road = UnionFind(n)
    
    for _ in range(k):
        p, q = readLine_int_list()
        p, q = p-1, q-1
        road.unite(p, q)
     
    for _ in range(l):
        p, q = readLine_int_list()
        p, q = p-1, q-1
        rail.unite(p, q)
        
    d = defaultdict(int)
    
    for i in range(n):
        d[road.root(i), rail.root(i)] += 1
    results = (d[road.root(i), rail.root(i)] for i in range(n))


    print(" ".join(str(n) for n in results))
    

if __name__ == "__main__":main()

Measured memory_bytes: 48612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vector<P> A(n);
  rep(i,n){
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(A.begin(),A.end());
  int count = 0;
  rep(i,n){
    if(abs(A[i].second - i) % 2 == 1) count++;
  }
  cout << count/2 << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
  int i,k,n,j,a[3],b[3],c[3];
  scanf("%d%d%d",&a[0],&a[1],&a[2]);
  scanf("%d%d%d",&b[0],&b[1],&b[2]);
  scanf("%d%d%d",&c[0],&c[1],&c[2]);
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&k);
    for(j=0;j<3;j++) if(a[j]==k) a[j]=1;
     for(j=0;j<3;j++) if(b[j]==k) b[j]=1;
     for(j=0;j<3;j++) if(c[j]==k) c[j]=1;
  }
  if((a[0]==1&&a[1]==1&&a[2]==1)||(b[0]==1&&b[1]==1&&b[2]==1)||(c[0]==1&&c[1]==1&&c[2]==1)||
     (a[0]==1&&b[0]==1&&c[0]==1)||(a[1]==1&&b[1]==1&&c[1]==1)||(a[2]==1&&b[2]==1&&c[2]==1)||
     (a[0]==1&&b[1]==1&&c[2]==1)||(a[2]==1&&b[1]==1&&c[0]==1)) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
n=int(input())
digit=0
for i in range(1,12):
    tmp=26**i
    if n<=tmp:
        digit=i
        break
    else:
        n-=tmp
# print(digit,n)
n-=1
ans=[]
for i in range(digit-1,-1,-1):
    tmp=26**i
    # print(n,tmp,n//tmp,n%tmp)
    ans.append(n//tmp)
    n%=tmp
# print(ans)
for ai in ans:
    print(chr(ai+97),end='')


Measured memory_bytes: 9060
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] o = sc.next().split("");
        String[] e = sc.next().split("");
        String ans = "";
        for(int i = 0; i < o.length; i++) {
          ans += o[i];
          if (i <= e.length - 1) {
            ans += e[i];
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
/*B - Ordinary Number*/
#include <bits/stdc++.h>
using namespace std;

using Long = long long;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int tam;

	cin >> tam;

	vector <int> arr(tam);

	for (int i = 0; i < tam; ++i){
		cin >> arr[i];
	}

	bool medio;
	int ans = 0;

	for (int i = 1; i < tam - 1 ; ++i)
	{
		medio = true;
		
		if(arr[i] < arr[i - 1] and arr[i] < arr[i + 1]){
			medio = false;
		}
		else if(arr[i] > arr[i - 1] and arr[i] > arr[i + 1]){
			medio = false;
		}

		if(medio){
			ans++;
		}
	}

	cout << ans;


	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m, k;

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

ll mod_inverse(ll x) {
    return mod_pow(x, mod-2);
}

const int max_n = 1000000;
ll fact[max_n];
ll fact_inv[max_n];
void calc_fact() {
    fact[0] = 1;
    for (ll i = 1; i < max_n; i++)
        fact[i] = (fact[i-1] * i) % mod;
    fact_inv[max_n-1] = mod_inverse(fact[max_n-1]);
    for (ll i = max_n-2; i >= 0; i--)
        fact_inv[i] = (fact_inv[i+1] * (i+1)) % mod;
}
ll mod_comb(ll n, ll k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return (fact[n] * fact_inv[k] % mod) * fact_inv[n-k] % mod;
}

ll solve() {
    calc_fact();
    ll res = 0;
    for (int i = 0; i <= k; i++) {
        ll v = m;
        v *= mod_pow(m-1, n-i-1);
        v %= mod;
        v *= mod_comb(n-1, i);
        v %= mod;
        res += v;
        res %= mod;
    }
    return res;
}

void input() {
    cin >> n >> m >> k;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 18772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int h, w;
int f[10][10];
int past[10];
int ans[10];
void dfs(int root, int cost, int now) {
    if(now==1) chmin(ans[root],cost);
    else {
        if(past[now]==0) {
            past[now] = 1;
            rep(i,10) {
                dfs(root, cost+f[now][i], i);
            }
            past[now] = 0;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> h >> w;
    rep(i,10) {
        rep(j,10) {
            cin >> f[i][j];
        }
    }
    rep(i,10) ans[i] = 1e9;
    rep(i,10) {
        dfs(i, 0, i);
    }

    int cnt = 0;
    rep(i,h) {
        rep(j,w) {
            int a; cin >> a;
            if(a!=-1) cnt += ans[a];
        }
    }
    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 256
import Data.Array

--価値と重さアレイ、使用する要素の最大インデックス、重さ制限、ナイーブ再帰。それぞれについて入れるかどうか。
naive_rec::Array Int (Int,Int)-> Int -> Int -> Int
naive_rec item 0 limit = 0
naive_rec item i limit = let no_i_v = naive_rec item (i-1) limit in
                         let usable_i = if ( limit - (snd (item!i)) )>=0
                                          then let use_v = naive_rec item (i-1) (limit - (snd (item!i))) in
                                               use_v+ (fst (item!i))
                                          else no_i_v in
                         max usable_i no_i_v

memo_ls::Array Int (Int,Int) -> Int ->  Int -> [Array Int Int]
memo_ls item m limit = (listArray (0,limit) (replicate (limit+1) 0)):
                        [ listArray (0,limit)
                            [ let no_i = prev!k in
                              let usable_i = if (k - (snd (item!i))) >=0
                                                then let use_i = (prev!(k-(snd (item!i)))) in
                                                     use_i + (fst (item!i))
                                                else no_i in
                              max no_i usable_i
                            | k <- [0..limit]]
                        | (prev,i) <- zip (memo_ls item m limit) [1..m]]

--vwリスト、リスト要素数、重さ制限、答え。
solver::[(Int,Int)]->Int->Int->Int
solver item_ls m limit = let item = listArray (1,m) item_ls in
                         (last (memo_ls item m limit))!limit

n_tp_get::Int->IO [(Int,Int)]
n_tp_get 0 = return []
n_tp_get n = do
  vw<-getLine
  let v:w:[]= map read (words vw)
  rest<-n_tp_get (n-1)
  return ((v,w):rest)

main::IO()
main=do
  ml<-getLine
  let m:l:[]=map read (words ml)
  dat<-n_tp_get m
  print (solver dat m l)


Measured memory_bytes: 122144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<int> p(3);


	for (int i = 1; i < n - 1; i++)
	{
		for (int j = 0; j < 3; j++) p[j] = a[i + j - 1];

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

		if (p[1] == a[i])count++;
	}

	cout << count << endl;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(std::string S){
    lli l=0,r=0;
    lli state=0;

    lli ans = 0;
    REP(i,0,S.size()){
        if(state==0){
            if(S[i]=='<')l++;
            else{
                state++;
                r++;
            }
        }
        else{
            if(S[i]=='<'){
                lli a = max(l,r);
                lli b = min(l,r);
                ans += (a*(a+1))/2;
                ans += max(0LL,b*(b-1)/2);

                l=1;
                r=0;
                state=0;
            }
            else r++;
        }
    }
                    lli a = max(l,r);
                lli b = min(l,r);
                ans += (a*(a+1))/2;
                ans += max(0LL,b*(b-1)/2);


    cout<<ans<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 1412
N, Y = map(int, input().split())

ans = [-1, -1, -1]
for x in range(N+1):
    a = 10000*x
    for y in range(0, (N+1)-x):
        b = 5000*y
        z = N-(x+y)
        c = 1000*z
        if (a+b+c) == Y:
            ans = [x, y, z]
            break
ans = map(str, ans)
print(" ".join(ans))

Measured memory_bytes: 9192
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	vec := make([]int, n)
	for i := 0; i < n; i++ {
		vec[i] = nextInt(sc)
	}
	for i := 0; i < n; i++ {
		if i == n-1 {
			break
		}
		fmt.Printf("%d ", vec[n-i-1])
	}
	fmt.Println(vec[0])

}



Measured memory_bytes: 1068
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<pair<int,int>>vp;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b;
    int t=0;
    for(int j=0;j<b;j++){
      cin>>c;
      t|=1<<(--c);
    }
    vp.emplace_back(t,a);
  }
  const int n=1<<N;
  const int inf=2e9;
  vector<int>dp(n,inf);
  dp.front()=0;
  for(int u=0;u<n;u++){
    for(auto& p:vp){
      int v=u|p.first;
      dp[v]=min(dp[v],dp[u]+p.second);
    }
  }
  cout<<(dp[n-1]<inf?dp[n-1]:-1)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
int n;
#define int ll
vector<int> edge[maxn];
vector<pair<int,int>> alle;
struct sgt {
	int v[maxn<<1], tag[maxn<<1], sz[maxn<<1];
	void init() {
		for (int i = 0;i < n;++i)
			sz[i+n] = 1;
		for (int i = n-1;i > 0;--i)
			sz[i] = sz[i<<1] + sz[i<<1|1];
	}
	void add_node(int i, int val) {
		v[i] += val * sz[i], tag[i] += val;
	}
	void push(int i) {
		if (i < n && tag[i]) {
			add_node(i<<1, tag[i]);
			add_node(i<<1|1, tag[i]);
			tag[i] = 0;
		}
	}
	void update(int i) {
		if (i < n) {
			push(i);
			v[i] = v[i<<1] + v[i<<1|1];
		}
	}
	void pa(int k) {
		for (int i = 20;i > 0;--i) push(k>>i);
	}
	void add(int l, int r, int val) {
		l += n, r += n;
		int sl = l>>1, sr = r>>1;
		for (;l < r;l>>=1, r>>=1) {
			if (l&1) add_node(l++, val);
			if (r&1) add_node(--r, val);
		}
		for (;sl;sl>>=1, sr>>=1)
			update(sl), update(sr);
	}
	int sum(int l = 0, int r = n) {
		int res = 0;
		l += n, r += n;
		for (int i = 20;i > 0;--i)
			push(l>>i), push(r>>i);
		//pa(l), pa(r);
		for (;l < r;l>>=1, r>>=1) {
			if (l&1) res += v[l++];
			if (r&1) res += v[--r];
		}
		return res;
	}
}tree;
ll res;
int bf(int l, int r) {
	int res = r-l+1;
	for (auto [x, y] : alle)
		if (max(x, y) <= r && min(x, y) >= l)
			--res;
	return res;
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int a, b, i = 1;i < n;++i) {
		cin >> a >> b;
		--a, --b;
		edge[a].pb(b);
		edge[b].pb(a);
		alle.pb(a, b);
	}
	tree.init();
	for (int i = 0;i < n;++i)
		tree.add(i, n, 1);
	for (auto [a, b] : alle) 
		tree.add(max(a, b), n, -1);
	for (int i = 0;i < n;++i) {
		res += tree.sum(i, n);
//		int ad = 0;
//		for (int j = i;j < n;++j) 
//			res += tree.sum(j, j+1), ad += tree.sum(j, j+1);
//		cout << ad << ' ' << tree.sum(i, n) << '\n';
//			if (tree.sum(j, j+1) != bf(i, j))
				//cout << i+1 << ' ' << j+1 << '\n';
			//cout << "Sum " << i+1 << ' ' << j+1 << ' ' << tree.sum(j, j+1) << ' ' << bf(i, j) << '\n';
		tree.add(i, n, -1);
		for (int u : edge[i]) if (u > i)
			tree.add(u, n, 1);
	}
//	ll v = 0;
//	for (int i = 0;i < n;++i)
//		for (int j = i;j < n;++j)
//			v += bf(i, j);
//	cout << v << '\n';
	cout << res << '\n';
}


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

int main(){
    int a, b, c, x, y;
    cin>>a>>b>>c>>x>>y;
    if(x>y){
        int t;
        t=a; a=b; b=t;
        t=x; x=y; y=t;
    }
    int mc=min(a*x+b*y, c*2*x+b*(y-x));
    mc=min(mc, c*2*y);
    cout<<mc<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>

using namespace std;

int main(){
  long long int n;
  long long int i,j,c=0,m=0,ans=0;
  vector <long long int> v,w;
  
  cin>>n;
  
 for(i=0;i<n;i++){
   cin>>j;
   v.push_back(j);
   w.push_back(abs(j));
   if(j<0)
     m++;
 }
 sort(w.begin(),w.end());
  for(i=0;i<n;i++){
    ans=ans+w[i];
  }
  cout<<(m%2==0?ans:ans-2*w[0])<<endl;
  
  return 0;
}

Measured memory_bytes: 2036
#include <cstdio>
#include <vector>

using namespace std;

int  s[10];

int main()
{
	//freopen("in.txt", "r", stdin);

	int case_t, case_num;
	scanf("%d", &case_num);
	for (case_t=1; case_t<=case_num; case_t++) {
		int i;
		for (i=0; i<10; i++)
			scanf("%d", &s[i]);

		int min1 = -1, min2 = -1;

		for (i=0; i<10; i++) {
			if (s[i]<min1 && s[i]<min2)
				break;
			if (s[i]>min1 && s[i]>min2) {
				if (min1 < min2)
					min2 = s[i];
				else
					min1 = s[i];
			}
			else if (s[i]>min1)
				min1 = s[i];
			else
				min2 = s[i];

		}
		if (i<10) printf("NO\n");
		else printf("YES\n");


	}

	return 0;
}

Measured memory_bytes: 1008
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int[] X = in.ii();
        int min = Integer.MAX_VALUE;
        for(int i = 1; i < 101; i++){
            int tmp = 0;
            for(int j = 0; j < N; j++){
                tmp += (X[j]-i)*(X[j]-i);
            }
            if(tmp < min){
                min = tmp;
            }
        }
        out.println(min);
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 22484
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < h.length; ++i) {
            h[i] = sc.nextInt();
        }

        System.out.println(solve(h));

        sc.close();
    }

    static int solve(int[] h) {
        int[] costs = new int[h.length];
        Arrays.fill(costs, Integer.MAX_VALUE);
        costs[0] = 0;

        for (int i = 1; i < costs.length; ++i) {
            for (int j = 1; j <= 2 && j <= i; ++j) {
                costs[i] = Math.min(costs[i], costs[i - j] + Math.abs(h[i] - h[i - j]));
            }
        }

        return costs[costs.length - 1];
    }
}

Measured memory_bytes: 59696
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if ((a == 5 && b == 5 && c == 7)
        || (a == 5 && b == 7 && c == 5)
        || (a == 7 && b == 5 && c == 5)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 21460
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=sum(b)
for i in range(n-1):
  if a[i+1]-a[i]==1:
    x+=c[a[i]-1]
print(x)

Measured memory_bytes: 3060
object Main {
  def main(args: Array[String]) {
    var check = true
    var count = 0
    var words = Array[String]()
    for(line <- io.Source.stdin.getLines()) {
      if(count == 0) {

      }
      else if(count == 1)
      {
        words = words :+ line
      }
      else{
        val start_char = words(count - 2)(words(count - 2).length - 1)
        if (start_char != line(0)) {
          check = false
        }

        for( c <- words ) {
          if(line == c) {
            check = false
          }
        }

        words = words :+ line
      }
      count += 1
    }

    if(check){
      println("Yes")
    }
    else {
      println("No")
    }
  }
}


Measured memory_bytes: 25420
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 55;

using namespace std;

ll x[N];
ll dp[N][N*N];

main()
{
    fast;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    int n,a,i,j,k;
    cin>>n>>a;
    for (i=1;i<=n;i++)
        cin>>x[i];
    ll cur_tot=0;
    for (i=1;i<=n;i++)
    {
        for (j=i-1;j>=0;j--)
        {
            for (k=cur_tot;k>=0;k--)
                dp[j+1][k+x[i]]+=dp[j][k];
        }
        cur_tot+=x[i];
    }
    ll ans=0;
    for (i=1;i<=n;i++)
        ans+=dp[i][i*a];
    cout<<ans<<endl;
}

Measured memory_bytes: 1536
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;

using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k,n; cin >> k >> n;
    vi A(n); rep(i,n) cin >> A[i];
    int ans = 0;
    for(int i=0; i<n; ++i) {
        if (i==0) {
            ans = max(ans, k-A[n-1]+A[0]);
        } else {
            ans = max(ans,A[i]-A[i-1]);
        }
    }
    cout << k-ans << "\n";
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "YES\n"
#define N cout << "NO\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i,n) for(int i = 0 ; i < n ; i++)

int main()
{
    ll n , a , ans = 0 , c = 0 , d , e , f , b ;
    cin >> n >> a >> b ;
    if( (b-a)%2 )
    {
        c = n - a ;
        d = a - 1 ;
        e = n - b ;
        f = b - 1 ;
        if( c < f )
        {
            ans = c ;
        }
        else
        {
            ans = f ;
        }
        e = ( (n - (a+e+1) ) /2 ) + (e + 1) ;
        if(ans > e)
        {
            ans = e ;
        } 
        d = ( ( b - (d+2) ) /2 ) + (d + 1) ;
        if(ans > d)
        {
            ans = d ;
        }
        cout << ans << endl ;
    }
    else
    {
        ans = b-a ;
        ans /= 2 ;
        cout << ans << endl ;
    }
}

Measured memory_bytes: 256
#include<iostream>
  
int const MAXN = 8;
int fact[MAXN+1] = {1};
int A[MAXN];

int order(int n, int* p) {
  if(n==1) return 0;
  int res = (p[0]-1)*fact[n-1];
  for(int j = 1; j < n; ++j) if(p[j] > p[0]) --p[j];
  return res + order(n-1, p+1);
}

int main() {
  int N; std::cin >> N;
  for(int i = 1; i <= N; ++i) fact[i] = fact[i-1]*i;
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  int a = order(N, A);
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  int b = order(N, A);
  std::cout << std::max(a-b, b-a) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  int a,b,c,d;
  int st,go;
  int hi,yo;
  int road[1111][1111];
  cin >> n >> m;
  for(int i=0;i<n;i++){//ありえない大きさの数を入れておく
    for(int j=0;j<n;j++){
      road[i][j]=8478;
    }
  }
  for(int i=0;i<m;i++){//エッジそれぞれにとりあえずの値を置換
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    road[a-1][b-1]=c;
    road[b-1][a-1]=d;
  }
  scanf("%d,%d,%d,%d",&st,&go,&yo,&hi);
  for(int i=0;i<n;i++){//ワーシャルフロイド開始
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	road[j][k]=min(road[j][k],road[j][i]+road[i][k]);
      }
    }
  }
  cout << yo-(hi+road[st-1][go-1]+road[go-1][st-1]) << endl;//road１つ目は往路、２つ目は復路
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
const ll MOD = 1000000007;

int enum_div(int n){
    int ret = 0;
    for(int i = 1 ; i <= n ; ++i){
        if(n%i == 0){
            ret++;
        }
    }
    return ret;
}

int main() {
    int n,ans = 0;
    cin >> n;
    for(int i = 1;i<=n;i++) {
        if(enum_div(i) == 8 && i%2 == 1)  {
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
//There was and will always be only one Chester. RIP legend
//--------------------Life is beautiful--------------------
#include<bits/stdc++.h>
using namespace std;
#define Nilesh ios_base::sync_with_stdio(false);
int main()
{
	Nilesh
	int pre[1001]={0};
	int ok=0;
	for(int i=1;i<=999;i++)
    {
        ok+=i;
        pre[i]=ok;
    }
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=999;i++)
    {
        if((pre[i]-a)==(pre[i+1]-b))
        {
            cout<<pre[i]-a;
            return 0;
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, l;
    cin >> n >> l;
    vi a(n);
    rep(i, n) a[i] = l + i;
    int sum = accumulate(all(a), 0);
    int x = INF;
    rep(i, n) if(abs(x) > abs(a[i])) x = a[i];
    cout << sum - x << '\n';
    return 0;
}

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

const int INF = INT_MAX;
const int MAXN = 1005;
int A[MAXN], B[MAXN];
int dp[MAXN];

int main() {
  int N;
  while(cin >> N) {
    for(int i = 0; i < N; ++i) {
      cin >> A[i] >> B[i];
    }
    vector<pair<int,int> > v;
    for(int i = 0; i < N; ++i) v.push_back(make_pair(B[i], i));
    sort(v.begin(), v.end());
    fill(dp, dp+MAXN, INF);
    dp[0] = 0;
    int res = 0;
    for(int j = 0; j < N; ++j) {
    for(int i = N; i >= 0; --i) {
        if(dp[i] == INF) continue;
        int k = v[j].second;
        if(dp[i]+A[k] <= B[k]) {
          dp[i+1] = min(dp[i+1], dp[i]+A[k]);
          res = max(res, i+1);
        }
      }
    }
    cout << res << endl;
  }
}

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

int n;
char a[1000];
int b[1000];
bool flg[1000];

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  int ans=0;
  while(1){
    int id=-1;
    for(int i=0;i<n;i++){
      if(flg[i]||a[i]=='n')continue;
      if(id==-1||b[i]<b[id])id=i;
    }
    if(id==-1)break;
    ans++;
    int l=id,r=id;
    while(0<=l-1&&(a[l-1]=='y'||b[l-1]<b[id]))l--;
    while(r+1<n&&(a[r+1]=='y'||b[r+1]<b[id]))r++;
    for(int i=l;i<=r;i++)flg[i]=true;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
  int n;
  int ans=1;
  cin >> n;
  vector<int> a(n);
  for(int r=0;r<n;r++){
    cin >> a.at(r);  
  }
  
  sort(a.begin(),a.end());
  
  for(int i=0;i<n-1;i++){
    if(a.at(i) != a.at(i+1)){ans++;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n1 := sc.NextInt()
	n2 := sc.NextInt()

	fmt.Printf("%v\n", n1+(n2/2))

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int H,A,B,N,R,M,K,X,Y,Z,C;
  string S,T,U;
  int N_tmp=0;
  cin >> K >> A >> B;

  for(int i=A; i <= B ; i++){
    if(i % K == 0){
       cout << "OK" << endl;
       return 0;
    }
  }

  cout << "NG" << endl;
  return 0;
  


}

Measured memory_bytes: 3624
a="#"
b="."
loop{
h,w=gets.split(" ").map(&:to_i)
break if h==0 and w==0
h.times{|i|
    w.times{|j|
        if (i+j)%2==0
            print("#{a}")
        else
            print("#{b}")
        end
    }
    puts""
}
puts""
}


Measured memory_bytes: 6856
H, W = gets.split.map(&:to_i)
A = Array.new(H){Array.new(W, 0)}
[1, -1].each do |c|
    H.times do |i|
        arr = gets.split.map(&:to_i)
        W.times do |j|
            A[i][j] += arr[j] * c
        end
    end
end

M = 160*80
dp = Array.new(H){Array.new(W, 0)}
dp[0][0] = 1 << M
H.times do |i|
    W.times do |j|
        dp[i][j] |= dp[i-1][j] if i > 0
        dp[i][j] |= dp[i][j-1] if j > 0
        dp[i][j] = (dp[i][j] << A[i][j]) | (dp[i][j] >> A[i][j])
    end
end

ans = M
(2*M).times do |i|
    ans = [ans, (M-i).abs].min if dp[H-1][W-1][i] == 1
end
puts ans


Measured memory_bytes: 41084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
 
int main() {
  int H,W; cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> a[i][j];
  }
  vector<vector<int>> ans(H*W, vector<int>(4));
  int N = 0;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] % 2 == 1) {
        if (i == H-1 && j == W-1) continue;
        else if (i == H-1) {
          a[i][j]--;
          a[i][j+1]++;
          ans[N][0] = i+1;
          ans[N][1] = j+1;
          ans[N][2] = i+1;
          ans[N][3] = j+2;
          N++;
        } else if (j == W-1) {
          a[i][j]--;
          a[i+1][j]++;
          ans[N][0] = i+1;
          ans[N][1] = j+1;
          ans[N][2]= i+2;
          ans[N][3] = j+1;
          N++;
        } else {
          if (a[i][j+1] % 2 == 1 || a[i+1][j] % 2 == 0) {
            a[i][j]--;
            a[i][j+1]++;
            ans[N][0] = i+1;
            ans[N][1] = j+1;
            ans[N][2] = i+1;
            ans[N][3] = j+2;
            N++;
          } else {
            a[i][j]--;
            a[i+1][j]++;
            ans[N][0] = i+1;
            ans[N][1] = j+1;
            ans[N][2] = i+2;
            ans[N][3] = j+1;
            N++;
          }
        }
      }
    }
  }
  
  cout << N << endl;
  for (int i = 0; i < N; i++) {
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
  }     
}

Measured memory_bytes: 16768