akhauriyash/Code-Regression huggingface dataset:
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a <= b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vector<string> v,w;
    string ans;
    rep(i, n+1) {
        string s;cin >> s;
        if(i==n) ans=s;
        string t = s;
        rep(j, s.size()) {
            if(s[j]=='?') {
                s[j]='a';
                t[j]='z';
            }
            
        }
        v.pb(s);w.pb(t);
    }
    sort(all(v));sort(all(w));
    // cout << endl;
    // for(auto p:v)cout << p << endl;
    // cout << endl;
    // for(auto p:w)cout << p << endl;
    int start,end;
    bool ok = false;
    rep(i, n+1) {
        if(v[i]==ans) {
            end=i+1;
            // cout << "oke" << endl;
        }
        if(!ok)if(w[i]==ans) {
            start=i+1;
            ok = true;
            // cout << "oks" << endl;
        }
    }
    // cout << ans << endl;
    // cout << start << ' ' << end << endl;
    for(int i = start;i<=end;i++) {
        cout << i;
        if(i==end)cout << endl;
        else cout << ' ';
    }
    return 0;
}

Measured memory_bytes: 4380
def fast_powmod(n, m):
    pow2 = 2
    result = 1
    while n > 0:
        if n % 2 == 1:
            result = (result * pow2) % m
        pow2 = (pow2 * pow2) % m
        n >>= 1

    return result

def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

n = int(input())
x = input()

res = dict()
res[1] = 1
res[2] = 1
for i in range(3, 2 * 10**5 + 1):
    val = i % popcnt3(i)
    if val == 0:
        res[i] = 1
    else:
        res[i] = res[val] + 1

count = 0
for i in x:
    if i == "1":
        count += 1

x = x[::-1]
small = 0
big = 0
for i in range(len(x)):
    if x[i] == "1":
        if count - 1 != 0:
            small += fast_powmod(i, count - 1)
        big += fast_powmod(i, count + 1)

try:
    small %= count - 1
except:
    small = 0
big %= count + 1

anse = []
for i in range(len(x)):
    if x[i] == "1":
        done = False
        ans = 0
        if count - 1 == 0:
            anse.append(0)
        else:
            cur = small - fast_powmod(i, count - 1)
            cur %= count - 1
            if cur == 0:
                anse.append(1)
            else:
                anse.append(res[cur] + 1)
    else:
        done = False
        ans = 0
        cur = big + fast_powmod(i, count + 1)
        cur %= count + 1
        if cur == 0:
            anse.append(1)
        else:
            anse.append(res[cur] + 1)


for i in anse[::-1]:
    print(i)
                
        
        
# print(small, big)
        



Measured memory_bytes: 102332
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;


int main(void){
    int n;cin >> n;
    vector<bitset<2000> > wins(2000);
    for(int i = 0;i < n;i++){
        wins[i][i] = 1;
        if(i > 0){
            string s;cin >> s;
            for(int j = 0;j < i;j++){
                wins[i][j] = (s[j] == '1');
                wins[j][i] = !wins[i][j];
            }
        }
    }
    
    vector<bitset<2000> > dpr(2000),dpl(2000),dpr2(2000),dpl2(2000);
    for(int d = 0;d < n;d++){
        if(d == 0){
            for(int i = 0;i < n;i++){
                dpr[i][i] = dpl[i][i] = dpr2[i][i] = dpl2[i][i] = 1;
            }
            continue;
        }
        
        for(int i = 0;i + d < n;i++){
            int j = i + d;
            bitset<2000> merged;
            merged = (wins[i] & dpr2[i+1] & dpl2[j]);
            if(merged.count() > 0){
                dpl[i][j] = dpl2[j][i] = 1;
            }
        }

        for(int i = n-1;i - d >= 0;i--){
            int j = i - d;
            bitset<2000> merged = (wins[i] & dpl2[i-1] & dpr2[j]);
            if(merged.count() > 0){
                dpr[i][j] = dpr2[j][i] = 1;
            }
        }
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        if(dpr[i][0] & dpl[i][n-1])ans++;
    }
    cout << ans << '\n';

}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#define lli long long int
#define loop(i,x,n) for(int i=x;i<n;i++)
#define loopr(i,x,n) for(int i=n-1;i>=x;i--)
#define st set<lli>
#define v vector<lli>
#define um unordered_map<lli,lli>
#define vpl vector<pair<lli,lli>>
#define llu long long unsigned
#define ms muliset<int,greater<int>>
#define ums unordered_map<string,lli>
#define pb push_back
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test lli t; cin>>t; while(t--)
using namespace std;
int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
v adj[100001];
lli vist[10001];

void dfs(lli node)
{
    vist[node]=1;
    for(lli child : adj[node]) if(!vist[child]) dfs(child);
}

int main()
{
    time
    lli x;
  cin>>x;
  if(x==0) cout<<"1";
  else if(x==1) cout<<"0";
  cout<<endl;
    return 0;
}

Measured memory_bytes: 5952
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,oo=1e9;
char s[N];
int n,temp_tot,o,min_a=1;
int nxt[30][N],g[N],a[N]; //g[i]为不包括i在组内没有出现的最小字母，（写包括一直wa） 
bool vis[30];
int main(){
//	freopen("in.txt","r",stdin);
	scanf("%s",s+1);
	n=strlen(s+1); //s+1 !!
	for(int i=1;i<=n;i++) a[i]=s[i]-'a'+1;
	for(int i=1;i<=26;i++) nxt[i][n+1]=oo;
	for(int i=n;i>=1;i--){
		for(int j=1;j<=26;j++) nxt[j][i]=nxt[j][i+1];
		nxt[a[i]][i]=i; //!
		g[i]=min_a; 
		if(!vis[a[i]]) vis[a[i]]=1;
		while(vis[min_a]) min_a++;
		if(min_a>26){
			min_a=1;
			memset(vis,0,sizeof(vis));
		}
	}
	for(int i=1;i<=26;i++) nxt[i][0]=nxt[i][1];
	nxt[a[1]][0]=1;
	g[0]=min_a,g[n+1]=1;
	int t=0;
	while(t<=n){
		putchar(g[t]+'a'-1);
//		cout<<" "<<g[t]<<endl;
		t=nxt[g[t]][t+1];
	}
	return 0;
}

Measured memory_bytes: 24576
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A, B, x;

int main() {
  INCANT;
  cin >> x >> A >> B;
  char ans = abs(x-B)>abs(x-A)?'A':'B';
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def solve():
  n,W = (int(i) for i in input().split())
  query = []
  for i in range(n):
    w,v = (int(i) for i in input().split())
    query.append((w,v))
  dp = [[0]*(W+1) for _ in range(n+1)]
  for i in range(n):
    nw,nv = query[i]
    for weight in range(W):
      if weight+nw <= W:
        dp[i+1][weight+nw] = max(dp[i][weight+nw],dp[i][weight]+nv)
      dp[i+1][weight] = max(dp[i][weight],dp[i+1][weight])
  print(dp[n][W])
solve()

Measured memory_bytes: 119664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct Cake {
    ll x, y, z;
};

bool cmp1(const Cake &a, const Cake &b) {
    ll as = a.x + a.y + a.z;
    ll bs = b.x + b.y + b.z;
    return (as > bs);
}

bool cmp2(const Cake &a, const Cake &b) {
    ll as = a.x + a.y - a.z;
    ll bs = b.x + b.y - b.z;
    return (as > bs);
}

bool cmp3(const Cake &a, const Cake &b) {
    ll as = a.x - a.y + a.z;
    ll bs = b.x - b.y + b.z;
    return (as > bs);
}

bool cmp4(const Cake &a, const Cake &b) {
    ll as = a.x - a.y - a.z;
    ll bs = b.x - b.y - b.z;
    return (as > bs);
}

bool cmp5(const Cake &a, const Cake &b) {
    ll as = -a.x + a.y + a.z;
    ll bs = -b.x + b.y + b.z;
    return (as > bs);
}

bool cmp6(const Cake &a, const Cake &b) {
    ll as = -a.x + a.y - a.z;
    ll bs = -b.x + b.y - b.z;
    return (as > bs);
}

bool cmp7(const Cake &a, const Cake &b) {
    ll as = -a.x - a.y + a.z;
    ll bs = -b.x - b.y + b.z;
    return (as > bs);
}

bool cmp8(const Cake &a, const Cake &b) {
    ll as = -a.x - a.y - a.z;
    ll bs = -b.x - b.y - b.z;
    return (as > bs);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<Cake> xyz(n);
    ll ans = LONG_MIN;
    ll tmp;
    rep(i, n) cin >> xyz[i].x >> xyz[i].y >> xyz[i].z;
    
    // x + y + z
    sort(all(xyz), cmp1);
    tmp = 0;
    rep(i, m) tmp += xyz[i].x + xyz[i].y + xyz[i].z;
    ans = max(ans, tmp);
    
    // x + y - z
    sort(all(xyz), cmp2);
    tmp = 0;
    rep(i, m) tmp += xyz[i].x + xyz[i].y - xyz[i].z;
    ans = max(ans, tmp);
    
    // x - y + z
    sort(all(xyz), cmp3);
    tmp = 0;
    rep(i, m) tmp += xyz[i].x - xyz[i].y + xyz[i].z;
    ans = max(ans, tmp);
    
    // x - y - z
    sort(all(xyz), cmp4);
    tmp = 0;
    rep(i, m) tmp += xyz[i].x - xyz[i].y - xyz[i].z;
    ans = max(ans, tmp);
    
    // -x + y + z
    sort(all(xyz), cmp5);
    tmp = 0;
    rep(i, m) tmp += -xyz[i].x + xyz[i].y + xyz[i].z;
    ans = max(ans, tmp);
    
    // -x + y - z
    sort(all(xyz), cmp6);
    tmp = 0;
    rep(i, m) tmp += -xyz[i].x + xyz[i].y - xyz[i].z;
    ans = max(ans, tmp);
    
    // -x - y + z
    sort(all(xyz), cmp7);
    tmp = 0;
    rep(i, m) tmp += -xyz[i].x - xyz[i].y + xyz[i].z;
    ans = max(ans, tmp);
    
    // -x - y - z
    sort(all(xyz), cmp8);
    tmp = 0;
    rep(i, m) tmp += -xyz[i].x - xyz[i].y - xyz[i].z;
    ans = max(ans, tmp);
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int N;
vector<vector<int>> g;

int tapu(int s) {
	vector<int> cost(N, -1);
	cost[s] = 0;
	deque<pair<int, int>> que;
	que.emplace_back(s, -1);
	bool ok = true;
	while (!que.empty()) {
		auto p = que.front(); que.pop_front();
		if (!ok) { break; }

		int u = p.first, pre = p.second;
		for (auto v : g[u]) {
			if (v == pre) { continue; }
			if (cost[v] < 0) {
				cost[v] = cost[u] + 1;
				que.emplace_back(v, u);
				continue;
			}
			if (cost[v] % 2 != (cost[u] + 1) % 2) {
				ok = false;
				continue;
			}
			if (cost[v] > cost[u] + 1) {
				cost[v] = cost[u] + 1;
				que.emplace_back(v, u);
			}
		}
	}

	return (ok ? *max_element(cost.begin(), cost.end()) + 1 : -1);
}

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

	g.resize(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (s[i][j] == '1') { g[i].push_back(j); }
		}
	}

	int ans = -1;
	for (int i = 0; i < N; ++i) {
		ans = max(ans, tapu(i));
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long int ll;

int main()
{
	int n, count = 0;
	string s;
	cin >> n;
	cin >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'C') {
			if (s[i - 2] == 'A' && s[i - 1] == 'B') {
				count++;
			}
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}



int main(void){
    int n,ans;
    cin>>n;
    ans=n;
    string s;
    vector<int> w(n+1);
    vector<int> e(n+1);
    cin>>s;
    rep(i,n){
        if(s[i]=='W'){
            w[i+1]=w[i]+1;
            e[i+1]=e[i];
        }else{
            w[i+1]=w[i];
            e[i+1]=e[i]+1;
        }
    }
    rep(i,n)ans=min(ans,w[i]-w[0]+e[n]-e[i+1]);
    cout<<ans;
}



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

int main() {
    ll N;
    string S;
    cin >> N >> S;
    // 白を黒に変えるときの数
    vector<ll> right(N+1,0);
    for(int i=0;i<N;i++){
        right[i+1] += right[i];
        if(S[i] == '#'){
            right[i+1]++;
        }
    }
    vector<ll> left(N+1,0);
    for(int i=N-1;i>=0;--i){
        left[i] += left[i+1];
        if(S[i] == '.'){
            left[i]++;
        }
    }

    ll ans = N;
    for(int i=0;i<=N;i++){
        ans = min(ans,right[i]+left[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6812
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    string S, T;

    cin >> S >> T;

    cout << T << S << endl;

    return 0;
    
}

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

int main(){
  long long N,a,b,c;
  a=0;
  b=0;
  c=1;
  cin>>N;
  vector<int> P(N);
  vector<int> Q(N);
  for(int i=0;i<N;i++) cin>>P.at(i);
  for(int i=0;i<N;i++) cin>>Q.at(i);
  //vec=整数昇順
  
  vector<int> vec(N);
  for(int i=0;i<N;i++) vec.at(i)=i+1;

  do{
    
   if(vec==P){
     a=c;
   }
    
   if(vec==Q){
      b=c;
    }
    
     c++;
    
  }while( next_permutation(vec.begin(), vec.end()) );
  
  cout <<abs(a-b) <<endl;
}



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

using namespace std;

const int N = 10000;

bool is_prime[N+1];
int n;

void sieve(){
  fill(is_prime, is_prime+N, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<=N;i++) if(is_prime[i]) for(int j=i+i;j<=N;j+=i) is_prime[j] = false;
}

main(){
  sieve();
  while(cin >> n){
    int ans = 0;
    for(int i=0;i<n;i++) if(is_prime[i+1] && is_prime[n-i]) ans++;
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		String s = in.next();
		int n = in.nextInt();
		int ans1 = s.charAt(0) - '0';
		for (int i=1; i<s.length(); i+=2) {
			if (s.charAt(i) == '+') {
				ans1 += s.charAt(i+1) - '0';
			} else {
				ans1 *= s.charAt(i+1) - '0';
			}
		}
		ArrayDeque<Integer> stack = new ArrayDeque<>();
		stack.add(s.charAt(0) - '0');
		for (int i=1; i<s.length(); i+=2) {
			if (s.charAt(i) == '+') {
				stack.add(s.charAt(i+1) - '0');
			} else {
				stack.add(stack.pollLast()*(s.charAt(i+1) - '0'));
			}
		}
		int ans2 = 0;
		while (stack.size() > 0) ans2 += stack.poll();

		if (ans1 == n) {
			if (ans2 == n) out.println("U");
			else out.println("L");
		} else {
			if (ans2 == n) out.println("M");
			else out.println("I");
		}
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

using namespace std;

int main()
{
    long long n,ans=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        if(a[i-1]>a[i])
        {
            ans+=a[i-1]-a[i];
            a[i]+=a[i-1]-a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4368
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,i,j,cnt;
    string a;
    set<string>s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<endl;
return 0;
}


Measured memory_bytes: 19192
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int nax=1e3+5;
int dp[nax][nax];
char grid[nax][nax];
void add_self(int &a,int b)
{
    a+=b;
    if(a>=mod)
        a-=mod;
}
int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
        scanf("%s",&grid[i]);
    dp[0][0]=1;
    for(int row=0;row<h;row++)
        for(int col=0;col<w;col++)
    {
        for(int r:{row,row+1})
            {
                int c=col;
                if(r==row)
                    c=col+1;
                if(r<h&&c<w&&grid[r][c]!='#')
                    add_self(dp[r][c],dp[row][col]);
            }

    }
    cout<<dp[h-1][w-1]<<endl;
    return 0;

}


Measured memory_bytes: 5120
# -*- coding: utf-8 -*-

##
## A - Frog1
## https://atcoder.jp/contests/dp/tasks/dp_a
##

import sys

def solve(N, nums):
    assert N > 0
    if N == 1:
        return 0
    cost_2 = 0
    cost_1 = abs(nums[1] - nums[0])
    for i in range(2, N):
        c1 = cost_1 + abs(nums[i] - nums[i-1])
        c2 = cost_2 + abs(nums[i] - nums[i-2])
        cost_i = min(c1, c2)
        cost_2 = cost_1
        cost_1 = cost_i
    return cost_1

def load(input):
    line = input.readline()
    N = int(line.strip())
    #buf = []; add = buf.append
    #size = 2**16
    #s = input.read(size)
    #while s:
    #    add(s)
    #    s = input.read(size)
    #return N, "".join(buf)
    return N, input.read()

def main():
    N, string = load(sys.stdin)
    nums = [ int(x) for x in string.split() ]
    result = solve(N, nums)
    print(result)

main()


Measured memory_bytes: 14404
#include<bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define int long long 
using namespace std;

int32_t main(){

    int n;  cin >> n;
    vector<int> a(n);   for(int x=0;x<n;x++)    cin >> a[x];

    deque<int> f;

    if(n&1){
        int flag = 0;
        for(int x=0;x<n;x++){
            int val = a[x];
            if(flag) f.push_front(val);
            else f.push_back(val);
            flag = !flag;
        }
    }else{
        int flag = 0;
        for(int x=0;x<n;x++){
            int val = a[x];
            if(flag) f.push_back(val);
            else f.push_front(val);
            flag = !flag;
        }
    }

    vector<int> ans;

    for(auto val : f)   ans.push_back(val);
    reverse(all(ans));

    for(auto x : ans)   cout << x << " ";   cout << endl;

    return 0;
}

Measured memory_bytes: 7152
#include<cstdio>
#include<cmath>
int arr[105];
int main()
{
    int n;
    int max=-1;
    int num;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        if(i%2==1)
            arr[i]=0;
        else
        {
            arr[i]=arr[i/2]+1;
        }
        if(arr[i]>max)
        {
            num=i;
            max=arr[i];
        }
    }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 128
from collections import deque

K = int(input())
queue = deque([1,2,3,4,5,6,7,8,9])

for i in range(K):
    ans = queue.popleft()
    x = ans % 10
    if x != 0:
        queue.append(ans*10 + x - 1)
    queue.append(ans*10 + x)
    if x != 9:
        queue.append(ans*10 + x + 1)

print(ans)

#解説+コードカンニングAC

Measured memory_bytes: 18744
#include<iostream>
#include<algorithm>
using namespace std;
int p[100][100], q[100][3], H, W;
int main() {
	cin >> H >> W; int maxn = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char V; cin >> V;
			if (V == 'W')p[i][j] = 0;
			if (V == 'B')p[i][j] = 1;
			if (V == 'R')p[i][j] = 2;
			q[i][p[i][j]]++;
		}
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= H; j++) {
			int P = H - i - j; if (P <= 0)continue;
			int I = i, J = i + j, sum = 0;
			for (int k = 0; k < H; k++) {
				if (k < I)sum += q[k][0];
				else if (k >= J)sum += q[k][2];
				else { sum += q[k][1]; }
			}
			maxn = max(maxn, sum);
		}
	}
	cout << H*W - maxn << endl;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
typedef long long ll;
#define forn(i, start, end) for (ll i = start; i < ll(end); i++)
#define input(arr, n) forn(i, 0, n) cin >> arr[i];
#define MOD 1000000007
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define mll map<ll, ll>
#define mcl map<char, ll>
#define sc set<char>
#define sll set<ll>
#define ssll stack<ll>
#define CHK(param) cout << #param << " is : " << param << "\n";
#define pb push_back
#define ppb pop_back
#define mk make_pair
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define LAUV                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define TC       \
    ll TTTT;     \
    cin >> TTTT; \
    while (TTTT--)
using namespace std;

int32_t main()
{
    LAUV;
    // TC
    {
        ll n,k,s=0;
        cin >> n>>k;
        ll arr[n];
        input(arr, n);
        sort(arr,arr+n);
        forn(i,0,k){
            s+=arr[i];
        }
        cout<<s<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> v[100001];
    int p[m], y[m];
    for (int i = 0; i < m; ++i) {
        cin >> p[i] >> y[i];
        v[p[i]].push_back(y[i]);
    }
    for (int i = 0; i < 100001; ++i) sort(v[i].begin(), v[i].end());
    for (int i = 0; i < m; ++i) {
        cout << setw(6) << setfill('0') << p[i];
        auto it = lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
        cout << setw(6) << setfill('0') << it + 1 << endl;
    }
}


Measured memory_bytes: 7808
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(String.format("%d %d", a * b, 2 * (a + b)));
        }
    }
}



Measured memory_bytes: 26172
n = gets.chomp.to_i
v = gets.chomp.split(" ").map(&:to_i)
c = gets.chomp.split(" ").map(&:to_i)
ans = 0
i = 0
until i == n
    sa = v[i] - c[i]
    if sa > 0
        ans += sa
    end
    i += 1
end
puts ans

Measured memory_bytes: 14332
from itertools import combinations
N = int(input())

def check(edge, s):
    nodes = [0] * (N+1)
    for a, b in edge:
        nodes[a] += b
        nodes[b] += a
    return all([s == i for i in nodes[1:]])

def main(N):
    # 合計になる2頂点のグループを作って、その塊でつないでいく
    group_cnt = -(-N//2)
    group_sum = N if N % 2 == 1 else N+1
    s = (group_cnt - 1) * group_sum
    edge = set()
    loop_num = group_cnt if N % 2 == 0 else group_cnt - 1
    for comb in combinations(range(1, loop_num+1), 2):
        for i in (comb[0], group_sum-comb[0]):
            for j in (comb[1], group_sum-comb[1]):
                edge.add((i, j))
    if N % 2 == 1:
        for i in range(1, N):
            edge.add((i, N))
    print(len(edge))
    for e in edge:
        print(*e)
    #print(check(edge, s))

main(N)


Measured memory_bytes: 74472
N,M=map(int,input().split())
A=[]
for i in range(N):
  B=list(map(int,input().split()))
  B.remove(B[0])
  A.append(B)
C=[]
for j in range(N):
    C+=A[j]
D=0
for k in range(M):
    if C.count(k+1)==N:
        D+=1
print(D)

Measured memory_bytes: 38384
#include <iostream>

using namespace std;
int findSumOfDigits(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(void){
    int A, B, N;
    int total = 0;
    cin >>N >>A >>B;
    for (int i = 0; i <= N; ++i) {
        int sum = findSumOfDigits(i);
        if (A <= sum && sum <= B) total += i;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    // Your code here!
    long long N, Q, l, r;
    string S;
    cin >> N >> Q;
    cin >> S;
    vector<int> AC_Count(N + 1, 0);
    for (int i = 0; i < N; i++)
    {
        int AC = 0;
        if (S[i] == 'A' && S[i + 1] == 'C')
        {
            AC = 1;
        }
        AC_Count[i + 1] = AC_Count[i] + AC;
    }
    
    for (int i = 0; i < Q; i++)
    {
        cin >> l >> r;
        cout << AC_Count[r - 1] - AC_Count[l - 1] << endl;
    }
}

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

int main()
{
  int N, T, min=1001;
  cin >> N >> T;
  vector<int> c(N), t(N);
  rep(i, N){
    cin >> c.at(i) >> t.at(i);
    if(t.at(i)<=T && c.at(i)<min) min=c.at(i);
  }
  if(min==1001) cout << "TLE" << endl;
  else cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<int> paths[650];
long double dp[650];
int N, M;
long double ans;

void input() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int s, t;
        cin >> s >> t;
        paths[s].push_back(t);
    }
}

void f(int block) {
    dp[N] = 0;
    for(int i = N - 1; i >= 1; i--) {
        long double sum = 0.0;
        long double maxi = 0.0;
        int num = paths[i].size();
        for(auto to : paths[i]) {
            sum += dp[to];
            chmax(maxi, dp[to]);
        }
        if(i == block && num >= 2) {
            num--;
            sum -= maxi;
        }
        dp[i] = sum / num + 1;
    }
    chmin(ans, dp[1]);
}

void solve() {
    input();
    ans = 1e18;
    for(int i = 0; i <= N - 1; i++) {
        f(i);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int sum = 0;
    for(int i = 0; i < 5; i++){
      sum += sc.nextInt();
    }
    System.out.println(15 - sum);
  }
}

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

bool isEvenDigit(int n) {
    int digit = 0;
    while (n > 0) {
        digit++;
        n /= 10;
    }
    if (digit % 2 != 0) return true;
    return false;
}

int main() {
    int n; cin >> n;
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        if (isEvenDigit(i)) res++;
    }
    cout << res << endl;
    return 0;

}

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

int main() {
  int A, B, m;
  cin >> A >> B >> m;
  
  vector<int> a(A);
  for (int i = 0; i < A; i++) {
    cin >> a.at(i);
  }
  vector<int> b(B);
  for (int i = 0; i < B; i++) {
    cin >> b.at(i);
  }
  
  vector<int> x(m);
  vector<int> y(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
  }
  
  int ans;
  for (int i = 0; i < m; i++) {
    if (i == 0) {
      ans = a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i);
    }
    else {
      ans = min(ans, a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i));
    }
  }
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  
  ans = min(ans, a.at(0) + b.at(0));
  
  cout << ans << endl;
}

Measured memory_bytes: 2176
import heapq
DEADLINE = 0
REQTIME = 1

ans = "Yes"

N = int(input())
min_heap = []
for i in range(N):
    job = [int(x) for x in input().split()]
    job = tuple((job[1], job[0]))
    heapq.heappush(min_heap, job) # 締め切りでmin heap

t = 0 # 現在時刻
for _ in range(N): # 取り出して仕事をする
    job = heapq.heappop(min_heap)
    t += job[REQTIME]
    if t > job[DEADLINE]:
        ans = "No"
        break

print(ans)

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

int main(void){
 int N,flag = 0;
 cin >> N;
 for(int  i = 1;i<10;i++){
     int t = N%i;
     int k = N/i;
    if(k>=1 && k<=9 && t == 0){
        flag = 1;
    }
 }
 if(flag == 1){
     cout << "Yes" << endl;
 }else{
     cout << "No"<< endl;
 }
 return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<double> v(n);
  for(int i=0; i<n; i++) cin >> v[i];
  
  sort(v.begin(), v.end());
  
  double sum = 0;
  for(int i=1; i<n; i++){
    if(i != 1){
      sum = (sum + v[i])/2;
    }
    
    else{
      sum = (v[i]+v[i-1])/2;
    }
  }
  cout << sum << endl;
}
    

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

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

const long long INF = 1LL << 60;


long long h[100010];

long long dp[100010];

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

	for (int i = 1;i < N;i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if(i>1)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[N - 1] << endl;

}

Measured memory_bytes: 1792
str = input()
s = list(str)

#print(s)


for i in range(0,len(s)):
    l = s[i]
    a = 1
    if i%2 == 0 and l=='L':
            break

    elif i%2 ==1 and l=='R':
            break

    else:
        	a = 0

if a==1:
	print('No')
else:
	print('Yes')


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


int main() {
  char b;
  cin >> b;

  switch (b) {
    case 'A':
    cout << 'T';
    return 0;
    case 'T':
    cout << 'A';
    return 0;
    case 'C':
    cout << 'G';
    return 0;
    case 'G':
    cout << 'C';
    return 0;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int n, m;
	int g;
	int map[1000];
	int dice[1000];
	int count;

	while (1){

		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0){
			break;
		}

		for (i = 0; i < n; i++){
			scanf("%d", &map[i]);
		}
		for (i = 0; i < m; i++){
			scanf("%d", &dice[i]);
		}

		i = 0;
		g = 1;
		count = 0;

		while (g < n){
			g += dice[i];
			g += map[g - 1];
			count++;
			i++;
		}

		printf("%d\n", count);
	}

	return (0);
}

Measured memory_bytes: 608
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

int main() {
    int N; cin >> N;
    int K; cin >> K;

    vector<int> as(N);
    int index = 0;
    for(int i = 0; i < N; ++i){
        int a; cin >> a;
        as[i] = a;
        if(a == 1) index = i;
    }

    int l = index;
    int r = N - index - 1;

    int ans = (N - 1) / (K - 1);
    if((N - 1) % (K - 1) != 0) ++ans;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
s = input()
n = len(s)
entire = s == s[::-1]
left = s[:int((n-1)/2)] == s[:int((n-1)/2)][::-1]
right = s[int((n+3)/2-1):] == s[int((n+3)/2-1):][::-1]
if entire and left and right:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9+21;
const long long LINF = (long long) 1e18;
const long double PI = 2 * acos((long double)0);
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
#define Mahmud main()
#define endl "\n"
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define alla(arr,n) arr,arr+n
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define pb push_back
///Debug
#define dbg1(x) std::cerr<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<','<<#z<<"="<<(z)<<endl;
#define dbgArr(arr,n) cerr<<#arr<<"=["; printArray(arr,n,0,93); cerr<<endl;
///traversing
#define rep(n) for(int i=0;i<n;++i)
#define trv(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();++i)
///necessary functions
inline ll Int()
{
    ll _x=0,_tmp=1;
    char _tc=getchar();
    while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
    if( _tc == '-' ) _tc=getchar(), _tmp = -1;
    while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
    return _x*_tmp;
}
inline long double Double()
{
    long double d;
    scanf("%Lf",&d);
    return d;
}
ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;
}
int ton(string x)
{
    int y;
    std::istringstream ss(x);
    ss >> y;
    return y;
}
template<typename T>
string tostring(T x)
{
    ostringstream ss;
    ss << x ;
    return ss.str();
}

///Current Code vars
#define N 100010
long long n,k,d;
int arr[N+1],brr[N+1];
///Current Code functions

string a,b,c;

void solve()
{
    cin>>n;
    cin>>a>>b>>c;
    int ans = 0;
    for(int i=0;i < n; ++i){
        if(a[i] == b[i] && b[i] == c[i]) continue;
        else if((a[i] == b[i] && b[i] != c[i]) || (a[i] == c[i] && a[i] != b[i]) || (b[i] == c[i] && a[i] != b[i])){
            ans++;
        }
        else ans += 2;
    }
    cout<<ans<<endl;
}

int Mahmud
{
    // ios_base::sync_with_stdio(0); //cin.tie(0);
  //#ifdef _LOCAL_
    //freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
  //while(1)
    solve();
  //#ifdef _LOCAL_
    //printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
  //#endif
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vl vector <long>
#define vll vector < ll >
#define pll pair < ll , ll >
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MODCONST 1000000007
//#define v[i] abs(v[i])

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    ld m = n/(3.0);
    cout<<fixed<<pow(m,3)<<endl;
}

int main()
{
    fastio ;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll tc=1;
    //cin>>tc; //for number of testcases
    //ll ts = tc;
    while(tc--){
        //cout<<"Case #"<<ts-tc<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int x;
    scanf("%d", &x);
    int i, j;
    int ans = 1;
    for (i=1; i<x; i++)
    {
        for (j=2; j<=10; j++)
        {
            if (pow(i, j) <= x) {
                if (pow(i, j) > ans) ans = pow(i, j);
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int H, W;
char A[1010][1010];
int d[1010][1010];
int main() {
	cin >> H >> W;
	queue<pii>Q;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> A[i][j];
			if (A[i][j] == '#') {
				Q.push({ i,j });
				d[i][j] = 0;
			}
			else {
				d[i][j] = INF;
			}
		}
	}
	while (!Q.empty()) {
		int y = Q.front().first;
		int x = Q.front().second;
		Q.pop();
		for (int i = 0; i < 4; ++i) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (0 <= ny && ny < H && 0 <= nx && nx < W&&A[ny][nx] == '.'&&d[ny][nx]==INF) {
				Q.push({ ny,nx });
				d[ny][nx] = d[y][x] + 1;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (d[i][j] == 0)continue;
			ans = max(ans, d[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 13456
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <queue>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int, in){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1;
	range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	int V {in()};
	vector<vector<int>> n(V);
	vector<int> v(V);
	for (int E {in()}; E; E--) {
		int a {in()}, b {in()};
		n[a].push_back(b);
		v[b]++;
	}
	queue<int> q;
	for (int i: range(V))
		if (!v[i])
			q.push(i);
	while(!q.empty()) {
		int i = q.front();
		q.pop();
		outl(i);
		for (int j: n[i])
			if (!(--v[j]))
				q.push(j);
	}
}


Measured memory_bytes: 3024
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
ll gi() {
    ll x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> void chkmax(T &a,T b) { a<b?a=b:0; };
template<typename T> void chkmin(T &a,T b) { a>b?a=b:0; };
int n,id[N],siz[N];
ll d[N];
map<ll,int> M;
pii e[N];
int tot=0;
vector<int> E[N];
bool cmp(int a,int b) { return d[a]<d[b]; }
ll dfs(int u,int dep) {
    ll ret=0;
    for(int v:E[u]) ret+=dfs(v,dep+1);
    return ret+dep;
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) d[i]=gi(),id[i]=i;
    sort(id+1,id+n+1,cmp);sort(d+1,d+n+1);
    for(int i=1;i<=n;i++) M[d[i]]=i;
    for(int i=1;i<=n;i++) siz[i]=1;
    for(int i=n;i>1;i--) {
        int p=M[d[i]-2*(n-siz[i])+n];
        if(!p||p>=i) return puts("-1"),0;
        e[++tot]=mp(id[p],id[i]);E[p].pb(i);siz[p]+=siz[i];
    }
    if(dfs(1,0)!=d[1]) puts("-1");
    else for(int i=1;i<=tot;i++) printf("%d %d\n",e[i].fi,e[i].se);
    return 0;
}


Measured memory_bytes: 17792
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
using namespace std;

int main() {
    int a, b;
    int c[5];
    cin >> a >> b;

    int count = 0;
    for (int i = a; i <= b; i++) {//総当たり
        int j = i;
        int k = 0;
        bool flag = true;//1個ずつ
        while (j > 0) {
            c[k] = j % 10;  //5桁分を1個ずつ
            j = j / 10;
            k++;
        }
        for (int l = 0; l < 5; l++) {
            if (c[l] != c[4 - l]) {
                flag = false;//回分じゃない
            }
        }
        if (flag == true) {
            count++;//回分だ
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N + 1];
        for (int i = 1; i <= N; ++i) {
            x[i] = sc.nextInt();
        }

        long[][][] dp = new long[N + 1][N + 1][N * A + 1];
        for (int i = 0; i < N; ++i) {
            dp[i][0][0] = 1;
        }

        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= i; ++j) {
                for (int k = 1; k <= N * A; ++k) {
                    if (k < x[i]) {
                        dp[i][j][k] = dp[i - 1][j][k];
                    } else {
                        dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
                    }
                }
            }
        }

        long ans = 0;
        for (int j = 1; j <= N; ++j) {
            ans += dp[N][j][j * A];
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 85432
#include<iostream>
using namespace std;
typedef long long int ll;

int main()
{
  ll a,b,c;
  cin >> a>> b >> c;
  if(a+b<c) cout << a+b+b+1 << endl;
  else if(a+c<b) cout << 2*c+1 << endl;
  else cout << b+c << endl;
}

Measured memory_bytes: 256
#n = int(input())
n, m = map(int, input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

dic = {}
for i in range(m):
    a, b = map(int, input().split())
    dic[(a, b)] = True
    dic[(b, a)] = True
ans = 'IMPOSSIBLE'
for i in range(2, n):
    if dic.get((1, i), False):
        if dic.get((i, n), False):
            ans = 'POSSIBLE'
            break
print(ans)


Measured memory_bytes: 72804
import threading, queue
N, M = map(int, input().split())

ans = [-1 for i in range(N+1)]
E = [ [] for i in range(N+1)]

for i in range(M):
  a, b = map(int, input().split())
  E[a].append(b)
  E[b].append(a)

q = queue.Queue(N)
q.put(1)
ans[1] = 0
while q.empty() == False:
  t = q.get()
  for j in E[t]:
    if ans[j] == -1:
      ans[j] = t
      q.put(j)
  

#Output

print('Yes')
for i in range(2,N+1):
  print(ans[i])


Measured memory_bytes: 34644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AHappyBirthday solver = new AHappyBirthday();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHappyBirthday {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();

            int max = Math.max(a, b);
            boolean answer = max <= 8;

            out.println(answer ? "Yay!" : ":(");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460