akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  
  for (int i = 0; i < (N - 1) / 2; i++){
    if (S[i] != S[(N - 1) / 2 - 1 - i]){
      cout << "No" << endl;
      return 0;
    }
  }
  //前半が回文かどうか
  
  for (int i = 0; i < (N - 1) / 2; i++){
    if (S[(N - 1) / 2 + 1 + i] != S[N - 1 - i]){
      cout << "No" << endl;
      return 0;
    }
  }
  //後半が回文かどうか
  
  string S2 = S;
  reverse(S.begin(), S.end());
  if (S2 != S){
    cout << "No" << endl;
    return 0;
  }
  
  cout << "Yes" << endl;
}
  


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define loop(i) for(int i = 0;true; i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mn 1000000007
int main() {
	ll a, b;
	cin >> a >> b;
	if (a==b) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		if (abs(a+b)%2==0) {
			cout << (a + b) / 2 << endl;
		}
		else {
			cout << "IMPOSSIBLE" << endl;
		}
	}
};


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ if(a>b) a=b;}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, s;
	while(cin >>n >>s){
		if(n==0 && s==0) break;
		vector<VL> dp(n+2, VL(s+2));
		dp[0][0] =1;
		
		rep(i, 101){
			repr(j, n-1, 0) rep(k, s+1) if(dp[j][k] >0){
				if(k + i <= s){
					dp[j+1][k+i] += dp[j][k];
				}
			}
		}
		cout <<dp[n][s] <<"\n";
		//for(auto x :dp[n]) cerr<<x<<" "; cerr<<"\n";
	}
	return 0;
}



Measured memory_bytes: 3164
from sys import stdin


def readline_from_stdin() -> str:
    return stdin.readline().rstrip


if __name__ == '__main__':
    pass
    # N = input()
    # X, Y, Z = input().split()
    # A = [int(i) for i in input().split()]
    X, Y = input().split()
    X = int(X)
    Y = int(Y)

    b = (X*2-Y)/(-2)
    a = X-b
    # print(a, b)
    if not a.is_integer() or not b.is_integer() or a < 0 or b < 0:
        print("No")
        exit(0)
    print("Yes")


Measured memory_bytes: 61824
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;

int fac[maxn], inv[maxn];

int qpow(int a, int n){
    int ret = 1;
    while(n > 0){
        if(n & 1){
            ret = 1LL * ret * a % mod;
        }
        a = 1LL * a * a % mod;
        n >>= 1;
    }
    return ret;
}

void pre_comb(){
    fac[0] = 1;
    for(int i = 1;i < maxn;i++){
        fac[i] = 1LL * fac[i - 1] * i % mod;
    }
    inv[maxn - 1] = qpow(fac[maxn - 1], mod - 2);
    for(int i = maxn - 2;i >= 0;i--){
        inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
    }
}

int comb(int n, int m){
    if(m > n or m < 0) return 0;
    return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int a[maxn];
int pos[maxn];
int ans[maxn];

int main(){
    int n;
    memset(pos, 0, sizeof(pos));
    memset(ans, 0, sizeof(ans));
    pre_comb();
    cin >> n;
    for(int i = 1;i <= n + 1;i++){
        ans[i] = comb(n + 1, i);
    }
    for(int i = 1;i <= n + 1;i++){
        scanf("%d", &a[i]);
        if(pos[a[i]] != 0){
            int x = pos[a[i]], y = i;
            int len = x - 1 + (n + 1 - y);
            for(int j = 0;j <= len;j++){
                ans[j + 1] = (ans[j + 1] - comb(len, j) + mod) % mod;
            }
            //for(int j = 0;j <= n - 1;j++){
            //    ans[j + 2] = (ans[j + 2] + comb(n - 1, j)) % mod;
            //}
        }
        pos[a[i]] = i;
    }
    for(int i = 1;i <= n + 1;i++){
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

int a[100010];

void solve(){
  int h,n;
  cin >> h >> n;
  ll sum = 0;
  rep(i,n){
      cin >> a[i];
      sum += a[i];
  }
  cout << (sum>=h? "Yes": "No") << endl;

}

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


Measured memory_bytes: 640
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;
typedef long long ll;

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

int main(){
ll X;
cin>>X;
ll amari;
ll num_500;
amari= X%500;
num_500 = X/500;
ll num_5 = amari/5;
ll ans = 1000*num_500 + 5*num_5;
cout<<ans<<endl;
return 0;


}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a < b && b < c) {
		printf("Yes\n");
	}
	
	else {
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int count = 0;
    bool flag[N];
    for (int i = 0; i < N; i++) {
        flag[i] = true;
    }
    
    int tmp = 0;

    while (flag[tmp]) {
        count += 1;
        flag[tmp] = false;
        tmp = a[tmp] - 1;
        if (tmp == 1) {
            cout << count << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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


int main(){
    ll N; cin >> N;
    ll ans = 1e13;
    for(int i = 1; i <= sqrt(N); ++i){
        if(N % i == 0){
            ll tmp = i + N/i -2;
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define INF (1LL<<60)
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))


class CAttention {
public:
	void solve(std::istream& in, std::ostream& out) {
    int n;
    string s;
    in >> n >> s;
    int diff = INF;
    int w = 0, e = 0;
    REP(i, s.length()){
      if(s[i] == 'W') w++;
      else e++;
    }
    int l = 0,r = e - (s[0] == 'E' ? 1 : 0);
    diff = l + r;
    FOR(i, 1, s.length()){
      if(s[i-1] == 'W') l++;
      if(s[i] == 'E') r--;
      if(diff > l + r) diff = l + r;
    }
    out << diff << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	CAttention solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3944
import itertools

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
l=[i for i in range(1,n+1)]
j = itertools.permutations(l, n)

a=0
b=0
for num,i in enumerate(j):
    if(list(i)==p):a=num
    if(list(i)==q):b=num

print(abs(a-b))

Measured memory_bytes: 3188
#include <iostream>
 
using namespace std;
 
int p[10], c[10];
int memo[11][2000000];
 
int solve(int d, int g)
{
	if(g <= 0)
	{
		return 0;
	}
 
	if(d == 0)
	{
		if(g > 0)
		{
			return 1 << 30;
		}
		else
		{
			return 0;
		}
	}
 
	if(memo[d][g] != -1)
	{
		return memo[d][g];
	}
 
	int ret = 1 << 30;
	for(int i = 0; i < p[d - 1]; ++i)
	{
		ret = min(ret, solve(d - 1, g - i * d) + i);
	}
 
	ret = min(ret, solve(d - 1, g - p[d - 1] * d - c[d - 1]) + p[d - 1]);
 
	return memo[d][g] = ret;
}
 
int main()
{
	int d, g;
 
	cin >> d >> g;
 
	g /= 100;
 
	for(int i = 0; i < d; ++i)
	{
		cin >> p[i] >> c[i];
		c[i] /= 100;
	}
 
	for(int i = 0; i <= 10; ++i)
	{
		for(int j = 0; j < 200000; ++j)
		{
			memo[i][j] = -1;
		}
	}
 
	cout << solve(d, g) << endl;
}

Measured memory_bytes: 29696
n,k = map(int,input().split())
if k%2 == 1:
    ans = (n//k)**3
else:
    if k <= 2*n:
        a = (n//(k//2))
        b = a//2
        ans = (a-b)**3 + b**3
    else:
        ans = 0
print(ans)

Measured memory_bytes: 9180
N = int(input())
a_score = 0
b_score = 0
for i in range(N):
  a = list(x for x in input().split())
  if a[0] == a[1]:
    a_score += 1
    b_score += 1
  else:
    b = sorted(a)
    if a[0] == b[0]:
      b_score += 3
    else:
      a_score += 3
print(f'{a_score} {b_score}')


Measured memory_bytes: 5616
N, M = map(int, input().split())
MOD = 10**9 + 7

fact = [1]
for i in range(1, N + M + 1):
    fact.append((fact[-1] * i) % MOD)

x = fact[N] * fact[M]

if N == M:
    ans = 2 * x % MOD
elif abs(N - M) == 1:
    ans = x % MOD
else:
    ans = 0

print(ans)


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    int m = 111;
    while(m<n) m+=111;
    cout<<m<<endl;
    return 0;
}


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

#define int long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i, l, r) for(int i=(int)(l);i<=(int)(r);i++)
#define repi(i, l, r) for(int i=(int)(l);i>=(int)(r);i--)
const int inf = 1e18;

using namespace std;


void solve() {
    int n;
    cin >> n;
    pair<int, int> p[n];

    rep(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        p[i].first = x;
        p[i].second = y;
    }

    int cnt = 0;
    bool flag = false, res = false;
    rep(i, 0, n - 1) {
        if (p[i].first == p[i].second and flag)
            cnt++;
        else if(p[i].first == p[i].second and !flag){
            flag = true;
            cnt++;
        }
        else if (p[i].first != p[i].second and flag) {
            flag = false;
            cnt = 0;
        }
        if(cnt >= 3){
            res = 1;
            break;
        }
    }
    if (res)
        cout << "Yes\n";
    else
        cout << "No\n";
}


int32_t main() {
    fastIO
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}



Measured memory_bytes: 3608
#!/usr/bin/env python3
import sys
import numpy as np

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


H, W, M = MI()

R = np.zeros(H + 1)
C = np.zeros(W + 1)
bombs = []
for _ in range(M):
    h, w = MI()
    bombs.append((h, w))
    R[h] += 1
    C[w] += 1

R_max = [R == max(R)]
ans = max(R) + max(C)
C_max = [C == max(C)]

cnt = 0
for h, w in bombs:
    if R_max[0][h] and C_max[0][w]:
        cnt += 1

if cnt == np.count_nonzero(R_max) * np.count_nonzero(C_max):
    print(int(ans - 1))
else:
    print(int(ans))


Measured memory_bytes: 72712
using System;

class Program{
    static void Main(string[] args){
        int num = Int32.Parse(Console.ReadLine());

        string[] arr = Console.ReadLine().Split(' ');
        int[] intarr = new int[num];
        int i=0;
        foreach(string s in arr){
            intarr[i] = Int32.Parse(s);
            if(intarr[i]%2 == 1){
                Console.WriteLine(0);
                return;
            }
            i++;
        }

        for(i=0;;i++){
            for(int j=0;j<num;j++){
                intarr[j] = intarr[j]/2;
                if(intarr[j]%2 != 0){
                    Console.WriteLine(i+1);
                    return;
                }
            }
        }
    }
}

Measured memory_bytes: 13140
def ascan; gets.split.map(&:to_i);end
#def zip(arr)
#    arr.each_with_index.to_a.sort.each_with_index.map{|pair,i|[pair[1],i]}.sort.map{|pair|pair[1]+1}
#end
def zip(arr)
    h={}
    arr.sort.each_with_index{|v,i| h[v]=i+1}
    arr.map{|v| h[v]}
end

N,A,B = ascan

if N+1 < A + B
    p -1
    exit
end


if A >= B
    arr = []
    ptr = 0
    rem = N - B
    (B).times do |i|
        row = [A-1, rem].min+1
        rem -= row-1
        #arr += (row).times.map{|e|e+ptr}.to_a
        row.times{|e| arr << e+ptr }
        ptr -= N
    end
    puts arr.size == N ? zip(arr)*" " : "-1"
end

if A < B
    arr = []
    ptr = 0
    rem = N - A
    (A).times do |i|
        row = [B-1, rem].min+1
        rem -= row-1
        #arr += (row).times.map{|e|-e+ptr}.to_a
        row.times{|e| arr << -e+ptr }
        ptr += N
    end
    puts arr.size == N ? zip(arr)*" " : "-1"
end


Measured memory_bytes: 30584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int n, m, x;
	int a[110];
	cin>>n>>m>>x;
	for(int i=0; i<m; i++) cin>>a[i];
	int cost1=0, cost2=0;
	for(int i=0; i<m; i++){
		if((a[i]-1)<x-1) cost1++;
		if((a[i]-1)>x-1) cost2++;
	}
	cout<<min(cost1, cost2)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,d;
long long n;
int main(){
    cin>>a>>b>>c>>d;
    cin>>n;
    long long ans = 0;
    ans = min((n*4)*a , (n*2)*b);
    ans = min(ans,n*c);
    if(n%2 == 0){
        ans = min(ans,(long long)n/2 * d);
    }
    else{
        ans = min(ans,(long long)n/2 * d + min(a*4,min(b*2,c)));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define f first
#define s second

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	int s[n];
	int dp[n];
	for(int i = 0; i < n; i++){
		cin >> s[i];
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	dp[1] = abs(s[1] - s[0]);
	for(int i = 2; i < n; i++){
		dp[i] = min(dp[i - 1] + abs(s[i - 1] - s[i]), dp[i - 2] + abs(s[i - 2] - s[i]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main extends App {

  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  sc.nextLine()
  val a = sc.nextLine().split(" ").map(_.toInt)

  val Alice = ArrayBuffer.empty[Int]
  val Bob = ArrayBuffer.empty[Int]

  a.sorted.reverse.foreach {
    an => if (Alice.length > Bob.length) Bob += an else Alice += an
  }

  println(Alice.sum - Bob.sum)

}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    for (ll i=0; i<n; ++i) {
        if (c * i - d * (n - 1 - i) <= b - a && b - a <= d * i - c * (n - 1 - i)) {
            cout << "YES" << '\n';
            return;
        }
    }
    cout << "NO" << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 764
n,k=gets.chomp.split(" ").map(&:to_i);
r,s,p=gets.chomp.split(" ").map(&:to_i);
t = gets.chomp
t = t.split('')
array = []
total = 0
l = k
i = 0
t.each do |char|
  if char == 's'
  	a = 'r'
  	total = total + r
  elsif char == 'p'
  	a = 's'
  	total = total + s
  else
  	a = 'p'
  	total = total + p
  end
  if k > 0
  	k = k - 1
  else
  	if a == array[i - l]
  	  if a == 'r'
  	  	total = total - r
  	  elsif a == 's'
  	  	total = total - s
  	  else
  	  	total = total - p
  	  end
  	  a = ''
  	end
  end
  array << a
  i = i + 1
end

print("#{total}\n")

Measured memory_bytes: 16124
#include <iostream>
using namespace std;
const int maxn = 1e5 + 7;

//1.用 ans[i]ans[i]ans[i] 数组记录与 iii 同在集合 friendship 中或有 blockship 关系的人的数量
//2.用 sum[i]sum[i]sum[i] 数组记录集合 friendship 的元素个数
//3.对第 iii 个答案 cnt=sum[i]−ans[i]−1  减1就是减去自身

int parent[maxn];
int sum[maxn];
int ans[maxn];
int n, m, k, x, y;

int find_parent(int x){
    if(parent[x] == x) return x;
    else return parent[x] = find_parent(parent[x]);
}

void _union(int a,int b){
    a = find_parent(a), b = find_parent(b);
    if(a != b) parent[b] = a, sum[a] += sum[b];   //路径压缩，不然会TLE
}

void init(){
    for(int i=0;i<=n;i++)
        parent[i]=i, sum[i]=1;
}
int main() {

    cin >> n >> m >> k;
    init();
    while(m--){
        cin >> x >> y;
        ans[x]++, ans[y]++;
        _union(x, y);
    }
    while(k--){
        cin >> x >> y;
        if(find_parent(x) == find_parent(y)) ans[x]++, ans[y]++;
    }
    for(int i=1;i<=n;i++){
        cout << sum[find_parent(i)]-ans[i]-1 << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

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

typedef vector<int> vi;

int main() {
	while (true) {
		int n, m, score[1001];
		vi v;
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		REP(i, n) scanf("%d", &score[i]);
		score[n++] = 0;

		REP(i, n) FOR(j, i, n) v.push_back(score[i] + score[j]);
		sort(v.begin(), v.end());
		unique(v.begin(), v.end());

		int ans = 0;
		REP(i, v.size()) {
			vi::iterator it = upper_bound(v.begin(), v.end(), m - v[i]);
			if (it != v.begin())
				ans = max(ans, *(it - 1) + v[i]);
		}

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

Measured memory_bytes: 5072
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R, V, E;

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

	long double r;
	vector<long double>ans;
	cin >> r >> N;
	while (r>0.5) {
		map<long double, long double>m;
		for (long double j = -20; j <= 20; j+=0.5) {
			m[j] = 0;
		}
		for (int i = 0; i < N; i++) {
			int a, b;
			long double c;
			cin >> a >> b >> c;
			for (long double j = a; j <= b; j+=0.5) {
				m[j] = max(m[j], c);
			}
		}
		for (long double i = -r + 0.5; i <= r - 0.5; i += 1) {
			m[i - 0.5] = min(m[i], m[i - 0.5]);
			m[i + 0.5] = min(m[i], m[i + 0.5]);
		}
		long double ret = 10000;
		for (int i = -r; i <= r; i++) {
			if (abs(i) > abs(r))continue;
			long double box = sqrt(r*r - i * i);
			ret = min(ret, m[i] - box + r);
		//	cout << i << " " << m[i] << endl;
		}
		ans.push_back(ret);
		cin >> r >> N;
	}
	for (auto i : ans) {
		cout << setprecision(20) << i << endl;
	}
	return 0;
}



Measured memory_bytes: 3316
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)
    
n = int(input())
a = list(map(int, input().split()))
if n==2:
  print(max(a))
  sys.exit(0)
elif n==3:
  lis = [gcd(a[0], a[1]), gcd(a[1], a[2]), gcd(a[2], a[0])]
  print(max(lis))
  sys.exit(0)
tmp_unused = gcd(a[0], a[1])
tmp_used = max(a[0], a[1])
#print("used=", tmp_used, "unused=", tmp_unused)
for i in range(2,n):
  #print(a[i])
  tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  tmp_unused = gcd(tmp_unused, a[i])
  
  #print("used=", tmp_used, "unused=", tmp_unused)
print(tmp_used)

Measured memory_bytes: 14052
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n,W;
  cin>>n>>W;
  int dp[n][W+1];
  rep(i,n)rep(j,W+1)dp[i][j]=0;
  dp[0][0]=0;
  int w[n],v[n];
  rep(i,n){
    cin>>v[i]>>w[i];
  }
  rep(i,n){
    rep(j,W+1){
      if(i==0 && j==0)continue;
      if(i==0){
	if(j>=w[0])dp[i][j]=v[i];
	else dp[i][j]=0;
      }else if(j-w[i]<0)dp[i][j]=dp[i-1][j];
      else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
    }
  }
  cout<<dp[n-1][W]<<endl;
  return 0;
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

// End of Template //

int main() {

	int N, M;
    cin >> N >> M;

    int prize = 0;
    if (N == 3)
        prize += 100000;

    if (M == 3)
        prize += 100000;

    if (N == 2)
        prize += 200000;

    if (M == 2)
        prize += 200000;

    if (N == 1)
        prize += 300000;

    if (M == 1)
        prize += 300000;

    if (M == 1 && N == 1) {
        prize += 400000;
    }
    cou(prize);
}

Measured memory_bytes: 256
//  a typical dynamic programming problem
import  java.util.*;
class Main{

    public static void main(String[] args){
    
        Scanner  s = new Scanner(System.in);
        int n = s.nextInt();
        int[][] dp  = new int[12][100001];
        int[] arr = {1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
        
        for(int i = 0;i < 12;i++){
            
            for(int j = 0;j < 100001;j++){
                
                if(i == 0)
                    dp[i][j] = j;
                else{
                    if(j < arr[i])
                        dp[i][j] = dp[i-1][j];
                    else
                        dp[i][j] = Math.min(dp[i-1][j] , dp[i][j-arr[i]] + 1  );
                }
//                     dp[i][j] = Math.min(dp[i-1][j] , );
                
            }
        }
        /*
        for(int i = 0;i < 6;i++){
            for(int j = 0;j < 18;j++)
                System.out.print("  "+dp[i][j]+" ");
            System.out.println();
        }
        */

        System.out.println(dp[11][n]);
    }
}


Measured memory_bytes: 27476
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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






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

    int a, b, c; 
    cin >> a >> b >> c;

    if (a == b)
    	cout << c;
    else if (c + b >= a){
    	while (b != a) {
    		c--;
    		b++;
    	}
    	cout << c;
    }
    else if (c + b < a)
    	cout << 0;
    else 
    	cout << c;

    


    return 0;
}


Measured memory_bytes: 3552
import java.io.*;
import java.util.*;

public class Main {
    private static void solve(InputReader sc, PrintWriter out) throws Exception {
        String s = sc.next();
        int n = s.length();
        long sum=0;
        for(int i=0; i<n; i++){
            int x = (int)(s.charAt(i) - 48);
            sum += x;
        }
        out.println(sum%9 == 0 ? "Yes" : "No");
    }

    public static Set<Integer> seive(int n) {
        boolean[] arr = new boolean[n + 1];
        Set<Integer> hs = new HashSet<>();
        Arrays.fill(arr, true);
        for (int i = 2; i <= n; i++) {
            if (arr[i]) {
                for (int j = i + i; j <= n; j += i) {
                    arr[j] = false;
                }
            }
        }
        for (int i = 2; i <= n; i++) {
            if (arr[i]) hs.add(i);
        }
        return hs;
    }

    private static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solve(in, out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

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

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


Measured memory_bytes: 36352
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Stack;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		int N = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		while (N-- != 0) {
			list.add(sc.nextInt());
		}
		Collections.reverse(list);
		ln(join(list, " "));
	}

	public static String join(Collection<?> array, String separator) {
		Iterator<?> it = array.iterator();
		StringBuilder str = new StringBuilder(it.next() + "");
		while (it.hasNext()) {
			str.append(separator).append(it.next() + "");
		}
		return str.toString();
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
h, w = map(int, input().split())

sn = [input() for _ in range(h)]
csn = [[0] * w for i in range(h)]

for i in range(h):
  for j in range(w):
    if sn[i][j] == "#" :
      csn[i][j] = -1
      if i-1 >= 0 and sn[i-1][j] == "." :
        csn[i-1][j] += 1
        
      if i+1 <= h-1 and sn[i+1][j] == "." :
        csn[i+1][j] += 1   
        
      if j-1 >= 0 and sn[i][j-1] == "." :
        csn[i][j-1] += 1
        
      if j+1 <= w-1 and sn[i][j+1] == "." :
        csn[i][j+1] += 1        

      if i-1 >= 0 and j-1 >= 0 and sn[i-1][j-1] == "." :
        csn[i-1][j-1] += 1
 
      if i-1 >= 0 and j+1 <= w-1  and sn[i-1][j+1] == "." :
        csn[i-1][j+1] += 1 

      if i+1 <= h-1 and j-1 >= 0 and sn[i+1][j-1] == "." :
        csn[i+1][j-1] += 1        
        
      if i+1 <= h-1 and j+1 <= w-1 and sn[i+1][j+1] == "." :
        csn[i+1][j+1] += 1    
        
for i in range(h):
  for j in range(w):  
    if csn[i][j] == -1 :
      print("#", end='')
    else :
      print(csn[i][j], end='')
  print()

Measured memory_bytes: 9280
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF =1e9;
const ll LINF=1e18;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a / gcd(a, b)*b;}
string s;
int k;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s>>k;
    int n=s.size();
    ll dp[n+1][k+1][2];
    memset(dp,0,sizeof dp);
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++){
            for(int l=0;l<2;l++){
                ll temp=s[i]-'0';
                if(j==k){//0を選ぶ
                    if(l==0){
                        if(temp==0){
                            dp[i+1][k][0]+=dp[i][k][l];
                        }
                        else{
                            dp[i+1][k][1]+=dp[i][k][l];
                        }
                    }
                    else{
                        dp[i+1][k][1]+=dp[i][k][l];
                    }
                }
                else{
                if(l==0){
                    if(temp==0){
                        dp[i+1][j][0]+=dp[i][j][l];
                    }
                    else{
                        dp[i+1][j][1]+=dp[i][j][l];
                        dp[i+1][j+1][0]+=dp[i][j][l];
                        dp[i+1][j+1][1]+=dp[i][j][l]*(temp-1);
                    }
                }
                else{
                        dp[i+1][j][1]+=dp[i][j][l];
                        dp[i+1][j+1][1]+=dp[i][j][l]*9;
                }
                }
            }
        }
    }
    /*
    for(int i=0;i<=n;i++){
        for(int j=0;j<=k;j++){
            for(int l=0;l<2;l++){
                cout<<dp[i][j][l]<<" ";
            }
            cout<<"\n";
        }
        cout<<"\n";
    }
    */
    cout <<dp[n][k][0]+dp[n][k][1] << "\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N (long long)(998244353)
#define MAX 500000
using namespace std;

long long factorial[MAX] = {0}, finverse[MAX] = {0},
          inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for(int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if(n == k && n == 0) return 1;
  if(n < 0 || k < 0 || n < k) return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] %
         N;
}

long long n, k, a;
long long dp[200005] = {0}, sum[200005] = {0};

long long solve();

int main() {
  cin >> n >> k >> a;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  smodfact();
  for(int i = 0; i <= n; ++i)
    dp[k + i] = 100 * inverse[a] % N;
  a *= inverse[100];
  a %= N;
  sum[k] = n;
  for(int i = k - 1; i >= 0; --i) {
    dp[i] = sum[i + 1] * inverse[n] % N;
    sum[i] = sum[i + 1] + dp[i] * a % N;
    sum[i] %= N;
    sum[i] -= dp[i + n] * a % N;
    sum[i] += N;
    sum[i] %= N;
  }
  return dp[0];
}


Measured memory_bytes: 17156
#include<stdio.h>
 
 int main(){
	 int a,b,n;
	 scanf("%d %d %d",&n,&a,&b);
	 char s[n+1];
	 scanf("%s",s);
	 int passer = 0;
	 int passer_foreigner = 0;
	 
	 int i=0;
	 for(i=0;i<n;i++){
		 if(s[i]=='c'){
			 printf("No\n");
		 }else if(s[i]=='a'){
			 if(passer<a+b){
				 printf("Yes\n");
				 passer++;
			 }else{
				 printf("No\n");
			 }
		 }else if(s[i]=='b'){
			 if(passer<a+b){
				 if(passer_foreigner<b){
					 printf("Yes\n");
					 passer++;
					 passer_foreigner++;
				 }else{
					 printf("No\n");
				 }
			 }else{
				 printf("No\n");
			 }
		 }
	 }
	 
	 return 0;
 }

Measured memory_bytes: 640
while 1:
    s1=input().split('"')
    if s1[0]==".":
        break
    s2=input().split('"')
     
    cnt1=0
    cnt2=0
    flag=0
     
    if len(s1)!=len(s2):
        print("DIFFERENT")
    else:
        i=0
        while i<len(s1):
            if s1[i]==s2[i]:
                cnt1+=1
            elif i%2==0:
                print("DIFFERENT")
                flag=1
                break
            else:
                cnt2+=1
                if cnt2>1:
                    print("DIFFERENT")
                    break
            i+=1
                 
        if flag==0 and cnt2==1:
            print("CLOSE")
        if cnt1==len(s1):
            print("IDENTICAL")


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

int main(void) {
  long X, A, B;
  cin >> X >> A >> B;

  if (B <= A) {
    cout << "delicious" << endl;
    return 0;
  }

  if (B - A <= X) {
    cout << "safe" << endl;
    return 0;
  }

  cout << "dangerous" << endl;
  return 0;
}


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

using namespace std;

int main(){

  while(1){
	int n,a,b,c,x;
	
	cin >> n >> a >> b >> c >> x;
	if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
	  break;
	
	vector<int> y(n);

	for(int i = 0;i < n; ++i)
	  cin >> y[i];

	int f = 0;
	int cnt = 0;
	
	while(1){

	  if(x == y[cnt]){
		cnt++;
		if(cnt == n)
		  break;
	  }
	  
	  x = (a * x + b) % c;
	  f++;
	  
	  if(f > 10000)
		break;
	}
	
	  if(f > 10000)
		cout << -1 << endl;
	  else
		cout << f << endl;
	
  }

  return 0;
  
}



Measured memory_bytes: 3056
S = str(input())
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

def afunc(a,b,c,d):
  alist = [a,b,c,d]
  pre = a
  for char in alist[1:4]:
    if pre == char:
      print("Bad")
      return
    else:
      pre = char
  print("Good")

afunc(a,b,c,d)


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			int[] a = new int[n], b = new int[n];
			int[] c = new int[m], d = new int[m];
			IntStream.range(0, n).forEach(i -> {
				a[i] = scanner.nextInt();
				b[i] = scanner.nextInt();
			});
			IntStream.range(0, m).forEach(i -> {
				c[i] = scanner.nextInt();
				d[i] = scanner.nextInt();
			});
			IntStream.range(0, n).map(i -> {
				int min = Integer.MAX_VALUE;
				int minIndex = -1;
				for (int j = 0; j < m; j++) {
					int distance = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
					if (distance < min) {
						min = distance;
						minIndex = j;
					}
				}
				return minIndex + 1;
			}).forEach(System.out::println);
		}
	}
}


Measured memory_bytes: 36608
import java.util.Scanner;

class Main {

	public void aa() {

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();

		int y = sc.nextInt();

		while(x != 0 || y != 0) {

			if(x < y) {

				System.out.println(x + " " + y);

			} else {

				System.out.println(y + " " + x);

			}

			x = sc.nextInt();

			y = sc.nextInt();

		}

	}

	public static void main(String[] args) {

		new Main().aa();

	}

}

Measured memory_bytes: 35028
#include <bits/stdc++.h>
#define max(a,b) a>b ? a:b

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,s,sb,m;
    cin>>a>>b;

    int mxm ;
    s=a+b;
    sb=a-b;
    m=a*b;
    if(a==0 || b==0)
    {

        mxm=max(s,sb);
        if(mxm>0) cout<<mxm<<endl;
        else cout<<0<<endl;
    }
    else {

        mxm=max(s,sb);
        mxm=max(mxm,m);
        cout<<mxm<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;
typedef long long ll;

int main(){

    int K, S;
    cin >> K >> S;

    int ans = 0;
    rep(x, K + 1)rep(y, K + 1){
        int z = S - x - y;
        if(0 <= z and z <= K)ans++;
    }
    cout << ans << endl;
    
}

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

using namespace std;

typedef long long ll;

const int N = 1e6;

const long double PI = acos(-1.0);

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<long double> x(n), y(n), p(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    for (int i = 0; i < N; ++i) {
        long double a = 2 * PI * i / N;
        int best = 0;
        long double d = 1e9;
        for (int j = 0; j < n; ++j) {
            long double tmp = x[j] * cos(a) + y[j] * sin(a);
            if (tmp < d) {
                d = tmp;
                best = j;
            }
        }
        ++p[best];
    }
    cout << fixed << setprecision(30);
    for (int i = 0; i < n; ++i) {
        cout << p[i] / N << '\n';
    }
    return 0;
}

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

int main(){
    map<int,int> A;
    int N;
    cin >> N;

    int ans=0;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        A[a]^=1;
        if(A[a]) ans++;
        else ans--;
    }

    cout << ans << endl;
}

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

string a[100],b[100],c[100],d[100];

int calc(string s){
	return ((s[0]-'0')*10+(s[1]-'0'))*60+(s[3]-'0')*10+s[4]-'0';
}

int main(){
	int N,T;
	cin >> N >> T;
	int cnt = 0;
	for(int i = 0 ; i < N ; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		if(i){
			if( calc(a[i])-calc(c[i-1]) >= T ){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	for(int i = 0 ; i < N ; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		if(i){
			if( calc(a[i])-calc(c[i-1]) >= T ){
				cout << b[i] << " " << calc(a[i])-calc(c[i-1]) << endl;
			}
		}
	}
}
	

Measured memory_bytes: 1224
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int R, C, n;
long long G[201000], M1, M2;
vector<int>E[201000], L[201000];
bool v[201000];
void DFS(int a, long long g){
    int i;
    v[a] = true;
    G[a] = g;
    if(a<=R)M1=min(M1,g);
    else M2=min(M2,g);
    for(i=0;i<E[a].size();i++){
        if(!v[E[a][i]])DFS(E[a][i], L[a][i]-g);
    }
}
int main(){
    int i, x, y, c, j;
    scanf("%d%d%d",&R,&C,&n);
    for(i=1;i<=n;i++){
        scanf("%d%d%d",&x,&y,&c);
        E[x].push_back(y+R);L[x].push_back(c);
        E[y+R].push_back(x);L[y+R].push_back(c);
    }
    for(i=1;i<=R+C;i++){
        M1 = M2 = 1e9;
        if(!v[i]){
            DFS(i,0);
        }
        if(M1+M2<0){
            printf("No\n");
            return 0;
        }
    }
    for(i=1;i<=R;i++){
        for(j=0;j<E[i].size();j++){
            if(G[i] + G[E[i][j]] != L[i][j]){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 23936
#include<stdio.h>

int main() {
	int a, b,c;
	int x;
	int result = 0;
	int i, j, k;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &x);
	for (i = 0; i <=a; i++) {
		for (j = 0; j <= b; j++) {
			for (k = 0; k <= c; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					result=result+1;
				}
			}
		}
	}
	printf("%d", result);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int nextInt();
void sort(int *a, int size);

int N, i;
int A[100000], B[100000], C[100000];
long long int a, b;

int main(){
	N=nextInt();
	for(i=0; i<N; i++){
		A[i]=nextInt();
		B[i]=nextInt();
		C[i] = A[i] + B[i];
		b += B[i];
	}
	sort(C, N);
	for(i=0; i<N; i+=2){
		a += C[i];
	}
	printf("%lld\n", a-b);
	return 0;
}

int nextInt(){
	int f=0; char c=getchar();
	while((c<'0')||('9'<c)){c=getchar();}
	while((c>='0')&&(c<='9')){f=f*10+(c-'0'); c=getchar();}
	return f;
}

char compare(int x, int y){
	return x > y;
}

int med3(int x, int y, int z){
	if(compare(x, y)){
		if (compare(y, z)){return y;}else if(compare(z, x)){return x;}else{return z;}
	} else {
		if (compare(z, y)){return y;}else if(compare(x, z)){return x;}else{return z;}
	}
}

void quickSort(int *a, int left, int right){
	if(left >= right){return;}
	int pivot = med3(a[left], a[left+(right-left)/2], a[right]);
	int l=left, r=right;
	int t;
	while(1){
		while (compare(a[l], pivot)){l++;}
		while (compare(pivot, a[r])){r--;}
		if(l>=r){break;}
		t=a[l]; a[l]=a[r]; a[r]=t;
		l++; r--;
	}
	quickSort(a, left, l-1);
	quickSort(a, r+1, right);
}

void sort(int *a, int size){
	quickSort(a, 0, size-1);
}


Measured memory_bytes: 1280
n = gets.chomp.to_i
h = {}

n.times do |i|
  p = gets.chomp.to_i
  h[p] = i
end

max = 0
count = 1
(1..(n-1)).each do |i|
  if h[i] < h[i+1]
    count += 1
  else
    max = count if max < count
    count = 1
  end
end
max = count if max < count

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

Measured memory_bytes: 14716
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

/*
0のアスキー　"48"
*/

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;

    if(a >= 0 and c >= 0)
        cout << b * d << endl;
    else if(b <= 0 and d <= 0)
        cout << a * c << endl;
    else if (b < 0 and c >= 0)
        cout << b * c << endl;
    else if(a >= 0 and d < 0)
        cout << a * d << endl;
    else if(a < 0 and b >= 0 and d <= 0)
        cout << a * c << endl;
    else if(b <= 0 and c < 0 and d >= 0)
        cout << a * c << endl;
    else if(a >= 0 and c < 0 and d >= 0)
        cout << b * d << endl;
    else if(a < 0 and b >= 0 and c >= 0)
        cout << b * d << endl;
    else if(a < 0 and b >= 0 and c < 0 and d >= 0){
        if(a * c >= b * d)
            cout << a * c << endl;
        else
            cout << b * d << endl;
    }
}

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

int main() {
	int n, q; cin >> n >> q;
	string s; cin >> s;
	vector<int> allCnt(n);
	for (int i = 0; i < n-1; i++) {
		string tmp; tmp += s[i]; tmp += s[i + 1];
		if (tmp == "AC") allCnt[i + 1] = allCnt[i] + 1;
		else allCnt[i + 1] = allCnt[i];
	}
	for (int i = 0; i < q; i++) {
		int l, r; cin >> l >> r;
		cout << allCnt[r - 1] - allCnt[l - 1] << endl;
	}

	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 n, a;
void solve(){
	cin >> n >> a;
	
	int cnt = 0, mi = INF, m = 1;
	for(int i = 0; i < n; i++){
		cnt += a+i;
		if(chmin(mi, abs(a+i)) && a+i < 0) m = -1;
	}
	cout << cnt-mi*m << endl;
}

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


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

int main() { 
    int h, n, sum = 0;
    cin >> h >> n;
    int a[n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if(sum >= h) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 640
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val W, H = ni()
    val P = na(W)
    val Q = na(H)

    case class Path(v: Int, x: Int)
    val A = Array.ofDim[Path](W + H)
    rep(W)(i => A(i) = Path(P(i), 0))
    rep(H)(i => A(i + W) = Path(Q(i), 1))
    Sorting.quickSort(A)(Ordering.by(_.v))

    var ans = 0L
    val c = Array[Long](H + 1, W + 1)
    rep(A.length) { i =>
      val p = A(i)
      ans += c(p.x) * p.v
      c(p.x ^ 1) -= 1
    }

    out.println(ans)
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

Measured memory_bytes: 115420
ans = "Yes"
s = input()
if s != s[::-1]: # スライスというやつ 全体が回文かどうか
  ans = "No"
n = len(s) // 2
if s[:n] != s[n-1::-1]: # 全体が回文は保証されているので片方だけ判定
  ans = "No"
print(ans)

Measured memory_bytes: 2940