akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    costs = [0]*(N+1)
    h = [10**16] + h
    for i in range(2,N+1):
        costs[i] = min(costs[i-1]+abs(h[i]-h[i-1]),costs[i-2]+abs(h[i]-h[i-2]))
    print(costs[-1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18832
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define got(container,num) get<num-1>(container)
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
using namespace std;
const int INF=LLONG_MAX-1e10;
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
main()
{
    IOS
    cin>>n>>m;
    if(n==1 or m==1)out(1)
    else  out(n*m-(n*m/2))
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, M = map(int, input().split())
L = 0
R = N
for i in range(M):
	l, r = map(int, input().split())
	if l > L:
		L = l
	if r < R:
		R = r

ans = min(R - L + 1, N)
if ans < 0:
	ans = 0
print(ans)


Measured memory_bytes: 41068
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

/*
ll mod(ll n, ll m) {
n -= (n / m)*m;
return n;
}
ll loop(ll n, ll m, ll k) {
if (k == 1) {
return n % m;
}
else if (k % 2 == 0) {
ll t = loop(n, m, k / 2);
return t * t%m;
}
else {
return loop(n, m, k - 1)*n%m;
}
}
*/
int main() {
	int n, d, x;
	cin >> n >> d >> x;
	int a[110];
	for (int i = 0; i < n; ++i) {
		//int a[i][110];
		//a[i] = new int[110];
		cin >> a[i];
	}
	int res = x;
	for (int i = 0; i < n; ++i) {
		for (int j = 1; j <= d ; j+=a[i]) {
			res++;
			//cout << j << endl;
		}
	}
	/*
	for (int i = 0; i < size(res); ++i) {
	cout << res[i] << endl;
	}
	*/
	//cout << size(res) << endl;
	cout << res << endl;
	return 0;

}


Measured memory_bytes: 256
n=int(input())
def f(x):
    s=0
    while x>0:
        s=max(s,t[x])
        x-=x&-x
    return s
def g(x,y):
    while x<n+1:
        t[x]=max(y,t[x])
        x+=x&-x
t=[0]*(n+1)
h=list(map(int,input().split()))
a=list(map(int,input().split()))
for i in range(n):
    g(h[i],f(h[i]-1)+a[i])
print(max(t))

Measured memory_bytes: 36592
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}





int main() {
  int N;
  cin>>N;
  string S[N];
  long long summ=0;
  long long suma=0;
  long long sumr=0;
  long long sumc=0;
  long long sumh=0;
  for(int i=0;i<N;i++){
    cin>>S[i];
    if(S[i].at(0)=='M'){
      summ++;
    }else if(S[i].at(0)=='A'){
      suma++;
    }else if(S[i].at(0)=='R'){
      sumr++;
    }else if(S[i].at(0)=='C'){
      sumc++;
    }else if(S[i].at(0)=='H'){
      sumh++;
    }
  }
  long long sum=summ*suma*sumr+summ*suma*sumc+summ*suma*sumh+summ*sumr*sumc+summ*sumr*sumh+summ*sumc*sumh+suma*sumr*sumc+suma*sumr*sumh+suma*sumc*sumh+sumr*sumc*sumh;
  cout<<sum<<endl;
  








  


  

  


  

    


  

  
  
  
  
}


  

Measured memory_bytes: 6144
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pii pair<int,int>
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int a,b; cin>>a>>b;
  co(a/b);
  co(a%b);
  double c=a,d=b;
  cout<<fixed<<setprecision(12);
  co(c/d);
  return 0;
}


Measured memory_bytes: 3252
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
	int N;
	cin >> N;
	int a[N+1];

	for(int i=1;i<=N;i++) cin >> a[i];

	bool put[N+1];
	for(int i=1;i<=N;i++) put[i] = false;

	int ans = 0;

	for(int i=N;i>0;i--){
		int cnt = 0;
		for(int j=2*i;j<=N;j+=i){
			if(put[j]) cnt++;
		}
		if((cnt%2)!=a[i]){
			put[i] = true;
			ans++;
		} 
	}

	cout << ans <<endl;

	for(int i=1;i<=N;i++){
		if(put[i]) cout << i << " ";
	}
	cout <<endl;


    
  	return 0;
}


Measured memory_bytes: 1920
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		WriteLine(Solve());
		Out.Flush();
	}
	long Solve()
	{
		var I = GL;
		long A = I[0], B = I[1];
		if (A == B) return A;
		if (A == 0) A++;
		var ans = 0L;
		for (var i = 0; i < 50; i++)
		{
			if (Calc(B, i) != Calc(A - 1, i)) ans |= 1L << i;
		}
		return ans;
	}
	long Calc(long n)
	{
		if (n == 0) return 0;
		if (n == 1) return 1;
		if (n % 2 == 0) return n ^ Calc(n - 1);
		if (n % 4 == 1) return 1;
		return 0;
	}
	long Calc2(long n)
	{
		var ans = 0L;
		for (var i = 0L; i <= n; i++) ans ^= i;
		return ans;
	}
	long Calc(long n, int k)
	{
		if (k == 0) return ((n + 1) / 2) & 1;
		var m = 1L << k;
		if (n < m) return 0;
		if ((n & m) == 0) return 0;
		return ((n & (m - 1)) + 1) & 1;
	}
	long Calc2(long n, int k)
	{
		var ans = 0L;
		for (var i = 0L; i <= n; i++) if ((i & (1L << k)) != 0) ans++;
		return ans & 1;
	}
}


Measured memory_bytes: 13268
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>

#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //CLion Standard Input


    int n;
    cin >> n;

    vector<int> a(n);

    for (int i = 0; i < n; i++) cin >> a[i];
    set<int> ss(a.begin(), a.end());

//    for(auto s: ss)cout << s << endl;

    if(ss.size() % 2) cout << ss.size();
    else cout << ss.size() - 1;
}

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

using namespace std;
#define int long long
#define INF 10e9
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N,W;
    cin>>N>>W;
    vector<vector<int> >dp(N+1,vector<int>(100001,INF+10));
    vector<int> w(N+1);
    vector<int> v(N+1);
    for(int i=1;i<=N;i++)
    {
        cin>>w[i]>>v[i];
    }
    int ans=0;
    for(int i=0;i<=N;i++)
    {
        for(int j=0;j<=100000;j++)
        {
            
            if(j==0)
            {
                dp[i][j]=0;continue;
            }
            if(i==0)
            {
                dp[i][j]=INF+10;continue;
            }
            
            dp[i][j]=dp[i-1][j];
            if(j-v[i]>=0)
            dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
            
            if(dp[i][j]<=W)
            {
                ans=max(ans,j);
            }
        }
    }
    cout<<ans;
    return 0;
    
}

Measured memory_bytes: 80256
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>

using namespace std;
int main() {

	int n,y,tmp;
	int i, j, k;
	int ansi=-1, ansj=-1, ansk=-1;
	cin >> n>>y;

	for (i = 0; i <= n; i++) {
		for (j = 0; j <= n - i; j++) {
			k = n - i - j;
			tmp = i * 10000 + j * 5000 + k * 1000;
			if (tmp == y) {
				ansi = i;
				ansj = j;
				ansk = k;
				break;
			}
		}
	}


	cout << ansi << " " << ansj << " " << ansk << endl;

	return 0;
}

Measured memory_bytes: 888
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInput() (int, int, int, int) {
	A := 0
	if sc.Scan() {
		A, _ = strconv.Atoi(sc.Text())
	}
	B := 0
	if sc.Scan() {
		B, _ = strconv.Atoi(sc.Text())
	}
	C := 0
	if sc.Scan() {
		C, _ = strconv.Atoi(sc.Text())
	}
	X := 0
	if sc.Scan() {
		X, _ = strconv.Atoi(sc.Text())
	}
	return A, B, C, X
}

func main() {

	A, B, C, X := getInput()

	num := 0
	for a := 0; a <= A; a++ {
		for b := 0; b <= B; b++ {
			for c := 0; c <= C; c++ {
				if a*500+b*100+c*50 == X {
					num++
				}
			}
		}
	}

	fmt.Println(num)
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int[n+1];
    for(int i = 0; i < m; i++){
      a[sc.nextInt()]++;
      a[sc.nextInt()]++;
    }
    for(int i = 1; i <= n; i++){
      System.out.println(a[i]);
    }
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(void)
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if (a > 0)
  {
    if (a >= k)
    {
      ans += k;
      k = 0;
    }
    else
    {
      ans += a;
      k -= a;
    }
  }
  if (b > 0 && k > 0)
  {
    if (b >= k)
    {
      k = 0;
    }
    else
    {
      k -= b;
    }
  }
  if (c > 0 && k > 0)
  {
    if (c >= k)
    {
      ans -= k;
    }
    else
    {
      ans -= c;
    }
  }

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> a,b;
    for(int i=0;i<n;i++){
        int c,d;
        cin >> c >> d;
        a.push_back(make_pair(d,c));
    }
    for(int i=0;i<n;i++){
        int c,d;
        cin >> c >> d;
        b.push_back(make_pair(c,d));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    vector<int> ismatch(n,0);
    int cnt = 0;
    for(int i=0;i<n;i++){//blue
        int c = -1;
        for(int j=0;j<n;j++){//red
            if(ismatch[j]) continue;
            if(a[j].second<b[i].first&&a[j].first<b[i].second){
                c = max(c,j);
            }
        }
        if(c!=-1){
            ismatch[c]=1;
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long x, y, a, cnt = 1;
    cin >> x >> y;
    a = x;
    while(a < y){
        a *= 2;
        if(a <= y) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
N, T = gets.split.map(&:to_i)
costMin = 1001
N.times do |i|
	c,t = gets.split.map(&:to_i)
	next if t > T
	costMin = [costMin, c].min
end

if costMin != 1001
	print("#{costMin}\n")
else
	print("TLE\n")
end

Measured memory_bytes: 1788
#include <stdio.h>

int main(void) {
	int a,b,c,anser=0;
	scanf("%d %d %d",&a,&b,&c);
	for(;;){
		if(c%a==0){
			anser++;
		}
		if(a==b){
			break;
		}
		a++;
	}
	printf("%d\n",anser);
	return 0;
}

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

int mod = 1'000'000'007;

int n, k;

int binary_search(vector<long long> &prime, int &x){
    int ok = 0;
    int ng = prime.size();
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if (prime[x] * prime[mid] > n) ng = mid;
        else ok = mid;
    }
    return ng;
}

int main(){
    cin >> n >> k;
    vector<long long> prime;
    int max_num = n;
    for (int i = 1; i <= max_num; i++){
        prime.push_back(i);
        if (max_num > n / i){
            if (i != max_num) prime.push_back(max_num);
            max_num = n / i;
        }
    }
    sort(prime.begin(), prime.end());
    vector<long long> tmp(prime.size(), 1);
    for (int i = 1; i < prime.size(); i++) tmp[i] = prime[i] - prime[i - 1];
    vector<long long>id(prime.size());
    for (int i = 0; i < id.size(); i++) id[i] = binary_search(prime, i);
    vector<long long> x = tmp;
    for (int i = 1; i < k; i++){
        vector<long long> nx(x.size(), 0);
        for (int j = 0; j < prime.size(); j++){
            nx[0] += x[j];
            nx[0] %= mod;
            if (id[j] != x.size()) nx[id[j]] += mod - x[j], nx[id[j]] %= mod;
        }
        for (int j = 0; j < prime.size() - 1; j++) nx[j + 1] += nx[j], nx[j + 1] %= mod;
        for (int j = 0; j < prime.size(); j++) nx[j] *= tmp[j], nx[j] %= mod;
        x = nx;
    }
    long long ans = 0;
    for (int i = 0; i < x.size(); i++){
        ans += x[i];
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2808
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n,cnt=0,good[4]={0,0,0,0};
  
  std::cin >> n;
  char s[100];
  for(int i=0; i<n; i++) {
    std::cin >> s[i];
    if(s[i]=='P' && good[0]==0){ cnt++; good[0]++; }
    else if(s[i]=='W' && good[1]==0){ cnt++; good[1]++;}
    else if(s[i]=='G' && good[2]==0) {cnt++; good[2]++;}
    else if(s[i]=='Y' && good[3]==0){ cnt++; good[3]++;}
  }

  if(cnt==3)printf("Three\n");
  else printf("Four\n");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    double x1 = stdin.nextDouble();
    double y1 = stdin.nextDouble();
    double x2 = stdin.nextDouble();
    double y2 = stdin.nextDouble();
    double x = Math.abs(x1 - x2);
    double y = Math.abs(y1 - y2);
    System.out.printf("%f%n", Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
  }

}

Measured memory_bytes: 19136
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll int modd = 1000000007;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int h, w;
    cin >> h >> w;

    vector<char> tempv(w);
    vector<vector<char>> grid(h, tempv);

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> grid[i][j];
        }
    }
    
    vector<ll int> tempdp(w, 0);
    vector<vector<ll int>> dp(h, tempdp);
    dp[h-1][w-1] = 1;
    for (int i = h-1; i >= 0; i--)
    {
        for (int j = w-1; j >= 0; j--)
        {
            if(dp[i][j] == 0 && grid[i][j] == '.'){
                //cout << "i : "<< i << ", j : " << j << endl;
                if(i == h-1 && grid[i][j+1] == '.'){
                    dp[i][j] = dp[i][j+1];
                }
                else if(j == w-1 && grid[i+1][j] == '.'){
                    dp[i][j] = dp[i+1][j];
                }
                else if(i != h-1 && j != w-1){
                    ll int ans = 0;
                    if(grid[i+1][j] == '.'){
                        ans += dp[i+1][j];
                    }
                    if(grid[i][j+1] == '.'){
                        ans += dp[i][j+1];
                        ans %= modd;
                    }
                    dp[i][j] = ans;
                }
            }
        }
    }
    cout << dp[0][0] << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    vec r;

    rep(i, n) {
        if (i != n-1) {
            if (s[i] == s[i+1]) {
                r.push_back(2);
                i++;
            }
            else {
                r.push_back(1);
            }
        }
        else {
            r.push_back(1);
        }
    }

    lint res;
    if (r[0] == 1) res = 3;
    else res = 6;
    int v = r.size();

    bool c = false;

    rep(i, v) {
        if (i == 0) continue;

        if (r[i] == 1 && r[i-1] == 1) {
            res *= 2;
        }
        else if (r[i] == 1 && r[i-1] == 2) {
            // res *= 1;
        }
        else if (r[i] == 2 && r[i-1] == 1) {
            res *= 2;
        }
        else {
            res *= 3;
        }
        res %= MOD;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

class cl
{
public:
	int s[4];

	void sortw(int a)
	{
		for(int i = 0; i < 4; i++)
		{
			s[i] = a % 10;
			a /= 10;
		}
		sort(s,s + 4);
	}

	int minw()
	{
		int w = 0;
		for(int i = 0; i < 4; i++)
		{
			w *= 10;
			w += s[i];
		}
		return w;
	}

	int maxw()
	{
		int w = 0;
		for(int i = 0; i < 4; i++)
		{
			w *= 10;
			w += s[3 - i];
		}
		return w;
	}
};

int func(int a)
{
	cl w;
	w.sortw(a);
	return w.maxw() - w.minw();
}

int stoi(char* a)
{
	int w = 0;
	for(int i = 0; i < 4; i++)
	{
		w *= 10;
		w += a[i] - '0';
	}
	if(w % 1111 == 0 && w != 0)
	{
		return -1;
	}
	return w;
}

int kai(int a)
{
	for(int i = 0; i < 10000; i++)
	{
		if(a == 6174)
		{
			return i;
		}
		a = func(a);
	}
}

int main()
{
	while(1)
	{
		char w[10];
		scanf("%s",w);
		int a = stoi(w);
		if(a == 0)
		{
			break;
		}
		if(a < 0)
		{
			printf("NA\n");
		}
		else
		{
			printf("%d\n",kai(a));
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>8 || b>8)
    cout<<":("<<endl;
  else
    cout<<"Yay!"<<endl;
return 0;}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int k = Integer.parseInt(line);
			if (k == 0) {
				break;
			}
			int sum = 0;
			StringTokenizer st = new StringTokenizer(br.readLine());
			while (st.hasMoreTokens()) {
				sum += Integer.parseInt(st.nextToken());
			}
			System.out.println(sum / (k - 1));
		}
	}
}

Measured memory_bytes: 25508
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        if(k == 0) {
            System.out.print((long) n * n);
            return;
        }

        long sum = 0;
        for(int i = k + 1; i <= n; i++) {
            sum += (long)(n / i) * (i - k) + Math.max(n%i-k+1, 0);
        }
        System.out.print(sum);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#define INF 1000000000
using namespace std;

int N, A, B, C;
vector<int> l;

int dfs(int cur, int a, int b, int c){// abcはそれぞれの長さ
    if(cur == N) return ((min({a, b, c})) ? (abs(a-A)+abs(b-B)+abs(c-C) -30) : INF);
    int ret0 = dfs(cur+1, a, b, c);             //curを使わないとき
    int ret1 = dfs(cur+1, a+l[cur], b, c) + 10; //curを1本目に
    int ret2 = dfs(cur+1, a, b+l[cur], c) + 10; //curを2本目に
    int ret3 = dfs(cur+1, a, b, c+l[cur]) + 10; //curを3本目に
    return min({ret0, ret1, ret2, ret3});
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++){
        int li; cin >> li; l.push_back(li);
    }
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
double p[333][333][333];n,c[4];double f(i,j,k){return~i&~j&~k?p[i][j][k]?:(p[i][j][k]=(i*f(i-1,j,k)+j*f(i+1,j-1,k)+k*f(i,j+1,k-1)+n)/(i+j+k)):0;}main(){for(***p=1;~scanf("%d",n?c:&n);)c[*c]++;printf("%.9f",f(c[1],c[2],c[3])-1);}

Measured memory_bytes: 260096
import std.stdio, std.string, std.conv;
void main() {
	string s = readln.chomp;
	readln;
	foreach (string l; lines(stdin)) {
		auto d = l.chomp.split;
		auto n = d[1..3].to!(int[]);
		if (d[0] == "print")
			s[n[0]..n[1]+1].writeln;
		if (d[0] == "reverse") {
			auto r = s[n[0]..n[1]+1].to!(char[]).reverse.to!string;
			s = s[0..n[0]] ~ r ~ s[n[1]+1..$];
		}
		if (d[0] == "replace")
			s = s[0..n[0]] ~ d[3] ~ s[n[1]+1..$];
	}
}

Measured memory_bytes: 2476
#include <iostream>
#include <algorithm>

using namespace std;

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

    int n, m;
    cin >> n >> m;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    bool f[n];
    fill(f, f+n, true);

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;

        if (h[u] >= h[v]) {
            f[v] = false;
        }
        if (h[u] <= h[v]) {
            f[u] = false;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += f[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4140
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
struct Monoid<T> {
    id: T,
    op: Box<Fn(&T, &T) -> T>,
}
impl<T> Monoid<T> {
    fn new(id: T, op: Box<Fn(&T, &T) -> T>) -> Monoid<T> {
        Monoid { id: id, op: op }
    }
}
impl Monoid<usize> {
    fn max() -> Monoid<usize> {
        Monoid::new(std::usize::MIN, Box::new(|x, y| std::cmp::max(*x, *y)))
    }
}
struct BinaryIndexedTree<T: Clone> {
    bit: Vec<T>,
    op: Monoid<T>,
}
impl<T: Clone> BinaryIndexedTree<T> {
    fn new(n: usize, op: Monoid<T>) -> BinaryIndexedTree<T> {
        let bit = vec![op.id.clone(); n + 1];
        BinaryIndexedTree { bit: bit, op: op }
    }
    fn query(&self, i: usize) -> T {
        let mut res = self.op.id.clone();
        let mut i = i as isize + 1;
        while i > 0 {
            res = (self.op.op)(&res, &self.bit[i as usize]);
            i -= i & -i;
        }
        res
    }
    fn update(&mut self, i: usize, x: T) {
        let mut i = i as isize + 1;
        while i < self.bit.len() as isize {
            self.bit[i as usize] = (self.op.op)(&self.bit[i as usize], &x);
            i += i & -i;
        }
    }
}
fn main() {
    input! { n, h: [usize; n], a: [usize; n] };
    let mut bit = BinaryIndexedTree::new(n + 1, Monoid::max());
    for i in 0..n {
        let pa = bit.query(h[i] - 1);
        bit.update(h[i], pa + a[i]);
    }
    println!("{}", bit.query(n));
}


Measured memory_bytes: 13560
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector < int > VI;
typedef pair < int, int > pii;
inline int read()
{
    int x = 0, ch = getchar(), f = 1;
    while (! isdigit(ch))
    {
        if (ch == '-')
            f = - 1;
        ch = getchar();
    }
    while (isdigit(ch))
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}
const int N = 100005;
int n, m, fl, col[N];
LL cnt2, cnt1, cnt3, sz;
VI E[N];
void dfs(int x, int c)
{
    if (col[x])
    {
        if (col[x] != c)
            fl = 0;
        return;
    }
    ++ sz;
    col[x] = c;
    for (int i = 0; i < E[x].size(); ++ i)
        dfs(E[x][i], 3 - c);
}
int main()
{
    n = read(), m = read();
    for (int i = 1; i <= m; ++ i)
    {
        int u = read(), v = read();
        E[u].push_back(v);
        E[v].push_back(u);
    }
    LL ans = 0;
    for (int i = 1; i <= n; ++ i)
        if (! col[i])
        {
            fl = 1;
            sz = 0;
            dfs(i, 1);
            if (sz == 1)
                ++ cnt1;
            else if (fl)
            ++ cnt2;
            else ++ cnt3;
        }
    ans += 1ll * cnt1 * (n - cnt1) * 2 + cnt1 * cnt1;
    ans += cnt2 * cnt2 * 2;
    ans += cnt3 * cnt2 * 2 + cnt3 * cnt3;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



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

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

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,n;cin>>h>>n;
  rep(i,n){
    ll a;cin>>a;
    h-=a;
  }
  if(h<=0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;

}


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


#pragma comment(linker, "/STACK:256000000")

using namespace std;

int main(){
	string S, ans;

	cin >> S;

	for(int i = 0; i < 1 << 4 - 1; ++i){
		int tmp = S[0] - '0';
		for(int j = 1; j < 4; ++j){
			if(i >> j - 1 & 1)
				tmp += S[j] - '0';
			else
				tmp -= S[j] - '0';
		}
		if(tmp == 7){
			for(int j = 0; j < 3; ++j){
				cout << S[j];
				if(i >> j & 1)
					cout << "+";
				else
					cout << "-";
			}
			cout << S[3];
			cout << "=7" << endl;
			break;
		}
	}

	return 0;
}

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


int n,m;
string s,t,s1;
int dp[3005][3005];



void path(int i,int j)
{
    if(i==0 || j==0)
    return;
    int ans=dp[i][j];
    if(s[i-1]==t[j-1])
    {
        s1+=s[i-1];
        return path(i-1,j-1);
    }
    if(ans==dp[i-1][j])
    return path(i-1,j);
    return path(i,j-1);
}
int32_t main() {
    cin>>s>>t;
    n=s.size();
    m=t.size();
	for(int i=0;i<=n;++i)
	{
	    for(int j=0;j<=m;++j)
	    {
	        if(i==0 || j==0)
	        dp[i][j]=0;
	        else if(s[i-1]==t[j-1])
	        dp[i][j]=dp[i-1][j-1]+1;
	        else
	        dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
	    }
	}
	path(n,m);
	for(int i=s1.size()-1;~i;--i)
	cout<<s1[i];
	return 0;
}

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

int main(){
  int n, k;
  int ans = 1;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    if(ans + k < 2 * ans) ans += k;
    else ans = ans * 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int v_i=0;
		double gousei=0;
		
		List<Double> v = new ArrayList<Double>();
		List<Double> v_g = new ArrayList<Double>();
		
		//要素の追加
		for(int i=0;i<n;i++) {
			v_i = sc.nextInt();
			v.add((double)v_i);
		}
		//要素の並び替え
		Collections.sort(v);
		//n-1回の合成作業
		for(int i=0;i<n-1;i++) {
			//最小の二つを組み合わせる
			if(v_g == null || v_g.size()==0) {
				gousei = v.get(0)+v.get(1);
				gousei = gousei/2;
				//上二つを削除して，v_gに追加
				v.remove(0);
				v.remove(0);
				v_g.add(gousei);
				
			
			}else if(v.size()==1) {
				gousei = v.get(0)+v_g.get(0);
				gousei = gousei/2;
			
				
			}else if(v_g.size()==1) {
				if(v.get(1) < v_g.get(0) ){
					gousei = v.get(0)+v.get(1);
					gousei = gousei/2;
					//上二つを削除して，v_gに追加
					v.remove(0);
					v.remove(0);
					v_g.add(gousei);
				}else {
					gousei = v.get(0)+v_g.get(0);
					gousei = gousei/2;
					//上二つを削除して，v_gに追加
					v.remove(0);
					v_g.remove(0);
					v_g.add(gousei);
				}
				
			}else {
				if(v.get(1) < v_g.get(0) ){
					gousei = v.get(0)+v.get(1);
					gousei = gousei/2;
					//上二つを削除して，v_gに追加
					v.remove(0);
					v.remove(0);
					v_g.add(gousei);
				}else if(v.get(0) < v_g.get(1) ){
					gousei = v.get(0)+v_g.get(0);
					gousei = gousei/2;
					//上二つを削除して，v_gに追加
					v.remove(0);
					v_g.remove(0);
					v_g.add(gousei);
				}else {
					gousei = v_g.get(0)+v_g.get(1);
					gousei = gousei/2;
					//上二つを削除して，v_gに追加
					v_g.remove(0);
					v_g.remove(0);
					v_g.add(gousei);
				}
				
			}


			//要素の並び替え
			Collections.sort(v_g);
			
			
		}
		
		
		System.out.println(gousei);
		
		
		
		
		
	}
}

Measured memory_bytes: 22996
def dig_sum(n):
    sum = 0
    while n>0:
        sum += n%10
        n //= 10
    return sum

import sys
x = []
for l in sys.stdin:
    x.append(int(l))
    if int(l) == 0: break

i = 0
while x[i]!=0:
    out = dig_sum(x[i])
    print(out)
    i += 1







Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
const ll mod=1e+9+7;
int main(void){
    // Your code here!
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll dight=1,res=0;
    rep(i,63){
        ll x=0,y=0;
        rep(j,n){
            if(a[j]%2==0)x++;
            else y++;
            a[j]/=2;
        }
        ll buf=x*y%mod;
        res+=buf*dight;
        res%=mod;
        dight*=2;
        dight%=mod;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] c = new int[3][3];
        
        for(int i = 0;i < 3;i++) {
            for(int j = 0;j < 3;j++) c[i][j] = sc.nextInt();
        }
        
        boolean isOK = true;
        isOK &= (c[0][0] - c[0][1]) == (c[1][0] - c[1][1]);
        isOK &= (c[0][0] - c[0][1]) == (c[2][0] - c[2][1]);
        isOK &= (c[1][0] - c[1][1]) == (c[2][0] - c[2][1]);
        isOK &= (c[0][0] - c[0][2]) == (c[1][0] - c[1][2]);
        isOK &= (c[0][0] - c[0][2]) == (c[2][0] - c[2][2]);
        isOK &= (c[1][0] - c[1][2]) == (c[2][0] - c[2][2]);
        isOK &= (c[0][1] - c[0][2]) == (c[1][1] - c[1][2]);
        isOK &= (c[0][1] - c[0][2]) == (c[2][1] - c[2][2]);
        isOK &= (c[1][1] - c[1][2]) == (c[2][1] - c[2][2]);

        String ans = isOK ? "Yes" : "No";
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
int Roundup(int a,int b){
    return (a+b-1)/b;
}

signed main(void){
    int H,A;
    cin >> H >> A;
    cout << Roundup(H,A) << endl;
    
    
    return 0;
}



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

int main()
{
    int n;
    cin >> n;
    double ans = (double)(n/2 + n%2) / n;
    printf("%.10f\n", ans);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    string s;
    cin>>s;
    reverse(ALL(s));
    ll ans=0;
    ll n = s.length();
    s += '0';
    Vec v(n+1);
    rep(i,n+1){
        v[i] = s[i]-'0';
    }
    //dbg(v);
    rep(i,n){
        ll now = v[i];
        ll next = v[i+1];
        if(now<5){
            ans += now;
        }else if(now == 5){
            ans += now;
            if(next>=5){
                v[i+1]++;
            }
        }else if(now < 10){
            ans += 10-now;
            v[i+1]++;
        }else{
            v[i+1]++;
        }
    }
   // dbg(v);
    ans += v[n];
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    set<int>d;
    scanf("%d%d%d",&a,&b,&c);
    d.insert(a),d.insert(b),d.insert(c);
    printf("%d\n",d.size());
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<class T> inline bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
    }
    template<class T> inline bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string S;
        cin>>S;
        map<char,ll> m;
        rep(i,Size(S)){
            m[S[i]]++;
            if(m[S[i]]>1){
                cout<<"no"<<endl;
                return 0;
            }
        }
        cout<<"yes"<<endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  string S;
  for (int i = 0; i < H; i++)
  {
  	for (int j = 0; j < W; j++)
    {
    	cin >> S[W * i + j];
    }
  }
  
  string T;
  int count = 0;
  for (int i = 0; i < H; i++)
  {
  	for (int j = 0; j < W; j++)
    {
        if (S[W * i + j] == '#') 
        {
          	T[W * i + j] = '#';
        }
      	else
        {
        	if (i != 0 && j != 0 && S[W * (i-1) + (j - 1)] == '#') count++;
          	if (i != 0 && S[W * (i-1) + j] == '#') count++;
          	if (i != 0 && j != W-1 && S[W * (i-1) + (j + 1)] == '#') count++;
          	if (j != 0 && S[W * i + (j - 1)] == '#') count++;
          	if (j != W -1 && S[W * i + (j + 1)] == '#') count++;
         	if (i != H-1 && j != 0 && S[W * (i+1) + (j - 1)] == '#') count++;
          	if (i != H-1 && S[W * (i+1) + j] == '#') count++;
          	if (i != H-1 && j != W-1 && S[W * (i+1) + (j + 1)] == '#') count++;
          	T[W * i + j] = std::to_string(count).at(0);
        }
      	count = 0;
      	cout << T[W*i+j];
    }
    cout << endl;
  }

}

Measured memory_bytes: 256
#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 A, B;
    scanf("%lld", &A);
    scanf("%lld", &B);
    if ( A + B == 3 ) printf("3\n");
    else if ( A + B == 5 ) printf("1\n");
    else printf("2\n");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), M = sc.nextInt(), X = sc.nextInt();
    int arr[] = new int[N+1];
    for(int i = 1; i<=M; i++){
      int n = sc.nextInt();
      arr[n] = 1;
    }
    int opt1 = 0; //cost of going from X to 0
    int opt2 = 0; //cost of going from X to N
    for(int i = X; i>=0; i--){
      opt1 += arr[i]; 
    }
    for(int i = X; i<=N; i++){
      opt2 += arr[i]; 
    }
    System.out.println(Math.min(opt1, opt2));
  }
}

/*

pre[i] = arr[1] + arr[2] + arr[3] + arr[4] + ... + arr[i]
The question for some l and r
arr[l] + arr[l+1] + arr[l+2] + ... + arr[r]
= 
pre[r] - pre[l-1]

pre[r]   = arr[1] + arr[2] + ... + arr[l-1] + arr[l] + arr[l+1] + ... + arr[r]
-
pre[l-1] = arr[1] + arr[2] + ... + arr[l-1]

*/


Measured memory_bytes: 35796
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
  Node *cur = nil->next;
  while( cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  Node *cur = nil->next;
  int isf = 0;
  while(1){
    if(cur == nil)break;
    if(isf++ > 0)printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if( t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deletekey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n,i;
  int size = 0;
  char com[20];
  int np = 0,nd = 0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d", com, &key);
    if( com[0] == 'i'){ insert(key);np++;size++;}
    else if(com[0] == 'd'){
      if( strlen(com) > 6){
	if(com[6] == 'F')deleteFirst();
	else if( com[6] == 'L')deleteLast();
      }else{
	deletekey(key); nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}

Measured memory_bytes: 32216
N=int(input())
s=[0]*N
for i in range(N):
    s[i] = input()
    s[i] = sorted(s[i])
s=sorted(s)
counter=1
sum=0
for i in range(N-1):
    if s[i] == s[i+1]:
        counter+=1
    else:
        sum+=counter*(counter-1)//2
        counter=1
sum+=counter*(counter-1)//2
print(sum)

Measured memory_bytes: 25420
n,x = map(int,input().split())
if x == 1 or x == 2*n-1:
    print("No")
    exit()

print("Yes")
ans = [i for i in range(1,2*n)]
ans.remove(x-1)
ans.remove(x)
ans.remove(x+1)
for i in range(n-2):
    print(ans[i])
print(x-1)
print(x)
print(x+1)
for i in range(n-2):
    print(ans[n-2+i])

Measured memory_bytes: 52464
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e9+7;
ll n;
// 0:a,1:t,2:g,3:c
int main(void) {
    cin >> n;
    ll dp[n+1][4][4][4]={};
    for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
    for(int k=0;k<4;k++){
        if(i==0&&j==2&&k==3)continue;
        if(i==2&&j==0&&k==3)continue;
        if(i==0&&j==3&&k==2)continue;
        dp[3][i][j][k]=1;
    }
    for(int a=4;a<n+1;a++)
     for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
    for(int k=0;k<4;k++){
        if(i==0&&j==2&&k==3)continue;
        if(i==2&&j==0&&k==3)continue;
        if(i==0&&j==3&&k==2)continue;
       for(int l=0;l<4;l++){
            if(l==0&&i==2&&k==3)continue;
            if(l==0&&j==2&&k==3)continue;
            dp[a][i][j][k]+=dp[a-1][l][i][j];
            dp[a][i][j][k]%=mod;
        }
    }
    ll res=0;
     for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
    for(int k=0;k<4;k++){
        res += dp[n][i][j][k];
        res %= mod;
    }
    cout << res << endl;
    return 0;
}


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

// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define F         first
#define S         second

template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if (f) Out(y); else Out(n); }

using int64 = long long;

signed main() {

    // ⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎



  string s;
  cin >> s;
  
  for(int i = 0; i < (1 << 3); i++){  
    int cur = s[0] - '0'; 

    string ans;
    ans += s[0];   

    for(int j = 1; j < 4; j++){
      if((i >> (j - 1)) & 1){
        cur += s[j] - '0';
        ans += "+";
        ans += s[j];
      } else {
        cur -= s[j] - '0';
        ans += "-";
        ans += s[j];
      }
    }
    if(cur == 7) {
      cout << ans << "=7" << endl;
          return(0);
    }
  }

    
 
}



Measured memory_bytes: 3592