akhauriyash/Code-Regression huggingface dataset:
N, C = map(int, input().split())
X, V = [], []

cw1 = [0]
cw2 = [0]
ccw1 = [0]
ccw2 = [0]

s = 0
for _ in range(N):
  x, v = map(int, input().split())
  X.append(x)
  V.append(v)
  s += v
  cw1.append(max(cw1[-1], s-x))
  cw2.append(max(cw2[-1], s-2*x))

s = 0

for x,v in zip(X[::-1], V[::-1]):
  s += v
  ccw1.append(max(ccw1[-1], s-(C-x)))
  ccw2.append(max(ccw2[-1], s-(C-x)*2))

ans = 0

for a,b,c,d in zip(cw1, ccw2[::-1], cw2, ccw1[::-1]):
  ans = max(ans, a+b, c+d)

print(ans)


Measured memory_bytes: 25828
#include <stdio.h>
#include <algorithm>
using namespace std;

int x, y, a, b, c;
int p[100100], q[100100], r[100100];

int main()
{
	scanf ("%d %d %d %d %d", &x, &y, &a, &b, &c);
	for (int i = 0; i < a; i++) scanf ("%d", &p[i]); sort(p, p + a); reverse(p, p + a);
	for (int j = 0; j < b; j++) scanf ("%d", &q[j]); sort(q, q + b); reverse(q, q + b);
	for (int k = 0; k < c; k++) scanf ("%d", &r[k]); sort(r, r + c); reverse(r, r + c);

	int i = 0, j = 0, k = 0; long long ans = 0;
	while (i + j + k < x + y){
		int mx = -1000;
		if (i < x) mx = max(mx, p[i]);
		if (j < y) mx = max(mx, q[j]);
		if (k < c) mx = max(mx, r[k]);
		if (i < x && p[i] == mx) ans += p[i++];
		else if (j < y && q[j] == mx) ans += q[j++];
		else ans += r[k++];
	}

	printf ("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1000000007;

int N,A,B,C,D;
string S;

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

    bool flag=true;
    if(C<D){
        rep(i,D-B-1){
            flag&=(S[(B-1)+i-1]=='.' || S[(B-1)+i]=='.');
        }
        S[D-1]='#';
        rep(i,C-A-1){
            flag&=(S[(A-1)+i-1]=='.' || S[(A-1)+i]=='.');
        }
    }else{
        bool f=false;
        rep(i,D-B+1){
            if(S[(B-1)+i-1]=='.' && S[(B-1)+i]=='.' && S[(B-1)+i+1]=='.') f=true;
        }
        flag&=f;
    }

    string ans;
    if(flag) ans="Yes";
    else ans="No";

    cout<<ans<<endl;
}

Measured memory_bytes: 3744
import java.util.*;

public class Main {

    // global
    static long fact[];
    static long inverse[];
    static int mod = 1_000_000_007;

    static long pow(long a,int n) {
        long res=1;
        while (n>0) {
            if ((n-n/2*2)==1) {
                res=res*a%mod;
            }
            a=a*a%mod;
            n>>=1;
        }
        return res;
    }

    static long modinv(long n) {
        return pow(n, mod-2);
    }

    static long comb(int n,int k){
        if(n<0 || k<0 || n<k)return 0;
        return fact[n]*(inverse[k]*inverse[n-k]%mod) %mod;
    }

    public static void main(String[] args) {
        // main method
        fact=new long[500000];
        fact[0]=1;
        inverse=new long[500000];
        inverse[0]=1;
        for(int i=1;i<500000;i++){
            fact[i]=(fact[i-1]*(long)i)%mod;
            inverse[i]=modinv(fact[i]);
        }
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (k>=n-1) {
            System.out.println(comb(n+n-1, n-1));
            return;
        }
        long ans = 0L;
        for (int i=0;i<=k;i++) {
            ans = (ans+comb(n, i)*comb(n-(n-i)+(n-i)-1, n-i-1)%mod)%mod;
        }
        System.out.println(ans);
    }
}

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

int main(void) {
	int m,f,r;
	char record[10000];
	int i=0,j;

	do{
		scanf("%d %d %d%*c",&m,&f,&r);

		if(m==-1||f==-1){
			record[i]='F';
		}
		else if((m+f)>=80){
			record[i]='A';
		}
		else if((m+f)>=65&&(m+f)<80){
			record[i]='B';
		}
		else if((m+f)>=50&&(m+f)<65){
			record[i]='C';
		}
		else if((m+f)>=30&&(m+f)<50){
			if(r>=50){
				record[i]='C';
			}
			else{
			record[i]='D';
			}
		}
		else if((m+f)<30){
			record[i]='F';
		}
		i++;
	}while((m!=-1)||(f!=-1)||(r!=-1));

	for(j=0;j<i-1;j++){
		printf("%c\n",record[j]);
	}
	return 0;
}

Measured memory_bytes: 1780
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};

typedef vector<vector<Edge>> Graph;

bool ishei(int x) {

	for (int i = 0; sqrt(x) + 1 >= i; i++) {
		if (i * i == x) {
			return true;
		}
	}
	return false;

}

signed main(void) {

	int n, d;
	cin >> n >> d;


	vector<vector<int>> x(n, vector<int>(d));

	REP(i, n) {
		REP(j, d) {
			cin >> x[i][j];
		}
	}
	int ans = 0;
	REP(i, n) {
		rep(j, i + 1, n) {
			int sum = 0;
			REP(k, d) {
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			if (ishei(sum)) {
				ans++;
			}
		}

	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NM[0]; var M = NM[1];
            var costs = new int[M + 1];
            var opens = new int[M + 1];
            for (int i = 1; i < M + 1; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                costs[i] = ab[0];
                var c = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                foreach (int op in c) opens[i] += 1 << (op - 1);
            }

            var DP = new int[M + 1, 1 << N];
            for (int i = 0; i < M + 1; i++) for (int j = 0; j < (1 << N); j++) DP[i, j] = int.MaxValue;
            DP[0, 0] = 0;
            for (int key = 0; key < M; key++)
            {
                for (int open = 0; open < (1 << N); open++)
                {
                    if (DP[key, open] == int.MaxValue) continue;
                    DP[key + 1, open] = Math.Min(DP[key + 1, open], DP[key, open]);
                    DP[key + 1, open | opens[key + 1]] = Math.Min(DP[key + 1, open | opens[key + 1]], DP[key, open] + costs[key + 1]);
                }
            }
            Console.WriteLine(DP[M, (1 << N) - 1] != int.MaxValue ? DP[M, (1 << N) - 1] : -1);
        }
    }
}


Measured memory_bytes: 26848
// https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<pair<string, int>> v(N);
    REP(i, N) { cin >> v[i].first >> v[i].second; }
    string w;
    cin >> w;
    int sum = 0;
    for (int i = N - 1; i > 0; i--) {
        if (v[i].first == w) {
            break;
        }
        sum += v[i].second;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll a,b;
    int k,i;
    cin>>a>>b>>k;
    for (i=0;i<k;i++)
    {
        if (i&1)
        {
            if (b&1)
                b--;
            a+=b/2;
            b/=2;
        }
        else
        {
            if (a&1)
                a--;
            b+=a/2;
            a/=2;
        }
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
# ABC143E - Travel by Car
import numpy as np

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall


def main():
    # FW -> once more FW to edges <= L
    global L, G, dist, ancestors
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    A, B, C, S, T = ABC[::3], ABC[1::3], ABC[2::3], ST[::2], ST[1::2]

    G = csr_matrix((C, (A, B)), (N + 1, N + 1))
    dist = floyd_warshall(G, directed=0)

    modified_G = np.full((N + 1, N + 1), np.inf)
    np.fill_diagonal(modified_G, 0)
    modified_G[dist <= L] = 1
    modified_dist = floyd_warshall(modified_G, directed=0)
    modified_dist[modified_dist == np.inf] = 0
    modified_dist = (modified_dist).astype(int)
    
    ans = modified_dist[S, T] - 1
    print("\n".join(ans.astype(str)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 45524
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((a+b)>(c+d))
		cout<<"Left";
	if((a+b)==(c+d))
		cout<<"Balanced";
	if((a+b)<(c+d))
		cout<<"Right";
	return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define RFOR(i, a, b) for(int i = (int)(b - 1); i >= (int)(a); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

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

int w, h;
char field[50][50];

int dfs(int x, int y, int &state) {
  field[y][x] = '*';

  int cnt = 1;
  REP(i, 4){
    int sx = x + dx[i];
    int sy = y + dy[i];
    if (sx < 0 || sx >= w || sy < 0 || sy >= h) continue;
    if (field[sy][sx] == 'B') state |= 1;
    else if (field[sy][sx] == 'W') state |= 2;
    else if (field[sy][sx] == '.') {
      cnt += dfs(sx, sy, state);
    }
  }
  if (state == 3)
    return 0;
  else
    return cnt;
}

int main() {
  while(cin >> w >> h, w) {
    fill_n((char *)field, 50 * 50, '.');
    REP(y, h) REP(x, w) {
      cin >> field[y][x];
    }

    int cb = 0, cw = 0;
    REP(y, h) REP(x, w) {
      if (field[y][x] == '.') {
        int state = 0;
        int v = dfs(x, y, state);
        if (state == 1) {
          cb += v;
        } else if (state == 2) {
          cw += v;
        }
      }
    }

    printf("%d %d\n", cb, cw);
  }
}

Measured memory_bytes: 3268
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        if (x == y)
            a[i] = 1;
        else
            a[i] = 0;
    }
    for (int i = 2; i < n; ++i)
    {
        if (a[i] == 1 && a[i - 1] == 1 && a[i - 2] == 1)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int count=0;
  string s;
  cin>>s;
  n=s.length();
  vector<char> c(n);
  for(int i=0;i<n;i++){
    c[i]=s.at(i);
    if(c[i]=='0'){
      count++;
    }
    else if(c[i]=='1'){
      count--;
    }
  }
  cout<<n-abs(count);
}
  

Measured memory_bytes: 512
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, K;
LP s[100000];
set<int> ss;
priority_queue<LP, vector<LP>, greater<LP> > q;

void solve()
{
    ll ans = 0, ans1 = 0;
    sort(s, s+N, greater<LP>());
    REP(i, K){
        if(ss.find(s[i].se) == ss.end()){
            ss.insert(s[i].se);
        }else{
            q.push(s[i]);
        }
        ans1 += s[i].fi;
        //cout << ans << " (" << s[i].fi << "," << s[i].se << ")" << endl;
    }
    //cout << endl;
    ans1 += ss.size() * ss.size();
    ans = ans1;
    FOR(i, K, N){
        if(q.size() == 0) break;
        if(ss.find(s[i].se) == ss.end()){
            int sz = ss.size();
            ans1 += 2*sz + 1 - (q.top().fi - s[i].fi);
            ans = max(ans, ans1);
            q.pop();
            ss.insert(s[i].se);
            //cout << ans << " " << ans1 << " (" << s[i].fi << "," << s[i].se << ")"
            //     << " (" << q.top().fi << "," << q.top().se << ")" << endl;
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    REP(i, N) cin >> s[i].se >> s[i].fi;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

string s;
int cnt[30];

int main(){
	cin>>s;
	
	for(int i=0; i<s.size(); i++){
		cnt[s[i]-'a']++;
		if(cnt[s[i]-'a']>1){
			cout<<"no\n";
			return 0;
		}
	}
	cout<<"yes\n";
}


Measured memory_bytes: 3644
#include<cstdio>
#define sz 17
#define mod 1000000007
int n,x,y,z;
long long dp[55][500005];
int add(int x,int k){return ((x<<k)|(1<<(k-1)))%(1<<sz);}
int check(int p){return (p&(1<<(z-1)))&&(p&(1<<(z+y-1)))&&(p&(1<<(z+y+x-1)));}
int main()
{
	scanf("%d%d%d%d",&n,&x,&y,&z);
	long long ans=1;for (int i=1;i<=n;i++) ans=ans*10%mod;
	dp[0][0]=1;
	for (int i=1;i<=n;i++)
	    for (int j=0;j<(1<<sz);j++)
	        for (int k=1;k<=10;k++)
	            if (!check(add(j,k)))
				    dp[i][add(j,k)]=(dp[i][add(j,k)]+dp[i-1][j])%mod;
	for (int i=0;i<(1<<sz);i++) ans=(ans-dp[n][i]+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

vector<pair<pair<int, int>, pair<int, int>>> li;

int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  rep(i, H) rep(j, W) cin >> a[i][j];
  vector<pair<int, int>> vs;
  rep(i, H) rep(j, W) {
    vs.push_back({i, i % 2 ? W - 1 - j : j});
  }
  vector<tuple<int, int, int, int>> ans;
  rep(i, vs.size() - 1) {
    int y = vs[i].first, x = vs[i].second;
    int ny = vs[i + 1].first, nx = vs[i + 1].second;
    if (a[y][x] % 2) {
      a[y][x]--;
      a[ny][nx]++;
      ans.emplace_back(y + 1, x + 1, ny + 1, nx + 1);
    }
  }
  cout << ans.size() << "\n";
  for (auto e: ans) {
    int a,b,c,d; tie(a,b,c,d) = e;
    cout << a << " "
         << b << " "
         << c << " "
         << d << "\n";
  }
}


Measured memory_bytes: 7152
N, A, B = gets.split.map(&:to_i)
 
H = []
N.times{ H << gets.to_i }
 
def enough(i)
  i >= H.map{ |x| ( [(x - i * B), 0].max * 1.0 / (A - B) ).ceil }.inject(:+)
end
 
puts (1..H.max).bsearch{ |i| enough(i) }


Measured memory_bytes: 17972
r, c = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

x = 0
grid = [[] for i in range(r)]
for i in range(r):
    while x < n and len(grid[i])+a[x] <= c:
        grid[i].extend([x+1]*a[x])
        x += 1
    if x < n:
        a[x] -= c-len(grid[i])
        grid[i].extend([x+1]*(c-len(grid[i])))

for i in range(1,r,2):
    grid[i] = grid[i][::-1]

for row in grid:
    print(*row)

Measured memory_bytes: 74556
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)


string s;


int main() {
	cin>>s;
	int ans = 0;
	for(int i=0;i<=2;i++){
		if(s[i]=='1') ans++;
	}
	cout<<ans<<endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;
    vector<vector<P>> adj(n);
    rep(i, n) {
        int u, k, v, c;
        cin>>u>>k;
        rep(j, k) {
            cin>>v>>c;
            adj[u].push_back(P(c, v));
        }
    }

    priority_queue<P, vector<P>, greater<P>> q;
    vector<int> wmap(n, -1);
    q.push(P(0, 0));
    while (!q.empty()) {
        P p = q.top(); q.pop();
        int w = p.first;
        int v = p.second;
        if (wmap[v] != -1) continue;

        wmap[v] = w;
        for (auto e : adj[v]) {
            q.push(P(e.first + w, e.second));
        }
    }

    rep(i, n) cout<<i<<" "<<wmap[i]<<endl;
}


Measured memory_bytes: 3348
f=lambda:map(int,input().split());n,m=f();g=[[] for _ in range(n)]
for _ in [0]*m:a,b=f();g[a-1]+=[b-1];g[b-1]+=[a-1]
p=[0]*n;from queue import*;q=Queue();q.put(0)
while not q.empty():
    v=q.get()
    for c in g[v]:
        if p[c]<1:p[c]=v+1;q.put(c)
print('Yes',*p[1:],sep='\n')

Measured memory_bytes: 39276
#include<bits/stdc++.h>
using namespace std;
int x[11][11]; 
int main()
{
	int n,d,i,j,k,cnt=0;
	double s;
	scanf("%d %d",&n,&d);
	for(i=0;i<n;i++)
		for(j=0;j<d;j++)
			scanf("%d",&x[i][j]);
	for(i=1;i<n;i++)
	{
		for(j=0;j+i<n;j++)
		{
			s=0.0;
			for(k=0;k<d;k++)
				s=s+(double)(x[j][k]-x[j+i][k])*(x[j][k]-x[j+i][k]);
			if(sqrt(s)==trunc(sqrt(s)))
				cnt++;
		}
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;


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

    int n, m;
    cin >> n >> m;

    cout << (n == m ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int h;
    cin>>h;
    int ans = (int)pow(2,(int)log2(h)+1) - 1;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 512
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>

#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    char alpha;
    cin >> alpha;
    if(islower(alpha)){
        cout << "a" << endl;
    }else{
        cout << "A" << endl;
    }
    return 0;
}





Measured memory_bytes: 3024
#include <stdio.h>
#include <string.h>

const char *operation[] = {
    "North",
    "East",
    "South",
    "West",
    "Right",
    "Left"
};

const int param[][3] = {
    {1, 2, -1},
    {0, 2, -1},
    {1, 2, 1},
    {0, 2, 1},
    {0, 1, -1},
    {0, 1, 1}
};


void rotate(int v[], int a1, int a2, int direction) {
    int t = v[a1];
    v[a1] = - direction * v[a2];
    v[a2] = direction * t;
}


int main (void) {
    int n, score, i, j, k;
    char buf[6];

    while (scanf("%d\n", &n) != EOF && n) {
        int m[][3] = {
            {1, 0, 0},
            {0, 1, 0},
            {0, 0, 1}
        };
        for (i = 0, score = 1; i < n; i++) {
            scanf("%s", buf);
            for (j = 0; j < 6; j++) {
                if (strcmp(buf, operation[j]) == 0) break;
            }
            for (k = 0; k < 3; k++) {
                rotate(m[k], param[j][0], param[j][1], param[j][2]);
            }
            if (m[0][2] == 1) score += 3;
            else if (m[0][2] == -1) score += 4;
            else if (m[1][2] == 1) score += 5;
            else if (m[1][2] == -1) score += 2;
            else if (m[2][2] == 1) score += 1;
            else if (m[2][2] == -1) score += 6;
        }
        printf("%d\n", score);
    }
    return 0;
}

Measured memory_bytes: 620
#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 n;
    cin >> n;
    cout << (1 << int(log2(n))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;
}

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

using namespace std;

typedef long long int Int;

double Calc(int a,int b)
{
    return (100.0*b)/(a+b);
}

bool create[50];
bool noudo[3500];

int main(void)
{
    int a,b,c,d,e,f;
    
    cin>>a>>b>>c>>d>>e>>f;

    for(int i = 0;i*a*100 <= f;i++) {
	for(int j = 0;j*b*100 <= f;j++) {
	    if((i*a+j*b)*100 > f)
		break;
	    create[i*a+j*b] = true;
	}
    }

    for(int i = 0;i*c <= f;i++) {
	for(int j = 0;j*d <= f;j++) {
	    if(i*c+j*d > f)
		break;
	    noudo[i*c+j*d] = true;;
	}
    }

    int w = a*100,sugar = 0;
    double den = 0.0;
    for(int i = 1;i*100 <= f;i++)
    {
	if(create[i])
	{
	    for(int j = 0;j <= i*e;j++)
	    {
		if(i*100+j <= f && noudo[j] && den < Calc(i*100,j))
		{
		    den = Calc(i*100,j);
		    w = i*100+j;
		    sugar = j;
		}
	    }
	}
    }

    cout<<w<<" "<<sugar<<endl;    

    return 0;
}


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

int main() 
{
	unsigned long long n, m;
	cin >> n >> m;

	if (n == 1 && m == 1) {
		cout << 1 << endl;
	}
	else if (n == 1) {
		cout << m - 2 << endl;
	}
	else if (m == 1) {
		cout << n - 2 << endl;
	}
	else {
		cout << (n - 2)*(m - 2) << endl;
	}

	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    vector<string> sarr({
        "dreamer",
        "dream",
        "eraser",
        "erase",
    }); 
    
    while (s.size() != 0) {
        bool ok(false);
        for (int i = 0; i < 4; i++) {
            string::size_type pos = s.rfind(sarr[i]);
            if (pos != string::npos && pos + sarr[i].size() == s.size()) {
                s = s.substr(0, pos);
                ok = true;
            }   
        }   
        if (!ok) {
            break;
        }   
    }   

    cout << ((s.size() == 0) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> maze(H, vector<char>(W));
    rep(h , H) rep(w, W) cin >> maze[h][w];
    
    const int d[4] = {1, -1, 0, 0};
    int ans = 0;
    rep(h, H)rep(w, W){
        if(maze[h][w] == '#') continue;
        vector<vector<int>> dist(H, vector<int>(W, 1e9));
        queue<pair<int,int>> que;
        dist[h][w] = 0;
        que.emplace(make_pair(h, w));

        while(!que.empty()){
            int i, k;
            tie(i, k) = que.front(); que.pop();

            rep(j ,4){
                if(i + d[j] < 0 || i + d[j] >= H || 
                    k + d[j  ^ 2] < 0 || k + d[j ^ 2] >= W || 
                    dist[i + d[j]][k + d[j ^ 2]] != 1e9 || maze[i + d[j]][k + d[j ^ 2]] == '#') {
                        continue;
                    }
                
                dist[i + d[j]][k + d[j ^ 2]] = dist[i][k] + 1;
                ans = max(ans, dist[i][k] + 1);
                que.emplace(make_pair(i + d[j], k + d[j ^ 2]));
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18,MOD=1e9+7;
int main(){
	string s;
	cin>>s;
	bool flag1=false,flag2=false;
	string a=s.substr(0,2);
	string b=s.substr(2,2);
	if(stoi(a)>=1&&stoi(a)<=12&&stoi(b)>=1&&stoi(b)<=12)cout<<"AMBIGUOUS"<<endl;
	else if(stoi(b)>=1&&stoi(b)<=12)cout<<"YYMM"<<endl;
	else if(stoi(a)>=1&&stoi(a)<=12)cout<<"MMYY"<<endl;
	else cout<<"NA"<<endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
llong w,a,b;
int main(){ _;
  cin>>w>>a>>b;
  if((b<=a+w && a+w<=b+w) || (a<=b+w && b+w<=a+w)){
      cout<<0<<endl;
      return 0;
    }
  cout<<min(abs((a+w)-b),abs((b+w)-a))<<endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

const int N = 1e5 + 10;
const int BINF = 1e18 + 10;
int dp[N], a[N], t[4 * N][2];

void update(int v, int l, int r, int need, int vl1, int vl2) {
	if (l == r) {
		t[v][0] = vl1;
		t[v][1] = vl2;
		return;
	}
	int mid = (l + r) / 2;
	if (need <= mid) {
		update(2 * v, l, mid, need, vl1, vl2);
	}
	else {
		update(2 * v + 1, mid + 1, r, need, vl1, vl2);
	}
	t[v][0] = min(t[2 * v][0], t[2 * v + 1][0]);
	t[v][1] = min(t[2 * v][1], t[2 * v + 1][1]);
}

int get(int v, int l, int r, int a, int b, int id) {
	if (l > b || r < a) {
		return BINF;
	}
	if (l >= a && r <= b) {
		return t[v][id];
	}
	int mid = (l + r) / 2;
	return min(get(2 * v, l,  mid, a, b, id), get(2 * v + 1, mid + 1, r, a, b, id));
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	int n, e, t;
	cin >> n >> e >> t;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[1] = a[1] + t;
	update(1, 1, n, 1, 0, -2ll * a[1]);
	int ptr = 0;
	for (int i = 2; i <= n; i++) {
		while (2ll * (a[i] - a[ptr + 1]) >= t) {
			ptr++;
		}
		//cout << i << ' ' << ptr << '\n';
		dp[i] = BINF;
		for (int j = i; j <= i; j++) {
			dp[i] = min(dp[i], dp[j - 1] + (a[i] - a[j - 1]) + max(2 * (a[i] - a[j]), t));
		}
		dp[i] = min(dp[i], get(1, 1, n, 1, ptr, 1) + 3ll * a[i]);
		dp[i] = min(dp[i], get(1, 1, n, ptr + 1, i - 1, 0) + t + a[i]);
		update(1, 1, n, i, dp[i - 1] - a[i - 1], dp[i - 1] - a[i - 1] - 2ll * a[i]);
		//cout << dp[i] << '\n';
	}
	//cout << '\n';
	cout << dp[n] + (e - a[n]) << '\n';
} 

Measured memory_bytes: 7936
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a =sc.nextInt();
		int v=(int) (a+Math.pow(a, 2)+Math.pow(a, 3));

		System.out.println(v);
		sc.close();
	}
}


Measured memory_bytes: 35800
def main():
    N = int(input())

    def fizzbuzz(i):
        if i % 3 == 0 and i % 5 == 0:
            return 'FizzBuzz'
        elif i % 3 == 0:
            return 'Fizz'
        elif i % 5 == 0:
            return 'Buzz'
        else:
            return i
    def is_int(v):
        return isinstance(v, int)
    ans = 0
    for k in range(1,N+1):
        if is_int(fizzbuzz(k)):
            ans += fizzbuzz(k)
    print(ans)
    return

if __name__ == "__main__":
    main()

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

int main()
{
	int a,b;
	cin>>a>>b;
	switch(a+b)
	{
		case 3:
			cout<<"3"<<endl;
			break;
		case 4:
			cout<<"2"<<endl;
			break;
		case 5:
			cout<<"1"<<endl;
			break;
		default:
			break;
	}
	return 0;
}



Measured memory_bytes: 256
a = str(input())
a = list(a)
for i in range(len(a)):
    a[i] = int(a[i])



for i in range(8):
    ans = a[0]
    for j in range(1,4):
        if (i >> (j-1)) & 1:
            ans += a[j]
        else:
            ans -= a[j]
    #print(ans, bin(i))
    if ans == 7:
        print(a[0], end="")
        for j in range(1,4):
            if (i >> (j-1)) & 1:
                print("+", end="")
            else:
                print("-",end="")
            print(a[j], end="")
        print("=7")
        exit(0)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

ll x[200010];
    ll y[200010];

int main() {
    ll n;
    
    cin >> n;
    imfor(i, n) {
        cin >> x[i];
        y[i] = x[i];
    }
    sort(x, x + n);
    imfor(i, n) {
        if (y[i] < x[n / 2]) {
            cout << x[n / 2] << endl;
        }
        else {
            cout << x[(n / 2) - 1] << endl;
        }
    }
}

Measured memory_bytes: 5376
import datetime
a, b = map(int, input().split())
count = 0
for i in range(a):
    target_date_str = '2018'+'{0:02d}'.format(a)+'{0:02d}'.format(b)
    target_date_date = datetime.datetime.strptime(target_date_str, '%Y%m%d')
    current_date_date = datetime.datetime.strptime('2018'+'{0:02d}'.format(
        i+1)+'{0:02d}'.format(i+1), '%Y%m%d')
    if current_date_date <= target_date_date:
        count += 1
print(count)

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

int main() {
  int a, b;
  string s, t, u;
  
  cin >> s;
  cin >> t;
  cin >> a;
  cin >> b;
  cin >> u;
  
  if(u == s) a--;
  else b--;
  
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import heapq
n=int(input())
s=list(map(int,input().split()))
heapq.heapify(s)
while len(s)!=1:
    a=heapq.heappop(s)
    b=heapq.heappop(s)
    heapq.heappush(s,(a+b)/2)
print(heapq.heappop(s))

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,k;
  cin>>n>>k;
  vvll a(70,vll(n));
  REP(i,n){
    cin>>a[0][i];
    a[0][i]--;
  }

  REP1(i,70){
    REP(j,n){
      ll to=a[i-1][j];
      a[i][j]=a[i-1][to];
    }
  }

  ll power=1;
  ll h=0;
  ll cur=0;
  while(power<=k){
    if((k>>h)&1){
      cur=a[h][cur];
    }
    power*=2;
    h++;
  }

  cur++;
  cout<<cur<<endl;
}



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

int cnt[10000001];

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

	int n;

	cin >> n;

	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j+=i)
		{
			cnt[j]++;
		}
	}

	long long int res = 0;

	for(long long int i=1;i<=n;i++)
	{
		long long int val = i * cnt[i];
		res += val;
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 42664
#include<stdio.h>
int main(){
  int t,n;
  int s,f;
  while(1){
    scanf("%d",&t);
    if(t==0) return 0;
    scanf("%d",&n);
    int i,study=0;
    for(i=0;i<n;i++){
      scanf("%d %d",&s,&f);
      study += f-s;
    }
    if(study>=t) printf("OK\n");
    else printf("%d\n",t-study);
  }
}

Measured memory_bytes: 1040
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 21:34:10 2020

@author: Kanaru Sato
"""

n = int(input())
memo = list(map(int, input().split()))
attend = [0]*n

for i in range(0,n):
    attend[memo[i]-1] = i+1

ans = [str(attend[i]) for i in range(0,n)]
ans = " ".join(ans)

print(ans)

Measured memory_bytes: 17788
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
const int maxn = 2e5 + 7;

ll n, s, w[maxn], a[maxn];
ll dp[maxn], mx;

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> s;
	for (int i = 1; i < maxn; i++)
		dp[i] = inf;
	dp[0] = 0;
	for (ll i = 1; i <= n; i++){
		cin >> w[i] >> a[i];
		for (ll j = 100000; j >= 0; j--){
			if (dp[j] != inf && dp[j] + w[i] <= s){
				dp[j + a[i]] = min(dp[j + a[i]], dp[j] + w[i]);	
			}
		}
	}
	for (ll i = 0; i < maxn; i++)
		if (dp[i] != inf)
			mx = max(mx, i);
	cout << mx;
	return 0;
} 

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

vector<string> s;

vector<tuple<int, int, int, int>> f( int sx, int sy, int ex, int ey )
{
	int cnt = 0;
	int divx = -1;
	int divy = -1;
	int cnty = -1;
	for( int y = sy; y < ey; y++ ) {
		for( int x = sx; x < ex; x++ ) {
			if( s[y][x] == '#' ) {
				if( cnt && divx < 0 ) divx = x;
				cnt++;
			}
		}
		if( cnt && divy < 0 ) {
			divy = y + 1;
			cnty = cnt;
		}
	}
	if( cnt == 1 ) {
		vector<tuple<int, int, int, int>> r;
		r.push_back( make_tuple( sx, sy, ex, ey ) );
		return r;
	}
	vector<tuple<int, int, int, int>> res;
	if( cnty < cnt ) {
		vector<tuple<int, int, int, int>> r1 = f( sx, sy, ex, divy );
		vector<tuple<int, int, int, int>> r2 = f( sx, divy, ex, ey );
		res = r1;
		res.insert( res.end(), r2.begin(), r2.end() );
	}
	else {
		vector<tuple<int, int, int, int>> r1 = f( sx, sy, divx, ey );
		vector<tuple<int, int, int, int>> r2 = f( divx, sy, ex, ey );
		res = r1;
		res.insert( res.end(), r2.begin(), r2.end() );
	}
	return  res;
}

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	s = vector<string>( H );
	for( int i = 0; i < H; i++ ) {
		cin >> s[i];
	}

	vector<tuple<int, int, int, int>> r = f( 0, 0, W, H );
	sort( r.begin(), r.end() );
	vector<vector<int>> ans( H, vector<int>( W ) );
	int n = 0;
	for( auto it = r.begin(); it < r.end(); it++ ) {
		int sx, sy, ex, ey;
		tie( sx, sy, ex, ey ) = *it;
		n++;
		for( int y = sy; y < ey; y++ ) {
			for( int x = sx; x < ex; x++ ) {
				ans[y][x] = n;
			}
		}
	}

	for( int i = 0; i < H; i++ ) {
		for( int j = 0; j < W; j++ ) {
			if( j ) cout << " ";
			cout << ans[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 4768
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}
bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};

int main(){
    ll N; cin >> N;
    map<ll, ll> as;
    REP(i, N) {
        ll a; cin >> a;
        if(as[a] == 1) as[a] = 0;
        else if(as[a] == 0) as[a] = 1;
    }
    ll ret = 0;
    for(auto i = as.begin(); i != as.end(); i++){
        ret += i->second;
    }
    cout << ret << endstr;
    return 0;
}


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

using namespace std;

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

int N, W, H;
int sumx[100010];
int sumy[100010];

int main() {

	cin >> N >> W >> H;
	rep(i, N) {
		int x, y, w;
		cin >> x >> y >> w;
		sumx[max(0,x-w)]++, sumx[min(W+1,x+w)]--;
		sumy[max(0,y-w)]++, sumy[min(H+1,y+w)]--;
	}
	REP(i, 1, 100010) {
		sumx[i] += sumx[i-1];
		sumy[i] += sumy[i-1];
	}

	bool ok = true;
	rep(i, W) {
		if(sumx[i] == 0) ok = false;
	}
	if(!ok) {
		ok = true;
		rep(i, H) {
			if(sumy[i] == 0) ok = false;
		}
	}

	cout << ( ok ? "Yes" : "No" ) << endl;

	return 0;
}

Measured memory_bytes: 1940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t=0,x=0,y=0; 
	int a[55];
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]!=i)cnt++;
	}
	if(cnt==2||cnt==0)printf("YES\n");
	else printf("NO\n");
	return 0;
}

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


int main(){

  int xmax, ymax, n;
  cin >> xmax >> ymax >> n;

  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  int xmin = 0;
  int ymin = 0;

  for (int i = 0; i < n; i++) {
    cin >> x.at(i) >> y.at(i) >> a.at(i);
    if (a.at(i) == 1) {
      xmin = max(xmin,x.at(i));

    } else if (a.at(i) == 2) {
      xmax = min(xmax,x.at(i));

    } else if (a.at(i) == 3) {
      ymin = max(ymin,y.at(i));

    } else if (a.at(i) == 4) {
      ymax = min(ymax,y.at(i));

    }
  }

  int s;
  s = max(0,(xmax-xmin))*max(0,(ymax-ymin));
  cout << s << endl;


}


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;

int main(){
	int h, w;
	int i,j,k;
	while(1){
		k=0;
		scanf("%d %d", &h, &w);
		if(!h && !w)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if((k%2+j) % 2){
					putchar('.');
				}else{
					putchar('#');
				}
			}
			putchar('\n');
			k++;
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1004
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;

int main(){
  int n,m; cin>>n>>m;
  vector<int> x(m);
  REP(i,m)cin>>x[i];
  sort(ALL(x));

  vector<int> diff(m-1);
  REP(i,m-1)diff[i]=x[i+1]-x[i];
  
  sort(ALL(diff));
  reverse(ALL(diff));

   ll res=0;
  if(n<m){
    REP(i,n-1)diff[i]=0;
   REP(i,m-1)res+=diff[i];
  }
  cout<<res<<endl;
}

Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
ll a[100005],rui[100005];

struct RMQ{
	#define s (1<<19)
	int seg[s];
	void init(){ memset(seg,0,sizeof(seg)); }
	void update(int k,int a){
		k+=s/2-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=(seg[k*2+1]+seg[k*2+2]);
		}
	}
	void update_add(int k,int a){
		k+=s/2-1; seg[k]+=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=(seg[k*2+1]+seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return 0;
		if(a<=l && r<=b) return seg[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return (vl+vr);
		}
	}
}kaede;

int main(){
	cin >> n;
	repn(i,n) cin >> a[i];
	
	ll lb = 0, ub = INF+7;
	while(ub-lb > 1){
		ll mid = (lb+ub)/2;
		repn(i,n){
			rui[i] = rui[i-1];
			if(a[i] >= mid) rui[i] ++;
			else rui[i] --;
		}
		kaede.init();
		repn(i,n) kaede.update_add(rui[i]+100002,1);
		ll ans = 0;
		repn(i,n){
			//rui[i-1]以上?
			ans += kaede.query(rui[i-1]+100002,s/2-1,0,0,s/2-1);
			//rui[i]を消す
			kaede.update_add(rui[i]+100002,-1);
		}
		ll x = 1LL*n*(n+1)/2;
		x = (x+1)/2;
		if(x <= ans) lb = mid;
		else ub = mid;
	}
	
	cout << lb << endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000007;

int main() {
	long long ans = 1, N; cin >> N;
	for( int i = 1; i <= N ; i++ ){
		ans *= i;
		ans %= INF;
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,x,m;
  cin>>n>>x>>m;
  if(n<m){
    int64_t a=0;
    for(int64_t i=x,j=0;j<n;i=i*i%m,j++)
      a+=i;
    cout<<a<<endl;
    return 0;
  }
  vector<int64_t> c(m,0);
  vector<int64_t> o(m,m);
  int l=m;
  int p=m;
  for(int64_t i=x,j=0;;i=i*i%m,j++){
    if(c.at(i)!=0){
      l=i;
      p=j-o.at(i);
      break;
    }
    c.at(i)++;
    o.at(i)=j;
  }
  for(int64_t i=l,j=0;j<p;i=i*i%m,j++){
    c.at(i)=0;
    c.at(i)+=(n-o.at(l))/p+(j<(n-o.at(l))%p?1:0);
  }
  int64_t s=0;
  for(int i=0;i<m;i++)
    s+=c.at(i)*i;
  cout<<s<<endl;
}

Measured memory_bytes: 4752