akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 1000001

ll fac[N],ifac[N];

ll power(ll a,ll b) {
	ll res = 1;
	while(b) {
		if(b&1) res=(res*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return res;
}

ll ncr(ll n,ll r) {
	if(n<r) return 0;
	ll res = fac[n];
	res = (res*ifac[n-r])%mod;
	res = (res*ifac[r])%mod;
	return res;
}

void pre() {
	fac[0]=ifac[0]=1;
	ifr(i,1,N) fac[i] = (1ll*fac[i-1]*i)%mod;
	ifr(i,1,N) ifac[i] = power(fac[i],mod-2);
}

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

    pre();
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ifr(i,0,n) cin>>a[i];
    sort(a,a+n);
    ll ans = 0,sol=0;
    ifr(i,0,n) {sol = 0;
    	// cout<<i+1<<" ";
    	if(i+k-1<n) {
    		sol = (a[i]+mod)%mod;
    		sol = (sol * ncr(n-i-1,n-i-k));
    		ans = (ans-sol+mod)%mod;
    	}
    	// cout<<sol<<" ";
    	sol = 0;
    	if(i-k+1>=0) {
    		sol = (a[i]+mod)%mod;
    		sol = (sol * ncr(i,i-k+1));
    		ans = (ans+sol)%mod;
    	}
    	// cout<<sol<<"\n";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16640
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.next().charAt(0);
    int y = sc.next().charAt(0);
    if(x>y){
      System.out.print(">");
    }else if(x<y){
      System.out.print("<");
    }else{
      System.out.println("=");
    }
  }
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int X = C - A, Y = D - B;

  cout << C - Y << " " << D + X << " " << C - Y - X << " " << D + X - Y << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int64_t n, m, s;
    cin >> n >> m;
    s = 0;
    for(int i=0;i<m;++i){
        int64_t a;
        cin >> a;
        s += a;
    }
    int64_t ans = n - s;
    cout << (ans < 0 ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert	//お試し
typedef pair<int,int> pii;//You can add other pairs of types in the same way.

int main(){
	int n;
	long long x[100000],a,b,ans=0;
	cin>>n>>a>>b>>x[0];
	for(int i=1;i<n;++i){
		cin>>x[i];
		ans+=min((x[i]-x[i-1])*a,b);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define  pb push_back
#define nl "\n"
#define fastScan ios_base::sync_with_stdio(0); cin.tie(NULL);
#define int long long int
using namespace std;
int wt[123456];
int val[123456];
int dp[105][123456];
signed main()
{
	fastScan;
	int n,w,ans=0;cin>>n>>w;
	for(int i=0;i<n;i++)
		cin>>wt[i]>>val[i];
	int v=100000;
	for(int i=1;i<=v;i++)
	{
		if(i==val[0])
			dp[1][i]=wt[0];
		else
			dp[1][i]=(int)(1e18);
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=v;j++)
		{
			if(j>=val[i-1])
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-val[i-1]]+wt[i-1]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	int res=0;
	for(int i=v;i>=1;i--)
	{
		if(dp[n][i]<=w)
		{
			res=i;
			break;
		}
	}
	cout<<res<<nl;
}


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

int main() {
  double N = 0;
  double count = 0;
  double rate = 0;
  cin >> N;
  for(int i = 1;i < N+1;i++) {
    if(i%2 == 1) {
      count = count + 1;
    }
  }
  rate = double (count / N);
  cout << rate << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N; cin>>N;
  int sum=0,count1=0,count2=0;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  rep(i,0,N){
    sum+=A[i];
    if(i%2==0){
      if(sum>=0){
        count1+=sum+1;
        sum=-1;
        }
      }
    else{
      if(sum<=0){
        count1+=1-sum;
        sum=1;
        }
      }
    }
  sum=0;
  rep(i,0,N){
    sum+=A[i];
    if(i%2==1){
      if(sum>=0){
        count2+=sum+1;
        sum=-1;
        }
      }
    else{
      if(sum<=0){
        count2+=1-sum;
        sum=1;
        }
      }
    }
  cout<<min(count1,count2)<<endl;
  }


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main(int argc , char **argv)
{
	(void)argc;
	(void)argv;

	int flag[100001] = {};
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		a--;
		if (a==i){flag[i]=1;}
	}

//for(int i=0;i<N;i++){ printf("%d ",flag[i]);}
//printf("\n");

	int fc = 0;
	int swapCnt = 0;
	for(int i=0;i<N;i++){
		if(flag[i]==1){
			fc++;
		}else{
			swapCnt += (fc+1)/2;
			fc = 0;
		}
	}
	if (0<fc){
		swapCnt+=(fc+1)/2;
	}

	printf("%d\n",swapCnt);

	return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static long N;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextLong();

        System.out.println( solve() );
    }

    private static int solve() {
        if( N < 10 ) return (int)N;

        String s = String.valueOf(N);

        int a = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            a += (c - '0');
        }

        int b = (s.charAt(0) - '0' - 1) + (s.length()-1) * 9;

        return Math.max(a, b);
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
	cin>>a;b=a;
	reverse(a.begin(),a.end());
	for(int i=0;i<a.size();i++)
	{
		if(a[i]=='b')a[i]='d';
		else if(a[i]=='d')a[i]='b';
		if(a[i]=='p')a[i]='q';
		else if(a[i]=='q')a[i]='p';
	}
	if(a==b)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 512
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))



n,m=map(int,input().split())
dsu=DSU(n)

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    dsu.merge(a,b)

print(len(dsu.groups())-1)

Measured memory_bytes: 98636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
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 > using matrix = vector< vector< T > >;

//FUNCTION  


void solve(void)
{
  int N;
  cin>>N;
  int ANS = 0;
  int prev = INF;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;

    if(i == 0)
    { 
      if(A == 0)
      prev = 0;
      else
      {
        cout<<-1<<endl;
        return;
      }
      continue;
    }

    
    if( A - prev == 1)
    {
      ANS++;
    }
    else if(A - prev == 0)
    {
      ANS += A;
    }
    else if( A - prev >= 2)
    {
      cout<<-1<<endl;
      return;
      break;
    }
    else if( A < prev)
    {
      ANS += A;
    }

    prev = A;
    // DEBUG(ANS,A);

  }
  cout<<ANS<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
import math

primes=[2]
top=2
nlist=[2*x-1 for x in range(2,500)]
while top<math.sqrt(500):
    top=nlist[0]
    primes.append(top)
    newnlist=[]
    for i in nlist:
        if i%top!=0:
            newnlist.append(i)
    nlist=newnlist
primes=primes+nlist

def getpoints(a):
    primelist=[]
    while a>1:
        primeflag=0
        for p in primes:
            if a%p==0:
                primeflag=1
                a=a/p
                if p not in primelist:
                    primelist.append(p)
                break
        if primeflag==0:
            primelist.append(a)
            a=1
    psorted=sorted(primelist)
    pts=primelist[-1]-sum(psorted[:-1])
    return pts
    
while(1):
    [a,b]=[int(x) for x in raw_input().split()]
    if a==0:
        break
    else:
        pta=getpoints(a)
        ptb=getpoints(b)
        if pta>ptb:
            print 'a'
        else:
            print 'b'

Measured memory_bytes: 4432
import heapq

N , K = map(int,input().split())
h_list = list(map(int,input().split()))
ans = 0
heap = []

for i in range(N):
    heapq.heappush(heap, h_list[i]*(-1))

for i in range(N):
    if (heapq.heappop(heap)*(-1) < K):
        break

    else:
        ans += 1


print(ans)

Measured memory_bytes: 12000
import java.util.*;
public class Main {
	public static void main(String[] args){
		final int MAX=999999;
		Scanner sc=new Scanner(System.in);
		boolean[] prime=primeList(MAX);
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int cnt=0;
			for(int i=0;i<=n;i++){
				if(prime[i]) cnt++;
			}
			System.out.println(cnt);
		}
		sc.close();
	}
	
	static boolean isPrime(int n){
		if(n<2) return false;
		for(int i=2;i*i<n;i++){
			if(n%i==0) return false;
		}
		return true;
	}
	
	static boolean[] primeList(int n){
		boolean[] prime=new boolean[n+1];
		for(int i=2;i<=n;i++) prime[i]=true;
		for(int i=2;i*i<n;i++){
			if(isPrime(i)){
				for(int j=i+i;j<=n;j+=i){
					prime[j]=false;
				}
			}
		}
		return prime;
	}
}

Measured memory_bytes: 22172
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10,mod=998244353;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a,int b) {
  a+=b;
  return a>=mod?a-mod:a;
}
int sub(int a,int b) {
  a-=b;
  return a<0?a+mod:a;
}
int mul(int a,int b) {
  return (int)((long long)a*b%mod);
}
struct BIT{
    vector<int> bit;
    int n;
    BIT(int _n){
            bit.resize(_n+5,0);
            n=_n+5;
    }
    void update(int idx,int val){
        for(;idx<n;idx+=(idx&(-idx)))
            bit[idx]+=val;
        return;
    }
    int get(int idx){
        int sum=0;
        for(;idx>0;idx-=(idx&(-idx)))
            sum+=bit[idx];
        return sum;
    }
    int get(int l,int r){
        return get(r)-get(l-1);
    }
};
struct pt{
    int x,y;
    pt():x(0),y(0){}
    void read(){
        scanf("%d%d",&x,&y);
    }
    bool operator <(const pt &a){
        return x==a.x?y<a.y:x<a.x;
    }
}p[maxn];
vector<int> ss;
int ans,n;
int p2[maxn];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        p[i].read();
        ss.push_back(p[i].x);
        ss.push_back(p[i].y);
    }
    ss.push_back((int)(-1e9-7));
    sort(ss.begin(),ss.end());
    ss.erase(unique(ss.begin(),ss.end()),ss.end());
    for(int i=1;i<=n;i++){
        p[i].x=(int)(lower_bound(ss.begin(),ss.end(),p[i].x)-ss.begin());
        p[i].y=(int)(lower_bound(ss.begin(),ss.end(),p[i].y)-ss.begin());
    }
    p2[0]=1;
    for(int i=1;i<=n;i++){
        p2[i]=add(p2[i-1],p2[i-1]);
    }
    sort(p+1,p+1+n);
    int cur=0,u1,u2,d1,d2;
    BIT f1((int)ss.size()),f2((int)ss.size());
    for(int i=1;i<=n;i++)
        f1.update(p[i].y,1);
    for(int i=1;i<=n;i++){
        int j=i,ct=0;
        while(p[j].x==p[i].x&&j<=n){
            f1.update(p[j].y,-1);
            ct++;
            j++;
        }
        j--;
        for(int k=i;k<=j;k++){
        u1=f1.get(p[k].y+1,(int)ss.size()),u2=f2.get(p[k].y+1,(int)ss.size());
        d1=f1.get(p[k].y-1),d2=f2.get(p[k].y-1);
        plusle(ans,sub(p2[n],1));
        ///completely above
        cur = u1 + u2 + (j-k);
        minun(ans,sub(p2[cur],1));
        ///completely below
        cur = d1 + d2 + (k-i);
        minun(ans,sub(p2[cur],1));
        ///completely left
        minun(ans,sub(p2[i-1],1));
        ///completely right
        minun(ans,sub(p2[n-j],1));
        ///shitty four corners
        ///left-up
        plusle (ans,sub(p2[u2],1));
        ///left down
        plusle(ans,sub(p2[d2],1));
        ///right up
        plusle(ans,sub(p2[u1],1));
        ///right down
        plusle(ans,sub(p2[d1],1));
        }
        for(int k=i;k<=j;k++){
            f2.update(p[k].y,1);
        }
        i=j;
    }
    printf("%d\n",ans);
}

/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 8944
#include<iostream>

using namespace std;

int main() {
	int r, g, b;
	cin >> r >> g >> b;

	int Q = r * 100 + g * 10 + b;
	if (Q % 4 == 0) {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
// A - ∴ (Therefore)
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	int s = S.back()-'0';
	string ans = "hon";
	if(s == 3) ans = "bon";
	else if(s==0 || s==1 || s==6 || s==8) ans = "pon";
	cout<< ans <<endl;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <utility>
#include <vector>
#include <string>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
bool scan(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	vector<string> b = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	string s;
	for (int i = in(); i--;) {
		scan(s);
		int n = -1, p = -1;
		for (char c: s) {
			c -= '0';
			if (c == n)
				p++;
			else {
				if (!c && n != -1)
					out(b[n][(p) % (int) b[n].size()]);
				n = c, p = 0;
			}
		}
		out('\n');
	}
}


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

typedef long long ll;
ll N;
ll a;

ll dbin(ll x){
    ll res = 0;
    while(x>0){
        if(x&1) break;
        res++;
        x>>=1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    ll ans = 0;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a;
        ans += dbin(a);
    }
    cout << ans << endl;
}


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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384


int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}


typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool is_prime (int x){
  if (x<=1) return false ;
  for (int i=2 ; i*i<=x ; i++){
    if (x%i==0) return false ;
  }
   return true;
}
string alpha = "abcdefghijklmnopqrstuvwxyz" ;

 
/*CODE START HERE*/
int main() {
  int n;
  cin >> n;
  vector <int> b(n-1);
  forn(i,n-1){
    cin >> b.at(i);
  }
  int sum = b.at(0)+b.at(n-2);
  forr (i,1,n-1){
    sum += min ( b.at(i) , b.at(i-1) );
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int X;
	cin >> X;
	
	int cur = X, ans = 1;
	while (1) {
		cur += X;
		++ans;
		if (cur % 360 == 0) break;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3620
N = gets.to_i
BS = [Float::INFINITY] + gets.split.map(&:to_i) + [Float::INFINITY]

# !  2  5  !
#  A1 A2 A3
#  ^  ^  ^
#  2  2  5
#
#  max(A1, A2) <= 2

ans = 0
N.times.map{|i|
  ans += [BS[i], BS[i+1]].min
}
p ans


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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i];
  }

  map<int, int> p;
  for (int i = 1; i <= n; i++) {
    p[i] = 0;
  }

  for (int i = 0; i < q; i++) {
    p[a[i]]++;
  }

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

}

Measured memory_bytes: 7296
def comb(n, k)
  return 1 if k.zero?
  num = 1
  (n-k+1).upto(n) do |i|
    num *= i
  end
  div = 1
  1.upto(k) do |i|
    div *= i
  end
  num / div
end

N, K = gets.split.map(&:to_i)
1.upto(K) do |i|
  if i > K || (N-K+3) < i
    puts 0
  else
    puts (comb(K-1, i-1) * comb(N-K+1, i)) % 1000000007
  end
end


Measured memory_bytes: 3096
#include <stdio.h>

using namespace std;

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

int main() {

    int D, N;
    scanf("%d %d", &D, &N);

    int a = 0;
    if (D == 0) {
        a = 1;
    } else if (D == 1) {
        a = 100;
    } else {
        a = 10000;
    }

    printf("%d\n", N == 100 ? a * 101 : a * N);

    return 0;
}


Measured memory_bytes: 128
import operator
from itertools import accumulate

def main():
  N = int(input())
  A = list(map(int, input().split()))
  A_sum = list(reversed(list(accumulate(reversed(A))))) + [0]
  B = [0] * (N+1)

  B[0] = 1 - A[0]
  d = A_sum[0] + B[0]
  if B[0] < 0:
    return -1
  for i in range(1, N+1):
    B[i] = min(B[i - 1] * 2 - A[i], A_sum[i+1])
    
    if B[i] < 0:
      return -1
    d += B[i]
  return d

print(main())

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

int main() {
	int n,q,*S,*T,c=0,i,j;
	
	cin>>n;
	S=new int[n];
	
	for(i=0;i<n;++i)cin>>S[i];
	
	cin>>q;
	T=new int[q];
	
	for(i=0;i<q;++i)cin>>T[i];
	
	for(i=0;i<q;++i)
		for(j=0;j<n;++j)
			if(S[j]==T[i])T[i]=-1;
	
	for(i=0;i<q;++i)if(T[i]==-1)++c;
	
	cout<<c<<endl;
	
	delete[]S;
	delete[]T;
	return 0;
}

Measured memory_bytes: 1232
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    k <- getInt
    let s1 = sum [gcd (gcd a b) c | a <- [1..k-2], b <- [a+1..k-1], c <- [b+1..k]]
        s2 = sum [gcd a b | a <- [1..k-1], b <- [a+1..k]]
        s3 = sum [1..k]
    print $ (6 * s1) + (6 * s2) + s3

Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
int mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);

// vector<vector<ll>> dp(1<<22,vector<ll> (25,-1));
ll dp[1<<22][25];
ll allmask;
ll recursion(ll &n,ll mask,vector<vector<int>> &vec,ll level){
  if(level>=n){
    if(mask==allmask) return 1;
    return 0;
  }
  if(dp[mask][level]!=-1) return dp[mask][level];
  ll val=0;
  for(int i=0;i<n;i++){
    if(vec[i][level]==1 && (mask & (1<<i))==0){
      val=(val%mod+recursion(n,mask | (1<<i),vec,level+1)%mod)%mod;
    }
  }
  dp[mask][level]=val;
  return dp[mask][level];
} 
int main()
{
  //------------ SEE BELOW ARTICLE---------------
 // https://codeforces.com/blog/entry/64250?#comment-484569
  // input_from_file;
  ll n;cin>>n;
  vector<vector<int>> vec(n,vector<int> (n,0));
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)  cin>>vec[i][j];
  }
  allmask=(1<<n)-1;
  memset(dp, -1 , sizeof dp);
  cout<<recursion(n,0,vec,0);
  return 0;
}


Measured memory_bytes: 819584
N=int(input())
a=[int(i) for i in input().split()]
if a.count(1)==0:
    print(-1)
else:
    ans=[]
    for i in range(N):
        if a[i]==len(ans)+1:
            ans.append(a[i])
    #print(N)
    #print(len(ans))
    print(N-len(ans))  

Measured memory_bytes: 26012
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, y;
    cin >> n >> y;
    vector<int> a = {10000, 5000, 1000};
    for(int i = 0; i <= n; i++){
        int yo = 5000 * (n - i) - (y - i * 10000);
        if(yo % 4000 == 0){
            int c = yo / 4000;
            int b = (n - i) - c;
            if(b >= 0 && c >= 0 && i + b + c == n && i * 10000 + b * 5000 + c * 1000 == y){
                cout << i << ' ' << b << ' ' << c;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

 int main() {
   int X;
   cin >> X;
   cout << (X / 500) * 1000 + X % 500 / 5 * 5 << endl;
 }


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

ll dp[101010][3];

int main() {
    int N;
    cin >> N;
    vector<ll> a(N), b(N), c(N);
    rep(i, N) {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i=0; i<N; ++i) {
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[i];
        dp[i+1][1] = max(dp[i][0], dp[i][2]) + b[i];
        dp[i+1][2] = max(dp[i][0], dp[i][1]) + c[i];
    }

    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int len = s.size();
    if (len == 2) {
        if (s[0] == s[1])
            puts("1 2");
        else
            puts("-1 -1");
        return 0;
    }

        for (int i = 1; i < len; i++) {
            if (s[i] == s[i - 1]) {
                printf("%d %d\n", i , i + 1);
                return 0;
            }
            if (s[i] == s[i - 2]) {
                printf("%d %d\n", i - 1, i + 1);
                return 0;
            }
        }
        printf("-1 -1\n");
        return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi c(n),s(n),f(n);
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(i,n-1){
        int now = 0;
        now+=s[i]+c[i];
        FOR(j,i+1,n-2){
            now = max((now+f[j]-1)/f[j]*f[j], s[j])+c[j];
        }
        cout<<now<<endl;
    }
    cout<<"0\n";
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[1000000], ans, dp[1000000][2];
Pll a[200000], b[2000000];
string str, ss, dd;
bool f[200000],ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v[2];
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i].fir >> a[i].sec;
			v[0].push_back(Pll(a[i].fir, i));
			v[1].push_back(Pll(a[i].sec, i));
	}
	sort(v[0].begin(), v[0].end());
	sort(v[1].begin(), v[1].end());
	rep(j, 2) {	
		LL num = 0, l = 0, r = 0;
		cnt = 0;
		ff = j;
		rep(i, 200000)f[i] = 0;
		rep(i, n) {
			if (i % 2 == ff) {
				while (f[v[0][n - l - 1].sec]) {
					l++;
				}
				f[v[0][n - 1 - l].sec] = 1;
				if (!(a[v[0][n - l - 1].sec].fir <= num && a[v[0][n - l - 1].sec].sec >= num)) {
					cnt += abs(num - v[0][n - l - 1].fir);
					num = v[0][n - l - 1].fir;
				}
				else {
					ff = !ff;
				}
			}
			else {
				while (f[v[1][r].sec]) {
					r++;
				}
				if (!(a[v[1][r].sec].fir <= num && a[v[1][r].sec].sec >= num)) {
					cnt += abs(num - v[1][r].fir);
					num = v[1][r].fir;
				}
				else {
					ff = !ff;
				}
				f[v[1][r].sec] = 1;
			}
		}
		cnt += abs(num);
		ans = max(ans,cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10212
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    cout << N * N << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

/*
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
*/

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-9;

void solve() {
    ll n;
    cin >> n;
    string ans = "ABC";
    if(n >= 1000) ans = "ABD";
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,pii> P;

const ll INF = 100000000000007;

int n,m,x;
int h[100000];
ll d[100000];
vector<pii> G[100000];
priority_queue<P,vector<P>,greater<P> > q;

int main(){
  scanf("%d %d %d",&n,&m,&x);
  for(int i=0;i<n;i++) scanf("%d",h+i);
  for(int i=0;i<m;i++){
    int a,b,t;
    scanf("%d %d %d",&a,&b,&t);
    a--; b--;
    G[a].push_back(pii(b,t));
    G[b].push_back(pii(a,t));
  }
  fill(d,d+n,INF);
  d[0] = 0;
  q.push(P(0,pii(0,x)));
  ll ans = INF;
  while(!q.empty()){
    int tree = q.top().second.first, pos = q.top().second.second;
    ll c = q.top().first;
    if(tree==n-1){
      ans = min(ans,c+h[n-1]-pos);
    }
    q.pop();
    if(d[tree]<c) continue;
    for(int i=0;i<G[tree].size();i++){
      int next_tree = G[tree][i].first, next_pos = pos - G[tree][i].second;
      ll cost = d[tree] + G[tree][i].second;
      if(h[tree]-G[tree][i].second<0) cost = INF;
      else if(next_pos<0){
        cost -= next_pos;
        next_pos = 0;
      }else if(next_pos>h[next_tree]){
        cost += next_pos - h[next_tree];
        next_pos = h[next_tree];
      }
      if(d[next_tree]>cost){
        d[next_tree] = min(d[next_tree],cost);
        q.push(P(d[next_tree],pii(next_tree,next_pos)));
      }
    }
  }
  if(ans==INF) printf("-1\n");
  else printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 15592
from operator import itemgetter

N = int(input())
tasks = [list(map(int, input().split())) for i in range(N)]

tasks.sort(key=itemgetter(1))

time = 0

for task in tasks:
    time += task[0]
    if time > task[1]:
        ans = "No"
        break
else:
    ans = "Yes"

print(ans)

Measured memory_bytes: 53732
def gcd(a, b):
	if b == 0:
		return a
	if a < b:
		a, b = b, a
	return gcd(b, a % b)

def main():
	mp = {}
	k = int(input())	
	s = 0
	for i in range(1, k + 1):
		for j in range(1, k + 1):
			d = gcd(j, i)
			if d not in mp:
				mp[d] = 0 
			mp[d] += 1 
	for key in mp:
		for j in range(1, k+1):
			s += gcd(key, j) * mp[key]
	print(s)		
	return 0

main()


Measured memory_bytes: 76972
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n; cin >> n;
  map<int,int> mp;

  int ar[n];

  for(int i=0;i<n-1;i++){
    cin >> ar[i];
    mp[ar[i]]++;
  }

  vector<int> ans;

  for(int i=0;i<n;i++){
    cout << mp[i+1] << '\n';
  }



  return 0;
}

Measured memory_bytes: 17724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QQ
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i=1; i<10; i++){
                for(int j=1; j<10; j++){
                    Console.WriteLine(i + "x" + j + "=" + i*j);
                }
            }
        }
    }
}

Measured memory_bytes: 5572
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define outl2(x,y) cout<< (x) << ' ' << (y) << '\n'
using pii = pair<int,int>;
using ll = long long;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
static constexpr int INF = 0x3f3f3f3f;


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

    int K;
    cin >> K;
    int even = K/2;
    int odd = K-even;

    outl(even * odd);

    return 0;
}



Measured memory_bytes: 256
##以下ググった（https://at274.hatenablog.com/entry/2020/01/24/060000）
n = int( input() )

cnt = [ [ 0 for i in range( 10 ) ] for j in range( 10 ) ]
# cnt[ i ][ j ] = 先頭がi，末尾がjである，n以下の整数の個数

for k in range( n + 1 ):
    head = int( str( k )[ 0 ] )
    foot = int( str( k )[ -1 ] )
    cnt[ head ][ foot ] += 1

ans = 0
for i in range( 1, 10 ):
    for j in range( 1, 10 ):
        ans += cnt[ i ][ j ] * cnt[ j ][ i ]

print( ans )

Measured memory_bytes: 8952
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> x(N,-1);
    while(M--){
        int s, c;
        cin >> s >> c;
        s--;
        if(x[s]!= -1 && x[s] != c){
            cout << "-1" << endl;
            return 0;
        }
        x[s] = c;
    }
    if(x[0] == -1 && N!=1){
        x[0]=1;
    }
    for(int& p :x){
        if(p == -1)
            p = 0;
    }
    if(x[0] == 0 && N != 1){
        cout << "-1" << endl;
        return 0;
    }
    for(int p :x){
        cout << p;
    }
    cout << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  if( (s.at(0) == 'a' and s.at(1) == 'b' and s.at(2) == 'c')
    or(s.at(0) == 'a' and s.at(1) == 'c' and s.at(2) == 'b')
    or(s.at(0) == 'b' and s.at(1) == 'c' and s.at(2) == 'a')
    or(s.at(0) == 'b' and s.at(1) == 'a' and s.at(2) == 'c')
    or(s.at(0) == 'c' and s.at(1) == 'b' and s.at(2) == 'a')
    or(s.at(0) == 'c' and s.at(1) == 'a' and s.at(2) == 'b') )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  int n, m;
  std::cin >> n >> m;

  std::vector<std::pair<int64_t, int>> val_list[6];
  for (int i = 0; i < 6; i++) {
    val_list[i] = std::vector<std::pair<int64_t, int>>(n);
  }
  std::vector<int64_t> x(n), y(n), z(n);

  for (int i = 0; i < n; i++) {
    std::cin >> x[i] >> y[i] >> z[i];

    for (int j = 0; j < 6; j++) {
      int64_t sum = 0;
      if (j % 2 == 0) {
        sum += x[i];
      } else {
        sum -= x[i];
      }
      if ((j / 2) % 2 == 0) {
        sum += y[i];
      } else {
        sum -= y[i];
      }
      if ((j / 4) % 3 == 0) {
        sum += z[i];
      } else {
        sum -= z[i];
      }
      val_list[j][i] = {sum, i};
    }
  }

  for (int i = 0; i < 6; i++) {
    std::sort(val_list[i].begin(), val_list[i].end(),
      std::greater<std::pair<int64_t, int>>());
  }

  int64_t ans = 0;
  for (int i = 0; i < 6; i++) {
    int64_t x_s = 0, y_s = 0, z_s = 0;
    for (int j = 0; j < m; j++) {
      x_s += x[val_list[i][j].second];
      y_s += z[val_list[i][j].second];
      z_s += y[val_list[i][j].second];
    }
    ans = std::max(ans,
      std::abs(x_s) + std::abs(y_s) + std::abs(z_s));
  }

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


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

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	int sum = 0;
	int now = 0;
	int mx = 0;
	rep(i,n-1){
		if(h[i+1] <= h[i]){
			sum++;
		}
		else{
			mx = max(mx,sum);
			sum = 0;
		}
		mx = max(mx,sum);
	}
	cout << mx << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int A, B;
  cin >> A >> B;
  int ans = max({A + B, A - B, A * B});
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
using namespace std;



int main() {
	cout << fixed << setprecision(10);
	long long int a, b, c, n, m, p[200005] = {}, q[200005] = {}, sum = 0;
	double t,x;
	cin >>m>>n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p, p + n);
	for (int i = 0; i < n-1; i++) {
		q[i] = p[i + 1] - p[i];
	}
	sort(q, q + n - 1);
	for (int i = 0; i < n - m; i++) {
		sum += q[i];
	}
	cout << sum;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

string S, T;
bool can = true;

map<char, char> mp, imp;

int main(void){
	cin>>S>>T;
	for (int i = 0; i < S.size(); i++) {
		char s = S[i], t = T[i];
		if (mp.count(s)) if (mp[s] != t) can = false;
		if (imp.count(t)) if (imp[t] != s) can = false;
		mp[s] = t; imp[t] = s;
	}

	if (can) cout<< "Yes" <<endl;
	else cout<< "No" <<endl;
	
	return 0;
}

Measured memory_bytes: 776