akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

Vi mul(VVi a, Vi b, ll m){
  ll x = a.size(), y = a[0].size(), y1 = b.size();
  assert(y == y1);
  REP(i, x) REP(j, y) {
    a[i][j] = residue(a[i][j], m);
  }
  REP(i, y) b[i] = residue(b[i], m);
  Vi c(x, 0);
  REP(i, x) REP(j, y){
    c[i] += a[i][j] * b[j] % m; c[i] %= m;
  }
  return c;
}
VVi mul(VVi a, VVi b, ll m){
  //a * b 要素はmで割ったあまり
  ll x = a.size(), y1 = a[0].size(), y2 = b.size(), z = b[0].size();
  assert(y1 == y2);
  ll y = y1;
  REP(i, x) REP(j, y) a[i][j] = residue(a[i][j], m);
  REP(i, y) REP(j, z) b[i][j] = residue(b[i][j], m);
  VVi c(x, Vi(z, 0));
  REP(i, x) REP(j, z) REP(k, y){
    c[i][j] += (a[i][k] * b[k][j]) % m; c[i][j] %= m;
  }
  return c;
}
VVi pow(VVi a, ll n, ll m){
  if(n == 0) {
    ll x = a.size();
    VVi I(x, Vi(x, 0));
    REP(i, x) I[i][i] = 1;
    return I;
  }
  if(n % 2 == 0) {
    VVi b = mul(a, a, m);
    return pow(b, n / 2, m);
  }
  else return mul(pow(a, n - 1, m), a, m);
}

int main(){
  ll l, a, b, m; cin >> l >> a >> b >> m;
  Vi p(18);
  REP(i, 18){
    ll x = max(0ll, (pow(10ll, i) - a + b - 1) / b); chmin(x, l);
    ll y = max(0ll, (pow(10ll, i + 1) - a + b - 1) / b); chmin(y, l);
    p[i] = y - x;
//    printf("p[%lld] = (%lld桁の項数) = %lld\n", i, i + 1, p[i]);
  }
  Vi X = {0, residue(a - b, m), 1};
  VVi Y = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
  REP(i, 18){
    VVi A = {{pow(10, i + 1, m), 1, b}, {0, 1, b}, {0, 0, 1}};
    Y = mul(pow(A, p[i], m), Y, m);
//    printf("i = %lld, X[0] = %lld, X[1] = %lld, X[2] = %lld\n", i, X[0], X[1], X[2]);
  }
  Vi Z = mul(Y, X, m);
  cout << Z[0] << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        Integer min = null;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int j = scanner.nextInt();
            if (min == null && j >= 0)
                min = Math.min(n - k, i);
            list.add(j);
        }

        if (min == null) {
            System.out.println();
            System.out.println(Math.abs(list.get(list.size() - k)));
        } else {
            System.out.println(IntStream.rangeClosed(0, min)
                    .map(i -> {
                        int min1 = list.get(i);
                        int max1 = list.get(i + k - 1);
                        return min1 < 0 && 0 <= max1 ? max1 - min1 + (-min1 > max1 ? max1 : -min1) : min1 < 0 ? -min1 : max1;
                    }).min()
                    .getAsInt());
        }
    }
}

Measured memory_bytes: 61856
import math
def main():
  n = int(input())
  sum = 0
  for i in range(1,n+1):
    for j in range(1,n+1):
      g = math.gcd(i,j)
      for k in range(1,n+1):
        sum += math.gcd(g,k)
  print(sum)

if __name__ == "__main__":
  main()

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

int main()
{	
	int n;
	int a[200000] = {0};
	cin >> n;
	for ( int i = 0; i < n; i++)
	{ 
		cin >> a[i];
	}

	int max = a[1] - a[0];
	int min = a[0];

	for (int j = 1; j < n; j++ )
	{
			if ( (a[j]-min) > max )
			{
				max = a[j] - min;
			}
			if ( a[j] < min )
			{
				min = a[j];
			}
	}

	cout << max << endl;

	return 0;
}


Measured memory_bytes: 3872
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

#define MAXN 100006
double dist[MAXN];

struct comp {
   inline bool operator () (int v, int w) const {
      if (dist[v] != dist[w]) return dist[v] < dist[w];
      return v < w;
   }
};

void dijkstra (int n, vector<pair<int,double> > *adj, int src) {
   REP(i,0,n+1) {
      dist[i] = 1e30;
   }
   dist[src] = 0;
   set<int,comp> q;
   q.insert(src);
   while (!q.empty()) {
      int v = *(q.begin());
      q.erase(q.begin());
      FOREACH(it,adj[v]) {
         double d = dist[v] + it->se; int w = it->fi;
         if (d < dist[w]) {
            q.erase(w);
            dist[w] = d;
            q.insert(w);
         }
      }
   }
}

const int N = 1024;
ll x[N], y[N], r[N];

double di (int i, int j) {
   return sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
}

vector<pair<int,double> > adj[N];

int main () {
   cin >> x[0] >> y[0] >> x[1] >> y[1];
   r[0] = r[1] = 0;
   wez(n);
   REP(i,2,n+1) cin >> x[i] >> y[i] >> r[i];
   REP(i,0,n+1) FOR(j,i) {
      double d = max(0.0, di(i,j) - r[i] - r[j]);
      adj[i].pb(mp(j,d));
      adj[j].pb(mp(i,d));
   }
   dijkstra(n,adj,0);
   cout << setprecision(11) << fixed << dist[1];
}

Measured memory_bytes: 16384
#include <iostream>

using namespace std;

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

    long long minimum_steps = n - 1;
    for(long long i = 1; i*i <= n; i++)
    {
        if(n%i == 0)
        {
            long long steps_here = (i - 1) + (n/i - 1);

            minimum_steps = min(minimum_steps, steps_here);
        }
    }

    cout << minimum_steps << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){

    int n;
    vector<int> input;
    double sum = 0;
    cin >> n;
    for(int i=0; i<n; i++) {
        int temp;
        cin >> temp;
        input.push_back(temp);
        sum += temp;
    }
    
    int ave;
    if(sum >= 0) ave = (int)((sum/n)+0.5);
    else         ave = (int)((sum/n)-0.5);

    int result = 0;
    for(int i=0; i<n; i++) {
        result += (input[i]-ave)*(input[i]-ave);
    }
    
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 256
/**
 *    author:  Sanchit Sinha
 *    created: 26.09.2020 21:45:56       
**/
#include "bits/stdc++.h"
using namespace std; 

#define ll long long 
ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
inline ll gcd(ll a,ll b) {if(b==0)return a;a%=b;return gcd(b,a);}
inline ll max(ll a,ll b) {return((a>b)?a:b);}
inline ll min(ll a,ll b) {return((a>b)?b:a);}
const ll N=1e5+11;
ll sz[N] , parent[N];
void make_set(ll node){
        parent[node] = node;
        sz[node] = 1;
}
ll find_set(ll a){
        if(a==parent[a]) return a;
        return parent[a]=find_set(parent[a]);
}
void union_set(ll a , ll b){
        ll p1=find_set(a);
        ll p2=find_set(b);
        if(p1!=p2){
                if(sz[p2]>sz[p1]) swap(p1,p2);
                parent[p2]=p1;
                sz[p1]+=sz[p2];
                sz[p2]=0;
        }
}
ll n,m;
int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>n>>m;
        for(ll i=1;i<=n;i++) make_set(i);
        for(ll i=0;i<m;i++){
                ll x,y;
                cin>>x>>y;
                union_set(x,y);
        }
        set<ll> p;
        for(ll i=1;i<=n;i++) {
                p.insert(find_set(i));
        }
        cout << (int)p.size() - 1<<"\n";
        return 0;
}


Measured memory_bytes: 8812
def rec(A,n):
    if n==0:
        return A
    else:
        return rec(draw(A),n-1)

def draw(A):
    l=[]
    for i in range(len(A)-1):
        a=(A[i+1][0]-A[i][0])/3
        b=(A[i+1][1]-A[i][1])/3
        u0=(a,b)
        u60=(a*(1/2)-b*(3**(1/2)/2),a*(3**(1/2)/2)+b*(1/2))
        u300=(a*(1/2)+b*(3**(1/2)/2),-a*(3**(1/2)/2)+b*(1/2))
        
        P=(A[i][0]+u0[0],A[i][1]+u0[1])
        Q=(P[0]+u60[0],P[1]+u60[1])
        R=(Q[0]+u300[0],Q[1]+u300[1])

        l.extend([A[i],P,Q,R])
    l.append(A[-1])   
    return l

n=int(input())
A=[(0.0,0.0),(100.0,0.0)]
B=rec(A,n)

for P in B:
    print(f'{P[0]} {P[1]}')


Measured memory_bytes: 6020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> inputString = Arrays.asList(br.readLine().split(""));
            List<Integer> numbers = new ArrayList<>();

            for (String operator : inputString) {
                numbers.add(Integer.parseInt(operator + "1"));
            }

            int sum = 0;

            for (int number : numbers) {
                sum += number;
            }

            System.out.println(sum);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

using ll = long long;

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

  int N;
  cin >> N;

  std::vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }

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

  ll cnt = 0;
  for (int j = 0; j < N; j++) {
    ll d1 = lower_bound(A.begin(), A.end(), B.at(j)) - A.begin();
    ll d2 = C.end() - upper_bound(C.begin(), C.end(), B.at(j));
    cnt += d1 * d2;
  }

  cout << cnt << '\n';
}


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

// vector<int> dp(100000, 1e9);

int main()
{
    bool flg = true;
    ll N;
    ll A[1005];
    cin >> N;
    rep(i,N){
        cin >> A[i];
        if(A[i]%2 ==0){
            if(A[i]%3 == 0 || A[i]%5 == 0){
            }
            else
                flg = false;
        }
    }

    if(flg)
        printf("APPROVED");
    else
        printf("DENIED");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    string S;cin>>S;
    string ans="";
    int N=S.size();
    REP(i,N){
        if(S[i]=='0')ans+='0';
        if(S[i]=='1')ans+='1';
        if(ans.size()!=0&&S[i]=='B')ans=ans.substr(0,ans.size()-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import Counter
from scipy.special import comb

s = input()
A = list(map(int, input().split()))

d = Counter(A)

sum_c = 0
for v in d.values():
    if v >= 2:
        sum_c += comb(v, 2, exact=True)

for a in A:
    x = sum_c - comb(d[a], 2, exact=True) + comb(d[a]-1, 2, exact=True)
    print(x)

Measured memory_bytes: 66208
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n,d;
    cin>>n>>d;
    d*=d;
    int c=0;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        a*=a;
        b*=b;
        a+=b;
        if(a<=d)
        c++;
    }
    cout<<c;
}

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

int a[10];
int k;

int main() {
	for(int i=1; i<=5; i++) cin>>a[i];
	cin>>k;
	for(int j=1; j<=5; j++)
		for(int i=j+1; i<=5; i++)
			if(abs(a[i]-a[j])>k) {
				cout<<":(";
				return 0;
			}
	cout<<"Yay!";




	return 0;
}


Measured memory_bytes: 256
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \

*/

#import<bits/stdc++.h>
typedef long long ll;
#define num 10000010
#define root 10000
#define forll(i,a,b,c) for(int i=a; i<=b; i+=c)
#define forll2(i,a,b,c) for(int i=a; i>=b; i-=c)
#define pb(n) push_back(n)

using namespace std;

int main()
{
  int n;
  string a;
  cin>>n;
  int ac=0,wa=0,tle=0,re=0;
  while(n--)
  {
    cin>>a;
    if(a=="AC") ac++;
    else if(a=="WA") wa++;
    else if(a=="TLE") tle++;
    else if(a=="RE") re++;
  }
  cout<<"AC x "<<ac<<"\nWA x "<<wa<<"\nTLE x "<<tle<<"\nRE x "<<re<<"\n";
}


Measured memory_bytes: 3636
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



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

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int l, m, n,i,ans;
	while (~fscanf(stdin, "%d", &l), l != 0) {
		ans = 0;
		for(i=1;i<=12;i++){
			fscanf(stdin, "%d%d", &m, &n);
			if (ans) continue;
			l -= m - n;
			if (l <= 0) ans = i;
		}
		if(ans) P(d, ans);
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007;
#define inf (1LL<<60)
using namespace std;

struct flower
{
    ll hi;
    ll bty;
};

ll solve(vector<flower>& v,int n)
{
    vector<ll> dp(n);
    map<ll,ll> m;
    dp[0]=v[0].bty;
    m[v[0].hi]=dp[0];
    ll ans=dp[0];
    for(int i=1;i<n;i++)
    {
        dp[i]=v[i].bty;
        auto it=m.lower_bound(v[i].hi+1);
        if(it!=m.begin())
        {
            it--;
            dp[i]+=it->second;
        }
        m[v[i].hi]=dp[i];
        it=m.upper_bound(v[i].hi);
        while(it!=m.end()&&it->second<=dp[i])
        {
            auto temp =it;
            temp++;
            m.erase(it);
            it=temp;
        }
        ans=max(ans,dp[i]);
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    vector<flower> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i].hi;
    for(int i=0;i<n;i++)
        cin>>v[i].bty;
    cout<<solve(v,n);
    return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<int> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];

    vec<int> c(M), d(M);
    rep(i, M) cin >> c[i] >> d[i];

    auto mhtn = [&](int x0, int y0, int x1, int y1) {
        return abs(x0 - x1) + abs(y0 - y1);
    };

    vec<int> ans(N,1e9+7);

    rep(i,N)rep(j,M){
        int diffj = mhtn(a[i],b[i],c[j],d[j]);
        if(ans[i] == 1e9+7) ans[i] = j;
        else {
            int diffb = mhtn(a[i],b[i],c[ans[i]],d[ans[i]]);
            if(diffb > diffj) ans[i] = j;
        }
    }
    rep(i,N) cout << ans[i]+1 << '\n';
}


Measured memory_bytes: 3608
n,m = map(int, input().split())
d = {}
ans = 0
for _ in range(n):
  a,b = map(int, input().split())
  if a in d:
    d[a] += b
  else:
    d[a] = b

d = sorted(d.items(), key= lambda x: x[0])

for i in range(len(d)):
  if m >= d[i][1]:
    ans += d[i][0] * d[i][1]
    m -= d[i][1]
  else:
    ans += d[i][0] * m
    break
print(ans)

Measured memory_bytes: 24152
#include<iostream>
	#include<vector>
	#include<algorithm>
	#include<string>
	#include<cmath>
	#include<map>
	#include<cstdio>
	#include<stack>
	#include<queue>
	#include<fstream>
	#include<cstdio>
	#include<deque>
	#include<iomanip>
	#include <numeric>
	//#include<bits/stdc++.h>

	using namespace std;
	#define ok1 printf("ok1\n");
	#define ok2 printf("ok2\n");
	#define M 1000000000000000000LL
	#define rep(i,n) for(int i=0;i<n;i++)
	#define REP(i,s,n) for(int i=(s);i<(n);i++)
	#define repr(i,n) for(int i=n-1;i>=0;i--)
	#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
	#define all(a) (a).begin(),(a).end()
	#define reall(a) (a).rbegin(),(a).rend()
	#define pb push_back
	#define pf push_front
	#define MIN(a,b) a=min((a),(b))
	#define MAX(a,b) a=max((a),(b))
	#define SIZE(v) (int)v.size()
	const double pi = acos(-1.0);

	typedef vector<int> vi;
	typedef vector<string> vs;
	typedef long long ll;
	typedef vector<ll> vll;
	typedef vector<vi> vvi;
	typedef vector<vll> vvll;
	typedef deque<ll> dll;
	typedef pair<ll, ll> P;
	const ll mod = 1e9 + 7;
	ll dx[4] = {1,0,-1,0};
	ll dy[4] = {0,1,0,-1};


	int main() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		
		ll n,x,y;
		cin >> n;
		REPR(i, sqrt(n) + 1, 1) {
			if (n % i == 0) {
				x = i;
				break;
			}
		}
		y = n / x;
		x = max(x, y);
		string s = to_string(x);
		cout << s.size() << endl;
		return 0;
	}	
	

Measured memory_bytes: 256
s = input()
t = input()
n = len(s)
r=[-1]*26
r2=[-1]*26
abcd = 'abcdefghijklmnopqrstuvwxyz'

def f(l,l2,R):
  for i in range(n):
    if R[abcd.index(l[i])]==-1 or R[abcd.index(l[i])]==l2[i]:
       R[abcd.index(l[i])]=l2[i]
    else:
       print("No")
       exit()

f(s,t,r)
f(t,s,r2)
print("Yes")

Measured memory_bytes: 41840
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int blank(const vi& table,int num)
{
	rep(i,table.size()-num+1){
		bool flg=true;
		rep(j,num)
			if(table[i+j])
				flg=false;
		if(flg)
			return i;
	}
	return -1;
}

int main()
{
	vi table(17);
	deque<int> customers;
	vi res(100);
	rep(t,1000){
		rep(i,table.size())
			table[i]=max(table[i]-1,0);
		if(t<=500 && t%5==0)
			customers.push_back(t/5);
		while(customers.size()){
			int customer=customers[0];
			int num=customer%5==1?5:2;
			int index=blank(table,num);
			if(index==-1)
				break;;
			res[customer]=t-customer*5;
			rep(i,num)
				table[index+i]=17*(customer%2)+3*(customer%3)+19;
			customers.pop_front();
		}
	}
	
	for(int n;cin>>n;)
		cout<<res[n]<<endl;
	
	return 0;
}

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

using namespace std;

struct edge
{
  int u, v, cost;

  edge(int u, int v, int c) : u(u), v(v), cost(c) {}
};

const int INF = 1 << 30;

int main()
{
  int N, C;
  int A[200], O[200], B[200], S[200], D[200];

  auto bellman_ford = [&]()
  {
    vector< edge > edges;
    vector< int > v(N, INF), lastupdate(N, -1);
    v[0] = 0, lastupdate[0] = 0;

    for(int i = 0; i < C; i++) {
      if(O[i] == 1) swap(A[i], B[i]);
      edges.emplace_back(B[i], A[i], 0);
      if(S[i] == 0) edges.emplace_back(B[i], A[i], -D[i]);
      else edges.emplace_back(A[i], B[i], D[i]);
      if(O[i] == 1) swap(A[i], B[i]);
    }

    for(int i = 0; i <= N; i++) {
      for(auto &e : edges) {
        if(v[e.u] + e.cost < v[e.v]) {
          v[e.v] = v[e.u] + e.cost;
          lastupdate[e.v] = i;
        }
      }
    }

    int ret = 0;
    for(int i = 0; i < N; i++) {
      if(lastupdate[i] == N) return (-1);
      if(v[i] < 0) return (-1);
      ret = max(ret, v[i]);
    }
    return (ret);
  };

  cin >> N >> C;
  vector< int > undefined;
  for(int i = 0; i < C; i++) {
    string str;
    cin >> str;
    int tail = 0, a = 0, b = 0, o, s, d = 0;
    while(isdigit(str[tail])) a = a * 10 + str[tail++] - '0';
    if(str[tail] == '*') o = 2;
    else if(str[tail] == '<') o = 0, ++tail;
    else o = 1, ++tail;
    ++tail;
    while(isdigit(str[tail])) b = b * 10 + str[tail++] - '0';
    if(str[tail] == '+') s = 0;
    else s = 1;
    ++tail;
    while(tail < str.size()) d = d * 10 + str[tail++] - '0';
    A[i] = --a, B[i] = --b, O[i] = o, S[i] = s, D[i] = d;
    if(o == 2) undefined.push_back(i);
  }
  int ret = -1;

  for(int i = 0; i < (1 << undefined.size()); i++) {
    for(int j = 0; j < undefined.size(); j++) O[undefined[j]] = (i >> j) & 1;
    ret = max(ret, bellman_ford());
  }

  if(ret >= INF) cout << "inf" << endl;
  else cout << ret << endl;
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  multimap<long long, long long> patterns;
  long long a, b;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    patterns.insert(make_pair(a, b));
  }
  long long ans = (long long)0;
  while (M) 
  {
    for (auto el : patterns) 
    {
      if (M >= el.second) {
        M -= el.second;
        ans += (el.first * el.second);
      } else {
        ans += (el.first * M);
        M = 0;
        break;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6528
n = int(input())
p = list(map(int, input().split()))
q = [None]*n
q[0] = p[0]
count = 1

for i in range(1, n):
    q[i] = min(q[i-1], p[i])
    if p[i] <= q[i]:
        count += 1

print(count)


Measured memory_bytes: 26012
#include <stdio.h>
int main(){
	int n, a[100],i;
	while (1)
	{
		scanf("%d", &n);
		if (n<=100)
		{
			break;
		}
	}
	for (i = n; i > 0; i--)
	{
		scanf("%d", &a[i]);
	}
	for (i = 1; i <= n; i++)
	{
		printf("%d", a[i]);
		if (i < n)
		{
			printf(" ");
		}
	}
	puts("");
	return 0;
}

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

int main(){
  
  char A, B;
  cin >> A >> B;
  
  if (A=='H'){
    cout << B << endl;
  }
  else {
    if (B=='H'){
      cout << 'D' << endl;
    }
    else {
      cout << 'H' << endl;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>

using namespace std;

int main()
{
  while(true){
    int n;
    bool ng = false;
    bool adj[32][32] = {{false,},};
    bool exist[32] = {false,};
    int in[32] = {0,};
    int out[32] = {0,};
    cin >> n;
    if( n == 0 ) break;
    string s;
    for(int i = 0; i < n; ++i){
      cin >> s;
      int src=s[0]-'a';
      int dst=s[s.length()-1]-'a';
      exist[ src ] = exist[ dst ] = true;
      adj[ src ][ dst ] = true;
      in[ dst ]++;
      out[ src ]++;
    }
    bool vis[32]={false,};
    queue<int> qs;
    qs.push(s[0]-'a');
    vis[s[0]-'a']=true;
    while(!qs.empty()){
      int now=qs.front();qs.pop();
      for(int i=0;i<32;++i){
	if(adj[now][i]&&!vis[i]){
	  vis[i]=true;
	  qs.push(i);
	}
      }
    }
    for(int i = 0; i < 32; ++i){
      if( exist[i] ){
	if( !vis[i] ) ng = true;
	if( (in[i]-out[i]) != 0 ){
	  ng=true;
	}
      }
    }
    if( ng ){
      cout << "NG" << endl;
    }else{
      cout << "OK" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
using Int = long long int;
map< int64_t, Int > prime_factor(int64_t n) {
  map< int64_t, Int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
Int gcd(Int a, Int b) {
 return b != 0 ? gcd(b, a % b) : a;
}

int main(){
  Int a,b;cin >> a >> b;
  set<Int> ai;

  Int gc = gcd(a,b);
  for(auto &i:prime_factor(gc)){
    while(i.second--){
      ai.insert(i.first);
    }
  }
  cout << ai.size()+1 << endl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int N;
  cin >> N;
  string answer = "No";

  int S = 0;
  for (int i = 0; i <= 9; i++) {
    int n = 1;
    for (int j = 0; j < i; j++) {
      n *= 10;
    }
    S += (N / n) % 10;
  }

  if (S > 0 && N % S == 0) answer = "Yes";
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
bars = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    bars[a - 1].append(b - 1)
    bars[b - 1].append(a - 1)

# 併せられるものは足し算して合わせる
# 直線形式に変更する
points = [0 for _ in range(N)]
for _ in range(Q):
    i, point = map(int, input().split())
    points[i - 1] += point
# print(bars)
# print(points)
# counters = [0 for _ in range(N)]
seen_points = [False for _ in range(N)]
queue = deque([0])
while queue:
    now_index = queue.pop()
    seen_points[now_index] = True
    for next_index in bars[now_index]:
        if not seen_points[next_index]:
            points[next_index] += points[now_index]
            queue.append(next_index)
# print(points)
print(*points)


Measured memory_bytes: 95820
#include <stdio.h>
#include <stdlib.h>

int main (void) {
    int h, n, i, sum=0;
    scanf("%d%d", &h, &n);
    int a[n];
    for ( i=0; i<n; i++ ) {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    if ( h > sum )
        printf("No\n");
    else
        printf("Yes\n");

    return EXIT_SUCCESS;
}


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

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], c = rd[1];
  struct Program { int s, t, c; }
  auto p = new Program[](n);
  bool[int][int] h;

  foreach (i; 0..n) {
    auto rd2 = readln.splitter;
    auto si = rd2.front.to!int; rd2.popFront();
    auto ti = rd2.front.to!int; rd2.popFront();
    auto ci = rd2.front.to!int;
    p[i] = Program(si, ti, ci);
    h[ci][ti] = true;
  }

  auto m = 10^^5*2+1;
  auto s = new int[](m);

  foreach (pi; p) {
    s[pi.s*2-(pi.c in h && pi.s in h[pi.c] ? 0 : 1)]++;
    s[pi.t*2]--;
  }

  foreach (i; 1..m) s[i] += s[i-1];

  writeln(s.reduce!max);
}


Measured memory_bytes: 12796
import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def prob():  # WA 2
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    L = getIntList()
    d.dmp((L), 'L')
    L.sort()
    count = 0
    for i in range(N):
        count += min(L[i*2], L[i*2+1])
    return count


ans = prob()
print(ans)


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

const int W = (int) 1e5 + 5;
const int N = 105;
const ll INF = (ll) 1e13;
pair<int,int> a[N];
ll dp[N][W];
int n,w;

ll solve(int idx , ll sum)
{
    if(sum > w)
        return -INF;
    if(idx == n)
        return 0;
    ll &ret = dp[idx][sum];
    if(ret != -1)
        return ret;
    return ret = max(a[idx].second + solve(idx+1,sum + a[idx].first),solve(idx+1,sum));
}

int main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> w;
    for(int i = 0;i < n;++i)
    {
        int x,y;
        cin >> x >> y;
        a[i] = {x,y};
    }
    memset(dp,-1,sizeof dp);
    cout << solve(0,0);
    return 0;
}


Measured memory_bytes: 82304
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);

    int n = stdIn.nextInt();

    if (n % 2 == 0) {
      System.out.println((n - 1) / 2);
    } else {
      System.out.println(n / 2);
    }
  }
}


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

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    ll x,y;
    if((a+b)<k){
        x=0;
        y=0;
    }else if(a<k){
        x=0;
        y=b+a-k;
    }else{ //a>k
        x=a-k;
        y=b;
    }
    cout<<x<<" "<<y<<endl;

}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define N 300050
#define M 200
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
#define MOD mod
using namespace std;
int a,v,b,w,t;
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    cin>>a>>v>>b>>w>>t;
    if(a>b)swap(a,b);
    a += v*t;
    b += w*t;
    if(a>=b){
        cout<<"YES";
    }
    else cout<<"NO";
  	return 0;
}



Measured memory_bytes: 3628
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int a,b,c,hasil;

int main()
{
	while(scanf("%d %d", &a, &b) != EOF)
	{
		hasil=1;
		c=a+b;
		while(c>=10)
		{
			c=c/10;
			hasil++;
		}
		printf("%d\n",hasil);
	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> s(3);
    for (int i = 0; i < 3; i++) cin >> s[i];

    for (int i = 0; i < 3; i++) cout << s[i][0];
    cout << endl;
}

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

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  ll l, r;
  cin >> l >> r;
  if (r - l + 1 >= 2019) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> a(r - l + 1);
  rep(i, r - l + 1) { a[i] = (l + i) % 2019; }
  ll ans = inf;
  rep(i, a.size() - 1) {
    for (int j = i + 1; j < a.size(); j++) {
      ll tmp = a[i] * a[j] % 2019;
      if (ans > tmp) ans = tmp;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3656
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 #define trace(x) cerr << #x << ": " << x << " " << endl;

#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}


int32_t main()
{
    IOS
  
            
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<n;++i)
    {
        if(s[i]=='L')
        {
            int count=1;
            for(int j=i+1;j<n;++j)
            {
                if(s[j]=='L')
                {
                    count++;
                    if(j==n-1)
                        i=n-1;
                }
                else
                {
                    i=j-1;
                    break;
                }
            }
            ans+=count-1;
        }
    }
    for(int i=0;i<n;++i)
    {
        if(s[i]=='R')
        {
            int count=1;
            for(int j=i+1;j<n;++j)
            {
                if(s[j]=='R')
                {
                    count++;
                    if(j==n-1)
                        i=n-1;
                }
                else
                {
                    i=j-1;
                    break;
                }
            }
            ans+=count-1;
        }
    }
    cout<<min(n-1,ans+2*k);
}

Measured memory_bytes: 512
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var M = one[1];
	
	var connect = new Array(M);
	for(var i = 0; i < M; i++){
		var tmp = nextIntArray();
		var connectCount = tmp[0];
		tmp.shift();
		connect[i] = {
			no : i,
			count : connectCount,
			list : tmp
		};
	}
	var onlist = nextIntArray();
	var output = 0;
	for(var i = 0; i < (1 << N); i++){
		var select = [];
		for(var j = 0; j < N; j++){
			if((i & (1 << j)) != 0){
				//選ぶ(j番目のスイッチをON)
				select.push(j);
			}
		}
		var onCount = 0;//すべての電球がON
			for(var k = 0; k < M; k++){
				var switchCount = 0;
				for(var l = 0; l < connect[k].count; l++){
					if(select.indexOf(connect[k].list[l] - 1) != -1){
						switchCount++;//つながってるスイッチがON
					}
				}
				if(switchCount % 2 == onlist[k]){
					onCount++;//電球を1個ON
				}
			}
		if(onCount == M){
			output++;
		}
	}
	myout(output);
}


Measured memory_bytes: 33272
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	string a,b;
	cin >> a >> b;
	REP(i,b.length()) cout << a[i] << b[i];
	if(a.length()>b.length()) cout << a[a.length()-1];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    vector<int> x(5);
    rep(i,5) cin >> x[i];
    rep(i,5) if(x[i] == 0) cout << i+1 << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 100001
#define MOD 1000000007
int N,K;
vi adj[maxn];
int par[maxn],depth[maxn],sz[maxn];
int ans[maxn];



int cur = 1;
void order(int x,int p){

	par[x] = p;
	aFOR(i,adj[x]){
		if (i != p){
			depth[i] = depth[x]+1;
			order(i,x);
		}
	}
}



void dfs(int x,int p){
	if (p == -1) ans[x] = K;
	else{
		int num = 0;
		if (depth[x] > 1) num = 2;
		else num = 1;
		
		
		num += sz[par[x]];
		
		ans[x] = K - num;
	}
	sz[par[x]]++;
	aFOR(i,adj[x]){
		if (i != p) dfs(i,x);
	}
	//sz[x]++;
}
		
int main(){
	fast;
	
	cin>>N>>K;
	
	FOR(i,0,N-2){
		int a,b;cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	
	order(1,-1);

	
	dfs(1,-1);
	
	ll lans = 1;
	FOR(i,1,N){
		//cout<<ans[i]<<' ';
		lans *= ans[i];
		lans %= MOD;
	}
	
	cout<<max(lans,(ll)0);
	
	
}



Measured memory_bytes: 10752
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
ans = float("inf")
for bit in range(1 << (h - 1)):
    cnt = 0
    l = [0] * h
    for i in range(h - 1):
        if bit & (1 << i):
            cnt += 1
        l[i + 1] = cnt
    m = max(l) + 1
    cnt2 = m - 1
    c = [0] * m
    for j in range(w):
        cur = [0] * m
        for i in range(h):
            c[l[i]] += int(s[i][j])
            cur[l[i]] += int(s[i][j])
            if c[l[i]] > k:
                cnt2 += 1
                for i in range(m):
                    c[i] = cur[i]
    ans = min(ans, cnt2)
print(ans)

Measured memory_bytes: 75552
// 平均点

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int point;
    int sum = 0;

    for (int i=0; i<5; i++) {
        cin >> point;
        sum += max(point, 40);
    }
    cout << sum / 5 << "\n";
    return 0;
}


Measured memory_bytes: 3100
N = int(input())

num_list = [int(i) for i in input().split()]

cnt = 0
flag = 0

while flag == 0:
    for i in range(N):
        if num_list[i] % 2 == 1:
            flag = 1
            break
        else:
            num_list[i] = num_list[i] / 2
            if i == N - 1:
                cnt += 1

print(cnt)


Measured memory_bytes: 2940
using System;

namespace diverta2019
{
	class Program
	{
		static void Main(string[] args)
		{
			// 入力
			int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			int N = inp[0];
			int K = inp[1];
			// 処理
			int answer;
			if(K==1){
				// 1人に配る場合は差がないので0
				answer = 0;
			}else{
				// そうでない場合は(N-K+1)-1
				answer = N - K;
			}
			Console.WriteLine(answer);
		}
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD 1000000007
#define INV_10 299473306
#define INF 1000000000
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string a, b;
	cin >> a >> b;
	string c=b.substr(0, b.length()-1);
	if(c==a)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 3644
n, m = map(int, input().split())

if min(n, m) == 1:
    if max(n, m) == 1:
        print(1)
    else:
        print(max(n, m)-2)
elif min(n, m) == 2:
    print(0)
else:
    print((n-2)*(m-2))

Measured memory_bytes: 3064
# include <stdio.h>
int main(void){
    int a,b,c,x;
    scanf("%d %d %d",&a,&b,&c);
    if(a > b){
    x = a;
    a = b;
    b = x;
    }
    if(b > c){
    x = b;
    b = c;
    c = x;
    }
    if(a > b){
    x = a;
    a = b;
    b = x;
    }printf("%d %d %d\n",a,b,c);









    return 0;
}

Measured memory_bytes: 596
#include <iostream>

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

using namespace std;

int a[10];
int r[10];
int r_i;
int l[10];
int l_i;

bool is_greater(int array[],int n){
	reep(i,1,n){
		if(array[i]<array[i-1]){
			return false;
		}
	}
	return true;
}

bool dfs(int n){
	if(n==10){
		if(is_greater(r,r_i)&&is_greater(l,l_i)){
			return true;
		}else{
			return false;
		}
	}

	r[r_i++] = a[n];
	if(dfs(n+1)){
		return true;
	}
	r_i--;

	l[l_i++] = a[n];
	if(dfs(n+1)){
		return true;
	}
	l_i--;
	return false;
}

int main(){
	int N;
	cin >> N;
	while(N--){
		rep(i,10){
			cin >> a[i];
		}
		r_i = l_i = 0;
		if(dfs(0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main()
{
  ll a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b)
    cout << "Zero" << endl;
  else if (b < 0 && abs(b - a) % 2 == 0)
    cout << "Negative" << endl;
  else
    cout << "Positive" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  	int N;
  	scanf("%d",&N);
  	if(((N / 100) == 7) || ((N % 100) / 10 == 7) || ((N % 10) == 7)){
  		printf("Yes\n");
  	} else { 
    	printf("No\n");
    }
  	return 0;
}


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

int main()
{
    int n, i;

    cin>>n;

    vector<int>P(n);

    for(i=0; i<n; i++)
    {
        cin>>P.at(i);
    }
    int j, k=0;

    for(j=0; j<n; j++)
    {
        if(P.at(j)!=j+1)
            k++;
    }
    if (k<=2)
        cout<<"YES"<<endl;

    else
        cout<<"NO"<<endl;

        return 0;
}

Measured memory_bytes: 3616
let () =
  let res = ref [] in
  let s = Scanf.scanf "%s\n" (fun x -> x) in
  let w = Scanf.scanf "%d\n" (fun x -> x) in
  for i = 0 to (String.length s) -1 do
    if i mod w = 0 then
      res := !res @ [s.[i]]
    else
      ()
  done;
  List.iter (Printf.printf "%c") !res;
  Printf.printf "\n"
  
    
          

Measured memory_bytes: 2688
from itertools import combinations
N,X,Y = map(int, input().split())
ans = [0]*(N-1)
for a,b in combinations(range(N),2):
  c = min([abs(a-b), abs(X-1-a)+abs(Y-1-b)+1, abs(Y-1-a)+abs(X-1-b)+1])
  ans[c-1] += 1
for i in ans: print(i)

Measured memory_bytes: 46940