akhauriyash/Code-Regression huggingface dataset:
"use strict";

var main = function main(input) {
  var N = parseInt(input.split("\n")[0]);
  var a = input.split("\n")[1].split(" ").map(function (elem) {
    return parseInt(elem, 10);
  });
  var Alice = 0;
  var Bob = 0;
  a.sort(function (a, b) {
    return a < b ? 1 : -1;
  }).forEach(function (element, i) {
    i % 2 == 0 ? Alice += element : Bob += element;
  });
  console.log(Alice - Bob);
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.length();
    reverse(all(s));
    int i = 0;
    bool ok = 1;
    while(i < n && ok){
        if (s[i] == 'r'){
            if (s.substr(i,6) == "resare") i += 6;
            else if (s.substr(i,7) == "remaerd") i += 7;
            else ok = 0;
        }
        else if (s[i] == 'm'){
            if (s.substr(i,5) == "maerd") i += 5;
            else ok = 0;
        }
        else if (s[i] == 'e'){
            if (s.substr(i,5) == "esare") i += 5;
            else ok = 0;
        }
        else ok = 0;
    }
    if (ok) PRINT("YES");
    else PRINT("NO");
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;
	cin >> str;
	int ans = 0;
	REP(i,str.size())if(str[i] == '1')ans++;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B;
  cin>>N>>A>>B;
  string S;
  cin>>S;
  int count_jp=0,count_al=0;
  vector<string> ans(N,"No");
  for(int i=0;i<N;i++){
    if(S.at(i)=='a' && count_jp+count_al<A+B){
      ans.at(i)="Yes";
      count_jp++;
    }
    else if(S.at(i)=='b' && count_jp+count_al<A+B && count_al<B){
      ans.at(i)="Yes";
      count_al++;
    }
  }  
  for(int i=0;i<N;i++){
  cout<<ans.at(i)<<endl;
  }
}

Measured memory_bytes: 6652
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 5e5 + 5;
int n, a[N], h[N];
int dp[N];
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) scanf("%d", h + i);
	for (int i = 0; i <= n; ++i) dp[i] = 1e9;
	dp[1] = 0;
	for (int i = 2; i <= n; ++i) {
		dp[i] = min(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[n];
}


Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {

    public static void main (String[] args) {
        int A, B, T;
        int result;
        Scanner scan = new Scanner(System.in);
        
        A = scan.nextInt();
        B = scan.nextInt();
        T = scan.nextInt();

        result = B * (T / A);

        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
struct Edge
{
	int v;
	int w;
	Edge(int v = 0, int w = 0):v(v),w(w){}
};
vector <Edge> g[MAXN];
int color[MAXN];
bool vis[MAXN];
void addedge(int u, int v, int w)
{
	g[u].push_back(Edge(v, w));
	g[v].push_back(Edge(u, w));
}
int n;
void dfs(int curr)
{
	vis[curr] = true;
	for (auto i:g[curr])
	{
		if (color[i.v] == -1)
		{
			if (i.w % 2 == 0)color[i.v] = color[curr];
			else color[i.v] = !color[curr];
		}
	}
	for (auto i:g[curr])
		if (!vis[i.v])dfs(i.v);
	
}
int main()
{
	memset(color, -1, sizeof color);
	memset(vis, 0, sizeof vis);
	cin >> n;
	for (int i = 1; i <= n - 1; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		addedge(u, v, w);
	}
	color[1] = 0;
	dfs(1);
	for (int i = 1; i <= n; i++)cout << color[i] << endl;
	return 0;
}


Measured memory_bytes: 7808
#include<iostream>
using namespace std;
int main(void){
  long long n,m;cin>>n>>m;
  if(n==1 && m==1){cout<<"1";}
  else if(n==1){cout<<m-2;}
  else if(m==1){cout<<n-2;}
  else{cout<<(n-2)*(m-2);}
  return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}
cnt = 0

for i in range(1,n+1):
    d[i] = int(input())

btn = 1
while True:
    cnt += 1
    if btn == 0:
        ans = -1
        break
    elif d[btn] == 2:
        ans = cnt
        break
    else:
        tmp = btn
        btn = d[btn]
        d[tmp] = 0

print(ans)


Measured memory_bytes: 17892
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
    string s, t; cin >> s >> t;
    int dp[3001][3001][2] = {};
    for (int i = s.size()-1; i >= 0; i--) {
        for (int j = t.size()-1; j >= 0; j--) {
            int n1 = dp[i+1][j][0], n2 = dp[i][j+1][0],
                n3 = dp[i+1][j+1][0] + (s[i] == t[j]);
            if (n1 >= n2 && n1 >= n3) { dp[i][j][0] = n1; dp[i][j][1] = 1; }
            else if (n2 >= n1 && n2 >= n3) { dp[i][j][0] = n2; dp[i][j][1] = 2; }
            else { dp[i][j][0] = n3; dp[i][j][1] = 3; }
        }
    }
    for (int i = 0, j = 0; i < s.size() && j < t.size(); ) {
        switch (dp[i][j][1]) {
        case 1: i++; break;
        case 2: j++; break;
        case 3: cout << s[i]; i++; j++;
        }
    }
    cout << endl;
}


Measured memory_bytes: 70656
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  // くっつかしたら勝ち
  int N, A, B; cin >> N >> A >> B;
  if(abs(A-B)%2==1) {
    cout << "Borys" << endl;
  } else {
    cout << "Alice" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
object Main extends App {
  def recursive_sum(i: Int): Int = {
    def accumlator(acc: Int, i: Int): Int = if (i == 0) {
      acc
    } else {
      accumlator(acc + (i % 10), i / 10)
    }

    accumlator(0, i)
  }

  val sc = new java.util.Scanner(System.in)
  val n, a, b = sc.nextInt()
  val xs = for {
    i <- Iterator.range(1, n + 1)
    t = (i, recursive_sum(i))
    if a <= t._2 && t._2 <= b
  } yield {
    t._1
  }
  val ret = xs.sum
  println(ret)
}


Measured memory_bytes: 32304
//1WA->add(a{0})for10000->AC
#include<iostream>
using namespace std;

int main(void){
  int N,x,y;
  int a[5];
  long long counter=0;
  cin >> N >> x >> y;

  for(int i=1;i<N+1;i++){
  	a[0]=i/10000;
  	a[1]=(i%10000)/1000;
  	a[2]=(i%1000)/100;
  	a[3]=(i%100)/10;
  	a[4]=i%10;
  	
  	//cout << a[0]+a[1]+a[2]+a[3]+a[4] << endl;
  	
    if(a[0]+a[1]+a[2]+a[3]+a[4]>=x&&a[0]+a[1]+a[2]+a[3]+a[4]<=y)counter+=i;
  }
  cout << counter << endl;
  return 0;
}


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

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

void print_board(vector<bitset<8>>& board) {
    for (auto i = 0; i < 8; i++) {
        for (auto j = 0; j < 8; j++) cout << board[i][j] << " ";
        cout << endl;
    }
}

int main(){
    int k;
    cin >> k;

    vector<pair<int, int>> q(k);
    vector<string> ans(8, string(8, '.'));
    vector<bitset<8>> board(8, bitset<8>(0));
    for (auto i = 0; i < k; i++) {
        // first : r, second : c
        cin >> q[i].first >> q[i].second;
        ans[q[i].first][q[i].second] = 'Q';
        board[q[i].first].set(q[i].second, true);
    }

    vector<int> num_r, num_c;
    for (auto i = 0; i < 8; i++) {
        bool r_used = false;
        bool c_used = false;
        for (auto j = 0; j < k; j++) {
            if(i == q[j].first) r_used = true;
            if(i == q[j].second) c_used = true;
        }
        if(not r_used) num_r.push_back(i);
        if(not c_used) num_c.push_back(i);
    }

    do {
        vector<bitset<8>> tmp = board;
        bool flg = true;
        for (auto i = 0; i < (int)num_r.size(); i++) {
            // cout << "base : " << num_r[i] << " " << num_c[i] << endl;
            for (auto l = 1; l < 8; l++) {
                for (auto m = 0; m < 8; m++) {
                    int nx = num_r[i] + dx[m] * l;
                    int ny = num_c[i] + dy[m] * l;
                    if(nx > 7 or 0 > nx or ny > 7 or 0 > ny) continue;
                    // cout << nx << " " << ny << endl;
                    if(tmp[nx][ny]) {
                        flg = false;
                        break;
                    }
                }
                if(not flg) break;
            }
            if(not flg) break;
            tmp[num_r[i]][num_c[i]] = true;
            // print_board(tmp);
        }

        if(flg) {
            for (auto i = 0; i < (int)num_r.size(); i++) {
                ans[num_r[i]][num_c[i]] = 'Q';
            }
            for (auto i = 0; i < 8; i++) cout << ans[i] << endl;
            return 0;
        }
    } while(next_permutation(num_r.begin(), num_r.end()));

    return 0;
}


Measured memory_bytes: 3212
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int num = sc.nextInt();
          int sum = sc.nextInt();
          if(num * 500 >= sum) {
            System.out.println("Yes");
          } else {
            System.out.println("No");
          }
          }
  }

Measured memory_bytes: 21844
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int n,lw[300010],re[300010];
  cin >> n;
  string s;
  cin >> s;
  lw[0]=0;
  REP(i,n-1){
    if(s[i]=='W'){
      lw[i+1]=lw[i]+1;
    } else {
      lw[i+1]=lw[i];
    }
  }
  re[n-1]=0;
  REP(i,n-1){
    if(s[n-i-1]=='E'){
      re[n-i-2]=re[n-i-1]+1;
    } else {
      re[n-i-2]=re[n-i-1];
    }
  }
  int m=300010;
  REP(i,n){
    if (lw[i]+re[i]<m) m=lw[i]+re[i];
  }
  cout << m;
  return 0;
}

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

public class Main {
	
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int w=s.nextInt();
		int prices[]=new int[n];
		int weights[]=new int[n];
		int maxp=0;
		for(int i=0;i<n;i++) {
			weights[i]=s.nextInt();
			prices[i]=s.nextInt();
			maxp+=prices[i];
		}
		
		long dp[][]=new long[n+1][maxp+1];
		for(int i=0;i<=n;i++) {
			for(int j=0;j<=maxp;j++) {
				if(i==0 && j==0)
					dp[i][j]=0;
				else if(i==0)
					dp[i][j]=(long)(1e11);
				else if(j>=prices[i-1]) {
					dp[i][j]=Math.min(weights[i-1]+dp[i-1][j-prices[i-1]], 
							dp[i-1][j]);
				}else
					dp[i][j]=dp[i-1][j];
			}
		}
//		for(int i=0;i<=n;i++) {
//			for(int j=0;j<=maxp;j++)
//				System.out.print(dp[i][j]+" ");
//			System.out.println();
//		}
		int ans=0;
		for(int i=0;i<=maxp;i++)
			if(dp[n][i]<=w)ans=i;
		
		System.out.println(ans);
		
	}


	
	
}

Measured memory_bytes: 140544
N = int(input())
A = sorted(list(map(int, input().split())))

Alice_sum = 0
Bob_sum = 0

if N % 2 == 0:
    Alice_sum = sum(A[1::2])
    Bob_sum = sum(A[0::2])
else:
    Alice_sum = sum(A[0::2])
    Bob_sum = sum(A[1::2])

result = Alice_sum - Bob_sum

print(result)

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

const int bB = 16;
const int B = 1 << bB;

int up(int x) {
	return (x + (1 << bB) - 1) >> bB;
}

int down(int x) {
	return x >> bB;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	int H = up(n);
	vector<int> bv(H), v(n);
	while (q--) {
		int com, x, y;
		cin >> com >> x >> y; x--;
		if (com == 0) {
			v[x] += y;
			bv[down(x)] += y;
		}
		else {
			int res = 0;
			for (int i = x; i < y && i < (up(x) << bB); i++) {
				res += v[i];
			}
			if (up(x) <= down(y)) {
				for (int i = up(x); i < down(y); i++) {
					res += bv[i];
				}
				for (int i = down(y) << bB; i < y; i++) {
					res += v[i];
				}
			}
			printf("%d\n", res);
		}
	}
	return 0;
}



Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  int base=700;
  
  cin>>S;
  
  if (S[0]=='o'){base=base+100;}
  if (S[1]=='o'){base=base+100;}
  if (S[2]=='o'){base=base+100;}
  
  cout<<base<<endl;
  
}

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

char s[2005][2005];
int x[2005][2005] = {};
int y[2005][2005] = {};


int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) cin >> s[i][j];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;

			y[i][j] = (0 < i ? y[i - 1][j] : 0) + 1;
			x[i][j] = (0 < j ? x[i][j - 1] : 0) + 1;
		}
	}
	int ans = 0;
	for (int i = h - 1; i >= 0; i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (s[i][j] == '#') continue;
			if (i < h - 1) y[i][j] = max(y[i + 1][j], y[i][j]);
			if (j < w - 1) x[i][j] = max(x[i][j + 1], x[i][j]);
			ans = max(ans, x[i][j] + y[i][j] - 1);
		}
	}

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

Measured memory_bytes: 35584
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
using namespace std;


int main(void) {
  string s;
  cin >> s;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){
    cnt += (s[i]=='o')?1:0;
  }
  cout << 700+cnt*100 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	char[] s;
	int max, dotCnt, id;
	
	char[] cArr = new char[]{'0', '1', '+', '-', '*', '(', ')'};
	
	int calc(){
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		StringBuilder sb = new StringBuilder();
		boolean mul = false;
		boolean mns = false;
		while(true){
			char c = '?';
			if(id<s.length){
				c = s[id];
				id++;
			}
			if(c=='0' || c=='1'){
				sb.append(c);
			}else{
				if(c=='(' || sb.length()>0){
					int num = -1;
					if(c=='(') num = calc();
					else if(sb.length()>0) num = Integer.parseInt(sb.toString(), 2);
					if(num<0 || num>=1024) return Integer.MAX_VALUE;
					if(mul) num *= q.pop();
					if(num<=-1024 || num>=1024) return Integer.MAX_VALUE;
					if(mns) num *= -1;
					q.push(num);	
					sb = new StringBuilder();
				}
				mns = false;
				mul = false;
				
				if(c=='*'){
					mul = true;
				}else{
					if(c=='-') mns = true;
					else mns = false;
					mul = false;
					if(c==')' || id==s.length){
						int sum = 0;
						while(!q.isEmpty()){
							sum += q.pollLast();
							if(sum<0 || sum>=1024) return Integer.MAX_VALUE;
						}
						return sum;
					}
				}
			}
		}
	}
	
	boolean isOpe(int id){
		if(s[id]=='+' || s[id]=='-' || s[id]=='*') return true;
		return false;
	}
	
	boolean isNum(int id){
		if(s[id]=='0' || s[id]=='1') return true;
		return false;
	}
	
	boolean checker(){
		if(isOpe(0) || isOpe(s.length-1)) return false;
		
		int cnt1 = 0;
		int cnt2 = 0;
		for(int i=0;i<s.length;i++){
			if(s[i]=='('){
				cnt1++;
				cnt2++;
			}
			else if(s[i]==')') cnt1--;
			if(cnt1<0) return false;
		}
		if(cnt1!=0) return false;
		
		boolean[] f = new boolean[cnt2];
		int id = -1;
		for(int i=0;i<s.length;i++){
			if(s[i]=='(') id++;
			else if(s[i]==')'){
				if(!f[id]) return false;
				f[id] = false;
				id--;
			}
			else if(id>=0 && isOpe(i)){
				f[id] = true;
			}
		}
		
		for(int i=0;i<s.length-1;i++){
			if(s[i]=='(' && isOpe(i+1)) return false;
			else if(s[i+1]==')' && isOpe(i)) return false;
			else if(isOpe(i) && isOpe(i+1)) return false;
			else if(s[i+1]=='(' && (isNum(i) || s[i]==')')) return false;
			else if(s[i]==')' && (isNum(i+1) || s[i+1]=='(')) return false;
		}
		
		return true;
	}
	
	void fnc(){
		boolean f = false;
		for(int i=0;i<s.length;i++){
			if(s[i]=='.'){
				for(int j=0;j<7;j++){
					s[i] = cArr[j];
					f = true;
					fnc();
					s[i] = '.';
				}
				break;
			}
		}
		if(!f && checker()){
			id = 0;
			int num = calc();
			if(num>=0 && num<=1023)	max = Math.max(max, num);
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		
		s = sc.next().toCharArray();
		dotCnt = 0;
		for(int i=0;i<s.length;i++){
			if(s[i]=='.') dotCnt++;
		}
		
		max = -1;
		fnc();
		System.out.println(max);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}	
}

Measured memory_bytes: 43616
#include<stdio.h>

int A[20];

int solve(int n, int m, int i){
  if(m == 0) return 1;

  if(m > 0 && i < n){
    if(solve(n, m - A[i], i + 1) || solve(n, m, i + 1)) return 1;
  }

  return 0;
}

int main(){
  int n, q, i, B[200];

  scanf("%d",&n);

  for(i = 0; i < n; i++) scanf("%d",&A[i]);

  scanf("%d",&q);

  for(i = 0; i < q; i++) scanf("%d",&B[i]);

  for(i = 0; i < q; i++){
    if(solve(n, B[i], 0)) printf("yes\n");
    else printf("no\n");
  }  

  return 0;
}

Measured memory_bytes: 580
n,p = map(int,input().split())
 
def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf
 
ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Measured memory_bytes: 9376
N, M, K = map(int, input().split())
mod = 998244353

facm = 200500
fac = [1] * facm
facinv = [1] * facm
for i in range(facm-1):
    fac[i+1] = (fac[i] * (i + 1)) % mod
    facinv[i+1] = (facinv[i] * pow(i+1, -1, mod)) % mod

def nCk(n, k):
    return (fac[n] * facinv[k] * facinv[n-k]) % mod

ans = 0
for i in range(K+1):
    ans = (ans + nCk(N-1, i) * pow(M-1, N-i-1, mod) * M) % mod

print(ans)

Measured memory_bytes: 24828
# coding: utf-8
# Your code here!

N = input()
if N[0]==N[1]==N[2]:
    print(N)
else:
    if int(N) <int(N[0]*3):
        print(int(N[0]*3))
    else:
        print(str((int(N[0])+1))*3)
        


Measured memory_bytes: 2940
// AOJ 2709 Dark Room
// 2018.3.31 bal4u

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

#define QMAX 40000
typedef struct { int t; int s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

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

#define INF 0x10101010
int d[18], rd[102];
int tbl[102][102];
int dist[1<<16];

int main()
{
	int N, M, K, v, i, j, s, e, t;

	N = in(), M = in(), K = in();
	memset(rd, -1, sizeof(rd));
	for (i = 0; i < M; i++) d[i] = in()-1, rd[d[i]] = i;

	memset(tbl, -1, sizeof(tbl));
	for (i = 0; i < N; i++) for (j = 0; j < K; j++) {
		v = in()-1;
		if (rd[i] >= 0 && rd[v] >= 0) tbl[i][j] = rd[v];
	}

	memset(dist, INF, sizeof(dist));
	qsize = 0;
	enq(s=(1<<M)-1, 0), dist[s] = 0;
	while (qsize) {
		s = que[0].s, t = que[0].t, deq();
	
		if (!s) break;
		if (dist[s] < t) continue;
		for (i = 0; i < K; i++) {
			e = 0;
			for (j = 0; j < M; j++) if ((s>>j)&1) {
				if (tbl[d[j]][i] >= 0) e |= 1<<tbl[d[j]][i];
			}
			if (dist[e] > t+1) dist[e] = t+1, enq(e, t+1);
		}
	}
	printf("%d\n", t);
	return 0;
}


Measured memory_bytes: 2404
N, M = map(int, input().split())
data = [0]*N
solved = [False]*N
for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if solved[p] == False and S == "WA":
        data[p] += 1
    if solved[p] == False and S == "AC":
        solved[p] = True

print(sum(solved),sum( x*y for x, y in zip(data, solved)) )


Measured memory_bytes: 75984
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
// #define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
#if !defined(ONLINE_JUDGE)
#include "debugging.h"
#endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
int const mod = 998244353;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 3055;
int const inf = 2e16;

int dp[N][N];

int func(int x,int y,int a,int b){
    if(dp[x][y] != -1) return dp[x][y];
    int res = 0;
    if(x-1 >= a)
    res = res + (y*func(x-1,y,a,b))%mod;
    res %= mod;
    if(y-1 >= b)
    res = res + (x*func(x,y-1,a,b))%mod;
    res %= mod;
    if(x-1>=a && y-1 >= b)
    res = res - ((x-1)*(y-1)*func(x-1,y-1,a,b))%mod;
    res %= mod;
    if(res < 0) res += mod;
    return dp[x][y] = res;
}

void solve(){
    int i,j,l;
    int a,b,c,d;
    cin >> a >> b >> c>>d;
    memset(dp,-1,sizeof(dp));
    dp[a][b] = 1;
    int ans = func(c,d,a,b);
    ans %= mod; ans += mod; ans %= mod;
    cout<<ans<<endl;
}              



int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*



*/

Measured memory_bytes: 76988
#include<stdio.h>

#define TRUE 1
#define FALSE 0


int func(int,int);

int n,A[2000];

int main(){
  int q,m[2000],i;



  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }

  for(i=0;i<q;i++){
    if(func(0,m[i])==TRUE){
      printf("yes\n");
    }else if(func(i,m[i])==FALSE){
      printf("no\n");
    }
  }

  return 0;
}




int func(int i,int m){
  int y;
  if(m==0){
    return TRUE;
  }else if(i>=n){
    return FALSE;
  }
  y=func(i+1,m) || func(i+1,m-A[i]);
  return y;
}



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

int main()
{
  int n, m, bulb[10] = {0}, p[10];
  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    int k, x;
    cin >> k;
    while (k--)
    {
      cin >> x;
      bulb[i] |= 1 << x - 1;
    }
  }
  for (int i = 0; i < m; i++)
    cin >> p[i];

  int ans = 0;
  for (int mask = 0; mask < 1 << n; mask++)
  {
    int isGood = 1;
    for (int i = 0; i < m; i++)
    {
      int numOn = 0;
      for (int j = 0; j < n; j++)
        if ((bulb[i] >> j & 1) && (mask >> j & 1))
          numOn ^= 1;
      isGood &= numOn == p[i];
    }
    ans += isGood;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int MX(int a,int b){
  if(b>a)return b;
  return a;
}
int main(){
  int n,r[200000],ans=-1000000000,mx;
  cin>>n;
  for(int i=0;i<n;i++)cin>>r[i];
  mx=r[n-1];
  for(int i=n-2;i>=0;i--)ans=MX(ans,mx-r[i]),mx=MX(mx,r[i]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
 
#define N_MAX (10*9*8*7*6*5*4*3*2*1)
map<long long,int> d;
 
int main(){
    int n;
    while(cin >> n && n){
        d.clear();
        long long a,b;
        cin >> a >> b;
         
        queue<long long> Q;
        Q.push(a);
        d[a] = 0;
        long long ten[10] = {};
        ten[0] = 1;
        for(int i = 1 ; i < 10 ; i++) ten[i] = ten[i-1] * 10;
        while(Q.size()){
            long long q = Q.front(); Q.pop();
            //cout << q << endl;
            if( q == b ){
                cout << d[q] << endl;
                break;
            }
            for(int i = n-1 ; i >= 0 ; i--){
                if( q / ten[i]%10 != b / ten[i]%10 ){
                    int ammount = ( b / ten[i] % 10 - q / ten[i] % 10 + 10 ) % 10;
                    long long next = q;
                    for(int j = i ; j >= 0 ; j--){
                        int nd = ( next / ten[j] % 10 + ammount ) % 10;
                        next = next - (next / ten[j] % 10) * ten[j] + ten[j] * nd;
                        if( d.count(next) == 0){
                            d[next] = d[q] + 1;
                            Q.push(next);
                        }
                    }
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 1904
import java.util.*;
public class Main {//ここが Main になっている
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Long N = Long.parseLong(sc.next());
        Long K = Long.parseLong(sc.next());
        Long next_n;
        Long t = N % K;
        Long k_t = K - t;
        if (t<k_t){
            System.out.println(t);
        }
        if (t>=k_t){
            System.out.println(k_t);
        }
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

vector<int> v[60];

int main(){


    int a, b;
    int n, m;
    cin >> n >> m;

    for(int i=0; i<m; i++){
        cin >> a >> b;
        a--;
        b--;
        v[a].pb(b);
        v[b].pb(a);
    }

    for(int i=0; i<n; i++){
        cout << v[i].size() << endl;
    }
}

Measured memory_bytes: 256
import sys

x,y=map(int,input().split())
d=abs(x-y)
if x>=y:
    x-=2*d
    y-=d
else:
    x-=d
    y-=2*d
if x%3!=0 or x<0:
    print(0)
    sys.exit()

cnt=x//3

mod=10**9+7
N=7*10**5+10
g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

def cmb(n,r):
    if (r<0 or r>n):
        return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod

print(cmb(2*cnt+d,cnt))

Measured memory_bytes: 127560
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	bool f = true;
	while(1){
		ll m; cin >> m;
		if(!m) break;
		ll a,b,c,d; cin >> a >> b >> c >> d;
		ll cnt = -inf;
		vl ans(4,0);
		rep(i,a+1){
			rep(j,b+1){
				rep(k,c+1){
					rep(l,d+1){
						ll t = i*10+j*50+k*100+l*500-m;
						if(t < 0) continue;
						ll c = 0;
						if(l&&t/500) continue;
						c += t / 500; t %= 500;
						if(k&&t/100) continue;
						c += t / 100; t %= 100;
						if(j&&t/50) continue;
						c += t / 50; t %= 50;
						if(i&&t/10) continue;
						c += t / 10;
						if(chmax(cnt,i+j+k+l-c)){
							ans[0] = i;
							ans[1] = j;
							ans[2] = k;
							ans[3] = l;
						}
					}
				}
			}
		}
		if(!f) cout << "\n";
		if(ans[0]>0) cout << 10 << " " << ans[0] << "\n";
		if(ans[1]>0) cout << 50 << " " << ans[1] << "\n";
		if(ans[2]>0) cout << 100 << " " << ans[2] << "\n";
		if(ans[3]>0) cout << 500 << " " << ans[3] << "\n";
		f = false;
	}
}


Measured memory_bytes: 2988
n = int(input())

def find(a):
    global total
    total = 0
    while a > 0:
        total += a % 10
        a //= 10
    return total

ans = float('inf')
for i in range(1,n):
    tmp = find(i) + find(n-i)
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 3060
from operator import itemgetter
n = int(input())
SP = []
for i in range(1, n+1):
    s, p = input().split()
    p = int(p)
    SP.append([i, s, -p])
SP.sort(key=itemgetter(1, 2))
print(*map(itemgetter(0), SP), sep='\n')

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::cmp;
use std::num::Wrapping; // overflowを回避
use std::f64::consts;


fn main() {
    let n: usize = read();
    let mut vec: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut count: i32 = 0;

    for i in 0..n {
        while(vec[i] > 0) {
            let mut endIndex = n-1;
            for j in i+1..n {
                if vec[j] == 0 {
                    endIndex = j-1;
                    break;
                }
            }
            for k in i..endIndex+1 {
                vec[k]-=1;
            }
            count+=1;
        }
    }
    println!("{}", count);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include<iostream>


int main() {
	 int A, B,C,D,E,F,G=0;
	std::cin >>A>> B;
	for (int i = A;i <= B;i++) {
		C = i % 10;
		D = (i /10) % 10;
		E = (i / 1000) % 10;
		F = (i / 10000) % 10;
		if (C == F&&D == E) {
			G=G+1;
		}
	}
	std::cout << G;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
int main(){
  int n,x,y;
  cin >> n >> x >> y;

  Graph G(n+1);
  for(int i=1;i<n;i++){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  G[x].push_back(y);
  G[y].push_back(x);

  vector<vector<int>> d(n+1,vector<int>(n+1));
  for(int i=1;i<=n;i++){
    d[i].assign(n+1,10000);
  }
  for(int i=1;i<n;i++){
    vector<int> dist(n+1,-1);
    queue<int> que;

    dist[i] = 0;
    que.push(i);

    while(!que.empty()){
      int v = que.front();
      que.pop();

      for(int nv:G[v]){
        if(dist[nv] != -1) continue;

        dist[nv] = dist[v]+1;
        //d[v][nv] = min(d[v][nv],dist[nv]);
        que.push(nv);
      }
    }
    for(int j=1;j<=n;j++){
      d[i][j] = min(d[i][j],dist[j]);
    }
  }

  vector<int> ans(n,0);
  for(int i=1;i<n;i++){
    for(int j=i+1;j<=n;j++){
      int t = d[i][j];
      ans[t]++;
    }
  }

  for(int i=1;i<n;i++){
    cout << ans[i] << endl;
  }
}


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

struct t_team{
	char c;
	int w, l, d;
	t_team(){ c = w = l = d = 0; }
};
bool operator<( const t_team &l, const t_team &r ){
	if( l.w == r.w )
		return l.l < r.l;
	else
		return l.w > r.w;
}

int main(){
	int n;
	while( cin >> n, n ){
		t_team t[10];
		for(int i=0; i<n; i++){
			cin >> t[i].c;
			for(int j=0; j+1<n; j++ ){
				int k;
				cin >> k;
				if(k==0)	  t[i].w++;
				else if(k==1) t[i].l++;
				else		  t[i].d++;
			}
		}
		stable_sort( t, t+n );
		for(int i=0; i<n; i++){
			cout << t[i].c << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1196
def main():
	l ,r = map(int,input().split())
	if (l-1)//2019 != r//2019:
		print("0")
		return 
	else:
		l = l%2019
		r = r%2019
		ans = 2018
		for i in range(l,r+1):
			for j in range(i+1,r+1):
				ans = min((i*j)%2019,ans)
		print(ans)
	return
main()


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  long long ans = 0;
  for(int i=1; i<=n; i++){
    int tmp = i;
    int sum = 0;
    while(tmp){
      sum += tmp % 10;
      tmp /= 10;
    }
    if(sum >= a && sum <= b)
      ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    
    void calc()
    {
        cin = new Scanner();

        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);

        Array.Sort(A);

        int ans = 0;
        int R = 0;
        for (int i = 0; i < N; i++)
        {
            while (R < N && A[i] >= A[R] - 2) R++;
            ans = Math.Max(ans, R - i);
        }
        Console.WriteLine(ans);
    }


        
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}
 

Measured memory_bytes: 16864
def main():
  M=10**9+7
  r1,c1,r2,c2=map(int,input().split())
  n=r2+c2+2
  fac=[0]*(n+1)
  fac[0]=val=1
  for i in range(1,n+1):fac[i]=val=val*i%M
  pr1=pow(fac[r1],M-2,M)
  pc1=pow(fac[c1],M-2,M)
  pr2=pow(fac[r2+1],M-2,M)
  pc2=pow(fac[c2+1],M-2,M)
  a=fac[r2+c2+2]*pr2*pc2
  a-=fac[r2+c1+1]*pr2*pc1
  a-=fac[r1+c2+1]*pr1*pc2
  a+=fac[r1+c1]*pr1*pc1
  print(a%M)
main()

Measured memory_bytes: 54128
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if (unique(s.begin(), s.end()) - s.begin() == 2) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#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;
typedef long double lb; 

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

ll vector_finder(vector<ll> vec, ll number) {
    auto itr = find(vec.begin(), vec.end(), number);
    ll index = distance(vec.begin(), itr);
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main() {
    ll x,n;
    cin >> x >> n;
    vector<ll> p(n);
    rep(i,n){
        cin >> p[i];
    }

    
    ll ans1 = x;
    ll ans2 = x-1;
    
    while(true){
        if(!vector_finder(p,ans1)){
            cout << ans1 << endl;
            return 0;
        }
        ans1++;
        if(!vector_finder(p,ans2)){
            cout << ans2 << endl;
            return 0;
        }
        ans2--;
    }
}


Measured memory_bytes: 3588
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main() { 
    int N;
    cin >> N;
    vector<string> S;
    vector<int> P;
    map<string, vector<int>> dic;
    map<string, int> idx;

    for (int i=0; i<N; i++) {
        string s;
        int p;
        cin >> s;
        cin >> p;
        dic[s].push_back(p);
        if (find(S.begin(), S.end(), s) == S.end()) {
            S.push_back(s);
        }
        idx[s+to_string(p)] = i + 1;
    }
    sort(S.begin(), S.end());

    for (int i=0; i<S.size(); i++) {
        // cout << S[i] << endl;
        sort(dic[S[i]].begin(), dic[S[i]].end(), greater<int>());
        // cout << dic[S[i]][0] << endl;
        for (int j=0; j<dic[S[i]].size(); j++) {
            int pt = dic[S[i]][j];
            cout << idx[S[i]+to_string(pt)] << endl;
            // cout << idx["moscow10"] << endl;
        }

    }
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	int dp[31];
	int n;
	while(scanf("%d",&n),n) {
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		for(int i=1;i<=n;i++) {
			dp[i]+=(i-1)>=0?dp[i-1]:0;
			dp[i]+=(i-2)>=0?dp[i-2]:0;
			dp[i]+=(i-3)>=0?dp[i-3]:0;
		}
		printf("%d\n",(int)ceil(ceil(dp[n]/10.0)/365.0));
	}
}

Measured memory_bytes: 1032
# coding: utf-8
import collections

n = int(input())
v = [int(s) for s in input().strip().split(" ")]
el = [0] * (n // 2)
ol = [0] * (n // 2)
ans = 0

for i in range(n):
    if i % 2 == 0:
        el[i//2] = v[i]
    else:
        ol[(i-1)//2] = v[i]
        
ec = collections.Counter(el)
oc = collections.Counter(ol)
e_num = ec.most_common()[0][0]
e_count = ec.most_common()[0][1]
o_num = oc.most_common()[0][0]
o_count = oc.most_common()[0][1]

if len(set(v)) == 1:
    ans = n //2
elif e_num != o_num:
    ans = n - e_count - o_count
elif e_count > o_count:
    #o_num = oc.most_common()[1][0]
    o_count = oc.most_common()[1][1]
    ans = n - e_count - o_count
elif e_count < o_count:
    #e_num = ec.most_common()[1][0]
    e_count = ec.most_common()[1][1]
    ans = n - e_count - o_count
elif e_count == o_count:
    if ec.most_common()[1][1] >= oc.most_common()[1][1]:
        e_count = ec.most_common()[1][1]
    else:
        o_count = oc.most_common()[1][1]
    ans = n - e_count - o_count

print(ans)

Measured memory_bytes: 80004
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl

int main ()
{
    ios_base :: sync_with_stdio(false),cin.tie(0), cout.tie(0);
    int n, i, sum = 0;
    cin >> n;
    int b[n+1];
    for(i = 1; i < n; i++) cin >> b[i];
    for(i = 2; i < n; i++)
    {
        sum += min(b[i], b[i-1]);
    }
    cout << sum + b[1] + b[n - 1] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int A[7] = {1,3,5,7,8,10,12};
	int B[4] = {4,6,9,11};
	int C = 2;

	int x,y;
	scanf("%d %d",&x,&y);

	int xg,yg;

	if(x == 2) xg = 3;
	else if(x == 4 || x == 6 || x == 9 || x == 11) xg = 2;
	else xg = 1;

	if(y == 2) yg = 3;
	else if(y == 4 || y == 6 || y == 9 || y == 11) yg = 2;
	else yg = 1;

	if(xg == yg) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{
   
    int d, t, s;
    cin >> d >> t >> s;
   
    if (d <= t * s)cout << "Yes" << endl;
    else cout << "No" << endl;
    
   
    return 0;

}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n,m;
string s;

int main(){
  ios_base::sync_with_stdio(false);
  
  m = 0;

  cin >> s;
  n = stoi(s);
  for(int i=0;i<s.size();i++){
    m += s[i]-'0';
  }

  if(n%m == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
using namespace std;

int main()
{
	int n, k, x[100];
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += min(x[i], k - x[i]);
	}
	cout << ans * 2 << endl;
	return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 3 * 100'000 + 5;

i64 n;
i64 a[MAXN];
i64 b[MAXN];

bool check_min(i64 v, i64 t) {
    i64 c = 0;
    for (i64 i = 0; i < n; i++) {
        if (a[i] <= v) {
            c += 1;
        }
    }
    return c >= t;
}

bool check_max(i64 v, i64 t) {
    i64 c = 0;
    for (i64 i = 0; i < n; i++) {
        if (b[i] >= v) {
            c += 1;
        }
    }
    return c >= t;
}

i64 bin_min(i64 l, i64 r, i64 t) {
    if (r - l == 1) {
        return r;
    }

    i64 m = (l + r) / 2;
    if (check_min(m, t)) {
        return bin_min(l, m, t);
    }
    else {
        return bin_min(m, r, t);
    }
}

i64 bin_max(i64 l, i64 r, i64 t) {
    if (r - l == 1) {
        return l;
    }

    i64 m = (l + r) / 2;
    if (check_max(m, t)) {
        return bin_max(m, r, t);
    }
    else {
        return bin_max(l, m, t);
    }
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

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

    if (n % 2) {
        i64 l = bin_min(0, mod, n / 2 + 1);
        i64 r = bin_max(0, mod, n / 2 + 1);
        cout << (r - l + 1) << endl;
        return 0;
    }
    else {
        i64 fl = bin_min(0, mod, n / 2);
        i64 fr = bin_max(0, mod, n / 2 + 1);

        i64 sl = bin_min(0, mod, n / 2 + 1);
        i64 sr = bin_max(0, mod, n / 2);

        i64 l = (fl + sl);
        i64 r = (fr + sr);
        cout << (r - l + 1) << endl;
        return 0;
    }


    return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
 
int main() {
    int n;
    int x[8];
    int y[8];
    cin>>n;
    rep(i,n)    cin>>x[i]>>y[i];

    float d=0.0;
    float count=0;

    for(int i=0;i<n-1;i++) {
        for(int j=i+1;j<n;j++) {
            d=d+sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            count++;
        }
    }
    float ans=d*(n-1)/count;

    cout<<setprecision(20)<<ans<<endl;

 return 0;
}

Measured memory_bytes: 256