akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>

using namespace std;

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

#define fs first
#define sc second

int n, m2;
struct edge{
    int to;
    ll s;
    ll ord;
};

vector<edge> e[100010];
int e_check[100100], v_check[100100][2];
ll v_value[100100][2];

bool ok = true;
void dfs(int s, ll a, int pm){
    v_check[s][pm] = 1;
    v_value[s][pm] = a;
    for(int i = 0; i < e[s].size(); i++){
        int dis = e[s][i].to;
        ll cost = e[s][i].s;
        if(v_check[dis][1-pm] == 1){
            ok = ok && (v_value[dis][1-pm] == cost - a);
        }
        else {
            dfs(dis, cost - a, 1 - pm);
        }
    }

}

int main(){
    cin >> n >> m2;
    for(int i = 0; i < m2; i++){
        int u, v;  ll s;   cin >> u >> v >> s;
        u--; v--;
        edge ee, ee2;
        ee.to = v; ee.s = s; ee.ord = i;
        ee2.to = u; ee2.s = s; ee2.ord = i;
        e[u].emplace_back(ee);
        e[v].emplace_back(ee2);
    }

    fill(v_check[0], v_check[0]+n, 0);
    fill(v_check[1], v_check[1]+n, 0);

    dfs(0, 0, 0);

    ll ub = 1LL << 60, lb = 1LL;
    if(!ok){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        if(v_check[i][0] == 1 && v_check[i][1] == 1){
            ll a = v_value[i][0], b = v_value[i][1];
            if((b-a) % 2 == 1){
                cout << 0 << endl;
                return 0;
            }
            else{
                lb = max(lb, (b-a)/2);
                ub = min(ub, (b-a)/2);
            }
        }
        if(v_check[i][0] == 1) lb = max(1-v_value[i][0], lb);
        if(v_check[i][1] == 1) ub = min(v_value[i][1]-1, ub);
        
    }


    cout << max(0LL, ub - lb + 1) << endl;




    return 0;
}

Measured memory_bytes: 23808
#include<iostream>
#include<string>

using namespace std;

int main(){

string s;
string p;

cin >> s;
cin >> p;

s += s;


if(s.find(p) != -1){
  cout << "Yes" << endl;
}else if (s.find(p) == -1){
  cout << "No" << endl;
}
return 0;

}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(a,b) ( (a) = (a)<0?(b):((b)<0?(a):((a)>(b)?(b):(a))) )
using namespace std;

int dp[2][10][10][2]; //dp[step&1][l][r][prv_foot]

inline bool valid(int l, int r){
  if(l==5 || r==5)return false;
  return (l-1)%3 <= (r-1)%3;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  string s;
  while(cin >> s, s!="#"){
    memset(dp,-1,sizeof(dp));
    int n = s.size();

    for(int j=1;j<=9;j++)for(int k=1;k<=9;k++){
	if(valid(j,k)){
	  dp[0][j][k][0] = dp[0][j][k][1] = 0;
	}
      }

    rep(i,n){
      int cur = i&1, nxt = 1-cur;
      for(int j=1;j<=9;j++)for(int k=1;k<=9;k++){
	  dp[nxt][j][k][0] = dp[nxt][j][k][1] = -1;
	}
      
      for(int j=1;j<=9;j++)for(int k=1;k<=9;k++){
	  int ns = s[i]-'0';
	  if(dp[cur][j][k][0] >= 0){
	    if(valid(ns,k)) chmin(dp[nxt][ns][k][0], dp[cur][j][k][0]+1);
	    if(valid(j,ns)) chmin(dp[nxt][j][ns][1], dp[cur][j][k][0]);
	  }
	  if(dp[cur][j][k][1] >= 0){
	    if(valid(ns,k)) chmin(dp[nxt][ns][k][0], dp[cur][j][k][1]);
	    if(valid(j,ns)) chmin(dp[nxt][j][ns][1], dp[cur][j][k][1]+1);
	  }
	}
    }

    int ans = -1;
    for(int j=1;j<=9;j++)for(int k=1;k<=9;k++){
	chmin(ans, dp[n&1][j][k][0]);
	chmin(ans, dp[n&1][j][k][1]);
      }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1332
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI = 3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM =
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k;
    ll a, b;
    cin >> k >> a >> b;
    for (ll i = 1;; i++)
    {
        ll hehe = k * i;
        if (hehe >= a && hehe <= b)
        {
            cout << "OK";
            return 0;
        }
        if (hehe > b)
            break;
    }
    cout << "NG";
    return 0;
}


//252908XL

/*
comments:-

*/


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int A, B;
int main() {
    cin >> A;
    cin >> B;
    if (A == 1) {
        if (B == 2) {
            cout << 3 << endl;
        } else {
            cout << 2 << endl;
        }
    } else if (A == 2) {
        if (B == 3) {
            cout << 1 << endl;
        } else {
            cout << 3 << endl;
        }
    } else {
        if (B == 2) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int INF = 1000000009;

int main() {
  int h, w, k; cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++) { cin >> s[i]; }

  int ans = INF;
  for (int bit = 0; bit < (1 << (h-1)); bit++) {
    int cur = 0;
    for (int i = 0; i < (h-1); i++) { if ((bit >> i) & 1) { cur++; } }
    int block_size = cur + 1;
    vector<int> block(block_size, 0);

    for (int i = 0; i < w; i++) {
      int block_id = 0;
      for (int j = 0; j < h; j++) {
        block[block_id] += (s[j][i] == '1');
        block_id += ( (bit >> j) & 1 );
      }
      bool is_ok = (*max_element(block.begin(), block.end()) <= k);
      if (!is_ok) {
        cur++;
        fill(block.begin(), block.end(), 0);
        block_id = 0;
        for (int j = 0; j < h; j++) {
          block[block_id] += (s[j][i] == '1');
          block_id += ( (bit >> j) & 1 );
        }
      }
      if (*max_element(block.begin(), block.end()) > k) { cur = INF; break; }
    }
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(c-a-b<0) return cout << "No", 0;
	cout << (4ll*a*b < (c-a-b)*1ll*(c-a-b) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin>>n;
    
    cout << n*(n+1)/2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
R,G,B,N = map(int,input().split())
ans = 0

for r in range(N // R + 1):

    for g in range( N // G + 1 ):

        if (N - r * R - g * G) >= 0 and (N - r * R - g * G) % B == 0:
            ans += 1

print (ans)


Measured memory_bytes: 40940
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c; cin>>a>>b>>c;
    cout << (a%b==0?0:1) << ednl;
}


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

constexpr int MAX = 100;

void print(int A[], int N){
   for(int i=0; i<N; i++){
      if(i != N-1) cout << A[i] << " ";
      else cout << A[i] << endl;
   }
}

void insertionSort(int A[], int N){
   for(int i=1; i<N; i++){
      int v = A[i];
      int j = i - 1;
      while(j>=0 && A[j] > v){
         A[j+1] = A[j];
         j--;
      }
      A[j+1] = v;
      print(A, N);
   }
}

int main()
{
   int N;
   int A[MAX];
   cin >> N;
   for(int i=0; i<N; i++) cin >> A[i];
   print(A, N);
   insertionSort(A, N);
}


Measured memory_bytes: 3124
n = int(input())
a = list(map(int, input().split()))
c = abs(0 - a[0])
for i in range(1, n):
  c += abs(a[i - 1] - a[i])
c += abs(a[n - 1] - 0)
print(c - abs(0 - a[0]) - abs(a[0] - a[1]) + abs(0 - a[1]))
for i in range(1, n - 1):
  print(c - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]))
print(c - abs(a[n - 2] - a[n - 1]) - abs(a[n - 1] - 0) + abs(a[n - 2] - 0))

Measured memory_bytes: 14168
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, ans;
char s[1000005], t[1000005];
int main(){
	scanf("%s%s", s+1, t+1);
	n=strlen(s+1);
	for(i=1; i<=n; i++){
		if(s[i]!=t[i]) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4156
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1L << 50;
enum mod = 10L^^9 + 7;

void main() {
    int n;
    scan(n);
    auto a = iota(n).map!(i => readln.split.to!(int[])).array;
    auto dp = new long[](1<<n);
    dp[0] = 1;

    foreach (s ; 1 .. 1<<n) {
        auto i = popcnt(s) - 1;
        foreach (j ; 0 .. n) {
            if (s & (1<<j) && a[i][j]) {
                dp[s] += dp[s ^ (1<<j)];
                dp[s] %= mod;
            }
        }
    }

    long ans = dp[(1<<n) - 1];
    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 18684
#include <iostream>

using namespace std;

int main()
{
	int N, M, A = 0, tmp, answer;
	cin >> N >> M;
	for (int count = 0; count < M; count++)
	{
		cin >> tmp;
		A += tmp;
	}
	if (A <= N)
	{
		answer = N - A;
	}
	else
	{
		answer = -1;
	}
	cout << answer << endl;
}

Measured memory_bytes: 3640
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <cstdio>

using namespace std;

/**
 * main
 */
int main () {
  int a, b, h;
  scanf("%d %d %d", &a, &b, &h);
  printf("%d\n", (a + b) * h / 2);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;

ll dfs(ll v) {
    vl b;
    for(auto u : G[v]) {
        b.pb(dfs(u));
    }
    sort(all(b));
    ll x = 0;
    rep(i, b.size()) {
        chmax(x, b[i]) + 1;
    }
    return x;
}

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

    G.resize(n);
    exrep(i, 1, n-1) {
        ll a;
        cin >> a;
        a--;
        G[a].pb(i);
    }
    
    out(dfs(0));
    re0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;

    string s;
    cin>>s;

    bool judge =true;

    if(s[a]!='-'){
        judge=false;
    }

    for (int i=0;i<a;i++) {
        if(s[i]=='-'){
            judge=false;
        }
    }
    for (int i=a+1;i<s.size();i++) {
        if(s[i]=='-'){
            judge=false;
        }
    }

    if(judge){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }

}


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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
using pii=pair<int, int>;
void solve(int n) {
	vector<string>s(n);
	rep(i, 0, n) {
		cin >> s[i];
	}
	vector<int>depth(n);
	rep(i, 0, n) {
		int idx = 0;
		while (idx < s[i].size() and s[i][idx] == '.') {
			s[i][idx] = ' ';
			idx++;
		}
		if (idx - 1 >= 0)s[i][idx - 1] = '+';
		depth[i] = idx - 1;
		//cout << s[i] << endl;
	}

	stack<pii>st;
	rep(i, 0, n) {
		if (st.empty()) {
			st.emplace(depth[i], i);
		}
		else {
			if (depth[i] > st.top().first) {
				st.emplace(depth[i], i);
			}
			else {
				int x = -1;
				while (depth[i] < st.top().first) {
					pii p = st.top();
					x = p.second;
					st.pop();
				}
				if (x != -1) {
					rep(idx, x, i) {
						s[idx][depth[i]] = '|';
					}
				}
				st.emplace(depth[i], i);
			}
		}
	}

	rep(i, 0, n) {
		cout << s[i] << endl;
	}
	
}

signed main() {
	for (int n; cin >> n && n;) {
		solve(n);
	}
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100001][101];
int val[101],wt[101];
ll func(int n,int w)
{
	if(w==0 || n<0)
		return 0;
	if(dp[w][n]!=-1)
		return dp[w][n];
	if(w-wt[n]<0)
		return dp[w][n] = func(n-1,w);
	else
		return dp[w][n] = max(val[n]+func(n-1,w-wt[n]),func(n-1,w));
}
int main()
{
	int n,w;
	cin>>n>>w;
	for(int i=0;i<n;i++)
		cin>>wt[i]>>val[i];
	memset(dp,-1,sizeof(dp));
	cout<<func(n-1,w);
}

Measured memory_bytes: 82480
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(std::string s) {
  int ssize = s.size();
  if (s[0] == s[ssize - 1]) {
    if (ssize % 2 == 0) {
      print("First");
    } else {
      print("Second");
    }
  } else {
    if (ssize % 2 == 0) {
      print("Second");
    } else {
      print("First");
    }
  }
}

int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


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

using ll = long long;
constexpr ll M = 1e9 + 7;

ll m_exp(const ll x, const int p) {
    if (p == 0) return 1;
    if (p % 2) return (x * m_exp(x, p - 1)) % M;
    const ll sq = m_exp(x, p / 2);
    return (sq * sq) % M;
}

int solve(const ll n) {
    if (n < 2) return 0;
    if (n == 2) return 2;

    const ll total = m_exp(10, n);
    const ll ones = m_exp(9, n);
    const ll nones = m_exp(8, n);

    return (((total - 2 * ones + nones) % M) + M) % M;
}

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

    int n;
    cin >> n;
    cout << solve(n) << '\n';

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;



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

long long A[N];
long long s[N+1];
s[0]=0;

rep(i,N){
    cin>>A[i];
    s[i+1]=s[i]+A[i];
}
map<long long,int>mp;
long long ans=0;

for(int i=1;i<=N;i++){
    long long res=s[i]%M;
    if(mp.find(res)==mp.end())mp.insert(make_pair(res,1));

    else{
        mp[res]++;
    }

    if(res==0)ans++;

}

auto it=mp.begin();

while(it!=mp.end()){
    long long  n=it->second;
    ans+=(n*(n-1))/2;
    //if(it->first==0)ans+=n;
    it++;
    
}
cout<<ans<<endl;


 return 0;
}
/*
3 2
4 1 5

3

13 17
29 7 5 7 9 51 7 13 8 55 42 9 81

6

10 400000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

25
*/


Measured memory_bytes: 5760
/*************************************************************************
    > File Name: D.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/4/29 20:27:44
 ************************************************************************/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------
vector<ll>v[6];
pii item[111];
int main(){
#ifdef HandsomeHow
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	int n;ll w;gn(n);gn(w);
	int mi = 1e9+5;
	rep(i,1,n){
		gn(item[i].first);gn(item[i].second);
		mi=min(mi,item[i].first);
	}
	rep(i,1,n){
		v[item[i].first - mi].pb(item[i].second);
	}
	ll ans = 0;
	rep(i,0,3)sort(v[i].begin(),v[i].end());
	rep(i,0,3)v[i].pb(0);
	rep(i,0,3) reverse(v[i].begin(),v[i].end());
	rep(i,0,3){
		for(int j = 1; j < (int)v[i].size(); ++j){
			v[i][j]+=v[i][j-1];
		}
	}
	rep(i,0,(int)v[0].size()-1){
		if(1ll * (i) * mi > w)
			break;
		rep(j,0,(int)v[1].size()-1){
			if(1ll * (i) * mi + 1ll * (j) * (mi + 1ll) > w)
				break;
			rep(k,0,(int)v[2].size()-1){
				if(1ll * (i) * mi + 1ll * (j) * (mi + 1ll) + 1ll * (k) * (mi + 2ll) > w)
					break;
				rep(l,0,(int)v[3].size()-1){
					if(1ll * (i) * mi + 1ll * (j) * (mi + 1ll) + 1ll * (k) * (mi + 2ll) + (l) * (mi + 3) > w)
						break;
					ll nowsu = v[0][i]+v[1][j]+v[2][k]+v[3][l];
					
					if(nowsu > ans){
						ans = nowsu;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int main(){
	cin>>n;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n && (i * j) < n; j++)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
int main(){

  int n,a[100],A = 0, B = 0;
  cin >> n;
  for (int i = 0; i < n; i++){
  cin >> a[i];
  }
  sort(a,a + n);
  for (int i = 0; i < n; i++){
  if (i % 2 == 0){
  A += a[n - 1 - i];
  }
  else{
  B += a[n - 1 - i];  
  }
  }
  
  cout << A - B << endl;

return 0;
}

Measured memory_bytes: 256
N,MOD=int(input()),10**9+7
memo=[{} for i in range(N+1)]

def ok(last4):
  for i in range(4):
    t=list(last4)
    if i!=3:
      t[i],t[i+1]=t[i+1],t[i]
    if "".join(t).count("AGC")>=1:
      return False
  return True

def solve(cur,last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur==N:
    return 1
  ret=0
  for c in "ACGT":
    if ok(last3+c):
      ret=(solve(cur+1,last3[1:]+c)+ret)%MOD
  memo[cur][last3]=ret
  return ret

print(solve(0,"TTT"))

Measured memory_bytes: 3876
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Created by YuyaKita on 16/07/13.
 */
public class Main {

    public static void main(String[] args){
        // write your code here
        
            Scanner scan = new Scanner(System.in);
            int x,y,temp;
            x = scan.nextInt();
            y = scan.nextInt();
            if(y>x){
                temp = x;
                x=y;
                y=temp;
            }
            while(y!=0){
                temp = y;
                y = x%y;
                x = temp;
            };
            System.out.println(x);


    }
}

Measured memory_bytes: 26148
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    int H[N], highest[N] = {};
    rep(i, N) cin >> H[i];
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        highest[A] = max(highest[A], H[B]);
        highest[B] = max(highest[B], H[A]);
    }
    
    rep(i, N) {
        if (highest[i] < H[i]) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  llint x, y;
  cin >> x >> y;
  llint ans = 0;
  while (x <= y) x += x, ans++;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 100005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int> adj[mex];
//a+b=a^b+2*(a&b)
ll dp[mex];
ll dp1[mex];

void dfs(int v, int p){
	
	int q=0;
	for(auto u:adj[v]){
		if(u!=p){
		 q=1;
		 dfs(u,v);
	    }
	}
	if(q==0){
		dp[v]=1;
		dp1[v]=1;
	}
	else{
		ll x=1,y=1;
		for(auto u:adj[v]){
			if(u!=p){
				x=(x*dp1[u])%mod;
				y=(y*(dp[u]+dp1[u])%mod)%mod;
			}
		}
		dp[v]=x%mod;
		dp1[v]=y%mod;
	}
}

		
int main(){
	fast
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		 int x,y;
		 cin>>x>>y;
		 adj[x].push_back(y);
		 adj[y].push_back(x);
	}
	dfs(1,1);
	cout<<(dp[1]+dp1[1])%mod;
	 
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char ch[1000];
    int n;
    cin>>n;
	scanf("%s",&ch);
	int len=strlen(ch);
	if(len<=n)
	{
		printf("%s",ch);
	}
	else
	{
		for(int i=0;i<n;i++) cout<<ch[i];
		cout<<"...";
	}
	return 0; 
}

Measured memory_bytes: 3756
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int x,y;

  int group[]={0,1,3,1,2,1,2,1,1,2,1,2,1};

  cin>>x>>y;
  
  if(group[x]==group[y]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
		 
  
  return 0;

}




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

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


signed main() {
	ll N,K;
	cin >> N >> K;
	vector<ll> a(N,0);
	rep(i,N)cin >> a[i];

	if(K==0){
		p(accumulate(a.begin(), a.end(), 0LL));
		return 0;
	}

	ll size=1+floor(log2(K));
	vector<ll> bit(size,0);

	rep(i,N){
		rep(j,size){
			if(a[i] & (1LL<<j)){
				bit[j]--;
			}else{
				bit[j]++;
			}
		}
	}

	ll k=0;
	for(ll i=size-1;i>=0;i--){
		if(bit[i]>0 && (k|(1LL<<i))<=K ){
			k|=(1LL<<i);
		}
	}
	debug(bit);
	debug(k);

	ll ans=0;
	rep(i,N){
		ans+=a[i]^k;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
xy = [list(map(int, input().split())) for _i in range(n)]
x = [i+j for i, j in xy]
y = [i-j for i, j in xy]
x.sort()
y.sort()
print(max(abs(x[0]-x[-1]), abs(y[0]-y[-1])))

Measured memory_bytes: 117548
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vector<pll> a(n) ;
	for(int i=0;i<n;i++){
		cin >> a.at(i).first >> a.at(i).second ;
	}
	sort(all(a)) ;
	for(int i=0;i<n;i++){
		k -= a.at(i).second ;
		if(k<=0){
			cout << a.at(i).first << endl ;
			return 0 ;
		}
	}
}


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

#define ll long long

int const N = 1e2 + 11, K = 1e5 + 11, MOD = 1e9 + 7;

int n, k;
int arr[N];

ll dp[N][K];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> arr[i];
    
    for (int i = 1; i <= arr[0] + 1; ++i)
        dp[0][i] = 1;
    
    for (int i = 1; i < n; ++i)
        for (int j = 1; j <= k + 1; ++j)
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][max(j - arr[i] - 1, 0)] + MOD) % MOD;
    
    cout << dp[n - 1][k + 1];
    
    return 0;
}

Measured memory_bytes: 80128
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();

    int[] elements = new int[size];
    for (int i = 0; i < size; i++) {
      elements[i] = sc.nextInt();
    }

    int searchSize = sc.nextInt();
    int[] searches = new int[searchSize];
    for (int i = 0; i < searchSize; i++) {
      searches[i] = sc.nextInt();
    }

    search(elements, searches);
  }

  public static void search(int[] elements, int[] searches) {
    int count = 0;
    int s;
    int l;
    int m;
    for (int search : searches) {
      s = 0;
      l = elements.length;
      while (true) {
        m = (s + l) / 2;

        if (elements[m]==search) {
          count++;
          break;
        }

        if (search >= elements[m]) {
          s = m + 1;
        } else {
          l = m;
        }

        if (s >= l) {
          break;
        }
      }
    }
    System.out.println(count);
  }
}



Measured memory_bytes: 68476
N, M, Q = list(map(int, input().split()))
abcd = [list(map(int, input().split())) for i in range(Q)]
# print(N, M, Q)
# print(abcd)

def calculate(A, abcd):
    total = 0
    for abcdi in abcd:
        a = abcdi[0] - 1
        b = abcdi[1] - 1
        c = abcdi[2]
        d = abcdi[3]
        if A[b] - A[a] == c:
            total += d
    # print(A, total)

    return total

import itertools
A = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# print(A)

maximum = 0
for Ai in A:
    maximum = max(calculate(Ai, abcd), maximum)

print(maximum)


Measured memory_bytes: 21664
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

			if(n == 0 && x == 0) break;

			int count = 0;
			// 重複リスト
			ArrayList<ArrayList<Integer>> duplications = new ArrayList<>();

			for(int i=1; i<=n; i++) {
				// 条件に合う組み合わせを数える
				for(int j=1; j<=n; j++) {
					if(j==i) continue;
					for(int y=1; y<=n; y++) {
						if(y == j || y == i) continue;
						if((i+j+y) == x) {
							// 重複チェック
							Boolean breakFlag = false;
							for(ArrayList<Integer> dup : duplications) {
								if(dup.indexOf(i) != -1 && dup.indexOf(j) != -1 && dup.indexOf(y) != -1) {
									breakFlag = true;
									break;
								}
								if(breakFlag) break;
							}
							if(!breakFlag) {
								count++;
								ArrayList<Integer> dup = new ArrayList<>();
								dup.add(i);
								dup.add(j);
								dup.add(y);
								duplications.add(dup);
							}
						}
					}
				}
			}

			System.out.println(count);
		}

		sc.close();

	}

}



Measured memory_bytes: 35144
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
 
const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
 
 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
 
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;

void solve(){
    int n; cin>>n;
    if(n%1000==0) cout<<0<<endl;
    else cout<<(n/1000 + 1)*1000 - n<<endl;
}
int main(){
    fastio();
    //write code
    int t; t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main(){
    ll n, k;
    cin >> n >> k;

    int max_bit = 31;
    vector<ll> a(n);
    vector<ll> b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    vector<ll> candidates;
    candidates.push_back(k);
    ll mask = 2;
    for(int i = 1; i < max_bit; i++){
        if(k&(1<<i)){
            ll tmp = k;
            tmp -= mask;
            tmp = tmp|(mask-1);
            candidates.push_back(tmp);
        }
        mask *= 2;
    }
  
    ll ans = -1;
    for(int i = 0; i < candidates.size(); i++){
        ll tmpsum = 0;
        for(int j = 0; j < n; j++){
            bool isOK = true;
            for(int bit = 0; bit < max_bit; bit++){
                if(!(candidates[i]&(1<<bit)) && a[j]&(1<<bit)){
                    isOK = false;
                    break;
                }
            }
            if(isOK){
                tmpsum += b[j];
            }
        }
        ans = max(ans,tmpsum);
    }
    cout << ans << endl;

}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();

			List<Long> orglist = new ArrayList<>(n);
			for (int i = 0; i < n; i++) {
				orglist.add(scanner.nextLong());
			}

			List<Long> sortList = new ArrayList<>(orglist);
			Collections.sort(sortList);

			int pos = n / 2;
			long val1 = sortList.get(pos - 1);
			long val2 = sortList.get(pos);

			for (int i = 0; i < n; i++) {
				long val = orglist.get(i);
				if (val <= val1) {
					System.out.println(val2);
				} else {
					System.out.println(val1);
				}
			}
		}
	}
}


Measured memory_bytes: 97448
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int R, C, k;
char g[800][801];
int cost[800][800];
int dr[4] = { -1,1,0,0 };
int dc[4] = { 0,0,-1,1 };
int main()
{
	clock_t T = clock();
	scanf("%d%d%d", &R, &C, &k);
	for (int i = 0; i < R; ++i)
		scanf("%s", g[i]);
	queue<pair<int, int> > q;
	memset(cost, -1, sizeof(cost));
	for(int i=0;i<R;++i)
		for(int j=0;j<C;++j)
			if (g[i][j] == 'S') {
				q.push(make_pair(i, j));
				cost[i][j] = 0;
				g[i][j] = '.';
				j = C;
				break;
			}
	int res = 1e9;
	while (!q.empty()) {
		int r = q.front().first;
		int c = q.front().second;
		q.pop();
		int mn = min(r, min(c, min(R - 1 - r, C - 1 - c)));
		res = min(res, 1 + (mn + k - 1) / k);
		if (cost[r][c] == k)
			continue;
		for (int i = 0; i < 4; ++i) {
			int nr = r + dr[i];
			int nc = c + dc[i];
			if (nr < 0 || nc < 0 || nr == R || nc == C || cost[nr][nc] != -1 || g[nr][nc] == '#')
				continue;
			cost[nr][nc] = cost[r][c] + 1;
			q.push(make_pair(nr, nc));
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main(){
    
    int a,b,C;
    double rad,PI,S,L,h;

    cin >> a >> b >> C;

    PI = acos(-1);//円周率
    rad = C * PI / 180;//ラジアンに変換 

    S = a * b * sin(rad) / 2.0;
    L = a + b + sqrt(a * a + b * b - 2.0 * a * b * cos(rad));
    h = S * 2.0 / a;

    printf("%lf\n",S);
    printf("%lf\n",L);
    printf("%lf\n",h);

    return 0;
}


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


using namespace std;

using ll   = long long;
using ii   = pair < int , int >;
using i3   = pair < int , ii >;
using li   = pair < ll , int >;
using lii  = pair <  ll,  ii >;
using vi   = vector < int >;
using vl   = vector < ll >;
using vli  = vector < li >;
using vii  = vector < ii >;
using vi3  = vector < i3 >;
using vlii = vector < lii >;

const int N  = 300 + 5;
const ll INF = 1e12;
const double eps = 1e-12 , PI = acos(-1);

int n , m;
ll L;

ll dis[N][N];

void floyed(){
    for(int k = 1 ; k <= n ; k ++){
            for(int i = 1 ; i <= n ; i ++){
                    for(int j = 1 ; j <= n ; j ++){
                            dis[i][j] = min(dis[i][j] , dis[i][k] + dis[k][j]);
                    }
            }
    }
}

void solve(int cs){
    scanf("%d %d %lld" , &n , &m , &L);

    for(int i = 1 ; i <= n ; i ++){
            for(int j = 1 ; j <= n ; j ++){
                    dis[i][j] = (i == j ? 0 : INF);
            }
    }

    for(int i = 0 ; i < m ; i ++){
            int u , v , w;
            scanf("%d %d %d" , &u , &v , &w);

            dis[u][v] = dis[v][u] = w;
    }

    floyed();
    for(int i = 1 ; i <= n ; i ++){
            for(int j = 1 ; j <= n ; j ++){
                    dis[i][j] = (i == j ? 0 : dis[i][j] <= L ? 1 : INF);
            }
    }
    floyed();

    int q;
    scanf("%d" , &q);
    while( q -- ){
            int u , v;
            scanf("%d %d" , &u , &v);

            printf("%lld\n" , dis[u][v] >= INF ? -1 : dis[u][v] - 1);
    }

}

main(){

    int t = 1;
    //scanf("%d" , &t);

    for(int cs = 1 ; t -- ; cs ++){
        solve(cs);
    }

    return 0;
}


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

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

  if (abs(a - c) <= d) cout << "Yes" << endl;
  else if (abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using ll = long long;
#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)

using frac = pair<ll,ll>;

ll S(ll n){
  ll res = 0;

  while(n){
    res += (n % 10);
    n /= 10;
  }

  return res;
}
ll S(string n){
  ll res = 0;

  for(int i = 0;i < n.size();i++){
    res += (ll)(n[i] - '0');
  }

  return res;
}
ll to_int(string s){

  ll res = 0;
  ll ten = 1;

  for(int i = s.size() - 1;i >= 0;i--){
    res += (ll)(s[i] - '0') * ten;
    ten *= 10;
  }

  return res;
}

ll get_snuke(ll n){

  ll res = n;
  frac tmp = make_pair(n,S(n));

  string num = to_string(n);
  int m = num.size();

  for(int i = 0;i < m;i++){
    string alt = num;
    for(char j = num[i] + 1;j <= '9';j++){
      alt[i] = j;
      for(int l = i + 1;l < m;l++){
        alt[l] = '9';
      }

      ll P = to_int(alt);
      ll Q = S(alt);

      if(tmp.first * Q > tmp.second * P){
        tmp = make_pair(P,Q);
        res = P;
      }

    }
  }

  return res;

}

int main(void){
  int k;cin >> k;
  ll tmp = 1;
  REP(i,k){
    cout << tmp << '\n';
    tmp = get_snuke(tmp + 1);
  }
}

Measured memory_bytes: 3648
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    C = [readline().strip() for _ in range(H)]

    for i in range(2 * H):
        print(C[i // 2])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int n; cin>>n;
	ll a[3*n];
	forn(i,3*n){
		cin>>a[i];
	}
	sort(a,a+3*n,greater<ll>());
	ll tot = 0;
	forn(i,2*n){
		if(i%2 == 1) tot += a[i];
	}
	cout<<tot<<ln;

	return 0;
}

Measured memory_bytes: 5988
using System;

namespace atcoder
{
    public class Class1
    {
        public static void Main()
        {
          string[] str = Console.ReadLine().Split(' ');
          int a = int.Parse(str[0]);
          int b = int.Parse(str[1]);
          int ans = Convert.ToInt32(Math.Ceiling((float)(b-1)/(float)(a-1)));
          Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,K,X,Y;
  cin>>N>>K>>X>>Y;
  int sum = 0;
  
	if (N>K) {
     sum = K*X+Y*(N-K); 
    } else {
      sum = N*X;
    }
  
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned int;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;
int const MOD = 1000000007;

int dp[2001][2001]; float dpf[2001][2001]={};

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

    int n; cin>>n; int a[n]; for (int i = 0; i < n; i++)cin>>a[i];
    sort(a,a+n);
    float ans=a[0];
    for (int i = 1; i < n; i++){
        ans=(ans+a[i])/2;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
S = input()[::-1]
i = 0
ls = len(S)
accept = True

while ls > i:
    if S[i: i+5] == "maerd" or S[i: i+5] == "esare":
        i += 5
    elif S[i: i+6] == "resare":
        i += 6
    elif S[i: i+7] == "remaerd":
        i += 7
    else:
        accept = False
        break

if accept:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188