akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	string s;
	cin >>s ;
	s.at(3) = '8';
	cout <<s<< endl;
}


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

using namespace std;

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

int main() {

	string s;

	cin >> s;

	if(s == "zyxwvutsrqponmlkjihgfedcba")
		puts("-1");
	else if(s.size() < 26) {
		char c = 'a';
		while(find(s.begin(), s.end(), c) != s.end())
			c++;
		printf("%s%c\n", s.c_str(), c);
	}
	else {
		int mask = 0;
		for(int i = 0; i < 26; i++)
			mask |= 1 << (s[i] - 'a');
		for(int i = 25; i >= 0; i--) {
			mask ^= 1 << (s[i] - 'a');
			int c = -1;
			for(int j = s[i] - 'a' + 1; j < 26 and c == -1; j++)
				if(!(mask & (1 << j)))
					c = j + 'a';
			if(c != -1) {
				for(int j = 0; j < i; j++)
					putchar(s[j]);
				putchar(c);
				puts("");
				return 0;
			}
		}
	}

    return 0;

}



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

#define F                   first
#define S                   second
#define int                 long long int
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define mod                 1000000007
#define endl                '\n'
#define rep(i,a,b)            for(int i=a;i<b;i++)
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void solve() {
    double n;
    cin >> n;

    if (n == 1.0) {
        cout << 0 << endl;
    }
    else if (n == 0.0) {
        cout << 1 << endl;
    }
}
int32_t main()
{
    c_p_c();
    solve();


    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int n, r_0=0, r_1=0, w_0=0, w_1=0;
    cin >> n;
    char m;
    vector<bool> data(n);
    REP(i, n) {
        cin >> m;
        if(m=='R') {
            data.at(i) = true;
            r_0++;
        } else {
            data.at(i) = false;
            w_0++;
        }
    }
    REP(i, r_0) if(data.at(i)==false) w_1++;
    reverse(ALL(data));
    REP(i, w_0) if(data.at(i)==true) r_1++;
    cout << max(r_1, w_1) << endl;
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(void)
{
    int N;
    cin >> N;
    for(int i = 0;i<N;i++){
        int a;
        cin >> a;
        if((a%2) ==0)
        {
            if((a%3)!=0 && (a%5)!=0)
            {
                cout << "DENIED" << endl;
                exit(0);
            }
        }
    }
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int M, D;

int main() {
    cin >> M >> D;

    int ans = 0;
    for (int m = 1; m <= M; m++) {
        for (int d = 1; d <= D; d++) {
            int d1 = d % 10;
            int d10 = floor(d / 10);
            if (d1 >= 2 && d10 >= 2 && d1 * d10 == m)
                ans++;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def sharpimage(h , w , a):

    reans = []
    aa = ""

    for i in range(w + 2):
        aa += "#"

 #   for i in range(h):
    for i in a:
        reans.append("#" + i + "#")

    reans.insert(0 , aa)
    reans.append(aa)

    return reans

def main():
    h , w = map(int, input().split())
    a=[str(input()) for i in range(h)]

    ans = sharpimage(h , w , a)
    for i in range(len(ans)):
        print(ans[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(s.equals("AAA") || s.equals("BBB")){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
	string s[100], res="";
	int n,l;
	cin >> n >> l;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	sort(s, s + n);

	for (int i = 0; i < n; ++i) {
		res += s[i];
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
N, M, X = map(int,input().split())
CA = [list(map(int,input().split())) for i in range(N)]

cost = []

for i in range(2 ** N):
  one = str(bin(i)).count('1')
  ca_list = [0] * M
  c = 0
  for j in range(N):
    if ((i >> j) & 1):
      c += CA[j][0]
      for k in range(M):
        ca_list[k] += CA[j][k+1]
  if min(ca_list) >= X:
    cost.append(c)

if cost:
  print(min(cost))
else:
  print(-1)
    

Measured memory_bytes: 9212
#include<stdio.h>

int main(void)
{
  int N;
  scanf("%d",&N);
  if(N==1||N==2||N==3||N==4||N==5||N==6||N==7||N==8||N==9||N==10||N==12||N==14||N==16||N==18||N==15||N==21||N==24||N==27||N==20||N==28||N==32||N==36||N==25||N==30||N==35||N==40||N==45||N==42||N==48||N==54||N==49||N==56||N==63||N==64||N==72||N==81){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;
int main(){
    int x;
        for (int i=1; 1; i++) {
            cin >> x;
       if (x == 0) break;
            cout << "Case" << " " << i << ":" << " " << x <<endl;
    }
}
    
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

void dfs(int i,int last,vec<vec<int>> &tree,vec<int> &ans,map<p,int> &edge){
    int dont=-1;
    if(last!=-1)dont=ans[max(edge[p(i,last)],edge[p(last,i)])-1];
    int j=0;
    for(auto v:tree[i]){
        if(v==last)continue;
        if(j==dont)j++;
        ans[max(edge[p(i,v)],edge[p(i,v)])-1]=j;
        dfs(v,i,tree,ans,edge);
        j++;
    }
    return;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vec<vec<int>> tree(n);
    map<p,int> edge;
    rep(i,n-1){
        int a,b;cin >> a >> b;
        a--;b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
        edge[p(a,b)]=i+1;
//最後に答えのvecに追加するときp(b,a)との大きい方を取って-1すればよくなる
    }
    int k=0;
    rep(i,n)k=max(k,(int)tree[i].size());
    cout << k << endl;
    vec<int> ans(n-1);
    dfs(0,-1,tree,ans,edge);
    rep(i,n-1)cout << ans[i]+1 << endl;
}

Measured memory_bytes: 24724
k = int(input())
"""
15:23
10000:3234566667
"""
from collections import deque
lun=deque([1,2,3,4,5,6,7,8,9])
x=0
for i in range(k):
  x = lun.popleft()
  if x % 10 != 0:
    lun.append((10 * x) + (x % 10) - 1)
  lun.append((10 * x) + (x % 10)) 
  if x % 10 != 9:
    lun.append((10 * x) + (x % 10) + 1)
print(x)


Measured memory_bytes: 11908
#include<iostream>

using namespace std;
#define int long long
int memo[51][51][51*51];

signed main(){

   int N, A;
   cin>> N>> A;
   int x[N];
   for(int i=0; i<N; i++) cin>> x[i];

   memo[0][0][0]=1;
   for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
         for(int k=0; k+x[i]<51*51; k++){
            memo[i+1][j][k]+=memo[i][j][k];
            memo[i+1][j+1][k+x[i]]+=memo[i][j][k];
         }
      }
   }

   int r=0;
   for(int j=1; j<=N&&A*j<51*51; j++){
      r+=memo[N][j][A*j];
   }
   cout<< r<< endl;

   return 0;
}


Measured memory_bytes: 52096
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	
	printf("%d\n", std::min(n * a, b));
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			String tmp = sc.nextLine();
			String[] str = new String[h];
			boolean[] isWhiteH = new boolean[h];
			boolean[] isWhiteW = new boolean[w];
			for (int j = 0; j < w; j++) {
				isWhiteW[j] = true;
			}
			for (int i = 0; i < h; i++) {
				str[i] = sc.nextLine();
				if (str[i].indexOf('#') == -1) {
					isWhiteH[i] = true;
				} else {
					isWhiteH[i] = false;
				}
				for (int j = 0; j < w; j++) {
					if(str[i].charAt(j) == '#') {
						isWhiteW[j] = false;
					}
				}
			}

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (!isWhiteH[i] && !isWhiteW[j]) {
						System.out.print(String.valueOf(str[i].charAt(j)));
					}
				}
				if (!isWhiteH[i])
					System.out.println();
			}
		}
	}
}


Measured memory_bytes: 23632
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string S, T;    
    cin >> S;
    cin >> T;

    const size_t len = S.size();
    const char *s = S.c_str();
    const char *t = T.c_str();

    size_t n = 0;
    for(size_t i = 0; i < len; ++i)
    {
        if(s[i] != t[i])
        {
            ++n;    
        }
    }

    cout << n << endl;

    return 0;    
}

Measured memory_bytes: 3856
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var n = s.Length + 1;
            var ai = new long[n];

            for (var i = 0; i < s.Length; i++)
            {
                if (s[i] == '<') ai[i + 1] = Math.Max(ai[i + 1], ai[i] + 1);
            }
            for (var i = s.Length - 1; i >= 0; i--)
            {
                if (s[i] == '>') ai[i] = Math.Max(ai[i], ai[i + 1] + 1);
            }
            Console.WriteLine(ai.Sum());
        }
    }
}


Measured memory_bytes: 16864
n = gets.chomp.to_i
s1 = gets.chomp
s2 = gets.chomp

MOD = 10**9 + 7
ans = 1
left = ""
right = ""
i = 0
loop do
  break if i >= n
  if i == 0
    if s1[i] == s2[i]
      ans *= 3
      left = "A"
      i += 1
    else
      ans *= 6
      left = "B"
      i += 2
    end
  else
    if s1[i] == s2[i]
      right = "A"
      i += 1
    else
      right = "B"
      i += 2
    end
    case left + right
    when "AA"
      ans *= 2
    when "AB"
      ans *= 2
    when "BA"
      ans *= 1
    when "BB"
      ans *= 3
    end
    ans %= MOD
    left = right
  end
end
puts ans % MOD

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

constexpr int INF = 1e9;

pair<vector<int>, bool> bellmanFord(int start,int V,const vector<tuple<int, int, int>>& edges) {
    vector<int> dist(V, INF);
    bool negativeLoop = false;
    dist[start] = 0;
    for (int i = 0; i < V; i++) {
        for (const auto& e: edges){
            int from, to, cost;
            tie(from, to, cost) = e;
            if (dist[from] < INF && dist[to] > dist[from] + cost) {
                dist[to] = dist[from] + cost;
                if (i == V - 1) {
                    return {dist, true};
                }
            }
        }
    }
    return {dist, false};
}

void dfs(int from, vector<bool>& v, vector<pair<int, int>>* g) {
    if (v[from]) return;
    v[from] = true;
    for (auto& e : g[from]) {
        dfs(e.second, v, g);
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, M, P;
    cin >> N >> M >> P;
    vector<pair<int, int>> g1[N];
    vector<pair<int, int>> g2[N];

    for (int i = 0; i < M; i++) {
        int from, to, cost;
        cin >> from >> to >> cost;
        from--; to--;
        (cost -= P) *= -1;
        g1[from].push_back(pair<int, int>(cost, to));
        g2[to].push_back(pair<int, int>(cost, from));
    }
    vector<bool> reachableFrom1(N, false);
    vector<bool> reachableFromN(N, false);
    dfs(0, reachableFrom1, g1);
    dfs(N - 1, reachableFromN, g2);

    vector<tuple<int, int, int>> G;
    for (int from = 0; from < N; from++) {
        for (auto& p : g1[from]) {
            bool useFrom = reachableFrom1[from] && reachableFromN[from];
            bool useTo = reachableFrom1[p.second] && reachableFromN[p.second];
            bool useEdge = useFrom && useTo;
            G.push_back(tie(from, p.second, (useEdge ? p.first : INF)));
        }
    }

    vector<int> d; bool loop;
    tie(d, loop) = bellmanFord(0, N, G);
    if (loop) {
        cout << -1 << endl;
        return 0;
    }
    cout << max(0, -d[N - 1]) << endl;
    return 0;
}


Measured memory_bytes: 768
n, k = map(int, input().split())
mod = 10**9+7

fact = [0] * (n+1)
inv = [0] * (n+1)

fact[0], fact[1] = 1, 1
inv[0], inv[1] = 1, 1

for i in range(2,n+1):
	fact[i] = (fact[i-1] * i) % mod
for i in range(2,n+1):
	inv[i] = (inv[i-1] * pow(i, mod-2, mod)) % mod

if k >= n:
	k = n-1

def C(a,b):
	out = fact[a]
	out *= inv[b]
	out %= mod
	out *= inv[a-b]
	out %= mod
	return out

ans = 0
for m in range(k+1):
	ans += (C(n,m) * C(n-1,n-m-1)) % mod
	ans %= mod

print(ans)
	

Measured memory_bytes: 42864
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
int b[maxn];
int main(){
	int n, m;
	cin >> m >> n;
	for(int i = 1 ; i <= n ; i++)cin >> a[i];
	b[1] = a[1] + m - a[n];
	for(int i = 2 ; i <= n ; i++)b[i] = a[i] - a[i - 1];
	sort(b + 1,b + 1 + n);
	cout << m - b[n] << endl;

}

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

int main() {
  int a,b;cin>>a>>b;
  if(a%3==0||b%3==0||(a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in(x) int x; cin>>x;
#define inn(x, y) int x, y; cin>>x>>y;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int32_t main(void){
	IOS;
	in(n);
	int ans = 0;
	int x = 100;
	while(true)
	{
		x += (x/100);
		ans += 1;
		if(x >= n) break;
	}
	cout<<ans;
}

Measured memory_bytes: 3636
# https://atcoder.jp/contests/agc033/tasks/agc033_a

from collections import deque
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
move = [(1, 0), (-1, 0), (0, 1), (0, -1)]     # 動ける場所の候補


def debug(start, goal, p, t):
    player = p
    debug_grid = list(list(grid[h]) for h in range(H))
    if start != (None, None):
        debug_grid[start[0]][start[1]] = "S"
    if goal != (None, None):
        debug_grid[goal[0]][goal[1]] = "G"
    debug_grid[player[0]][player[1]] = "P"
    print("~~~~~~~~~ t = " + str(t+1) + "  ~~~~~~~~")
    for debug_h in range(H):
        print("".join(str(debug_grid[debug_h][debug_w]) for debug_w in range(W)))


def bfs(grid, next_set, goal, visit):
    visit[start[0]][start[1]] = 1               # スタート地点はすでに訪れている
    while next_set:                             # p = [] になったら止める
        p, t = next_set.popleft()               # 要素を消去して、消去した要素を出力
        h, w = p
        for dh, dw in move:                     # 頂点 p から進める経路の候補から一つ選ぶ
            q = (h + dh, w + dw)
            if q[0] < 0 or q[0] >= H or q[1] < 0 or q[1] >= W:
                continue
            if grid[q[0]][q[1]] == wall:         # 壁があったら進まない
                continue
            if visit[q[0]][q[1]] == 1:           # 一度訪れていた場合は進まない
                continue
            #### (debug code) ######
            # debug(start, goal, q, t)
            ########################
            if q == goal:                       # ゴールがあるならば、ここで判定
                return t + 1                    # 経路の長さは t + 1 で与えられる
            visit[q[0]][q[1]] = 1               # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある)
            next_set.append((q, t + 1))         # p から q へと移動。時刻を 1 進める
    return t


road, wall = ".", "#"                         # (進行可能を意味する記号, 進行不可を意味する記号)

H,W = map(int,input().split())                # 左上は(h,w)=(0,0)、右下は(h,w)=(H-1,W-1)

grid = []
next_set = deque()
visit = [[0]*W for _ in range(H)]
for h in range(H):
    grid.append(input())
    for w, a in enumerate(grid[-1]):
        if a == "#":
            start = (h, w)
            next_set.append((start,0))
            visit[start[0]][start[1]] = 1

print(bfs(grid, next_set, (None,None), visit))

Measured memory_bytes: 149464
N = int(input())
xmin = ymin = float('inf')
xmax = ymax = 0
p = []
for i in range(N):
    x,y = map(int, input().split())
    if x > y : 
        x,y= y,x
    p.append((x, y))
    if x < xmin:
        xmin = x
    elif x > xmax:
        xmax = x
    if y < ymin:
        ymin = y
    elif y > ymax:
        ymax = y
ret = (ymax-ymin) * (xmax-xmin)


p.sort()
dx = p[-1][0] - p[0][0]
ymin = p[0][0]
tymin = float('inf')
for i in range(N-1):
    # print(i, dx, (xmax, xmin), end=' ==> ')
    tymin = min(tymin, p[i][1])
    xmax = max(xmax, p[i][1])
    xmin = min(tymin, p[i+1][0])
    dx = min(dx, xmax - xmin)
    if tymin < p[i+1][0]:
        break
    # print(i, dx, (xmax, xmin))

print(min(ret, (ymax-ymin) * dx))




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

int main()
{
  char a, b;
  cin >> a >> b;
  
  if(a == 'H')
  {
    cout << b << endl;
  }
  else
  {
    if(b == 'H')
      cout << 'D' << endl;
    else
      cout << 'H' << endl;
  }
}

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

int main(){
  int N, a, b, c;
  cin >> N >> a >> b >> c;
  map<char,int> M;
  M['A'] = a;
  M['B'] = b;
  M['C'] = c;
  vector<string> S(N);
  for(int i = 0; i < N; ++i){
    cin >> S[i];
  }
  vector<char> ans;
  for(int i = 0; i < N; ++i){
    string s = S[i];
    char l = s[0], r = s[1];
    if(M[l] == 0 and M[r] == 0){
      puts("No");
      return 0;
    }
    if(M[l] == 1 and M[r] == 1){
      if(i+1 < N){
        if(count(S[i+1].begin(), S[i+1].end(),l)) ++M[l],--M[r],ans.push_back(l);
        else if(count(S[i+1].begin(), S[i+1].end(),r)) ++M[r],--M[l],ans.push_back(r);
        else ++M[l],--M[r],ans.push_back(l);
      }else
        ++M[l],--M[r],ans.push_back(l);
    }else{
      if(M[l] >= M[r]){
        ++M[r],--M[l],ans.push_back(r);
      }else{
        ++M[l],--M[r],ans.push_back(l);
      }
    }
  }
  puts("Yes");
  for(auto e : ans)
    cout << e << "\n";
}


Measured memory_bytes: 6732
#include<stdio.h>
#include<stdlib.h>

int main()
{
 char a;
 char b;
 char ans;
 scanf("%c %c",&a, &b);
 if((a=='H')&&(b=='H')) printf("H");
 if((a=='H')&&(b=='D')) printf("D");
 if((a=='D')&&(b=='H')) printf("D");
 if((a=='D')&&(b=='D')) printf("H");
 return 0;
}


Measured memory_bytes: 128
n =int(input())
x = list(map(int,input().split()))
MOD = 10**9+7
f =[0,1]  
g =[0,1] 
c = 0
ans = 0
for j in range(1,n+1):
    f.append((f[-1]*j)%MOD)
    g.append((g[-1]*(n-j))%MOD)

for i in range(1,n):
    c = (c*i + f[i])%MOD
    ans = (ans+c*(x[i]-x[i-1])*g[n-i])%MOD
print(ans)

Measured memory_bytes: 16044
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll oo = 1e18;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, ans=0;
    cin >> a >> b;

    while (a){
        a/=b;
        ans++;
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	int n;
	cin >> n;
	cout << n * n;
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using ll = long long;
ll n;
ll p;
std::vector<ll> vec;

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> p;
        vec.push_back(p);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = 0; k < n; k++) {
            ll w = std::abs(vec[i]-vec[k]);
            if (w > ans) {
                ans = w;
            }
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/dp/tasks/dp_u

//参考：https://www.hamayanhamayan.com/entry/2019/01/12/151211

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL a[16][16];
 
LL ans = 0;

void solve(){
	//dp[bit] := グループが決まったうさぎがbitである場合の点数の最大値
	vector<LL> dp(1<<N,0);
	//cst[bit] := bitの立ったうさぎを全部同じグループに入れたときの点数
	vector<LL> cst(1<<N,0);

    for(int bit=0;bit<(1<<N);bit++){
        for(int i=0;i<N;i++){//i番目のウサギを見ていく
        	for(int j=i+1;j<N;j++){//i+1~N-1番目のウサギを見る
        		//bitのうちi,jビット目が両方1なら同じグループに入っているとみなし、
        		//cst[bit]に対応するスコアを格納

        		//例えばbit=01001なら1番目と4番目のウサギを見ることを表し、
        		//cst[01001] = a[1][4]となる
        		//cst[01011] = a[1][3] + a[1][4] + a[3][4]となる
        		if((bit&(1<<i)) && (bit&(1<<j))) cst[bit] += a[i][j];
        	}
        }
    }
 
    for(int bit=0;bit<(1<<N);bit++){
    	//sub_bitはbitの部分集合
    	//forでbitの部分集合を0を除いて全て列挙
    	//例えばbit=110なら110,100,010の3つを調べる

    	//0~bitに収まる全てのビット列はそれぞれ、bitとandをとると
    	//bitの部分集合を全部列挙できる
        for(int sub_bit=bit;sub_bit>0;sub_bit=(sub_bit-1)&bit){
        	//dp[bit] = dp[bit - sub_bit] + cst[sub_bit]
        	//とは、すでにbit-sub_bitで表されるウサギについて
        	//グループ分けが決まっている時、sub_bitで表されるウサギを
        	//新たに1グループ作って全部それに入れることを表す
            dp[bit] = max(dp[bit],dp[bit - sub_bit] + cst[sub_bit]);
        }
    }
 
    ans = dp[(1<<N)-1];
}

int main(){
    cin >> N;
    for(int h=0;h<N;h++){
    	for(int w=0;w<N;w++) cin >> a[h][w];
    }
 
    solve();

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {
	string s, t, x = "";
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	for (int i = t.size() - 1; i >= 0; i--) {
		x += t[i];
	}
	if (s < x)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
def input():
	return sys.stdin.buffer.readline()[:-1]

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

dp = [1 for _ in range(n)]
def dfs1(x, p):
	for c in adj[x]:
		if c == p:
			continue
		dfs1(c, x)
		dp[x] *= dp[c]+1
		dp[x] %= m
	return

dfs1(0, -1)
ans = [0 for _ in range(n)]
ans[0] = dp[0]
def dfs2(x, p):
	l = len(adj[x])
	cuml = [1 for _ in range(l+2)]
	cumr = [1 for _ in range(l+2)]
	for i in range(l):
		cuml[i+1] = (cuml[i] * (dp[adj[x][i]] + 1)) % m
	for i in range(l-1, -1, -1):
		cumr[i+1] = (cumr[i+2] * (dp[adj[x][i]] + 1)) % m
	pres_x = dp[x]
	for i, c in enumerate(adj[x]):
		if c == p:
			continue
		pres_c = dp[c]
		dp[x] = (cuml[i] * cumr[i+2]) % m
		dp[c] *= dp[x] + 1
		dp[c] %= m
		ans[c] = dp[c]
		dfs2(c, x)
		dp[x] = pres_x
		dp[c] = pres_c
	return

dfs2(0, -1)
print(*ans, sep="\n")

Measured memory_bytes: 132012
using System;
using System.Linq;
#if !DEBUG
    using System.IO;
#endif

public class Program {
    public static void Main() {
        #region SetAutoFlushIsFalse
#if !DEBUG
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
#endif
        #endregion
        var s = Console.ReadLine();
        var first = int.Parse(new string(s.Take(2).ToArray()));
        var second = int.Parse(new string(s.Skip(2).ToArray()));

        string msg;
        if (canMonth(first) && canMonth(second)) {
            msg = "AMBIGUOUS";
        } else if (canMonth(first)) {
            msg = "MMYY";
        } else if (canMonth(second)) {
            msg = "YYMM";
        } else {
            msg = "NA";
        }

        Console.WriteLine(msg);
        #region Flush
#if !DEBUG
        Console.Out.Flush();
        sw.Close();
#endif
        #endregion

    }

    private static bool canMonth(int s) {
        return 1 <= s && s <= 12;
    }
}

static class ReadLib {
    public static long ReadAsLong() {
        return long.Parse(Console.ReadLine());
    }

    public static int ReadAsInt() {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadAsIntArray() {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    public static long[] ReadAsLongArray() {
        return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    public static ulong[] ReadAsULongArray() {
        return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
    }

    public static string[] ReadAsStringArray() {
        return Console.ReadLine().Split(' ');
    }

    public static int[] ReadNTimesAsInt(int n) {
        return Enumerable.Range(1, n).Select(s => int.Parse(Console.ReadLine())).ToArray();
    }

    public static int[][] ReadNTimesAsIntArray(int n) {
        return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray();
    }

}

Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
 //---------------------------------------------------
 //+++++++++++++++++++++++++++++++++++++++++++++++++++
char a[100][100];
int b[26];
bool YU(int x) {
	int t = -1;
	for (int z = 0; z < 26; z++) {
		if (t == -1 && b[z] >= x)
			t = z;
		else if (b[z] >= x && b[z] < b[t])
			t = z;
	}
	if (t == -1) {
		cout << "No\n";
		return false;
	}
	b[t] -= x;
	return true;
}
signed main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string y;
		cin >> y;
		for (int j = 0; j < w; j++) {
			a[i][j] = y[j];
			b[(int)y[j] - 'a']++;
		}
	}
	for (int i = 0; i <= (h - 1) / 2; i++) {
		for (int j = 0; j <= (w - 1) / 2; j++) {
			if ((h % 2 == 1) && ((h - 1) / 2 == i) && (w % 2 == 1) && ((w - 1) / 2 == j)) {
				if (YU(1) == false) {
					return 0;
				}
			}
			else if (h % 2 == 1 && (h - 1) / 2 == i) {
				if (YU(2) == false) {
					return 0;
				}
			}
			else if (w % 2 == 1 && (w - 1) / 2 == j) {
				if (YU(2) == false) {
					return 0;
				}
			}
			else {
				if (YU(4) == false) {
					return 0;
				}
			}
		}
	}
	cout << "Yes\n";
	getchar(); getchar();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
ll dp[213456][9]; 
 
int valid(vector <char> vec){
    if(vec[0] == 'L' && vec[2] == 'R') return 1;
    if(vec[0] == 'R' && vec[2] == 'L') return 1;
    if(vec[0] == 'R' && vec[1] == 'L') return 1;
    if(vec[1] == 'R' && vec[2] == 'L') return 1;
    return 0;
}
 
char change(char c, int val){
    if(val)
    return c == 'L'? 'R': 'L';
    return c;
}
 
int main(){

    ll n, x, t;
    cin >> n >> x >> t;
    ll ans = n/x;
    if(n%x) ans++;
    ans *= t;
    cout << ans;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void solve(){
  string n;
  cin>>n;
  ll cnt=0;
  rep(i,n.size()){
    if(n[i]=='9')cnt++;
    }
  if(cnt==n.size()||(cnt==n.size()-1&&n[0]!='9')){
    ll a=n[0]-'0';
    cout<<a+(9*(n.size()-1));
}
  else {
    ll a=n[0]-'0';
    cout<<a-1+(9*(n.size()-1));
}
}

int main(){
    cout<<std::fixed<<std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

ll a[100001];
ll h[100001];
ll r[100001];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	printf("%d %d\n",Min(a, b),Max(0,a+b-n));
}

Measured memory_bytes: 128
// Kevin Mathew T
// Birla Institute of Technology, Mesra
// LinkedIn - https://www.linkedin.com/in/KevinMathewT/
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define F first
#define S second
#define fi(a, b) for(ll i=(a);i<=b;i++)
#define fj(a, b) for(ll j=(a);j<=b;j++)
#define fid(a, b) for(ll i=(a);i>=b;i--)
#define fjd(a, b) for(ll j=(a);j>=b;j--)

// #include <ext/pb_ds/assoc_container.hpp> // Common file 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> // for less 
// #include <iostream> 
// using namespace __gnu_pbds; 
// using namespace std; 
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) : Value at kth index in sorted array. 
// order_of_key(k) : Index of the value k.

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    os << "]";
	return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, unordered_map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}


const ll N = 1, M = 1e9 + 7;
ld r;

void solve(){
	cin >> r;
	ld pi = 3.14159265358979323846;
	cout << setprecision(10) << fixed;
	cout << pi * r * 2 << "\n";
}

int main(){
	// freopen("input.txt", "r", stdin);		//Comment
	// freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	// ll T;
	// cin >> T;
	// while(T--)
		solve();

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int n= s.size();
  bool judge = true;
  rep(i,n) {
    if (i%2 == 0) {
      if (s.at(i) == 'L') judge = false;
    }
    if (i%2 == 1) {
      if (s.at(i) == 'R') judge = false;
    }
  }
  
  if (judge)
    cout << "Yes" << endl;
  else
    cout << "No" << 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>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#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)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint x;
    cin >> x;
    lint ans, tmp;
    lint num = 100;

    //vector<lint> v(1000000001),n5(num);
    vector<lint> v(100), n5(num);
    REP(i, num){
        n5[i] = pow(i,5);
    }
    vector<lint> xs(num*num);
    REP(i,num)
    REP(j,num){
        lint tmp=n5[i] + n5[j];
        if(x==tmp){
            cout << i <<" "<< -j;
            return 0;
        }
    }
    lint a=0, b=0;
    while(true){
        lint a5 = pow(a, 5), b5 = pow(b, 5);
        lint tmp = a5 - b5;
        if (x == tmp)
        {
            cout << a << " " << b;
            return 0;
        }
        if(tmp>x){
            b++;
        }else{
            a++;
        }
        //cout << a <<" "<< b;
    }

    return 0;
}

Measured memory_bytes: 4148
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      int n;
      cin>>n;
      int arr[n];
      int dp[n];
      for(int i=0;i<n;i++)
      {
        cin>>arr[i];
      }
      dp[0]=0;
      dp[1]=abs(arr[0]-arr[1]);
      for(int i=2;i<n;i++)
      {
    	dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
      }
      cout<<dp[n-1]<<"\n";
      
      return 0;
    }

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int A, B; cin >> A >> B;
	if (A <= 5) cout << 0 << endl;
	else if (A >= 13) cout << B << endl;
	else cout << B / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 1e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
priority_queue<int> q;
signed main(){
	n=read();m=read();
	int ans=0;
	for(register int i=1;i<=n;i++){
		int x=read();q.push(x);
		ans+=x;
	}
	for(register int i=1;i<=m;i++){
		int x=q.top();q.pop();
		ans-=(x+1)/2;
		q.push(x/2);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1400
import sys
input=sys.stdin.readline   #input高速化 １文字の時の改行文字に注意+

d={i:0 for i in range(3001)}
db={i:0 for i in range(3001)}

n,t=map(int,input().split())

x=[tuple(map(int,input().split()))for i in n*[0]]
x.sort()
dp=[]
dp2=[]
for time,value in x:
    for k,v in d.copy().items():
        if k+time<t:
            if d[k+time]<v+value:
                d[k+time]=v+value
        else:
            break
    l=[0]
    for i in range(1,t+1):
        if d[i]>l[-1]:
            l.append(d[i])
        else:
            l.append(l[-1])

    dp.append(l)    
        
for time,value in x[::-1]:
    for k,v in db.copy().items():
        if k+time<t:
            if db[k+time]<v+value:
                db[k+time]=v+value
        else:
            break

    l=[0]
    for i in range(1,t+1):
        if db[i]>l[-1]:
            l.append(db[i])
        else:
            l.append(l[-1])
        
    dp2.append(l)
dp=[[0]*t,[0]*t]+dp
dp2=([[0]*t,[0]*t]+dp2)[::-1]

ans=0

for i in range(len(dp)):
    for j in range(t):
        if i==0 or i==len(dp)-1:
            tmp=dp[i][j]+dp2[i][t-j-1]
            if ans<tmp:
                ans=tmp
        else:
            tmp=dp[i][j]+dp2[i][t-j-1]+x[i-1][1]
            if tmp>ans:
                ans=tmp
print(ans)

Measured memory_bytes: 200328
import java.util.Scanner;
import java.util.Stack;
class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext())
		{
			Scanner pol = new Scanner(sc.nextLine());
			Stack<Double> stack = new Stack<Double>();
			while (pol.hasNext())
			{
				String str = pol.next();
				char a = str.charAt(0);
				try
				{
					stack.push((double) Integer.parseInt(str));
				}
				catch (NumberFormatException e)
				{
					double x = stack.pop();
					double y = stack.pop();
					switch (a)
					{
					case '+':
						stack.push(y + x);
						break;
					case '-':
						stack.push(y - x);
						break;
					case '*':
						stack.push(y * x);
						break;
					case '/':
						stack.push(y / x);
						break;
					}
				}
			}
			System.out.printf("%.6f\n", stack.pop());
		}
	}
}

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

int step(int n){
  int digit=1,tmp;
  tmp=n;
  int res=0;
  while((tmp=tmp / 10)>0)digit++;
  for(int i=1;i<digit;i++){
    int first,latter;
    first=n/(int)pow(10,i);
    latter=n%(int)pow(10,i);
    res=max(res,first*latter);
  }
  return res;
}

int main(){
  int q,n;
  cin>>q;
  for(int i=0;i<q;i++){
    int ans=0;
    cin>>n;
    while(n>9){
      n=step(n);
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
import sys
sys.setrecursionlimit(10**7) #再帰回数の上限を変更
from collections import deque

N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
    l=list(map(int,input().split()))
    C.append(l[0])
    a=[]
    for j in range(1,M+1):
        a.append(l[j])
    A.append(a)
ans=10**10
flag=False
for i in range(2**N):
    op=["-"]*N
    for j in range(N):
        if ((i>>j)&1):
            op[N-1-j]="+"
    tmp=0
    l=[0]*M
    for j in range(N):
        if op[j]=="+":
            tmp+=C[j]
            for k in range(M):
                l[k]+=A[j][k]
    f=True
    for j in range(M):
        if l[j]<X:
            f=False
    if f:
        flag=True
        ans=min(ans,tmp)

if flag:
    print(ans)
else:
    print(-1)

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<Long> list = new ArrayList<Long>(n);
		int count = 0;

		for(int i = 0;i < n;i++) {
			list.add(scan.nextLong());
		}

		Collections.sort(list);

		for(int i = 0;i < n - 2;i++) {
			for(int j = i + 1;j < n - 1;j++) {
				for(int k = j + 1;k < n;k++) {
					if(list.get(i).equals(list.get(j)) || list.get(j).equals(list.get(k)) || list.get(i).equals(list.get(k))) {
						continue;
					}

					if(list.get(i) + list.get(j) > list.get(k)) {
						count++;
					}
				}
			}
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 37304
#include <iostream>

using namespace std;

int main() {
    int S, h, m, s;
    cin >> S;
    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = S - h * 3600 - m * 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair
 
typedef long long ll;
 
const int maxn = 5e3 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
 
int n;
 
int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);  freopen(Task".out", "w", stdout);
  cin >> n;
  #define pii pair<int,int>
  vector<pair<pii,int> > group1, group2;
  int sum = 0;
 
  for (int i = 0; i < n; ++i){
    string s; cin >> s;
    int mi1 = 0, mi2 = 0, t1 = 0, t2 = 0;
 
    for (int j = 0; j < sz(s); ++j) t1 = t1 + (s[j] == '(' ? 1 : -1), mi1 = min(mi1, t1);
    for (int j = sz(s) - 1; j >= 0; --j) t2 = t2 + (s[j] == '(' ? -1 : 1), mi2 = min(mi2, t2);
 
    if (t1 >= 0) group1.push_back(mp(mp(t1, -mi1), i + 1) );
    else group2.push_back(mp(mp(t2, -mi2), i + 1) );
    sum += t1;
  }
  if (sum != 0){
    cout << "No";
    return 0;
  }
 
  vector<int> ansgr1, ansgr2;
 
  int cur;
 
  sort(All(group1), [&](pair<pii, int> x, pair<pii, int> y){
    return x.first.second < y.first.second;
  });
 
  cur = 0;
  for (int i = 0; i < (int)group1.size(); ++i){
    int t = group1[i].first.first, cost = group1[i].first.second, pos = group1[i].second;
    if (cur < cost){
      cout << "No"; return 0;
    }
    ansgr1.push_back(pos);
    cur += t;
  }
 
  sort(All(group2), [&](pair<pii, int> x, pair<pii, int> y){
    return x.first.second < y.first.second;
  });
 
  cur = 0;
  for (int i = 0; i < (int)group2.size(); ++i){
    int t = group2[i].first.first, cost = group2[i].first.second, pos = group2[i].second;
    if (cur < cost){
      cout << "No"; return 0;
    }
    ansgr2.push_back(pos);
    cur += t;
  }
  reverse(ansgr2.begin(), ansgr2.end());
  cout << "Yes\n";
//  for (auto p : ansgr1) cout << p <<' '; for (auto p : ansgr2) cout << p <<' ';
}

Measured memory_bytes: 20940