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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int mp[505][505];

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

    int A, B;
    cin >> A >> B;
    for(int i = 1; i <= 50; ++i) {
        for(int j = 1; j <= 100; ++j) {
            mp[i][j] = 1;

        }
    }
    A--, B--;

    int x = 1, y = 1;
    while(B > 0) {
        mp[y][x] = 0;
        x += 2;
        if(x > 100) {
            y += 2;
            x = 1;

        }
        B--;
    }

    x = 1, y = 100;
    while(A > 0) {
        mp[y][x] = 1;
        x += 2;
        if(x > 100) {
            y -= 2;
            x = 1;

        }
        --A;
    }

    cout << "100 100" << endl;
    for(int i = 1; i <= 100; ++i) {
        for(int j = 1; j <= 100; ++j) {
            if(mp[i][j] == 1) cout << '.';
            else cout << "#";

        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while(s.hasNext()) {
			int n = ((s.nextInt()-1)%39+1);
			if(n > 0 && n < 10) {
				System.out.println("3C0"+n);
			}
			else {
				System.out.println("3C"+n);
			}
		}
	}
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int main()
{
  string s;
  cin >> s;
  int n = s.size();

  if((s[0] == s[n-1])^(n%2)) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
#define BOOST        std::ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define sp           <<" "<<
#define ll           long long
#define ld           long double
#define P(x,y)       pair < x,y >
#define V(x)         vector < x >
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define PI           3.14159265358979323846264338327950288419716939937510
 
const ll mod=1e9+7,N=1e6+5;

int n,a[N][3],ans[N][3]; 

int main() 
{ 
    BOOST
    
    cin>>n;
    
    for(int i=0;i<n;i++)    cin>>a[i][0]>>a[i][1]>>a[i][2];
    
    for (int k = 0; k < 3; k++)
        ans[0][k] = a[0][k];

    for (int i = 1; i<n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            ans[i][j] = a[i][j] + max(ans[i - 1][(j + 1) % 3], ans[i - 1][(j + 2) % 3]);
        }
    }

    // cout<<max( max(solve(0,0),solve(0,1)), solve(0,2) );
    cout<<max( max(ans[n-1][0],ans[n-1][1]), ans[n-1][2] );
    return 0; 
} 

Measured memory_bytes: 5504
use whiteread::parse_line;

fn main() {
    let n: i32 = parse_line().unwrap();
    let mut c: i32 = 0;
    let mut j: i32 = 0;

    for i in  1..(n+1) {
        c = 0;
        j = (i as f64).sqrt() as i32;
        if j > 1 {
            for x in 1..j {
                for y in 1..j {
                    let k: i32 = -3*(x*x) -3*(y*y) - 2*x*y + 4*i;
                    if k > 0 {
                        let z: f64 = (((-1*(x+y)) as f64) + (k as f64).sqrt()) / 2.0;
                        if z.fract() == 0.0 && z > 0.0 {
                            c = c + 1;
                        }
                    }
                }
            }
        }
        println!("{}", c);
    }
}


Measured memory_bytes: 2596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,r;
    cin>>n>>r;
    if(n>=10)
    {
        cout<<r<<endl;
    }
    else
    {
        r=(100*(10-n))+r;
        cout<<r<<endl;
    }
    return 0;
}


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

#define ll long long

#define reps(i, s, n) for (int i = s; i < (n); i++)
#define rep(i, n) reps(i, 0, n)

using namespace std;

ll n, m, k;
const ll N = 222222;
const ll mod = 998244353;
//---------------------------------------------------------------------------------------------------
ll f[N];
void init()
{
	f[0] = 1;
	reps(i, 1, N) f[i] = (f[i - 1] * i) % mod;
}
//---------------------------------------------------------------------------------------------------
// ll inv(ll x)
// {
// 	ll res = 1;
// 	ll k = mod - 2;
// 	ll y = x;
// 	while (k)
// 	{
// 		if (k & 1)
// 			res = (res * y) % mod;
// 		y = (y * y) % mod;
// 		k /= 2;
// 	}
// 	return res;
// }

ll inv(ll x, ll p)
{
	if (p == 1)
	{
		return x;
	}

	ll half = inv(x, p / 2);
	ll rest = p % 2 == 0 ? 1 : x;
	return ((half * half) % mod * rest) % mod;
}

ll inv(ll x)
{
	return inv(x, mod - 2);
}

//---------------------------------------------------------------------------------------------------
ll C(int n, int k)
{
	ll a = f[n];	 // = n!
	ll b = f[n - k]; // = (n-k)!
	ll c = f[k];	 // = k!

	return ((a * inv(b)) % mod * inv(c)) % mod;
}

void solve()
{
	init();

	ll ren[N] = {0};
	ren[0] = 1;
	ren[1] = m;
	reps(i, 2, n + 1)
	{
		ren[i] = (ren[i - 1] * (m - 1)) % mod;
	}

	ll result = 0;
	rep(i, k + 1)
	{
		ll ans = (ren[n - i] * C(n - 1, i)) % mod;
		//cout << "cha " << i << " " << ren[n - i] << " " << C(n - 1, i) << endl;

		result = (result + ans) % mod;
	}

	cout << result << endl;
}

void input()
{
	cin >> n >> m >> k;
}

int main()
{
	input();
	solve();
}


Measured memory_bytes: 6668
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
void solve(){
	ll n ;
	cin>> n ;
	set<ll> st ;
	st.insert(0);st.insert(1);st.insert(6);st.insert(8);
	if(n%10==3){
		cout<<"bon"<<endl;
		return ;
	}
	ll ps=n%10;
	if(st.count(ps))cout<<"pon"<<endl;
	else cout<<"hon"<<endl;


}
int main(){
	//mahakal(),fast;
	ll t=1,tc=1 ;
	// cin>> t;
	while(t--)solve();

	return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>

int main(){
	int h,w,i,j,sum=0;
	char s[8][9];
	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++)scanf("%s",s[i]);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j]=='#'){
				sum++;
			}
		}
	}
	if(sum==h+w-1)puts("Possible");
	else puts("Impossible");
	return 0;
}

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

#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define all(v) v.begin(),v.end()
#define mod %
#define pb push_back

const ll N = (ll)(100007);


int main()
{
	FIO
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++) {
		cin >> v[i];
	}

	int cur = 1;
	int cnt = 0;
	for(int i=0; i<n; i++) {
		if(v[i]==cur) {
			cur+=1;
			cnt+=1;
		}
	}
	if(cur == 1) {
		cout << -1 << "\n";
	} else {
		cout << n - cnt << "\n";
	}
	return 0;	
}

Measured memory_bytes: 1024
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 PRICE PICTURE 9999.
       01 RESULT PICTURE 999.
       77 TOPPING PICTURE XXX.
       PROCEDURE DIVISION.
       MAIN.
       	MOVE 700 TO PRICE.
      	ACCEPT TOPPING FROM SYSIN.
      	IF TOPPING(1:1) = 'o' THEN
      		ADD 100 TO PRICE
      	END-IF.
      	IF TOPPING(2:1) = 'o' THEN
      		ADD 100 TO PRICE
      	END-IF.
      	IF TOPPING(3:1) = 'o' THEN
      		ADD 100 TO PRICE
      	END-IF.
      	IF PRICE=1000 THEN
      		DISPLAY 1000
      	ELSE 
      		MOVE PRICE TO RESULT
      		DISPLAY RESULT UPON SYSOUT
      	END-IF.
      	STOP RUN.

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

int n, m, k;
vector<vector<int> > E(1 << 17);
vector<int> dis(1 << 17, -1);
queue<int> q;

void bfs() {
    while (!q.empty()) {
        int s = q.front();
        q.pop();
        for (int j = 0; j < E[s].size(); j++) {
            int next = E[s][j];
            if (dis[next] == -1) {
                q.push(next);
                dis[next] = dis[s] + 1;
                // cout << next << " " << dis[next] << endl;
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i, j;
    cin >> n >> m >> k;
    int d[m];
    for (i = 0; i < m; i++) {
        cin >> d[i];
    }
    vector<vector<int> > w(n, vector<int>(k, -1));
    for (i = 0; i < n; i++) {
        for (j = 0; j < k; j++) {
            int v;
            cin >> v;
            for (int l = 0; l < m; l++) {
                if (v == d[l]) w[i][j] = (1 << l);
            }
        }
    }

    for (i = 0; i < (1 << m); i++) {
        for (int l = 0; l < k; l++) {
            int nex = 0;
            for (j = 0; j < m; j++) {
                if (((i >> j) & 1) == 0) continue;
                if (w[d[j] - 1][l] >= 0) nex |= w[d[j] - 1][l];
            }
            if (nex != i) {
                E[nex].push_back(i);
                // cout << nex << " " << i << endl;
            }
        }
    }

    q.push(0);
    dis[0] = 0;
    bfs();
    cout << dis[(1 << m) - 1] << endl;
}



Measured memory_bytes: 82948
#include <bits/stdc++.h>
using namespace std;
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

const int N = 1e6 + 10;
int dp[N];
int dp2[N];

void solve()
{
   for(int i=1;i<N;i++)
       for(int j=i;j<N;j+=i) dp[j]++;
    
   int n;
    cin >> n;
    
   int res = 0;
   
   for(int i=1;i<=n;i++)
   {
       if(n-i >= 0) res+=dp[n-i];
   }
    
   cout << res;
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 11464
// Problem : B - Multiple of 9
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    string s;
    cin>>s;
    int ans = 0;
    for(char c : s) ans += c-'0';
    if(ans % 9 == 0) cout<<"Yes\n";
    else cout<<"No\n";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) ); 
// 大文字65-90(-32)
// 小文字97-122(+32)

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n; cin >> n;
  vector<int> x(n);
  rep(i,n){
    cin >> x[i];
  }
  int xmax = MAX(x);
  int xmin = MIN(x);
  ll res= INF;
  for(int i=xmin;i<=xmax;i++){
    ll temp=0;
    for(int j:x){
      temp+=(j-i)*(j-i);
    }
    res = min(temp,res);
  }
  cout << res << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ll x,i,j;
    cin >> x;
    int f = 0;
    for ( i = -118; i < 120; i++)
    {
        for ( j = -118; j < 120; j++)
        {
            if(i*i*i*i*i - j*j*j*j*j == x)
            {
                f = 1;
                break;
            }
        }
        if(f) break;    
    }
    cout << i << " " << j << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main(){
  int m;
  cin >> m;
  cin.ignore();
  while(m--){
    int tmp;
    vector<int> v;
    while(cin >> tmp && tmp != 0) v.push_back(tmp);
    int n = v.size();
    vector<int> to[200];
    int cur = 0;
    int mem[200] = {};
    int rest[200] = {};
    int level = 0;
    REP(i, n){
      while(level >= 0 && rest[level] == 0) level--;
      //printf("v[%d] = %d , lev = %d\n", i, v[i], lev);
      if(v[i] > 0){
        if(level >= 0){
          //printf("%d <-> %d\n", mem[lev - 1], cur);
          to[mem[level]].push_back(cur);
          to[cur].push_back(mem[level]);
        }
        mem[level + 1] = cur++;
        rest[level]--;
        rest[level + 1] = v[i] - 1;
        level ++;
      }else if(v[i] < 0){
        //printf("%d <-> %d\n", mem[lev], mem[lev2]);
        to[mem[level]].push_back(mem[level + v[i]]);
        to[mem[level + v[i]]].push_back(mem[level]);
        rest[level]--;
        rest[level + v[i]]--;
      }
    }
    REP(i, cur){
      printf("%d ",  i + 1);
      sort(to[i].begin(), to[i].end());
      REP(j, to[i].size()){
        printf("%d", to[i][j] + 1);
        if(j == to[i].size() - 1) cout << endl;
        else cout << " ";
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1260
r=require("fs").readFileSync("/dev/stdin","utf8").split("\n");
[x,n]=r[0].split(" ").map(x => parseInt(x));
p=r[1].split(" ").map(x => parseInt(x));
max=999;
min=-999;
s=Array.from(Array(max-min+3), (v,k) => min-1+k).filter(x => p.indexOf(x)<0);
i=0;
s.reduce(function(ac,cv,idx){
    d=Math.abs(cv-x);
    if(ac>d)
    {
        i=idx;
        return d;
    }
    return ac;
}, 9999);
console.log(s[i]);

Measured memory_bytes: 29844
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		double L = sc.nextDouble();
		
		// 計算
		double result = 0;
		result = L*L*L/27;
		
		// 出力
		//System.out.println(result);
		System.out.println(String.format("%.16f", result));
		
	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int inf=1e18;
 
int n,m,l,q,d[301][301],d2[301][301];
 
signed main(){
    cin>>n>>m>>l;
    rep(i,n)rep(j,n)if(i!=j)d[i][j]=d2[i][j]=inf;
    rep(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        d[a-1][b-1]=d[b-1][a-1]=c;
    }
    rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    rep(i,n)rep(j,n)if(d[i][j]<=l)d2[i][j]=1;
    rep(k,n)rep(i,n)rep(j,n)d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
    cin>>q;
    rep(i,q){
        int s,t;
        cin>>s>>t;
        cout<<(d2[s-1][t-1]<inf?d2[s-1][t-1]-1:-1)<<"\n";
    }
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B)cout << C;
	else if (A == C)cout << B;
	else cout << A;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

vector<ll> dist(vector<vector<P>> G, ll N, ll K){
    vector<ll> dist(N);
    vector<ll> visit(N, 0);
    dist[K] = 0;

    stack<P> sk;
    sk.push({K, 0});
    while(!sk.empty()){
        P n = sk.top();
        ll now = n.first;
        sk.pop();
        if(visit[now]) continue;
        visit[now] = 1;
        dist[now] = n.second;

        for(auto e : G[now]) if(!visit[e.first]) sk.push({e.first, n.second + e.second});
    }

    return dist;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vector<vector<P>> tree(N);
    rep(i, N - 1){
        ll a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        tree[a].pb({b, c});
        tree[b].pb({a, c});
    }
    ll Q, K;
    cin >> Q >> K;
    --K;

    vector<ll> d = dist(tree, N, K);
    rep(i, Q){
        ll x, y;
        cin >> x >> y;
        --x, --y;
        print(d[x] + d[y]);
    }
    return 0;
}

Measured memory_bytes: 17520
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int X,N;
  int x=0;
  cin>>X>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++)
  {
    cin>>p.at(i);
  }
  for(int j=0;j<N;j++)
  {
    if(X==p.at(j))
    {
      x++;
    }
  }
  if(x==0)
  {
    cout<<X<<endl;
  }else
  {
    for(int k=1;k>0;k++)
    {
      x=0;
      for(int l=0;l<N;l++)
      {
        if(X-k==p.at(l))
        {
          x++;
        }
      }
      if(x==0)
      {
        cout<<X-k<<endl;
        break;
      }
      x=0;
      for(int m=0;m<N;m++)
      {
        if(X+k==p.at(m))
        {
          x++;
        }
      }
      if(x==0)
      {
        cout<<X+k<<endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3632
def main():
  
  n,w=map(int,input().split())
  item=[[0,0]]+[list(map(int,input().split())) for _ in range(n)]
  DP=[[0]*(w+1) for _ in range(n+1)]
  for i in range(n+1):
    weight=item[i][0]
    value=item[i][1]
    for j in range(w+1):
      if j<weight:
        DP[i][j]=DP[i-1][j]
      else:
        DP[i][j]=max(DP[i-1][j],DP[i-1][j-weight]+value)
        
  print(DP[n][w])
      
if __name__=="__main__":
  main()

Measured memory_bytes: 118896
// DP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    ll h, n; cin >> h >> n;
    vector<ll> a(n);
    ll max_damage = 0;
    vector<ll> b(n);
    REP(i, n){
        cin >> a[i] >> b[i];
        max_damage = max(a[i], max_damage);
    }
    // vectorの長さは後で考える
    vector<ll> dp(h+max_damage, INF);
    dp[0] = 0;
    REP(i, h){
        REP(j, n){
            dp[a[j]+i] = min(dp[a[j]+i], b[j]+dp[i]);
        }
    }
    ll ans = INF;
    REP(i, max_damage){
        ans = min(ans, dp[h+i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    string a[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for(int i=0; i<7; i++){
        if(s==a[i]){
            cout << 7-i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d %s" (fun a b s ->
    let rec loop i =
        if i = a + b + 1 then true else
        if i = a then (if s.[i] = '-' then loop (i + 1) else false) else
            if s.[i] >= '0' && s.[i] <= '9' then loop (i + 1) else false
    in
    print_endline @@ if loop 0 then "Yes" else "No"
)

Measured memory_bytes: 3748
n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
x.sort_by!{|z| z}
y = []
(m - 1).times do |i|
  y << x[i + 1] - x[i]
end
puts n >= m ? 0 : y.sort_by!{|z| -z}.drop(n - 1).inject(:+)

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end(), greater<ll>());
    vector<ll>sum(N+1);
    sum[0] = 0;
    for (int i = 0; i < N; i++) {
        sum[i+1] = sum[i] + A[N-i-1];
    }

    vector<bool>check(N, false);
    check[N-1] = true;
    ll ans = 1;
    for (int i = 1; i < N; i++) {
        ll s = sum[N-i];
        if (2*s >= A[i-1] && check[N-i]) {
            ans++;
            check[N-i-1] = true;
        } else {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

int main() {
	int N, K; cin >> N >>K;
	for (int i = 0; i < N; ++i) cin >> h[i];

	// 初期化 (最小化問題なので INF に初期化)
	for (int i = 0; i < 100010; ++i) dp[i] = INF;

	// 初期条件
	dp[0] = 0;

	// ループ
	for (int i = 0; i < N; ++i) {
		for (int j = 1; j <= K; j++)
		{
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}

	// 答え
	cout << dp[N - 1] << endl;
}

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

int main()
{
	int N,K,X,Y;
	cin>>N>>K>>X>>Y;

	int ans1;
	if(K>N){
		ans1=N*X;
		cout<<ans1<<endl;
	}else{
		ans1=K*X+(N-K)*Y;
		cout<<ans1<<endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int x;cin>>x;cout<<!x;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vec vector
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << a << endl
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Yes "Yes"
#define YES "YES"
#define No "No"
#define NO "NO"


const ll mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint &operator+=(const mint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint &p) { x = x * p.x % mod; return *this; }
  mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; }
  mint operator-() const { return mint(-x); }
  mint operator+(const mint &p) const { return mint(*this) += p; }
  friend mint operator+(const int &c,const mint &p) { return mint(c) += p; }
  mint operator-(const mint &p) const { return mint(*this) -= p; }
  friend mint operator-(const int &c,const mint &p) { return mint(c) -= p; }
  mint operator*(const mint &p) const { return mint(*this) *= p; }
  friend mint operator*(const int &c,const mint &p) { return mint(c) *= p; }
  mint operator/(const mint &p) const { return mint(*this) /= p; }
  friend mint operator/(const int &c,const mint &p) { return mint(c) /= p; }
  bool operator==(const mint &p) const { return x == p.x; }
  friend bool operator==(const int &c,const mint &p) { return mint(c) == p; }
  bool operator!=(const mint &p) const { return x != p.x; }
  friend bool operator!=(const int &c, const mint &p) { return mint(c) != p; }
  mint inverse() const {
    ll a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return mint(u);
  }
  mint pow(ll n) const {
    mint ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os,const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is,mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};


int main() {
  int N,K;
  cin >> N >> K;
  vec<pair<int,int>> S(K);
  vec<mint> dp(N+1);
  rep(i,K) {
    cin >> S[i].first >> S[i].second;
  }
  dp[0] = 1;
  mint sum = 0;
  rep(i,N) {
    dp[i] += sum;
    if (i > 0)
      sum = dp[i];
    rep(k,K) {
      if (S[k].first+i >= N)
        continue;
      dp[S[k].first+i] += dp[i];
      if (S[k].second+i >= N)
        continue;
      dp[S[k].second+i+1] -= dp[i];
    }
  }
  print(dp[N-1]);
  return 0;
}

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

int main(){
    int k,n;
    cin>>n>>k;
    vector<int>h(n);
    int64_t sum=0;
    for(int i=0; i<n; i++){
        cin>>h.at(i);
    }
    if(n<=k) cout<<0<<endl;
    else{
        sort(h.begin(),h.end());
        for(int i=0; i<n-k; i++){
            sum+=h.at(i);
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    string s;
    cin >> s;
    
    int ans = 0;
    REP(i, 4){
        if(s[i] == '+')ans++;
        else ans--;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var a, b int 
    fmt.Scan(&a, &b) 
    if a == 1 { 
        if b == 1 { 
            fmt.Println(1)
        } else {
            fmt.Println(b - 2)
        }   
    } else if b == 1 { 
        fmt.Println(a - 2)
    } else {
        fmt.Println((a - 2) * (b - 2)) 
    }   
}


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

int main()
{
	int date;
  	cin>>date;
  	cout<<"Christmas";
  	date-=25;
  	date*=-1;
  	for(int i=0 ; i<date ; ++i)
    cout<<" Eve";
  	cout<<endl;
	return 0;
}

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

using namespace std;

#define ll long long
#define fr(i,n) for(int i=0; i<n; ++i)
#define frr(i,n) for(int i=n; i>=0; --i)

int main(){

    int n, k;
    cin>>n>>k;
    vector<int> A(n);
    fr(i, n) cin>>A[i];
    vector<int> dp(n, INT_MAX);
    dp[0]=0;
    for(int i=1; i<n; i++){
        for(int j=i-1; j>=0 && j>=i-k;--j){
            dp[i]=min(dp[i], dp[j]+abs(A[j]-A[i]));
        }
    }
    cout<<dp[n-1];
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = (int) 1e5 + 123;

int n;
vector<pair<int, int>> g[N];
ll dist[N];

void dfs(int v, int p = -1, ll cur = 0) {
    dist[v] = cur;
    for (auto &e : g[v]) {
        int u = e.first;
        if (u != p) dfs(u, v, cur + e.second);
    }
}

void run() {
    cin >> n;
    rep(i, 0, n - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].pb({b, c});
        g[b].pb({a, c});
    }
    int q, k;
    cin >> q >> k;
    dfs(k);
    rep(i, 0, q) {
        int u, v;
        cin >> u >> v;
        cout << dist[u] + dist[v] << "\n";
    }
}


Measured memory_bytes: 12800
#include <iostream>

class Node {
public:
    long long int A;
    long long int B;
    Node* smaller;
    Node* bigger;
    
    Node();
};
Node::Node() {
    A = B = 0;
    smaller = bigger = 0;
}

void showNode(Node* root) {
    if (!root) {
        return;
    }
    showNode(root->smaller);
    std::cout << root->A << ' ' << root->B << std::endl;
    showNode(root->bigger);
}

void joinNode(Node* root, Node* node) {
    if (!root) {
        return;
    }
    
    if (root->A == node->A) {
        root->B += node->B;
    } else if (root->A > node->A) {
        if (root->smaller) {
            joinNode(root->smaller, node);
        } else {
            root->smaller = node;
        }
    } else if (root->A < node->A) {
        if (root->bigger) {
            joinNode(root->bigger, node);
        } else {
            root->bigger = node;
        }
    }
    return;
}

int m = 0;
long long int calc (Node *root) {
    if (!root) {
        return 0;
    }
    if (m <= 0) {
        return 0;
    }
    
    long long int amount = 0;
    amount += calc(root->smaller);
//    std::cout << root->A << ' ' << root->B << ' ' << amount << ' ' << m << std::endl;
    if (m > 0) {
        if (m > root->B) {
            amount += root->A * root->B;
            m -= root->B;
        } else {
            amount += root->A * m;
            m = 0;
        }
    }
    amount += calc(root->bigger);
    return amount;
}

int main() {
    int N, M;
    std::cin >> N >> M;
    long long int A;
    long long int B;
    Node *nodes = new Node[N];
    Node *root = &nodes[0];
    std::cin >> A >> B;
    root->A = A;
    root->B = B;
    for (int i = 1; i < N; i++) {
        Node* node = &nodes[i];
        std::cin >> A >> B;
        node->A = A;
        node->B = B;
        joinNode(root, node);
    }
    // showNode(root);
    m = M;
    std::cout << calc(root);
    delete [] nodes;
}

Measured memory_bytes: 3328
X,Y,A,B,C=map(int,input().split())
ls_a=list(map(int,input().split()))
ls_b=list(map(int,input().split()))
ls_c=list(map(int,input().split()))

ls_a.sort(reverse=True)
ls_b.sort(reverse=True)
ls_c.sort(reverse=True)

ls=sorted(ls_a[:X]+ls_b[:Y])
ans=sum(ls)
for i in range(min(X+Y, C)):
    if ls[i] < ls_c[i]:
        ans += ls_c[i] - ls[i]
print(ans)

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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
int n,m,k;
const int maxn=1e5+7;
ll a[maxn<<4];
ll mp[11];
ll tot;
ll t,zero,u,v;
int dx[10]={0,-1,-1,-1,0,0,0,1,1,1};
int dy[10]={0,-1,0,1,-1,0,1,-1,0,1};
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n>>m>>k;
	rep(i,k){
		int p,q;
		cin>>p>>q;
		rep(j,9){
			if(p+dx[j]>=2&&p+dx[j]<=n-1&&q+dy[j]>=2&&q+dy[j]<=m-1){
				tot++;
				a[tot]=(p+dx[j])*INF+q+dy[j];
			}
		}
	}
	sort(a+1,a+tot+1);
	u=n-2;
	v=m-2;
	zero=u*v;
	t=1;
	rep(i,tot){
		if(a[i]==a[i+1]){
			t++;
		}
		else{
			mp[t]++;
			zero--;
			t=1;
		}
	}
	mp[0]=zero;
	rep0(i,10){
		cout<<mp[i]<<endl;
	}
	return 0;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int y;
string ans = "No";

int main() {  // TODO
  int x;
  cin >> x >> y;
  for (int i = 0; i <= x; i++) {
    if ((i * 2) + ((x - i) * 4) == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
using namespace std;
int a[10];
int main(){
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a + 3);
  if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    long long n, k;
    cin >> n >> k;

    long long ans = LLONG_MAX;
    int count = 0;
    while (true) {
        n = min(n % k, abs(n - k));
        if (ans > n) {
            ans = n;
            count = 0;
        } else
            count++;
        if (count == 2) break ;
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if (s.at(1)!=s.at(2)&&(s.at(0)==s.at(1)&&s.at(2)==s.at(3))) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
const N,K=map(x->parse(Int,x),split(readline()))
const mod=10^9+7
const L=Int[]
const R=Int[]
function f(dp)
	N=length(dp)
	next=zeros(Int,N)
	now=0
	for i=N:-1:1
		now=(now+dp[N-i+1])%mod
		next[i]=now*(R[i]-L[i]+1)%mod
	end
	next
end
function init()
	id=0
	for i=1:isqrt(N)
		id+=1
		push!(L,i)
		push!(R,i)
	end
	T=L[id]
	T-=T*T==N
	for t=T:-1:1
		id+=1
		push!(L,R[id-1]+1)
		push!(R,div(N,t))
	end
	dp=R-L.+1
	for i=2:K
		dp=f(dp)
	end
	println(sum(dp)%mod)
end
init()


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

int main() {
	string S;
	cin >> S; REP(i, S.size()) S[i] -= '0';
	
	int ans = S.size();
	REP(i, S.size() - 1) if (S[i] != S[i + 1])
		chmin(ans, max(i + 1, (int)S.size() - i - 1));
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
const ll mod=1e9+7;

int32_t main()
{
    SPEED;
    int N,W,w[101],v[101];
    cin>>N>>W;
    int maxv=0;
    for (int i = 1; i <= N; ++i)
    {
        cin>>w[i]>>v[i];
        maxv+=v[i];
    }
    int dp[N+1][maxv+1];
    memset(dp,0,sizeof(dp));
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= maxv; ++j)
        {
            if(i==1)
            {
                if(j==v[i])
                    dp[i][j]=w[i];
                else
                    dp[i][j]=INT_MAX;
            }
            else
            {
                dp[i][j]=dp[i-1][j];
                if(j>=v[i])
                {
                    dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
                }
            }
            //cout<<j<<endl;
        }
        //cout<<1<<endl;
    }
    //cout<<2<<endl;
    int ans=0;
    map<ll,ll>mp;
    for (int i = 0; i <= maxv; ++i)
    {
        //cout<<dp[N][i]<<endl;
        if(dp[N][i]<=W)
        {
            ans=i;
            //mp[dp[N][i]]=1;
        }
    }
    cout<<ans<<endl;
}



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

int main() {
  string s, s2;
  int total = 0;
  cin >> s;
  cin >> s2;
  for (int i = 0; i < s.length(); i++) {
      if (s[i] != s2[i]) {
          total++;
      }
  }
  cout << 3-total;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
A = []
for _ in range(N):
    A.append(list(input().rstrip()))
B = []
for _ in range(M):
    B.append(list(input().rstrip()))
n = len(A[0])
m = len(B[0])
def search(point):
    x, y = point
    for i in range(M):
        if y > N - 1:
            return 0
        a = A[y][x:x + m]
        if a != B[i]:
            return 0
        y += 1
    return 1
for i in range(N):
    for j in range(n):
        if search([i, j]):
            print("Yes")
            sys.exit()
print("No")







Measured memory_bytes: 3064
def show_list(num_list):
    for i in range(len(num_list)):
        print(str(num_list[i]), end="")
        if i < len(num_list)-1:
            print(" ", end="")
        else:
            print()

input_num = int(input())
num_list = [int(i) for i in input().split()]
show_list(num_list)
for i in range(1, len(num_list)):
    v = num_list[i]
    j = i - 1
    while j >= 0 and num_list[j] > v:
        num_list[j+1] = num_list[j]
        j -= 1
    num_list[j+1] = v
    show_list(num_list)

Measured memory_bytes: 8532
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
//#include <map>
#include <iomanip>
#include <vector>

using namespace std;



int main()
{
	int heya[4][3][10];
	int n, b, f, r, v;
	bool first_flag;
	
	for (int i=0; i<4; i++)
	{
		for (int j=0; j<3; j++)
		{
			for (int k=0; k<10; k++)
			{
				heya[i][j][k] = 0;
			}
		}
	}
	
	cin >> n;
	for (int i=0; i<n; i++)
	{
		cin >> b >> f >> r >> v;
		heya[b-1][f-1][r-1] += v;
	}
	
	first_flag = true;
	for (int i=0; i<4; i++)
	{
		if (!first_flag)
		{
			cout << "####################" << endl;
		} else {
			first_flag = false;
		}
		for (int j=0; j<3; j++)
		{
			for (int k=0; k<10; k++)
			{
				cout << " " << heya[i][j][k];
			}
			cout << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main(void)
{
	int a, b, h;
	cin >> a >> b >> h;
	int ans;
	ans = (a + b)*h/2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
using graph = vector<vector<int>>;
typedef long long ll;

int main() {
	ll n;
	cin >> n;
	ll mem;
	vector<ll> ninzu(n, 0);
	for (ll i = 0; i < n - 1; i++) {
		cin >> mem;
		ninzu[mem - 1] ++;
	}
	for (ll i = 0; i < n; i++) {
		cout << ninzu[i] << endl;
	}
	return 0;
}


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

using namespace std;

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

const string s[4] = { "dream", "dreamer", "erase", "eraser" };

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

	bool ok = true;
	while(!S.empty()){
		bool update = false;
		rep (i, 4){
			if (S.length() < s[i].length()) continue;
			string T = S.substr(S.length() - s[i].length());
			if (T == s[i]){
				S = S.substr(0, S.length() - s[i].length());
				update |= true;
				break;
			} // end if
		} // end rep
		if (!update){
			ok = false;
			break;
		} // end if
	} // end while

	cout << (ok ? "YES" : "NO") << endl;
	
	return 0;
}

Measured memory_bytes: 592
while line = gets
    h, w = line.split.map(&:to_i)
    break if h == 0 && w == 0
    for i in 1..h
        if i == 1 || i == h
            for j in 1..w
                print "#"
            end
        else
            print "#"
            for j in 2..(w-1)
                print "."
            end
            print "#"
        end
        puts ""
    end
    puts ""
end

Measured memory_bytes: 6860
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
#include <queue>
using namespace std;

typedef long long ll;

#define INF 100000000;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define eps 1.0e-14;

using pint = pair<ll,ll>;

int main(){
	ll n; cin >> n;
	ll a[200006];
	map<ll,ll> mp;
	repl(i,n) mp[i] = 0;
	repl(i,n){
		cin >> a[i];
		mp[a[i] + (i + 1)]++; //1_indexed
		//cout << a[i] + (i + 1) << endl;
	}
	ll ans = 0;
	repl(i,n){
		//cout << mp[a[i] - (i + 1)] << endl;
		ll soeji = ((i + 1) - a[i]);
		if (mp[soeji] >= 1){
			ans += mp[soeji];
			//cout << soeji << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35280
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int A[15][15] = {};
	for (int n; cin >> n&&n;) {
		memset(A, 0, sizeof(A));
		rep(i, 0, n) {
			rep(j, 0, n) {
				cin >> A[i][j];
				A[i][n] += A[i][j];
				A[n][j] += A[i][j];
				A[n][n] += A[i][j];
			}
		}
		rep(i, 0, n + 1) {
			rep(j, 0, n + 1) {
				cout << setfill(' ') << setw(5) << A[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

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

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

    map<std::pair<std::string, int> , int>mp;

    int N; cin >> N;

    for (int i = 0;i < N;i++){
        string s; int a;
        cin >> s >> a;
        mp[{s,-a}] = i+1;
    }

    //sort(lis.begin(),lis.end());

    for(auto&& i:mp){
        cout << i.second << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    cin>>n;
    ll ans=0;
    ll p=n/500;
    ans+=p*1000;
    n-=p*500;
    ans+=(n/5)*5;
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3660