akhauriyash/Code-Regression huggingface dataset:
// ABC 076 B- Addition and Multiplication

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

int main() {
  int N, K;
  cin >> N >> K;

  int j = 1;
  rep(i, N) {
    if (j * 2 < j + K) {
      j *= 2;
    }
    else {
      j += K;
    }
  }
  cout << j << endl;
}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while(A > 0 || C > 0){
    C -= B;
    
    if(C <= 0){
      cout << "Yes" <<endl;
      break;
    }
    
    A -= D;
    
    if(A <= 0){
      cout << "No" <<endl;
      break;
    }
  }
}


  


Measured memory_bytes: 3652
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    N,M = isRaw()
    As = isRaw()
    sAs = sum(As)
    if sAs > N:
        return -1
    
    ans = N-sAs
    return ans

if __name__ == "__main__":
    print(main())


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

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  int dx = tx - sx;
  int dy = ty - sy;
  
  rep(i, dx) {
    cout << "R";
  }

  rep(i, dy) {
    cout << "U";
  }

  rep(i, dx) {
    cout << "L";
  }

  rep(i, dy) {
    cout << "D";
  }
  cout << "D";
  rep(i, dx + 1) {
    cout << "R";
  }

  rep(i, dy + 1) {
    cout << "U";
  }
  
  cout << "LU";

  rep(i, dx + 1) {
    cout << "L";
  }

  rep(i, dy + 1) {
    cout << "D";
  }
  
  cout << "R";

  
}


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

int main() {
    string s, t;
    cin >> s >> t;
    puts(s == t.substr(0, t.size() - 1) ? "Yes" : "No");
}

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

int main() {
  char X, Y;
  cin >> X >> Y;
  
  if ( X > Y ) {
    cout << ">" << endl;
  }
  else if ( X == Y ) {
    cout << "=" << endl;
  }
  else {
    cout << "<" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#define BOTTOM 0
#define LEFT 1
#define RIGHT 2
#define TOP 3
using namespace std;
 
class P{
public:
    int x,y;
    P(int xx=0,int yy=0){
        x=xx;
        y=yy;
    }
};
 
class Segment{
public:
    P p1,p2;
    Segment(P pp1=P(),P pp2=P()){
        p1=pp1;
        p2=pp2;
    }
};
 
class EndPoint{
public:
    P p;
    int seg,st;
    EndPoint(){}
    EndPoint(P pp,int segg,int stt){
        p=pp;
        seg=segg;
        st=stt;
    }
 
    bool operator <(const EndPoint &ep)const{
        if(p.y==ep.p.y){
            return st<ep.st;
        }
        return p.y<ep.p.y;
    }
};
 
EndPoint EP[2000000];
 
int manhattanIntersection(vector<Segment> S){
    int n=S.size();
    for(int i=0,k=0;i<n;i++){
        if(S[i].p1.y==S[i].p2.y){
            if(S[i].p1.x>S[i].p2.x)swap(S[i].p1,S[i].p2);
        }else if(S[i].p1.y>S[i].p2.y)swap(S[i].p1,S[i].p2);
        if(S[i].p1.y==S[i].p2.y){
            EP[k++]=EndPoint(S[i].p1,i,LEFT);
            EP[k++]=EndPoint(S[i].p2,i,RIGHT);
        }else{
            EP[k++]=EndPoint(S[i].p1,i,BOTTOM);
            EP[k++]=EndPoint(S[i].p2,i,TOP);
        }
    }
    sort(EP,EP+(2*n));
    set<int> BT;
    BT.insert(1000000001);
    int cnt=0;
    for(int i=0;i<2*n;i++){
        if(EP[i].st==TOP){
            BT.erase(EP[i].p.x);
        }else if(EP[i].st==BOTTOM){
            BT.insert(EP[i].p.x);
        }else if(EP[i].st==LEFT){
            set<int>::iterator b=lower_bound(BT.begin(),BT.end(),S[EP[i].seg].p1.x);
            set<int>::iterator e=upper_bound(BT.begin(),BT.end(),S[EP[i].seg].p2.x);
            cnt+=distance(b,e);
        }
    }
    return cnt;
}
 
int main(void){
    int n;
    vector<Segment> ss;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        Segment s;
        scanf("%d %d",&s.p1.x,&s.p1.y);
        scanf("%d %d",&s.p2.x,&s.p2.y);
        ss.push_back(s);
    }
    printf("%d\n",manhattanIntersection(ss));
    return 0;
}


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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;

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

	while(n > 0){
		n -= 1000;
	}

	cout << abs(n) << endl;

	return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	int N;
	cin >> N;
	vector<int>a(N);
	rep(i, N)cin >> a[i];
	int ans = 0;
	rep(i, N)while (a[i] % 2 == 0) {
		ans++;
		a[i] /= 2;
	}
	cout << ans << endl;



	return 0;
}



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

const int Maxn = 105;

int n;
int a[Maxn];
int res;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i + 1 < n; i++)
		if (a[i] == a[i + 1]) {
			res++; i++;
		}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto w = readln.chomp;
  auto a = new int[](26);
  foreach (c; w) ++a[cast(int)(c - 'a')];
  writeln(a.all!(ai => ai % 2 == 0) ? "Yes" : "No");
}


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

using namespace std;

using int64 = long long;
const int mod = 1000003;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

template <typename T = int64>
vector<T> make_v(size_t a) {
  return vector<T>(a);
}

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

template <typename F>
struct FixPoint : F {
  FixPoint(F &&f) : F(forward<F>(f)) {}

  template <typename... Args>
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};

template <typename F>
inline decltype(auto) MFP(F &&f) {
  return FixPoint<F>{forward<F>(f)};
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  cin >> A;

  for (int i = 0; i < N; i++) {
    if (A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }

  cout << "APPROVED" << endl;
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define point pair<double,double>
#define segment pair<point,point>
#define circle pair<point,double> //titik pusat, radius
#define line pair<double,double> //m,c
#define ins insert
#define er erase
#define pss pair<string,string>

const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 1e9+7;

#define yu using
#define don namespace
#define sei std

yu don sei;

int n;
string s,s1,s2;

map<pss,ll> M1;
map<pss,ll> M2;

void brute1(int idx,string a,string b)
{
	if(idx==n)
	{
		M1[mp(a,b)]++;
		return;
	}
	brute1(idx+1,a+s1[idx],b);
	brute1(idx+1,a,b+s1[idx]);
	return;
}

void brute2(int idx,string a,string b)
{
	if(idx==n)
	{
		M2[mp(a,b)]++;
		return;
	}
	brute2(idx+1,a+s2[idx],b);
	brute2(idx+1,a,b+s2[idx]);
	return;
}

int main()
{
	cin>>n;
	cin>>s;
	s1=s.substr(0,n);
	s2=s.substr(n,n);
	// cout<<s1<<" "<<s2<<endl;
	brute1(0,"","");
	brute2(0,"","");
	ll ans=0;
	for(auto x:M1)
	{
		string ss1=x.fi.fi;
		string ss2=x.fi.se;
		reverse(ss1.begin(),ss1.end());
		reverse(ss2.begin(),ss2.end());
		pss pas=mp(ss1,ss2);
		// cout<<x.fi.fi<<" "<<x.fi.se<<" "<<ss1<<" "<<ss2<<endl;
		if(M2.count(pas)==1)
		{
			ans+=x.se*M2[pas];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 87808
#include <bits/stdc++.h>
using namespace std;
#define For(i, n) for(int i = 0; i < (n); i ++)
void revsort(vector<long> &vec){
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

}
int main(void){
    int X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    vector<long> A(X);
    vector<long> B(Y);
    vector<long> C(Z);
    vector<long> vec;
    For(i,X){
        cin>>A.at(i);
    }
    For(i,Y){
        cin>>B.at(i);
    }
    For(i,Z){
        cin>>C.at(i);
    }
    revsort(A);
    revsort(B);
    revsort(C);
    For(i,X){
        For(j,Y){
            For(k,Z){
                if((i+1)*(j+1)*(k+1)<=K){
                    vec.push_back(A.at(i)+B.at(j)+C.at(k));
                }
                else{
                    break;
                }
            }
        }
    }
    revsort(vec);
    For(i,K){
        cout<<vec.at(i)<<endl;
    }
}


Measured memory_bytes: 1404
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

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

int main(){
	int N;cin>>N;
	vector<int> slime(N);
	rep(i,N)cin>>slime[i];
	vector<vector<ll>> dp(N,vector<ll> (N,INF));
	vector<vector<ll>> cost(N,vector<ll> (N,INF));
	rep(i, N)cost[i][i] = slime[i];
	for(int i = 1; i<N; ++i){
		int l = 0, r = i;
		for(int _ = 0; _<N-i; ++_){
			for(int k = l; k<r; ++k){
				chmin(cost[l][r], cost[l][k] + cost[k+1][r]);
			}
			++l; ++r;
		}
	}
	rep(i,N)dp[i][i] = 0;
	for(int i = 1; i<N; ++i){
		int l = 0, r = i;
		for(int _ = 0; _<N-i; ++_){
			for(int k = l; k<r; ++k){
				chmin(dp[l][r], dp[l][k] + dp[k+1][r] + cost[l][r]);
			}
			++l; ++r;
		}
	}
	cout<<dp[0][N-1]<<endl;
	return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    ll N;
    cin >> N;
    string S[N]; ll P[N], ans[N];
    for(int i = 0; i < N; i++){
        cin >> S[i] >> P[i];
        ans[i] = i + 1;
        for(int j = 0; j < i; j++){
            if(S[i] < S[j] || (S[i] == S[j] && P[i] > P[j])){
                swap(S[i], S[j]);
                swap(P[i], P[j]);
                swap(ans[i], ans[j]);
            }
        }
    }
    for(int i = 0; i < N; i++)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush,heappop

n,m,s,t=map(int,input().split())
INF=10**20
G1,G2 = [{} for _ in range(n)],[{} for _ in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  G1[u-1][v-1] = G1[v-1][u-1] = a
  G2[u-1][v-1] = G2[v-1][u-1] = b
  
def dijkstra(G,start = 0):
    d = [INF for i in range(len(G))]
    d[start] = 0
    que = []
    heappush(que, (0, start))

    while len(que):
        p = heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for u in G[v].keys():
            if d[u] > d[v] + G[v][u]:
                d[u] = d[v] + G[v][u]
                heappush(que, (d[u], u))
    return d
  
d1 = dijkstra(G1,s-1)
d2 = dijkstra(G2,t-1)

ans=[]
MIN = INF
for i in range(n-1,-1,-1):
  MIN = min(MIN,d1[i]+d2[i])
  if i == s-1:
    MIN = min(MIN,d2[s-1])
  if i == t-1:
    MIN = min(MIN,d1[t-1])
    
  ans.append(MIN)
  
print(*[10**15-ans[-i-1] for i in range(n)])

Measured memory_bytes: 98432
import collections
import sys
input = sys.stdin.readline
n=int(input())
E=[[] for i in range(n)]
EE=[]
P=collections.defaultdict(int)
for i in range(n-1):
  a,b=map(int,input().split())
  E[a-1]+=[b-1]
  E[b-1]+=[a-1]
  EE.append([a,b])
  P[a-1]+=1
  P[b-1]+=1
C=[int(i) for i in input().split()]
C.sort(reverse=True)
P=sorted(P.items(), key=lambda x:x[1],reverse=True)
CC=[0]*n
stack=[P[0][0]]
CC[P[0][0]]=C[0]
ct_p,ct_c=1,1
while stack:
  label=stack.pop(-1)
  for i in E[label]:
    if CC[i]==0:
      CC[i]=C[ct_c]
      ct_c+=1
      stack+=[i]
ans=0
for i in range(n-1):
  a,b=EE[i][0],EE[i][1]
  ans+=min(CC[a-1],CC[b-1])
print(ans)
print(*CC)


Measured memory_bytes: 8868
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int N = sc.nextInt();
        int x=0;
        int s,f;
        
        for(int i=0;i<N;i++){
        	s = sc.nextInt();
        	f = sc.nextInt();
        	if((b>s) && (f>a)){
        		System.out.println(1);
        		x =1;
        		return;
        	}
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 26324
#include <iostream>
#include <algorithm>
#include <cmath>

int main(){
    // 元値:moto_A, moto_B
    // 建前としてmoto_A = moto_Bになるはず
    // rounddown( moto_A * 0.08 ) = A
    // moto_A * 0.08 = A + a(任意の1未満の数字)
    //  a = 0
    //   moto_A = A / 0.08
    //  a = 0.999999...
    //   moto_A = A / 0.08 + a / 0.08
    //          = A / 0.08 + 12.499...
    //  A / 0.08 <= moto_A < A / 0.08 + 12.5
    // moto_B * 0.10 = B + b(任意の1未満の数字)
    //   b = 0.999...
    //    moto_B = B / 0.10 + b / 0.10
    //           = B / 0.10 + 9.999...
    //  B / 0.10 <= moto_B < B / 0.10 + 10

    int input_A, input_B;
    std::cin >> input_A >> input_B;

    int moto_A_min, moto_A_max, moto_B_min, moto_B_max, moto;

    moto_A_min = std::ceil((double)input_A/0.08);
    moto_A_max = std::floor((double)input_A/0.08 + 12.4999);
    moto_B_min = std::ceil((double)input_B/0.10);
    moto_B_max = std::floor((double)input_B/0.10 + 9.999);

    // printf("%d %d %d %d\n", moto_A_min, moto_A_max, moto_B_min, moto_B_max);

    if( moto_A_min > moto_B_max || moto_A_max < moto_B_min ){
        printf("-1");
    }else{
        printf("%d", std::max( moto_A_min, moto_B_min ));
    }

    return(0);
}

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

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

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

/*
両端が同じ文字
  偶数：先手の勝ち
違う場合
  偶数：後手の勝ち
*/

string s;

int main(){
  cin >> s;
  if(s[0] == s[s.size()-1]){
    if(s.size()%2==1) cout << "Second"<<endl;
    else cout << "First" <<endl;
  }else{
    if(s.size()%2==0) cout << "Second" <<endl;
    else cout << "First" <<endl;
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  ll n; cin >> n;
  set<string> s;
  rep(i,n){
    string str; cin >> str;
    s.insert(str);
  }

  cout << s.size() << endl;

}

Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
int32_t main()
{
 	fast;
 	int n;
 	cin>>n;
 	int ans=(n/500)*1000;
 	int re=n-(n/500)*500;
 	ans+=(re/5)*5;
 	cout<<ans;

}       
      

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

using grid = pair<int, int>;

int func(const vector<grid> &p, const vector<grid> &q) {
  auto ip = p.begin();
  auto iq = q.begin();
  int ans = INT_MAX / 10;
  while (ip != p.end() && iq != q.end()) {
    if ((*ip).first > (*iq).first)
      ++iq;
    else if ((*ip).first < (*iq).first)
      ++ip;
    else {
      if ((*ip).second < (*iq).second) {
        ans = min(ans, (*iq).second - (*ip).second);
        ++ip;
      } else {
        ++iq;
      }
    }
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  vector<grid> u;
  vector<grid> d;
  vector<grid> r;
  vector<grid> l;

  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    char dir;
    cin >> dir;
    if (dir == 'U') {
      u.push_back(make_pair(x, y));
    } else if (dir == 'D') {
      d.push_back(make_pair(x, y));
    } else if (dir == 'R') {
      r.push_back(make_pair(y, x));
    } else if (dir == 'L') {
      l.push_back(make_pair(y, x));
    }
  }

  sort(u.begin(), u.end());
  sort(d.begin(), d.end());
  sort(r.begin(), r.end());
  sort(l.begin(), l.end());
  int ans = INT_MAX;
  ans = min(ans, func(u, d) * 5);
  ans = min(ans, func(r, l) * 5);

  auto f1 = [](vector<grid> &p) {
    for (auto &[x, y] : p) {
      swap(x, y);
    }
  };
  auto f2 = [](vector<grid> &p) {
    for (auto &[y, x] : p) {
      y += x;
    }
  };
  f1(u);
  f1(d);
  f2(u);
  f2(d);
  f2(r);
  f2(l);
  sort(u.begin(), u.end());
  sort(d.begin(), d.end());
  sort(r.begin(), r.end());
  sort(l.begin(), l.end());
  ans = min(ans, func(r, u) * 10);
  ans = min(ans, func(d, l) * 10);
  auto f3 = [](vector<grid> &p) {
    for (auto &[xy, x] : p) {
      xy -= 2 * x;
    }
  };
  f3(u);
  f3(d);
  f3(r);
  f3(l);
  sort(u.begin(), u.end());
  sort(d.begin(), d.end());
  sort(r.begin(), r.end());
  sort(l.begin(), l.end());
  ans = min(ans, func(u, l) * 10);
  ans = min(ans, func(r, d) * 10);

  if (ans > INT_MAX / 10)
    cout << "SAFE" << endl;
  else
    cout << ans << endl;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  int a[n+1];

  for(int i=1;i<=n;i++) cin>>a[i];

  for(int i=1;i<=n-k;i++){
    if(a[i+k]>a[i]) cout<<"Yes"<<endl;
    else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 4408
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os, zlib, base64
    open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${rgL2iRE5WFMthrP7HjT3>?N)<}_ku(Re4Xo<ei7_PoeeIYAr>Re7X4svbbz}4a*thMpS|2M@Nhu^SJRG&La5R-_MVd5TB(Y}e-g4A8z7>{rm7z|E$~I}jxM)CX)$ZPMcZxmm33R;sO=Sd>Zc&zL0`A<XngW9@<N-c+C<PRg$e-GgQ@4!FFgA|a!0USnwGq|V%=l^yUZBWf=`<^+38WErFbde@Yt+c0;ym*%kY3GP?o9?a2%9aa$P(Y-9+q3UM0Wf)!ZWNe$^!b~5X%2Ed=UH{9pMA=s8{a``-X9^)!Zu@td9a$J_H{+h0}a>Q(6iGg)vReXuCU8jW(_-s%iI`B4voj#aPf#g8VN%k;t+A?KeZiBQ!ojZl$)I9#pn?lKfLG=rzKTxHbCAKq9@6y$BYEU~zQh52KB`-v")))
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 12956
n = int(input())
if n <= 599:
    print(8)
elif n <= 799:
    print(7)
elif n <= 999:
    print(6)
elif n <= 1199:
    print(5)
elif n <= 1399:
    print(4)
elif n <= 1599:
    print(3)
elif n <= 1799:
    print(2)
else:
    print(1)


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

using ll = long long;
#define f first
#define s second

#ifndef LOCAL
	#define cerr if(0) cerr
#endif

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	
	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	for (int& x : a)
		cin >> x;
	sort(a.begin(), a.end());
	
	int sum = 0;
	for (int i = 0; i < k; ++i) {
		sum += a[i];
	}
	cout << sum << "\n";
	// you should actually read the stuff at the bottom
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smthn instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[20][100010];
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll w;
    cin >> w;
    vector<ll> weight(1, 1);
    for (ll i = 6; i <= w; i *= 6)
    {
        weight.emplace_back(i);
    }
    for (ll i = 9; i <= w; i *= 9)
    {
        weight.emplace_back(i);
    }
    ll n = (ll)weight.size();
    for (ll i = 0; i < 20; i++)
    {
        for (ll j = 0; j < 100010; j++)
        {
            dp[i][j] = 1LL << 60;
        }
    }
    for (ll i = 0; i <= n; i++)
    {
        dp[i][0] = 0;
    }
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j <= w; j++)
        {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if (j >= weight[i])
                dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - weight[i]] + 1);
        }
    }

    cout << dp[n][w] << endl;
}

Measured memory_bytes: 15872
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
xyh = [LIST() for _ in range(N)]

for x, y, h in xyh:
	if h >= 1:
		tmp = (x, y, h)

for i in range(101):
	for j in range(101):
		x_, y_, h_ = tmp
		H = h_ + abs(i-x_) + abs(j-y_)

		for x, y, h in xyh:
			if max(H-abs(x-i)-abs(y-j), 0) != h:
				break
		else:
			print(i, j, H)
			exit()


Measured memory_bytes: 5200
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int count=0;
  
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==n){
        count++;
      }
    }
  }
  
  if(count==0){
    printf("No");
  }else{
    printf("Yes");
  }
  
  return 0;
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
//const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int n, k;
    cin >> n >> k;
    
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    int ans = 1e12;
    
    bitset<20> b;
    for(int bi = 0; bi < (1 << n); ++bi) {
        b = bi;
        if(b.count() < k) continue;
        auto t = a;
        int max_h = 0;
        
        for(int i = 0; i < n; ++i) {
            if(b[i]) {
                t[i] = max(t[i], max_h + 1);
            }
            max_h = max(max_h, t[i]);
        }
        
        int cost = 0;
        rep(i,n) cost += t[i] - a[i];
        ans = min(ans, cost);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int MOD = 1e9+7;
const int INF = 1e9;
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif


int main() {
  string s, t;
  cin >> s >> t;
  int N, M; cin >> N >> M;

  string u; cin >> u;

  if (u == s)
    --N;
  else
    --M;
  cout << N << " " << M <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string as = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string ab = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------

int main() {

  ll n, k;
  cin >> n >> k;

  ll x = n%k;

  if(x==0) {
    cout << 0 << endl;
  }else {
    if(n<(-1)*(x-k)) {
      cout << n << endl;
    }else {
      cout << (-1)*(x-k) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100001
int p[N];int r[N];int f(int x){if(p[x]==x){return x;}return p[x]=f(p[x]);}int u(int x,int y){x=f(x);y=f(y);if(r[x]<r[y]){p[x]=y;r[y]+=r[x];}else {p[y]=x;r[x]+=r[y];}}int main(){long n,m,i,b[N],a[N][2];scanf("%ld%ld",&n,&m);for(i=0;i<m;i++)scanf("%d%d",&a[i][0],&a[i][1]);b[m]=(long long)n*(n-1)/2;for(i=0;i<N;i++){p[i]=i;r[i]=1;};for(i=m-1;i>=0;i--){if(f(a[i][0])==f(a[i][1]))b[i]=b[i+1];else{b[i]=b[i+1]-(long)r[f(a[i][0])]*r[f(a[i][1])];u(a[i][0],a[i][1]);}}for(i=1;i<=m;i++)printf("%ld\n",b[i]);return 0;}

Measured memory_bytes: 4352
//
// Created by Naman Bhalla on 2019-08-18.
//

#include <bits/stdc++.h>

using namespace std;

int ctr[200005];
long long int val[200005];
bool vis[200005];

void dfs(int node, vector< vector< int > > &ad_l, long long int csum){
    csum += ctr[node];
    val[node] = csum;

    for(auto nd: ad_l[node]){
        if(!vis[nd]){
            vis[nd] = true;
            dfs(nd, ad_l, csum);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, q;
    cin >> n >> q;

    vector< vector< int > > ad_l(n + 1);

    int a, b;

    for(int i = 1; i < n; ++i){
        cin >> a >> b;

        ad_l[a].push_back(b);
        ad_l[b].push_back(a);
    }

    memset(ctr, 0, sizeof ctr);

    for(int i = 1; i <= q; ++i){
        cin >> a >> b;
        ctr[a] += b;
    }

    memset(vis, 0, sizeof vis);
    memset(val, 0, sizeof val);

    vis[1] = true;
    dfs(1, ad_l, 0);

    for(int i = 1; i <= n; ++i){
        cout << val[i] << " ";
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 25216
//https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_E

#include <bits/stdc++.h>

using namespace std;

long long MOD = 1e9 + 7;

long long f[1010][1010];

int main() {
    long long n;//ボール
    long long k;//箱
    cin >> n >> k;

    for (int i = 0; i <= k; ++i) {
        f[i][0] = 1;
        f[i][i] = 1;
    }

    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= n; ++j) {
            f[i][j] = (f[i - 1][j - 1] + f[i - 1][j] + MOD) % MOD;
        }
    }

    cout << f[k][n] << endl;
    return 0;
}

/*
 * どの箱にボールを入れるかだけ考えればいい。
 * B(k,n)
 * 普段使ってる二項係数の関数を使って
 * cout << binomial(k, n, MOD) << endl;
 * としたらREを食らってしまった。
 * ちなみにbinomial(1000,500)は300桁。
 *
 */


Measured memory_bytes: 10992
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

enum Type{
	from_S,
	from_T,
};

int N;
int dist[2][SIZE];
vector<int> G[SIZE];

void dfs(Type type,int node_id,int pre,int D){

	dist[type][node_id]= D;

	for(int i = 0; i < G[node_id].size(); i++){

		if(G[node_id][i] == pre)continue;

		dfs(type,G[node_id][i],node_id,D+1);
	}
}

int main(){

	scanf("%d",&N);

	int from,to;

	for(int i = 0; i < N-1; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(to);
		G[to].push_back(from);
	}

	dfs(from_S,0,-1,0);
	dfs(from_T,N-1,-1,0);

	int num_S = 0,num_T = 0;

	for(int i = 0; i < N; i++){

		if(dist[from_S][i] <= dist[from_T][i]){

			num_S++;
		}else{

			num_T++;
		}
	}

	if(num_S > num_T){

		printf("Fennec\n");

	}else{

		printf("Snuke\n");
	}

	return 0;
}


Measured memory_bytes: 16088
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>
#define all(n) n.begin(),n.end()
#define forr(i,a,b) for(i=a;i<b;i++)
#define forrr(i,a,b) for(i=b-1;i>=a;i--)


 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fast;
    ll t;
    t=1;
    while(t--){
      ll n;
      cin>>n;
      cout<<(n==1?0:1)<<endl;

            




    }
    
return 0;    
 }  

Measured memory_bytes: 3644
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;



signed main() {
int ans,D,N;
cin >> D >> N;
if(D==0){
ans=N;
}
ans = pow(100,D) *N;
if(N==100){
    ans = pow(100,D) *(N+1);
} 
answer(ans);
return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

int main()
{
	string s;
	cin >> s;
	vector<int> alp(26);
	int n = s.size();
	string extract = "";
	deque<int> xcnt;
	int cnt = 0;
	rep(i, n)
	{
		if (s[i] != 'x')
		{
			extract.push_back(s[i]);
			xcnt.push_back(cnt);
			cnt = 0;
		}
		else
		{
			cnt++;
		}
	}

	xcnt.push_back(cnt);

	bool ok = true;
	int m = extract.size();

	rep(i, extract.size() / 2)
	{
		if (extract[i] != extract[m - 1 - i])
		{
			ok = false;
		}
	}
	if (ok)
	{
		
			int ans = 0;
			m = xcnt.size();
			rep(i, m / 2)
			{
				ans +=abs(xcnt[i]-xcnt[m - 1 - i]);
			}
			cout << ans << endl;
		
	}
	else
	{
		cout << -1 << endl;
	}
}


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

typedef pair<int, int> Pair;
struct Edge {
  int v;
  Pair w;
  bool operator < (const Edge &e) const {
    return w > e.w;
  }
};

typedef vector<vector<Edge> > Graph;

const int INF = 1<<28;
int N, M;
Graph G;

int dijkstra() {
  priority_queue<Edge> que;
  vector<pair<int, int> > cost(N, make_pair(INF, INF));
  cost[0] = Pair(0, 0);
  que.push((Edge){0, Pair(0, 0)});
  while (que.size()) {
    const Edge s = que.top();
    que.pop();
    if(cost[s.v] < s.w) continue;
    for (int i = 0; i < G[s.v].size(); ++i) {
      const Edge &e = G[s.v][i];
      const Edge t = {e.v, Pair(s.w.first  + e.w.first,
                                e.w.second)};
      if (cost[t.v] <= t.w) continue;
      cost[t.v] = t.w;
      que.push(t);
    }
  }
  int res = 0;
  for (int i = 0; i < N; ++i) {
    res += cost[i].second;
  }
  return res;
}

int main() {
  while (cin >> N >> M && (N|M)) {
    G = Graph(N);
    for (int i = 0; i < M; ++i) {
      int a, b, d, c;
      cin >> a >> b >> d >> c;
      --a; --b;
      G[a].push_back((Edge){b, Pair(d, c)});
      G[b].push_back((Edge){a, Pair(d, c)});
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 2724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

class Main {
	public static void main(String[] args)
	{
		FastScanner in=new FastScanner();
		int n=in.nextInt();
		int w=in.nextInt();
		int[] wt=new int[n];
		long[] val=new long[n];
		for(int i=0;i<n;i++)
		{
			wt[i]=in.nextInt();
			val[i]=in.nextLong();
		}
		long[] dp=new long[w+1];
		for(int i=0;i<n;i++)
		{
			for(int j=w;j>=0;j--)
			{
				if(wt[i]<=j)
					dp[j]=Math.max(dp[j], dp[j-wt[i]]+val[i]);
			}
		}
		System.out.println(dp[w]);
	}
static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 33752
n, k = map(int, input().split())
li = list(map(int, input().split()))
li.append(0)
li.sort()
zero_index = li.index(0)
if zero_index == 0:
    print(li[k])
elif zero_index == len(li) -1:
    print(abs(li[-k-1]))
else:
    near_zero_small = li[zero_index-1]
    near_zero_big = li[zero_index+1]
    li.pop(zero_index)
    ans = 0
    cost = 0
    for i in range(n-k+1):
        minimam = li[i]
        maximam = li[i+k-1]
        if (minimam > 0 and maximam > 0 ):
            if minimam == near_zero_big:
                cost = maximam
        elif (minimam < 0 and maximam < 0 ):
            if minimam == near_zero_big:
                cost = abs(minimam)
        else:
            cost = min(abs(minimam), maximam)*2 + max(abs(minimam), maximam)
        if ans > cost or ans == 0:
            ans = cost
    print(ans)

Measured memory_bytes: 14480
import * as fs from "fs";

// inputで受け取り配列化する
const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");

const a = input[1].split(" ").map(Number);
let cnt = 0;

for (let index = 0; index < a.length; index++) {
  const num = index + 1;
  if (num % 2 === 0) {
    continue;
  }
  if (a[index] % 2 === 0) {
    continue;
  }
  cnt++;
}

console.log(cnt);


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	string S; cin >> S;
	vector<int> A(4);
	REP(i,4){
		A[i] = S[i] - '0';
	}

	REP(i,8){
		int tmp = i;

		int sum = A[0];
		FOR(j,1,4){
			if(tmp&1) sum += A[j];
			else sum -= A[j];
			tmp = tmp >> 1;
		}

		if(sum == 7){
			tmp = i;
			REP(j,3){
				cout << A[j];
				if(tmp&1) cout << "+";
				else cout << "-";
				tmp = tmp >> 1;
			}
			cout << A.back() << "=7" << endl;

			return 0;
		}


	}





	return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string S;

int main()
{
  std::cin >> S;

  ll ans = 700;

  rep( i, 3 ) if( S[i] == 'o' )
    ans += 100;

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fi first
#define se second
 
const ll MOD = 1000000007;

int main() {
   int a, b, c; scanf("%d%d%d", &a, &b, &c);
   printf("%d", max(0, c - a + b));
   return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int N,x,y,z,Y;
    cin >> N >> Y;
    
    x=-1;
    y=-1;
    z=-1;
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
                int sum =10000*i+5000*j+1000*(N-i-j);
                if(sum==Y){
                    x=i;
                    y=j;
                    z=N-i-j;
                    break;
                }
        }
    }

    cout << x<<" "<<y<<" "<<z<<endl;
    
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int intA = sc.nextInt();
		int intB = sc.nextInt();
		int intC = sc.nextInt();

		int[] arr = new int[]{intA,intB,intC};
		Arrays.sort(arr);

		System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);
	}
}

Measured memory_bytes: 26200
#include<stdio.h>
int main(void) {
	int  a=100000,c;
	double b = 100000;
	scanf("%d", &c);
	for (int i = 0; i < c; i++)
	{
		b*= 1.05;
		a = b;
		if (a % 1000 != 0)
		{
			b = (b - (a % 1000)) + 1000;
		}
		a = b;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 1020
#include<stdio.h>
int n,a[111111];
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	int r=0;
	for(int i=1; i<=n; i++)
		if(a[a[i]] == i)
			r++;
	printf("%d\n",r/2);
	return 0;
}

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

using namespace std;

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

  int n;
  cin >> n;

  vector<int> d(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());

  cout << d[n / 2] - d[n / 2 - 1] << '\n';

  return 0;
}


Measured memory_bytes: 640
import scala.io.StdIn._
object Main extends App {
  @scala.annotation.tailrec
  def next(diff: Int, maxValue: Int, num: Int, as: Seq[Int]): Int = {
    as match {
      case Nil => num
      case _ => 
        val targetValue = as.head
        val newDiff = maxValue - targetValue
        if (newDiff > diff) next(newDiff, maxValue, 1, as.tail) // must be (targetValue < maxValue)
        else if (newDiff == diff) next(diff, targetValue, num + 1, as.tail) // must be (targetValue > maxValue)
        else next(diff, targetValue max maxValue, num, as.tail)
    }
  }

  val n = readLine.split(" ").head map {_.toInt}
  val as = (readLine.split(" ") map {_.toInt}).toList.reverse

  println(next(0, as.head, 0, as.tail))
}

Measured memory_bytes: 37428
#include<bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define popb  pop_back
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define mp make_pair
#define bs binary_search
using namespace std;
ll m=1000000000+7;

int main()
{
   IOS;
   int t=1;
   ll ac=0,wa=0,tle=0,re=0;
   cin>>t;
   while(t--)
   {
      ll n,cnt=0,i,j,p,l,ans=0,d,k=0,mn,id=0;
      //cin>>n;
      string s;
      cin>>s;
      if(s=="AC")
      {
        ac++;
      }
      else if(s=="TLE")
      {
        tle++;
      }
      else if(s=="WA")
      {
        wa++;
      }
      else if(s=="RE")
      {
        re++;
      }
   }
   cout<<"AC x "<<ac<<"\n";
   cout<<"WA x "<<wa<<"\n";
   cout<<"TLE x "<<tle<<"\n";
   cout<<"RE x "<<re<<"\n";

   return 0;
}


Measured memory_bytes: 3652
using System;
using System.Text;

namespace Main
{
  class Program
  {
    static void Main(string[] args)
    {
      string[] lines = Console.ReadLine().Split(' ');
      int a = int.Parse(lines[0]);
      int b = int.Parse(lines[1]);
      int k = int.Parse(lines[2]);

      StringBuilder buf = new StringBuilder();
      if (b - a < k << 1)
      {
        for (int i = a; i <= b; i++)
          buf.Append(i + "\n");
      }
      else
      {
        for (int i = a; i < a + k; i++)
          buf.Append(i + "\n");
        for (int i = b - k + 1; i <= b; i++)
          buf.Append(i + "\n");
      }

      Console.Write(buf);
    }
  }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 2e5+1;
int n, v[N];
map<int,int>cm;

int main(){
   // freopen("read.txt","r",stdin); 
    scanf("%d",&n);
    for(int i = 0 ; i<n; ++i){
    	  scanf("%d",v+i);
    	  cm[i] = cm[i-1] + v[i];
    }
    int an = 1e9;
    for(int i = 1; i<n;++i){
    	  int l = cm[i-1];
    	  int r = cm[n-1] - l;
    	  an = min(an,abs(r-l));
    }
    printf("%d\n",an);
}


Measured memory_bytes: 256