akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
#define all(a) a.begin(),a.end()
using namespace std;

signed main(){
    int n; cin>>n;
    vector<double> x(n);
    vector<string> u(n);
    double ans=0;
    rep(i,n){
        cin>>x.at(i)>>u.at(i);
        if(u.at(i)=="JPY") ans+=x.at(i);
        else ans+=380000*x.at(i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
nums = int(input())
data = {}
for i in range(nums):
    name, num = input().split()
    data[name] = data.get(name, 0) + int(num)
sorteddata = sorted(list(data.items()), key=lambda x: (len(x[0]), x))
for name, num in sorteddata:
    print(name, num)


Measured memory_bytes: 5624
N, M = map(int, input().split())
P = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(M)]


class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

uni = UnionFind(N)
for x, y in XY:
    uni.Unite(x, y)

group = {}
for i, r in enumerate(uni.root):
    if r < 0:
        group[i] = set([i])
for i, r in enumerate(uni.root):
    if r > 0:
        w = uni.Find_Root(i)
        group[w].add(i)

ans = 0
for k, v in group.items():
    if k == 0:
        continue
    L = set()
    for ind in v:
        L.add(P[ind-1])
    ans += len(v & L)
print(ans)

Measured memory_bytes: 65832
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,m;
  cin >>n>>m;
  vector<int>vec(m);
  rep(i,m){
    int k;
    cin >>k;
    rep(j,k){
      int s;
      cin >> s;
      s--;
      vec[i]|=1<<s;
    }
  }
  vector<int>p(m);
  rep(i,m)cin>>p[i];
  
  int ans=0;
  for(int bit=0;bit<(1<<n);bit++){
    int sum=0;
    rep(j,m){
      int s=bit&vec[j];
      int cnt=__builtin_popcount(s);
      if(cnt%2==p[j])sum++;
    }
    if(sum==m)ans++;
  }
  cout << ans << endl; 
          
}

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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = MOD - 2;

string s;
int x, y;
vector<int> yoko, tate;
bool dp[8001][16001];

void dpinit(void){
    rep(i, 8001){
        rep(j, 16001){
            dp[i][j] = false;
        }
    }
    return;
}

bool solve(void){
    dpinit();
    cin >> s;
    if(s[s.size()-1] != 'T'){
        s.push_back('T');
    }
    cin >> x >> y;
    x += 8000;
    y += 8000;
    int dir = -1, cnt = 8000;
    rep(i, s.size()){
        if(s[i] == 'F'){
            cnt++;
        }else{
            if(dir == -1){
                dp[0][cnt] = true;
                dir = 1;
            }else if(dir == 0){
                yoko.push_back(cnt);
                dir = 1;
            }else{
                tate.push_back(cnt);
                dir = 0;
            }
            cnt = 0;
        }
    }
    REP(i, 1, yoko.size()+1){
        rep(j, 16001){
            if(j >= yoko[i-1]){
                dp[i][j] = dp[i][j] || dp[i-1][j-yoko[i-1]];
            }
            if(j + yoko[i-1] <= 16000){
                dp[i][j] = dp[i][j] || dp[i-1][j+yoko[i-1]];
            }
        }
    }
    if(!dp[yoko.size()][x]){
        return false;
    }
    dpinit();
    dp[0][8000] = true;
    REP(i, 1, tate.size()+1){
        rep(j, 16001){
            if(j >= tate[i-1]){
                dp[i][j] = dp[i][j] || dp[i-1][j-tate[i-1]];
            }
            if(j + tate[i-1] <= 16000){
                dp[i][j] = dp[i][j] || dp[i-1][j+tate[i-1]];
            }
        }
    }
    if(!dp[tate.size()][y]){
        return false;
    }
    return true;
}

int main(){
    if(solve()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define INF 1e9
using namespace std;

#define REPR(i, n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 二項係数ライブラリ
long long combination(int n, int k) {
    static const int maxi = 1e6 + 1;
    static vector<ll> fac(maxi, 0), finv(maxi, 0), inv(maxi, 0);
    static const int mod = 1e9 + 7;
    if (fac[0] == 0) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < maxi; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


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

    vector<ll> As(N);
    REP(i, N) cin >> As[i];

    sort(ALL(As));

    ll sum_maxS = 0;
    // calc sum(maxS)
    FOR(i, K - 1, N) {
        sum_maxS += As[i] * combination(i, K - 1);
        sum_maxS %= ll(INF + 7);
        sum_maxS = sum_maxS < 0 ? sum_maxS+ll(INF)+7 : sum_maxS;
    }

    ll sum_minS = 0;
    // calc sum(minS)
    REP(i, N - (K - 1)) {
        sum_minS += As[i] * combination(N - (i + 1), K - 1);
        sum_minS %= ll(INF + 7);
        sum_minS = sum_minS < 0 ? sum_minS+ll(INF)+7 : sum_minS;
    }
    ll ans = sum_maxS - sum_minS < 0 ? (sum_maxS - sum_minS)+(ll)INF+7 : sum_maxS - sum_minS;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 24448
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int a[150];
int n,s[2];
bool cmp(int a,int b){
	return a>b;
}
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++){
		if(i&1)	
			s[1]+=a[i];
		else
			s[0]+=a[i];
	}
	printf("%d\n",abs(s[0]-s[1]));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void read(int &x){
    char c=getchar();
    int p=1;
    x=0;
    while(!isdigit(c)){
        if(c=='-')p=-1;
        c=getchar();
    }
    while(isdigit(c)){
        x=(x<<1)+(x<<3)+(c^'0');
        c=getchar();
    }
    x*=p;
}
int n;
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    read(n);
    if(n==3){
        cout<<"2 5 63"<<endl;
        return 0;
    }
    for(register int i=min(n-1,15000);i>=max(1,n-5000);--i){
        if((n-i)%2==0&&(i%3==0||i%3==2)){
            for(register int j=1;j<=i;++j){
                printf("%d ",j*2);
            }
            for(register int j=1;j<=n-i;++j){
                printf("%d ",j*6-3);
            }
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e6; 
const long long Mod=(1e9)+7;
int n,m;
char s[Max_N+10];
long long ans=0,p[Max_N*2+10]={},inv[Max_N*2+10]={};
inline long long Mul(int x,int y){
	long long a=1,b=x;
	for(;y;b=b*b%Mod,y>>=1) if(y&1) a=a*b%Mod;
	return a; 
}
inline long long C(int n,int m){
	return p[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main(){
	scanf("%d",&n); scanf("%s",s); m=strlen(s);
	p[0]=1; for(int i=1;i<=n+m;i++) p[i]=p[i-1]*i%Mod;
	inv[0]=inv[1]=1; for(int i=2;i<=n+m;i++) inv[i]=inv[Mod%i]*(Mod-Mod/i)%Mod;
	for(int i=1;i<=n+m;i++) inv[i]=inv[i-1]*inv[i]%Mod;
	for(int i=0;i<=n;i++) ans+=C(n+m-i-1,m-1)*Mul(26,i)%Mod*Mul(25,n-i)%Mod,ans%=Mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 35972
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2)%mod;}
void comp() {
	ll i,j,k,m,n;
	cin>>n;
	vector<ll>v1;
	ll sum=0;
	fl(i,n) {
		cin>>j;
		v1.pb(j);
	}
	sort(all(v1));
	sum+=v1[n-1];
	ll temp=n-2;
	k=n-2;
	while(temp>0) {
		sum+=v1[k];
		temp--;
		if(temp==0) break;
		sum+=v1[k];
		temp--;
		k--; 
	}
	cout<<sum<<"\n";
}
int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

Measured memory_bytes: 5324
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int H, W;
const int MAX_H=2000;
string S[MAX_H];

int main() {
  cin >> H >> W;
  for(int i=0; i<H; i++) cin >> S[i];

  vector<vector<int>> T(H, vector<int>(W, 0)), U(H, vector<int>(W, 0));

  for(int i=0; i<H; i++){
    int cnt = 0;
    for(int j=0; j<W; j++){
      if(S[i][j] == '#'){
        T[i][j] = -1;
        for(int k=1; k<=cnt; k++) T[i][j-k] = cnt;
        cnt = 0;
      }
      else{
        cnt++;
      }
      if(j == W-1) for(int k=0; k<cnt; k++) T[i][j-k] = cnt;
    }
  }

  for(int i=0; i<W; i++){
    int cnt = 0;
    for(int j=0; j<H; j++){
      if(S[j][i] == '#'){
        U[j][i] = -1;
        for(int k=1; k<=cnt; k++) U[j-k][i] = cnt;
        cnt = 0;
      }
      else{
        cnt++;
      }
      if(j == H-1) for(int k=0; k<cnt; k++) U[j-k][i] = cnt;
    }
  }


  // for(int i=0; i<H; i++){
  //   for(int j=0; j<W; j++){
  //     cout << U[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  int ans=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j] != '#') ans = max(ans, T[i][j] + U[i][j] - 1);
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
const int N=101;

string arr[N];
int solve()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
        cout<<arr[i];
    return 0;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt" ,"r" ,stdin);
    //freopen("output.txt" ,"w" ,stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   // int t;
   // cin>>t;
   // while(t--)
        solve();

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    long long int a=1,b=n,ans=1+n-2;
    for(long long int i=floor(sqrt(n));i>=2;i--)
    {
        if(n%i==0)
        {
            a=i;b=n/i;
            ans=a+b-2;
            cout<<ans;return;
        }
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3708
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner io = new Scanner(System.in);
		int N = io.nextInt();
		int M = io.nextInt();
		ArrayList<LinkedList<Integer>> favor = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			favor.add(new LinkedList<Integer>());
			for (int j = 0; j < M; j++) {
				favor.get(i).offer(io.nextInt());
			}
		}
		boolean[] fire = new boolean[M+1];//1.2...M
		int ans = Integer.MAX_VALUE;
		while(favor.get(0).size()>0){
			int[] count = new int[M+1];
			int max = 0;
			int maxNum = 0;
			for (int i = 0; i < N; i++) {
				int num = favor.get(i).peek();
				count[num] ++;
				if(count[num]>max){
					max = count[num];
					maxNum = num;
				}
			}
			ans = Math.min(ans, max);
			fire[maxNum] = true;
			for(int i=0;i<N;i++){
				LinkedList<Integer> now = favor.get(i);
				while(now.size()>0 && fire[now.peek()]) now.poll();
			}
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 63300
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
        int b = scan.nextInt();
      
		int sum1 = 0;
		int a1 = a;
      	int b1 = b;
      
      	sum1=a1;
        a1=a1-1;
      
      	if(a1>=b1)
          sum1=sum1+a1;
        else
          sum1=sum1+b1;
       
      int sum2 = 0;
		int a2 = a;
      	int b2 = b;
      
      	sum2=b2;
        b2=b2-1;
      
      	if(a2>=b2)
          sum2=sum2+a2;
      else
        sum2=sum2+b2;
      
      
      if(sum1>=sum2)
        		System.out.println(sum1);
      else
        		System.out.println(sum2);
        
 
 
	}
}

Measured memory_bytes: 21588
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		while(n-- != 0)
		{
			String str = stdIn.next();
			Deque<Character> train = new ArrayDeque<Character>();
			Set<Character> marked = new TreeSet<Character>();
			train.addFirst(str.charAt(0));
			marked.add(str.charAt(0));
			for(int i = 1; i < str.length(); i += 3)
			{
				if(str.charAt(i) == '-' && str.charAt(i + 1) == '>')
				{
					if(!marked.contains(str.charAt(i + 2)))
					{
						marked.add(str.charAt(i + 2));
						train.addLast(str.charAt(i + 2));
					}
				}
				else if(str.charAt(i) == '<' && str.charAt(i + 1) == '-')
				{
					if(!marked.contains(str.charAt(i + 2)))
					{
						marked.add(str.charAt(i + 2));
						train.addFirst(str.charAt(i + 2));
					}
				}
			}
			Iterator it = train.iterator();
			while(it.hasNext())
			{
				System.out.print(it.next());
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 12000
ABCD = str(input())
n = len(ABCD)-1
ABCD_ = ''
output = ''
for i in range(2**n):
  ABCD_ = ABCD[0]
  for j in range(n):
    if ((i  >> j)&1) == 1:
      ABCD_ = ABCD_ + '+' + ABCD[j+1]
    else:
      ABCD_ = ABCD_ + '-' + ABCD[j+1]
  if eval(ABCD_) == 7:
    output = ABCD_ + '=7'
print(output)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pa pair<int,int>
#define pii pair<ll,ll>
#define st first
#define nd second
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x...) cerr<<#x<<" = "<<x<<"\n";
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
const int MAX=100005;
const int inf=1e9+9;
int a[MAX],b[MAX];
int ans=inf;
int minimum1=inf,minimum2=inf;
int main()
{
    BOOST;
    int n,m,k;
    cin>>n>>m>>k;
    for (int i=1;i<=n;i++)cin>>a[i],minimum1=min(minimum1,a[i]);
    for (int i=1;i<=m;i++)cin>>b[i],minimum2=min(minimum2,b[i]);
    ans=min(ans,minimum1+minimum2);
    for (int s=1;s<=k;s++)
    {
        int i,j,c;
        cin>>i>>j>>c;
        if (a[i]+b[j]-c<ans)ans=a[i]+b[j]-c;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=200005,mod=998244353;
char s[N];
int f[N][3][3];
int power(int x,int y)
{
	int s=1;
	for(;y;y/=2,x=1ll*x*x%mod)
		if(y&1) 
			s=1ll*s*x%mod;
	return s;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(n==2)
	{
		printf("%d\n",1+(s[1]!=s[2]));
		return 0;
	}
	if(n==3)
	{
		if(s[1]==s[2]&&s[2]==s[3]) 
			puts("1");
		else if(s[1]==s[2]||s[2]==s[3]) 
			puts("6");
		else if(s[1]==s[3]) 
			puts("7");
		else 
			puts("3");
		return 0;
	}
	int fl=1;
	for(int i=1;i<n;i++)
		if(s[i]!=s[i+1]) 
			fl=0;
	if(fl)
	{
		puts("1");
		return 0;
	}
	int ans=power(3,n-1);
	int v=0;
	for(int i=1;i<=n;i++)
		v=(v+s[i]-'a')%3;
	for(int i=0;i<3;i++)
		f[1][i][i]=1;
	for(int i=2;i<=n;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				for(int l=0;l<3;l++)
					if(k!=l)
						f[i][(j+l)%3][l]=(f[i][(j+l)%3][l]+f[i-1][j][k])%mod;
	for(int i=0;i<3;i++)
		ans=(ans+mod-f[n][v][i])%mod;
	fl=1;
	for(int i=1;i<n;i++)
		if(s[i]==s[i+1]) 
			fl=0;
	printf("%d\n",(ans+fl)%mod);
	return 0;
}


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

#define IS_DEBUG true

#define DEBUG_OUTPUT(X) if (IS_DEBUG) cout << X << endl
#define RESULT_OUTPUT(X) cout << X << endl

int main()
{
  int N;
  cin >> N;
  
  int A, B, C, D;
  D = N % 10;
  C = (N / 10) % 10;
  B = (N / 100) % 10;
  A = (N / 1000);
  
  for (int i = 0; i < 8; i++)
  {
    int result = A;
    char op1 = (i / 4) % 2 ? '+' : '-';
    char op2 = (i / 2) % 2 ? '+' : '-';
    char op3 = i % 2 ? '+' : '-';

    if (op1 == '+')
      result += B;
    else
      result -= B;
    if (op2 == '+')
      result += C;
    else
      result -= C;
    if (op3 == '+')
      result += D;
    else
      result -= D;
    
    if (result == 7)
    {
      cout << A << op1 << B << op2 << C << op3 << D << "=7" << endl;
      return 0;
    }
  }

    

	if (IS_DEBUG)
	{
		int end;
		cin >> end;
	}
	return 0;
}


Measured memory_bytes: 256
n,m=gets.split.map(&:to_i)
array=[]
n.times do
	array.push(gets.split.map(&:to_i))
end
cnt=0
for i in 0..n-1
	array[i].shift
end
array.flatten!
for i in 1..m
	cnt += 1 if array.count(i)==n
end

puts cnt

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
#define mid (l+r>>1)
const int N=2e5+5;
const int P=1e9+7;
int n,s[N],f[N],g[N];
struct Node{int x,y;}p[N],q[N];
bool cmp(Node A,Node B){return A.y^B.y?A.y<B.y:A.x<B.x;}
int Mod(int x){return x>=P?x-P:x;}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)p[i]=(Node){read(),read()};
	sort(p+1,p+n+1,cmp),s[0]=0,s[n+1]=1e9;
	for(int i=1;i<=n;i++){
		s[i]=max(s[i-1],p[i].x);
		int l=1,r=i,&t=q[i].x;
		while(l<=r)s[mid]>=p[i].x?(r=(t=mid)-1):(l=mid+1);
	}
	for(int i=n;i>=1;i--){
		s[i]=min(s[i+1],p[i].x);
		int l=i,r=n,&t=q[i].y;
		while(l<=r)s[mid]<=p[i].x?(l=(t=mid)+1):(r=mid-1);
	}
	sort(q+1,q+n+1,cmp),f[0]=g[0]=1;
	for(int i=1,j=1;i<=n;i++){
		while(j<=n&&q[j].y==i){
			int l=q[j++].x;
			f[i]=Mod(f[i]*2%P+Mod(g[i-1]+P-(l<=1?0:g[l-2])));
		}g[i]=Mod(g[i-1]+f[i]);
	}printf("%d",f[n]);
	return 0;
}


Measured memory_bytes: 9104
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	long long int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	long long int ans = 0;
	if(2 * c <= a + b){
		ans += 2 * c * min(x, y);
		if(x > y){
			if (2 * c <= a) ans += 2 * c * (x - y);
			else ans += a * (x - y);
		} else {
			if(2 * c <= b) ans += 2 * c * (y - x);
			else ans += b * (y - x);
		}
	} else {
		ans = a * x + b * y;
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card  L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for(i=0; i < n2; i++)R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    
    i = j = 0;
    for (k = left; k < right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for( j = p; j < r; j++){
        if(A[j].value <= x.value){
            i++;
            t = A[i]; A[i]=A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if(p < r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q + 1, r);
    }
}


int main(){
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d", &n);
    
    for (i =0; i < n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }
    
    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);
    
    for(i=0; i<n; i++){
        if(A[i].suit  != B[i].suit ) stable = 0;
    }
    
    if ( stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    
    return 0;
    
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a[ohara],b[ohara],c[ohara],d[ohara],cmp,cmpp,m,h,w,x,y,sum=0,pos,par1[ohara],ran1[ohara],par2[ohara],ran2[ohara],k,l;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

void init1(int nn) {
	for (int i=0; i<nn; i++) {
		par1[i] = i;
		ran1[i] = 0;
	}
}//初期化

ll root1(ll xx){
    if(par1[xx]==xx){
        return xx;
    }
    else{
        return par1[xx]=root1(par1[xx]);
    }
}
//木の根を求めている。
 
void unite1(ll xx,ll yy){
    xx=root1(xx);
    yy=root1(yy);
    if(xx==yy)return;
    
    if(ran1[xx]<ran1[yy]){
        par1[xx]=yy;
    }
    else{
        par1[yy]=xx;
        if(ran1[xx]==ran1[yy])ran1[xx]++;
    }
}
//xとyの属する集合を併合

void init2(int nn) {
	for (int i=0; i<nn; i++) {
		par2[i] = i;
		ran2[i] = 0;
	}
}//初期化

ll root2(ll xx){
    if(par2[xx]==xx){
        return xx;
    }
    else{
        return par2[xx]=root2(par2[xx]);
    }
}
//木の根を求めている。
 
void unite2(ll xx,ll yy){
    xx=root2(xx);
    yy=root2(yy);
    if(xx==yy)return;
    
    if(ran2[xx]<ran2[yy]){
        par2[xx]=yy;
    }
    else{
        par2[yy]=xx;
        if(ran2[xx]==ran2[yy])ran2[xx]++;
    }
}
//xとyの属する集合を併合

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>k>>l;
    init1(n+2),init2(n+2);
    rep(i,k){
        cin>>a[i]>>b[i];
        unite1(a[i],b[i]);
    }
    rep(i,l){
        cin>>c[i]>>d[i];
        unite2(c[i],d[i]);
    }
    map<pair<ll,ll>,ll> mp;
    rep(i,n){
        mp[{root1(i+1),root2(i+1)}]++;
    }
    rep(i,n){
        cout<<mp[{root1(i+1),root2(i+1)}];
        if(i==n-1)cout<<"\n";
        else cout<<" ";
    }
    return 0;
}


Measured memory_bytes: 38144
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int main(void) {
    int num, rem;
    get_int2(&num, &rem);
    int64_t ans = 0;
    if(rem==0) {
        ans = (int64_t)num*num;
        goto finish;
    }

    int b;
    for(b = rem+1; b <= num; b++) {
        // b+rem, b+rem+1, ...b+(b-1)
        int res = num/b;
        int re = num%b;
        int cnt = (re-rem+1);
        if(cnt <= 0) cnt = 0;
#ifdef DEBUG
        printf("%d: %d\n", b, res*(b-rem)+cnt);
#endif
        ans += (int64_t)res * (b-rem) + cnt;
    }
finish:
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void yn(bool ok){if(ok) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int cnt=0;
    rep(i,s.size()) cnt+=s[i]-'0';
    string ans;
    if(cnt%9==0) ans="Yes";
    else ans="No";
    out(ans);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3724
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
class PQ
  attr_reader :elements
  def initialize(array = nil, &block)
    @elements = [nil]
    array.each{|e| push(e)} if array
    @compare_func = block
  end

  def push(element)
    @elements << element
    bubble_up(@elements.size - 1)
  end

  def pop
    swap(1, @elements.size - 1)
    max = @elements.pop
    bubble_down(1)
    max
  end

  def size() @elements.size - 1 end
  def top() @elements[1] end
  def empty?() @elements.size == 1 end

  private

  def compare(a, b)
    @compare_func.call(a, b)
  end

  def bubble_up(idx)
    parent_idx = idx / 2
    return if idx <= 1
    return if compare(@elements[parent_idx], @elements[idx])

    swap(idx, parent_idx)
    bubble_up(parent_idx)
  end

  def bubble_down(idx)
    child_idx = (idx * 2)
    return if child_idx > @elements.size - 1

    not_the_last_element = child_idx < @elements.size - 1
    left_element = @elements[child_idx]
    right_element = @elements[child_idx + 1]
    child_idx += 1 if not_the_last_element && compare(right_element, left_element)

    return if compare(@elements[idx], @elements[child_idx])

    swap(idx, child_idx)
    bubble_down(child_idx)
  end

  def swap(source, target)
    @elements[source], @elements[target] = @elements[target], @elements[source]
  end
end
t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i

  left  = []
  right = []
  ans = 0
  n.times do
    k, l, r = gets.chomp.split.map(&:to_i)
    ans += [l, r].min
    if l >= r
      left.push [k, l-r]
    else
      right.push [k, r-l]
    end
  end

  h = Hash.new{|h,k| h[k] = []}
  left.each do |k, lr|
    h[k].push lr
  end

  # p h
  pq = PQ.new{|a,b| a > b}
  n.downto(1) do |i|
    h[i].each{|num| pq.push num}
    ans += pq.pop unless pq.empty?
  end

  h = Hash.new{|h,k| h[k] = []}
  right.each do |k, lr|
    h[k].push lr
  end

  # p h
  pq = PQ.new{|a,b| a > b}
  1.upto(n) do |i|
    h[i-1].each{|num| pq.push num}
    ans += pq.pop unless pq.empty?
  end

  puts ans
end


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

class union_find {
	vector<int> par;
	int find(int a) {
		return par[a] < 0 ? a : par[a] = find(par[a]);
	}
public:
	union_find(int n) : par(n, -1) {}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (par[a] < par[b]) {
			par[a] += par[b];
			par[b] = a;
		}
		else {
			par[b] += par[a];
			par[a] = b;
		}
	}
	int size(int a) {
		return -par[find(a)];
	}
};

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i]; --p[i];
	}
	union_find uf(N);
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y; --x, --y;
		uf.unite(p[x], p[y]);
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += uf.same(i, p[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
module ABC064

	! <module>s to import
	use, intrinsic :: iso_fortran_env


	! require all variables to be explicitly declared
	implicit none


	! accessibility of <subroutine>s and <function>s in this <module>
	public  :: ABC064_A


	! contained <subroutine>s and <function>s are below
	contains


	subroutine ABC064_A

		! variables for this <subroutine>
		character( len=3, kind=1 ) :: stat
		integer( kind= INT16 )     :: r, g, b, target

		! STEP.01
		! read out the target positive integers
		read *, r, g, b

		! STEP.02
		! judge whether the target integer is the multiplie of 4 or not
		if( mod( 10*((10*r)+g)+b, 4 ) .eq. 0 ) then
			stat = 'YES'
		else
			stat = 'NO'
		end if

		! STEP.03
		! output the result
		write( unit=OUTPUT_UNIT, fmt='(A)', advance='yes' ) trim( stat )

		! STEP.END
		return

	end subroutine ABC064_A

end module ABC064


program main

	! <module>s to import
	use, non_intrinsic :: ABC064

	! require all variables to be explicitly declared
	implicit none

	call ABC064_A


end program main


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

    using namespace std;

    int main()
    {
      int N, C[500], S[500], F[500];

      cin >> N;
      for (int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
      }
      for (int i = 0; i < N; i++) {
        int cur = 0;
        for(int j = i; j < N - 1; j++) {
          cur = max(cur, S[j]);
          cur = (cur + F[j] - 1) / F[j] * F[j] + C[j];
        }
        cout << cur << endl;
      }
    }


Measured memory_bytes: 256
[N,K]=[int(x) for x in raw_input().split()]
Dlist=raw_input().split()

ans=0
while(1):
    ans+=1
    if ans>=N:
        anstr=str(ans)
        Din=0
        for D in Dlist:
            if D in anstr:
                Din=1
        if not Din:
            print ans
            break
            

Measured memory_bytes: 2568
def days(m,d)
  d + [0,31,28,31,30,31,30,31,31,30,31,30,31][0..m].inject(:+)
end
y,m,d=gets.split(?/).map(&:to_i)
puts days(m,d)<=days(4,30) ? :Heisei : :TBD

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

/*
int	gcd(int A, int B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}
*/

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<int> A(N, 0);
	vector<int> B(N, 0);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	for (int i=0; i<N; i++)
		cin >>B.at(i);
	int SA=0;
	int SB=0;
	while (prev_permutation(A.begin(), A.end()))
		SA++;
	while (prev_permutation(B.begin(), B.end()))
		SB++;
	cout <<abs(SA-SB) <<endl;
	return 0;
}



Measured memory_bytes: 256
use strict;
use warnings;
use utf8;


my ($A) = split /\s/, <STDIN>;
my ($B) = split /\s/, <STDIN>;
my ($C) = split /\s/, <STDIN>;
my ($X) = split /\s/, <STDIN>;


my @patterns;
for (my $cc = 0; $cc <= $C; $cc++) {
    for (my $bb = 0; $bb <= $B; $bb++) {
        for (my $aa = 0; $aa <= $A; $aa++) {
            my $sum = $aa * 500 + $bb * 100 + $cc * 50;
            if ($sum == $X) {
                push @patterns, $sum;
            }
        }
    }
}

printf "%s\n", scalar @patterns;


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    map<pair<char,char>,ll>lol;
    rep(i,1,n+1)
    {
        string s=to_string(i);
        // cout<<s[0]<<" "<<s.back()<<endl;
        lol[{s[0],s.back()}]++;
    }
    // for(auto u:lol)
    // {
    //     cout<<u.F.F<<" "<<u.F.S<<" "<<u.S<<endl;
    // }
    ll ans=0;
    ll res=0;
    for(auto u:lol)
    {
        if(u.F.F==u.F.S)
        {
            ans+=u.S*u.S;
        }
        else
        {
            res+=u.S*lol[{u.F.S,u.F.F}];
        }
    }
    cout<<ans+res<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,c;
	cin >>a >>b >>c;
		if(a%2 || b%2 || c%2){puts("0"); return 0;}
	
	int ans =0;
	while(1){
		
		int oa=a, ob=b, oc=c;
		a = ob/2 + oc/2;
		b = oa/2 + oc/2;
		c = oa/2 + ob/2;
		ans++;
		if(ans >=2000000) {puts("-1"); return 0;}
		if(a%2 || b%2 || c%2) break;
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!
ll dfs(ll S, ll i, ll sum);
int main(void){
    ll S;
    scanf("%lld", &S);
    printf("%lld\n", dfs(S, 10, 0));
    return 0;
}
ll dfs(ll S, ll i, ll sum){
    if(S/i == 0) return S+sum;
    return dfs(S/i, 10, sum+S%i) + dfs(S, i*10, sum);
}
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;

int main() {
  string s;
  cin >> s;

  // 移動のステップ
  vector<int> ans(s.size(), 0);

  for (int i = 0; i < s.size(); i++) {
    // L が出てくるまで進む
    int l = 0;
    while (s[i + l] != 'L') {
      l++;
    }
    if (l == 0) {
      continue;
    }

    for (int j = 0; j < l; j++) {
      if (abs(l - j) % 2 == 0) {
        ans[i + l]++;
      } else {
        ans[i + l - 1]++;
      }
    }
    i += l;
  }

  for (int i = s.size() - 1; i > 0; i--) {
    // R が出てくるまで進む
    int r = 0;
    while (s[i - r] != 'R') {
      r++;
    }
    if (r == 0) {
      continue;
    }

    for (int j = 0; j < r; j++) {
      if (abs(r - j) % 2 == 0) {
        ans[i - r]++;
      } else {
        ans[i - r + 1]++;
      }
    }
    i -= r;
  }

  for (size_t i = 0; i < s.size(); i++) {
    cout << ans[i];
    if (i == s.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;


inline int read(char *s){
  char c=getchar(); int len=0;
  for (;!(c=='<' || c=='>');c=getchar());
  for (;c=='<' || c=='>';s[++len]=c,c=getchar()); return len;
}

int n;

char S[100005];
int a[100005];
int pnt;
char s[100005];

int main(){
  scanf("%d",&n);
  read(S);
  for (int i=1;i<=n;i++)
    if (S[i]!=S[i-1])
      s[++pnt]=S[i],a[pnt]=1;
    else
      a[pnt]++;
  int ans=n;
  int maxv=0;
  if (s[1]=='<')
    maxv=max(maxv,a[1]),ans-=a[1];
  if (s[pnt]=='>')
    maxv=max(maxv,a[pnt]),ans-=a[pnt];
  ans+=maxv;
  printf("%d\n",ans);
}

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

using namespace std;

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

    int d[105];
    for(int i = 0;i < n; i++){
        cin >> d[i];
    }

    set<int> s;
    for(int i = 0; i < n; i++){
        s.insert(d[i]);
    }
    
    cout << s.size() << endl;
}

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())


ll n,k;
long double m=0,t=0;
signed main(){
	cin >> n >> k;
	vector<ll> p(n);
	vector<long double> S(n);

	REP(i,n){
		cin >> p.at(i);

		if(i==0) S.at(i) = (p.at(i)+1)/2.0;
		if(i>0) S.at(i) = S.at(i-1) + (p.at(i)+1)/2.0;

		// cout << (p.at(i)+1)/2.0 << endl;
	}

	REP(i,n-k+1){
		if(i==0) t=S.at(k-1);
		if(i>0) t=S.at(i+k-1)-S.at(i-1);
		// cout << t << endl;
		if(m<t) m=t;
	}

	cout << fixed << m << endl;


	return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001001001;
const ll MOD = 1000000007;

ll N, M, ans=0, tmp=0;
vector<vector<pair<ll,ll>>> G;

signed main(){
    cin >> N >> M;
    G.resize(N);
    vector<ll> dist(N, INF);
    dist[0] = 0;
    for(int i=0;i<M;i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        c = -c;
        G[a].push_back(make_pair(b,c));
    }
    ll state = 0;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            if (dist[j] >= INF/2) continue;
            for(int l=0;l<G[j].size();l++) {
                if(dist[G[j][l].first]>dist[j]+G[j][l].second) {
                    dist[G[j][l].first]=dist[j]+G[j][l].second;
                    if(i==N-1&&G[j][l].first==N-1) state++;
                }
            }
        }
    }
    if(state==0) cout << -dist[N-1] << endl;
    else cout << "inf" << endl;
    return 0;
}

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

using namespace std;

int main()
{
    string a, b;
    cin >> a;
    cin >> b;
    string ans;

    int n = a.compare(b);

    if (a.size() > b.size()) ans = "GREATER";
    else if (a.size() < b.size()) ans = "LESS";
    else {
        if (n == 0) ans = "EQUAL";
        else if (n < 0) ans = "LESS";
        else ans = "GREATER";
    }

    cout << ans << endl;

    return 0;
}
     

Measured memory_bytes: 256
// A0J 1160 How Many Islands?

#include <iostream>

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

using namespace std;

int map[51][51];
int moumita[51][51];
int w,h;

bool check(int j, int k){
	if (j>=0 && j<h && k>=0 && k<w && map[j][k]==1 && !moumita[j][k]) return true;
	else return false;
}

int dfs(int j, int k){
	moumita[j][k] = true;
	
	if (check(j-1,k-1)) dfs(j-1,k-1);
	if (check(j-1,k)) dfs(j-1,k);
	if (check(j-1,k+1)) dfs(j-1,k+1);
	if (check(j,k-1)) dfs(j,k-1);
	if (check(j,k+1)) dfs(j,k+1);
	if (check(j+1,k-1)) dfs(j+1,k-1);
	if (check(j+1,k)) dfs(j+1,k);
	if (check(j+1,k+1)) dfs(j+1,k+1);
	
	return 1;
}

int main(){
	while (true){
		int ans;
		ans = 0;
		cin >> w >> h;
		
		if (w==0 && h==0) break;
		
		REP(j,h){
			REP(k,w){
				cin >> map[j][k];
				moumita[j][k] = false;
			}
		}
		
		REP(j,h){
			REP(k,w){
				if (check(j,k))	ans += dfs(j,k);
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3300
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
int K, N, A[maxn];
int main()
{
    scanf("%d %d", &K, &N);
    for(int i = 1; i <= N; i++)
        scanf("%d", &A[i]);
    int ans = K - (A[N] - A[1]);
    for(int i = 2; i <= N; i++)
        ans = max(ans, A[i] - A[i-1]);
    printf("%d", K - ans);
    return 0;
}


Measured memory_bytes: 1024
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ManavJ07▒▀██████▄
░███▀▒▒▒▒BITS▒▒▒▒▒▒▀█████
░▐██▒▒▒.........▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define endl "\n"
#define MOD 998244353
#define nl cout<<"\n"
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i];nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
    ll N,M;
    cin>>N>>M;
    if(N!=1&&M!=1)
        cout<<1;
    else if(N!=2&&M!=2)
        cout<<2;
    else
        cout<<3;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n, a, k, br = 0;
	cin >> n >> k;
	for(long long i = 0; i < n; ++i){
		cin >> a;
		if(a >= k) ++br;
	}
	cout << br;

	return 0;
}



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

bool darray[10] = {false};
bool check(int num){
  while(num){
    if(darray[num % 10]){
      return false;
    }
    num /= 10;
  }
  return true;
}

int main(){
    int money, N;
  	cin>>money>>N;

  	for(int i = 0; i<N;i++){
      int t;
      cin>>t;
      darray[t] = true;
    }
  
  	for(int i = money;;i++){
 		if(check(i)){
          cout<<i<<endl;
          break;
        }
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    if((n & (n - 1)) == 0) finish("No");
    cout << "Yes\n";
    cout << "1 2\n2 3\n3 " << n + 1 << "\n" << n + 1 << " " << n + 2 << "\n" << n + 2 << " " << n + 3 << "\n";
    for(int i = 4 ; i + 1 <= n ; i += 2){
        cout << i + 1 << " " << i << "\n" << i << " 1\n1 " << n + i + 1 << "\n" << n + i + 1 << " " << n + i << "\n";
    }
    if(n % 2 == 0){
        for(int i = 2 ; i < n ; i++){
            int j = n ^ 1 ^ i;
            if(1 < j && j < n){
                cout << n << " " << i + n * (i % 2) << "\n" << j + n * (j % 2) << " " << n + n << "\n";
                break;
            }
        }
    }
}


Measured memory_bytes: 2304