akhauriyash/Code-Regression huggingface dataset:
import math
from functools import lru_cache
def Frog1():
    n = int(input())
    h = list(map(int,input().split(' ')))
    @lru_cache(None)
    def Solve(i):
        if i==n-1:
            return 0
        if i==n-2:
            return abs(h[i]-h[i+1])
        return min(Solve(i+1)+abs(h[i]-h[i+1]),Solve(i+2)+abs(h[i]-h[i+2]))
    dp = [0]*n
    for i in reversed(range(n)):
        if i==n-1:
            dp[i] = 0
        elif i==n-2:
            dp[i] = abs(h[i]-h[i+1])
        else:
            dp[i] = min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]))
    print(dp[0])
def Frog2():
    n,k = input().split(' ')
    n,k = int(n),int(k)
    h = list(map(int, input().split(' ')))
    @lru_cache(None)
    def Solve(i):
        if i==n-1:
            return 0
        ans = math.inf
        for j in range(1,k+1):
            new_i = i+j
            if new_i<=n-1:
                ans = min(ans , Solve(new_i)+abs(h[i]-h[new_i]))
            else:
                break
        return ans

    dp = [0]*n
    for i in reversed(range(n)):
        if i==n-1:
            dp[i] = 0
        else:
            ans = math.inf
            for j in range(1,k+1):
                new_i = i+j
                if new_i<=n-1:
                    ans = min(ans,dp[new_i]+abs(h[i]-h[new_i]))
                else:
                    break
            dp[i] = ans
    print(dp[0])

Frog2()

Measured memory_bytes: 85900
import java.util.Scanner;

public class Main {
	public static int N = 0;
	public static int magic = 0;
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		int a[] = new int[N];
		
		for(int i = 0;i < N;i++) {
			a[i] = scan.nextInt();
		}
	
		for(int i = 0;i < N - 1;i++) {
			int count = 1;
			while(a[i] == a[i+1]) {
				count++;
				i++;
				if(i == N - 1)break;
			}
			magic += count / 2;
		}
		
		scan.close();
		System.out.println(magic);
	}
}



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

/*

1:9
2:8*3+1*2
3:

1,2,3,4,5,6,7,8,9
00,01
10,11,12,
21,22,23
31,32,33
...
87,88,89
98,99

dp[桁数,最上位数]とすると，
dp[n][0] = dp[n-1][0]+dp[n-1][1]
dp[n][1] = dp[n-1][0]+dp[n-1][1]+dp[n-1][2]
...
dp[n][8] = dp[n-1][7]+dp[n-1][8]+dp[n-1][9]
dp[n][9] = dp[n-1][8]+dp[n-1][9]

dp_sum[n] = dp[n][1]+...+dp[n][9]
*/

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

	vector<vector<int>> dp(1000, vector<int>(10, 1));

	int K;
	scanf("%d", &K);

	int count = 9;  // 1桁
	if (count >= K) {
		printf("%d", K);
		return 0;
	}
	int i, j;
	for (i = 2; i < 1000; i++) {
		dp[i][0] = dp[i - 1][0] + dp[i - 1][1];

		for (j = 1; j <= 8; j++) {
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1];
			count += dp[i][j];
			if (count >= K) {
				goto finish;
			}
		}

		dp[i][9] = dp[i - 1][8] + dp[i - 1][9];
		count += dp[i][9];
		if (count >= K) {
			goto finish;
		}
	}

finish:
	// printf("result is in dp[%d][%d] because count = %d\n", i, j, count);
	// printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
	// printf("%d桁%d始まり の %d番目\n", i, j, K - (count - dp[i][j]));
	printf("%d", j);
	// printf("%d-1桁目\n", i);
	for (int ii = 0; ii < 9; ii++) {
		// printf("%d ", dp[i - 1][ii]);
	}
	// printf("\n");

	int n = K - (count - dp[i][j]);
	i--;
	for (; i >= 1; i--) {  // iは引き継ぐ
		int num = 0;
		for (auto k : {j - 1, j, j + 1}) {
			if (k == -1 || k == 10) {
				continue;
			}
			num += dp[i][k];
			if (num >= n) {
				printf("%d", k);
				// printf("%d桁%d始まり の %d番目\n", i, k, n - (num -
				// dp[i][k]));
				n = n - (num - dp[i][k]);
				j = k;
				break;
			}
		}
	}
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int cnt=0;
  int ans=0;
  
  for (int i=0;i<s.size(); i++){
    if (s.at(i)=='A'||s.at(i)=='T'||s.at(i)=='G'||s.at(i)=='C'){
      cnt++;
    }
    else{
      cnt = 0;
    }
    ans = max(ans,cnt);
  }
  
  cout << ans << endl;
}


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

int N, M, K;
vector<unordered_set<int>> friends;
vector<unordered_set<int>> enemies;
vector<unordered_set<int>> clusters;


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

    friends.resize(N);
    enemies.resize(N);
    clusters.resize(N);

    //friend
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        friends[a].insert(b);
        friends[b].insert(a);
    }

    //enemy
    for (int i = 0; i < K; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        enemies[a].insert(b);
        enemies[b].insert(a);
    }

    // bfs 
    unordered_set<int> searched;
    deque<int> bfs_q;
    int cluster_id = 0;
    vector<int> cluster_ids(N);

    for (int i = 0; i < N; ++i) {
        auto check_itr = searched.find(i);

        // bfs
        if (check_itr == searched.end()) {
            bfs_q.push_back(i);
            cluster_ids[i] = cluster_id;
            clusters[cluster_id].insert(i);

            while (!bfs_q.empty()) {
                int now = bfs_q.front();
                bfs_q.pop_front();

                for (auto itr = friends[now].begin(); itr != friends[now].end(); itr++) {
                    auto check_itr = searched.find(*itr);
                    if (check_itr == searched.end()){
                        bfs_q.push_back(*itr);
                        cluster_ids[*itr] = cluster_id;
                        clusters[cluster_id].insert(*itr);
                    }
                }
                searched.insert(now);
            }
            cluster_id++;
        }  
    }

    //ans
    for (int i = 0; i < N; ++i) {
        int base = clusters[cluster_ids[i]].size();
        int ans = base - (1 + friends[i].size());
        for (auto itr = enemies[i].begin(); itr != enemies[i].end(); itr++) {
            int enemy = *itr;
            if (cluster_ids[i] == cluster_ids[enemy]) ans--;
        }
        cout << ans << endl;
    }

    // debug clusters
    // for (int i = 0; i < cluster_id; i++){
    //     cout << "id:" << i << endl;
    //     for (auto itr = clusters[i].begin(); itr != clusters[i].end(); itr++){
    //         cout << *itr << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}

Measured memory_bytes: 46664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String t = sc.nextLine();
        int l = t.length();
        int k;
        if(l == 1){
            k = t.charAt(0) - '0';
        }else if(l == 3){
            k = 100;
        }else{
            k = (t.charAt(0) - '0') * 10 + t.charAt(1) - '0';
        }
        String s = sc.nextLine();
        int n = s.length();
        if(n <= k){
            System.out.println(s);
        }else{
            System.out.println(s.substring(0,k) + "...");
        }
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,K;
ll mo=1000000007;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	
	ll ret1=0,ret2=0;
	for(int t=1;t<=K;t++) {
		(ret1+=2LL*(t-1)*(K+1-t))%=mo;
		ret2+=K+1-t;
	}
	ret1=ret1*(1LL*H*W%mo)%mo*modpow(H+W)%mo*modpow(H+W-1)%mo;
	(ret1+=ret2+K)%=mo;
	
	for(i=H+W-K+1;i<=H+W;i++) ret1=ret1*i%mo;
	cout<<ret1<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define int long long

struct UnionFind{
    vector<int> tree;

    UnionFind(int n): tree(n+1, -1) {};

    int root(int i){ return tree[i] < 0 ? i : tree[i] = root(tree[i]); }

    bool unite(int i, int j){
        i = root(i), j = root(j);
        if(i == j) return false;
        tree[i] += tree[j], tree[j] = i;
        return true;
    }

    bool same(int i, int j){ return root(i) == root(j); }

    int size(int i){ return -tree[root(i)]; }
};

int a[100010], b[100010];
int c[100010], d[100010];

int cnt[100010] = {};

signed main(){

	int n, m, k;
	cin >> n >> m >> k;
	UnionFind uf(n);

	for(int i = 0;i < m;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		cnt[a[i]]--;
		cnt[b[i]]--;
		uf.unite(a[i], b[i]);
	}

	for(int i = 0;i < k;i++){
		cin >> c[i] >> d[i];
		c[i]--; d[i]--;
	}

	for(int i = 0;i < n;i++){
		cnt[i] += uf.size(i)-1;
	}

	for(int i = 0;i < k;i++){
		if(uf.same(c[i], d[i])){
			cnt[c[i]]--;
			cnt[d[i]]--;
		}
	}
	
	cout << cnt[0];

	for(int i = 1;i < n;i++){
		cout << " " << cnt[i];
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 5888
S=list(input())
l=len(S)
s=0
for i in range(l-1):
    if S[i]==S[i+1] and S[i]=='0':
        s+=1
        S[i+1]='1'
    elif S[i]==S[i+1] and S[i]=='1':
        s+=1
        S[i+1]='0'
print(s)

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    if(n>=10)
        cout<<k<<'\n';
    else
    {
        ll jia=100*(10-n);
        cout<<k+jia<<'\n';
    }









}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<u32>()[0];
    let mut sum: f64 = 0.0;
    let rate: f64 = 380000.0;

    for _ in 0..n{
        let line = read_as_string();
        let line: Vec<&str> = line.split_whitespace().collect();
        if line[1] == "JPY"{
            sum += line[0].parse::<f64>().unwrap();
        }else{
            sum += line[0].parse::<f64>().unwrap()*rate;
        }
    }
    println!("{}", sum);
}


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

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (2 * x < a * a * b) {
    double c;
    c = a * b * b / (2.0 * x);
    cout << fixed << setprecision(8) << 180 * atan(c) / 3.14159265358979 << endl;
  }
  else {
    double d;
    d = 2.0 * (a * a * b - x) / (a * a * a);
    cout << fixed << setprecision(8) << 180 * atan(d) / 3.14159265358979 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'

int32_t main()
{
	ninja
	int t; 
	int th,ts,ah,as;
	cin>>th>>ts>>ah>>as;
	bool f=1;
	while(true)
	{
		if(f){
			ah-=ts;
			if(ah<=0)
			{
				cout<<"Yes";
				break;
			}
			f=0;
		}
		else{
			th-=as;
			if(th<=0){
				cout<<"No";
				break;
			}
			f=1;
		}
	}
}



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

const int MAX = 3;
int main() {
	int num[MAX];
	for (int i = 0;i < MAX;i ++) cin >> num[i];
	sort(num, num+MAX);
	if (num[0] == 5 && num[1] == 5 && num[2] ==7) cout << "YES";
	else cout << "NO";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

575の並び替えパターンは3C2=3通りなので全部if文で見れば終わり
上のコードみたいにソートして比較しても良いけど無駄な操作ね
*/

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private void Process()
        {
            int a, b;
            string s;
            char[] o = new char[1] { ' ' };

            s = Console.ReadLine();
            while (s != "" && s != "\n" && s != "\r\n" && s != null)
            {
                a = int.Parse(s.Split(o, StringSplitOptions.RemoveEmptyEntries)[0]);
                b = int.Parse(s.Split(o, StringSplitOptions.RemoveEmptyEntries)[1]);

                Console.WriteLine("{0}", (a + b).ToString().Length);
                s = Console.ReadLine();
            }
        }
    }
}

Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<pii> X(n);
    rep(i, n) {
        int a;
        cin >> a;
        X[i] = {a, i + 1};
    }
    sort(all(X));
    rep(i, n) {
        cout << X[i].se << " \n"[i == n - 1];
    }
}

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


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

#define ll  long long
const int M=1e9+7;
int n,a,b;
ll iv[200001];


ll nck(int n,int k){
    ll ans=1;
    for(int i=1;i<=k;++i)
        ans =ans*(n-i+1)%M*iv[i]%M;
    return ans;
}

ll powM(ll b, int p){
    ll r=1;
    for(;p;b=b*b%M,p/=2)
       if(p&1) r=r*b%M;
    return r;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    ll ans=1;
    ans =powM(2,n);

    iv[1]=1;
    for(int i=2;i<=200000;i++){
        iv[i]= M-M/i*iv[M%i]%M;
    }

    cout<<(ans+2*M-nck(n,a)-nck(n,b)+M-1)%M<<endl;
        
    return 0;
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

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

const int N = 1000;

int a[N + 5], b[N + 5];
int n;

ll solve(){
	ll x = 1, y = 1;
	FOR(i,n){
		ll mx = max((x+a[i]-1) / a[i], (y + b[i]-1) / b[i]);
		x = mx * a[i], y = mx * b[i];
	}
	return x + y;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	FOR(i,n) cin >> a[i] >> b[i];
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++)
	{
		if(a*i%b==c)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
def profit(R, n):
    max_profit = R[1] - R[0]
    min_n = R[0]
    for i in range(1, n-1):
        if min_n > R[i]:
            min_n = R[i]
        if max_profit < R[i+1] - min_n:
            max_profit = R[i+1] - min_n
    return max_profit


def main():
    n = int(input())
    R = [int(input()) for i in range(n)]

    print(profit(R, n))


if __name__ == "__main__":
    main()



Measured memory_bytes: 13600
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MP(x,y) make_pair(x,y)
#define X first
#define Y second
#define all(x) x.begin(), x.end()

using namespace std;
using ll= long long ;


int main(void){
  string s, igx="";
  vector<int> index;
  int l,r;
  cin >> s;
  rep(i, s.size()){
    if(s[i] != 'x'){
      igx += s[i];
      index.push_back(i);
    }
  }

  bool flg = true;
  for(int i = 0; i < igx.size(); ++i){
    if(igx[i] != igx[igx.size()-i-1]){
      flg = false;
    }
  }

  if(!flg){
    cout << -1 << endl;
    return 0;
  }
  if(igx.size()==0){
    cout << 0 << endl;
    return 0;
  }

  int ans = 0;
  int cl, cr;
  cl = index[igx.size()/2]-1;
  cr = index[igx.size()/2]+1;
  if(igx.size()%2==0){
    cl = index[igx.size()/2-1]-1;
  }

  while(0 <= cl || cr < s.size()){
    if(cl >= 0 && cr < s.size() && s[cl] == 'x' && s[cr] == 'x'){
      cl--;cr++;
    }else if(s[cl] == 'x'){
      cl--;ans++;
    }else if(s[cr] == 'x'){
      cr++;ans++;
    }else if(s[cl] == s[cr]){
      cl--;cr++;
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1148
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
ll n, a[10010], b[10010], aa, bb, m;
int main() {
	cin >> n;
	rep(i, n)cin >> a[i], aa += a[i];
	rep(i, n)cin >> b[i], bb += b[i];
	m = bb - aa;
	if (m < 0) { cout << "No" << endl; exit(0); }
	aa = bb = 0;
	rep(i, n) {
		if (a[i] < b[i]) {
			if ((b[i] - a[i]) % 2 == 1)--m;
			aa += (b[i] - a[i]) / 2;
		}
		if (b[i] < a[i]) {
			bb += a[i] - b[i];
		}
	}
	if(aa<bb) { cout << "No" << endl; exit(0); }
	if(aa-bb==0&&aa==m) { cout << "Yes" << endl; exit(0); }
	aa -= bb;
	if(bb+2*aa==m) { cout << "Yes" << endl; exit(0); }
	cout << "No" << endl;
	return 0;
}

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

//var 
int h1,h2,m1,m2,k,h,m,t;

int main(){
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	h = (((h2 - h1) % 24) + 24)%24;
	m = (((m2 - m1) %60) + 60)%60;
	if(m1 > m2)h--; h+=24; h%=24;
	t = h*60 + m;
	cout << t-k << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    ll x,y;
    while(cin >> x >> y){
        ll ans = 0;
        while(x != y){
            if(abs(x) == abs(y)){
                ans++;
                x = y;
                continue;
            }
            if(abs(x) < abs(y)){
                if(x < 0){
                    ans++;
                    x *= -1;
                    continue;
                }
                ans += abs(y)-abs(x);
                x = abs(y);
                continue;
            }
            if(x < 0){
                ans += abs(abs(y)-abs(x));
                x = -abs(y);
                continue;
            }
            ans++;
            x *= -1;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin>>n;
  int arr[200006][3];
  int dp[200006][3] = {0};
  for(int i=0;i<n;i++){
    for(int j = 0;j<3;j++){
    cin>>arr[i][j];
    }
  }
  dp[0][0] = arr[0][0];
  dp[0][1] = arr[0][1];
  dp[0][2] = arr[0][2];
 // cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<"\n";
  for(int i = 1;i<n;i++){
    for(int j = 0; j<3;j++){
       if(j==0){
       //  cout<<dp[i-1][j+1]<<" "<<dp[i-1][j+2]<<" "<<arr[i][j]<<"\n";
        dp[i][j] = max(dp[i-1][j+1],dp[i-1][j+2]) + arr[i][j];
    }
      if(j==1){
          dp[i][j] = max(dp[i-1][j+1],dp[i-1][j-1]) + arr[i][j];
  }
        if(j==2){
          dp[i][j] = max(dp[i-1][j-2],dp[i-1][j-1]) + arr[i][j];
  }
     // cout<<dp[i][j]<<"\n";
    }
  }
  int ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  cout<<ans<<"\n";
 return 0; 
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll H, N, A;
    scanf("%lld %lld", &H, &N);
    ll Sum = 0;
    REP(int,i,0,N){
        scanf("%lld", &A);
        Sum += A;
    }
    if ( Sum >= H ){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
object Main {

  def main(args: Array[String]) {
    val source = scala.io.Source.stdin.getLines.toSeq

    source.map(_.toInt).filter(_ != 0).foreach { n =>
      val useCoins: List[Int] = coins.takeWhile(_ <= n).reverse.toList

      val result = pay_num(n, useCoins)

      println(result)
    }
  }


  lazy val coins: Stream[Int] = Stream.from(1).map(p => p * p)

  def pay_num(n: Int, useCoins: List[Int]): Int = {
    if (n == 0 || useCoins.size <= 1) {
      1
    } else {
      val x = useCoins.head
      (0 to n / x).fold(0) {(sum, i) => sum + pay_num(n - (i * x), useCoins.tail)}
    }
  }
}

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

a_div_max = int(a ** (1/2)) + 1
b_div_max = int(b ** (1/2)) + 1

a_divs = {1}
b_divs = {1}
for i in range(1, a_div_max):
	if a % i == 0:
		a_divs.add(i)
		a_divs.add(a // i)

for i in range(1, b_div_max):
	if b % i == 0:
		b_divs.add(i)
		b_divs.add(b // i)

divs = a_divs & b_divs

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			return False
	return True

res = len([d for d in divs if is_prime(d)]) + 1
print(res)


Measured memory_bytes: 5152
def main():
    import decimal
    A , B = map(decimal.Decimal, input().split())
    C = decimal.Decimal(A) * decimal.Decimal(B)
    #print(C)
    D = str(C)
    D = D.split(".")[0]
    #print(D)
    E = int(D)
    print(E)



if __name__ == '__main__':
    main()


Measured memory_bytes: 10012
//#include <algorithm>
//#include <cassert>
//#include <cfloat>
//#include <cmath>
//#include <cstdio>
//#include <cstdlib>
//#include <deque>
#include <iostream>
//#include <limits>
//#include <map>
//#include <queue>
//#include <set>
//#include <stack>
//#include <string>
//#include <tuple>
//#include <unordered_map>
//#include <unordered_set>
//#include <vector>
using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int a[100000];

long getTotal(int n, int dir) {
  long total{0}, sum{0};
  for (int i{0}; i < n; ++i) {
    sum += a[i];
    if (dir > 0 && sum <= 0) {
      total += -sum + 1;
      sum = 1;
    } else if (dir < 0 && sum >= 0) {
      total += sum + 1;
      sum = -1;
    }
    dir *= -1;
  }
  return total;
}

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

  long try1 = getTotal(n, 1);
  long try2 = getTotal(n, -1);

  cout << MIN(try1, try2) << "\n";
  return 0;
}


Measured memory_bytes: 768
n=int(input())
l=list(map(int,input().split()))
l2=sorted(l)
box=[0] #各長さの棒が何本あるか　最初の０は数合わせ
ans=0

num=1
while num<l2[0]: #最小の棒までは０をappend
    box.append(0)
    num+=1
    
now=l2[0]
bounum=1
for i in range(1,n):
    if l2[i]!=now:
        box.append(bounum)
        next=now+1
        while next<l2[i]:
            box.append(bounum)
            next+=1 
        now=l2[i]
        bounum+=1
    else:
        bounum+=1
if len(box)!=l2[-1]+1:
    box.append(bounum) #boxの完成

for i in range(n-2):
    for j in range(i+1,n-1):
        c=l2[i]+l2[j]-1
        if c>l2[-1]:
            c=l2[-1]
        add=box[c]-(j+1)
        if add<0:
            add=0
        ans+=add

print(ans)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
    int W , H , x , y , r , i = 0;
    cin >> W >> H >> x >> y >> r;
    if(y - r >= 0){
        if(y + r <= H){
            if(x + r <= W){
                if(x - r >= 0){
                    cout << "Yes"<<endl;
                    i = 1;


                }
            }
        }
    }
    if(i==0){
        cout << "No"<<endl;

    }
    return 0;

}


Measured memory_bytes: 3116
/*       Rohan Balot
    NSIT, New Delhi, India  */
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <unordered_set>
#include <unordered_map>
#include <ratio>

#include <cctype>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
using namespace std;
 
#define FIND(c, e) (c).find(e) != (c).end()
#define NFIND(c, e) (c).find(e) == (c).end()
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair

const int N = int( 1e5 ) + 1;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1.0);
const double eps = 1e-6;
template<typename T> T gcd(T a,T b){while (b){ T r=a%b;a=b;b=r;}return a;}
template<typename T> T lcm(T a,T b){return (a*b)/gcd(a,b);}

struct graph {
	int vertices;
	int edges;
	vector< vector<int> > adj;
	vector< bool > visited;
	vector< int > level;
	graph() { }
	graph(int vertices) {
		this->adj.resize(vertices + 1);
		this->level.resize(vertices + 1, -1);
		this->visited.resize(vertices + 1, false);
		this->vertices = vertices;
		edges = 0;
	}
	void add_directed_edge(int from, int to) {
		this->adj[from].emplace_back(to);
		this->edges++;
	}	
	void add_undirected_edge(int from, int to) {
		this->adj[from].emplace_back(to);
		this->adj[to].emplace_back(from);
		this->edges += 2;
	}
	void read_undirected_edges(int edge_count) {
		this->edges += edge_count << 1;
		for (int i = 0; i < edge_count; i++) {
			int from, to;
			cin >> from >> to;
			this->adj[from].emplace_back(to);
			this->adj[to].emplace_back(from);
		}
	}	
	void read_directed_edges(int edge_count) {
		this->edges += edge_count;
		for (int i = 0; i < edge_count; i++) {
			int from, to;
			cin >> from >> to;
			this->adj[from].emplace_back(to);
		}
	}
	void dfs(int src) {
		this->visited[src] = true;
		for(int i : this->adj[src]) {
			if(this->visited[i] == false) {
				this->dfs(i);
			}
		}
	}
	void bfs(int src) {
		this->level[src] = 0;
		queue<int> q;
		q.push(src);
		while (!q.empty()) {
			int cur = q.front();
			q.pop();
			for(int i : this->adj[cur]) {
				if(this->level[i] == -1) {
					this->level[i] = this->level[cur] + 1;
					q.push(i);
				}
			}
		}
	}
};

void __answer()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a ,a + 3);
	cout << a[0] + a[1] <<endl;

}  
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #ifdef LOCAL
        freopen("sample_input.txt", "r", stdin);
        // freopen("data.txt", "w", stdout);
        // freopen("log.txt", "w", stderr);
    #endif
    __answer();
    return 0;
}  

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

typedef long long ll;
using namespace std;
int memo[100001];
int calc(int ar[], int n, int k) {
	if(n==1) {
		return 0;
	}
	
	if(memo[n]!=-1) {
		return memo[n];
	}
	
	int mn = INT_MAX;
	for (int i=1; i<=k; i++) {
		if(n-i>=1) {
			int a = calc(ar, n-i, k) + abs(ar[n]-ar[n-i]);
			mn = min(mn, a);
		}
	}
	memo[n] = mn;
	return mn;
}

int main() {
 	int n,k;
 	cin>>n>>k;
 	int ar[100001];
 	int dp[100001];
 	for(int i=1; i<=n; i++) {
 		cin>>ar[i];
 		memo[i] = -1;
 		dp[i] = INT_MAX;
 	}
 
 	dp[1] = 0;
 	for (int i=2; i<=n; i++) {
 		for (int j=1; j<=k; j++) {
 			if(i-j>=1) {
 				dp[i] = min(dp[i], dp[i-j] + abs(ar[i]-ar[i-j]));
 			}
 		}
 	}
 	
 	cout << dp[n];
 	
 	//cout << calc(ar, n, k);
 	
	return 0;
}

Measured memory_bytes: 1408
s = input()
q = int(input())

reverse = 0
sento = ''
matsubi = ''

for i in range(q):
    inp = input()
    if len(inp) <= 1:
        reverse += 1
    else:
        dmy, f, c = inp.split()
        f = int(f)
        if reverse & 1:
            if f == 1:
                matsubi = matsubi + c
            else:
                sento = c + sento
        else:
            if f == 1:
                sento = c + sento
            else:
                matsubi = matsubi + c

s = sento + s + matsubi

if reverse & 1:
    print(s[::-1])
else:
    print(s)



Measured memory_bytes: 4700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	ll N, flag=0, ans = 1;

	cin >> N;
	vector<ll> a(N);

	rep(i, N) cin >> a[i];

	rep(i, N){
		
		if (a[i]<=(ll)1000000000000000000/ans) {
			ans *= a[i];
		}
		else{
			flag = 1;
		}
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	if (flag == 1) cout << -1 << endl;
	if (flag == 0) cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3964
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::string S; std::cin >> S;
  for (char c : S) {
    if (c + N > 'Z') c = c + N - 26;
    else             c += N;
    std::cout << c;
  }
  std::cout << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    int ans = 0;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
    cin >>d[i];
    	for(int j = 0; j < N; j++){
          if(i != j) {
        ans+=d[i]*d[j];
          }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#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)

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B){
    if(A*B*1 % 2 == 1){
        cout << YES << endl;
    } else     if(A*B*2 % 2 == 1){
        cout << YES << endl;
    } else     if(A*B*3 % 2 == 1){
        cout << YES << endl;
    } else{
        cout << NO << endl;
    }


}

int main(){

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}



Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    ll n;
    cin>>n;
    vector<ll> vec(n+1, 2);
    for(ll i = 2; i*i <= n; i++)
        for(ll j = i*i; j <= n; j += i)
            if(i != j/i)
                vec[j] += 2;
            else
                vec[j] += 1;

    ll ans= 1;
    // cout<<vec[4];
    for(int i = 2; i <= n; i++)
        ans += i*vec[i];
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

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

int main() {
  int N;
  
  cin >> N;
  
  vector<int> vec(4);
  
  for(int i = 0; i < N;i++){
    string a;
    cin >> a;
    if(a=="AC") vec.at(0)++;
    else if(a=="WA") vec.at(1)++;
    else if(a=="TLE") vec.at(2)++;
    else vec.at(3)++;
  }
  cout << "AC x " << vec.at(0) << endl;
  cout << "WA x " << vec.at(1) << endl;
  cout << "TLE x " << vec.at(2) << endl;
  cout << "RE x " << vec.at(3);
    
}



Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 400005;
const int mod = 1000000007;

void gcd(ll a,ll b, ll& d,ll& x,ll& y){  //      已经测试 FZU 1402
  if(!b) {d=a;x=1;y=0;}
  else   {	gcd(b,a%b,d,y,x);	y-=a/b*x;}
}

ll inv(ll a,ll n)  { //无逆元返回-1
  ll d,x,y;	gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}
ll p[maxn];

ll solve(int n, int m) {
  return p[n] * inv(p[m]*p[n-m]%mod, mod)%mod;
}

ll solve2(int n, int m){
  if (n==0)return 1;
  return p[n+m-1] * inv(p[m-1]*p[n]%mod, mod)%mod;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  p[0] = 1;
  for(int i=1;i<maxn;i++)p[i] = p[i-1] *i %mod;
  ll ret = 0;
  int n, m;
  cin>>n>>m;
  for(int i=0;i<n&&i<=m;i++){
    ret = (ret + solve(n,i)*solve2(i, n-i))%mod;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    fastio;
    vector<bool > is_prime(MAXN,true);
    ll x;
    cin>>x;
    for(ll i=2;i<MAXN;i++){
        if(is_prime[i] && i*i<MAXN){
            for(ll j=i*i;j<MAXN;j+=i) is_prime[j]=false;
        }
    }
    for(int i=x;i<MAXN;i++){
        if(is_prime[i]){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 36

typedef struct{
  char paint;
  int number;
}card;                                                                   ;
 
void Bubblesort(card *);
void Selectionsort(card *);
int isStable(card *,card *);

int a;

int main()
{
  int i;
  card trump[N],trump1[N],trump2[N];
  
  scanf("%d",&a);
  for(i = 0;i < a;i++){
    scanf(" %c%d",&trump[i].paint,&trump[i].number);
    trump1[i] = trump[i];
    trump2[i] = trump[i];
  }
  
  Bubblesort(trump);
  if(isStable(trump2,trump) == 1) printf("Stable\n");
  else printf("Not stable\n");
  
  Selectionsort(trump1);
  if(isStable(trump2,trump1) == 1) printf("Stable\n");
  else printf("Not stable\n");
  
  return 0;
}

void Bubblesort(card *trump)
{
  int i,j;
  card tmp;
  
  for(i = 0;i < a;i++){
    for(j = a-1;j > i;j--){
      if(trump[j].number < trump[j-1].number){
	tmp = trump[j];
	trump[j] = trump[j-1];
	trump[j-1] = tmp;
      }
    }
  }
  for(i = 0;i < a-1;i++){
    printf("%c%d ",trump[i].paint,trump[i].number);
  }
  printf("%c%d\n",trump[a-1].paint,trump[a-1].number);
}

void Selectionsort(card *trump)
{
  int i,j,minj;
  card tmp;
  
  for(i = 0;i < a;i++){
    minj = i;
    for(j = i;j < a;j++){
      if(trump[j].number < trump[minj].number){
	minj = j;
      }
    }
    tmp = trump[i];
    trump[i] = trump[minj];
    trump[minj] = tmp;
  }
  
  for(i = 0;i < a-1;i++){
    printf("%c%d ",trump[i].paint,trump[i].number);
  }
  printf("%c%d\n",trump[a-1].paint,trump[a-1].number);
}

int isStable(card *trump,card *trump1)
{
  int i,j,x,y,num = 1;

  for(i = 0;i < a;i++){
    for(j = i+1;j < a;j++){
      for(x = 0;x < a;x++){
	for(y = x+1;y < a;y++){
	  if(trump[i].number == trump[j].number && trump[i].number == trump1[y].number && trump[j].number == trump1[x].number && trump[i].paint == trump1[y].paint && trump[j].paint == trump1[x].paint){
	    num = 0;
	    break;
	  } 
	}
      }
    }
  }

  return num;
}

Measured memory_bytes: 608
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 105, K = (int)1e5 + 10;
bool dp[K];
int n, k, ar[N];

void solve () {
   for (int i = 0; i <= k; ++i) dp[i] = false;
   for (int i = 1; i <= n; ++i) dp[ar[i]] = true;

   for (int i = 0; i <= k; ++i) {
      for (int j = 1; j <= n; ++j) {
         if (i + ar[j] <= k) dp[i+ar[j]] |= (!dp[i]);
      }
   }

   cout << (dp[k] ? "First\n" : "Second\n");
}

signed main() {
   IOS; PREC;
   cin >> n >> k;

   for (int i = 1; i <= n; ++i) cin >> ar[i];
   solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 384
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int[] a = na(1 << n);

    // dp[s][0/1]
    // s=01101 > (iorj)
    int[][] dp = new int[1 << n][2];
    for (int k = 0; k < (1 << n); k++) {
      dp[k][0] = a[k];
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < (1 << n); j++) {
        if ((j & (1 << i)) != 0) {
          add(dp[j], dp[j ^ (1 << i)]);
        }
      }
    }
    
    int now = 0;
    for (int j = 1; j < (1 << n); j++) {
      now = Math.max(now, dp[j][0] + dp[j][1]);
      out.println(now);
    }
  }
  
  //a+=b
  private static void add(int[] a, int[] b) {
    int[] x = {a[0], a[1], b[0], b[1]};
    Arrays.sort(x);
    a[0] = x[3];
    a[1] = x[2];
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 97888
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    long a[n], lf = 0, ls = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    reverse(a, a+n);
    for(int i = 0; i < n; i++){
        if(lf == 0 && a[i] == a[i+1]){
            lf = a[i];
            i++;
        } else if(lf != 0 && a[i] == a[i+1]){
            ls = a[i];
            break;
        }
    }
    cout << lf*ls << endl;
}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define VCIN(x) for(auto&youso:(x))cin >> (youso)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
V<int> vec;
bool check(int a){
    string str = to_string(a);
    FOREACH(b,str){
        FOREACH(c,vec){
            if(b-'0'==c){
                return false;
            }
        }
    }
    return true;
}
int main(){
    CIN(N);CIN(K);
    REP(a,K){
        CIN(b);
        vec.pb(b);
    }
    FOR(a,N,1000000){
        if(check(a)){
            COUT(a);
            return 0;
        }
    }
    return 0;
}


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

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int H,W,K;
    cin >> H >> W >> K;
    ll ans = 0;
    vector<vector<char>> c(H,vector<char> (W));
    rep(i,H) rep(j,W) cin >> c[i][j];

    int n = H + W;

    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> Sh,Sw;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                if(i < H){
                    Sh.push_back(i);
                }else{
                    Sw.push_back(i-H);
                }
            }
        }
        int nowh,noww;
        nowh = noww = 0;
        int cnt = 0;
        int hsize = Sh.size();
        int wsize = Sw.size();
        /*
        rep(j,hsize){
            cout << Sh[j];
        }
        cout << "|";
        rep(j,wsize){
            cout << Sw[j];
        }
        cout << endl;
        */
        rep(j,H){
            if(nowh < hsize && Sh[nowh] == j){
                nowh++;
                continue;
            }
            noww = 0;
            rep(k,W){
                if(noww < wsize && Sw[noww] == k){
                    noww++;
                    continue;
                }
                if(c[j][k] == '#') cnt++;
            }
        }
        if(cnt == K){
            ans++;
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn main() {
    let v: Vec<u64> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (a, p) = (v[0], v[1]);
    
    println!("{}", (a * 3 + p) / 2);
}


Measured memory_bytes: 4352