akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
//#include<conio.h>

using namespace std;



int main()
{
   	//IOS
	int n,m;
	cin>>n>>m;
	vi v;
	vector<pair<int,int>> vp;
	for(int i=1;i<=n;i++){
        int temp;
        cin>>temp;
        v.pb(temp);
        }
    for(int i=1;i<=m;i++){
        int b,c;
        cin>>b>>c;
        vp.pb({c,b});
    }
    sort(vp.begin(),vp.end());
    sort(v.begin(),v.end());
    /*for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    cout<<"\n";*/
    int j=0;
    long long sum=0;
    for(int i=m-1;i>=0;i--)
    {
        if(v[j]>=vp[i].first)
            break;
        //cout<<j<<" ";
        //getch();
        int ctr=0;
        int temp=j;
        for(;v[temp]<vp[i].first&&temp<n;temp++)
            ctr++;;
        //cout<<temp<<" "<<ctr<<" ";
        //getch();
        vp[i].second=min(vp[i].second,ctr);
            //cout<<vp[i].second<<" ";
            //getch();
        sum=sum+(long long)vp[i].first*(long long)vp[i].second;
        j+=vp[i].second;
        //cout<<j<<"\n";
        //getch();
        if(j==n)
            break;
    }
    for(;j<v.size();j++)
        sum=sum+v[j];
    cout<<sum<<"\n";
	return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

int N;
vvi G(100050);
vi colored(100050, 0);
V(bool) counted(100050, false);

void dfs(vi &dis, int n) {
    int cnt = 0;
    rep(i, G[n].size()) {
        if(dis[G[n][i]]==INF) {
            dis[G[n][i]] = dis[n]+1;
            dfs(dis, G[n][i]);
            cnt++;      
        }
    }
}

void ftos(vi &fdis, vi &sdis,  int n) {
    if(fdis[n] <= sdis[n]) colored[n] = 1;
    else colored[n] = 2;
    if(n==N-1) return; 
    rep(i, G[n].size()) {
        if(sdis[n] > sdis[G[n][i]]) {
            ftos(fdis, sdis, G[n][i]);
        }
    }
}

void fill(int n, int c) {
    rep(i, G[n].size()) {
        if(colored[G[n][i]]==0 || colored[G[n][i]]==c) {
            if(!counted[G[n][i]]) {
                counted[G[n][i]] = true;
                colored[G[n][i]] = c;
                fill(G[n][i], c);
            }
        }
    }
}

signed main() {
    cin >> N;
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    vi fdis(N, INF), sdis(N, INF);
    fdis[0] = 0; sdis[N-1] = 0;
    dfs(fdis, 0); dfs(sdis, N-1);

    ftos(fdis, sdis, 0);
    counted[0]=true; counted[N-1]=true;
    fill(0, 1); fill(N-1, 2);

    int f=0, s=0;
    rep(i, N) {
        if(colored[i]==1) f++;
        else s++;
    }

    /*rep(i, N) {
        cout << i+1 << " ";
        if(colored[i]==1) cout << "black" << endl;
        else cout << "white" << endl;
    }*/


    if(f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}

Measured memory_bytes: 17160
#include<bits/stdc++.h>
using namespace std;
long long int a[100010], temp, i, j, k, l;
int main()
{
    cin >> k;
    for(i=1;i<10;i++)
    {
        a[j++] = i;
    }
    while(j<=k)
    {
        temp = a[l++];
        if(temp%10!=0)
            a[j++] = temp*10 + (temp%10-1);
        a[j++] = temp*10 + temp%10;
        if(temp%10!=9)
            a[j++] = temp*10 + (temp%10+1);
    }
    cout << a[k-1] << endl;
    return 0;
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  ll ans = 0;
  rep(i, n) {
    ans += A[i]/2;
    A[i] %= 2;
    if(A[i] && i+1 < n && A[i+1]) {
      ans++;
      A[i+1]--;
    }
  }
  cout << ans << endk;
  return 0;
}


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

N=10**9+7

def fac(n,r,N):
    ans=1
    for i in range(r):
        ans=ans*(n-i)%N
    return ans

def combi(n,r,N):
    if n<r or n<0 or r<0:
        ans = 0
        return ans
    if n==r:
        ans = 1
        return ans
    r= min(r, n-r)
    ans = fac(n,r,N)*pow(fac(r,r,N),N-2,N)%N
    return ans


if n==1:
    print(0)
    exit()
else:
    ans1=pow(10,n,N)-pow(9,n,N)*2+pow(8,n,N)
    ans1%=N
    if ans1<0:
        ans1+=N
    print(ans1)


Measured memory_bytes: 9216
from collections import Counter

def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())
arr = dict(Counter(factorize(N)))
ans = 0

for v, c in arr.items():
    count=0
    z = c
    for i in range(55):
        z -= i
        if z < 0:
            break
        count = i
    ans+=count
print(ans)

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

using namespace std;

int main(){
    long long n; cin >> n;

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

    sort(a, a + n);

    bool flag = false; 
    for (long long i = 1; i < n; i++){
        if(a[i] == a[i - 1]) flag = true;
    }
    if(flag){
        puts("NO");
    }else{
        puts("YES");
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    rep(i,0,n)cin>>x[i];
    rep(i,0,n)cin>>y[i];
    
    rep(i,1,4){
        double ans=0;
        rep(j,0,n){
            ans+=pow(abs(x[j]-y[j]),i);
        }
        printf("%.10f\n",pow(ans,1.0/i));
    }
    
    int ans=0;
    rep(i,0,n){
        ans=max(ans,abs(x[i]-y[i]));
    }
    printf("%.10f\n",(double)ans);
    return 0;
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int ans;
  ans = C - ( A - B );
  if( ans > 0 ){
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REPC(x,c) for(auto x:(c))
#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>

#define ll long long

using namespace std;

int main() {
	int n;
	cin >> n;
	VI v(n);
	REP(i, n) {
		cin >> v[i];
	}

	int mx = 0, mn = pow(10, 9);
	REPC(x, v) {
		mn = min(mn, x);
		mx = max(mx, x);
	}
	cout << mx - mn << endl;
}

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

const int N = 500005;

int n;
struct kmp {
	int z[N];
	void build(std::string s) {
		int j = -1; s = '#' + s; z[0] = -1;
		for (int i = 1; i <= n; z[i++] = ++j)
			while (j >= 0 && s[i] != s[j + 1]) j = z[j];
	}
} a, b;
std::string s;

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> s, n = s.size(), a.build(s), b.build(std::string(s.rbegin(), s.rend()));
	if (a.z[n] == n - 1) return std::cout << n << "\n1\n", 0;
	if (!a.z[n] || n % (n - a.z[n])) return std::cout << "1\n1\n", 0;
	int ans = 0;
	for (int i = 1, j = n - 1; i < n; ++i, --j)
		ans += (!a.z[i] || i % (i - a.z[i])) &&
			   (!b.z[j] || j % (j - b.z[j]));
	std::cout << "2\n" << ans << '\n';
	return 0;
}

Measured memory_bytes: 5812
#include <stdio.h>
int main(void){
    int a,b,c,d,i;
    int sum=0;
    scanf("%d%d%d",&a,&b,&c);
    for(i=0;i<2;i++){
        if(a>b){
            d=a;
            a=b;
            b=d;
        }
         if(b>c){
            d=c;
            c=b;
            b=d;
        }
    }
    printf("%d\n",c-a);
    return 0;
}

Measured memory_bytes: 128
a, b, k = map(int, input().split())

if b-a+1 <= 2*k:
    for num in range(a, b+1):
        print(num)
else:
    for num in range(a, a+k):
        print(num)
    for num in range(b-k+1,b+1):
        print(num)

Measured memory_bytes: 3060
W,H,N = map(int, input().split())
ans = [[1 for _ in range(W)] for _ in range(H)]

for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        for i in range(H):
            for j in range(x):
                ans[i][j] = 0
    if a == 2:
        for  i in range(H):
            for j in range(x, W):
                ans[i][j] = 0
    if a == 3:
        for i in range(y):
            for j in range(W):
                ans[i][j] = 0
    if a == 4:
        for i in range(y, H):
            for j in range(W):
                ans[i][j] = 0
print(sum([sum(ans[i]) for i in range(H)]))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
using ll = long long;
int main(){
  ll N, M;
  cin >> N >> M;
  priority_queue<pair<ll,ll>> pq;
  for(int i = 0; i < N; ++i){
    int a, b;
    cin >> a >> b;
    pq.emplace(-a,b);
  }
  ll ans = 0;
  while(M > 0){
    pair<ll,ll> p = pq.top();
    pq.pop();
    ans += -p.first*min(M,p.second);
    M -= min(M,p.second);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
n = int(input())
m = int(input())
S_max = m
for i in range(n):
    a, b = map(int, input().split())
    m += a - b
    if m < 0:
        print(0)
        break
    if S_max < m:
        S_max = m
else:
    print(S_max)


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

int main() {
  int a, b;
  
  cin >> a >> b;
  if((a + b) % 2){
    cout << (a + b) / 2 + 1 << endl;
  }else{
    cout << (a + b) / 2 << endl;
  }
}


Measured memory_bytes: 3564
function Main(input) {
    var min_amari = 100;
    var sum = 0;
    for(var i = 0; i< 5; i++) {
        var time = parseInt(input[i]);
        min_amari = Math.min(min_amari, ((time + 9) % 10) + 1);
        sum += Math.floor((time + 9) / 10) * 10;
    }
    
    sum = sum - 10 + min_amari;

    console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
signed main() {
    int A,B;
    cin>>A>>B;

    cout<<lcm(A,B)<<endl;
}

Measured memory_bytes: 3632
a, b, k = map(int, input().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        a, b = a // 2, b+a//2
    else:
        if b % 2 == 1:
            b -= 1
        a, b = a+b//2, b//2
print(a, b)

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

int n, x, now = 1;

int main() {
  scanf("%d%d", &n, &x);
  if (x == 1 || x == (2 * n - 1)) return puts("No"), 0;
  puts("Yes");
  for (int i = 1; i <= n - 2; i++) {
    while (now == x || now == x - 1 || now == x + 1) ++now;
    printf("%d\n", now++);
  }
  printf("%d\n%d\n%d\n", x - 1, x, x + 1);
  for (int i = 1; i <= n - 2; i++) {
    while (now == x || now == x - 1 || now == x + 1) ++now;
    printf("%d\n", now++);
  }
  return 0;
}


Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1 && b==2)
        cout<<3<<endl;
    else if(a==1 && b==3)
        cout<<2<<endl;
    else if(a==2 && b==3)
        cout<<1<<endl;
    else if(a==2 && b==1)
        cout<<3<<endl;
    else if(a==3 && b==1)
        cout<<2<<endl;
    else if(a==3 && b==2)
        cout<<1<<endl;
        return 0;
}


Measured memory_bytes: 256
n=int(input())
f={}
h=list(map(int,input().split()))
ans=0
for i in range(n):
    if i-h[i] in f:
        ans+=f[i-h[i]]
    if i+h[i] in f:
        f[i+h[i]]+=1
    else:f[i+h[i]]=1
print(ans)

Measured memory_bytes: 40520
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> l(101,0);

int main(){
    int i,j,N,Q,M,d;
    
    while(1){
        scanf("%d %d",&N,&Q);
        if(!N && !Q){break;}
        fill(l.begin(),l.end(),0);
        for(i=0;i<N;i++){
            scanf("%d",&M);
            for(j=0;j<M;j++){
                scanf("%d",&d);
                l[d]++;
            }
        }
        auto maxit=max_element(l.begin(),l.end());
        if(*maxit>=Q){
            size_t midx=distance(l.begin(),maxit);
            printf("%lu\n",midx);
        }
        else{
            printf("0\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2580
#include<iostream>
#include<cstdio>
#include<math.h>

using namespace std;

int a,b;
int sum;
int ans = 0;
int digit;

int main(){
	while(cin >> a >> b){
		sum = a + b;
		digit = sum / 10;

		printf("%d\n",(int)log10(sum) + 1);
	}
    return 0;
}

Measured memory_bytes: 3352
#include <iostream>
using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if ((A != 1) & (B != 1) & (C != 1) & (A * B * C == 5 * 7 * 5)) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  while(true){
    if(a%b==0){
      break;
    }else{
      int c=a%b;
      a=b;
      b=c;
    }
  }
  return b;
}
int main(){
  int n,x;
  cin>>n>>x;
  if(n==1){
    int a;
    cin>>a;
    cout<<abs(a-x);
    return 0;
  }
  int a,b;
  cin>>b;
  a=abs(b-x);
  cin>>b;
  int m=gcd(max(a,abs(b-x)),min(a,abs(b-x)));
  for(int i=2;i<n;i++){
    cin>>b;
    m=gcd(max(m,abs(b-x)),min(m,abs(b-x)));
  }
  cout<<m;
}

Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_10_A

if __name__ == "__main__":
    n = int(input())

    if n == 0 or n == 1:
        result = 1
    else:
        A = [1] * (n + 1)

        for i in range(2, n+1):
            A[i] = A[i-1] + A[i-2]

        result = A[n]

    print(result)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcopy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

const double PI=acos(-1);

struct pt {
	ll x,y;int id;
	pt(ll x, ll y, int id=-1):x(x),y(y),id(id){}
	pt(){}
	ll norm2(){return *this**this;}
	double norm(){return sqrt(norm2());}
	pt operator+(pt p){return pt(x+p.x,y+p.y);}
	pt operator-(pt p){return pt(x-p.x,y-p.y);}
	ll operator*(pt p){return x*p.x+y*p.y;}
	double angle(pt p){
		return acos(*this*p/(norm()*p.norm()));}
	ll operator%(pt p){return x*p.y-y*p.x;}
	bool operator<(pt p)const{
		return x<p.x||x==p.x&&y<p.y;}
	bool left(pt p, pt q){
		return (q-p)%(*this-p)>0;}
};
vector<pt> chull(vector<pt> p){
	vector<pt> r;
	sort(p.begin(),p.end());
	fore(i,0,p.size()){
		while(r.size()>=2&&r.back().left(r[r.size()-2],p[i]))r.pop_back();
		r.pb(p[i]);
	}
	r.pop_back();
	int k=r.size();
	for(int i=p.size()-1;i>=0;--i){
		while(r.size()>=k+2&&r.back().left(r[r.size()-2],p[i]))r.pop_back();
		r.pb(p[i]);
	}
	r.pop_back();
	return r;
}

int n;vector<pt> p;
double r[128];

int main(){
	scanf("%d",&n);
	fore(i,0,n){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		p.pb(pt(x,y,i));
	}
	p=chull(p);
	fore(i,0,SZ(p)){
		r[p[i].id]=(PI-(p[(i+1)%SZ(p)]-p[i]).angle(p[(i+SZ(p)-1)%SZ(p)]-p[i]))/2/PI;
	}
	fore(i,0,n)printf("%.12lf\n",r[i]);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int S = sc.nextInt();

		int s1 = S/1000 ;
		int s2 = (S/100)%10 ;
		int s3 = (S/10)%10 ;
		int s4 = S%10 ;


		if(s1 == s2 || s2 == s3 || s3 == s4) {
			System.out.println("Bad");
		}else {
			System.out.println("Good");
		}


	}

}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

template<class V,int NV> class SegTree_2 {
public:
	vector<V> val;
	SegTree_2(){val.resize(NV*2,1LL<<60);};
	
	V getval(int entry) {
		entry += NV;
		ll ret=val[entry];
		while(entry>1) entry>>=1, ret=min(ret,val[entry]);
		return ret;
	}
	
	void update(int x,int y, V v,int l=0,int r=NV,int k=1) {
		if(l>=r) return;
		if(x<=l && r<=y) val[k]=min(val[k],v);
		else if(l < y && x < r) {
			update(x,y,v,l,(l+r)/2,k*2);
			update(x,y,v,(l+r)/2,r,k*2+1);
		}
	}
};

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

    int N, Q;
    cin >> N >> Q;
    set<ll> time_set;
    time_set.insert(-1LL<<60);
    time_set.insert(1LL<<60);

    vector<ll> S(N), T(N), X(N);

    for(int i = 0; i < N; i++){
        cin >> S[i] >> T[i] >> X[i];
        time_set.insert(S[i]-X[i]);
        time_set.insert(T[i]-X[i]);
    }

    vector<ll> D(Q);
    for(int i = 0; i < Q; i++){
        cin >> D[i];
        time_set.insert(D[i]);
    }

    vector<ll> time;
    for(auto itr = time_set.begin(); itr != time_set.end(); itr++){
        time.push_back(*itr);
    }
    
    SegTree_2<ll, 1<<20> st;

    int x, y;
    for(int i = 0; i < N; i++){
        x = lower_bound(time.begin(), time.end(), S[i] - X[i]) - time.begin();
        y = lower_bound(time.begin(), time.end(), T[i] - X[i]) - time.begin();
        st.update(x, y, X[i]);
    }

    for(int i = 0; i < Q; i++){
        x = lower_bound(time.begin(), time.end(), D[i]) - time.begin();
        ll ret = st.getval(x);
        if(ret >= 1LL<<50){
            cout << -1 << endl;
        }else{
            cout << ret << endl;
        }

    }

    return 0;
}



Measured memory_bytes: 58088
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(input())

x, y = [], []
for i, a in enumerate(A):
    if i % 2:
        y.append('#' + a[1:])
        x.append('.' + '#' * (W-1))
    else:
        x.append(a[:-1] + '#')
        y.append('#' * (W-1) + '.')

print(*x, sep='\n')
print('')
print(*y, sep='\n')

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


map<P,LL> ma;




int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    LL ans=0;
    for(int k=0;k<(1<<N);k++){
        string a="",b="";
        for(int i=0;i<N;i++){
            if(k&(1<<i)) a+=s[i];
            else b+=s[i];
        }
        reverse(ALL(b));
        ma[mp(a,b)]++;
    }
    for(int k=0;k<(1<<N);k++){
        string a="",b="";
        for(int i=0;i<N;i++){
            if(k&(1<<i)) a+=s[N+i];
            else b+=s[N+i];
        }
        reverse(ALL(b));
        ans+=ma[mp(b,a)];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 87040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};




int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    int N; cin >> N;
	vi A(N); vin(A);
	int Q; cin >> Q;
	vi B(Q), C(Q); rep(i,Q) cin >> B[i] >> C[i];


	vi cnt(100005, 0);
	rep(i,N) cnt[A[i]]++;

	ll ans = 0; rep(i,100005) ans += (ll) cnt[i] * i;

	//out(ans);

	rep(i,Q) {
		cnt[C[i]] += cnt[B[i]];
		ans += (ll) cnt[B[i]] * (C[i] - B[i]);
		cnt[B[i]] = 0;
		out(ans);
	}
}

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

struct UnionFind{
    vector<int> par;
    UnionFind(int n): par(n, -1){}
    //親さがし
    int root(int x){
        if(par[x]<0) return x;
        return par[x] = root(par[x]);//経路短くしとく
    }
    //くっつける
    void unite(int x, int y){
        int rx = root(x); 
        int ry = root(y);
        if(ry==rx) return ;
        if(par[rx]>par[ry]) swap(rx, ry);//小さい方をくっつける
        par[rx]+=par[ry];
        par[ry] = rx;
        return ;
    }
    //同じグループかどうか
    bool same(int x, int y){
        if(root(x)==root(y)) return true;
        return false;
    }
    //サイズ確認
    int size(int x) {return -par[root(x)];}
};

int sob[1000006];
vector<int> dame[1000006];

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        sob[a]++; sob[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int a, b;
        cin >> a >> b;
        a--; b--;
        dame[a].push_back(b);
        dame[b].push_back(a);
    }
    
    rep(i,n){
        int ans = uf.size(i) - sob[i] - 1;
        for(int x: dame[i]){
           if(uf.same(i,x)) ans--;
        }
        printf("%d%c", ans, i==n-1?'\n':' ');
    }
    
    return 0;
}

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

int main()
{
    int64_t X;
    cin >> X;
    int64_t total = 0;
    for (int i = 1;; i++)
    {
        total = (i + 1) * i / 2;
        if (total >= X)
        {
            cout << i << endl;
            return 0;
        }
    }
}

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

using namespace std;
static vector<int> primeNum;
vector<int> setPrime(long N)
{
	vector<int> v;
	v.push_back(2);
	for (long i = 3; i <= 1000000; i++)
	{
		bool flag = false;
		for (long j = 2; j * j <= i; j++)
		{
			if (i % j == 0)
			{
				flag = true;
				break;
			}
		}

		if (!flag)
		{
			v.push_back(i);
		}
	}

	return v;
}
int main()
{
	int N, P;
	primeNum = setPrime(1000000);
	while (cin >> N >> P && N != -1 && P != -1)
	{
		vector<int> primeSum;
		int index = 0;
		while (primeNum.at(index) <= N)
		{
			index++;
		}
		for (int i = index; i < index + P; i++)
		{
			for (int j = i; j < index + P; j++)
			{
				primeSum.push_back(primeNum.at(i) + primeNum.at(j));
			}
		}
		sort(primeSum.begin(),primeSum.end());
		cout << primeSum.at(P - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

vector<char> print(int , int , string, vector<char>);
string reverse(int , int, string);
string replace(int , int, string, string);


int main()
{
        string str, order, arg3;
        int num, arg1, arg2;
        vector<char> result;

        cin >> str;
        cin >> num;

        for(int i = 0; i < num; i++) {
                cin >> order;

                if(order == "print") {
                        cin >> arg1 >> arg2;
                        result = print(arg1, arg2, str, result);
                } else if(order == "replace") {
                        cin >> arg1 >> arg2 >> arg3;
                        str = replace(arg1, arg2, arg3, str);
                } else if(order == "reverse") {
                        cin >> arg1 >> arg2;
                        str = reverse(arg1, arg2, str);
                }
        }

        for(vector<char>::iterator ite = result.begin(); ite != result.end(); ++ite) {
                cout << *ite;
        }

        return 0;
}

vector<char> print(int arg1, int arg2, string s, vector<char> q)
{
//      cout << "print_in: " << s << endl;
        for(int i = arg1; i <= arg2; i++) {
                q.push_back(s[i]);
        }
        q.push_back('\n');

//      cout << "print_out: " << s << endl;
        return q;
}

string reverse(int arg1, int arg2, string s)
{
//      cout << "reverse_in: " << "arg1: " << arg1 << " arg2: " << arg2 << ' ' << s << endl;
        string s_tmp;

//      cout << "reverse: ";
        for(int i = 0; i < arg2 - arg1 + 1; i++) {
                s_tmp[i] = s[arg1 + i];
//              cout << s_tmp[i];
        }
//      cout << endl;

        for(int i = 0; i < s.size(); i++) {
                if(i >= arg1 && i <= arg2) {
                        s[i] = s_tmp[arg2-i];
                }
        }
//      cout << "reverse_out: " << "arg1: " << arg1 << " arg2: " << arg2 << ' ' << s << endl;
        return s;
}

string replace(int arg1, int arg2, string s1, string s2)
{
//      cout << "replace_in: " << "arg1: " << arg1 << "arg2: " << arg2 << ' ' << s2 << endl;
        for(int i = 0; i < arg2 - arg1 + 1; i++) {
                s2[i+arg1] = s1[i];
        }
//      cout << "replace_out: " << "arg1: " << arg1 << "arg2: " << arg2 << ' ' << s2 << endl;
        return s2;
}



Measured memory_bytes: 3228
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int main(){
	string s;
	while(cin >> s){
		int n = s.size();
		int joi = 0, ioi = 0;
		rep(i, n - 2){
			if(s[i+1] == 'O' && s[i+2] == 'I'){
				if(s[i] == 'J') joi++;
				if(s[i] == 'I') ioi++;
			}
		}
		cout <<joi << endl;
		cout << ioi << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

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

	cout << a*b/2 << endl;
}



Measured memory_bytes: 256
import sys
 
N = int(input())
l = [int(x) for x in input().split()]
if 0 in l:
  print(0)
  sys.exit()
ans = 1
for i in range(N):
  if ans > pow(10, 18):
    ans = -1
    break
  else:
    ans *= l[i]
if ans > pow(10, 18):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 21796
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    #n = int(stdin.readline().rstrip())
    x,n = map(int, stdin.readline().rstrip().split())
    if n != 0:
        ps = list(map(int, stdin.readline().rstrip().split()))
    else:
        print(x)
        exit()
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ps.sort()
    ab = []
    for i in range(n):
        ab.append(abs(ps[i] - x))
    m = ps[ab.index(min(ab))]
    small = m
    big = m
    if m not in ps:
        print(m)
        exit()
    while True:
        small = small - 1
        big = big + 1
        if small not in ps:
            print(small)
            exit()
        elif big not in ps:
            print(big)
            exit()

main()


Measured memory_bytes: 9236
#include <cstdio>
#include <cstring>
#include <algorithm>

using std::max;
using std::min;

const int MAXN=1e5+5;
char s[MAXN];

int main(){
	scanf("%s",s);
	int n=strlen(s),ans=n;
	for(int i=1;i<n;++i){
		if(s[i]!=s[i-1])
			ans=min(ans,max(i,n-i));
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, sum, mx = -1e18, a[100005], d[100005], ans;

int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		sum += a[i];
		if(i > 1) d[i-1] = a[i] - a[i-1];
	}
	d[n] = a[1] - a[n];
	for(int i=1;i<=n;i++) {
		mx = max(mx, d[i]);
	}
	if(mx < 0) {puts("NO"); return 0;}
	for(int i=1;i<=n;i++) {
		if((d[i] - mx)%n) {puts("NO"); return 0;}
		ans -= (d[i] - mx) / n;
	}
	if(mx != ans) {puts("NO"); return 0;}
	if(sum < n*(n+1)/2*mx || (sum - n*(n+1)/2*mx) % (n*(n+1)/2*n) != 0) {puts("NO"); return 0;}
	puts("YES");
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		String a=scn.next();
		String b=scn.next();
		int[][] dp=new int[a.length()+1][b.length()+1];
		char[][] ss=new char[a.length()+1][b.length()+1];
		for(int i=0;i<=a.length();i++) {
			for(int j=0;j<=b.length();j++) {
				if(i==0||j==0) {
					dp[i][j]=0;
					ss[i][j]='@';
					continue;
					
				}
				if(a.charAt(i-1)==b.charAt(j-1)) {
					dp[i][j]=dp[i-1][j-1]+1;
					ss[i][j]='d';
				}else {
					dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
					if(dp[i][j]==dp[i-1][j]) {
						ss[i][j]='u';
					}else {
						ss[i][j]='l';
					}
				}
					
				
				
			}
		}
		int len=dp[a.length()][b.length()];
		StringBuilder sb=new StringBuilder();
		int i=a.length();
		int j=b.length();
		while(sb.length()!=len) {
			if(ss[i][j]=='d') {
				sb.append(a.charAt(i-1));
				i=i-1;
				j=j-1;
			}else if(ss[i][j]=='u') {
				i=i-1;
				
			}else {
				j--;
			}
			
		}
		sb=sb.reverse();
		System.out.println(sb.toString());
		

	}

}


Measured memory_bytes: 103636
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

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


		// 1行目数字
		int iCount = Integer.parseInt(br.readLine());

		// 2行目、複数数字
		String[] ss0 = br.readLine().trim().split(" ", 0);

				
				// 3行目以降、複数数字
				for(int i = 0; i < iCount; i++){
					//System.out.print("[" + ss0[i] + "]");
				}
				//System.out.println("");
				

		int n = 0;
		int m = 0;
		int iAns = 0;
		for(int i = 0; i < iCount; i++){
			n = Integer.parseInt(ss0[i]);
					//System.out.print("n=[" + n + "]");
			m = Integer.parseInt(ss0[n-1]);
			if (m == (i+1)) { iAns++; }
					//System.out.println("ss0[n-1]=[" + ss0[n-1] + "], i=[" + i + "], iAns=[" + iAns + "]");
		}

		System.out.print(iAns/2);
    }
}



Measured memory_bytes: 23008
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n%2==0)System.out.println(0.50000);
      else System.out.println((double)(n+1)/(2*n));
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
 
using namespace std;
using LL = long long int; 

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.st <<","<<P.nd <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAXN = 1e6;
int cnt[MAXN];
int t[MAXN];

int n;
LL res;

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> t[i];
    cnt[t[i]]++;
  }

  for (int i = 1; i <= n; ++i) {
    res += (LL)cnt[i] * (LL)(cnt[i] - 1) / 2;
  }
  debug(res);
  for (int i = 1; i <= n; ++i) {
    cout << res - (LL)(cnt[t[i]] - 1) << endl;
  }
}


Measured memory_bytes: 7424
#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() {
    ll n, d;
    cin >> n >> d;
    ll a[n][2];
    rep(i,n) cin >> a[i][0] >> a[i][1];
    ll ans = 0;
    rep(i,n){
        if (sqrt(a[i][0]*a[i][0] + a[i][1]*a[i][1]) <= d) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6704
#include <stdio.h>
#include <string.h>
int main(){
    int n,r=0,b=0;
    char s[100];
    scanf("%d\n",&n);
    scanf("%s",s);
    for (int i=0;i<strlen(s);i++){
        if (s[i]=='R') r++;
        else b++;
    }
    if (r>b) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

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

const int N = 1006;
const int MOD = (int)1e9 + 7;

int n, m, dp[N][N];
char a[N][N];

int main() {
  init_ios();
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      cin >> a[i][j];
  dp[0][1] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] == '#')
        continue;
      if (a[i-1][j] != '#')
        dp[i][j] = dp[i-1][j];
      if (a[i][j-1] != '#')
        dp[i][j] = (dp[i][j]+dp[i][j-1])%MOD;
    }
  cout<<dp[n][m]<<"\n";
}

Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    public class AtCoder20171118D
    {
        static void Main(string[] args)
        {
            var s1 = Console.ReadLine().Split().Select(f => int.Parse(f)).ToList();
            var s2 = new List<int[]>();
            for(int i = 0; i<=9; i++)
            {
                s2.Add(Console.ReadLine().Split().Select(f => int.Parse(f)).ToArray());
            }
            var s3 = new List<int>();
            for (int i = 0; i < s1[0]; i++)
            {
                s3.AddRange(Console.ReadLine().Split().Select(f => int.Parse(f)).ToList());
            }
            
            Console.WriteLine(funcMain(s1,s2,s3));

            Console.ReadKey();
        }

        static public string funcMain(List<int> arg1, List<int[]> arg2, List<int> arg3)
        {
            int ret = 0;
            int[] weight = new int[10];

            for (int i = 0; i < 10; i++)
            {
                weight[i] = funcGetNextWeight(arg2[i][1], 0, i, arg2);
            }

            foreach(int i in arg3){
                if (i == -1) continue;
                ret += weight[i];
            }

            return ret.ToString();
        }

        static private int funcGetNextWeight(int tarWeight,int curWeight, int _i, List<int[]> clist)
        {
            int retWeight = curWeight + clist[_i][1];
            for (int j = 0; j < 10; j++)
            {
                if (j == 1) continue;
                if (_i == j) continue;
                if (curWeight + clist[_i][j] < tarWeight) {
                    var tmp = funcGetNextWeight(tarWeight, curWeight + clist[_i][j],j , clist);
                    if (tmp < retWeight) {
                        retWeight = tmp;
                    }
                }
            }

            return retWeight;
        }

    }
}


Measured memory_bytes: 13664
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;cin>>n;
    int modempat=0,ganjil=0,notmod=0;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        if(a%2==1)ganjil++;
        else if(a%4!=0&&a%2==0)notmod++;
        else modempat++;
    }
    if(modempat>=ganjil)cout<<"Yes\n";
    else if(modempat==ganjil-1&&notmod==0)cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3636
#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] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,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;

vector<int> divisor(int n){
    vector<int> ret;
    vector<int> v(n+3,0);
    for(int i=6; i<=n; i+=7){
        if(!v[i]){
            int tmp = n;
            if(tmp % i == 0){
                for(int j=i; j<=n; j+=i) v[j]++;
            }
            while(tmp % i == 0){
                tmp /= i;
                ret.push_back(i);
            }
        }
        int tmp = n;
        if(v[i+2]) continue;
        if(tmp % (i+2) == 0){
            for(int j=i+2; j<=n; j+=i+2) v[j]++;
        }
        while(tmp % (i+2) == 0){
            tmp /= (i+2);
            ret.push_back(i+2);
        }
    }
    sort(all(ret));
    ret.erase(unique(all(ret)),ret.end());
    return ret;
}

int main(){
    while(1){
        int n; cin >> n;
        if(n == 1) break;
        auto div = divisor(n);
        cout << n << ": ";
        rep(i,div.size()-1) cout << div[i] << " ";
        cout << div[div.size()-1] << "\n";
    }
}


Measured memory_bytes: 5136
import sys;input=sys.stdin.readline

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

event.sort()
is_stop=False
stop=set()
minstop=float('inf')
ans=[-1]*q
for t,e,x in event:
    if e > 0:
        stop.add(x)
        if x<minstop:
            minstop=x
            is_stop=True
    elif e<0:
        stop.remove(x)
        if minstop==x:
            is_stop=False
    elif len(stop)>0:
        if not is_stop:
             minstop=min(stop)
             is_stop=True
        ans[x]=minstop

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}


ll calc(ll y,ll m,ll d){
	ll res = 0;
	y--;
	res += (y/3)*(20*20+19*10);
	y %= 3;
	res += y*(20*5+19*5);
	y++;
	if(y % 3 == 0)res += (m-1)*20;
	else {
		rep(i,m-1){
			if(i % 2 == 0)res += 20;
			else res += 19;
		}
	}
	res += d;
	return res;
}

ll n;

int main(){
	cin >> n;
	ll y,m,d;
	// cout << calc(1,1,1) << endl;
	rep(i,n){
		cin >> y >> m >> d;
		cout << calc(1000,1,1) - calc(y,m,d) << endl;
	}
}


Measured memory_bytes: 3092
n, m, x = [*map(int, input().split())]
k = [[*map(int, input().split())] for _ in range(n)]
ans = 10 ** 9

for i in range(2 ** n):
    cost = 0
    skills = [0] * m
    for j in range(n):
        if ((i >> j) & 1):
            cost += k[j][0]
            for s, t in enumerate(k[j][1:]):
                skills[s] += t
            if all(map(lambda skill: skill >= x, skills)):
                ans = min(ans, cost)
print(-1 if ans == 10 ** 9 else ans)


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a*c <= b) cout << c << endl;
    else cout << b/a << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
struct trump
{
	char suit;
	int number;
	trump() {}
	trump(char s, int n) : suit(s), number(n) {}
	bool operator<(const trump&t)const
	{
		return number < t.number;
	}
	bool operator==(const trump&t)const
	{
		return number == t.number && suit == t.suit;
	}
};
ostream&operator<<(ostream&os, const trump&t)
{
	os << t.suit << t.number;
	return os;
}
void bubblesort(vector<trump>&c)
{
	REP(i, c.size())REPR1(j, i_len - 1)if (c[j] < c[j - 1])swap(c[j], c[j - 1]);
}
void selectionsort(vector<trump>&c)
{
	REP(i, c.size())
	{
		int min_index = i;
		REPI(j, i + 1, i_len)if (c[j] < c[min_index])min_index = j;
		swap(c[i], c[min_index]);
	}
}
bool is_stable(const vector<trump>&c1, const vector<trump>&c2)
{
	REP1(i, 9)
	{
		string strc1;
		REPC(j, c1)if (j.number == i)strc1.push_back(j.suit);
		string strc2;
		REPC(j, c2)if (j.number == i)strc2.push_back(j.suit);
		if (strc1 != strc2)return false;
	}
	return true;
}
int main()
{
	int n = in();
	vector<trump> origin(n), cards1(n), cards2(n);
	REP(i, n)
	{
		char suit = in<char>();
		int num = in();
		origin[i] = cards1[i] = cards2[i] = trump(suit, num);
	}
	bubblesort(cards1);
	REP(i, cards1.size())
	{
		if (i != 0)cout << ' ';
		cout << cards1[i];
	}
	cout << endl;
	cout << (is_stable(origin, cards1) ? "Stable" : "Not stable") << endl;
	selectionsort(cards2);
	REP(i, cards2.size())
	{
		if (i != 0)cout << ' ';
		cout << cards2[i];
	}
	cout << endl;
	cout << (is_stable(origin, cards2) ? "Stable" : "Not stable") << endl;
}


Measured memory_bytes: 3212