akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1007;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	while(1){
		string s;
		cin>>s;
		if(s[0]=='#')break;
		ll a,b,c;
		cin>>a>>b>>c;
		if(a<31 || (a==31&&b<5)){
			cout<<s<<" "<<a<<" "<<b<<" "<<c<<endl;
		}else{
			s = "?";
			ll d = 0;
			d += c;
			ll y=31,m=5;
			while(y!=a || m!=b){
				d += days[m];
				m++;
				if(m==13){
					m=1;
					y++;
				}
			}
			a = 1;b = 4;c = 30;
			while(d){
				if(c+d>days[b]){
					d -= (days[b] - c+1);
					c = 1;
					b++;
					if(b==13){
						b=1;
						a++;
					}
				}else{
					c+=d;
					d=0;
				}
			}
			cout<<s<<" "<<a<<" "<<b<<" "<<c<<endl;
		}
	}
}



Measured memory_bytes: 3088
<?php

$in = file_get_contents('php://stdin');

$inarr = explode("\n", $in);

$s = array_splice($inarr, 0, 1)[0];
$q = intval(array_splice($inarr, 0, 1)[0]);

$queries = $inarr;
$rev = false;

$left = "";
$right = "";
foreach ($queries as $query) {
  $t = explode(" ", $query);
  if ($t[0] == 1) {
    $rev = !$rev;
  } else {
    $f = $t[1];
    $c = $t[2];
    if ($f == 1) {
      if (!$rev) {
        $left = $c . $left;
      } else {
        $right = $right . $c;
      }
    } else {
      if (!$rev) {
        $right = $right . $c;
      } else {
        $left = $c . $left;
      }
    }
  }
}

if ($rev) {
  $s = strrev($right) . strrev($s) . strrev($left);
} else {
  $s = $left . $s . $right;
}
echo $s . PHP_EOL;


Measured memory_bytes: 27120
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String replaced = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "");
        if(replaced.length() == 0) System.out.println("YES");
        else System.out.println("NO");
    }
}


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

using namespace std;

int cntDiv(int n)
{
    int res = 0;
    for(int i = 1; i <= n; i++)
    {
        if(n % i == 0)
            res++;
    }
    return res;
}

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

    int n;
    cin >> n;

    int ans = 0;
    for(int i = 1; i <= n; i += 2)
    {
        if(cntDiv(i) == 8)
            ans++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
import copy
import collections

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))
H={v:set() for v in V}
L={v:None for v in V}

for i in range(M):
    v,w=map(int,input().split())
    H[v].add(w)
    H[w].add(v)

Q=collections.deque()
Q.append(V[0])

L[1]=1
n=1

while Q:
    x=Q.popleft()
    for v in H[x]:
        if L[v]!=None:
            continue
        L[v]=x
        n+=1
        Q.append(v)

if n==N:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")

Measured memory_bytes: 123532
N=int(input())
A=list(map(int,input().split()))
I=2*N
D=[[-I]*(N+1)for _ in range(N+1)]
M=0
r=[-I]*(N+1)
def c(i,j,k):
    D[i][j]=max(k,D[i][j])
    D[j][i]=max(k,D[j][i])
    r[i]=max(r[i],D[i][j])
    r[j]=max(r[j],D[i][j])
    global M
    M=max(M,k)
a=0
D[A[0]][A[1]]=0
D[A[1]][A[0]]=0
r[A[0]]=0
r[A[1]]=0
for i in range(N-1):
    n=A[3*i+2:3*i+5]
    C=[]
    if len(set(n))==1:
        a+=1
        continue
    if len(set(n))==2:
        for j in range(3):
            if n.count(n[j])==2:
                X=n[j]
            else:
                Y=n[j]
        for j in range(1,N+1):
            C.append((j,Y,D[X][j]+1))
    X,Y,Z =n
    C.append((X,Y,D[Z][Z]+1))
    C.append((Y,Z,D[X][X]+1))
    C.append((X,Z,D[Y][Y]+1))
    C.append((X,Y,M))
    C.append((X,Z,M))
    C.append((Y,Z,M))
    for j in range(1,N+1):
        for k in range(3):
            C.append((j,n[k],r[j]))
    for j,k,l in C:
        c(j,k,l)
M=max(M,D[A[-1]][A[-1]]+1)
print(a+M)

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    REP(i,N)cin >> P[i];
    REP(i,N)cin >> Q[i];

    vector<int> D(N);
    REP(i,N)D[i] = i+1;

    int p,q;
    int count = 0;
    int indexP, indexQ;
    do{
        bool flagP = true;
        bool flagQ = true;
        REP(i,N){
            if(P[i] != D[i])flagP = false;
            if(Q[i] != D[i])flagQ = false;
        }

        if(flagP)indexP = count;
        if(flagQ)indexQ = count;
        count++;
    }while(next_permutation(ALL(D)));

    cout << abs(indexP - indexQ) << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;

ll calc(string s) {
	ll add = 0, res = 0;
	rep(i, 0, s.size()) {
		if (s[i] == '+') {
			res += add; add = 0;
		}
		else {
			add = add * 10 + (s[i] - '0');
		}
	}
	res += add; return res;
}

int main() {
	string s; cin >> s;
	int n = s.size();
	ll ans = 0;
	rep(mask, 0, 1 << (n - 1)) {
		string t = "";
		rep(i, 0, n - 1) {
			t += s[i];
			if ((mask >> i) & 1) t += "+";
		}
		t += s[n - 1];
		ans += calc(t);
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int solve(string s) {
	reverse(s.begin(), s.end());
	int n = s.size();
	vector<vector<int>> dp(n + 10, vector<int>(2, INF));
	dp[0][0] = s[0] - '0';
	dp[0][1] = 10 - (s[0] - '0');
	for(int i = 1; i < n; i++) {
		int d = s[i] - '0';
		dp[i][0] = min(dp[i-1][0] + d, dp[i-1][1] + (d+1));
		dp[i][1] = min(dp[i-1][0] + 10 - d, dp[i-1][1] + 10 - (d+1));
	}
	return min(dp[n-1][0], dp[n-1][1] + 1);
}

int main() {
	string s;
	cin >> s;
	cout << solve(s) << endl;
	return 0;
}


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

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

int main()
{
    int n;
    scanf("%d", &n);

    int mx[n - 1];
    for (int i = 0; i < n - 1; i++)
        scanf("%d", &mx[i]);

    int ans = mx[0] + mx[n - 2];
    for (int i = 0; i < n - 2; i++) {
        ans += min(mx[i], mx[i + 1]);
    }

    printf("%d\n", ans);

    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    int k;
    char ans='1';
    cin>>s>>k;
    
    for(int i = 0; i < min((int)s.size(), k); i++)
    {
        if(s[i]!='1')
        {
            ans=s[i];
            break;
        }
    }
    

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
 char S[100];
 int a,b; 
 while(1){
  cin>>S;
  if(S[0]=='0') break;
  for(int i=1;S[i]!='\0';i++){
   if(S[i]=='A') a++;
   if(S[i]=='B') b++; 
   }
  if(a>b) a++;
  else b++;
  cout<<a<<' '<<b<<endl;
  a=0; b=0;

 }  

 return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define mod 998244353
#define maxn 200005
using namespace std;
long long n,x,m,tt=99999999999ll;
int vis[maxn];
long long arr[maxn];
int main()
{
	long long sum=0;
	cin>>n>>x>>m;
	for (int i=1;i<=n;i++)
	{
		if (vis[x]!=0)
		{
			arr[i]=arr[i-1]+x;
			long long zhouqihe,zhouqi;
			zhouqihe=arr[i]-arr[vis[x]];
			zhouqi=i-vis[x];
			long long lef=n-i+1;
			long long tim=lef/zhouqi;
			sum+=zhouqihe*tim;
			tt=i+tim*zhouqi;
			break;
		}
		sum+=x;
		arr[i]=arr[i-1]+x;
		vis[x]=i;
		x=x*x%m;
	}
	for (tt;tt<=n;tt++)
	{
		sum+=x;
		x=x*x%m;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    string s;
    cin >> s;
    int n = s.size();
    vector<int> h{0};
    for(auto c : s) {
        int cur = h.back() + (c == '1' ? 1 : -1);
        h.push_back(cur);
    }
    vector<int> z = h;
    FORR(i, n) chmax(z[i], z[i + 1]);
    int mx = *max_element(ALL(h));
    int ans = 1 << 30;
    rep(_, 2) {
        int cur = 0, mn = 0;
        rep(i, n) {
            if(s[i] == '?') {
                if(cur + z[i + 1] - h[i] + 2 <= mx)
                    cur++;
                else
                    cur--;
            } else if(s[i] == '0')
                cur--;
            else
                cur++;
            chmin(mn, cur);
        }
        chmin(ans, mx - mn);
        mx++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12432
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	h := nextInt()
	n := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = nextInt()
	}
	// dp[hp] = cost
	dp := make([]int, 10001)
	for i, _ := range dp {
		dp[i] = -1
	}
	dp[h] = 0
	for i := h; i > 0; i-- {
		if dp[i] != -1 {
			for j := 0; j < n; j++ {
				tmp_hp := max(0, i-a[j])
				tmp_cost := b[j]
				if dp[tmp_hp] == -1 {
					dp[tmp_hp] = dp[i] + tmp_cost
				} else {
					dp[tmp_hp] = min(dp[tmp_hp], dp[i]+tmp_cost)
				}
			}
		}
	}
	fmt.Println(dp[0])
}

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

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

int main() {
  int N;
  cin >> N;
  int a = N / 1000;
  int b = (N - a * 1000) /100;
  int c = (N - a * 1000 - b * 100) /10;
  int d = N - a * 1000 - b * 100 - c* 10;
  
  if (b != c) {
    cout << "No" << endl;
  }

  else if(a == b || c == d){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
const int N = 8003;
string s;
int x, y;
vector <pii> a, b;
bool canx[N][2 * N];
bool cany[N][2 * N];
void make(string s, vector <pii> &a, vector <pii> &b) {
    a.clear(); b.clear();
    int cnt = 0, flip = 0;
    s += 'T';
    for (auto x: s) {
        if (x == 'T') {
            if (!flip) {
                if (a.size() == 0)
                    a.push_back(make_pair(cnt, cnt));
                else
                    a.push_back(make_pair(cnt, -cnt));
            }
            else b.push_back(make_pair(cnt, -cnt));
            cnt = 0;
            flip = 1 - flip;
        } else cnt++;
    }
}
void canReach(vector <pii> c, bool can[N][2 * N]) {
    memset(can, 0, sizeof(can));
    can[0][N] = true;
    int n = c.size();
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 2 * N; j++)
            if (can[i - 1][j]) {
                can[i][j + c[i - 1].first] = can[i][j + c[i - 1].second] = true;
            }
    }
}
void process (string s, bool canx[N][2 * N], bool cany[N][2 * N]) {
    make(s, a, b);
    canReach(a, canx);
    canReach(b, cany);
}
int main() {
    try {
        cin >> s;
        process(s, canx, cany);
        cin >> x >> y;
        if (canx[(int)a.size()][x + N] && cany[(int)b.size()][y + N]) {
            cout << "Yes";
        } else cout << "No";
    } catch (exception ex) {
    }
    return 0;
}


Measured memory_bytes: 125824
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  for (int i = 0; i < N; i++) {
  string x;
    cin>>x;
    if(x=="Y"){
      cout<<"Four"<<endl;
      break;
    }
      else if(i==N-1){
        cout<<"Three"<<endl;
    }
  }
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long 
#define FF first
#define SS second
#define MOD 1000000007

using namespace std;

int gcd(int a, int b) {
  while (a > 0 && b > 0)
    if (a > b) a %= b;
    else b %= a;
  return a + b;
}

ll modpower(ll x, ll y, ll p) //x^y mod p
{
    ll res = 1;      // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y %2!= 0)
            res = (res*x) % p;
 
        // y must be even now
        y = y/2;
        x = (x*x) % p;  
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	int arr[n];
	int dp[n+1];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		dp[--arr[i]]=i;
	}
	int ans = 1;
	int maxn = 1;
	for(int i=1;i<n;i++)
	{
		if(dp[i]>=dp[i-1])
			ans++,maxn = max(ans,maxn);
		else ans=1;
	}
	cout<<n-maxn;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> A(N);
  REP(i, N) cin >> A[i];
  map<lint, lint> ma;
  REP(i, N) {
    ma[-A[i]]++;
  }
  int ans = 0;
  for(auto itr=ma.begin(); itr!=ma.end(); itr++) {
    lint a = -(itr->first);
    lint b = 1;
    while(b <= a) b *= 2;
    b -= a;
    if(ma.find(-b) != ma.end()) {
      if(a != b && ma[-a] >= 1 && ma[-b] >= 1) {
        int t = min(ma[-a], ma[-b]);
        ma[-a] -= t;
        ma[-b] -= t;
        ans += t;
      } else if(a == b && ma[-a] >= 2){
        int t = ma[-a] / 2;
        ma[-a] -= t*2;
        ans += t;
      }
      
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 14336
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int main() 
{
    int n,k,i;
    cin>>n>>k;
    //cin>>d;
    int c[n+1];
    for(i=1;i<=n;i++)c[i]=0;
    while(k--)
    {
        int x;
        cin>>x;
        int a[x];
        for(i=0;i<x;i++)
        {
            cin>>a[i];c[a[i]]++;
        }
    }
    int count=0;
    for(i=1;i<=n;i++)
    {
     //   cout<<c[i]<<" ";
        if(c[i]==0)
        count++;
    }
    cout<<count;
}
    

Measured memory_bytes: 3632
//Main.java
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long a = k;
		for (long i = 1; i < n; i++) {
			a *= k - 1;
		}
		System.out.println(a);
	}
}

Measured memory_bytes: 9804
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        ArrayList<Integer> xx = new ArrayList<>();
        ArrayList<Integer> yy = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            xx.add(sc.nextInt());
        }
        for (int i = 0; i < m; i++) {
            yy.add(sc.nextInt());
        }
        xx.add(x);
        yy.add(y);
        int maxX = Collections.max(xx);
        int minY = Collections.min(yy);
        //Collections.sort(xx);
        //Collections.sort(yy);
        if(minY - maxX > 0) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }
    }
}

Measured memory_bytes: 35856
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(void) {

	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;
	S[K - 1] = tolower(S[K - 1]);

	cout << S << endl;


	return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

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



int main() {
  // 入力
  int N, K;
  cin >> N >> K;

  ll ans = 0;
  if (K == 0) {
    ans = 1LL * N * N;
  } else {
    // bを固定して考える
    for (int i = 1; i <= N; i++) {
      int p = N / i;
      int q = N % i;
      ans += p * max(0, i - K) + max(0, q - K + 1);
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  long int day[110000][3];
  cin >> N;

  rep(i,N) {
    rep(j,3) cin >> day[i][j];
  }

  long int dp[110000][3];
  memset(dp, -1, sizeof(dp));
  rep(i,3) dp[0][i] = 0;

  FOR(i,1,N) {
    rep(j,3) {
      rep(k,3) {
	if(j==k) continue;
	dp[i][j] = max(dp[i][j], dp[i-1][k] + day[i-1][j]);
      }
    }
  }

  long int res = 0;
  rep(i,3) res = max(res, dp[N][i]);

  cout << res << endl;
}


Measured memory_bytes: 5376
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
}



Measured memory_bytes: 892
from collections import defaultdict

n, m = map(int, (input().split()))
dic = defaultdict(list)
seen = [False] * (n+1)
count = 0

for _ in range(m):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)


def dfs(pos, pre_pos, depth, seen):
    if seen[pos]:
        return

    seen[pos] = True
    todo = dic[pos]

    for next_pos in todo:
        if next_pos == pre_pos:
            continue
        dfs(next_pos, pos, depth+1, seen)

    seen[pos] = False
    if depth == n:
        global count
        count += 1
    return


dfs(1, -1, 1, seen)
print(count)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int moji(char in){
    return (int)in - (int)'a';
}

int main() {
    //cout.precision(10);
    string S;
    cin >> S;
    int n = S.size();
    string revS;
    string T;
    string revT;
    for(int i = 0; i < n; i++){
        revS.push_back(S[n - i - 1]);
        if(S[i] != 'x'){
            T.push_back(S[i]);
        }
        if(revS[i] != 'x'){
            revT.push_back(revS[i]);
        }
    }
    if(T != revT){
        cout << -1 << endl;
        return 0;
    }
    //cout << S << endl << revS << endl;
    int ans = 0;
    vector<int> field[2];
    field[0].push_back(0);
    for(int i = 0; i < n; i++){
        if(S[i] != 'x'){
            field[0].push_back(0);
            continue;
        }
        field[0].back()++;
    }
    field[1].push_back(0);
    for(int i = 0; i < n; i++){
        if(revS[i] != 'x'){
            field[1].push_back(0);
            continue;
        }
        field[1].back()++;
    }
    /*
    for(int i = 0; i < field[0].size(); i++){
        cout << field[0][i] << endl;
    }
    cout << endl;
    for(int i = 0; i < field[1].size(); i++){
        cout << field[1][i] << endl;
    }*/
    for(int i = 0; i < field[0].size(); i++){
        ans += max(0, field[1][i] - field[0][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  ll a;
  ci(a);
  long double c=0;
  vector<double> b(a);
  for(i,0,a)
    ci(b[i]);
  for(i,0,a)
    c+=(1/b[i]);
  co(1/c);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}

int main(void)
{
	ll q,h,s,d,n;
	scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
	if(q*2<h) h=q*2;
	if(h*2<s) s=h*2;
	if(s*2<d) d=s*2;
	if(n==1) printf("%lld\n",s);
	else if(n==2) printf("%lld\n",d);
	else{
		if(n%2) printf("%lld\n",d*(n/2)+s);
		else printf("%lld\n",d*(n/2));
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int r,d;
  cin >> r >> d;
  ll x;
  cin >> x;
  rep(i,10){
    x = r*x - d;
    cout << x << endl;
  }
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        int[] num = new int[N+1];

        // from left to right
        int tmp = 0;
        for (int i=0;i<N;i++) {
            if (S.charAt(i)=='<') {
                num[i]=tmp;
                tmp++;
            } else {
                if (0<i && S.charAt(i-1)=='<') {
                    num[i]=tmp;
                }
                tmp=0;
            }
        }
        if (S.charAt(N-1)=='<') {
            num[N]=tmp;
        }

        // from right to left
        tmp = 0;
        for (int i=N-1;i>=0;i--) {
            if (S.charAt(i)=='>') {
                num[i+1]=tmp;
                tmp++;
            } else {
                if (N-1>i && S.charAt(i+1)=='>') {
                    num[i+1]=Math.max(num[i+1], tmp);
                }
                tmp=0;
            }
        }
        if (S.charAt(0)=='>') {
            num[0]=tmp;
        }

        long ans = 0L;
        for (int i=0;i<N+1;i++) {
            ans += (long)num[i];
        }
        System.out.println(ans);
        // System.out.println(Arrays.toString(num));
    }
}

Measured memory_bytes: 32312
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,c,x;//500 100 50
int ans;
int main()
{
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if((i*500+j*100+k*50)==x)ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

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


int main(){
    int n,a;
    cin>>n>>a;

    cout<<n*n-a<<endl;

    return 0;
}


Measured memory_bytes: 256
/************
* 	@Just Another Source code by: ankit.sangwan1999
*	@created on: 24 Jun 2020
*	@Based On : MCM
*/
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9+7;
const long double pie = 3.14159265358979323846;
#define endl '\n'
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, ll> ma; // orderd_map using pb_ds
const int N = 405;		
ll dp[N][N];
ll sum[N];

void pre_sum(int *arr, int n){
	sum[0] = arr[0];
	for(int i=1;i<n;i++) sum[i] = sum[i-1] + arr[i];
}

// Cost of interval l to r is -> minimum among the partitions from (k=i to k=j) + sum of terms i to j
// dp[i][j] -> stores the minimum cost of the interval i to j.

// O(n^2) time and space
ll MCM(int i, int j, int *arr){
	if(dp[i][j] != -1) return dp[i][j];
	
	if(i==j){
		return dp[i][j] = 0;
	}

	ll ans = ULLONG_MAX/2;
	
	ll curr_cost = (i==0?sum[j]:sum[j]-sum[i-1]); // sum till i to j.(cost of joining the left and right intervals)
	
	for(int k=i;k<j;k++){

		ll left_cost = MCM(i,k,arr);
		ll right_cost = MCM(k+1,j,arr);
		ll tmp = left_cost + right_cost + curr_cost;
		ans = min(ans, tmp);

	}
	return dp[i][j] = ans;

}

void solve(){
	memset(dp, -1, sizeof(dp));
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	pre_sum(arr, n); // to calculate the prefix sums.
	cout<<MCM(0,n-1, arr);

}
signed main(){

    fastio;
    int t=1;
    //cin>>t;

    while(--t>=0){
    	solve();
    }
	
    return 0;
}

Measured memory_bytes: 4980
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N = 100;
static const int MOD = 10000;
static const int NIL = -1;

int N, K;
int menu[MAX_N];
int memo[MAX_N][3][3][3];

int main(){
	cin >> N >> K;
	fill(menu, menu + N, NIL);
	fill(memo[0][0][0], memo[N][0][0], 0);
	for(int i = 0; i < K; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		menu[a] = b;
	}
	for(int i = 0; i < 3; i++){
		if(menu[0] != NIL && i != menu[0]) continue;
		memo[0][0][0][i]++;
	}
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			if(menu[1] != NIL && j != menu[1]) continue;
			memo[1][0][i][j] += memo[0][0][0][i];
		}
	}
	for(int i = 2; i < N; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				for(int l = 0; l < 3; l++){
					if(menu[i] != NIL && l != menu[i]) continue;
					if(l == k && l == j) continue;
					for(int m = 0; m < 3; m++){
						memo[i][j][k][l] += memo[i - 1][m][j][k];
						memo[i][j][k][l] %= MOD;
					}
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				ans += memo[N - 1][i][j][k];
				ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3092
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;

typedef long long ll;



int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int x;
    cin >> x;
    cout << (x<1200? "ABC":"ARC") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
  ll n,m,ans;
  cin>>n>>m;
  if (2*n>=m) {
    ans=m/2;
  }
  else {
    m -= 2*n;
    ans=n+m/4;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

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

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

ll fact[MAX], fact_inv[MAX];

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////


void Main() {
  ll N; cin >> N;
  vector<ll> C(N);
  vector<queue<int>> place(MAX);
  rep(i, 0, N){
    cin >> C[i];
    place[C[i]].push(i);
  }
  vector<ll> dp(MAX, 0);
  dp[0] = 1;
  rep(i, 1, N + 1){
    ll n = i - 1;
    dp[i] += dp[i - 1];
    if(place[C[n]].front() != n){
      if(place[C[n]].front() != n - 1){
        dp[i] += dp[place[C[n]].front() + 1];
      }
      place[C[n]].pop();
    }
    dp[i] %= MOD;
  }
  cout << dp[N] << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 342528
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		while (in.hasNext()) {
			int N = in.nextInt();
			PriorityQueue<Double> pq = new PriorityQueue();
			
			for (int i = 0; i < N; ++i) {
				pq.add(in.nextDouble());
			}
			
			while (pq.size() > 1) {
				double ingredient1 = pq.poll();
				double ingredient2 = pq.poll();
				double newIngredient = (ingredient1 + ingredient2) / 2;
				
				pq.add(newIngredient);
			}
			
			System.out.println(pq.peek());
		}
	}

}


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int d,n;cin>>d>>n;
	if(n==100){
		cout << (int)pow(100, d) * 101 << endl;
	}else{
		cout << (int)pow(100, d) * n << endl;
	}
	
	return 0;
}


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

int main()
{
    string S;
    cin >> S;
//    string S = "BWBWBW";
    long long ret = 0;
    long long leftB = 0;
    for(int idx = 0; idx < S.size(); idx++)
    {
        if(S[idx] == 'B')
            leftB++;
        else if(S[idx] == 'W')
            ret += leftB;
    }
    cout << ret;
    return 0;
}


Measured memory_bytes: 640
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

n = 0
memo = []
for i in range(h):
    for j in range(w):
        if i==h-1 and j==w-1:
            continue

        if a[i][j]%2==1:
            n += 1
            a[i][j] -= 1
            if j == w-1:
                a[i+1][j] += 1
                memo.append([i+1, j+1, (i+1)+1, j+1])
            else:
                a[i][j+1] += 1
                memo.append([i+1, j+1, i+1, (j+1)+1])

print(n)
for k in memo:
    print(" ".join(list(map(str, k))))

Measured memory_bytes: 29832
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define eps 1e-9
#define double long long
using namespace std;
struct point{
	double x,y;
	void read(){scanf("%lld%lld",&x,&y);}
	void write(){printf("%.9f %.9f\n",x,y);}
	point(double X=0.0,double Y=0.0):x(X),y(Y){}
	point operator +(const point a)const{return point(x+a.x,y+a.y);}
	point operator -(const point a)const{return point(x-a.x,y-a.y);}
	point operator *(double a)const{return point(x*a,y*a);}
	point operator /(double a)const{return point(x/a,y/a);} 
};
double dis(point a){return a.x*a.x+a.y*a.y;}
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
short int jiao(point a,point b)//2:px 1:cz 0:other
{
	if(cross(a,b)==0) return 2;
	if(dot(a,b)==0) return 1;
	return 0;
}
point p1,p2,p3,p4;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		p1.read();p2.read();p3.read();p4.read();
		printf("%d\n",jiao(p2-p1,p4-p3));
	}
	return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <set>
#include <queue>

using namespace std;

vector<vector<int>> graph;

int n, m;

int addBit(int mask, int bit) {
	return mask + (1LL << bit);
}

int getBit(int mask, int bit) {
	return (1LL << bit) & mask;
}

int ans = 0;

void dfs(int root, int mask) {
	mask = addBit(mask, root);
	if (mask == (1LL << n) - 1) ++ans;
	for (int i = 0; i < (int) graph[root].size(); ++i) {
		if (!getBit(mask, graph[root][i])) {
			dfs(graph[root][i], mask);
		}
	}
}

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

	cin >> n >> m;

	graph.resize(n);

	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		--l; --r;
		graph[l].push_back(r);
		graph[r].push_back(l);
	}

	dfs(0, 0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n;
i;
u,v;
ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],L[2<<17],R[2<<17]={1};
dfs1(u,p)
{
	dp1[u]=1;
	int id=first[u];
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs1(eb[id],u);
			dp1[u]=dp1[u]*-~dp1[eb[id]]%M;
		}
		id=next[id];
	}
}
make();
dfs2(u,p,x)
{
	dp2[u]=dp1[u]*x%M;
	make(first[u],p,x);
	int id=first[u];
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs2(eb[id],u,L[id]*R[next[id]]%M+1);
		}
		id=next[id];
	}
}
make(i,p,x,t)long x,t;
{
	if(i)
	{
		L[i]=x;
		t=eb[i]!=p?-~dp1[eb[i]]:1;
		make(next[i],p,t*x%M);
		R[i]=R[next[i]]*t%M;
	}
}
main()
{
	scanf("%d%d",&n,&M);
	for(i=0;~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}
	for(i=1;i<2*n-1;i++)
	{
		next[i]=first[ea[i]];
		first[ea[i]]=i;
	}
	dfs1(1,0);
	dfs2(1,0,1);
	for(i=1;i<=n;i++)printf("%d\n",dp2[i]);
}

Measured memory_bytes: 13056
#include <stdio.h>

int main()
{
    int a, b, c, d, e;
    scanf("%d %d", &a, &b);
    c = a + b;
    d = a - b;
    e = a * b;
    int arr[3] = {c, d, e};
    int palinggede = arr[0];
    for (int i = 1; i < 3; i++) 
        {
		if (palinggede < arr[i])
			palinggede = arr[i];
	    }
 
    printf("%d", palinggede);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <deque>
#include <numeric>

using namespace std;
int main() {
	int n;
	int fh, h, fty, ten, f, i;
	int th = 1000;
	for (;;) {
		cin >> n;
		if (n == 0)break;
		th -= n;
		fh = th / 500;
		th -= 500 * fh;
		h = th / 100;
		th -= 100 * h;
		fty = th / 50;
		th -= 50 * fty;
		ten = th / 10;
		th -= 10 * ten;
		f = th / 5;
		th -= 5 * f;
		i = th;
		cout << fh + h + fty + ten + f + i << endl;
		th = 1000;
	}
	


}

Measured memory_bytes: 3072
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val k = sc.nextInt()
    val n = sc.nextInt()
    val a = (1..n).map { sc.nextInt() }

    var ans = k - (k - a.last()) - a.first()
    for (i in 0 until n - 1) {
        ans = Math.min(ans, k - (a[i + 1] - a[i]))
    }
    println(ans)
}

Measured memory_bytes: 77364
inpl = lambda: tuple(map(int,input().split()))
N, M, Q = inpl()
abcd = []
for _ in range(Q):
    a, b, c, d = inpl()
    abcd.append((a-1,b-1,c,d))

ans = 0
pool = [(0,0)]
A = []
while pool:
    d, m = pool.pop()
    while len(A) > d:
        A.pop()
    A.append(m)
    if d == N-1:
        point = sum(d for a, b, c, d in abcd if A[b]-A[a] == c)
        if point > ans:
            ans = point
    else:
        for k in range(m,M):
            pool.append((d+1,k))
print(ans)


Measured memory_bytes: 69332
#include<bits/stdc++.h>
using namespace std;
int main() {
  string n, n_c;
  cin >> n;
  n_c = n;
  reverse(n.begin(), n.end());
  if (n == n_c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
using ll=long long;
int main(){
    int n;
    ll k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n){cin>>a[i];a[i]--;}
    vector<int> path;
    set<int> used; 
        int v=0;
        while(used.count(v)==0){
            used.insert(v);
            path.push_back(v);
            v=a[v];
        }
        int l=find(path.begin(), path.end(), v) - path.begin();
        int w=path.size() - l;
    
    if(l>k)cout<<path[k]+1<<endl;
    else cout<<path[(k-l)%w+l]+1<<endl;
 
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"

ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
// dsu start

vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}

// dsu end
//vi vis(200001,0);
vi adj[200001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
    int sx, sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int ud = ty-sy;
    int lr = tx-sx;

    for(int i=0; i<ud; ++i) cout<<"U";

    for(int i=0; i<lr; ++i) cout<<"R";

    for(int i=0; i<ud; ++i) cout<<"D";

    for(int i=0; i<lr; ++i) cout<<"L";

    cout<<"L";
	
	for(int i=0; i<ud+1; ++i) cout<<"U";

	for(int i=0; i<lr+1; ++i) cout<<"R";

	cout<<"D";
	
	cout<<"R";

	for(int i=0; i<ud+1; ++i) cout<<"D";

	for(int i=0; i<lr+1; ++i) cout<<"L";

	cout<<"U";





}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int w, d;
	while(cin >> w >> d and w > 0) {
		map<int, pair<int, int>> mp;
		for(int i = 0; i < w; ++i) {
			int h; cin >> h;
			mp[h].first++;
		}
		for(int i = 0; i < d; ++i) {
			int h; cin >> h;
			mp[h].second++;
		}
		int ans = 0;
		for(auto e : mp) {
			auto p1 = e.first;
			auto p2 = e.second;
			ans += p1 * max(p2.first, p2.second);
		}
		cout << ans << '\n';
	}
	return 0;
}



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

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String num = scan.nextLine();
		String[] numbers = num.split(" ");
		double N = Integer.parseInt(numbers[0]);
		double M = Integer.parseInt(numbers[1]);


		String num2 = scan.nextLine();
		String[] numbers2 = num2.split(" ");
//		int A1 = Integer.parseInt(numbers[0]);
//		int A2 = Integer.parseInt(numbers[1]);
//		int A3 = Integer.parseInt(numbers[2]);
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i<N; i++) {
			list.add(Integer.parseInt(numbers2[i]));
		}
		int count = 0;
		double sum = 0;
		for(int i = 0; i<N; i++) {
			sum=sum+list.get(i);
		}
		for(int i = 0; i<N; i++) {
			if(list.get(i)<(sum)/(4*M)) {

			}else {
				count++;
			}
		}
//		System.out.println(count);
		if(count>=M) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;//pは素数の数
}

int solve(ll A, ll B) {
  ll g = gcd(A, B);
  int ans = 1;
  sieve(1001001);
  REP(i,1000000) {
    if (!is_prime[i]) continue;
    if (g % i == 0) {
      ans++;
      while (g % i == 0) g /= i;
    }
  }

  if (g > 1) ans++;

  return ans;
}

ll solve2(ll A, ll B) {
    ll g = gcd(A,B);
 
    ll ans = 1;
    for(ll i=2;i*i<=g;++i){
        if(g%i==0){
            ++ans;
            while(g%i==0) g/=i;
        }
    }
    if(g>1) ++ans;
    return ans;
}

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

  ll A,B;
  cin >> A >> B;

  cout << solve(A, B) << endl;
  // cout << solve2(A, B) << endl;
}


Measured memory_bytes: 4944