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

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i < (int)vec.size(); ++i) {
        os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
void dump_func() {
    cerr << "\n";
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) == 0) {
        cerr << " ";
    } else {
        cerr << ", ";
    }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" << to_string(__LINE__) << "]"        \
                       << "    " << string(#__VA_ARGS__) << " = ", \
                  dump_func(__VA_ARGS__)

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()
#define CAUTO const auto&

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI w(n);
    VI s(n + 1);
    s[0] = 0;
    REP(i, n) {
        int temp;
        cin >> temp;
        w[i] = temp;
        s[i + 1] = s[i] + temp;
    }
    int ans = INT_MAX;
    FOR(i, 0, n - 2) {
        int l, r;
        l = s[i + 1], r = s[n] - s[i + 1];
        if (ans > abs(r - l)) ans = abs(r - l);
    }
    cout << ans << ln;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void) {
  int n, m, rmax;
  cin >> n >> m >> rmax;
  int r[8];
  for (int i = 0; i < rmax; i++) {
    cin >> r[i];
    r[i]--;
  }
  int dist[200][200];
  for (int i = 0; i < 200; i++) {
    for (int j = 0; j < 200; j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = 1e8;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a - 1][b - 1] = c;
    dist[b - 1][a - 1] = c;
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  /*
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cout << dist[i][j] << " ";
    }
    cout << endl;
  }
  cout << "---------------" << endl;
  */

  sort(r, r + rmax);
  int ans = 1e8;
  do {
    int progress = 0;
    for (int i = 0; i + 1 < rmax; i++) {
      int from = r[i];
      int to = r[i + 1];
      int d = dist[from][to];
      progress += d;
    }
    ans = min(ans, progress);
  } while (next_permutation(r, r + rmax));
  cout << ans << endl;
  return EXIT_SUCCESS;
}



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

int main() {
  int K;
  cin >> K;
  string S;
  cin >> S;
  
  if(S.size()<=K){
    cout << S << endl;
  }
  else{
    for(int i=0; i<K; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
}




Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
	ll a,b,x;cin>>a>>b>>x;
	if(a%x==0) a=a;
	else a=a+x-a%x;
	//cout<<a<<endl;
	b=b-b%x;
	//cout<<b<<endl;
	cout<<(b-a+x)/x<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a = [(num,i) for i,num in enumerate(a)]
a.sort(reverse=True)
dp=[[0]*(n+1) for _ in range(n+1)]
for i in range(n+1):
    for j in range(n-i+1):
        if i>0:
            dp[i][j] = max(dp[i][j],dp[i-1][j]+a[i+j-1][0]*abs(a[i+j-1][1]-(i-1)))
        if j>0:
            dp[i][j] = max(dp[i][j],dp[i][j-1]+ a[i+j-1][0]*abs(a[i+j-1][1]-(n-j)))
ans = max(dp[i][n-i] for i in range(n+1))
print(ans)


Measured memory_bytes: 106044
a=[]
a=input().split(" ")
N=int(a[0])
K=int(a[1])
b=[]
b=[int(input()) for i in range(N)]
b.sort()
c=[]
for i in range(0,N-K+1) :
    b1=b[K-1+i]
    b2=b[i]
    d=b1-b2
    c.append(d)
c.sort()
p=c[0]
print(p)


Measured memory_bytes: 11316
MAX_VAL = 10000

def countingSort(a, b, k, n)
  c = Array.new(k, 0)

  n.times do |i|
    c[a[i]] += 1
  end

  1.upto(k-1) do |i|
    c[i] = c[i] + c[i-1]
  end

  (n-1).downto(0) do |i|
    b[c[a[i]]-1] = a[i]
    c[a[i]] -= 1
  end

end

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
b = Marshal.load(Marshal.dump(a))
countingSort(a, b, MAX_VAL, n)
puts b.join(' ')

Measured memory_bytes: 218172
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}

ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}

bool sortreverse(ll a, ll b) {
	return a > b;
}

bool kansu(pll a, pll b) {
	return a.first < b.first;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll dp[40010];


int main() {
	ll h, n;
	cin >> h >> n;
	vl a(n), b(n);
	rep(i, 0, n) {
		cin >> a[i] >> b[i];
	}
	dp[h] = 0;
	rep(i, 0, 10010) {
		if (i == h)continue;
		dp[i] = 100000000000;
	}
	for (ll i = 1; i < h + 1; i++) {
		ll ref = INF,ma = 0;
		for (ll j = 0; j < n; j++) {
			if (ref > dp[h - i + a[j]] + b[j]) {
				ref = dp[h - i + a[j]] + b[j];
			}
		}
		dp[h - i] = ref;
	}
	ll ans = INF;
	rep(i, 0, n) {
		rep(j, 0, a[i] + 1) {
			ans = min(ans, dp[j] + b[i]);
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>

using namespace std;

int main(){
    long long N,A,B;
    long long H[100000];
    cin>>N>>A>>B;
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    //high回やれば必ず可能，low回では必ず不可能
    long long low=0;
    long long high=1e9;
    long long sa=A-B;
    while(high-low>1){
        long long mid=(low+high)/2;
        long long num=0;
        for(int i=0;i<N;i++){
            long long tmp=H[i]-mid*B;
            if(tmp>0){
                num += (tmp+sa-1)/sa;
            }
        }
        if(num<=mid){
            high=mid;
        }else{
            low=mid;
        }
    }
    cout<<high<<endl;
    return 0;
}


Measured memory_bytes: 1024
ary = list(map(int, input().split()))
ary = sorted(ary)

ans = -1
if ary[0] == 1:
    ans = 1 if ary[1] == 1 else (ary[1] - 2)
elif ary[0] == 2:
    ans = 0
else:
    ans = (ary[0] - 2) * (ary[1] - 2)
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Exception;
import java.lang.Integer;
import java.lang.System;

public class Main {
    public static void main(String[] a) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        String s;
        int n, count;

        while ((s = r.readLine()) != null) {
            count = 0;
            n = Integer.parseInt(s);
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    for (int k = 0; k < 10; k++) {
                        for (int m = 0; m < 10; m ++) {
                            if ((i + j + k + m) == n) {
                                count++;
                            }
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 18992
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(br.readLine());
        int i = 1;

        do {
            int x = i;
            if (CHECK_NUM(x) != -1) {
                bw.append(" " + i);
            } else {
                loop:
                while (x > 0) {
                    if (INCLUDE3(x) != -1) {
                        bw.append(" " + i);
                        break;
                    }
                    x /= 10;
                }
            }
        }
        while (++i <= n);
        bw.newLine();
        bw.flush();
    }

    static int INCLUDE3(int x) {
        if (x % 10 == 3) {
            return x;
        }
        return -1;
    }

    static int CHECK_NUM(int x) {
        if (x % 3 == 0) {
            return x;
        }
        return -1;
    }

}


Measured memory_bytes: 26024
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>

using namespace std;

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

	string ans;
	for(char& c: input) {
		if(c == '0' || c == '1') {
			string c_str{c}; // char to string
			ans += c_str;
		} else {
			if(ans.size() > 0) ans.pop_back(); // いけた
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
    long long n,m;
    scanf("%lld %lld",&n,&m);
    if(n*500>=m)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
int dy[] = {1,0,-1,0};
int dx[] = {0,1,0,-1};
int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char> > g(H,vector<char>(W));
  rep(i,H) rep(j,W) cin >> g[i][j];
  rep(i,H) rep(j,W) {
    if(g[i][j] == '.')continue;
    bool ok = false;
    rep(k,4) {
      int ny = i + dy[k];
      int nx = j + dx[k];
      if(ny < 0 || nx < 0 || nx >= W || ny >= H)continue;
      if(g[ny][nx] == '#')ok = true;
    }
    if(!ok) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;
bool used[30][30];
bool forbid[30][30];
int H, W;
int dfs(int x, int y){
    if(x == W) return dfs(0, y + 1);
    if(y == H) return 1;
    if(used[y][x]) return dfs(x + 1, y);
    if(forbid[y][x]) return 0;
    int res = 0;
    if(y + 1 < H && !used[y][x] && !used[y + 1][x]){
        bool tmp = forbid[y + 2][x + 1];
        used[y][x] = true;
        used[y + 1][x] = true;
        forbid[y + 2][x + 1] = true;
        res += dfs(x + 1, y);
        used[y][x] = false;
        used[y + 1][x] = false;
        forbid[y + 2][x + 1] = tmp;
    }
    if(x + 1 < W && !used[y][x] && !used[y][x + 1]){
        bool tmp = forbid[y + 1][x + 2];
        used[y][x] = true;
        used[y][x + 1] = true;
        forbid[y + 1][x + 2] = true;
        res += dfs(x + 2, y);
        used[y][x] = false;
        used[y][x + 1] = false;
        forbid[y + 1][x + 2] = tmp;
    }
    return res;
}
int main(){
    while(cin >> H >> W && (H > 0 && W > 0)){
        memset(used, 0, sizeof used);
        memset(forbid, 0, sizeof forbid);
        REP(y, 30) REP(x, 30) assert(!used[y][x]);
        REP(y, 30) REP(x, 30) assert(!forbid[y][x]);
        cout << dfs(0, 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1180
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];

		for(int i=0; i<n; i++) {
			x[i] = sc.nextInt();
		}

		for(int i=0; i<n; i++) {
			y[i] = sc.nextInt();
		}

		// マンハッタン距離
		double manhattan = 0;
		for(int i=0; i<n; i++) {
			manhattan += Math.abs(x[i] - y[i]);
		}


		// ユークリッド距離
		double euclid = 0;
		for(int i=0; i<n; i++) {
			euclid += Math.pow(x[i] - y[i], 2);
		}
		euclid = Math.sqrt(euclid);

		// チェビシェフ距離
		ArrayList<Double> distances = new ArrayList<>();
		for(int i=0; i<n; i++) {
			Double d = Math.abs(x[i] - y[i] - 0.0);
			distances.add(d);
		}
		Collections.sort(distances);
		Collections.reverse(distances);
		double chebyshev = distances.get(0);

		// 	ミンコフスキー距離
		double minkowski = 0;
		double p = 3.0;
		for(int i=0; i<n; i++) {
			minkowski += Math.pow(Math.abs(x[i] - y[i]), p);
		}
		minkowski = Math.pow(minkowski, 1/p);


		System.out.println(manhattan);
		System.out.println(euclid);
		System.out.println(minkowski);
		System.out.println(chebyshev);

		sc.close();

	}

}


Measured memory_bytes: 26644
def main():
    s = input()
    start = 200000
    end = 0
    for i in range(len(s)):
        if s[i] == 'A' and start > i:
            start = i
        elif s[i] == 'Z' and end < i:
            end = i
    print(end - start + 1)



if __name__ == '__main__':
    main()

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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long x = scan.nextLong();
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextLong();
        }
        Arrays.sort(a);
        int answer = 0;
        for (int i = 0; i < N; i++) {
            if (i == N - 1) {
                if (a[i] == x) {
                    answer += 1;
                }
                break;
            }
            if (a[i] <= x) {
                answer += 1;
                x -= a[i];
                continue;
            }
            break;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23764
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
print((n - 1) * n // 2)

Measured memory_bytes: 59500
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;cin>>s;
	int n = s.size();
	string a,b;
	for(int i = 0; i < n / 2; i++) {
		a.pb(s[i]);
	}
	int j = 0;
	for(int i = n / 2 + 1; i < n; i++) {

		b.pb(s[i]);
		j++;
	}
	n = a.size();
	for(int i = 0; i < n/2; i++) {
		if (a[i] == a[n - 1 - i] &&b[i] == b[n - 1 - i]){
			continue;
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i = 0; i < n; i++) {
		if (a[i] == b[i]){
			continue;
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int bucket[4][128];
	int player[256][4];
	int n, i, j;
	int score;

	memset(bucket, 0, sizeof(bucket));

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			scanf("%d", &player[i][j]);
			bucket[j][player[i][j]]++;
		}
	}
	for (i = 0; i < n; i++){
		score = 0;
		for (j = 0; j < 3; j++){
			score += player[i][j] * (bucket[j][player[i][j]] == 1);
		}
		printf("%d\n", score);
	}
	return (0);
}

Measured memory_bytes: 604
#include<iostream>

using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  while (1)
  {
      if(a > 0){
          c  = c - b;
      }else
      {
          cout << "No" << endl;
          return 0;
      }
      if(c > 0){
          a  = a - d;
      }else
      {
          cout << "Yes" << endl;
          return 0;
      }
      
  }
  
}

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

typedef long long int lli;
#define pb push_back
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen("aaa.in","r",stdin);freopen("aaa.out","w",stdout);

using namespace std;

const long long int N = (lli)(1e5 + 5);
const long long int llinf = (1e18 + 5);

lli n;
char str[N];

int main ()
{
	fast;
	//fast2;
	cin >> n;
	cin >> str + 1;
	if (n % 2 == 1)
		return cout << "No",0;
	for (int i = 1; i <= n / 2; i++)
	{
		if (str[i] != str[i + n / 2])
			return cout << "No",0;
	}
	cout << "Yes\n";
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, d float64
	fmt.Scan(&a, &b, &c, &d)
	if math.Abs(a - c) <= d {
		fmt.Println("Yes")
		return
	} else if math.Abs(a - b) <= d && math.Abs(b - c) <= d {
		fmt.Println("Yes")
		return
	} else {
		fmt.Println("No")
		return
	}
}


Measured memory_bytes: 512
N=int(input())
L=list(range(1,N+1))
L3=list(range(3,N+1,3))
L5=list(range(5,N+1,5))
L15=list(range(15,N+1,15))
ans=sum(L)-sum(L3)-sum(L5)+sum(L15)
print(ans)

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

int main(){
    int a;
    cin >> a;
    cout << a*a*a + a*a + a << endl;
}

Measured memory_bytes: 3628
h,w,n=map(int,input().split())
s=set()
l=[[0,0],[1,1],[1,-1],[-1,1],[-1,-1],[0,1],[0,-1],[1,0],[-1,0]]
ans=[(h-2)*(w-2),0,0,0,0,0,0,0,0,0]
for i in range(n):
    a,b=[int(j) for j in input().split()]
    s.add((a,b))
    for i,j in l:
        if a+i>=1 and a+i<=h and b+j>=1 and b+j<=w:
            c=0
            for p,q in l:
                if a+i+p>=1 and a+i+p<=h and b+j+q>=1 and b+j+q<=w:
                    if (a+i+p,b+j+q) in s:
                        c+=1
                else:
                    c=0
                    break
            if c!=0:
                ans[c-1]-=1
                ans[c]+=1

for i in range(10):
    print(ans[i])







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

// void Q_sort(int Nums[], int left, int right){
//   int pivot, l_tmp, r_tmp;
//   l_tmp = left;
//   r_tmp = right;
//   pivot = Nums[left];
//   while(left<right){
//     while((Nums[right] >= pivot) && (left < right)){
//       right--;
//     }
//     //divide area: [left:r_tmp]
//     if(left != right){
//       Nums[left] = Nums[right];
//       left++;
//     }
//     while((Nums[left] <= pivot) && (left < right)){
//       left++;
//     }
//     //divide area: [l_tmp:right]
//     if(left != right){
//       Nums[right] == Nums[left];
//       right--;
//     }
//   }
//   Nums[left] = pivot;
//   pivot = left;
//   left = l_tmp;
//   right = r_tmp;
//   if (left < pivot)//left block
//     Q_sort(Nums, left, pivot-1);
//   if (right > pivot)//right block
//     Q_sort(Nums, pivot+1, right);
// }

void QuickSort(int Num[],int left, int right){
  int i,j,Pivot,w,Flag;
  if(left<right){
    Pivot = Num[left];
    i = left+1;
    j = right;
    Flag = 1;
    while(Flag == 1){
      while((Num[i]<=Pivot) && (i<right)){
	i = i+1;
      }
      while((Num[j]>=Pivot) && (j>left)){
	j = j-1;
      }
      if(i>=j)
	Flag = 0;
      else{
	w = Num[i];
	Num[i] = Num[j];
	Num[j] = w;

      }
    }
    Num[left] = Num[j];
    Num[j] = Pivot;
    QuickSort(Num,left,j-1);
    QuickSort(Num,j+1,right);
  }
}

void Quick_Sort(int Nums[], int N){
  QuickSort(Nums, 0, N-1);
}


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

  Quick_Sort(a,N);
 
  int alice=0,bob=0;

  // for debug
  // for(int i=0;i<N;i++)
  //   cout << a[i] << " ";
  // cout << endl;

  bob = 1;
  for(int i=N-1;i>=0;i--){
    alice += bob*a[i];
    bob = bob*(-1);
  }
  
  // for(int i=N-1;i>0;i--){
  //   alice += a[i];
  //   bob += a[i-1];
  // }
  // cout <<"alice: "<< alice << " bob:  "<<bob<< endl;
  cout << alice << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

template <int MD>
struct ModInt {
    typedef ModInt M;
    int v;
    ModInt(int _v = 0) : v(_v) {}
    M& operator += (const M &r) {
        if ((v += r.v) >= MD) v -= MD;
        return *this;
    }
    M& operator *= (const M &r) {
        v = ll(v) * r.v % MD;
        return *this;
    }
    M operator + (const M &r) const { return M(*this) += r; }
    M operator * (const M &r) const { return M(*this) *= r; }
};
typedef ModInt<1000000007> Mint;

const int MN = 100010;
int n;
Mint dp[MN][2];
vector<int> g[MN];

void dfs(int v, int p) {
    dp[v][0] = 1;
    dp[v][1] = 1;
    for (int i = 0; i < int(g[v].size()); i++) {
        int u = g[v][i];
        if (u == p) continue;
        dfs(u, v);
        dp[v][0] *= (dp[u][0] + dp[u][1]);
        dp[v][1] *= dp[u][0];
    }
}

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

    cin >> n;
    if (n == 1) {
        cout << 2 << endl;
        return 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, -1);
    cout << (dp[0][0] + dp[0][1]).v << endl;
    return 0;
}

Measured memory_bytes: 13440
#include <iostream>;
#include<algorithm>
using namespace std;
int main()
{
int a[3];
cin>> a[0]>> a[1]>> a[2];
for(int i=0;i<2;i++)
{
     for(int j=1;j<3;j++)
     {
         if(a[i]>a[j])
         {
            int temp=a[i]; a[i]=a[j]; a[j]=temp;
         }
     }
}
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>

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

using namespace std;

int main() {
    int price[6];
    rep(i, 6) {
        price[i] = 100 + i;
    }   
    bool dp[100000] = {false};
    int x;
    cin >> x;
    rep(i, 101) {
        dp[i] = false;
    }   
    rep(i, 6) {
        dp[100 + i] = true;
    }   
    for (int i = 106; i < x + 1; i++) {
        for (int j = 0; j < 6; j++) {
            if (dp[i - 100 - j]) {
                dp[i] = true;
            }   
        }   
    }   
    if (dp[x]) {
        cout << 1 << endl;
    }   
    else {
        cout << 0 << endl;
    }   
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int imos[100100];

bool isPrime(int x){
    if(x == 1){return false;}
    
    for(ll i=2;i*i<=x;++i){
        if(x % i == 0){return false;}
    }
    return true;
}

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

    for(int i=1;i<=100000;i+=2){
        if(isPrime(i) && isPrime((i + 1) / 2)){
            imos[i] = 1;
        }
    }

    for(int i=1;i<=100000;++i){
        imos[i+1] += imos[i];
    }

    int Q;
    std::cin >> Q;

    for(int i=0;i<Q;++i){
        int l, r;
        std::cin >> l >> r;

        int res = imos[r] - imos[l-1];
        std::cout << res << std::endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ld r; cin >> r;
    cout << r * 2 * pi << "\n";
}

Measured memory_bytes: 3760
#!/usr/bin/env python3

def main():
    *N, = map(int, open(0).read().split())
    p = N[1:]
    N = N[0]

    I = []
    for i in range(1, N+1):
        I.append(i)
    
    err = 0
    for i in range(0, N):
        if not p[i] == I[i]:
            err += 1

    if err <= 2:
        print('YES')
    else:
        print('NO')


main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    
    vector<int> s_cnt(26, 0), t_cnt(26, 0);
    rep(i, s.size()) s_cnt[s[i] - 'a'] = 1;
    rep(i, t.size()) t_cnt[t[i] - 'a'] = 1;
    rep(i, 26) {
        if (t_cnt[i] && !s_cnt[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<vector<int>> s_basyo(26);
    rep(i, s.size()) s_basyo[s[i] - 'a'].push_back(i);
    long long ans_0 = 0;
    long long ans_1 = -1;
    rep(i, t.size()) {
        auto iter = upper_bound(s_basyo[t[i] - 'a'].begin(), s_basyo[t[i] - 'a'].end(), ans_1);
        if (iter ==  s_basyo[t[i] - 'a'].end()) {
            ++ans_0;
            ans_1 = *s_basyo[t[i] - 'a'].begin();
        } else {
            ans_1 = *iter;
        }
    }
    cout << ans_0 * s.size() + ans_1 + 1 << endl;
}


Measured memory_bytes: 1216
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var AB = ReadSplitLong();
            if (AB.All(x => x >= 1 && x <= 9))
                Println(AB[0] * AB[1]);
            else
                Println(-1);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
  int price[1000];
  int n, m, pack, hoge, howmach;

  while (cin >> n >> m, n) {
    for (int i = 0; i < n; i++)
      cin >> price[i];

    sort(price, price + n);
    pack = n / m;
    hoge = n % m;
    howmach = accumulate(price, price + n, 0);
    for (int i = 0; i < pack; i++) {
      howmach -= price[m * i + hoge];
    }
    cout << howmach << endl;
  }
  return 0;
}

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

int main()
{
    int n,m=0;
    cin>>n;
    int arr[n];
   
    
    for(int i=0 ; i<n;i++)
        cin>>arr[i];
    
   
    
    int mini,temp;
    
	for (int i=0; i < n-1; i++)
	{
        
	    mini = i;
		
        
        
		for (int j=i+1; j < n; j++)
           if (arr[j] < arr[mini])
                mini=j;
        
		
        
        if (mini != i)
        {
            temp = arr[i];
            arr[i] = arr[mini];
            arr[mini] = temp;
            m++;
        }
        
        
        
	}

    for(int i=0 ; i<n-1;i++)
        cout<<arr[i]<<" ";
    cout<<arr[n-1]<<endl;
    
    cout<<m<<endl;
    
	return 0;
}

Measured memory_bytes: 1160
#値を入力
n = int(input())
s = []
for i in range(n):
  s.append(input())

m = int(input())
t = []
for i in range(m):
  t.append(input())

#sに含まれる文字列個数を辞書にカウント
dic = {}

for i in range(n):
  if s[i] not in dic:
    dic[s[i]] = 0
  dic[s[i]] += 1

#tの文字列の中で、sにも含まれている文字列の引き算だけ行う
for i in range(m):
  if t[i] in dic:
    dic[t[i]] -= 1

#辞書の最大値あるいは0のうち大きい方が答え
max_dic = max(max(dic.values()), 0)

print(max_dic)

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

int main(){
    ll n;
    cin >> n;
    ll p = ll(pow(n, 0.5));
    
    rrep(i, p){
        if (n % (i + 1) == 0){
            string x = to_string(n / (i + 1));
            string y = to_string(i + 1);
            cout << max(x.size(), y.size()) << endl;
            break;
        }
    }
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;
long long a[N];

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a+i);
  }
  sort(a, a+n);
  long long lo = 0, hi = n-1;
  vector<pair<long long, long long>> vp;
  while (lo+1 < hi) {
    if (abs(a[hi-1]-(a[lo]-a[hi])) >= abs(a[lo+1]-(a[hi]-a[lo]))) {
      vp.emplace_back(a[lo], a[hi]);
      a[lo] = a[lo]-a[hi--];
    } else {
      vp.emplace_back(a[hi], a[lo]);
      a[hi] = a[hi]-a[lo++];
    }
  }
  printf("%lld\n", a[hi]-a[lo]);
  for (const auto &p: vp) {
    printf("%lld %lld\n", p.first, p.second);
  }
  printf("%lld %lld", a[hi], a[lo]);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 6148
/* bellman_ford.cpp
    ベルマンフォード法で、ある頂点から各頂点への最短距離を求めるアルゴリズム
    負の辺が含まれる場合も適用でき、負の閉路も検出可能

    始点から終点に行くまでに通らない負の閉路は検出したくない時:
        http://sigma1113.hatenablog.com/entry/2019/08/12/130042

    verified:
*/

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

struct Edge {
    long long from;
    long long to;
    long long cost;
};
using Edges = vector<Edge>;
const long long INF = 1LL << 60;

/* bellman_ford(Es,s,t,dis)
    入力: 全ての辺Es, 頂点数V, 開始点 s, 最短経路を記録するdis
    出力: 負の閉路が存在するなら ture
    計算量：O(|E||V|)
    副作用：dis が書き換えられる
*/
bool bellman_ford(const Edges &Es, int V, int s, vector<long long> &dis) {
    dis.resize(V, INF);
    dis[s] = 0;
    int cnt = 0;
    while (cnt < V) {
        bool end = true;
        for (auto e : Es) {
            if (dis[e.from] != INF && dis[e.from] + e.cost < dis[e.to]) {
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
            }
        }
        if (end) break;
        cnt++;
    }
    return (cnt == V);
}

int main() {
    int V, E, r;
    cin >> V >> E >> r;
    Edges Es;
    for (int i = 0; i < E; i++) {
        long long s, t, d;
        cin >> s >> t >> d;
        Es.push_back({s, t, d});
    }
    vector<long long> dis;
    if (bellman_ford(Es, V, r, dis)) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < V; i++) {
            if (dis[i] == INF) {
                cout << "INF" << endl;
            } else {
                cout << dis[i] << endl;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

char a[1010][1010];
char w, x, y, z;

int hantei(int i, int j, int k, char p)
{
	if(k==0)
	{
		if(p==w && a[i][j+1]==x && a[i+1][j]==y && a[i+1][j+1]==z) return 1;
		else return 0;
	}
	else if(k==1)
	{
		if(a[i][j]==w && p==x && a[i+1][j]==y && a[i+1][j+1]==z) return 1;
		else return 0;
	}
	else if(k==2)
	{
		if(a[i][j]==w && a[i][j+1]==x && p==y && a[i+1][j+1]==z) return 1;
		else return 0;
	}
	else if(k==3)
	{
		if(a[i][j]==w && a[i][j+1]==x && a[i+1][j]==y && p==z) return 1;
		else return 0;
	}
}

int main()
{
	int m, n;
	cin >> m >> n;
	
	int b[1010][1010]={};
	rep(i, m) rep(j, n) cin >> a[i][j];
	
	cin >> w >> x >> y >> z;
	int ans1=0;
	rep(i, m-1) rep(j, n-1)
	{
		if(a[i][j]==w && a[i][j+1]==x && a[i+1][j]==y && a[i+1][j+1]==z)
		{
			b[i][j]=1;
			ans1++;
		}
	}
	int ans=0, tmp, tmp1, tmp2, tmp3;
	rep(i, m) rep(j, n)
	{
		tmp=tmp1=tmp2=tmp3=0;
		if(i>0 && j>0)
		{
			if(b[i-1][j-1]==1) tmp--;
				tmp1+=hantei(i-1, j-1, 3, 'J');
				tmp2+=hantei(i-1, j-1, 3, 'O');
				tmp3+=hantei(i-1, j-1, 3, 'I');
		}
		if(i>0 && j<n-1)
		{
			if(b[i-1][j]==1) tmp--;
				tmp1+=hantei(i-1, j, 2, 'J');
				tmp2+=hantei(i-1, j, 2, 'O');
				tmp3+=hantei(i-1, j, 2, 'I');
		}
		if(i<m-1 && j>0)
		{
			if(b[i][j-1]==1) tmp--;
				tmp1+=hantei(i, j-1, 1, 'J');
				tmp2+=hantei(i, j-1, 1, 'O');
				tmp3+=hantei(i, j-1, 1, 'I');
		}
		if(i<m-1 && j<n-1)
		{
			if(b[i][j]==1) tmp--;
				tmp1+=hantei(i, j, 0, 'J');
				tmp2+=hantei(i, j, 0, 'O');
				tmp3+=hantei(i, j, 0, 'I');
		}
		tmp1=max(tmp1, max(tmp2, tmp3));
		tmp+=tmp1;
		ans=max(ans, tmp);
	}
	cout << (ans+ans1) << endl; 
	return 0;
}

Measured memory_bytes: 8072
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val timelines = Array(N + 1) { IntArray(N + 1) }
    for (i in 1 until N) {
        val (c, s, f) = nextIntList()
        for (j in 1..i) {
            val t = timelines[j][i]
            val n = ((t - s + f - 1) / f).coerceAtLeast(0)
            timelines[j][i + 1] = c + s + f * n
        }
    }
    for (i in 1..N) {
        println(timelines[i][N])
    }
}

Measured memory_bytes: 40744
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Usize1},
};

#[fastout]
fn main() {
    input! {
        k : usize
    }
    let mut a = vec![0 ; k+1];
    a[1] = 7%k;
    for i in 2..k+1 {
        a[i] = (a[i-1]*10+7)%k;
    }
    for i in 1..k+1 {
        if a[i] == 0 {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 9968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r = sc.nextInt();
		int ans;

		if (n < 10) {
			ans = r + 100 * (10 - n);
		} else {
			ans = r;
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 35692
n=gets.to_i
a=gets.split.map &:to_i

j=false
if n==2
  if a[0]==1 && a[1]==1
    j=true
  end
elsif a.all?{|w|w==a[0]}
  if a[0]==1
    j=true
  elsif a[0]==n-1
    j=true
  elsif n/2>=a[0]
    j=true
  end
else
  g=a.min
  if a.max-g==1
    gg=a.count{|e|e==g}
    if (n-gg)/2>=a.max-gg && a.max-gg>=1
      if a.max!=n
        j=true
      end
    end
  end
end
puts j ? :Yes : :No


Measured memory_bytes: 8084
#include <bits/stdc++.h>
#include <algorithm> //next_permutation

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;

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

ll a=0;
a=n.size();
ll dp[101][2][5];
memset(dp,0, sizeof(dp));
//dp[桁][0:同じ 1:未満][0以外の数]
dp[0][0][0]=1;

for (int i=0; i<a; i++){
 for (int j=0; j<2; j++){
  for (int k=0; k<4; k++){
  if (j==0){ //制約あり
    ll x=n[i]-'0';
    if (x==0){
      dp[i+1][0][k]+=dp[i][0][k];
    }
    else{
    //0のとき
    dp[i+1][1][k]+=dp[i][0][k];
    //制約保持
    dp[i+1][0][k+1]+=dp[i][0][k];
    //それ以外
    dp[i+1][1][k+1]+=dp[i][0][k]*(x-1);
  }
  }
  if (j==1){
    //0のとき
    dp[i+1][1][k]+=dp[i][1][k];
    //それ以外
    dp[i+1][1][k+1]+=dp[i][1][k]*9;


  }



  }

 }


}
ll ans;
ans=dp[a][1][q]+dp[a][0][q];
cout<<ans;
}


Measured memory_bytes: 256
S = input()
cnt = 0
ml = 0
for i in range (len(S)):
  
  for j in range (i+1, len(S)+1):
    cnt = S[i:j].count("A") + S[i:j].count("T") + S[i:j].count("G") + S[i:j].count("C")    
    if len(S[i:j]) == cnt and cnt > ml:
      ml = cnt
    
print(ml)  

Measured memory_bytes: 3060
import copy

h, w = map(int , input().split() )

board = [input() for _ in range(h)]

left = [ [0]*w for _ in range(h)] 
right = [ [0]*w for _ in range(h)]        #いくつ右のマスを照らせるか
down = [ [0]*w for _ in range(h)]
up = [ [0]*w for _ in range(h)]



for hi in range(h):
    for wi in range(w):

        if board[hi][wi] == '.':
            left[hi][wi] = 1
            up[hi][wi] = 1

            if 1 <= wi:
                left[hi][wi] += left[hi][wi-1]

            if 1 <= hi:
                up[hi][wi] += up[hi-1][wi]


        if board[hi][w-wi-1] =='.':
            right[hi][w-wi-1] = 1

            if 1<=wi:
                right[hi][w-wi-1] += right[hi][w-wi] 

        if board[h-hi-1][wi] == '.':
            down[h-hi-1][wi] = 1

            if 1 <= hi:
                down[h-hi-1][wi] += down[h-hi][wi]


def dbcheck():
    print()
    tag = ["r","l","d","u"]
    for t,x in zip(tag,[right,left,down,up]):
        print(t)
        for row in x:
            print(row)
        print()


#dbcheck()

ans = 0
for i in range(h):
    for j in range(w):
        t = right[i][j] + left[i][j] + up[i][j] + down[i][j]
        t -= 3
        ans = max(ans,t)

print(ans)

Measured memory_bytes: 179844
#include <iostream>

int main(){
	int a = 0, b = 0;
	
	scanf("%d %d", &a, &b);

	if (a < b){
		printf("a < b\n");
	}else if (a > b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}

	return 0;
}

Measured memory_bytes: 1152
using System;
namespace aizu
{
    class No0005
    {
        public static void Main()
        {
            string read;
            while((read = Console.ReadLine()) != null){
                string[] input = read.Split(' ');
                if(input.Length != 2){
                    continue;
                }
                long a = long.Parse(input[0]);
                long b = long.Parse(input[1]);
                long gcd = Euclid(a, b);
                long lcm = a / gcd * b;
                Console.WriteLine("{0} {1}", gcd, lcm);
            }
        }
        public static long Euclid(long value1, long value2)
        {
            long big = value1 > value2 ? value1 : value2;
            long small = value1 > value2 ? value2 : value1;
            long result = small;
            while(big % small != 0){
                result = big % small;
                big = small;
                small = result;
            }
            return result;
        }
    }
}

Measured memory_bytes: 5632
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;

int n;
int a[100011];
int ans;
int main()
{
    int i,j,k;
    
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    ans=0;
    for(i=1;i<=n;i++)
    {
        if(a[a[i]]==i)
        {
            ans++;
        }
    }
    
    cout<<ans/2<<endl;
    
    return 0;
}


Measured memory_bytes: 640
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*3 for i in range(n)]
dp[0][0]=a[0][0]
dp[0][1]=a[0][1]
dp[0][2]=a[0][2]
for i in range(1,n):
    dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2])
    dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2])
    dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0])
print(max(dp[n-1]))   

Measured memory_bytes: 47384
#include "bits/stdc++.h"
using namespace std;

int main() {
	string A, B;
	cin >> A >> B;
	reverse(B.begin(),B.end());
	if (A == B) {
		cout << "YES"<<endl;
	}
	else {
		cout << "NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  const int MOD=1e9+7;
  const int N=2e5+2;

  int32_t main()
  {
   /* #ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
       IOS
       double a,b;
       cin>>a>>b;
       double prod=a*b;
       int ans=(int)prod;
       cout<<ans;
       
    return 0;
 }


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

using namespace std;

typedef long long int ll;

int main()
{
    ll n,d;
    cin>>n>>d;
    ll cnt=0;
    while(n--){
        ll x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d) cnt++;
    }
    cout<<cnt;

    return 0;
}


Measured memory_bytes: 3556