akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using P = pair<int, int>;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> maze(H);
  queue<P> que;
  for (int y = 0; y < H; y++) {
    cin >> maze[y];
    for (int x = 0; x < W; x++) {
      if (maze[y][x] == '#') {
        que.push(P(y, x));
      }
    }
  }
  int count = 0;
  while (!que.empty()) {
    int a = que.size();
    int y[4] = {1, 0, -1, 0};
    int x[4] = {0, 1, 0, -1};
    for (int i = 0; i < a; i++) {
      P p = que.front(); que.pop();
      
      for (int j = 0; j < 4; j++) {
        int ny = p.first + y[j];
        int nx = p.second + x[j];
        
        if (ny >= 0 && ny < H && nx >= 0 && nx < W && 
             maze[ny][nx] == '.') {
          maze[ny][nx] = '#';
          que.push(P(ny, nx));
        }
      }
    }
    
    if (!que.empty()) count++;
  }
  
  cout << count << endl;
}

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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  int cnt = 0;
  while(A[0] != A[1] || A[1] != A[2] || A[2] != A[0])
  {
    sort(A, A+3);
    if (A[1] == A[2])
    {
      A[0] += 2;
    }
    else
    {
      A[0]++;
      A[1]++;
    }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
/* Breadth First Graph */
#include <stdio.h>

void visit(int);
int dequeue(void);
void enqueue(int);

int map[101][101];
int Q[101], n, head=0, tail=0, color[101], d[101];

int main()
{
    int i, j, v, vv, m, u, k;

    scanf("%d", &n);
    for(i=0; i<n; i++){
        color[i] = 0;
        for(j=0; j<n; j++){
            map[i][j] = 0;
        }
    }
    for(i=0; i<n; i++){
        scanf("%d%d", &v, &m);
        for(j=0; j<m; j++){
            scanf("%d", &vv);
            map[v-1][vv-1] = 1;
        }
    }
    for(j=0; j<n; j++){
        if(map[0][j] == 1){
            color[j] = 0;
        }
    }
    color[0] = 1;
    d[0] = 0;
    enqueue(0);
    while(head != tail){
        u = dequeue();
        for(k=0; k<n; k++){
            if(map[u][k] == 1 && color[k] == 0){
                color[k] = 1;
                d[k] = d[u]+1;
                enqueue(k);
            }
            color[u] = 2;
        }
    }

    for(i=0; i<n; i++){
        if(color[i] == 2){
            printf("%d %d\n", i+1, d[i]);
        } else{
            printf("%d -1\n", i+1);
        }
    }
    return 0;
}

int dequeue()
{
    int x;
    x = Q[head];
    if(head + 1 == 100){
        head = 0;
    } else{
        head = head + 1;
    }
    return x;
}

void enqueue(int x)
{
    Q[tail] = x;
    if(tail +1 == 100){
        tail = 0;
    } else{
        tail = tail + 1;
    }
}


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

using namespace std;

typedef long ll;

int main(int, char**)
{
	ll n, k;
	double ans = 0;
	cin >> n >> k;

	double tmp = (double)1.0/(double)n;
	for (int i = 1; i <= n; i++) {
		if (i >= k) {
			ans += (double)tmp * (n - k + 1);
			break;
		}
		double x = tmp;
		int now = i;
		while (k > now) {
			x *= (double)0.5;
			now *= 2;
		}

		ans += x;
	}

	cout << fixed << setprecision(12) <<  ans << endl;
	return 0;
}



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


int ASC( void *a,  void *b) {
	return strcmp(*(const char **)a, *(const char **)b);//降順
}
int GCD(int a, int b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main(void)
{
	int a, b, k;
	scanf("%d%d%d",&k,&a,&b);
	for (int i = a; i <= b; i++) {
		if (i%k == 0) {
			printf("OK");
			return 0;
		}
	}
	printf("NG");
	
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int M,D;
    cin >>M>>D;
    int count=0;
    loop(i,1,M+1)
    {
        loop(j,1,D+1)
        {
            if ((j%10)>=2 && ((j/10)%10)>=2 && (j%10)*((j/10)%10)==i) 
            {
                // cout << i << " " << j << endl;
                count++;
            }
        }
    }
    cout << count << "\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = 3.141592654;
void solve()
{
    ll n,m;
    cin>>n>>m;
    ll arr[m];
    string s[m];

    for(int i=0;i<m;i++)
    {
        cin>>arr[i]>>s[i];
    }
    set<ll> st;
    map<ll,ll> mp;

    ll wa=0,ac=0;

    for(int i=0;i<m;i++)
    {
        if(st.count(arr[i])==0 && s[i]=="WA")
           mp[arr[i]]++;
        else if(st.count(arr[i])==0 && s[i]=="AC")
        {
            st.insert(arr[i]);
            wa+=mp[arr[i]];
            ac++;
        }
    }
    cout<<ac<<" "<<wa<<endl;

}
int main()
{
#ifndef oj
    //freopen("input", "r", stdin);
    //freopen("output.txt","w",stdout);
#endif
    // system("cls");
    //getchar();
    // cout<<adj[1][0];

    int t,sum=0;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();

    }


}




Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int A[N];
    ll ans = 0,sum = 0;
    REP(i,N){
        cin >> A[i];
        sum += A[i];
    }
    ll cnt = INFF,now = 0;
    REP(i,N){
        now += A[i];
        cnt = min({cnt,abs(abs(sum - now) - now)});
    }
    cout << ans + cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int x,y;
	cin >> x >> y;
	for (int i=0; i<=x; i++) {
		if (2*i + 4*(x-i) == y) return cout << "Yes", 0;
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 3608
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let n:u64 = procon_read()[0];
	let mut ret = 1;
	for i in 1..(n+1) {
		ret = (ret*i)%1000000007;
	}
	println!("{}", ret);
}

Measured memory_bytes: 4352
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String... args) throws IOException {
        final int[] targetAry = load();

        insertionSort(targetAry);
    }

    public static int[] load() throws IOException {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int[] nums = new int[n];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }

        return nums;
    }

    public static void insertionSort(final int[] targetAry) {
        for (int i = 0; i < targetAry.length; i++) {
            for (int j = i; 0 < j; j--) {
                if (targetAry[j - 1] > targetAry[j]) {
                    swap(targetAry, j - 1, j);
                }
                if ((1 < j) && (targetAry[j - 1] > targetAry[j - 2])) {
                    break;
                }
            }

            print(targetAry);
        }
    }

    public static void swap(final int[] targetAry, final int from, final int to) {
        final int tmp = targetAry[to];
        targetAry[to] = targetAry[from];
        targetAry[from] = tmp;
    }

    public static void print(final int[] targetAry) {
        final StringBuilder sb = new StringBuilder();
        for (int j = 0; j < targetAry.length; j++) {
            sb.append(targetAry[j]).append(j != targetAry.length - 1 ? ' ' : '\n');
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 21640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=105,INF=1<<20;
int dp[1<<14][15];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<string> S(N),T;
        vector<int> no(N);
        for(int i=0;i<N;i++){
            cin>>S[i];
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(i==j) continue;
                if(S[i].size()<=S[j].size()) continue;
                
                for(int k=0;k+S[j].size()-1<S[i].size();k++){
                    bool ok=true;
                    for(int l=0;l<S[j].size();l++){
                        if(S[i][k+l]!=S[j][l]){
                            ok=false;
                            break;
                        }
                    }
                    if(ok) no[j]=1;
                }
            }
        }
        
        for(int i=0;i<N;i++){
            if(no[i]==0) T.push_back(S[i]);
        }
        
        S=T;
        
        N=S.size();
        
        for(int i=0;i<(1<<N);i++){
            for(int j=0;j<N+1;j++){
                dp[i][j]=INF;
            }
        }
        dp[0][N]=0;
        
        S.push_back("{");
        
        for(int bit=0;bit<(1<<N);bit++){
            for(int i=0;i<=N;i++){
                if(bit&&!(bit&(1<<i))) continue;
                if(bit==0&&i<N) continue;
                for(int to=0;to<N;to++){
                    if(bit&(1<<to)) continue;
                    
                    int ma=0;
                    
                    for(int k=min(S[i].size(),S[to].size());k>=1;k--){
                        bool ok=true;
                        
                        for(int l=0;l<k;l++){
                            if(S[i][S[i].size()-k+l]!=S[to][l]){
                                ok=false;
                                break;
                            }
                        }
                        if(ok){
                            ma=k;
                            break;
                        }
                    }
                    
                    dp[bit|(1<<to)][to]=min(dp[bit|(1<<to)][to],dp[bit][i]+int(S[to].size())-ma);
                }
            }
        }
        
        int ans=INF;
        
        for(int i=0;i<N;i++){
            ans=min(ans,dp[(1<<N)-1][i]);
        }
        
        cout<<ans<<endl;
        
    }
}





Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

#define INF 1000000009
#define MAX_V 500000

struct edge {
    int to;
    int cost;
    edge(int to,int cost):to(to),cost(cost){}
};



int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

map<P,int> zip(vector<P> v){
  sort(all(v));
  map<P,int> res;
  int vsz=v.size();
  rep(i,vsz){
    res[v[i]]=i;
  }
  return res;
}

int main(){
  int n,m;cin>>n>>m;
  V=500000;
  int p[m],q[m],c[m];
  rep(i,m){
    cin>>p[i]>>q[i]>>c[i];
    --p[i];--q[i];--c[i];
  }
  vector<P> tozip;
  rep(i,m){
    tozip.push_back(P(p[i],c[i]));
    tozip.push_back(P(q[i],c[i]));
  }
  rep(i,n){
    tozip.push_back(P(i,-1));
  }
  auto index=zip(tozip);
  rep(i,m){
    G[index[P(p[i],c[i])]].push_back(edge(index[P(q[i],c[i])],0));
    G[index[P(q[i],c[i])]].push_back(edge(index[P(p[i],c[i])],0));
    G[index[P(p[i],c[i])]].push_back(edge(index[P(p[i],-1)],1));
    G[index[P(q[i],c[i])]].push_back(edge(index[P(q[i],-1)],1));
    G[index[P(p[i],-1)]].push_back(edge(index[P(p[i],c[i])],1));
    G[index[P(q[i],-1)]].push_back(edge(index[P(q[i],c[i])],1));
  }
  dijkstra(0);
  cout<<(d[index[P(n-1,-1)]]==INF?-1:d[index[P(n-1,-1)]]/2)<<endl;
}

    

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

const long long INF = 1LL << 60;
int MOD = 1000000007;
double PI = 3.14159265358979323846;
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; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define For(i,s,n) for (int i=s;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >
#define All(c) (c).begin(), (c).end()
#define Print(x) cout<<(x)<<"\n"

int N, A;
int X[51];
ll dp[51][51][2501];

int main() {
	cin >> N >> A;
	rep(i, N) cin >> X[i];


	rep(i, 51) {
		rep(j, 51) {
			rep(k, 2501) {
				if (i == 0 && j == 0 && k == 0) {
					dp[i][j][k] = 1;
				}
				else if (i>=1 && k<X[i-1]) {
					dp[i][j][k] = dp[i - 1][j][k];
				}
				else if (i>=1 && j>=1 && k>=X[i-1]){
					dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - X[i-1]];
				}
			}
		}
	}

	ll ans = 0;
	rep1(i, N+1) {
		ans += dp[N][i][i * A];
	}
	cout << ans << endl;
}

Measured memory_bytes: 50048
S = input()
T = input()

if S == T:
    print("Yes")
else:
    ans = "No"
    S = list(S)
    for i in range(len(S)):
        s = S.pop()
        S.insert(0, s)
        if "".join(S) == T:
            ans = "Yes"
            break
    print(ans)

Measured memory_bytes: 9052
n , k  = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9 
for i in range(n-k+1):
    l = x[i]
    r = x[i+k-1]
    if l*r >= 0:
        ans = min(ans,max(abs(r),abs(l)))
    elif l*r < 0:
        ans = min(ans,r-l + min(abs(r),abs(l)))
print(ans)

Measured memory_bytes: 14392
package main

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

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

const yes = "Yes"
const no = "No"

func subSolve(m int64, as []string, bs []string,  i int,  j int) bool {
	for y := 0; y < int(m); y ++ {
		if as[y + j][i:i + int(m)] != bs[y] {
			return  false
		}
	}
	return true
}

func solve(n int64, m int64, as []string, bs []string) bool {
	k := n - m
	for i := 0; i <= int(k); i++ {
		for j := 0; j <= int(k); j++ {
			if subSolve(m, as, bs, i, j) {
				return true
			}
		}
	}
	return false
}

func main() {
	defer out.Flush()

	n := nextInt()
	m := nextInt()
	as := nextStrings(n)
	bs := nextStrings(m)
	if solve(n, m, as, bs) {
		fmt.Fprintln(out, yes)
	} else {
		fmt.Fprintln(out, no)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 1776
#include <iostream>
using namespace std;
 
int main(){
  int K,S;
  cin >> K >> S;
  int res=0;
  
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
      int z=S-x-y;
      if( z >=0 && z<=K){
        int sum=x+y+z;
        if(sum==S){
          res++;
        }
      }
    }
  }
  
 cout << res << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class d{
    public static void Main(){
        long n = long.Parse(Console.ReadLine());
        long k = n/3;
        long ans = 0;
        long div = (long)Math.Pow(10,9) + 7;
        long[,] dp = new long[n+1,n+1];
        for(long i=1; i<=k; i++){
            long res = n - 3*i;
            if(res < i-1){
                ans += nCr(res+i-1, res, ref dp, div);
                //Console.WriteLine("{0}C{1}", res+i-1, res);
                ans %= div;
            }
            else{
                ans += nCr(res+i-1, i-1, ref dp, div);
                //Console.WriteLine("{0}C{1}", res+i-1, i-1);
                ans %= div;
            }
        }
        Console.WriteLine(ans);
    }
    public static long nCr(long n, long r, ref long[,] dp, long div){
        if(dp[n,r] > 0){
            return dp[n,r];
        }
        if(r == 0 || n == r){
            dp[n,r] = 1;
            return 1;
        }
        else{
            long ret = nCr(n-1, r, ref dp, div) + nCr(n-1, r-1, ref dp, div);
            ret %= div;
            dp[n,r] = ret;
            return ret;
        }
    }
}


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

using namespace std;

int n;
vector<int> a,b,c;
vector<vector<int>> dp;

int func(int idx, int j) {
	if(idx>=n||idx<0||j<0||j>=3) 
		return -1;

	if(idx==0){
		if(j==0)
			return a[0];
		if(j==1)
			return b[0];
		return c[0];
	}

	if(dp[idx][j]!=-1)
		return dp[idx][j];

	int res;
	if(j==0)
		res = a[idx] + max(func(idx-1,1), func(idx-1,2));
	else if(j==1)
		res = b[idx] + max(func(idx-1,0), func(idx-1,2));
	else
		res = c[idx] + max(func(idx-1,0), func(idx-1,1));

	return dp[idx][j] = res;
}
int main(){
	cin>>n;

	a.resize(n);
	b.resize(n);
	c.resize(n);
	dp.resize(n, vector<int>(3,-1));

	for(int i=0;i<n;i++) {
		cin>>a[i]>>b[i]>>c[i];
	}

	cout<<max(func(n-1,0), max(func(n-1,1), func(n-1,2)))<<endl;
	return 0;
}

Measured memory_bytes: 11520
uses math;
var i,n,j,max1,max2,res:longint;
    a,b:array[1..20] of longint;
begin
  readln(n);
  for i:=1 to n do read(a[i]);
  for i:=2 to n - 1 do 
    begin
      max1:=high(longint); max2:=high(longint);
      for j:=i- 1 to i + 1 do 
        max1:=min(max1,a[j]);
      for j:=i - 1 to i + 1 do 
        if (a[j] < max2) and (a[j] <> max1) then max2:=a[j];
      if a[i] = max2 then b[i]:=1;
    end;
  for i:=1 to n do if b[i] = 1 then inc(res);
  write(res)
end.

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

const long long MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c.at(i);
    }
    c.push_back(0);
    vector<long long> cnt(200001);
    vector<long long> dp(n + 1);
    cnt.at(c.at(0)) = 1;
    for (int i = 1; i <= n; i++) {
        if (c.at(i - 1) == c.at(i)) continue;

        dp.at(i) = cnt.at(c.at(i - 1));
        cnt.at(c.at(i)) += dp.at(i) % MOD;
        cnt.at(c.at(i)) %= MOD;
    }
    
    cout << dp.at(n) << endl;
}

Measured memory_bytes: 4208
#include<bits/stdc++.h>
#define   ll    long long int
#define   sz    200010

using namespace std;


int main()
{

   string s;

   ll i,j,k,p,d;

   cin>>s;

   ll a=0;
   ll b=0;

   for(i=0;i<s.length();i++)
   {
       if(s[i]=='0')a++;
       else
        b++;
   }

   p=min(a,b);

   cout<<p*2<<endl;


    return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long


int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    ll b =0  ;
    ll Min=LLONG_MAX;
    //cout<<Min<<endl;
    rep(i,n){
        cin>>a[i];
        //cout<<a[i]<<endl;
        a[i]-=(i+1);
        b+=a[i];
    } 
    ll ans=0;
    ll ans1=0;
    //cout<<b<<endl<<endl;
    sort(all(a));
    //rep(i,n)cout<<a[i]<<endl;
    if(n%2){
        rep(i,n)ans+=abs(a[i]-a[(n-1)/2]);
    }else{
        rep(i,n)ans+=abs(a[i]-a[(n)/2]);
        rep(i,n)ans1+=abs(a[i]-a[(n)/2-1]);
        ans=min(ans1,ans);
        //cout<<ans<<" "<<ans1<<endl;
    }
    cout<<ans<<endl;

    return 0;


}



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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

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

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

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

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;

	int ans = 0, ok = 0, cur = 1;
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		if (x == cur) {
			cur++;
			ok = 1;
		} else {
			ans++;
		}

	}

	if (!ok) cout << -1 << '\n';
	else cout << ans << '\n';
	

	return 0;
}

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

int main(){
    using namespace std;
    unsigned long N, Q;
    cin >> N >> Q;
    vector<unsigned long> c(N);
    for(auto&& i : c){
        cin >> i;
        --i;
    }
    vector<tuple<unsigned long, unsigned long, unsigned long>> queries(Q);
    {
        unsigned long cnt{0};
        for(auto&& [i, l, r] : queries){
            cin >> l >> r;
            --l;
            i = cnt++;
        }
    }
    constexpr unsigned long B{500};
    sort(begin(queries), end(queries), [&B](const auto& lhs, const auto& rhs){
        const auto& [i, li, ri] = lhs;
        const auto& [j, lj, rj] = rhs;
        return li / B == lj / B ? (li / B) & 1 ? ri > rj : ri < rj : li < lj;
    });
    unsigned long nl{0}, nr{0}, now{0};
    vector<unsigned long> cnt(N), ans(Q);
    for(const auto& [i, l, r] : queries){
        while(nr < r)now += !cnt[c[nr++]]++;
        while(nr > r)now -= !--cnt[c[--nr]];
        while(nl < l)now -= !--cnt[c[nl++]];
        while(nl > l)now += !cnt[c[--nl]]++;
        ans[i] = now;
    }
    for(const auto& i : ans)cout << i << endl;
    return 0;
}

Measured memory_bytes: 27144
x=input()
res=[0,0,0]

for i in x:
    if i=='a':
        res[0]=1
    if i == 'b':
        res[1] =1
    if i =='c':
        res[2]=1

if res==[1,1,1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
w=list(input())
w.sort()
w=groupby(w)
for i in w:
    if i[1]%2==1:
        print("No")
        break
else:
    print("Yes")

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

int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  int count = 0;
  for (int i=0; i<n; i++){
    if(s[i]=='R')count++;
  }
  if(count>(n-count))cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> P;
static const int INF=1<<24;

int main(){
	string s;
	int n;
	while(cin>>n,n){
		int a[240010]={0};
		
		char tmp;
		rep(i,n){
			stringstream ss1,ss2;
			int t1=0,t2=0;
			cin>>s;
			//cout<<s<<endl;
			ss1<<s[0]<<s[1]<<s[3]<<s[4]<<s[6]<<s[7];
			ss1>>t1;
			cin>>s;
			ss2<<s[0]<<s[1]<<s[3]<<s[4]<<s[6]<<s[7];
			ss2>>t2;
			//cout<<t1<<" "<<t2<<endl;
			for(int i=t1;i<t2;i++){
				a[i]++;
			}
		}
		int res=0;
		rep(i,240001){
			res=max(res,a[i]);
		}
		cout<<res<<endl;
	}
	return 0;
}
		

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

#define all(v) v.begin(), v.end()

int h, w;
int n;
int x[101010], y[101010];
vector<int> X, Y;

int main()
{
  cin >> h >> w;
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
    X.push_back(x[i]);
    Y.push_back(y[i]);
  }

  sort(all(X));
  sort(all(Y));

  vector<int> ax, ay;
  ax.push_back(X[X.size() / 2]);
  ax.push_back(X[(X.size() - 1) / 2]);
  ay.push_back(Y[Y.size() / 2]);
  ay.push_back(Y[(Y.size() - 1) / 2]);
  
  sort(all(ax)); sort(all(ay));
  long long ans = 1e18, max_d = 0;
  int ans_x, ans_y;

  for (int i = 0; i < ax.size(); i++){
    for (int j = 0; j < ay.size(); j++){
      long long m = 0, cnt = 0;
      for (int k = 0; k < n; k++){
        long long d = abs(x[k] - ax[i]) + abs(y[k] - ay[j]);
        cnt += 2 * d;
        m = max(m, d);
      }

      if (ans > cnt - m){
        ans = cnt - m;
        ans_x = ax[i];
        ans_y = ay[j];
      }
    }
  }

  /*
  for (int i = 0; i < n; i++){
    long long d = abs(x[i] - ax) + abs(y[i] - ay);
    ans += 2 * d;
    max_d = max(d, max_d);
  }
  */

  cout << ans << endl;
  cout << ans_x << " " << ans_y << endl;
}

Measured memory_bytes: 4752
from collections import deque
cnt = int(input())
a = deque()

for i in range(cnt):
    li = list(map(int,input().split()))
    if li[0] == 0:
        if li[1] == 0:
            a.appendleft(li[2])
        else:
            a.append(li[2])
    if li[0] == 1:
        print(a[li[1]])
    if li[0] ==2:
        if li[1]==0:
            a.popleft()
        else:
            a.pop()


Measured memory_bytes: 21984
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
V,E = map(int,input().split())#頂点、辺の数
INF = float("inf")
cost = [[INF]*V for _ in range(V)]#iからjへの重み付き距離cost[i][j]
for i in range(V):
    cost[i][i] = 0
for _ in range(E):
    s,t,dd = map(int,input().split())
    cost[s][t] = dd
#実装
for k in range(V):
    for i in range(V):
        for j in range(V):
            cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j])
judge = 0
for i in range(V):
    if judge == 1:
        break
    for j in range(i+1,V):
        
        if cost[i][j] + cost[j][i] < 0:
            judge = 1
            break
for i in range(V):
    for j in range(V):
        if cost[i][j] == INF:
            cost[i][j] = "INF"
        else:
            cost[i][j] = str(cost[i][j])
if judge == 1:
    print("NEGATIVE CYCLE")
else:
    for i in range(V):
        print(*cost[i])


Measured memory_bytes: 8144
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long X, long long D){
  if(D==0&&X==0){
    cout<<1<<endl;
    return;
  }
  if(D==0){
    cout<<N+1<<endl;
    return;
  }
  if(X==0){
    cout<<N*(N-1)/2+1<<endl;
    return;
  }
  if(D<0){
    D=-D;
    X=-X;
  }
  ll g = gcd(X,D);
  ll l = X/gcd(X,D)*D;
  if(D/g>N){
    cout<<N*(N+1)*(N-1)/6+N+1<<endl;
    return;
  }
  vector<pll> A(D/g,pll(-0,-1));
  ll ans=0;
  REP(N+1){
    ll ii=i%(D/g),il=i/(D/g);
    pll tmp(il*(X/g)+i*(i-1)/2,il*(X/g)+i*(N-1+N-i)/2);
    if(A[ii].first>tmp.second||A[ii].second<tmp.first){
      ans+=A[ii].second-A[ii].first+1;
      dump(ans);
      A[ii]=tmp;
    }else{
      A[ii].second=max(tmp.second,A[ii].second);
      A[ii].first=min(tmp.first,A[ii].first);
    }
  }
  dump(A);
  REP(D/g){
    ans+=A[i].second-A[i].first+1;
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long D;
    scanf("%lld",&D);
    solve(N, X, D);
    return 0;
}


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

int N;

void out(int* arr){
	for(int i=0; i<N; i++) {
		cout << arr[i];
		if(i!=N-1) cout << " ";
	}
	cout << endl;
}

int main(){
	int v,j;
	cin >> N;
	int* A = new int[N];

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

//insertion sort
	for(int i=1;i<=N-1;i++){
		v=A[i];
		j=i-1;
		while(j>=0 && A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		out(A);
	}
	return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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;
}

int main()
{
  ll N,X,M;
  cin >> N >> X >> M;
  vector<ll> vec(100010,0);
  vec[X]=0;
  ll loop=1;
  ll preloop=0;
  ll now=X;
  vector<ll> x;
  x.push_back(X);
  REP2(i,1,M){
    now=(now*now)%M;
    if(vec[now]!=0){
      loop=i-vec[now];
      preloop=vec[now];
      break;
    }
    x.push_back(now);
    vec[now]=i;
  }

  ll ans=0;
  if(N<=preloop){
    REP(i,N){
      ans+=x[i];
    }
  }else{
    REP(i,preloop){
      ans+=x[i];
    }
    N-=preloop;
    ll sum=0;
    REP2(i,preloop,preloop+loop-1){
      sum+=x[i];
    }
    ans+=(N/loop)*sum;
    REP2(i,preloop,preloop+(N%loop)-1){
      ans+=x[i];
    }
  }

  // REP(i,6){
  //   cout << x[i] << endl;
  // }
  // cout << preloop << "a" << loop << endl;

  cout << ans << endl;
}


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

#define int long long
#define pii pair <int, int>
#define ff first
#define ss second

const int mex = 1e16 + 5;
int seg[400005];

void update(int node, int s, int e, int l, int r, int value){
          if(s > r || e < l) return;
          if(s >= l && e <= r) {
              seg[node] = min(seg[node], value); return;
          }
          int mid = (s+e)>>1;
          update(node<<1, s, mid, l, r, value);
          update((node<<1)|1, mid+1, e, l, r, value);
}

int query(int node, int s, int e, int ind){
         if(s == e) return seg[node];
         int mid = (s+e)>>1;
         seg[node<<1] = min(seg[node<<1], seg[node]);
         seg[(node<<1)|1] = min(seg[(node<<1)|1], seg[node]);
         if(ind <= mid) return query(node<<1, s, mid, ind);
         else return query((node<<1)|1, mid+1, e, ind);
}

signed main(){
    int n, m, x, y, z; cin >> n >> m;
    
    for(int i = 0; i <= 400000; i++) seg[i] = mex;
    update(1, 1, n, 1, 1, 0);
    
    vector <pair <pii, int> > v;
    
    while(m--){
        cin >> x >> y >> z;
        v.push_back({{x,y},z});
    }
    
    sort(v.begin(), v.end());
    
    for(auto i : v){
        int upto = query(1, 1, n, i.ff.ff);
        upto += (i.ss);
        update(1, 1, n, i.ff.ff + 1, i.ff.ss, upto);
    }
    
    int ans = query(1, 1, n, n);
    if(ans == mex) ans = -1;
    
    cout << ans << '\n';
    
}

Measured memory_bytes: 8052
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=999999017;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=t;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, r, m, tc;
ll dist[222][222];
ll loc[8];

ll solve(void)
{
	cin>>n>>m>>r; int i, j, k; ll u, v, w, ans=1e18;
	for(i=0 ; i<r ; i++) cin>>loc[i]; sort(loc,loc+r);
	for(i=1 ; i<=n ; i++)
		for(j=1 ; j<=n ; j++)
			dist[i][j]=1e18;
	for(i=1 ; i<=n ; i++) dist[i][i]=0;
	for(i=1 ; i<=m ; i++)
	{
		cin>>u>>v>>w;
		dist[u][v]=min(dist[u][v],w);
		dist[v][u]=min(dist[v][u],w);
	}
	for(k=1 ; k<=n ; k++)
		for(i=1 ; i<=n ; i++)
			for(j=1 ; j<=n ; j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	do
	{
		int i; ll cc=0;
		for(i=0 ; i<=r-2 ; i++) cc+=dist[loc[i]][loc[i+1]];
		ans=min(ans,cc);
	} while(next_permutation(loc,loc+r));
	return ans;
}

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	cin>>tc; int i;
//	for(i=1 ; i<=tc ; i++)
	//	cout<<"#"<<i<<" "<<
          cout<<solve(); //<<"\n";
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
int i,j,temp;
int x[10000];
int y[10000];

for(i=0; i<10000; i++){
   scanf("%d%d", &x[i], &y[i]);
if(x[i]>y[i]){
 temp = x[i];
 x[i] = y[i];
 y[i] = temp;
}

if(x[i]==0 && y[i]==0){
  break;
 }
}

for(j=0; j<i; j++){
 printf("%d %d\n", x[j], y[j]);
}

return 0;

}  

Measured memory_bytes: 624
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    	if (c == '\\') 
  	{
  		push(i,&st1);
  		// '\' が出た時の処理
      // 位置 i を st1 にプッシュ(write your code)
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      // 水たまりの総水量 sum を更新(write your code)
      	int j=pop(&st1);
    	sum+=i-j;
      // st2_j と st2_a を用いて水たまりの水量を更新 
      int a = i - j;   // 更新する水たまりの水量を a に格納していく
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
      	a+=pop(&st2_a);
      	pop(&st2_j);
      	// 水たまりの水量を求めていく (write your code)
      }
    	push(j,&st2_j);
    	push(a,&st2_a);
    	// 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
    int d, n;
    cin >> d >> n;
    int p = pow(100, d);
    if(n == 100)
        cout << p * n + p << endl;
    else
        cout << p * n << endl;
}


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

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define p push
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

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

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

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


int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	reverse(all(a));
	rep(i, n) {
		printf("%d", a[i]);
		if (i != n - 1)printf(" ");
	}
	printf("\n");

	Please AC;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head

int x,n,k,res;
int a[201000] = {};
int b[201000] = {};
queue<int> que;
queue<int> que2;
string s;

signed main() {
	std::cin >>n;
	rep(i,0,n){
		std::cin >> a[i];
	}
	rep(i,0,n){
		std::cin >> b[i];
	}
	sort(a,a+n);
	rep(i,1,30){
		res = 0;
		vector<int> c;
		rep(k,0,n){
			c.pb(b[k] % (1<<i));
		}
		sort(all(c));
		rep(jj,0,n){
			int j = a[jj] % (1<<i);
			res += lower_bound(all(c), (1<<(i-1))*2-j)- lower_bound(all(c), (1<<(i-1))-j);
			res += lower_bound(all(c), (1<<(i-1))*4-j)- lower_bound(all(c), (1<<(i-1))*3-j);
		}
		que.push(res);
		c.clear();
	}
	res = 0;
	rep(i,0,29){
		if (que.front()%2 == 1){res += 1<<i;}
		que.pop();
	}
	std::cout << res << '\n';
}

Measured memory_bytes: 9012
from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)
def solve():
    N = int(input())
    G = defaultdict(list)
    for i in range(N-1):
        u,v,w = map(int,input().split())
        u -= 1
        v -= 1
        G[u].append((v,w))
        G[v].append((u,w))

    res = [0] * N

    dfs(0,-1,1,G,res)

    print(*res, sep='\n')
def dfs(v,p,c,G,res):
    res[v] = c
    for e in G[v]:
        if e[0] == p:
            continue
        if e[1] % 2 != 0:
            dfs(e[0], v, 1-c,G,res)
        else:
            dfs(e[0],v,c,G,res)
        
if __name__ == '__main__':
    solve()

Measured memory_bytes: 154712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int[] AP=cin.ArrayInt(2,0);
        int P=AP[0]*3+AP[1];
        Console.WriteLine(P/2);
        
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 13140
n = gets.chomp.to_i
h = gets.chomp.split(" ").map(&:to_i)

possible = true
last = h[n-1]
for i in 2..n do
    if h[n-i]-last > 1
        possible = false
    elsif h[n-i]-last > 0
        h[n-i] -= 1
    end
    last = h[n-i]
end

if possible
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 9604