akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// 移動元と行先と辺のコストを記録する構造体
struct Edge {
    int from, to;
    long double cost;
    Edge(int s, long double d) : to(s), cost(d) {}
    Edge(int f, int s, long double d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};

// 1つの頂点について、辺の情報を保存するために必要な vector
// Edgesのサイズは各頂点から出る辺の数に等しくなる
typedef vector<Edge> Edges;

// 辺の情報を保存する vector
// Graphのサイズは頂点の数に等しいので、 V である。
typedef vector<Edges> Graph;
typedef pair<long double, int> PDI;

vector<long double> dijkstra(Graph &G, int s) {
    int V = G.size();
    vector<long double> d(V); fill(d.begin(), d.end(), LLONG_MAX);
    priority_queue<PDI, vector<PDI>, greater<PDI> > que;
    d[s] = 0;
    que.push(PDI(0,s));

    while(!que.empty()) {
        PDI p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i<G[v].size(); i++) {
            Edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(PDI(d[e.to], e.to));
            }
        }
    }
    return d;
}

signed main() {
    int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
    int n; cin >> n;
    int x[1010], y[1010], r[1010];
    Graph G(n+2);
    rep(i,0,n) cin >> x[i] >> y[i] >> r[i];
    x[n] = xs, y[n] = ys, r[n] = 0;
    x[n+1] = xt, y[n+1] = yt, r[n+1] = 0;

    rep(i,0,n+2) rep(j,0,n+2) {
        if(i == j) continue;
        int xx = (x[i] - x[j]) * (x[i] - x[j]);
        int yy = (y[i] - y[j]) * (y[i] - y[j]);
        long double dist = max((long double)0.0, sqrt(xx + yy) - (long double)r[i] - (long double)r[j]);
        G[i].pb(Edge(j, dist));
    }
    vector<long double> ans = dijkstra(G, n);
    cout << fixed << setprecision(15) << ans[n+1] << endl;
    return 0;
}

Measured memory_bytes: 40704
N = int(input())
ab = []
for i in range(N):
    ab.append(list(map(int,input().split())))
cd = []
for i in range(N):
    cd.append(list(map(int,input().split())))
cd.sort()
#print(ab[2][1])
#print(cd[2][1])
ans = 0
for i in range(N):
    lis = []
    #print(cd[i])
    for j in range(len(ab)):
        #print(cd[i],ab[j])
        #print(ab)
        if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
            #print(cd[i],ab[j])
            lis.append(ab[j])
    #print(lis)
    if len(lis) > 0:
        lis.sort(key=lambda x:x[1])
        lis.reverse()
        ans += 1
        #print(lis)
        ab.remove(lis[0])
        #print(lis[0])
    #print(ab)
print(ans)


Measured memory_bytes: 67644
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define db double
#define ui unsigned int
#define ll long long
#define ull unsiged ll
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define boots     ios::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define pp pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mod 998244353
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define inf 0x3f3f3f3f
#define lnf LLONG_MAX
#define mii map<int, int>
#define mll map<ll, ll>
#define mil map<int, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>
#define umcc unordered_map<char, char>
#define si(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define pf(n) printf("%lld\n", n)
#define sz size
using namespace std;
const db pi = 3.1415926535898;
const int MX = 1e5 + 7;
const int maxn = 1e6 + 7;
const int esp = 1e-6;
bool ji[MX];
int top;
//unordered_map<pair<int, int>, int>mp;
//ll modulo(ll num, ll MOD = mod) { return ((num%MOD) + MOD) % MOD; }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
//void prime() { rep(i, 2, MX - 1) { if (!ji[i])pri[++top] = i; for (int j = 2; j*i < MX; j++)ji[j*i] = 1; } }
const int N = 1e6 + 5;
umii mp;
ll p[MX];
vector<int> pri;
vector<bool> isp(MX, false);
int n;
int vj(int a) {
	if (mp[a] == 0)
		return 0;
	else {
		int b = vj(a + mp[a]);
		mp[a] += b;
		return mp[a];
	}
}
int main() {
	boots;
	int n;
	cin >> n;
	cout << n * n*n << '\n';
}

Measured memory_bytes: 256
nl = ['3', '5', '7']


def r(n, s=''):
    c = 0
    if int(0 if s == '' else s) > int(n):
        return 0
    if all([x in s for x in nl]):
        c += 1
    for l in nl:
        c += r(n, s + l)
    return c


def main():
    n = input()
    print(r(n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

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

#define SUPwl 16
#define UNDEFCHAN 2*pow(10,10)
#define EPS 1*pow(1,-10)
#define EQ(a,b) (fabs(a-b)<EPS)

struct W{
	int n,d,r; //name, distance from main castle, number of senryobako
};
typedef vector<int> Path;
struct TandP{
	double t; Path p;
	TandP(){t=UNDEFCHAN; p=Path();}
};

int wl;
W wos[SUPwl];
TandP memf[1<<SUPwl][SUPwl];

double getV(int s){
	double m=0;
	FOR(wi,0,wl){
		if(s>>wi&1) m += 20.0*wos[wi].r;
	}
	return 2000.0/(70.0+m);
}

TandP f(int s, int wi){
	if(!EQ(memf[s][wi].t,UNDEFCHAN)){return memf[s][wi];}
	
	TandP re = TandP();
	if(s==(1<<wl)-1){
		re.t=0;
		re.p.push_back(wi);
	}else{
		FOR(bwi,0,wl){
			if(s&(1<<bwi)) continue;
			if(bwi==wi) continue;
			TandP bre = f(s+(1<<bwi),bwi);
			double nret = bre.t+fabs(wos[wi].d-wos[bwi].d)/getV(s);
			if(re.t>nret){
				re.t=nret;
				re.p.clear();
				copy(bre.p.begin(), bre.p.end(), back_inserter(re.p));
				re.p.push_back(wi);
			}
		}
	}
	//cout<<s<<" "<<wi<<" "<<re.t<<endl;
	memf[s][wi] = re;
	return re;
}

Path solve(){
	FOR(s,0,1<<wl) FOR(wi,0,wl) memf[s][wi]=TandP();

	double ret = UNDEFCHAN; Path rep=Path();
	FOR(bwi,0,wl){
		TandP bre=f(1<<bwi,bwi);
		if(ret>bre.t){
			ret=bre.t;
			//cout<<0<<" "<<bwi<<" "<<ret<<endl;
			rep.clear();
			copy(bre.p.begin(), bre.p.end(), back_inserter(rep));
		}
	}
	return rep;
}

int main(){
	cin >> wl;
	FOR(wi,0,wl) cin >> wos[wi].n >> wos[wi].d >> wos[wi].r;
	Path rep = solve();
	for(int wi=rep.size()-1;wi>0;--wi){
		cout << wos[rep[wi]].n << " ";
	}
	cout<<wos[rep[0]].n<<endl;
	return 0;
}

Measured memory_bytes: 45036
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    solve2
  }

  def solve2(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, q = sc.nextInt
    val to = Array.fill[ArrayBuffer[Int]](n)(ArrayBuffer.empty[Int])

    for (i <- 0 until n - 1) {
      val a = sc.nextInt - 1
      val b = sc.nextInt - 1
      to(a).append(b)
      to(b).append(a)
    }

    val ans = Array.fill[Long](n)(0L)
    for (i <- 0 until q) {
      val p = sc.nextInt - 1
      val x = sc.nextInt
      ans(p) += x
    }

    var stack = scala.collection.mutable.Stack[Int](0)
    val isVisited = Array.fill[Boolean](n)(false)
    while (stack.nonEmpty) {
      val top = stack.pop()
      isVisited(top) = true
      for (next <- to(top); if (!isVisited(next))) {
        ans(next) += ans(top)
        stack.push(next)
      }
    }
    println(ans.mkString(" "))
  }


  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, q = sc.nextInt
    val to = Array.fill[ArrayBuffer[Int]](n)(ArrayBuffer.empty[Int])

    for (i <- 0 until n - 1) {
      val a = sc.nextInt - 1
      val b = sc.nextInt - 1
      to(a).append(b)
      to(b).append(a)
    }

    val ans = Array.fill[Long](n)(0L)
    for (i <- 0 until q) {
      val p = sc.nextInt - 1
      val x = sc.nextInt
      ans(p) += x
    }

    def dfs(v: Int, p: Int = -1): Unit = {
      for (u <- to(v)) {
        if (u != p) {
          ans(u) += ans(v)
          dfs(u, v)
        }
      }
    }

    dfs(0, -1)

    println(ans.mkString(" "))
  }
}


Measured memory_bytes: 152004
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

vi nums, ans;
int N, cnt = 0;
char c = 'R';
string S;

void solve(){
    rep(i, N){
        if(S[i] == c) {
            cnt++;
        } else {
            nums.push_back(cnt);
            c = S[i];
            cnt = 1;
        }
    }
    nums.push_back(cnt);

    // for(auto v : nums) cout << v << endl;

    ans.resize(N, -1);
    int id = 0, tmp;

    rep(i, N-1){
        if(S[i] == 'R' && S[i+1] == 'L'){
            tmp = nums[id] + nums[id+1];
            if(tmp % 2 == 0){
                ans[i] = tmp/2;
                ans[i+1] = tmp/2;
            } else {
                if(nums[id] > nums[id+1]){
                    ans[i] = (tmp+1)/2;
                    ans[i+1] = (tmp-1)/2;
                } else {
                    ans[i] = (tmp-1)/2;
                    ans[i+1] = (tmp+1)/2;
                }
                if(max(nums[id], nums[id+1]) % 2 == 0) swap(ans[i], ans[i+1]);
            }
            i++;
            id += 2;
        } else {
            ans[i] = 0;
        }
    }

    if(ans[N-1] == -1) ans[N-1] = 0;

    rep(i, N){
        cout << ans[i];
        if(i==N-1) cout << endl;
        else cout << " ";        
    } 
}

int main(){
    cin >> S;
    N = S.size();

    solve();
}


Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std ;
long long int power(long long int a,long long int n,long long int m) ;
 long long int power(long long int a,long long int n,long long int m)
{  if(n==0)
   return 1 ;
   long long int x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
int main()
{ long long int n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,m1,a;
  string s  ;
  cin>>n ;
   sum=0 ;
   for(i=1;i<=n;i++)
   {
       for(j=1;j<=n;j++)
       {
           for(k=1;k<=n;k++)
           {
               x=__gcd(i,j) ;
               x=__gcd(x,k) ;
               sum+=x ;
       }
   } }
   cout<<sum ;
   return 0 ;  }



Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	for(int i=1;i<=N*2;i++){
	    if(N*i%2==0){
		System.out.print(N*i);
		break;
	    }
	}
    }
}


Measured memory_bytes: 21332
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

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

    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (p[i] == i + 1) {
            swap(p[i], p[i + 1]);
            ans++;
        }
    }
    if (p.back() == n) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
N=int(input())
a = [int(i) for i in input().split()]
ans = [0]*N

for i in reversed(range(1,N+1)):
  c = N//i
  if c==1:
    if a[i-1]==1:
      ans[i-1]=1
  else:
    d = 0
    for j in range(2,c+1):
      d += ans[i*j-1]
    ans[i-1]=(d+a[i-1])%2
#    print(i,c,j,d,a[i])
print(sum(ans))
if sum(ans)!=0:
  for i in range(len(ans)):
    if ans[i]==1:
      print(i+1, end=" ")

Measured memory_bytes: 7100
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, m;
    cin >> n >> m;
    if(n % m == 0) cout << 0;
    else cout << 1;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    int p[n];
    for (int i = 0; i < n; i++)
        cin>>p[i];
    int min_index = 0;
    int sum = 0;
    for (int i = 0; i < k; i++){
        int min = 100000;
        for (int j = 0; j < n; j++){
            if (min > p[j]){
                min = p[j];
                min_index = j;
            }
        }
        sum += min;
        p[min_index] = 10001;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3176
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int a,b,c,d; 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>a>>b>>c>>d;
	if(abs(a-b)<=d && abs(b-c)<=d || abs(a-c)<=d)
	cout<<"Yes";
	else
	cout<<"No";
	//system("pause");
	return 0;
}

Measured memory_bytes: 764
def a():
    mod = 998244353

    def bi(x):
        o = []
        while x != 0:
            o.append(x%2)
            x //= 2
        return o

    o = bi(mod - 2)
    leo = len(o)
    p = [0] * leo

    def modinv(m):
        p[0] = m
        for i in range(1,leo):
            a = p[i-1]
            a *= a
            a %= mod
            p[i] = a
        b = 1
        for i in range(leo):
            if o[i]:
                b *= p[i]
                b %= mod
        return b

    N,M,K = map(int,input().split())

    C = [1]*(K+1)
    for i in range(1,K+1):
        C[i] = (C[i-1] * (N-i) * modinv(i))%mod

    M1 = [1]*N
    for i in range(1,N):
        M1[i] = M1[i-1] * (M-1)
        M1[i] %= mod

    ans = 0
    for k in range(0,K+1):
        ans += C[k] * M * M1[N-k-1]
        ans %= mod

    print(ans)

a()


Measured memory_bytes: 88604
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
// typedef cpp_int ll;
typedef pair<ll, ll> p;

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  else return gcd(b, a % b);
  // return (b == 0) ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
  ll g = gcd(a, b);
  return a / g * b;
}

int f(int x){
  int res = 0;
  while(x > 0 && x % 2 == 0){
    x /= 2;
    res++;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  vector<ll> v(n);
  rep(i, n){
    cin >> v[i];
    if(v[i] % 2 == 0) v[i] /= 2;
    else{
      cout << 0 << endl;
      return 0;
    }
  }
  ll l = 1;
  int t = f(v[0]);
  rep(i, n){
    if(f(v[i]) != t){
      cout << 0 << endl;
      return 0;
    }
    v[i] >>= t;
  }
  m >>= t;

  rep(i, n){
    l = lcm(l, v[i]);
    if(l > m) {
      cout << 0 << endl;
      return 0;
    }
  }
  m /= l;
  int res = (m+1) / 2;
  cout << res << endl;

}


Measured memory_bytes: 1024
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n;
    l(i,0,n)
    {
        cin>>a;
        v.pb(a);
        u.pb(a);
    }
    lw(v);
    l(i,0,n)
    {

        if(v[i]!=u[i])
        {
            d++;
        }

    }
   if(d==0||d==2)
   {
       cout<<"YES";
   }
   else{cout<<"NO";}
}


Measured memory_bytes: 3668
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,M = map(int,input().split())
tree = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    tree[a] += [b]
    tree[b] += [a]

# print(tree)
def dfs(node,p,passed):
    # print(node,passed)
    if len(passed) == N:
        return 1
    cnt = 0
    for new_node in tree[node]:
        if new_node == p:
            continue
        if not new_node in passed:
            passed2 = copy.deepcopy(passed)
            passed2 += [new_node]
            cnt += dfs(new_node,node,passed2)
    return cnt

ans = dfs(0,-1,[0])
print(ans)


Measured memory_bytes: 5460
#include <iostream>

using namespace std;

int n, q, m;
int A[20];

bool solve(int i, int sum) {
    if (i == n) return false;
    if (sum + A[i] == m) return true;
    return solve(i + 1, sum) || solve(i + 1, sum + A[i]);
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> A[i];
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> m;
        cout << (solve(0, 0) ? "yes" : "no") << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
def is_upper_case(s):
  return not (ord('a') <= ord(s) <= ord('z'))

S = input()

if S[0] != 'A':
  print("WA")
  exit()

if S[2:-1].count('C') != 1:
  print("WA")
  exit()

upper_num = list(map(is_upper_case, S)).count(True)

if upper_num != 2: # expected only 'A', 'C'
  print("WA")
  exit()

print("AC")


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

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll c;
    cin >> n >> c;
    VL x(n), v(n);
    REP(i, n) cin >> x[i] >> v[i];
    VL xx(n);
    REP(i, n) xx[i] = c - x[n - i - 1];
    VL intake_clock(n);
    intake_clock[0] = v[0];
    FOR(i, 1, n - 1) intake_clock[i] = v[i] + intake_clock[i - 1];
    VL intake_unclock(n);
    intake_unclock[0] = v[n - 1];
    FOR(i, 1, n - 1) intake_unclock[i] = v[n - i - 1] + intake_unclock[i - 1];
    
    ll only_clock = intake_clock[0] - x[0];
    int only_clock_index = 0;
    vector<pair<ll, int>> opt_clock(n);
    REP(i, n) {
        if(only_clock < intake_clock[i] - x[i]) {
            only_clock = intake_clock[i] - x[i];
            only_clock_index = i;
        }
        opt_clock[i].first = only_clock;
        opt_clock[i].second = only_clock_index;
    }
    ll only_unclock = intake_unclock[0] - xx[0];
    int only_unclock_index = 0;
    vector<pair<ll, int>> opt_unclock(n);
    REP(i, n) {
        if(only_unclock < intake_unclock[i] - xx[i]) {
            only_unclock = intake_unclock[i] - xx[i];
            only_unclock_index = i;
        }
        opt_unclock[i].first = only_unclock;
        opt_unclock[i].second = only_unclock_index;
    }
    ll fold = 0;
    FOR(i, 0, n - 2) {
        fold = max(fold, opt_clock[i].first 
                         - x[opt_clock[i].second] 
                         + opt_unclock[n - i - 2].first);
        fold = max(fold, opt_unclock[i].first 
                         - xx[opt_unclock[i].second] 
                         + opt_clock[n - i - 2].first);
    }

    fold = max(fold, only_clock);
    fold = max(fold, only_unclock);
    cout << fold << endl;
    
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> l(n),a(3),bit(3);
    for(int i = 0;i < 3;i++) cin >> a[i];
    for(int i = 0;i < n;i++) cin >> l[i];
    
    int ans = 1<<30;
    
    for(bit[0] = 1;bit[0] < (1<<n);bit[0]++){
        for(bit[1] = 1;bit[1] < (1<<n);bit[1]++){
            if(bit[0]&bit[1]) continue;
            for(bit[2] = 1;bit[2] < (1<<n);bit[2]++){
                if(bit[0]&bit[2]) continue;
                if(bit[1]&bit[2]) continue;
                
                vector<int> sums(3),nums(3);
                for(int i = 0;i < n;i++){
                    for(int j = 0;j < 3;j++){
                        if(bit[j]&(1<<i)){
                            sums[j] += l[i];
                            nums[j]++;
                        }
                    }
                }
                
                int cost = 0;
                for(int i = 0;i < 3;i++){
                    cost += abs(sums[i]-a[i]);
                    cost += (nums[i]-1)*10;
                }
                ans = min(ans,cost);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

INF = 10**6

n, m = map(int, input().split())
dp = [INF] * (2**n)
dp[0] = 0
for i in range(m):
    a, b = map(int, input().split())
    bit = ['0'] * n
    for x in set(map(int, input().split())):
        bit[x-1] = '1'
    bit = int(''.join(bit[::-1]), 2)
    for j in range(2**n-1, -1, -1):
        dp[j|bit] = min(dp[j|bit], a + dp[j])
if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])


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

int main(){
        int N;
        string S;

        cin >> N;
        cin >> S;
        for(int i=0;i<S.length();i++){
                S[i] += N;
                if((int)S[i] > 90){
                        S[i] = (int)S[i] - 26;
                }
        }
        cout << S << endl;
        return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

double coin(double s,double g){
    double ret=0;
    while(s<g){
        s*=2;
        ret++;
    }
    return ret;
}


signed main(){start();
    double n,k,ans=0;
    cin>>n>>k;
    REP(i,1,n+1){
        ans+=pow(0.5,coin(i,k));
    }
    cout << fixed << setprecision(10) << ans/n << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
#include<math.h>
#include<stdio.h>
#include<complex>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;
const int intINF = 1e9 * 2 + 3;
//--------------------------------------------------

ulli gcd(ulli a, ulli b) {return (b <= 0) ? a : gcd(b, a % b);}
ulli lcm(ulli a, ulli b) {return a * b / gcd(a, b);}

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------



void Main()
{
	int n;
	cin >> n;
	vector<char> s(n), t(n);
	rep(i, n)cin >> s[i];
	rep(i, n)cin >> t[i];
	rep(i, n) {
		cout << s[i] << t[i];
	}
	cout << endl;
}


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

Measured memory_bytes: 256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*b,c*d);
	return 0;
}

Measured memory_bytes: 256
def run(N, K, t, d):
    '''
    おいしさ(d)の昇順でソートする O(NlogN)
    おいしさが大きいもののK個の合計を取得 O(K)
    K個のうちおいしさが少ないものから順にネタの種類が
    増えるように変更していく O(K)
    ネタの種類のうち最大の物の値とインデックスを取得しておく O(K)
    ネタの種類を変えた合計のうち最大のものが答え
    '''
    t_dic = dict(zip(range(N), t))
    d_dic = dict(zip(range(N), d))
    d_dic_sorted = sorted(d_dic.items(), key=lambda x: x[1], reverse=True)
    d_dic_sorted_i = [dd[0] for dd in d_dic_sorted]
    d_dic_sorted_d = [dd[1] for dd in d_dic_sorted]
    d_sum = sum(d_dic_sorted_d[:K])
    t_used = {}
    t_cnt = 0
    for i in t:
        t_used[i] = 0
    for i in d_dic_sorted_i[:K]:
        t_used[t_dic[i]] += 1
        if t_used[t_dic[i]] == 1:
            t_cnt += 1
    t_sum = t_cnt ** 2
    max_sum = d_sum + t_sum
    del_list = d_dic_sorted_i[:K]
    for i in d_dic_sorted_i[K:]:
        di = d_dic[i]
        ti = t_dic[i]
        # ネタの種類が増えるように追加
        if t_used[ti] == 0:
            t_used[ti] += 1
            t_cnt += 1
            t_sum += 2*t_cnt - 1
            d_sum += di
            # ネタが重複しているものを削除
            flg = True
            while len(del_list) > 0 and flg:
                del_i = del_list.pop()
                del_di = d_dic[del_i]
                del_ti = t_dic[del_i]
                if t_used[del_ti] > 1:
                    t_used[del_ti] -= 1
                    d_sum -= del_di
                    max_sum = max(max_sum, d_sum + t_sum)
                    flg = False
    return max_sum


def main():
    N, K = map(int, input().split())
    t = []
    d = []
    for _ in range(N):
        ti, di = map(int, input().split())
        t.append(ti)
        d.append(di)
    print(run(N, K, t, d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 50576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
int main()
{
    cin>>n>>k;
    if(n%k==0)
    {
        cout<<"0"<<endl;
    }
    else if(n>k)
    {
        cout<<min(n%k,k-n%k)<<endl;
    }
    else if(n<k)
    {
        cout<<min(n,k-n)<<endl;
    }



}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }


int calc_required_level_to_rooms(int* res)
{
	int w, h, sx, sy;
	static int req[512][512];
	cin >> w >> h >> sx >> sy;
	--sx, --sy;
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			cin >> req[y][x];

	static bool visit[512][512];
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			visit[y][x] = false;

	int c = 0;
	res[c++] = 0;

	typedef pair<int, pint> P;
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(P(1, pint(sx, sy)));
	while (c <= w * h)
	{
		P tt = q.top(); q.pop();
		int level = tt.first;
		int x = tt.second.first, y = tt.second.second;
		if (visit[y][x])
			continue;

		visit[y][x] = true;
		res[c++] = level;

		for (int i = 0; i < 4; ++i)
		{
			int tx = x + dx[i], ty = y + dy[i];
			if (valid_pos(tx, ty, w, h) && !visit[ty][tx])
				q.push(P(max(level, req[ty][tx]), pint(tx, ty)));
		}
	}
	return w * h;
}
int main()
{
	ios::sync_with_stdio(false);

	int r;
	while (cin >> r, r)
	{
		static int a[512 * 512], b[512 * 512];
		int a_size = calc_required_level_to_rooms(a);
		int b_size = calc_required_level_to_rooms(b);

		int res = 1e9;
		for (int i = min<int>(r, a_size); i >= 0 && r - i <= b_size; --i)
			min_swap(res, a[i] + b[r - i]);
		cout << res << endl;
	}
}

Measured memory_bytes: 0
from sys import stdin


N,K=map(int, stdin.readline().rstrip().split())

P = [int(x) for x in stdin.readline().rstrip().split()]
psum = 0.0
for i in range(K):
    psum += P[i]

ans = psum

for i in range(K,N):
    psum -= P[i-K]
    psum += P[i]
    ans = max(psum,ans)

print((ans+K)/2)

Measured memory_bytes: 32140
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e10)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

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

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}

int N,M;
int ans = 0;

int main()
{
	cin >> N;
	int s[N];

	int sum = 0;

	REP(i,0,N){
		cin >> s[i];
		sum += s[i];
	}

	sort(s, s + N);

	int ans = 0;

	if(sum%10!=0){
		cout << sum << endl;
		return 0;
	}
	else
	{
		REP(i,0,N){
			sum -= s[i];
			if(sum%10!=0){
				cout << sum << endl;
				return 0;
			}
			sum += s[i];
		}
	}

	cout << 0 << endl;

	return 0;
}

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

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

using namespace std;

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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  string res = "";
  rep(i, n) {
    res += s[i];
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


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

using ll = long long;

using namespace std;


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

    vector<string> s = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    map<string, int> m;

    rep(i,7){
        m[s[i]]+= i;
    }
    

    cout << 7 - m[ss] << endl;
}

Measured memory_bytes: 256
# E - Roadwork
# https://atcoder.jp/contests/abc128/tasks/abc128_e

from heapq import heappop, heappush
from collections import defaultdict

n, q = map(int,input().split())
task = []
for _ in range(n): 
  s, t, x = map(int, input().split())
  task.append((t - x, 0, x)) 
  task.append((s - x, 1, x)) 

for i in range(q):
  d = int(input())
  task.append((d, 2, i)) 

answer = [-1] * q

task.sort()

se = set()
se_hp = []

for a, b, c in task:
  if b == 0:
    se.remove(c)
  elif b == 1:
    se.add(c)
    heappush(se_hp, c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str, answer)))


Measured memory_bytes: 106044
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;
#define MOD 1000000007

using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS

    ll n;
    cin>>n;
    multiset<string> m;
    string a[4] = {"AC","WA","TLE","RE"};
    for(int i = 0; i<n; i++){
        string tmp;
        cin>>tmp;
        m.insert(tmp);
    }

    for(string s : a) cout<<s<<" x "<<m.count(s)<<endl;

    return 0;
}

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

void Main()
{
	int a, b;
	string s;
	cin >> a >> b >> s;
	rep(i, s.size()) {
		if (i == a) {
			if (s[i] == '-') {

			} else {
				cout << "No" << endl;
				return;
			}
		} else {
			if (s[i] != '-') {

			} else {
				cout << "No" << endl;
				return;
			}
		}
	}
	cout << "Yes" << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3660
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for i in range(n)]
#wv[i][0]:i番目の品物の重さ
#wv[i][1]:i番目の品物の価値

dp = [0]*(w+1)#dp[i]:重さiにおける最大価値
for i in range(n):#あるi番目の品物について
    for j in range(w,wv[i][0]-1, -1):
        dp[j] = max( dp[j], dp[j-wv[i][0]]+wv[i][1] )#i番目の品物を使うほうが良い場合は値を更新

print(max(dp))

Measured memory_bytes: 41836
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int min = Integer.parseInt(sc.next());
        int max = Integer.parseInt(sc.next());
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            char[] array = Integer.toString(i).toCharArray();
            int sum = 0;
            for (char c : array) {
                sum += Character.getNumericValue(c);
            }
            if (sum >= min && sum <= max) {
                ans += i;
            }
        }
        System.out.println(ans);
    }
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  std::string s;
  std::cin >> s;

  std::vector<int64_t> ans(s.size(), 0);

  int64_t even = 0, odd = 0;
  for (int64_t i = 0; i < s.size(); i++) {
    if (s[i] == 'R') {
      std::swap(even, odd);
      odd++;
    } else {
      ans[i] += even;
      ans[i - 1] += odd;
      even = 0;
      odd = 0;
    }
  }
  even = 0;
  odd = 0;

  for (int64_t i = s.size() - 1; 0 <= i; i--) {
    if (s[i] == 'L') {
      std::swap(even, odd);
      odd++;
    } else {
      ans[i] += even;
      ans[i + 1] += odd;
      even = 0;
      odd = 0;
    }
  }

  for (int64_t i = 0; i < s.size(); i++) {
    std::cout << ans[i];
    if (i != s.size() - 1) {
      std::cout << " ";
    }
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main( void ) {

    int N;
    cin >> N;

    vector<int> A;

    for ( int i = 0; i < N; i++ ) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

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

    cout << A.at(A.size() - 1) - A.at(0) << endl; 
 
    return 0;
}

Measured memory_bytes: 256
from math import sqrt

n, d = map(int, input().split(' '))

x = []
for i in range(n):
    x.append(list(map(int, input().split(' '))))

result = 0

for i in range(n):
    for j in range(i + 1, n):
        distance = 0
        for k in range(d):
            distance += abs(x[i][k] - x[j][k]) ** 2
        else:
            if distance == 0 or sqrt(distance).is_integer():
                result += 1

print(result)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

int n, m, q, x, y, dest, pocz, dis, col;
pair< int, int > Q[100010][12];
vector< int > tab[100010];
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>n>>m;
	for( int a = 1; a <= m; a++ )
	{
		cin>>x>>y;
		tab[x].push_back( y );
		tab[y].push_back( x );	
	}
	cin>>q;
	for( int a = 1; a <= q; a++ )
	{
		cin>>pocz>>dis>>col;
		Q[pocz][dis] = max( Q[pocz][dis], make_pair( a, col ) );
	}
	for( int a = 1; a <= 10; a++ )
	{
//		for( int a = 1; a <= n; a++ )cout<<Q[a][0].second<<" ";
//		cout<<endl;
		for( int b = 1; b <= n; b++ )
		{
			for( int d = 1; d <= 10; d++ )
			{
				Q[b][d-1] = max( Q[b][d-1], Q[b][d] );
				for( int c = 0; c < tab[b].size(); c++ )
				{	
					
						Q[tab[b][c]][d-1] = max( Q[tab[b][c]][d-1], Q[b][d] ); 
					
				}
			}
		}
	}
	for( int a = 1; a <= n; a++ )cout<<Q[a][0].second<<endl;
	 
	
	return 0;
}

Measured memory_bytes: 15864
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	ll n, a, b;
	cin >> n >> a >> b;
	cout << n/(a+b)*a+min(n%(a+b), a);
}

Measured memory_bytes: 3620
import sys

input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    h = list(map(int, input().split()))

    h += [0]
    N += 1
    ans = 0
    while True:
        l = 0
        min_h = INF
        for r in range(N):
            if h[r] == 0:
                if min_h == INF:
                    l += 1
                else:
                    for i in range(l, r):
                        h[i] -= min_h
                    ans += min_h
                    l = r + 1
                    min_h = INF
            else:
                if h[r] < min_h:
                    min_h = h[r]
        if sum(h) == 0:
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[1][110];
int main()
{
     int n;
	 int ans=0;
	 cin>>n;
	 for (int i=0;i<n;i++)
	    cin>>a[0][i];
	for (int i=0;i<n;i++)
	   cin>>a[1][i];
	int c=0;
	for (int i=0;i<n;i++)
	{
	   for (int b=i;b>=0;b--)
	      c+=a[0][b];
	   for (int j=i;j<n;j++)
	      c+=a[1][j];
	   ans=max(ans,c);
	   c=0;
	}
	cout<<ans;
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d.at(i);
  sort(d.begin(), d.end());
  cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
}


Measured memory_bytes: 640