akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define in insert
#define ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf(a) printf("%d ",a)
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
//#define scan(v) for(int i = 0; i<n; i++){int x;cin>>x;v.pb(x);}
#define pi 2 * acos (0.0)
#define inf 1e9
#define co cout
#define en '\n'
#define re return
#define con continue
#define dbg cout<<"___________ok____________"<<endl;
#define yes() printf("YES\n")
#define no() puts("NO\n")
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define all(v) v.begin(), v.end()
#define unq(a) sort(all(a)), a.erase(unique(all(a)),a.end())
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
#define prn(v) for(auto x: v)cout<<x<<" ";
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int a[MXX];
int main ()
{

    FAST_IO;
    string s;
    cin>>s;
   // s = "*" + s;
    if(s[2] == s[3] && s[4] == s[5])co<<"Yes"<<en;
    else co<<"No"<<en;
    return 0;
}


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

using namespace std;

bool diff(vector<int> &a, vector<int> &b) {
    int sum = 0;
    for (int i = 0; i < a.size(); i++) {
        sum += ((b[i] - a[i]) * (b[i] - a[i]));
    }   
    int dist = sqrt(sum);
    if (sum == dist * dist) {
        return true;
    } else {
        return false;
    }   
}

int main()
{
    int n, d; cin >> n >> d;
    vector< vector<int> > inputs(n, vector<int> (d, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> inputs[i][j];
        }
    }   

    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += (diff(inputs[i], inputs[j]));
        }
    }   
    cout << ans << endl;
}


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

long long cnt = 0;
int count = 0;
int a[1000000] = {};
int g[100] = {};

void insertSort(int a[], int n, int g)
{
    for (int i = g; i < n; i++)
    {
        int v = a[i];
        int j = i - g;

        while (j >= 0 && a[j] > v)
        {
            a[j + g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j + g] = v;
    }
}

void shellSort(int a[], int n)
{
    int h = 1;
    g[count] = 1;

    while ((3 * h + 1) <= n)
    {
        h = 3 * h + 1;
        count++;
        g[count] = h;
    }

    for (int i = count; i >= 0; i--)
    {
        insertSort(a, n, g[i]);
    }       
}

int main()
{
    int n;

    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    
    shellSort(a, n);

    printf("%d\n", count + 1);
    for (int i = count; i >= 0; i--)
    {
        printf("%d", g[i]);
        if (i > 0)
        {
            printf(" ");
        }
    }
    printf("\n");

    printf("%d\n", cnt);

    for (int i = 0; i < n; i++)
    {
        printf("%d\n", a[i]);
//        if (a[i] > a[i + 1])
//            printf("err\n");
    }
    
    return 0;
}


Measured memory_bytes: 6632
#include <stdio.h>

int main(void)
{
	int i,j,a,b,c[3000],d[3000];

	i=0;

	scanf("%d %d", &a, &b);

	while((a!=0) || (b!=0))
	{	
		if(a>b)
		{
			c[i]=b;
			d[i]=a;
		}
		else
		{
			c[i] = a;
			d[i] = b;
		}

		i++;
		scanf("%d %d", &a, &b);
	}

	for(j=0;j<i;j++)
	{
		printf("%d %d\n", c[j], d[j]);
	}

	return 0;
}

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

signed main() {
  int n; cin >> n;
  int t[100100], x[100100], y[100100];
  t[0] = x[0] = y[0] = 0;
  for(int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];

  bool flag = true;
  for(int i = 0; i < n; i++) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if(dist > dt) flag = false;
    if(dt%2 != dist%2) flag = false;
  }

  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')cout << "vowel" << endl;
	else cout << "consonant" << endl;

	return 0;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;

  if ( m1 != m2 ) cout << 1 << endl;
  else cout << 0 << endl;
  
  return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
int main(void)
{
    int ans=0, cnteven[2], cntodd[2], i=0;
    char s[10*10*10*10*10*10];

    scanf("%s", s);
    while(s[i]!='\0'){
        if(i%2==0){
            cnteven[s[i]-'0']++;
        }
        else cntodd[s[i]-'0']++;
        i++;
    }


    ans=cnteven[0]+cntodd[1];
    if(ans>cnteven[1]+cntodd[0]) ans=cnteven[1]+cntodd[0];

                                  
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;


int main(){
    int n;
    cin>>n;
    int color[9]={0,0,0,0,0,0,0,0,0};
    rep(i,n){
        int a;cin>>a;
        if(a<=399){
            color[0]++;
        }else if(a<=799){
            color[1]++;
        }else if(a<=1199){
            color[2]++;
        }else if(a<=1599){
            color[3]++;
        }else if(a<=1999){
            color[4]++;
        }else if(a<=2399){
            color[5]++;
        }else if(a<=2799){
            color[6]++;
        }else if(a<=3199){
            color[7]++;
        }else if(a>=3200){
            color[8]++;
        }
    }
    
    int anss=0;
    
    rep(i,8){
        if(color[i]>=1){anss++;}
    }
    
    if(color[8]==0){
        cout<<anss<<" "<<anss<<endl;
        return 0;
    }
    
    
    
    int ansmin,ansmax;
    if(anss==0){
        ansmin=1;
        ansmax=color[8];
    }else{
        ansmin=anss;
        ansmax=anss+color[8];
      
    }
   
    cout<<ansmin<<" "<<ansmax<<endl;
    
    
    return 0;
}


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

long long int N, K;

int main(int argc, char **argv)
{
	cin >> N >> K;
	long long int c{0}, b{LLONG_MAX};

	long long  tmp = N / K;
	N = N - tmp * K;

	while (true)
	{
		c = abs(N - K);
		
		if (c >= N)
		{
			c = N;
			break;
		}
		else
		{
			N = c;
		}
	}	
	std::cout << c << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int X, A, B;

int main() {
  while (cin >> X >> A >> B) {
	if (B - A <= 0) cout << "delicious" << endl;
	else if (B - A <= X) cout << "safe" << endl;
	else cout << "dangerous" << endl;
  }
}
					


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

signed main(){
  int N;
  cin >> N;

  vector<vector<int>> A(3, vector<int>(N));
  for( int i = 0; i < N; i++ ){
    for( int j = 0; j < 3; j++ ){
      cin >> A.at(j).at(i);
    }
  }

  vector<vector<int>> dp(3, vector<int>(N, 0));
  //今A, B, Cを選んだ場合に取れる選択の最大値
  dp.at(0).at(0) = A.at(0).at(0);
  dp.at(1).at(0) = A.at(1).at(0);
  dp.at(2).at(0) = A.at(2).at(0);
  for( int i = 1; i < N; i++ ){
    for( int j = 0; j < 3; j++ ){
      for( int k = 0; k < 3; k++ ){
        if( j == k ) continue;
        dp.at(j).at(i) = max(dp.at(j).at(i), A.at(j).at(i)+dp.at(k).at(i-1));
      }
    }
  }
  cout << max( { dp.at(0).at(N-1), dp.at(1).at(N-1), dp.at(2).at(N-1) } ) << endl;
}


Measured memory_bytes: 5744
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			@SuppressWarnings("unchecked")
			List<Path>[] pathLists = new List[n];
			IntStream.range(0, n).forEach(i -> pathLists[i] = new ArrayList<>());
			Path[] paths = new Path[n - 1];
			IntStream.range(0, n - 1).forEach(i -> {
				int from = scanner.nextInt() - 1;
				int to = scanner.nextInt() - 1;
				paths[i] = new Path(from, to);
				pathLists[from].add(paths[i]);
				pathLists[to].add(paths[i]);
			});
			int maxColor = 0;
			int maxColorNode = 0;
			for (int node = 0; node < n; node++) {
				if (pathLists[node].size() > maxColor) {
					maxColor = pathLists[node].size();
					maxColorNode = node;
				}
			}
			paint(maxColorNode, pathLists, new boolean[n]);
			System.out.println(maxColor);
			Arrays.stream(paths).forEach(path -> System.out.println(path.color));
		}
	}

	private static void paint(int node, final List<Path>[] pathLists, boolean[] visited) {
		if (!visited[node]) {
			int color = 1;
			Set<Integer> colorSet = pathLists[node].stream().filter(path -> path.color != 0).map(path -> path.color)
					.collect(Collectors.toSet());
			for (Path path : pathLists[node]) {
				if (colorSet.contains(color)) {
					color++;
				}
				if (path.color == 0) {
					path.color = color;
					color++;
				}
			}
			visited[node] = true;
			for (Path path : pathLists[node]) {
				paint(path.getNextNode(node), pathLists, visited);
			}
		}
	}

	/**
	 * ノード間の一つのパスを表すクラス
	 */
	private static class Path {
		int node1;
		int node2;
		/** 色 */
		int color;

		Path(int node1, int node2) {
			super();
			this.node1 = node1;
			this.node2 = node2;
			this.color = 0;
		}

		int getNextNode(int currentNode) {
			if (currentNode == node1) {
				return node2;
			} else {
				return node1;
			}
		}
	}
}


Measured memory_bytes: 114572
int main(void)
{
  int n, i;

  scanf("%d", &n);

  int a[n];

  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);

  for(i = n-1; i >= 0; i--) {
    printf("%d", a[i]);
    if(i == 0) break;
    printf(" ");
  }


  printf("\n");

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int X, Y; cin >> X >> Y;
	cout << (X + Y / 2) << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;
const LL mo=1e9+7;

int n,a[maxn];

LL f[maxn],s[maxn];
int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	
	f[0]=1;
	fo(i,1,n)
	{
		f[i]=f[i-1];
		if (a[i]!=a[i-1]) (f[i]+=s[a[i]])%=mo, (s[a[i]]+=f[i-1])%=mo;
	}
	
	printf("%lld\n",f[n]);
}

Measured memory_bytes: 4096
#include <boost/multiprecision/cpp_int.hpp>
#include <math.h>
#include <stdio.h>
typedef long long ll;
ll ab(ll x) {
	return x > 0 ? x : -x;
}
ll min(ll x, ll y) {
	return x > y ? y : x;
}
ll max(ll x, ll y) {
	return x < y ? y : x;
}
int main() {
	ll x, k, d;
	scanf("%lld%lld%lld", &x, &k, &d);
	boost::multiprecision::cpp_int mx = ab(x);
	boost::multiprecision::cpp_int mk = k;
	boost::multiprecision::cpp_int md = d;
	if (mx >= mk * md) {
		printf("%lld\n", ab(ab(x) - k * d));
		return 0;
	}
	ll n, m, c;
	if (x >= 0) {
		n = x % d;
		m = n - d;
		c = x / d;
	} else {
		n = (-x) % d;
		m = n - d;
		c = (-x) / d;
	}
	// printf("%lld %lld %lld\n", n, m, c);
	if ((k - c) % 2 == 0) {
		printf("%lld\n", ab(n));
	} else {
		printf("%lld\n", ab(m));
	}
	return 0;
}

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

using str = string;
using ss = stringstream;

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

    str s,t;cin>>s>>t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());

    int ans=2;
    int i=0;

    for(;i<min(s.size(),t.size());i++)
    {
        if(s[i]<t[i]){ans=1;break;}
        if(s[i]>t[i]){ans=0;break;}
    }

    if(ans==2)
    {
        if(s.size()<t.size())ans=1;
        else ans=0;
    }

    puts(ans?"Yes":"No");

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,mx,ans,p=1e9+7,f[4020][4020],fac[500001],ny[500001],a[500001],b[500001];
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
ll C(ll x,ll y){
	return fac[x]*ny[x-y]%p*ny[y]%p;
}
int main(){
	ll i,j;
	mx=2001;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld%lld",&a[i],&b[i]);
	fac[0]=ny[0]=1;
	for(i=1;i<=500000;i++)fac[i]=fac[i-1]*i%p,ny[i]=ksm(fac[i],p-2);
	for(i=1;i<=n;i++)f[mx-a[i]][mx-b[i]]++;
	for(i=1;i<=4010;i++)
	 for(j=1;j<=4010;j++)f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%p;
	for(i=1;i<=n;i++){
		ans=(ans+f[a[i]+mx][b[i]+mx])%p;
		ans=(ans-C(a[i]*2+b[i]*2,a[i]*2)%p+p)%p;
	}
	printf("%lld",ans*ksm(2,p-2)%p);
}

Measured memory_bytes: 141312
#include<stdio.h>
main()
{
  int a;
  int b;
  int c;

  scanf("%d%d",&a,&b);
  if(a >= b)
    {
      c = b;
      b = a;
      a = c;
    } 
  while(1)
    {
      c = b % a;
      if(c == 0)
	{
	  printf("%d\n",a);
	  break;
	}
      else 
	{
	  b = a;
	  a = c;
	}
    }
  return 0;
}

Measured memory_bytes: 592
import sys
s = input()
a = []

for i in range(len(s)):
    num = int(s[i])
    a.append(num)


op = ['+', '-']

for i in range(2):
    for j in range(2):
        for k in range(2):
            temp = 0
            if op[i] == '+':
                temp = a[0] + a[1]
            else:
                temp = a[0] - a[1]
            if op[j] == '+':
                temp += a[2]
            else:
                temp -= a[2]
            if op[k] == '+':
                temp += a[3]
            else:
                temp -= a[3]

            if temp == 7:
                n1, n2, n3, n4 = map(str, [a[0], a[1], a[2], a[3]])
                #n1, n2, n3, n4 = a[0], a[1], a[2], a[3]
                print(n1 + op[i] + n2 + op[j] + n3 + op[k] + n4 + '=7')
                sys.exit()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main() {
    map<int, int> mp;
    int n, m, kn;
    int cnt=0;
    cin >> n >> m;
    for(int i=1;i<=30;i++){
        mp[i]=0;
    }
    for(int i=0;i<n;i++){
        cin >> kn;
        for(int j=0;j<kn;j++){
            int tmp;
            cin >> tmp;
            mp[tmp]++;
        }
    }
    for(int i=1;i<=30;i++){
        if(mp[i]==n){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
double eps = 0.0000001;

int main()
{
  while(true)
  {
    double x, y;
    int s;
    cin >> x >> y >> s;
    if(s == 0)
      break;
    x /= 100.0;
    y /= 100.0;
    int n = 0;
    for(int a = 1; a < s; a++)
      for(int b = 1; b < s; b++)
        if((int)(a * (1 + x) + eps) + (int)(b * (1 + x) + eps) == s)
          n = max(n, (int)(a * (1 + y) + eps) + (int)(b * (1 + y) + eps));
    cout << n << endl;
  }
}

Measured memory_bytes: 1232
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int A, B, C, X, ans = 0;

        cin >> A;
        rep(i, 26)
        {
                rep(j, 15)
                {
                        if (A == 4 * i + 7 * j)
                        {
                                ans += 1;
                        }
                }
        }
        if (ans)
                cout << "Yes" << endl;
        else
                cout << "No" << endl;

        return 0;
}


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


/*
 *A,B,C はそれぞれ大きい順にソートしておく。まず一番大きいのは A,B,C
 * それぞれの最大値をとったもの A1+B1+C1 で決まりである。ここから priority_queue をうまく用いる。
 * この次に大きいものは

    A2+B1+C1
    A1+B2+C1
    A1+B1+C2
    の 3 つの候補があるが、それぞれをキューに push しておく。このときにキューの先頭にあるものが、2 番目に大きい値になる。

    同様にその 2 番目に大きい値を pop して来て、それに対し

    A のみ index を 1 個進めて足したもの
    B のみ index を 1 個進めて足したもの
    C のみ index を 1 個進めて足したもの
    の 3 通りの値をキューに push していく。そしてこの時点でキューの先頭にあるものが 3 番目の値になる。
    以後これを繰り返して行く。注意点として、「一度 push したものは二度 push しない」という管理が必要となる。

    計算量は、

    キューから pop する回数が K 回
    その K 回それぞれについて、キューの push するのは 3 回以下なので、キューに push する回数も多くても 3K 以下
    ということで、計算量は O(KlogK) となる。
 * */

using Data = pair<ll, vector<int>>;

int main() {
    vector<long long> N(3);
    int K;
    for (int i = 0; i < 3; ++i) cin >> N[i]; cin >> K;
    vector<vector<long long> > v(3);
    for (int iter = 0; iter < 3; ++iter) {
        v[iter].resize(N[iter]);
        for (int i = 0; i < N[iter]; ++i) cin >> v[iter][i];
        sort(v[iter].begin(), v[iter].end(), greater<long long>());
    }
    priority_queue<Data> que;
    set<Data> se;
    que.push(Data(v[0][0] + v[1][0] + v[2][0], vector<int>({0, 0, 0})));
    for (int k = 0; k < K; ++k) {
        auto c = que.top();que.pop();
        cout << c.first << endl;
        
        // 次の三候補
        for (int iter = 0; iter < 3; ++iter) {
            if (c.second[iter] + 1 < N[iter]) {
                long long sum = c.first - v[iter][c.second[iter]] + v[iter][c.second[iter] + 1];
                auto num = c.second; num[iter]++;
                auto d = Data(sum, num);
                
                // すでに push されたもの以外
                if (!se.count(d)) se.insert(d), que.push(d);
            }
        }
    }
}

Measured memory_bytes: 1408
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
int dp[2010][2010] = {};
int nxt_s[2010][30] = {};
int nxt_t[2010][30] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string T = S;
    reverse(T.begin(), T.end());
    vector<int> pos_s[30], pos_t[30];
    ll N = S.size();
    rep(i,0,N) pos_s[S[i]-'a'].push_back(i);
    rep(i,0,N) pos_t[T[i]-'a'].push_back(i);
    memset(nxt_s, -1, sizeof(nxt_s));
    memset(nxt_t, -1, sizeof(nxt_t));

    dp[0][0] = 1;
    rrep(i,N-1,0){
        rep(k,0,26){
            nxt_s[i][k] = nxt_s[i+1][k];
        }
        nxt_s[i][S[i]-'a'] = i;
    }
    rrep(i,N-1,0){
        rep(k,0,26){
            nxt_t[i][k] = nxt_t[i+1][k];
        }
        nxt_t[i][T[i]-'a'] = i;
    }


    rep(i,0,N){
        rep(j,0,N){
            rep(k,0,26){
                ll ps = nxt_s[i][k];
                ll pt = nxt_t[j][k];
                if(ps != -1 && pt != -1){
                    if(ps + pt + 2 <= N){
                        dp[ps+1][pt+1] += dp[i][j];
                        dp[ps+1][pt+1] %= MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i,0,N+1){
        rep(j,0,N+1){
            if(dp[i][j] != 0 && i + j <= N){
                ll cnt = 0;
                ll lv = i, rv = N-1-j;
                rep(k,0,26){
                    ll p = upper_bound(pos_s[k].begin(), pos_s[k].end(), rv) - pos_s[k].begin();
                    ll p2 = lower_bound(pos_s[k].begin(), pos_s[k].end(), lv) - pos_s[k].begin();
                    if(p - p2 > 0) cnt++;
                }
                ans += dp[i][j] * (cnt+1);
                ans %= MOD;

            }

        }
    }
    ans--;
    print(ans);

}


Measured memory_bytes: 17488
#include <stdio.h>
#include <stdlib.h>
#define M 100001

int A[M];

long int sumA(void){
    long int sum;
    sum = 0;
    for(int i=0; i<M; i++){
        sum = sum + i*A[i];
    }
    return sum;
}

int main(void){
    for(int i=0; i<M; i++){
        A[M] = 0;
    }

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

    int tmp;

    for(int i=0; i<N; i++){
        scanf("%d", &tmp);
        A[tmp]++;
    }

    long int sum;
    sum = sumA();

    int Q, B, C;
    scanf("%d", &Q);

    for(int i=0; i<Q; i++){
        scanf("%d %d", &B, &C);
        sum += (C-B)*A[B];
        A[C] += A[B];
        A[B] = 0;
        printf("%ld\n", sum);
    }

    return 0;
}

Measured memory_bytes: 2064
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 1005
#define M 200005
#define LL long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define PB push_back
#define SZ size
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MP make_pair
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
int n, sv, W;
LL sw;
int w[N], v[N], vv[N], f[1000005];
int g[N][10005];
void up(int &x, int y){
    if(y > x) x = y;
}
int main(){
   // IN;
    SC(n); SC(W);
    FF(i, 1, n){
        SC(w[i]);
        SC(v[i]);
        vv[i] = v[i];
        sw += w[i];
        sv += v[i];
    }
    if(sw <= W){
        printf("%d\n", sv);
        return 0;
    }
    if(w[1] >= 500){
        int cnt = W / w[1];
        int tmp = W % w[1];
        if(n < cnt) cnt = n;
        int ans = 0;
        sw = 0;
        FF(i, 2, n){
            w[i] -= w[1];
            sw += w[i];
        }
        w[1] = 0;
        FF(p, 1, n){
            RR(i, cnt, 1)
                RR(j, sw, w[p])
                up(g[i][j], g[i - 1][j - w[p]] + v[p]);
        }
        FF(i, 1, cnt - 1)
            FF(j, 0, sw)
            if(g[i][j] > ans) ans = g[i][j];
        if(tmp >= sw) ans = g[cnt][sw];
        else FF(j, 0, tmp) if(g[cnt][j] > ans) ans = g[cnt][j];
        printf("%d\n", ans);
    }else {
        int ans = 0;
        FF(i, 1, n){
            RR(j, W, w[i]) f[j] = max(f[j - w[i]] + v[i], f[j]);
        }
        RR(i, W, 0) if(f[i] > ans) ans = f[i];
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2560
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    long long MX = 1e18;
    cin >> n;
    long long res = 1;
    for (int i = 0; i < n; ++i) {
        long long x;
        cin >> x;

        if (x == 0) {
            res = 0;
            continue;
        }

        if (res <= 0) {
            continue;
        }
        if (res > MX / x) {
            res = -1;
            continue;
        }
        res *= x;
    }

    if (res > MX) {
        res = -1;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r, g, b;
	r = g = b = 0;
	rep(i, s.size()){
		if(s[i] == 'R') r++;
		else if(s[i] == 'G') g++;
		else b++;
	}
	ll ans = (ll)r*g*b;
	cerr << ans << endl;
	rep(i, s.size()-1)rep2(j, i+1, s.size()){
		if(s[i] == s[j]) continue;
		int nx = i + (j-i)*2;
		if(nx >= s.size()) continue;
		if(s[i] != s[nx] && s[j] != s[nx]){
			// cerr << i << " " << j << " " << nx << endl;
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;

int main(){
	cin>>s;
	ll n=s.size(),res=0,t=0;
	for(int i=0;i<n;i++){
		if(s[i]=='A') t++;
		else if(s.substr(i,2)=="BC") res+=t,i++;
		else t=0;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    long long a, b, r, mul;
    while (cin >> a >> b) {
        mul = a * b;
        while ((r = a % b) != 0) {
            a = b;
            b = r;
        }
        cout << b << " " << mul / b << endl;
    }

    return 0;
}

Measured memory_bytes: 1156
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n, k;
	cin >> n >> k;
	cout << fixed << setprecision(20);
	long double ans = 0;
	for (int i = 1; i <= n; ++i) {
		long double percent = 1;
		int now = i;
		while (now < k) {
			percent /= 2.00000;
			now *= 2;
		}
		ans += percent / (long double)n;
	}
	cout << ans << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int a[1000100];
int main()
{
	int n,l,t,all=0;scanf("%d%d%d",&n,&l,&t);
	for (int i=0;i<n;i++)
	{
		int x,w;scanf("%d%d",&x,&w);
		if (w==1)
		{
			x+=t;
			all=(all+x/l)%n;
			a[i]=x%l;
		}
		else
		{
			x-=t;
			all=(all+x/l)%n;
			x%=l;
			if (x<0) {x+=l;all--;}
			a[i]=x;
		}
	}
	sort(a,a+n);
	if (all<0) all+=n;
	for (int i=0;i<n;i++) printf("%d\n",a[(i+all)%n]);
}

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

using namespace std;

#define all(c)	(c).begin(),(c).end()
#define rall(c)	(c).rbegin(),(c).rend()
#define rep(i,N)	for(int i=0;i<N;++i)
#define pb	push_back
#define eb	emplace_back

using ll = long long;

constexpr ll INF = 0x0fffffffffffffff;
constexpr int inf = 0x1fffffff;
constexpr double inf_l = 1e18;
constexpr ll MOD = 1000000007LL;
constexpr int mod = 1000000007;

int main()
{
	int N; cin >> N;
	cout << N*(N + 1) / 2 << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
void solve( string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
   int index = L[m][n]; 
  
   char lcs[index+1]; 
   lcs[index] =0; 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; 
          i--; j--; index--;     
      } 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   }
   cout << lcs; 
} 
  
   
int main(){
  string s1,s2;
  cin>>s1>>s2;
  int n1=s1.size(),n2=s2.size();
  
  solve(s1,s2,n1,n2);
  return 0;
}

Measured memory_bytes: 35456
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
s=gs
puts s=='ABC' ? 'ARC' : 'ABC'

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

int main()
{
	map<string, int> mp;
	int n;
	string s;
	int i, j;
	int saidai = 1;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> s;
		if (mp[s] != 0) {
			mp[s]++;
			saidai = max(saidai, mp[s]);
		}
		else {
			mp[s] = 1;
		}
	}

	vector<string> ans;

	for (auto it = mp.begin(); it!=mp.end(); it++) {
		if (it->second == saidai) {
			ans.push_back(it->first);
		}
	}

	sort(ans.begin(), ans.end());

	for (auto it = ans.begin(); it != ans.end(); it++) {
		cout << *it << endl;
	}

	return 0;
}


Measured memory_bytes: 26868
import java.util.Scanner;

public class Main {
    static public void main(String[] args) {

        int[] H = new int[10000];
        int[] W = new int[10000];
        int a = 0;
        int b = 0;
        boolean flg = true;
        boolean flg2 = true;

        Scanner s = new Scanner(System.in);
        for (int i = 0; ; i++) {
            H[i] = s.nextInt();
            W[i] = s.nextInt();
            if ((H[i] == 0) && (W[i] == 0)) {
                break;
            }
        }
        for (int I = 0; H[I] != 0; I++) {
            a = H[I];
            while (a > 0) {
                b = W[I];
                if (flg) {
                    while (b > 0) {
                        if (flg2) {
                            System.out.print('#');
                            flg2 = false;
                        } else {
                            System.out.print('.');
                            flg2 = true;
                        }
                        b--;
                    }
                    flg2 = true;
                    flg = false;
                } else {
                    while (b > 0) {
                        if (flg2) {
                            System.out.print('.');
                            flg2 = false;
                        } else {
                            System.out.print('#');
                            flg2 = true;
                        }
                        b--;
                    }
                    flg2 = true;
                    flg = true;
                }
                System.out.println("");
                a--;
            }
            flg =true;
            System.out.println("");

        }


    }
}



Measured memory_bytes: 34740
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

signed main()
{
  int n;
  scanf("%d", &n);

  int a[n];
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

  int l = *min_element(a, a+n);
  int r = *max_element(a, a+n);

  int ans = INF;
  for (int i = l; i <= r; ++i) {
    int score = 0;
    for (int j = 0; j < n; ++j) {
      int d = a[j] - i;
      score += d * d;
    }
    ans = min(ans, score);
  }

  printf("%d\n", ans);

  return (0);
}

Measured memory_bytes: 3824
n,Y=map(int,input().split())

for y in range(n+1):
    for z in range(n-y+1):
        x = n-(y+z)
        if 5*y+9*z == n*10-Y*(10**(-3)) and x >= 0:
            print(x,end="  ")
            print(y,end=" ")
            print(z,end="")
            exit()

print("-1 -1 -1")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    
    ll n,m;
    cin>>n>>m;
    ll ans=0ll;
    ll num=min(n,m/2ll);
    ans+=num;
    m-=num*2ll;
    ans+=m/4ll;
    cout<<ans<<endl;
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    if n%2 == 1:
        print(0)
    else:
        res = 0
        base = 10
        while base <= n:
            res += n//base
            base *= 5
        print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vp;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define M 1000000007
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)

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

void Main(){
  ll n;
  cin>>n;
  string s = to_string(n);
  if(s.length()>=2){
    bool ch=false;
    rep(i,s.length()-1){
      if(s[i+1]!='9') ch = true;
    }    
    if(ch){
      s[0]--;
      rep(i,s.length()-1){
        s[i+1]='9';
      }      
    }
  }
  int ans=0;
  for(auto a:s) ans+=a-'0';
  cout<< ans <<endl;
} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    static final long MOD = 1000000007;

    static long modPow(long x, long n, long mod) {
        long sum = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                sum = sum * x % mod;
            }
            x = x * x % mod;
            n >>= 1;
        }
        return sum;
    }

    static long modComb(long n, long r, long mod) {
        long ans = 1;
        long y = 1;
        for (int i = 1; i <= r; i++) {
            ans = ans * (n - i + 1) % mod;
            y = y * i % mod;
        }
        return ans = ans * modPow(y, mod - 2, mod) % mod;
    }

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        long n = Long.parseLong(stdIn.next());
        long a = Long.parseLong(stdIn.next());
        long b = Long.parseLong(stdIn.next());

        long all = modPow(2, n, MOD) - 1;
        long nCa = modComb(n, a, MOD);
        long nCb = modComb(n, b, MOD);

        System.out.println((all - nCa - nCb + 3 * MOD) % MOD);
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
char s[110];

int main()
{
    int i,cnt;

    while(scanf("%s",s) != EOF)
    {
        cnt = 0;
        for(i = 1;s[i+1] != '\0';i++)
        {
            cnt++;
        }
        printf("%c%d%c\n",s[0],cnt,s[i]);
    }

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>

template <typename T> void in(T &_){
	char c=getchar(); _=0; int fl=1;
	while(c<'0'||c>'9') fl=c=='-'?-1:fl, c=getchar();
	while(c>='0'&&c<='9') _=_*10+c-'0', c=getchar(); _*=fl;
}
template <typename T, typename... A> void in(T &_, A &...a){in(_); in(a...);}

#define MOD 1000000007

int N, M, bit[1<<15], f[16][1<<15], h[1<<15];
bool map[16][16];

int ksm(int x, int y){
	int z=1;
	for(; y; y>>=1, x=1LL*x*x%MOD) if(y&1) z=1LL*z*x%MOD;
	return z;
}
int lowbit(int x){return (x&(-x));}

int main(){
	for(int i=0; i<15; i++) bit[1<<i]=i+1;
	in(N, M);
	for(int x, y, i=1; i<=M; i++){
		in(x); in(y);
		map[x][y]=true;
	}
	for(int i=1; i<=N; i++)
		for(int j=0; j<(1<<N); j++)
			f[i][j]=f[i][j-lowbit(j)]+map[i][bit[lowbit(j)]];
	for(int i=0; i<(1<<N); i++){
		h[i]=1;
		for(int j=i&(i-1); j; j=i&(j-1))
			if(((j&1)^((j&2)>>1))==0 && (((i^j)&1)^(((i^j)&2)>>1))==0){
				int tmp=h[i^j];
				for(int k=j; k; k-=lowbit(k)) 
					tmp=1LL*tmp*ksm(2, f[bit[lowbit(k)]][i^j])%MOD;
				for(int k=i^j; k; k-=lowbit(k))
					tmp=1LL*tmp*(ksm(2, f[bit[lowbit(k)]][j])-1)%MOD;
				h[i]=(h[i]+tmp)%MOD;
			}
	}
	printf("%d\n", (ksm(2, M)-h[(1<<N)-1]+MOD)%MOD);
	return 0;
}

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

int main(){
    
	string s, t;
	cin >> s >> t;
	int ans = 0;
	if (s[0] == t[0]) { ans++; }
	if (s[1] == t[1]) { ans++; }
	if (s[2] == t[2]) { ans++; }
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace abc044_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int[] moji = new int[26];
            for (int i = 0; i < s.Length; i++)
            {
                moji[s[i] - 97]++;
            }
            bool flag = true;
            for (int i = 0; i < 26; i++)
            {
                if (moji[i] % 2 == 1)
                {
                    flag = false;
                }
            }
            Console.WriteLine(flag ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13140
N,K = map(int,input().split())
D = list(map(int,input().split()))
E = []
for i in range(10):
    if i not in D:
        E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
    if int(N[i]) not in E:
        ind = i
        break
if ind==len(N):
    print(N)
else:
    flag = 0
    x = ""
    for i in range(ind,-1,-1):
        n = int(N[i])
        for e in E:
            if e>n:
                x = N[:i]+str(e)+str(E[0])*(len(N)-i-1)
                flag = 1
                break
        if flag==1:break
    if flag==0:
        if E[0]>0:
            a = E[0]
        else:
            a = E[1]
        x = str(a)+str(E[0])*len(N)
    print(x)

Measured memory_bytes: 9196
#include <iostream>
#include <map>
using namespace std;
const int INF = (1e9);

int main(){
  int N;
  const string g = "000";
  while(cin >> N, N){
    string d, t, e, id, D;
    map<string, int> T, I, O;
    for(int i = 0; i < N; ++i){
      cin >> d >> t >> e >> id;
      if(D != d){
        D = d;
        for(auto itr = I.begin(); itr != I.end(); ++itr) itr->second = INF;
        for(auto itr = O.begin(); itr != O.end(); ++itr) itr->second = -1;
      }
      int m = stoi(t.substr(0,2))*60 + stoi(t.substr(3,2));
      if(e == "I"){
        I[id] = m;
        O[id] = INF;
      }else{
        O[id] = m;
        if(id != g && O[g] > m){
          T[id] += max(0, m - max(I[g],I[id]));
        }else if(id == g){
          for(auto itr = O.begin(); itr != O.end(); ++itr){
            id = itr->first;
            int o = itr->second;
            if(o > m){
              T[id] += max(0,m - max(I[id],I[g]));
            }
          }
        }
      }
    }
    int ans = 0;
    for(auto itr = T.begin(); itr != T.end(); ++itr){
      if(itr->first == g) continue;
      //cout << itr->first << " " << itr->second << endl;
      ans = max(ans, itr->second);
    }
    cout << ans << endl;
  }
  return 0;
}



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



int main() {
  int a,b;
  cin >> a >>b;
  cout << a*b << endl;
}

Measured memory_bytes: 3620