akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
a = gets.split.map(&:to_i)
h = Hash.new(0)
a.sort!.reverse!
a.each{|t| h[t]+=1}

def f(x)
  res = 1
  while x>0
    x /= 2
    res *= 2
  end
  res
end

ans = 0
a.each{|t|
  r = f(t)
  if t==r-t
    if h[t]>=2
      h[t]-=2
      ans+=1
    end
  else
    if h[r-t]>=1 && h[t]>=1
      h[t]-=1
      h[r-t]-=1
      ans+=1
    end
  end
}

p ans


Measured memory_bytes: 28908
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ').map(Number)).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && arr[left] > arr[i]) largest = left;
    else largest = i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest - i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 110732
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Set<Integer> set = new HashSet<>();
    set.add(sc.nextInt());
    set.add(sc.nextInt());
    set.add(sc.nextInt());
    System.out.println((set.size() == 2) ? "Yes" : "No");
  }
}

Measured memory_bytes: 23636
n = int(input())

arr = []

for i in range(n):
    x, y, h = map(int, input().split())
    arr.append([x, y, h])

for i in range(101):
    for j in range(101):
        for k in range(n):
            if arr[k][2] > 0:
                len1 = abs(arr[k][0] - i) + abs(arr[k][1] - j)
                ch = len1 + arr[k][2]
                break
            else:
                continue
        for k in range(n):
            lenk = abs(arr[k][0] - i) + abs(arr[k][1] - j)
            if max(ch - lenk, 0) == arr[k][2]:
                if k == n-1:
                    print("{} {} {}".format(i, j, ch))
                else:
                    continue
            else:
                break

Measured memory_bytes: 3064
/*input
1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

void solve(){
  	int n;
  	cin >> n;
  	int ans = 0;
  	int x = n;
  	for(int i = 2;i*i <= x;i++){
  		if(n%i == 0){
  			int cur = 0;
  			while(n%i == 0){
  				cur++;
  				n/= i;
  			}
  			int fir = 1;
  			int all = 0;
  			while(all+fir <= cur){
  				all += fir;
  				ans++;
  				fir++;
  			}
  		}
  	}
  	if(n > 1)ans++;
  	cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
N="0"+raw_input()
l=len(N)

F=[ 0 for _ in range(l) ] #繰り上がりなし
T=[ 0 for _ in range(l) ] #繰り上がりあり
#初期化
x=int(N[l-1])
F[l-1]=x
T[l-1]=10-x

for i in range(l-1,0,-1):
    next_x=int(N[i-1])
    #繰上なしへの遷移。前の桁が繰上なしの場合は単に該当桁の数字を足す、
    #前の桁が繰上ありの場合は、今の桁の数字が1増える
    F[i-1]=min(F[i]+next_x, T[i]+next_x+1) 
    #繰上ありへの遷移。前の桁が繰上なしの場合は(10-該当桁の数字)を足す、
    #前の桁が繰上ありの場合は今の桁の数字が1増えているので(10-該当桁の数字+1)
    T[i-1]=min(F[i]+10-next_x, T[i]+10-(next_x+1))

print F[0]


Measured memory_bytes: 51308
#include <stdio.h>

int main (){
    
    char str[10005];
    scanf("%[^\n]", str);
    int flag = 0;
    for(int i = 0;str[i] != '\0';i++){
    	if(str[i] == ' '){
    		if(str[i-1] != str[i+1]){
    			flag = 1;
    			break;
			}
		}
	}
	flag == 0 ? puts("YES") : puts("NO");
    
    return 0;
}

Measured memory_bytes: 1580
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
 
//using namespace __gnu_pbds;
 
#define N 2000001
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;

ll d[10001][10003], n, P, offset = 3000;

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

	d[0][offset] = 1;
	d[1][offset + 1] = 1;

	for (int i = 2; i <= 3 * n; i++)
		for (int j = - i / 2; j <= i; j++) {
			d[i][offset + j] += d[i-1][offset + j - 1];
			if (d[i][offset + j] >= P) d[i][offset + j] -= P;
			d[i][offset + j] += d[i-2][offset + j + 1] * (i - 1) % P;
			if (d[i][offset + j] >= P) d[i][offset + j] -= P;
			if (i > 2) d[i][offset + j] += d[i-3][offset + j] * (i - 1) * (i - 2) % P;
		}

	ll ans = 0;

	for (int i = 0; i <= 3 * n; i++) {
		ans += d[3 * n][offset + i];
		if (ans >= P) ans -= P;
	}

	cout << ans;
}

Measured memory_bytes: 238560
def main():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    bef = sum(a)
    for i in range(n-1):
        if a[i] + a[i+1] > x:
            a[i+1] -= min(a[i]+a[i+1]-x, a[i+1])
            a[i] -= a[i] + a[i+1] - x

    print(bef-sum(a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef vector<double> vec;
typedef vector<vec> mat;
double eps=1e-8;

vec gauss_jordan(const mat& A,const vec&b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];
  for(int i=0;i<n;i++)B[i][n]=b[i];

  vector<bool> flg(n,false);
  
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=0;j<n;j++){
      if(flg[i])continue;
      if(abs(B[i][j]) > abs(B[pivot][i]))pivot=j;
    }
    if(abs(B[i][i]) < eps)continue;
    flg[i]=true;
    double val=B[i][i];
    for(int j=0;j<=n;j++)B[i][j]/=val;
    for(int j=0;j<n;j++){
      if(i==j)continue;
      double va=B[j][i];
      for(int k=0;k<=n;k++)B[j][k]-=B[i][k]*va;
    }
  }
  for(int i=0;i<n;i++){
    if(abs(B[i][i])<eps && abs(B[i][n])>eps)return vec();
  }
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

int N,si,ti;
double t[100][100];
int f[100];
int G[100][100];

int main(){

  while(1){
    cin>>N>>si>>ti;
    if(N==0&&si==0&&ti==0)break;
    mat A( N, vec(N,0) );
    vec B(N,0);
    si--,ti--;
    for(int i=0;i<N;i++)cin>>f[i];

    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        cin>>G[i][j];
        t[i][j]=G[i][j];
        if(G[i][j]==0)G[i][j]=1e8;
      }
    }
    for(int i=0;i<N;i++)G[i][i]=0;
    
    for(int k=0;k<N;k++)
      for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
          G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
    


    for(int i=0;i<N;i++){
      if(f[i]){
        for(int j=0;j<N;j++){
          if(t[i][j]+G[j][ti]!=G[i][ti]){
            t[i][j]=0;
          }
        }
      }
    }
    /*
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        printf("%.4f ",t[i][j]);
      }
      cout<<endl;
    }
    cout<<endl;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        printf("%d ",G[i][j]);
      }
      cout<<endl;
    }
    */
    for(int i=0;i<N;i++){
      double sum=0,cnt=0;
      for(int j=0;j<N;j++){
        if(t[i][j]>0){
          sum+=t[i][j];
          cnt+=1.0;
        }
      }
      
      for(int j=0;j<N;j++)
        if(t[i][j]>0)A[i][j]=1.0/cnt;
      
      A[i][i]-=1.0;
      B[i]=-sum/cnt;
      B[ti]=0.0;
      for(int j=0;j<N;j++)A[ti][j]=0;
      A[ti][ti]=1.0;
    }
    vec ans=gauss_jordan(A,B);
    printf("%.10f\n",ans[si]);
  }
  return 0;
}

Measured memory_bytes: 3336
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

//----------------------------------------------------------------

int main()
{
    ll s, w;
    cin >> s >> w;
    if (s <= w)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>; 

ll a,b,c,d,n,m,k;
ll ans=100000000000;

string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll x,n;
  cin>>x>>n;
  vector<ll> vec(n);
  ll l=x,r=x,l_abs=0,r_abs=0;
  rep(i,n){
    cin>>vec[i];
  }
  int i=x;
  while(1){
    if(find(vec.begin(), vec.end(), i) != vec.end()){
      i--;
    } else {
      l = i;
      break;
    }
  }
  i=x;
  while(1){
    if(find(vec.begin(), vec.end(), i) != vec.end()){
      i++;
    } else {
      r = i;
      break;
    }
  }
  if(abs(x-r)==abs(x-l))ans=l;
  else if(abs(x-r)<abs(x-l))ans=r;
  else ans=l;
  cout<<ans;

  return 0;
}



Measured memory_bytes: 3620
using System;

namespace AIZU {
	class Program {
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		#endregion
		
		static void Main(string[] args) {
			const long wall = 1000000000 + 7;
			long[] Fact = new long[100001];
			Fact[0] = 1;//0!
			for (int i = 1; i < 100001; i++) {
				Fact[i] = Fact[i - 1] * i % wall;
			}
			int[] ani = cins();
			int N = ani[0], M = ani[1];
			if (N - M < -1 || N - M > 1) { print(0);return; }
			long Res;
			Res = (Fact[N] * Fact[M])%wall;
			if (N == M) Res = (Res * 2) % wall;
			print(Res);
			Console.ReadLine();
		}
	}
}

Measured memory_bytes: 11744
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if((abs(a-c)<=d)||((abs(a-b)<=d)&&abs(b-c)<=d))printf("Yes\n");
    else printf("No");
    
    return 0;
}

Measured memory_bytes: 128
def main():

    N, W = map(int, input().split())
    v, w = [0] * N, [0] * N
    for i in range(N):
        v[i], w[i] = map(int, input().split())

    dp = [[0 for _ in range(W + 2)] for _ in range(N + 1)]

    for i in range(N):
        for j in range(W + 1):
            if j - w[i] >= 0:
                dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i])
            else:
                dp[i + 1][j] = dp[i][j]

    print(max(dp[N]))


if __name__ == '__main__':
    main()



Measured memory_bytes: 16124
a,b,c = map(int,input().split())

#import math
#if math.sqrt(a) + math.sqrt(b) < math.sqrt(c):
if c>=a+b: 
    if 4*a*b<(c-a-b)**2:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    bool flg = true;
    for( int i = 0; i < s.size() - 1;++i ) {
        if( s[i] == s[i + 1] ) flg = false;

    }
    if( flg ) cout << "Good";
    else cout << "Bad";
    cout << endl;
    return 0;
}



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

int main() {
  int N, X; cin >> N >> X;
  vector<int> L(N+1), D(N+1);
  D[0] = 0;
  for(int i = 1; i <= N; ++i) {
    cin >> L[i-1];
    D[i] = D[i-1] + L[i-1];
  }
  int ans = 0;
  for(int i = 0; i <= N; ++i) {
    if(D[i] <= X) ans++;
    else {
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
mat=Array.new(h){gets.chomp.split("")}.transpose
 
def compression(mat)
  mat.each do |v|
    if v.all?{|a| a=="."}
      mat.delete(v)
      compression(mat)
    end
  end
  return mat
end

puts compression(compression(mat).transpose).map(&:join)

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

map<int, int>mp;
vector<P>v;
int main() {
	int p, s;
	while (scanf("%d,%d", &p, &s), p) {
		v.push_back(P(s, p));
	}
	sort(v.begin(), v.end(), greater<>());
	int j = 1; mp[v[0].second] = 1;
	for (int i = 1; i < v.size(); i++) {
		if (v[i].first == v[i - 1].first)mp[v[i].second] = j;
		else mp[v[i].second] = ++j;
	}
	int q; while (cin >> q)cout << mp[q] << endl;
	return 0;
}



Measured memory_bytes: 3164
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	string s;cin>>s;
	lint n=s.size(),ctr=0,ans=0;
	for(int i=0;i<n;++i){
		if(s[i]=='W'){
			ans+=i-ctr;
			++ctr;
		}
	}cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 720
n=int(input())
a=list(map(int,input().split()))
q=int(input())
temp=sum(a)
import collections
ca=collections.Counter(a)
for i in range(q):
  b,c=map(int,input().split())
  ba=ca[b]
  temp=temp-b*ba+c*ba
  print(temp)
  ca[b]=ca[b]-ba
  ca[c]=ca[c]+ba


Measured memory_bytes: 24024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=1;i<10;i++){
            for(int j=1;j<10;j++){
                if(i*j == N){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21844
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    ll val,lcm=1;
    rep(i,n){
    	cin>>val;
    	lcm=lcm/(__gcd(val,lcm));
    	lcm*=val;
    	//cout<<lcm<<endl;
    }
    cout<<lcm<<endl;


    return 0;      

}



Measured memory_bytes: 256
N, W = map(int, input().split())
Bs = [tuple(map(int, input().split())) for _ in range(N)]

dp = [0] * (W + 1)
for w, v in Bs:
    for i in range(W, w - 1, -1):
        dp[i] = max(dp[i], dp[i - w] + v)

print(dp[W])


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

bool solve(string s) {
    int left = 0, right = s.length() - 1;
    bool ans = true;
    while (left <= right) {
        if (s[left] != s[right]) {
            ans = false;
            break;
        }
        left++;
        right--;
    }
    return ans;
}

int main() {
source:
    string s;
    cin >> s;
    int n = s.length();
    bool a = solve(s.substr(0, (n - 1) / 2)),
         b = solve(s.substr((n + 3 / 2 - 1)));
    bool c = solve(s);
    if (a && b && c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(), v.end()
#define sc(a) scanf("%l64d", &a)
#define pr(a) printf("%l64d", a)

using namespace std;

int n;
 
const int INF = 1e9;
 
vector<vector<int>> d;
 
void floyd() {
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j){
                    d[i][j] = 0;
                }
                if (d[i][j] > d[i][k] + d[k][j] && i != j) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
}
 
main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int m, r;
    cin >> n >> m >> r;
    d.resize(n, vector<int>(n, INF));
    int from, to, w;
    vector<int> ri(r);
    for (int i = 0; i < r; i++){
        cin >> ri[i];
        ri[i]--;
    }
    for (int i = 0; i < m; i++) {
        cin >> from >> to >> w;
        from--;
        to--;
        d[from][to] = w;
        d[to][from] = w;
    }
    floyd();
    int ans = INF;
    sort(all(ri));
    do {
        int sm = 0;
        for (int i = 0; i < r - 1; i++){
            sm += d[ri[i]][ri[i + 1]];
        }
        ans = min(ans, sm);
    } while (next_permutation(all(ri)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
vector<int> a, b, c;
int n;
int dp[100000][3];
int f(int i, int last)
{
	if(i == n)
		return 0;
	else if(dp[i][last]!=-1)
		return dp[i][last];
		
	if(last == 0)
	{
		int bvalue = b[i];
		int cvalue = c[i];
		return dp[i][last] = max(b[i] + f(i+1,1), c[i] + f(i+1,2));
	}
	else if(last == 1)
	{
		int avalue = a[i];
		int cvalue = c[i];
		return dp[i][last]=max(a[i] + f(i+1,0), c[i] + f(i+1,2));
	}
	else
	{
		int avalue = a[i];
		int bvalue = b[i];
		return dp[i][last]=max(a[i] + f(i+1,0), b[i] + f(i+1,1));
	} 
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int q,w,e;
		cin>>q>>w>>e;
		a.push_back(q);
		b.push_back(w);
		c.push_back(e);
	}
	cout<<max(max(f(0,0),f(0,1)),f(0,2));
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;

    rep(i,N){
        int tmp=i*C-(N-1-i)*C;

        int u=A+tmp+(D-C)*i;
        int l=A+tmp-(D-C)*(N-1-i);
        if(l<=B&&B<=u){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int n = sc.nextInt();
                        int ans = 0;
			a %= b;
		        for(int i = 0; i < n; i++){
			      a *= 10;
			      ans += a/b;
			      a %= b;
		        }
			System.out.println(ans);
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  vector<P> D(N);
  rep(i, N) {
    cin >> D[i].first >> D[i].second;
  }
  for(int i = 0; i < N ; i++) {
    while(D[i].first == D[i].second && i < N) {
      cnt++;
      i++;
    }
    if (cnt >= 3) {
      cout << "Yes" << endl;
      return 0;
    } else {
      cnt = 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3624
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 8000000000000000000
int main() {
	int n;
	cin >> n;
	vector<pair<int,int>> cards;
	map<int, int> hogee;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		hogee[tmp]++;
	}
	for (auto i = hogee.begin();i != hogee.end();++i) {
		cards.push_back(make_pair(i->first, i->second));
	}
	for (int i = 0;i < cards.size();++i) {
		while(cards[i].second > 2) {
			int wow = cards[i].second % 3;
			cards[i].second /= 3;
			cards[i].second += wow;
		}
	}
	int cnt_one = 0, cnt_two = 0;
	for (int i = 0;i < cards.size();++i) {
		if (cards[i].second == 1) {
			cnt_one++;
		}
		else cnt_two++;
	}
	long long ans = cnt_two/2;
	ans *= 2;
	ans += cnt_one;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6136
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
//const int inf = 1e9; //1(1倍)e(指数)9(10^9)
//const ll MX = 1e18; //1(1倍)e(指数)18(10^18)
//const ll MOD = 1e9 + 7; //1000000007で割った余りを聞かれたら使う
//加算代入演算子は+=
//int 2^31 10^9まで
//intは10桁、long longは18桁、doubleは308桁、long double は4932桁
//10^10くらいまででdoubleは誤差が発生しちゃう。なるべく整数にすること
//doubleからlong longにキャストするときは、+0.5で切り捨ての誤差を調整
//__int128()で128bit対応の整数（多倍長整数）
//||は片方が成り立つとき
int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    if ((100 * r + 10 * g + b) % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}


	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }
	bool operator < (const Point &p)const { return x != p.x ? x < p.x : y < p.y; }
	bool operator ==(const Point &p)const { return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS; }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }
};
typedef Point Vector;
struct Segment
{
	Point p1, p2;
};
typedef Segment Line;
class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }//内積
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }//外積
bool isOrthogonal(Vector a, Vector b) { return fabs(dot(a, b)) < EPS; }//直行？
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); }
bool isOrthogonal(Line l1, Line l2) { return fabs(dot(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
bool isParallel(Vector a, Vector b) { return fabs(cross(a, b)) < EPS; }//平行？
bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); }
bool isParallel(Line l1, Line l2) { return fabs(cross(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
Point project(Line s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}


int main()
{
	int a[3]; cin >> a[0] >> a[1] >> a[2];
	int f=0, s=0;
	for (int i = 0; i < 3; i++)
	{
		f += a[i] == 5;
		s += a[i] == 7;
	}
	if (f == 2 && s == 1)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
typedef long long ll;
typedef double d;
typedef long double ld;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    map<string,bool> m;
    char lc;
    for(ll i=0;i<n;i++)
    {
        if(i==0)
        {
            string s;
            cin>>s;
            m[s]=1;
            lc=s[s.size()-1];
        }
        else
        {
            string s;
            cin>>s;
            if(m[s])
            {
                cout<<"No";
                return 0;
            }
            else if(s[0]!=lc)
            {
                cout<<"No";
                return 0;
            }
            m[s]=1;
            lc=s[s.size()-1];
        }
    }
    cout<<"Yes";
    return 0;
}



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

bool is_square(int n) {
  for(int i = 0; i * i <= n; ++i) {
    if(i * i == n) {
      return true;
    }
  }
  return false;
}

int main() {
  string a, b;
  cin >> a >> b;
  int n = stoi(a + b);
  if(is_square(n)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
inline void Fail(){printf("0");exit(0);}

const int maxn=100005;
int n,cnt;
int a[maxn],c[maxn],res[maxn];
ll ans[maxn];
vector<int>all,fir[maxn];

namespace BIT{
	int t[maxn];
	void inc(int v){for(v++;v<=n;v+=(v&-v))t[v]++;}
	int sum(int v){
		int res=0;
		for(v++;v;v-=(v&-v))res+=t[v];
		return res;
	}
}
 
int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
		all.pb(a[i]);
	}
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin());
	for(int i=n-1;i>=0;i--){
		a[i]=lower_bound(all.begin(),all.end(),a[i])-all.begin();
		c[a[i]]=i;
	}
	for(int i=all.size()-2;i>=0;i--)c[i]=min(c[i],c[i+1]);
	rep(i,all.size())fir[c[i]].pb(i);
	for(int i=n-1;i>=0;i--){
		BIT::inc(a[i]);
		rep(j,fir[i].size()){
			int x=fir[i][j];
			res[x]=BIT::sum(n-1)-BIT::sum(x-1);
//			cout<<x<<" "<<res[x]<<endl;
		}
	} 
	rep(i,all.size()){
		ans[c[i]]+=1LL*(all[i]-(!i?0:all[i-1]))*res[i];
	}
	rep(i,n)printf("%lld\n",ans[i]);
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int W,H,N;
  cin>>W>>H>>N;
  int x,y,a;
  int x_min=0;
  int x_max=W;
  int y_min=0;
  int y_max=H;
  vector<vector<int>> v(N,vector<int>(3));
  for(int i=0;i<N;i++){
    cin>>x>>y>>a;
    switch(a){
      case 1:
        x_min=max(x,x_min);
        break;
      case 2:
        x_max=min(x,x_max);
        break;
      case 3:
        y_min=max(y,y_min);
        break;
      case 4:
        y_max=min(y,y_max);
        break;
      default:
        break;
    }
  }
  if(x_max < x_min || y_max < y_min){
    cout<<0<<endl;
  }else{
    cout<<(x_max-x_min)*(y_max-y_min)<<endl;
  }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

var m = make(map[string]string)

func main() {
	_ = readInt()
	s := readString()

	bitCnt := strings.Count(s, "1")
	bitPlusCnt := bitCnt + 1
	bitMinusCnt := bitCnt - 1
	// fmt.Println(bitCnt, bitMinusCnt, bitPlusCnt)

	plusR := make([]int, len(s))
	minusR := make([]int, len(s))
	plusR[0] = 1 % bitPlusCnt
	minusR[0] = 1 % max(1, bitMinusCnt)
	for i := 1; i < len(s); i++ {
		plusR[i] = plusR[i-1] * 2 % bitPlusCnt
		minusR[i] = minusR[i-1] * 2 % max(1, bitMinusCnt)
	}
	// fmt.Println(plusR)
	// fmt.Println(minusR)

	rPlus := 0
	rMinus := 0
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == '1' {
			rPlus = (rPlus + plusR[len(s)-1-i]) % bitPlusCnt
			rMinus = (rMinus + minusR[len(s)-1-i]) % max(1, bitMinusCnt)
		}
	}

	for i := 0; i < len(s); i++ {
		ans := 1
		r := 0
		if s[i] == '1' {
			if bitMinusCnt == 0 {
				fmt.Println(0)
				continue
			}
			r = ((rMinus-minusR[len(s)-1-i])%bitMinusCnt + bitMinusCnt) % bitMinusCnt
		} else {
			r = ((rPlus+plusR[len(s)-1-i])%bitPlusCnt + bitPlusCnt) % bitPlusCnt
		}

		for r != 0 {
			bcnt := strings.Count(fmt.Sprintf("%b", r), "1")
			r = r % bcnt
			ans++
		}

		fmt.Println(ans)
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

int main() {
    int a, b, c, tmp;
    cin >> a >> b >> c;
    if (a>b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    if (b>c) {
        tmp = b;
        b = c;
        c = tmp;
    }
    if (a>b) {
        tmp = b;
        b = a;
        a = tmp;
    }
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3088
use std::str::FromStr;
use std::collections::HashMap;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let s : Vec<char> = get_one::<String>().chars().collect();
    let mut m : HashMap<char, i32>= HashMap::new();
    for c in s {
        let cnt = m.entry(c).or_insert(0);
        *cnt += 1;
    }
    let mut ans = true;
    for (_k,v) in &m {
        if v % 2 != 0 {
            ans = false;
            break;
        }
    }
    println!("{}", if ans {"Yes"} else {"No"});

}


Measured memory_bytes: 4352
using System;


public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            var s = int.Parse(line[2]);
            if (x == 0 && y == 0 && s == 0) break;
            var maxret = 0;
            for (int i = 1; i <= s - 1; i++)
            {
                var ret = calcAB(i, x, y, s);
                if (ret != -1) maxret = Math.Max(maxret, calcAB(i, x, y, s));
                else break;
            }
            Console.WriteLine(maxret);
        }
    }
    public static int calcAB(int a, int x, int y, int s)
    {
        var ret = 0;
        var w = new int[5];
        var az = a * (100 + x) / 100;
        var bz = s - az;
        if (bz <= 0) return -1;
        w[2] = bz * 100 / (100 + x);
        w[1] = w[2] - 1; w[0] = w[1] - 1; w[3] = w[2] + 1; w[4] = w[3] + 1;
        var az2 = a * (100 + y) / 100;
        for (int i = 0; i < 5; i++)
        {
            var bzw = w[i] * (100 + x) / 100;
            if (az + bzw == s) ret = az2 + w[i] * (100 + y) / 100;
        }
        return ret;
    }
}



Measured memory_bytes: 9200
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 2e5 + 60;
ll a[N];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", a + i), a[i] += a[i - 1];
    ll ans = numeric_limits<decltype(ans)>::max();
    for (int i = 2, sp1 = 1, sp2 = 3; i <= n - 2; i++)
    {
        for (; sp1 < i; sp1++)
        {
            auto res = {a[sp1] - a[0], a[i] - a[sp1], a[sp2] - a[i], a[n] - a[sp2]};
            ans = min(ans, max(res) - min(res));
            if (a[sp1] - a[0] > a[i] - a[sp1]) break;
        }
        for (; sp2 < n; sp2++)
        {
            auto res = {a[sp1] - a[0], a[i] - a[sp1], a[sp2] - a[i], a[n] - a[sp2]};
            ans = min(ans, max(res) - min(res));
            if (a[sp2] - a[i] > a[n] - a[sp2]) break;
        }
        for (int j = -20; j <= 20; j++)
            for (int k = -20; k <= 20; k++)
            {
                int sp3 = max(min(sp1 + j, i - 1), 1);
                int sp4 = max(min(sp2 + k, n - 1), i + 1);
                auto res = {a[sp3] - a[0], a[i] - a[sp3], a[sp4] - a[i], a[n] - a[sp4]};
                //printf("%d %d %d %lld\n", sp3, i, sp4, max(res) - min(res));
                ans = min(ans, max(res) - min(res));
            }
        /*while (sp1 < i && abs((a[sp1] - a[0]) - (a[i] - a[sp1])) >= abs((a[sp1 + 1] - a[0]) - (a[i] - a[sp1 + 1]))) sp1++;
        while (sp2 < n && abs((a[sp2] - a[i]) - (a[n] - a[sp2])) >= abs((a[sp2 + 1] - a[i]) - (a[n] - a[sp2 + 1]))) sp2++;*/
        /*auto res = {a[sp1] - a[0], a[i] - a[sp1], a[sp2] - a[i], a[n] - a[sp2]};
        ans = min(ans, max(res) - min(res));*/
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}

const LL N=1003;
struct NODE{
	db o,r,d;
};
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;
char a[1111];
LL cnt[333];

int main()
{
//	FOUT;//FIN;
	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v,d;
	cin>>a;
	l=strlen(a);
	rep(i,0,l){
		cnt[a[i]]++;
	}
	if((cnt['N']&&cnt['S'])||(!cnt['N']&&!cnt['S'])){
		if((cnt['W']&&cnt['E'])||(!cnt['W']&&!cnt['E']))puts("Yes");
		else puts("No");
	}
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    int sum = max(a * pow(2, k) + b + c,
              max(b * pow(2, k) + a + c,
                  c * pow(2, k) + b + a));
                  
    cout << sum;
    
    

}

Measured memory_bytes: 256
N,M=map(int,input().split())
edges=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  edges[a-1]+=[b-1]
  edges[b-1]+=[a-1]
vis=[1]+[0]*(N-1)#訪問フラグ

def DFS(v):
  if vis==[1]*N: 
    return 1
  ret=0
  for u in edges[v]:
    if vis[u]==0:
      vis[u]=1
      ret+=DFS(u)
      vis[u]=0
  else: return ret
print(DFS(0))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		int[] c = new int[4];
		int[] best = new int[4];
		int[] coin = { 10, 50, 100, 500 };
		for (int t = 0;; ++t) {
			int P = sc.nextInt();
			if (P == 0) break;
			for (int i = 0; i < 4; ++i) {
				c[i] = sc.nextInt();
			}
			int min = 1000;
			for (int i = 0; i <= c[0]; ++i) {
				for (int j = 0; j <= c[1]; ++j) {
					for (int k = 0; k <= c[2]; ++k) {
						for (int l = 0; l <= c[3]; ++l) {
							int sum = i * 10 + j * 50 + k * 100 + l * 500;
							if (sum < P) continue;
							int rest = sum - P;
							int ret = c[0] + c[1] + c[2] + c[3] - i - j - k - l;
							ret += rest / 500;
							rest -= rest / 500 * 500;
							ret += rest / 100;
							rest -= rest / 100 * 100;
							ret += rest / 50;
							rest -= rest / 50 * 50;
							ret += rest / 10;
							if (ret < min) {
								min = ret;
								best[0] = i;
								best[1] = j;
								best[2] = k;
								best[3] = l;
							}
						}
					}
				}
			}
			if (t > 0) System.out.println();
			for (int i = 0; i < 4; ++i) {
				if (best[i] != 0) {
					System.out.println(coin[i] + " " + best[i]);
				}
			}
		}
	}
}

Measured memory_bytes: 34116
#include <iostream>
using namespace std;
typedef long long ll;
ll n, c, f[35][110000], s, t, res, ans;
int main(void){
    // Your code here!
    cin >> n >> c;
    for (ll i = 0; i < n; i++) {
        cin >> s >> t >> c;
        f[c][s]++;
        f[c][t]--;
    }
    for (ll i = 1; i <= 30; i++) {
        for (ll j = 1; j <= 100000; j++) {
            if (f[i][j + 1] == 1) {
                f[i][j]++, f[i][j + 1]--;
            }
            f[i][j] += f[i][j - 1];
        }
    }
    for (ll i = 1; i <= 100000; i++) {
        ans = 0;
        for (ll j = 1; j <= 30; j++) {
            ans += f[j][i];
        }
        res = max(res, ans);
    }
    cout << res << endl;
}


Measured memory_bytes: 25984
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    int N;
    cin >> N;
    for (int k = 2; k <= 500; k++) {
        int m = k*(k-1) / 2;
        if (m == N) {
            int it = 1;
            vector<vector<int>> vec(k);
            for (int i = 0; i < k; i++) {
                for (int j = 0; j < i; j++) {
                    vec[i].push_back(vec[j][i-1]);
                }
                while ((int)vec[i].size() != k-1) {
                    vec[i].push_back(it);
                    it++;
                }
            }
            cout << "Yes\n";
            cout << k << "\n";
            for (int i = 0; i < k; i++) {
                cout << k-1 << " ";
                for (int x : vec[i]) cout << x << " ";
                cout << "\n";
            }
            return 0;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;

using namespace std;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k; cin >> n >> k;

    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    
    vector<ll> c(n+1,0);


    rep(i,k){
          rep(i,n+1) c[i] = 0;
          rep(i,n){
              if(a[i] == 0){ c[i]++; c[i+1]--;}
              else{
                  if(i - a[i] >= 0) c[i-a[i]]++;
                  else c[0] ++;
                  if(i+a[i]+1 <= n) c[i+a[i]+1]--;
                  else c[n]--;
              }
          }
          rep(i,n+1){  //simulate
              if(0 < i) c[i] += c[i-1];
          }
          rep(i,n) a[i] = c[i];  //update
          ll min = n+100;
          rep(i,n) chmin(min,a[i]);
          if(min == n) break;
    }

    rep(i,n) cout << a[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N - 1);
  vector<int> ans(N);
  rep(i, N - 1) {
    cin >> A[i];
    A[i]--;
    ans[A[i]]++;
  }

  rep(i, len(ans)) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 6336