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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

string split(const string &str, const string &delim){
    string res;
    size_t current = 0, found, delimlen = delim.size();
    while((found = str.find(delim, current)) != string::npos){
        res+=string(str, current, found - current) + " " + delim + " ";
        current = found + delimlen;
    }
    res+=string(str, current, str.size() - current);
    return res;
}

int n,c;
typedef tuple<int,int,int> edge;
vector<edge> es;
vector<int> dist;

void bellmanford(){
    fill_n(dist.begin(),n,inf);
    dist[0]=0;

    for(int i=0; i<n; ++i){
        for(edge& e:es){
            int a=get<0>(e),b=get<1>(e),w=get<2>(e);
            if(dist[a]+w<dist[b]) dist[b]=dist[a]+w;
        }
    }
}

void add_edge(string& constraint){
    constraint=split(constraint,">=");
    constraint=split(constraint,"<=");
    constraint=split(constraint,"+");
    constraint=split(constraint,"-");

    int a,b,d;
    string tmp1,tmp2;
    stringstream ss(constraint);
    ss >> a >> tmp1 >> b >> tmp2 >> d;
    --a; --b;

    if(tmp1=="<=") es.push_back(make_tuple(b,a,0));
    else if(tmp1==">=") es.push_back(make_tuple(a,b,0));

    int w=-d;
    if(tmp2=="-"){
        w*=-1;
        swap(a,b);
    }
    if(tmp1=="<=") es.push_back(make_tuple(b,a,w));
    else if(tmp1==">=") es.push_back(make_tuple(a,b,w));
}

void solve(){
    cin >> n >> c;

    dist.resize(n);
    vector<string> unfixed;

    rep(i,0,c){
        string constraint;
        cin >> constraint;
        if(constraint.find("*")==string::npos) add_edge(constraint);
        else unfixed.push_back(constraint);
    }
    rep(v,1,n) es.push_back(make_tuple(v,0,0));

    vector<edge> es_=es;
    int ans=-1;
    rep(b,0,1<<unfixed.size()){
        es=es_;
        rep(i,0,unfixed.size()){
            string constraint=unfixed[i];
            if(1&(b>>i)) constraint.replace(constraint.find("*"),1,"<=");
            else constraint.replace(constraint.find("*"),1,">=");
            add_edge(constraint);
        }

        bellmanford();
        if(dist[0]<0) continue;
        rep(i,0,n) ans=max(ans,dist[i]);
    }
    if(ans==inf) cout << "inf" << endl;
    else cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a, b, c, x,cnt=0;
    cin >> a >> b >> c >> x;
    for (int i = 0; i <= 500 * a; i += 500) {
        for (int j = 0; j <= 100 * b; j += 100) {
            for (int k = 0; k <= 50 * c; k += 50) {
                if ((i + j + k) == x)cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<ll>size;

    UnionFind(int N){ //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
        	par.push_back(i);
        	size.push_back(1);
        }
    }

    ll root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        size[ry]+=size[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    ll getSize(ll x){
    	return size[root(x)];
    }
};

int main(){
	ll n,m;
	cin>>n>>m;
	ll a[m],b[m];
	for(ll i=0;i<m;i++){
		cin>>a[i]>>b[i];
		//tree.unite(a[i],b[i]);
	}
	ll ans[m+1];
	memset(ans,0,sizeof(m+1));
	ans[m]=n*(n-1)/2;
	UnionFind tree(n);
	for(int i=m-1;i>=0;i--){
	//	cout<<i<<endl;
		ans[i]=ans[i+1];
	//	cout<<"a"<<endl;
		if(tree.root(a[i])!=tree.root(b[i])){
		//	cout<<"aa"<<endl;
			ans[i] -= tree.getSize(a[i])*tree.getSize(b[i]);
			tree.unite(a[i],b[i]);
		}
	}
	for(ll i=1;i<m+1;i++)cout<<ans[i]<<endl;
}


Measured memory_bytes: 5484
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<functional>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end(), greater<int>());
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans = ans + l[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
   ;
    //サンプルコード;;
    //ABC093-B;;
    ;;
    int a, b, c;;;
    cin >> a >> b >> c;;;
    ;;
    int sum = a + b + c;;;
    int ans = 0;;;
    while(1){;;;
        if(sum%3==0 && sum/3>=max(max(a, b), c)){ cout << (ans) << endl;; return 0;;}
        sum += 2; ++ans;;
    ;};;
}

Measured memory_bytes: 256
_,*s=*$<
eval"_,*A="+_.split*?,
f=->i{s[i]&.chop&.bytes{|x|$*[i]=""<<y=s[i].sum-x-10;A[y-=65]+=1;f[i+1]if~0<A[x-=65]-=1;A[x]+=1;A[y]-=1}||puts(:Yes,$*)+exit}
f[0]
puts:No

Measured memory_bytes: 155244
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int a, b, n;
int dp[17][17];
int mp[17][17];

int main(void) {
  while(cin >> a >> b, !(a == 0 && b == 0)) {
    cin >> n;

    REP(i, 1, a + 1) REP(j, 1, b + 1) mp[i][j] = 0;
    REP(i, 0, n) {
      int j, k;
      cin >> j >> k;
      mp[j][k] = 1;
    }

    REP(i, 1, a + 1) {
      REP(j, 1, b + 1) {
        if(mp[i][j] == 1) dp[i][j] = 0;
        else {
          if(i == 1 && j == 1) {
            dp[i][j] = 1;
          } else if(i == 1) {
            dp[i][j] = dp[i][j - 1];
          } else if(j == 1) {
            dp[i][j] = dp[i - 1][j];
          } else {
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
          }
        }
      }
    }

    cout << dp[a][b] << endl;
  }

  return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

ll  lshiftmod(int x){
    ll res=1;
    rep(i,x)res=(res<<1)%MOD;
    return res;
}

int main(){

    int n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];

    ll ans=0;
    rep(i,60){
        vl num(2,0);
        rep(j,n)num[(a[j]>>i)&1]++;
        ans=(ans+((num[0]*num[1])%MOD)*lshiftmod(i))%MOD;
    }

    cout<<ans<<"\n";
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 mod
#define mod2 100000009
//#define endl "\n"
#define show(a) for(int i=0;i<a.size();i++) cout<<a[i & 1]<<" ";
#define fi first
#define se second
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>
#define pb push_back
#define pi pair<int,int>
#define si set<int>
#define sll set<ll>
#define pll pair<ll, ll>
#define sci(x) scanf("%d",&x)
#define scs(x)  scanf("%s", x)
#define scll(x) scanf("%I64d",&x)
#define all(v) v.begin(),v.end()
#define sot(v) sort(v.begin(), v.end())
#define maxheap priority_queue<int>
#define mp make_pair
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);
#define PI 3.1415926535
#define long_zero 0ll
#define long_one 1ll

inline int sbt(int x) {return __builtin_popcount(x);}

using namespace std;
using namespace __gnu_pbds;
#define FOR(i, j, k, in) for ( i=j ; i<k ; i+=in)
#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif
#define N 10003
bool ok;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

inline int mul(int a, int b, int m = mod) { return (a * b) % m; }
inline int add(int a, int b, int m = mod) { return (a + b) % m; }
inline int sub(int a, int b, int m = mod) { return (a - b + m) % m; }

bool Comparator (pair <int, int> x, pair <int, int> y) {
	return x.first < y.first;
}
const int mxN = 1e7;
int n, c[mxN + 1];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; (j += i) <= n; )
			++c[j];
	ll ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += (ll)i * c[i];
	cout << ans;
}

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

int A[1000000];
int H;

void maxHeapify(int i){
    int l = i*2;
    int r = i*2 + 1;
    int largest;
    if(l <= H && A[l] > A[i]){
        largest = l;
    } else {
        largest = i;
    }
    if(r <= H && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
    return;
}

void buildMaxHeap(){
    for (int i = H/2; i >= 1; i--){
        maxHeapify(i);
    }
}


int main() {
    cin >> H;
    rep(i, H){
        cin >> A[i+1];
    }
    buildMaxHeap();
    rep(i, H){
        cout << " " << A[i+1];
    }
    cout << endl;

    return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int h, w;
    cin >> h >> w;

    vector<vector<int>> v(h, vector<int>(w));
    int ct = 0;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            cin >> v[i][j];
        }
    using pii = pair<int, int>;
    vector<pair<pii, pii>> ans;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            if (i + 1 < h and v[i][j] & 1) {
                v[i][j]--, v[i + 1][j]++;
                ans.push_back({{i,     j},
                               {i + 1, j}});
            }
        }

    for (int j = 0; j < w; j++) {
        if (j + 1 < w and v[h - 1][j] & 1) {
            v[h - 1][j]--, v[h - 1][j + 1]++;
            ans.push_back({{h - 1, j},
                           {h - 1, j + 1}});
        }
    }

    cout << ans.size() << endl;
    for (auto x: ans) {
        cout << x.first.first + 1 << " " << 1 + x.first.second << " " << 1 + x.second.first << " "
             << 1 + x.second.second;
        cout << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL (vec)(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define eb emplace_back
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
int n,K;
ll check(T4 area,VL&x,VL&y){
  int u,d,r,l;
  tie(u,d,r,l)=area;
  int in=0;
  rep(i,n){
    bool yin=(u>=y[i] && d<=y[i]);
    bool xin=(r>=x[i] && l<=x[i]);
    in+=(yin && xin);
  }
  return in;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  
  cin>>n>>K;
  VL x(n),y(n);
  rep(i,n)cin>>x[i]>>y[i];

  ll res=LONG_MAX;
  rep(i,n){
    rep(j,n){
      rep(k,n){
        rep(m,n){
          ll u,d,r,l;
          u=max({y[i],y[j],y[k],y[m]});
          d=min({y[i],y[j],y[k],y[m]});
          r=max({x[i],x[j],x[k],x[m]});
          l=min({x[i],x[j],x[k],x[m]});
          T4 area=m_t(u,d,r,l);
          ll in=check(area,x,y);
          if(in>=K)chmin(res,1LL*abs(u-d)*abs(r-l));
        }
      }
    }
  }
  out(res);
  
  
  return 0;
}



Measured memory_bytes: 384
'''
参考
https://note.com/tanon_cp/n/n6b51b9a57076
'''
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
spl = 0                     # 1つ前の勇者の余力
B.append(0)                 # リストの要素数を調整

for i in range(N+1):
    ans += min(spl, A[i])   # まず1つ前の勇者の余力を討伐に充てる
    mst = max(0, A[i]-spl)  # モンスター残数

    ans += min(B[i], mst)
    spl = max(0, B[i]-mst)

print(ans)


Measured memory_bytes: 19156
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"sort"
)

var sc  = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	intBox := make([]int,n)
	for i:=0; i<n; i++ {
		intBox[i] = nextInt()
	}
	sort.Ints(intBox)
	total := 0
	for i:=0; i<len(intBox); i++ {
		total += intBox[i]
	}
	if total % 10 != 0 {
		fmt.Println(total)
	} else {
		for j:=0; j<len(intBox); j++ {
			if intBox[j] % 10 != 0 {
				fmt.Println(total-intBox[j])
				return
			}
		}
		fmt.Println(0)
		return
	}
}


Measured memory_bytes: 640
S=int(input())

if S<3:
    print(0)
    exit()

cnt=0

MOD = 10**9+7 
n = 10**4 
C1 = [1, 1]
C2 = [1, 1] 
inv = [0, 1] 
for i in range( 2, n + 1 ):
    C1.append( ( C1[-1] * i ) % MOD )
    inv.append( ( -inv[MOD % i] * (MOD//i) ) % MOD)
    C2.append( (C2[-1] * inv[-1]) %MOD )
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return C1[n] * C2[r] * C2[n-r] % MOD

for i in range(S//3):
    S-=3
    cnt+=cmb(S+i,i)
    cnt%=MOD
print(cnt)

Measured memory_bytes: 10168
import java.util.Scanner;
import java.util.Arrays;
 
public class Main{
    public static void main(String[]args){
      Scanner sc = new Scanner(System.in);
      String s = sc.nextLine();
      Long n = sc.nextLong();
      boolean found = false;
      int ans = 0;
      for(int i = 0;i < Math.min(s.length(),n);i++){
          if(s.charAt(i) != '1'){
              ans = Character.getNumericValue(s.charAt(i));
              found = true;
           	  System.out.println(ans);
              break;
          }
      }
      //sが全て1のとき
      if(!found){System.out.println('1');}
    }  
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    cin >> a;
    cout << a/3 << endl;
}


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

int main(){
	int N, K, dmin;
	cin >> N >> K;
	vector<int> h(N);
	vector<int> csum(N);
	for(int i=0; i<N; i++){
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	//csum[0] = h[0];
	//for(int i=0; i<N; i++){
	//	csum[i] = csum[i-1] + h[i];
	//}
	dmin = 1000000000;
	for(int i=0; i+K-1<N; i++){
		dmin = min(dmin, h[i+K-1] - h[i]);
	}
	cout << dmin << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct edge{
	ll to,cost,t;
};

struct state{
	ll d,city,ag;
};

bool operator>(const state& a,const state& b){
    return a.d>b.d;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,m,s;
	cin>>n>>m>>s;
	vector<vector<edge>> g(n);
	rep(i,m){
		ll u,v,a,b;
		cin>>u>>v>>a>>b;
		u--,v--;
		g[u].push_back({v,a,b});
		g[v].push_back({u,a,b});
	}
	vector<ll> c(n),d(n);
	rep(i,n){
		cin>>c[i]>>d[i];
	}
	ll ma=1000;
	chmin(s,ll(ma));
	vector<vector<ll>> dist(n,vector<ll>(10001,inf));//j==maは銀貨無限枚
	priority_queue<state,vector<state>,greater<state>> que;
	dist[0][s]=0;
	que.push({0,0,s});
	while(!que.empty()){
		auto now=que.top();
		que.pop();
		ll v=now.city,ag=now.ag;
		if(dist[v][ag]<now.d) continue;
		for(auto to:g[v]){
			ll nag=ag;
			ll nt=to.t;
			if(nag==ma){
				if(chmin(dist[to.to][nag],dist[v][ag]+nt)){
					que.push({dist[to.to][nag],to.to,nag});
				}
				continue;
			}
			if(nag>=to.cost){
				if(chmin(dist[to.to][nag-to.cost],dist[v][ag]+nt)){
					que.push({dist[to.to][nag-to.cost],to.to,nag-to.cost});
				}
			}
			while(nag<ma){
				nag+=c[v];
				chmin(nag,ll(ma));
				nt+=d[v];
				if(nag>=to.cost){
					if(chmin(dist[to.to][nag-to.cost],dist[v][ag]+nt)){
						que.push({dist[to.to][nag-to.cost],to.to,nag-to.cost});
					}
				}
			}
		}
	}
	FOR(i,1,n){
		ll ans=inf;
		rep(j,ma+1) chmin(ans,dist[i][j]);
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 27964
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#define int long long
using namespace std;
int32_t main(){
	int n, ai;
	int max1 = 0, max2 = 0;
	map<int, int> mm;
	cin >> n;
	int big_max = 0;
	for (int i=0; i < n; i++){
		cin >> ai;
		mm[ai]++;
		if (mm[ai] == 2){
			if (ai > max1){
				max2 = max1;
				max1 = ai;
			}
			else if (ai > max2){
				max2 = ai;
			}
		}
		if (mm[ai] == 4){
			big_max = max(big_max, ai);
		}
	}
	cout << max(max1 * max2, big_max*big_max) << endl;
	return 0;
}

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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    lint up[200002];
    for(int i=0;i<=200000;i++) up[i]=0;

    int N;
    cin >> N;
    int P[200001];
    for(int i=1;i<=N;i++) cin >> P[i];
    for(int i=1;i<=N;i++) up[P[i]]=up[P[i]-1]+1;
    
    sort(up,up+N+1);
    cout << (N-up[N]) << endl;
    return 0;
}

Measured memory_bytes: 3840
n = int(input())
a = list(map(int, input().split()))
co = 0

for i in range(n):
    minv = a[i]
    mink = i
    for j in range(i, n):
        if a[j] < minv:
            minv = a[j]
            mink = j
    if a[i] != minv:
        a[i], a[mink] = a[mink], a[i]
        co += 1

print(*a)
print(co)


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

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Q,H,S,D;
double n;
pair<double ,double> per[5];
#define MP make_pair
map<double,ll> cost;
int main()
{
    scanf("%lld%lld%lld%lld",&Q,&H,&S,&D);
    scanf("%lf",&n);
    per[1]=MP(Q*4.0,0.25),per[2]=MP(H*2.0,0.5),per[3]=MP(S*1.0,1.0),per[4]=MP(D/2.0,2.0);
    cost[0.25]=Q,cost[0.5]=H,cost[1.0]=S,cost[2.0]=D;
    sort(per+1,per+5);
    int tmp=1;
    ll Ans=0;
    while(n>0.0 && tmp<=4){
        int res=0;
        //printf("n=%lf per[%d].second=%lf\n",n,tmp,per[tmp].second);
        if(n>=per[tmp].second){
            res=(int)floor(n/per[tmp].second);
            //printf("res=%d\n",res);
            n-=(double)res*per[tmp].second;
            Ans+=res*cost[per[tmp].second];
        }
        tmp++;
    }
    printf("%lld\n",Ans);
    return 0;
}


Measured memory_bytes: 256
/*
ID: dorijan1
TASK: tu napisi ime zadatka molim te molim te ali samo ako si na usaco training
LANG: C++11
*/
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define rand rund
#define pb push_back

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
const int MOD=1000000007;
const int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

ll raand()
{
	ll a=rand();
	a*=RAND_MAX;
	a+=rand();
    return a;
}

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

int sub(int a,int b)
{
	return (a-b+MOD)%MOD;
}

int add(int a,int b)
{
	return (a+b)%MOD;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=300010;
int n,w;
ll ma;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll dp[110][N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(raand()%MOD+13893829);
	cin>>n>>w;
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[0][0]=0;
	for (int i=0;i<n;++i)
	{
		int k,v;
		cin>>k>>v;
		for (int j=0;j<=1e5;++j) dp[i+1][j]=dp[i][j];
		for (int j=0;j<=1e5-v;++j)
		{
			dp[i+1][j+v]=min(dp[i+1][j+v],dp[i][j]+k);
			if (dp[i+1][j+v]<=w) ma=max(ma,j+v);
		}
	}
	cout<<ma;
}



Measured memory_bytes: 258048
import math
n = int(input())
li = sorted(list(map(int,input().split())), reverse = True)

if 0 in li:
    print(0)
else:
    ans = 1
    limit = 10**18
    for i in range(n):
        if li[i] > limit:
            ans = -1
            break
        else:
            ans = ans * li[i]
            limit = limit/li[i]
    if ans > 10**18:
        ans = -1
    print(ans)

Measured memory_bytes: 22332
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
 
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define T int t = 0; cin >> t; while(t--)
#define pr(a) for(int i = 0; i < (int)a.size(); ++i)cout << a[i] << " ";cout << endl;
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e15;
const ll mx = 1e3 + 1;
const ll inf = 1e9;
const int sz = 256;
const int max_k = 20;
typedef long long ll;

void input(){
    IOS;
    string s;
    cin >> s;
    int ans = 0;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')ans = 3;
    else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))ans = 2;
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')ans = 1;
    cout << ans << endl;
}

int main(){
    input();
    return 0;
} 
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


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

int main(){
    int N, T;
    int c, t;
    vector<int> vc;
    vector<int> vt;
    int ans = 2147483647;

    //input
    cin >> N >> T;
    for(int i = 0; i < N; i++){
        cin >> c >> t;
        if(t <= T && c < ans){
                ans = c;
        }
    }

    //output
    if(ans != 2147483647){
        cout << ans << endl;
    }else{
        cout << "TLE" << endl;
    }

}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXN = 1e5+2; //AREGLAAAAAAAAR!!!!

int main(){
	string s;
	cin>>s;
	s[0]='2';
	s[1]='0';
	s[2]='1';
	s[3]='8';
	cout<<s<<endl;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    ll a;
    long double b;
    cin>>a>>b;
    cout<<(ll)(a*b);
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  //解説みました
  int a[5];
  rep(i,5) cin >> a[i];
  int sa=0,ans=0;
  rep (i,5){
    ans += a[i];
    int amari = a[i]%10;
    if(amari!=0){
      sa = max(sa,10-amari);
      ans += 10-amari;
    }
  }
  cout << ans - sa << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    c*=2;
    ll ans=LLINF;
    rep(i,max(x,y)+1){
        ll X=max(0ll,x-i),Y=max(0ll,y-i);
        ll sum=X*a+Y*b+c*i;
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e13;
const lld MAXM = 2000;

struct edge   //コストの値がcostの頂点fromから頂点toへの(有向な)辺
{
	lld from;
	lld to;
	lld cost;

	edge()
	{
		from = 0;
		to = 0;
		cost = 0;
	}
};

lld n,m,r=1;    //グラフの頂点数,辺数,始点
lld d[1001];
edge es[MAXM];


void shortest_path(int r)
{
	for(int i = 1; i <= n; i++)
	{
		d[i] = INF;
	}

	d[r] = 0;

	for(int j = 0; j < n; j++)
	{
		bool update = false;

		for(int i = 0; i < m; i++)
		{
			edge e = es[i];

			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)  //辺の更新
			{
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}

		if (!update) break;   //辺の更新がなくなったらループ終了
	}

}



bool canINF()
{
	bool nega[1001] = {false};

	for(int i = 0; i < m; i++)
	{
		edge e = es[i];
		if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)  //辺の更新
		{
			nega[e.to]= true;
		}

		if (nega[e.from])
		{
			nega[e.to]= true;
		}
	}

	return nega[n];
}


int main()
{
	scanf("%lld %lld", &n,&m);
	for(int i = 0; i < m; i++)
	{
		lld a,b,c;
		scanf("%lld %lld %lld",&a,&b,&c);
		es[i].from = a;
		es[i].to = b;
		es[i].cost = -c;
	}

	shortest_path(1);

	lld sol = d[n];

	if (canINF())
	{
		printf("inf\n");
	}else
	{
		printf("%lld\n", -sol);
	}

	return 0;
}

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

#define int long long

const int MAX_K = 200002;

struct Data
{
    int v, cost, s;
    Data() {}
    Data(int _v, int _cost, int _s) { v = _v; cost = _cost; s = _s; }

    bool operator < (const Data &a) const
    {
        return cost > a.cost;
    }
};

struct Edge
{
    int to, cost;
    Edge() {}
    Edge(int _to, int _cost) { to = _to; cost = _cost; }
};

int N, M, K, X[MAX_K], Y[MAX_K];
pair<int, int> P[MAX_K];
vector<Edge> e[MAX_K][2];

void GenerateEdge(vector<int> &v, int pos[MAX_K], int s)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i > 0) e[v[i]][s].push_back(Edge(v[i - 1], abs(pos[v[i]] - pos[v[i - 1]])));
        if (i < v.size() - 1) e[v[i]][s].push_back(Edge(v[i + 1], abs(pos[v[i]] - pos[v[i + 1]])));
    }
}

signed main()
{
    cin >> N >> M >> K;
    map<int, vector<int> > mx, my;
    for (int i = 1; i <= K; i++)
    {
        cin >> P[i].first >> P[i].second;
    }
    K += 2;
    P[0] = make_pair(1, 1);
    P[K - 1] = make_pair(N, M);
    sort(P, P + K);
    for (int i = 0; i < K; i++)
    {
        X[i] = P[i].first; Y[i] = P[i].second;
        mx[X[i]].push_back(i);
        my[Y[i]].push_back(i);
    }
    map<int, vector<int> >::iterator ix = mx.begin(), iy = my.begin();
    while (ix != mx.end()) GenerateEdge(ix->second, Y, 0), ix++;
    while (iy != my.end()) GenerateEdge(iy->second, X, 1), iy++;

    priority_queue<Data> pq;
    pq.push(Data(0, 0, 0));
    bool isUsed[MAX_K][2] = {};
    int ans = -1;
    while (!pq.empty())
    {
        Data t = pq.top(); pq.pop();
        if (t.v == K - 1)
        {
            ans = t.cost;
            break;
        }
        if (isUsed[t.v][t.s]) continue;
        isUsed[t.v][t.s] = true;
        for (int i = 0; i < e[t.v][t.s].size(); i++)
        {
            pq.push(Data(e[t.v][t.s][i].to, t.cost + e[t.v][t.s][i].cost, t.s));
        }
        if (t.v != 0) pq.push(Data(t.v, t.cost + 1, 1 - t.s));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 52088
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353

dp=[[0]*(S+1) for _ in range(N)]

dp[0][0]=2
if A[0]<=S:
  dp[0][A[0]]=1
for i in range(N-1):
    for j in range(S+1):
        dp[i+1][j]+=dp[i][j]*2
        dp[i+1][j]%=mod
        if j+A[i+1]<=S:
            dp[i+1][j+A[i+1]]+=dp[i][j]
            dp[i+1][j+A[i+1]]%=mod

print(dp[N-1][S]%mod)

Measured memory_bytes: 139116
n, x = map(int, input().split())
l = list(map(int, input().split()))
 
ans = 0
cnt = 0
 
for i in range(n):
  if cnt <= x:
    ans += 1
  cnt += l[i]
if sum(l) <= x:
  print(ans + 1)
else:
  print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>
using namespace std;

int main() {
	int C[3][3];
	int N = 3;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> C[i][j];

		}
	}

	int x[3];
	int y[3];
	y[0] = 0;
	for (int i = 0; i < N; ++i) x[i]=C[0][i]-y[0];
	for (int i = 0; i < N; ++i) y[i] = C[i][0] - x[0];
	
	bool hantei = true;
	int D[3][3];

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j){
			if (x[j] + y[i] != C[i][j]) hantei = false;
	    }
	}

	if (hantei == true)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a1,b1;
char a[1002][1002];
int b[1002][1002],sum=0;
int main()
{
	cin>>a1>>b1;
    for(int i=1;i<=a1;i++)
    for(int j=1;j<=b1;j++)
    {
    	cin>>a[i][j];
	}
	for(int i=1;i<=a1;i++)
    for(int j=1;j<=b1;j++)
    {
    	if(a[i][j]=='#')
    	{
			b[i+1][j]++;
			b[i+1][j+1]++;
			b[i+1][j-1]++;
			b[i][j-1]++;
			b[i][j+1]++;
			b[i-1][j-1]++;
			b[i-1][j]++;
			b[i-1][j+1]++;
		}
	}
	for(int i=1;i<=a1;i++)
	{
		for(int j=1;j<=b1;j++)
        {
			if(a[i][j]=='#')cout<<'#';
			else cout<<b[i][j];
	    }
	    cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 2432
#include<iostream>
//#include <stdio.h>
#include <cstdio>
//#include<string>
#include <cstring>
using namespace std;

int main(void){
    int n;
    int taro=0,hanako=0;
    char string1[101],string2[101];
    cin >> n;

    for(int i = 0;i<n;i++){
        cin >> string1 >> string2;
        if(strcmp(string1,string2)==0){
            taro++;
            hanako++;

        }else if(strcmp(string1,string2)>0){
            taro+=3;
            //taro=taro+3;
        }else{
            hanako+=3;
            //hanako=hanako+3;
        }

    }
    cout << taro << " " << hanako << endl;
}


Measured memory_bytes: 3092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> pos(n);
  for(int i=0; i<n; i++)  cin >> pos[i];
  sort(all(pos));

  int ans = 1000000000;
  for(int i=0; i<n; i++){
    if(i+k>n) break;
    int left = abs(pos[i]), right = abs(pos[i+k-1]);
    if(pos[i] > 0 && pos[i+k-1] > 0)  
      ans = min(ans, right);
    else if (pos[i] < 0 && pos[i+k-1] < 0)  
      ans = min(ans, left);
    else {
      int num;
      if(left < right) num = left * 2 + right;
      else num = left + right * 2;
      ans = min(ans, num);
    }
  }
  
  cout << ans << ln;
}

Measured memory_bytes: 640
#include<iostream>
#include<set>
using namespace std;
typedef long long ll;

int n;
ll a[200000], c[200000];
set<int> s;

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

	for (ll i = 0;i < n;i++) c[a[i] - 1] = i;

	long long ans = 0;
	s.insert(-1); s.insert(n);
	for (ll i = 0;i < n;i++) {
		auto itr = s.lower_bound(c[i]);
		ll right = *itr, left = *(--itr);

		ans += (i + 1) * (c[i] - left) * (right - c[i]);
		s.insert(c[i]);
	}

	cout << ans << endl;

    return 0;
}



Measured memory_bytes: 12800
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [h,w] <- map (read::String->Int) . words <$> getLine
  as <- lines <$> getContents
  let comped = (transpose .comp .transpose .comp) as
  putStrLn $ unlines comped

comp ls = map snd $ filter ((==False).fst) $zip (map (all (=='.')) ls) ls

Measured memory_bytes: 5688
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    ll a,b,sum=0;
    pair<ll,ll> p[200000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&a,&b);
        p[i].first=b;
        p[i].second=a;
    }
    sort(p,p+n);
    for(int i=0;i<n;i++){
        sum+=p[i].second;
        if(sum>p[i].first){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 3328
import Control.Monad
import Data.Array.IO
import Data.Array
import Data.List

import Debug.Trace

main = do
  [a,b] <- fmap (map read . words) getLine
  ans <- solve a b
  putStrLn $ show (length ans) ++ " " ++ show(length(head ans))
  mapM_ putStrLn ans

type Grid = IOArray (Int,Int) Char

solve :: Int -> Int -> IO [String]
solve a b = do
  g <- newArray ((1,1),(100,100)) '.'
  n <- solve1 g 1 a' b'
  g' <- fmap (ixmap ((1,1),(n,n+1)) id) (freeze g)
  let ans = split (n+1) $ elems g'
  return $ (if a==a' then id else map (map invert)) ans

  where
    invert '.' = '#'
    invert '#' = '.'
    invert c   = c

    (a',b') = (min a b, max a b)


split :: Int -> [a] -> [[a]]
split n =
  unfoldr f
  where
    f [] = Nothing
    f ys = let (as,bs) = splitAt n ys in Just (as,bs)

solve1 :: Grid -> Int -> Int -> Int -> IO Int
solve1 g n w b
--  | traceShow (n,w,b) False = undefined
  | w == 0 && b == 0 = do
      return (n-1)
  | w == 0           = do
--      trace "w==0" (return ())
      sequence_ [black g (x,y) | (x,y)<-tail $ direction $ line n]
      solve2 g (n+2) (b+n-2) '.'
  | n <= w && n <= b = do
      sequence_ [black g (x,y) | (x,y)<-line n, even(x+y)]
      solve1 g (n+1) (w-n) (b-n)
  | w < n            = do
      sequence_ [black g (x,y) | (x,y)<- direction $ line n]
      n' <- solve2 g (n+1) w '#'
      solve2 g (n'+2) (b+n-3 + (if w > 1 then 1 else 0)) '.'
{-
  | otherwise        = do
      trace "otherwise" (return ())
      sequence_ [black g (x,y) | (x,y)<-line n, even(x+y)]
      sequence_ $ take (max 0 w) [black g (x,y) | (x,y)<-direction $ line (n+1), odd(x+y),(x,y)/=(n,n+1)]
      sequence_ [black g (x,y) | (x,y)<-init $ direction $ line (n+2)]
      solve2 g (n+4) (b-w-1) '.'
-}
  where
    direction = if even n then id else reverse


solve2 :: Grid -> Int -> Int -> Char -> IO Int
solve2 g n 0 c =
  return (n-1)
solve2 g n t c = do
--  traceShow (n,t,c) (return ())
  sequence_ [paintr (x,y) | (x,y)<-init $ line n]
  sequence_ paintLine
  sequence_ [paint (x,y) | (x,y)<-init $ line (n+1)]
  if t <= paintLineN then return (n+1) else solve2 g (n+2) (t-paintLineN) c
  where
    paint = if c=='#' then black g else white g
    paintr = if c=='#' then white g else black g

    paintLine = take (t-1) [paint (x,y) | (x,y)<-init $ line n, (if even n then odd else even) (x+y)]
    paintLineN = length paintLine + 1

line :: Int -> [(Int,Int)]
line k = [(x,k+1)|x<-[1..k]] ++ [(k,y)|y<-[k,k-1..1]]

black :: Grid -> (Int,Int) -> IO ()
black g ix = writeArray g ix '#'

white :: Grid -> (Int,Int) -> IO ()
white g ix = writeArray g ix '.'

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B, x;
  cin >> N >> A >> B;
  //500円で払える分だけ払う
  if (N * A < B) {
    x = N * A;
  }else if(N * A > B){
  	x = B;
  }else{
  	x = x;
  }
  cout << x << endl;
}

Measured memory_bytes: 3548
import numpy as np
n,t = map(int, input().split())
DP = np.full((t), -float("inf"))
DP[0] = 0
ans = 0
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
for a,b in ab:
    ans = max(ans, max(DP)+b)
    if a<t:
        DP[a:] = np.maximum(DP[a:], DP[:-a]+b)

ans = int(ans)
print(ans)

Measured memory_bytes: 14536
#include<iostream>
#define pb push_back
#define ll long long

int main(){
 ll n;
 std::cin >> n;
 ll a[n];
  for(ll i=0;i<n;i++){
    std::cin >> a[i];
 }
 ll t=0;
 ll x=a[0];
 for(ll i=0;i<n;i++){
    if(a[i-1]>a[i] && i-1>=0){
        t+=a[i-1]-a[i];
        a[i]=a[i-1];
    }
    else if(a[i-1]<a[i] && i-1<n)
      x=a[i];
 }
 std::cout << t;
 return 0;
}


Measured memory_bytes: 5164
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

vector<ll> point(200000+1);
vector<ll> Ans(200000+1);
vector<vector<ll>>G(200000+1,vector<ll>());

ll dfs(ll idx,ll res){
	res+=point[idx];
	for(int i=0;i<G[idx].size();i++){
		res+=dfs(G[idx][i],res);
	}
	Ans[idx]=res;
	res-=Ans[idx];
	return res;
}

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

	ll N,Q;
	cin>>N>>Q;
    for(int i=0;i<N-1;i++){
        ll s,t; //起点の頂点、終点の頂点
        cin>>s>>t;
        G[s].push_back(t);
    }
	for(int i=0;i<Q;i++){
		ll a,b;
		cin>>a>>b;
		point[a]+=b;
	}
	dfs(1,0);
	for(int i=1;i<=N;i++){
		cout<<Ans[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 25856
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll n, k;
	scanf("%lld%lld", &n, &k);
	printf("%lld\n", min({ n, n - (n / k) * k, abs(n - (n / k + 1) * k) }));

	Please AC;
}

Measured memory_bytes: 888