akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] A = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        int N = sc.nextInt();
        while (N-- > 0) {
            int b = sc.nextInt();
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    if (A[i][j] == b) {
                        A[i][j] = 0;
                    }
                }
            }
        }

        // row
        for (int i = 0; i < 3; i++) {
            if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0) {
                System.out.println("Yes");
                return;
            }
        }
        // column
        for (int j = 0; j < 3; j++) {
            if (A[0][j] == 0 && A[1][j] == 0 && A[2][j] == 0) {
                System.out.println("Yes");
                return;
            }
        }

        // naname
        if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) {
            System.out.println("Yes");
            return;
        }
        if (A[2][0] == 0 && A[1][1] == 0 && A[0][2] == 0) {
            System.out.println("Yes");
            return;
        }

        System.out.println("No");
    }
}


Measured memory_bytes: 24020
n = int(input())
a = list(map(int, input().split()))

total = [0]*n
total[0] = abs(a[0])
fee = [0]*n
fee[0] = abs(a[0])

for i in range(1,n):
    fee[i] = abs(a[i-1]-a[i])
    total[i] = total[i-1] + fee[i]

dist = total[-1]

print(total[-1] - fee[0] - fee[1] + abs(a[1]) + abs(a[-1]))

for i in range(1,n-1):
    ans = dist - fee[i] - fee[i+1] + abs(a[i-1]-a[i+1])
    ans += abs(a[-1])
    print(ans)

print(total[-2] + abs(a[-2]))

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    long int n;
    cin>>n;
    string s;
    cin>>s;
    long int w=0,r=0;
    for(long int i=0;i<n;i++){
        w+=(s[i]=='W');
        r+=(s[i]=='R');
    }
    long int nw=0;
    for(long int i=0;i<r;i++){
        nw+=(s[i]=='R');
    }
    long int ans=min(w,r-nw);
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3760
import math

A, B, H, M = map(int,input().split())

T = M + H * 60

a_x = A * math.cos(math.pi * T / 360)
a_y = A * math.sin(math.pi * T / 360)
b_x = B * math.cos(math.pi * M / 30)
b_y = B * math.sin(math.pi * M / 30)

print(math.sqrt((a_x - b_x)**2 + (a_y - b_y)**2))

Measured memory_bytes: 9512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        List<Integer> ac = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }

        for (int i = 0; i < n - 1; i++) {
            int prev;
            if (i == 0) {
                prev = 0;
            } else {
                prev = ac.get(i - 1);
            }
            if ("A".equals(str[i]) && "C".equals(str[i + 1])) {
                ac.add(prev + 1);
            } else {
                ac.add(prev);
            }
        }
        for (int i = 0; i < q; i++) {
            int start = l.get(i);
            int end = r.get(i);
            if (start == 1) {
                System.out.println(ac.get(end - 2));
            } else {
                System.out.println(ac.get(end - 2) - ac.get(start - 2));
            }
        }
    }

}


Measured memory_bytes: 109480
n,k = map(int,input().split())
s = input()
c = [int(s[i]) for i in range(n)]
ids = [0]
for i in range(1,n):
  if c[i] != c[i-1]:
    ids.append(i)
ids.append(n)
l = len(ids)
result = []
for i in range(l-1):
  if c[ids[i]] == 0:
    if i + 2*k < l:
      result.append(ids[i+2*k] - ids[i])
    else:
      result.append(n - ids[i])
  else:
    if i + 2*k + 1 < l:
      result.append(ids[i+2*k+1] - ids[i])
    else:
      result.append(n - ids[i])
print(max(result))

Measured memory_bytes: 11892
#include<algorithm>
#include<iostream>
using namespace std;
int n,m,o,ans,dp[55],a[55],b[55],c[55],d[55];
int shu() 
{
    int sum=0;
    for(int i=1;i<=o;i++) 
	{
        if(dp[b[i]]-dp[a[i]]==c[i]) 
		{
            sum+=d[i];
        }
    }
    return sum;
}
void dfs(int temp) 
{
    if(temp>n) 
	{
        ans=max(ans,shu());
        return;
    }
    for(int i=dp[temp-1];i<=m;i++) 
	{
        dp[temp]=i;
        dfs(temp+1);
    }
}
 
int main() 
{
    cin>>n>>m>>o;
    for(int i=1;i<=o;i++) 
	{
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dp[0]=1;
    dfs(1);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  val a = sc.nextInt()
  val b = sc.nextInt()


  private val res = (1 to n)
    .map(i => (i, i.toString.split("").filter(_.length!=0).map(_.toInt).sum))
    .filter { case (_, isum) => isum >= a && isum <= b }.map(_._1).sum

  println(res)


}


Measured memory_bytes: 45840
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);    
    int num = scan.nextInt();
    scan.close();
        
    int hapiness = 0;
    
    hapiness += (num / 500) * 1000;
    
    hapiness += ((num % 500) / 5) * 5;
    
    System.out.println(hapiness);
  }
}


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

int main() {
  string s; cin >> s;
  string res = "";
  for (int i=0;i<s.size();i++) {
    switch(s[i]) {
      case '0':
        res+="0";
        break;
      case '1':
        res+="1";
        break;
      case 'B':
        if (res.size()==0) break;
        res.erase(res.size()-1);
        break;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3588
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!(
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    );
    println!("{}", [a*c, a*d, b*c, b*d].iter().max().unwrap());
}


Measured memory_bytes: 2204
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define pb push_back
#define mp make_pair
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;



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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;
	Array p(n);
	REP(i, n) {
		cin >> p[i];
	}

	ll min = INF;
	ll ans = 0;
	REP(i, n) {
		if (min >= p[i])ans++;
		chmin(min,p[i]);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
  int n;
  int i;
  int j;
  int flag;

  scanf("%d", &n);

  i = 1;
  while (i <= n) {
    flag = 0;
    if (i % 3 == 0 ) {
      flag = 1;
    }
    else {
      j = i;
      while (j) {
        if (j % 10 == 3 ) {
          flag = 1;
          break;
        }
        j /= 10;
      }
    }

    if (flag) printf(" %d", i);
    i++;
  }

  printf("\n");
  return (0);
}



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

using namespace std;
typedef long long int lld;
#define INF 1000000000000000000
vector<int> nei[100000];
int DP[1000000];
int n,m;
int compute(int node){
	if(DP[node]!=-1)return DP[node];
	DP[node]=0;
	for(int i=0;i<nei[node].size();i++){
		int v=nei[node][i];
		DP[node]=max(DP[node],compute(v)+1);
	}
	return DP[node];
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		nei[x].push_back(y);
	}
	lld ans=0;
	for(int i=0;i<n;i++)DP[i]=-1;
	for(int i=0;i<n;i++)ans=max(ans,(lld)compute(i));
	cout<<ans<<endl;
	return 0;
}

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



int main() 
{
  ll A; cin>>A;
  string S; cin>>S;
  ll B=(S.at(0)-'0')*100+(S.at(2)-'0')*10+(S.at(3)-'0')*1;
  cout<<(A*B)/100<<endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
using namespace std;

/*
            ॐ
    || Jai Shree Ram ||  
 
 */


void solve()
{
   
    string s,t;
    cin>>s>>t;

    int n = s.size();
    int  ans = 0;
    for(int i=0; i<n; i++) {
        if(s[i] != t[i])    ans++;
    }

    cout<<ans;

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


Measured memory_bytes: 3688
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/**@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*/
/**status : */
/**url: */
/* Generate with Contest-Helper **/
/* https://github.com/goldenbijoy/Contest_Helper */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define clr(arr,value) memset(arr,value,sizeof(arr))
#define MOD 1000000007
#define PI acos(-1)
#define PB push_back
#define MP make_pair
#define SP " "
#define NL "\n"
#define DE cout<<"HERE"<<endl;
#define INF 1e18
#define __FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr2V(x,sz) for(int iii=0;i<=sz;iii++) x[iii].clear();
#define NUM1(x) __builtin_popcount(x)
#define Pause system("pause");
#define MAX 100050/** can increase another 0 */

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    ll i,j,k,arr[MAX],l,m,n,x,y,coun,sum,ans,T,check;
    vector<ll> v;
    string s,s2;

    cin>>T;

    cin>>s>>s2;

    for(j=0,i=0,k=0;k<2*T;k++){
        if(k%2==0) cout<<s[i++];
        else cout<<s2[j++];
    }


    /// Don't forget to initialize array....
    return 0;
}


Measured memory_bytes: 256
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
MP = {tuple(p): i for i, p in enumerate(P)}

def cross(C, A, B):
    return (C[0] - A[0])*(C[1] - B[1]) - (C[1] - A[1])*(C[0] - B[0])

def convex_hull(P):
    P.sort()
    Q = []
    for p in P:
        while 1 < len(Q) and cross(Q[-2], Q[-1], p) >= 0:
            Q.pop()
        Q.append(p)
    k = len(Q)
    for p in reversed(P[:-1]):
        while k < len(Q) and cross(Q[-2], Q[-1], p) >= 0:
            Q.pop()
        Q.append(p)
    return Q

from math import atan2, pi

Q = convex_hull(P)[:-1]
K = len(Q)
ans = [0.]*N
for i in range(K):
    S = Q[i-1]; T = Q[i]; U = Q[(i+1)%K]
    X0 = T[0] - S[0]; X1 = U[0] - T[0]
    Y0 = T[1] - S[1]; Y1 = U[1] - T[1]
    ans[MP[tuple(Q[i])]] = atan2(X1*Y0 - X0*Y1, X0*X1 + Y0*Y1) / 2. / pi
print(*ans, sep='\n')

Measured memory_bytes: 3444
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  long long L,R;
  cin >> L >> R;
  long long l,r;
  l = L;
  r = R;
  if(R - L > 6057){
    r = L+6057;
  }
  long long ans = 2019;
  for(long long i=l;i<=r;i++){
    for(long long j=l;j<=r;j++){
      if(i == j) continue;
      ans = min(ans,(i*j)%2019);
    }
  }

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


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll dp[N];
int w[105],v[105];
int main(){
    int n,W;
    cin>>n>>W;
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=W;j>=w[i];j--) dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    }
    cout<<dp[W];
}


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

const int MOD = 1e9+7;

const int MAX = 100010;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i=0;i<n;i++) {
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());
    ll ans=0;
    COMinit();
    for (int i=0;i<n;i++) {
        if (n-i-1>=k-1) {
            ll c=COM(n-i-1, k-1);
            ll b=a[i]-a[n-1-i];
            while (b<0) b+=MOD;
            ans+=((b%MOD)*(c%MOD))%MOD;
            ans=ans%MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var PriorityQueue=(function(){
  function f(){return new PriorityQueue();}
  function PriorityQueue(){
    this.heap=[];
  }
  PriorityQueue.prototype.push=function(x){
    var h=this.heap,i=h.length++,j;
    while(i){
      j=i-1>>1;
      if(h[j][0]<=x[0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
  };
  PriorityQueue.prototype.pop=function(){
    var h=this.heap,r=h[0],x=h.pop(),l=h.length,i=0,j;
    if(l===0)return r;
    var k=l>>1;l--;
    while(i<k){
      j=(i<<1)+1;
      if(j<l&&h[j+1][0]<h[j][0])j++;
      if(x[0]<=h[j][0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
    return r;
  };
  return f;
})();

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var b = o.l();
  var pq = PriorityQueue();
  for(var i = 0; i < n; i++){
    if(a[i] === b[i])continue;
    if(a[i] > b[i])return -1;
    pq.push([-b[i],i]);
  }
  var ans = 0;
  while(pq.heap.length){
    var t = pq.pop();
    var j = t[1];
    var y = b[(j+n-1)%n] + b[(j+1)%n];
    var z = (b[j]-a[j])/y|0;
    if(z === 0)return -1;
    ans += z;
    b[j] -= y*z;
    if(a[j] === b[j])continue;
    if(a[j] > b[j])return -1;
    pq.push([-b[j],j]);
  }
  return ans;
}

Measured memory_bytes: 121440
import java.nio.Buffer;
import java.util.Scanner;

public class Main {
    public static Scanner r=new Scanner(System.in);
    public static long []fac=new long[2000010];
    public static long mod=1000000007;
    public static long mul(long a,long b){
        return a*b%mod;
    }
    public static void init(){
        fac[0]=fac[1]=1;
        for(int i=2;i<2000010;++i){
            fac[i]=mul(fac[i-1],1l*i);
        }
    }
    public static long poww(long a,long b){
        long r=1;
        while(b>0){
            if(b%2==1) r=mul(r,a);
            a=mul(a,a);
            b/=2;
        }
        return r;
    }
    public static long inv(long x) {
        return poww(x, mod - 2);
    }
    public static long bino(int n,int k){
        if(k<0) return 0;
        if(k==0) return 1;
        return mul(fac[n],mul(inv(fac[n-k]),inv(fac[k])));
    }
    public static void main(String[] args) {
        init();
        long ans=0;
        int k=r.nextInt();
        String s=r.next();
        int n=s.length();
        long maxx=n+k;
        for(int len=n;len<=maxx;++len){
            long last=maxx-len;
            long ch_last=poww(26,last);
            long pos=bino(len-1,n-1);
            long ch25=poww(25,len-n);
            long cur=mul(mul(pos,ch25),ch_last);
            ans+=cur;
            ans%=mod;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 71516
#include<iostream>
#include<queue>
#include<map>
#define LEN 100
#define BASE 25

using namespace std;

int maps[LEN][LEN];
int off[LEN][LEN];

int checker[4];
int ncheck[4];

map<int, int> points[LEN];

class State {
public:
	char where;
	int enemy;
	int budget;
	int check[4];
	State() {check[0]=0;check[1]=0;check[2]=0;check[3]=0;}
	State(char w, int e, int b ) {
		where = w;
		enemy = e;
		budget = b; 
		check[0] = ncheck[0];
		check[1] = ncheck[1];
		check[2] = ncheck[2];
		check[3] = ncheck[3];
	}
};


inline bool operator< ( const State& a, const State& b) {
	if( a.enemy == b.enemy )
		return a.budget > b.budget;
	return a.enemy < b.enemy;
}

inline bool operator> ( const State& a, const State& b) {
	if ( a.enemy == b.enemy )
		return a.budget < b.budget;
	return a.enemy > b.enemy;
}

priority_queue<State, deque<State>, greater<State> > status;

inline void copy ( State now ) {
	checker[0] = now.check[0];
	checker[1] = now.check[1];
	checker[2] = now.check[2];
	checker[3] = now.check[3];
}

inline void ncopy ( ) {
	ncheck[0] = checker[0];
	ncheck[1] = checker[1];
	ncheck[2] = checker[2];
	ncheck[3] = checker[3];
}

inline bool check ( int i ) {
	return 0 == ((1<<(i%25)) & checker[i/BASE]);
}

inline void add ( int i ) {
	ncheck[i/BASE] = ((1<<(i%25)) | checker[i/BASE]);
}

inline void insert ( int i, int e, int b ) {
	
	map<int,int>::iterator itr = points[i].find(e);
	if ( itr == points[i].end() ) {
		points[i][e] = b;
		status.push(State(i,e,b));
	} else if ( (*itr).second < b ) {
		(*itr).second = b;
		status.push(State(i,e,b));
	}
	
	itr++;
	int min = b+1;
	
	while( itr != points[i].end() ) {									
		if ((*itr).second > min) {
			(*itr).second = min;
		} else {
			min = (*itr).second+1;
		}
		itr++;
	}
}

int main () {


	while ( true ) {
		int n,m,l;
		cin >> n >> m >> l;

		if ( n == 0 )
			break;

		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<n; j++ ) {
				maps[i][j] = -1;
				off[i][j] = 0;
			}
			points[i].clear();
		}

		for ( int i=0; i<m; i++ ) {
			int a,b,d,e;
			cin >> a >> b >> d >> e;

			maps[a-1][b-1] = maps[b-1][a-1] = d;
			off[a-1][b-1] = off[b-1][a-1] = e;
		}

		for ( int i=0; i<4; i++ ) {
			ncheck[i] = 0;
			checker[i] = 0;
		}

		priority_queue<State, deque<State>, greater<State> > empty;
		status = empty;

		ncheck[0] = 1;
		status.push(State(0,0,l));
		int count = 0;
		while(!status.empty()) {
			State now = status.top();
			status.pop();
			if ( now.where == n-1 ) {
				cout << now.enemy << endl;
				break;
			}

			copy(now);

			for ( int i=0; i<n; i++ ) {
				if ( maps[now.where][i] > 0 ) {
					if ( check( i ) ) {
						ncopy();
						add(i);
						int e, b;
						if ( off[now.where][i] == 0 ) {
							e = now.enemy;
							b = now.budget;
							insert(i,e,b);
						} else {
							if ( now.budget - maps[now.where][i] >= 0 ) {
								e = now.enemy;
								b = now.budget - maps[now.where][i];
								insert(i,e,b);
							}
							e = now.enemy + off[now.where][i];
							b = now.budget;
							insert(i,e,b);
						}
					}
				}
			}
		}
	}
}

		

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n,m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  rep(i,m){
    int a,b;cin >> a >> b;
    a--,b--;
    v[a].push_back(b);
  }
  int S,T;
  cin >> S >> T;
  S--,T--;
  vector<vector<int>> d(n,vector<int>(3,-1));
  d[S][0] = 0;
  queue<P> que;
  que.push(make_pair(S,0));
  while(!que.empty()){
    P ov = que.front();que.pop();
    for(auto nv : v[ov.first]){
      if(d[nv][(ov.second+1)%3] != -1)continue;
      d[nv][(ov.second+1)%3] = d[ov.first][ov.second] + 1;
      que.push(make_pair(nv,(ov.second+1)%3));
    }
  }
  cout << (d[T][0] != -1 ? d[T][0]/3 : -1) << endl;



  return 0;
}

Measured memory_bytes: 14028
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
counter_comb = list(map(lambda y: int(y*(y-1)/2), counter.values()))
sum_counter = sum(counter_comb)
for i in range(n):
    z = counter[A[i]]
    if z>0:
        print(sum_counter-(z-1))
    else:
        print(sum_counter)
    

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

int main()
{
	
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else
		cout << "Impossible" << endl;
	return 0;
}

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

#define ll long long int
#define VI vector<int>
#define lf(i,a,b) for(int i=a;i<=b;i++)

string s;
ll n;

ll fun(ll k)
    {   ll flag1=1;
        ll flag2=1;
        lf(i,n-k+1,k)
            if(s[i-1]!='1')
                flag1=0;
        lf(i,n-k+1,k)
            if(s[i-1]!='0')
                flag2=0;
        return flag1||flag2;
    }
int main()
{   cin>>s;
    n=s.length();
    ll l=1,r=n;
    ll ans;
    while(l<=r)
    {   ll mid=(l+r)>>1;
        if(fun(mid))
        {   ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    cout<<ans<<endl;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

constexpr int N = 8;

int check(int queen[N])
{
	int i, j;

	for (i = 0; i < N - 1; i++) {
		for (j = i + 1; j < N; j++) {
			if (queen[i] == queen[j] || abs(queen[i] - queen[j]) == j - i) return 0;
		}
	}
	return 1;
}

void printQueen(int queen[N])
{
	for (int y = 0; y < N; y++) {
		for (int x = 0; x < N; x++) {
			if (queen[y] == x) {
				cout << "Q";
			}
			else {
				cout << ".";
			}
		}
		cout << endl;
	}
}

vector<int> ds(8, -1);

bool setQueen(int queen[], int y)
{
	if (y == N) {
		if (check(queen)) {
			printQueen(queen);
			return true;
		}
		else {
			return false;
		}		
	}

	if (ds[y] >= 0) {
		queen[y] = ds[y];
		if (setQueen(queen, y + 1)) {
			return true;
		}
		return false;
	}
	for (int j = 0; j < N; j++) {
		queen[y] = j;
		if (setQueen(queen, y + 1)) {
			return true;
		}
	}
	return false;
}


int main() {
	int a;
	cin >> a;
	rep(i, a) {
		int y, x;
		cin >> y >> x;
		ds[y] = x;
	}
	int queen[N];
	setQueen(queen, 0);
	return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
long long a[100100];
int main()
{
    int n;
   while(~scanf("%d",&n))
  {
      int i,p=0,m=0;
      for(i=0;i<n;i++)
    scanf("%lld",&a[i]);
   for(i=0;i<n;i++)
     {
         if(a[i]%4==0)  p++;
        if(a[i]%4!=0&&a[i]%2==0) m++;
     }
     m=m/2; p=p+m;
   if(p>=n/2) printf("Yes\n");
   else      printf("No\n");
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <map>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    map<int, int> bc;
    int s[m];
    int c[m];
    for (int i = 0; i < m; i++)
    {
        cin >> s[i] >> c[i];
        for (int j = 0; j < i; j++)
        {
            if (s[i] == s[j] && c[i] != c[j])
            {
                goto ERROR;
            }
        }
    }
    if (n == 1)
    {
        bc[0] = 0;
    }
    else
    {
        bc[0] = 1;
    }
    for (int i = 1; i < n; i++)
    {
        bc[i] = 0;
    }
    for (int i = 0; i < m; i++)
    {
        bc[s[i] - 1] = c[i];
    }

    if (bc[0] == 0 && n != 1)
    {
        goto ERROR;
    }
    for (int i = 0; i < n; i++)
    {
        cout << bc[i];
    }
    cout << endl;

    return 0;
ERROR:
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, i, l, r[200002][3];
    int max = -999999999;
    int min =  999999999;
    int rie = -999999999;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> r[i][0];
        if (r[i][0] < min) {
          r[i][2] = min = r[i][0];
        } else {
          r[i][2] = r[i][0];
        }
    }
    for (i = n-1; i > 0; i--) {
        if (r[i][0] > max) {
          r[i][1] = max = r[i][0];
        } else {
          r[i][1] = max;
        }
        if (rie < r[i][1] - r[i-1][2]) {
          rie = r[i][1] - r[i-1][2];
        }
    }
    cout << rie << endl;
    return 0;
}



Measured memory_bytes: 5456
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int a, b;
    cin >> a >> b;
    int n = b - a, ans = 0;
    for(int i = 1 ; i <= n ; i++){
        ans += i;
    }
    ans -= b;
    cout << ans << endl;
    return 0;
}

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

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

    string s; cin >> s;
    deque<char> deq;
    for (char c : s) deq.push_back(c);

    bool flip = false;
    int q; cin >> q;

    REP(i, q) {
        int t; cin >> t;
        if (t == 1) flip = !flip;
        else {
            int f;
            char c;
            cin >> f >> c;
            if (flip) f = 3 - f;
            if (f == 1) deq.push_front(c);
            else deq.push_back(c);
        }
    }

    if (flip) reverse(deq.begin(), deq.end());
    string ans;
    for (char c : deq) ans += c;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1368
h={}
l=0
n=gets
n=n.split(' ')
n.each{|m|
  h[m]||=0
  if l < m.length then
    l=m.length
    $str=m
  end
  h[m]+=1
}
h.select!{|k,v|v==h.values.max}
print "%s %s\n" %  [h.keys.pop,$str]

Measured memory_bytes: 6104
s = input().strip()

ok_list = ['A', 'T', 'C', 'G']

max_len, i = 0, 0

while i < len(s):
    if s[i] in ok_list:
        l = 0
        while i < len(s) and s[i] in ok_list:
            i += 1
            l += 1

        if l > max_len:
            max_len = l

    else:
         i += 1

print(max_len)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    rep(i, N - 1){
        int num;
        cin >> num;
        A.at(num - 1) += 1;
    }
    rep(i, N){cout << A[i] << endl;}
}

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


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

typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pi           acos(-1)


ll t;
vector<ll>v[100005];



int main()
{
    ll a,b,c,d,e,f,g,i,j;
    string s;
    cin>>s;
    string ss=s;
    reverse(ss.begin(),ss.end());
    a=s.size();
    b=(a-1)/2;
    c=(a+3)/2;
    c--;
    string p=s.substr(0,b);
    string q=p;
    reverse(q.begin(),q.end());
    string m=s.substr(c,a);
    string n=m;
    reverse(n.begin(),n.end());
    if(s==ss&&p==q&&n==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 2560
import math
N, K = list(map(int, input().split()))
res = 0
for i in range(1, min(N + 1, K)):
    res += math.pow(0.5, math.ceil(math.log2(math.ceil(K / i)))) / N
print(f'{res + max(0, (N - K + 1) / N):.10f}')


Measured memory_bytes: 9332
#include<iostream>
#include<algorithm>
using namespace std;
string s,c;
int cnt;
int main(){
    cin>>s;
    int a=s.size();
    for(int i=a-1;i>=0;i--){
      if(s[i]==s[i-1] && s[i]=='B'){
        cnt++;
        continue;
      }
      if(s[i]=='B'){
            i-=cnt+1;
            continue;
        }
        c+=s[i];

    }
    reverse(c.begin(),c.end());
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  ll x;
  cin >> x;
  for(ll a = 0;a<100000;a++){
    for(ll b = -100000; a-b>0; b++){
      ll left = a-b;
      if(x%left > 0) continue;
      ll smallx = x/left;
      //cout << x << " " << smallx << " ";
      ll right = a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b;
      //cout << right << endl;
      if(smallx == right){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
        #define int long long
        using namespace std;
        int pw(int a, int b, int m){
            if (b==0) return 1;
            if (b==1) return a%m;
            if (b%2){
                return (pw(a, b-1, m) * a)%m;
            }
            int rs = pw(a, b/2, m);
            return (rs*rs)%m;
        }
        signed main(){
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            int n, k, m;
            cin >> n >> k >> m;
            int dp[n+1];
            for (int i=0; i <= n; i++) dp[i] = 0;
            dp[0] = 1;
            int dyr[n+1][n+1];
            for (int i=1; i <= n; i++){
                for (int j=0; j <= n; j++){
                    dyr[i][j] = 0;
                    dyr[0][j] = 1;
                }
            }
            int st[4*n][4*n];
           for (int i=0; i < 4*n; i++) for (int j=0; j < 4*n; j++) st[i][j] = pw(i, j, m);
            for (int i=1; i <= n; i++){
                for (int j=0; j <= n; j++){
                    for (int p=j; p <= n; p++){
                        dyr[i][p] += dyr[i-1][j] * st[i+1][p-j];
                        dyr[i][p] %= m;
                    }
                }
            }
            for (int i=0; i < k; i++){
                int dp2[n+1];
                for (int j=0; j <= n; j++) dp2[j] = 0;
                for (int j=0; j <= n; j++){
                    for (int p=j; p <= n; p++){
                        dp2[p] += dyr[j][p-j] * dp[j];
                        dp2[p] %= m;
                    }
                }
                for (int j=0; j <= n; j++) dp[j] = dp2[j];
            }
             cout << dp[n]  << endl;
        }

Measured memory_bytes: 12160
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

struct RollingHash {
	static const int base1 = 1007, base2 = 2009;
	static const int mod1 = 1000000007, mod2 = 1000000009;
	vector<long long> hash1, hash2, power1, power2;

	// construct
	RollingHash(const string& S) {
		int n = (int)S.size();
		hash1.assign(n + 1, 0);
		hash2.assign(n + 1, 0);
		power1.assign(n + 1, 1);
		power2.assign(n + 1, 1);
		for (int i = 0; i < n; ++i) {
			hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
			hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
			power1[i + 1] = (power1[i] * base1) % mod1;
			power2[i + 1] = (power2[i] * base2) % mod2;
		}
	}

	// get hash of S[left:right]
	inline pair<long long, long long> get(int l, int r) const {
		long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
		if (res1 < 0) res1 += mod1;
		long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
		if (res2 < 0) res2 += mod2;
		return { res1, res2 };
	}

	// get lcp of S[a:] and T[b:]
	inline int getLCP(int a, int b) const {
		int len = min((int)hash1.size() - a, (int)hash1.size() - b);
		int low = 0, high = len;
		while (high - low > 1) {
			int mid = (low + high) >> 1;
			if (get(a, a + mid) != get(b, b + mid)) high = mid;
			else low = mid;
		}
		return low;
	}
};


ll n, m[210000], q[210000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	string s[40][2], t[40];
	REP(i, n) {
		ll x;
		cin >> x;
		REP(j, 32) {
			if (x & (1ll << j)) {
				s[j][0].push_back('1');
				s[j][1].push_back('0');
			}
			else {
				s[j][0].push_back('0');
				s[j][1].push_back('1');
			}
		}
	}
	REP(i, n) {
		ll x;
		cin >> x;
		REP(j, 32) {
			if (x & (1ll << j)) t[j].push_back('1');
			else t[j].push_back('0');
		}
	}
	REP(i, 32) {
		REP(j, 2) {
			s[i][j] += s[i][j];
			s[i][j].pop_back();
		}
	}
	REP(i, 32) {
		REP(j, 2) {
			RollingHash a(s[i][j]), b(t[i]);
			REP(k, (ll)s[i][j].size() - (ll)t[i].size() + 1) {
				if (a.get(k, k + t[i].size()) == b.get(0, t[i].size())) {
					m[k]++;
					if (j == 1) q[k] += (1ll << i);
				}
			}
		}
	}
	REP(i, n) {
		if (m[i] >= 32) {
			cout << i << " " << q[i] << endl;
		}
	}
}



Measured memory_bytes: 57472
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    """
    条件成立＝（２進数表示した時に各桁に１が高々1つしか登場しない）
    なので尺取り法でいけそう
    """
    left = 0
    right = 1
    bit = {i for i in range(20) if A[0] & (1 << i)}

    ans = 0
    while right <= N:
        #print("[{}, {}) -> {}".format(left, right, right - left))
        ans += right - left
        if right == N:
            print(ans)
            return

        bit_right = {i for i in range(20) if A[right] & (1 << i)}
        while bit & bit_right:
            bit_left = {i for i in range(20) if A[left] & (1 << i)}
            bit -= bit_left
            left += 1
        bit |= bit_right
        right += 1



if __name__ == "__main__":
    main()


Measured memory_bytes: 100672
#include <bits/stdc++.h>
using namespace std;
int calculateStamina(vector<int> v,int P){
    int totalStamina = 0;
    for(int i=0;i<v.size();i++){
        totalStamina += pow(v[i] - P,2);
    }
    return totalStamina;
}
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int minElement = *min_element(v.begin(),v.end());
    int maxElement = *max_element(v.begin(),v.end());
    int minStamina = INT_MAX;
    for(int i=minElement;i<=maxElement;i++){
        int currStamina = calculateStamina(v,i);
        if(currStamina < minStamina){
            minStamina = currStamina;
        }
    }
    cout<<minStamina<<endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n;
    while(1){
        cin>>n;
        if(n==0)return 0;
        vector<int> V(n);
        for(int i=0;i<n;i++)cin>>V[i];
        sort(V.begin(),V.end());
        int sum=0;
        for(int i=1;i<n-1;i++)sum+=V[i];
        cout<<sum/(n-2)<<endl;
    }
}

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


int main() {
  int n, x;
  cin >> n >> x;
  int d = 0, ans = 1;
  rep(i,n) {
    int l;
    cin >> l;
    d += l;
    if(d <= x) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vec a(n);
  vec b(n);
  loop(i,n)cin>>a[i]>>b[i];
  pair<ll,ll> itv[n];
  loop(i,n){
    itv[i].first=b[i];
    itv[i].second=a[i];
  }
  sort(itv,itv+n);
  loop(i,n){
    b[i]=itv[i].first;
    a[i]=itv[i].second;
  }
  ll time=0;
  bool ans=true;
  loop(i,n){
    time+=a[i];
    if(time>b[i])ans=false;
  }
  if(ans)putout("Yes");
  else putout("No");
}

Measured memory_bytes: 6528
// j;main(i){for(;9/i;i+=!(j%=9))printf("%dx%d=%d\n",i,j,++j*i);}

// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?log10(a+b)+1:1.));}
k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?floor(log10(a+b))+1:1.));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",a+b?(int)log10(a+b)+1:1));}


// #include <stdio.h>
 
// int main( void ) {
//     int a, b, d, tmp;
 
//     for ( ; scanf( "%d %d", &a, &b ) == 2; printf( "%d\n", d ) ) {
//         tmp = a + b;
//         for ( d = 1; tmp /= 10; d++ ) ;
//     }
 
//     return 0;
// }

// main(i,a,t,p,j){for(;~scanf("%d",&t)?i++<4?t<p?p=t:1:t<j?j=t:1:!printf("%d\n",p+j-50););}




// double a,b,c,d;i;main(){scanf("%lf%lf%lf%lf",&a,&b,&c,&d);i=!printf("%f\n",hypot(a-c,b-d));}
// double c[4];i;main(){for(;~scanf("%lf",c+i++););i=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double c[4],*p=c;i;main(){for(;~scanf("%lf",p++););i=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double c[],*p=c;main(){for(;~scanf("%lf",p++););p=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double a,b,c,d,*p=&d;main(){for(;~scanf("%lf",p++););p=!printf("%f\n",hypot(d-c,b-a));}




// s,n,i;main(x,y){for(;~scanf("%d,%d",&x,&y)?s+=x*y:!printf("%d\n%.f\n",s,.5+1.*n/i);i++)n+=y;}


// L;main(A,B,C,D){scanf("%d%d%d%d%d",&L,&A,&B,&C,&D);L=!printf("%.f\n",L-fmax(--A/C,--B/D)-1);}
// a,b,c,d,e,*p=&d;main(){for(;~scanf("%d",p++););p=!printf("%.f\n",d-fmax(--b/c,--e/a)-1);}



// char c[];p;main(t){for(;gets(c)**c;p=!puts(strncat(c,c,p%=strlen(c))+p))for(gets(&t);scanf("%d ",&t);p+=t);}

Measured memory_bytes: 676
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;
#define ll long long
typedef long long LL;
int main()
{
    ll dp[110000];
    ll a[110000];
    ll n,x,b;
    cin>>n>>x>>b;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    dp[1]=0;
    a[0]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+(a[i]-a[i-1])*x,dp[i-1]+b);
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1792
MOD = 998244353

def print_dp(dp, c):
    for i in range(1, c+1):
        print(dp[i][1:])

def main():
    a, b, c, d = map(int, input().split())
    dp = [[0]*(d+1) for _ in range(c+1)]
    t = [[0]*(d+1) for _ in range(c+1)]
    dp[a][b] = 1
    for i in range(a, c+1):
        for j in range(b, d+1):
            dp[i][j] += dp[i-1][j]*j
            dp[i][j] += dp[i][j-1]*i
            dp[i][j] -= t[i][j-1] * (i-1)
            dp[i][j] %= MOD
            t[i][j] += dp[i-1][j]*j
            t[i][j] %= MOD
    print(dp[c][d])

if __name__ == "__main__":
    main()

Measured memory_bytes: 209364
N, M = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
y = [list(map(int, input().split())) for _ in range(M)]
for a,b in x:
    z = [abs(a-c) + abs(b-d) for c,d in y]
    print(z.index(min(z))+1)

Measured memory_bytes: 9072
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

//   a/b mod c
ll moddiv(ll a,ll b){
	ll x0=MOD,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%MOD;
      if (x2==1){
        ans=(n2+MOD)%MOD;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%MOD)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1) ans=ans*aa%MOD;
    aa=aa*aa%MOD;
    beki/=2;
    if (beki==0)break;
  }
  return ans;
}



int main(){
  ll ans=1;
  cin >> x >> y;
  if ((x+y)%3!=0){
    cout<<0<<endl;
    return 0;
  }

  if ((x*2<y)|(y*2<x)){
    cout<<0<<endl;
    return 0;
  }

  ll xx=(x+y)/3;
  xx=x-xx;
  n=(x+y)/3;
  k=n;
  for(ll i=1;i<=xx;i++){
    ans=ans*k%MOD;
    //ans/=i
    ans=moddiv(ans,i);
    k--;
  }



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

Measured memory_bytes: 256
n = int(input())
s = input()
t = s
counter = 0  # 左:+1 右:-1 最終的に0にしたい
# "("の手前の"）"のインデックスでcounterが負の場合にその数ぶん左に"("を足す
# 最終的にcounterが0でない場合、その数ぶんを左右どちらかに足す

before = ""
i = 0
while i < n:
    if s[i] == "(":
        if i > 0 and before == ")":
            if counter < 0:
                t = "(" * (-counter) + t
                counter = 0
        counter += 1
        before = "("
    else:
        counter -= 1
        before = ")"
    i += 1
if counter > 0:
    t += ")" * (counter)
elif counter < 0:
    t = "(" * (-counter) + t
print(t)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    int a[M];
    int high = 0;
    int low = 0;
    for(int i = 0; i < M; i++){
        cin >> a[i];
        if(a[i] > X) high++;
        else low++;
    }
    cout << min(high, low) << endl;

    return 0;
}

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

int main() {
	long long N;
	long long A, B;
	cin >> N >> A >> B;
	long long C = N / (A + B);
	long long D = N % (A + B);
	long long ans = C * A;
	if (D < A) ans += D;
	else ans += A;
	cout << ans;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i=0; i<n; i++){
    cin >> h.at(i);
  }
  sort (h.begin(), h.end());
  int ans = h.at(k-1) - h.at(0);
  for (int i=1; i<=n-k; i++){
    int diff = h.at(i+k-1) - h.at(i);
    if (diff < ans){
      ans = diff;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int num = 0;
    while (true) {
        num++;
        if (num * Y + (num + 1) * Z > X) {
            break;
        }
    }
    cout << num - 1 << endl;
}


Measured memory_bytes: 256