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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int div1(ll x){
  return x%1000000007;
}

main(){
    int st[31];
    st[0]=1;
    st[1]=1;
    st[2]=2;
    for (int i=3;i<31;i++){
        st[i]=st[i-1]+st[i-2]+st[i-3];
    }
    int n=in();
    while(n!=0){
        cout << (st[n]+3650-1)/3650 << endl;
        n=in();
    }
}


Measured memory_bytes: 2988
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  ll a[N];
  ll sum[N];
  ll tmp_sum = 0;
  for(int i=0;i<N;i++){
  	cin >> a[i];
  	tmp_sum += a[i];
  	sum[i] = tmp_sum;
  }



  ll plus = 0;

  int sgn = 1;
  /*ll dif[N+1]; //i番目以降に施される変化量
  for(int i=0;i<=N;i++) dif[i] = 0;*/
  ll dif = 0;

  for(int i=0;i<N;i++){
  	if((sum[i]+dif)*sgn<=0){
  		plus += abs(sgn-sum[i]-dif);
  		dif += sgn - sum[i]-dif;	
  	}
  	sgn *= -1;
  }


  ll minus = 0;
  sgn = -1;
 // for(int i=0;i<=N;i++) dif[i] = 0;
  dif = 0;
  for(int i=0;i<N;i++){
  	if((sum[i]+dif)*sgn<=0){
  		minus  += abs(sgn-sum[i]-dif);
  		dif += sgn - sum[i]-dif;
  	}
  	sgn *= -1;
  }

  cout << min(plus, minus) <<endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int W, H, N;
    while(cin>>W>>H>>N){
        int a, b, c;
        int x1=0, x2=W;
        int y1=0, y2=H;
        for(int i=0;i<N;i++){
            cin>>a>>b>>c;
            if(c==1){
                x1=max(x1, a);
            }
            else if(c==2){
                x2=min(x2, a);
            }
            else if(c==3){
                y1=max(y1, b);
            }
            else if(c==4){
                y2=min(y2, b);
            }
        }
        if(x2-x1>0&&y2-y1>0){
            cout<<(x2-x1)*(y2-y1)<<endl;
        }
        else  cout<<0<<endl;
    }
    return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n, start;
  vector<vector<int>> t;
  vector<int> color;
  vector<int> sum, dp, path, subp;
  Solver(LL n) : n(n), t(n), color(n), sum(n), dp(n), path(n), subp(n){};
  void dfs(int c, int p) {
    DBG(c, p)
    if (t[c].size() == 1 and t[c][0] == p) {
      //leaf
      if (color[c] == 0) {
        sum[c] = dp[c] = 1;
      }
      return;
    }
    int cnt = 0;
    for (int x : t[c]) {
      if (x != p) {
        dfs(x, c);
        if (sum[x]) cnt++;
        sum[c] += sum[x];
      }
    }
    if (cnt == 0) {
      sum[c] = dp[c] = 1 - color[c];
      return;
    }
    if (c == start) cnt--;
    sum[c] += cnt + 1;
    dp[c] = cnt + 1;
    if ((cnt + 1 + color[c]) % 2 == 0) sum[c]++, dp[c]++;
  }
  void dfs2(int c, int p) {
    if (t[c].size() == 1 and t[c][0] == p) {
      //leaf
      return;
    }
    int cnt = (c != start);
    vector<int> child;
    for (int x : t[c]) {
      if (x != p) {
        dfs2(x, c);
        if (sum[x]) {
          cnt++;
          child.push_back(x);
        }
      }
    }
    DBG(c, cnt, child)
    sort(child.begin(), child.end(), [&](int& a, int& b) { return path[a] > path[b]; });
    if (cnt <= 1) {
      return;
    } else if (child.size() == 1) {
      path[c] = path[child[0]] + (dp[c] > cnt);
      subp[c] = path[child[0]] + (dp[c] > cnt);
    } else {
      path[c] = (dp[c] > cnt) + path[child[0]];
      subp[c] = (dp[c] > cnt) + path[child[0]] + path[child[1]];
    }
  }

  void solve() {
    for (int i = 0; i < n - 1; ++i) {
      int x, y;
      cin >> x >> y;
      t[--x].push_back(--y);
      t[y].push_back(x);
    }
    DBG(t)
    for (int i = 0; i < n; ++i) {
      char tmp;
      cin >> tmp;
      color[i] = (tmp == 'B');
    }
    DBG(color)
    for (start = 0; start < n and color[start] == 1; start++) {
    }
    if (start == n) {
      cout << 0 << endl;
      return;
    }
    if (n == 1) {
      cout << 1 - color[0] << endl;
      return;
    }
    dfs(start, -1);
    DBG(sum)
    dfs2(start, -1);
    DBG(dp)
    DBG(subp)
    cout << sum[start] - *max_element(subp.begin(), subp.end()) * 2 << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 17024
#include<iostream>

using namespace std;

int main(){
    int a, b, c, d; 
    cin >> a >> b >> c >> d;
    if(abs((a-b)) <= d && abs((b-c)) <= d || abs((a-c)) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin>>n>>m;
	vector<pair<int,int> > vec(m);
	for(int i = 0; i < m; ++i){
		int l, r;
		cin>>l>>r;
		vec[i] = make_pair(l, r);
	}
	int l = -1;
	int r = n + 1;
	for(int i = 0; i < m; ++i){
		l = max(vec[i].first, l);
		r = min(vec[i].second, r);
	}
	if(l > r)cout<<0<<endl;
	else cout<<r - l + 1<<endl;
	return 0;
}


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

int main(){
  int N,K;
  cin>>N;
  cin>>K;
  int i;
  int s=1;
  
  for(i=1;i<=N;i++){
    if(s<=K){
      s=s*2;
    }
    else{
      s=s+K;
    }
  }
  cout<<s<<endl;
}

Measured memory_bytes: 384
#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
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define SIZE 26
int main(void) {
    string str;
    int k;
    cin >> str;
    int len = str.length();
    cin >> k;
    string ans;
    for(char ch: str) {
        int next_a = (SIZE - (ch - 'a'))%SIZE;
        if(next_a <= k) {
            k -= next_a;
            ch = 'a';
        }
        ans.push_back(ch);
    }
    debug("k: %d -> %s\n", k, ans.c_str());

    if(k > 0) {
        char last = ans[len-1] - 'a';
        ans[len-1] = (last + k)%SIZE + 'a';
    }

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

Measured memory_bytes: 3744
import itertools
import math

n = int(input())
xy = []
for _ in range(n):
    a = input().split()
    a[0] = int(a[0])
    a[1] = int(a[1])
    xy.append((a))

res = 0
for i in list(itertools.permutations(list(range(n)))):
    for j in range(len(i)-1):
        x1 = xy[i[j]][0]
        y1 = xy[i[j]][1]
        x2 = xy[i[j+1]][0]
        y2 = xy[i[j+1]][1]
        res += math.sqrt((x1-x2)**2 + (y1-y2)**2)

res /= math.factorial(n)

print(res)

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

int main() {
string X,Y;
  cin >>X>>Y;
  if(X[0]==Y[2] &&X[1]==Y[1]&&X[2]==Y[0]){
    cout <<"YES";
  }
  else {
    cout <<"NO";
  }

}


Measured memory_bytes: 256
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(l[k -1])

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC   
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve(ll testnum)
{
    char t;
    cin >> t;
    if(t <= 'z' && t >= 'a') {
    	cout << "a\n";
    } else {
    	cout << "A\n";
    }
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        solve(i);
    }
}

Measured memory_bytes: 3644
n,m = map(int,input().split())
S = list(input())[::-1]
memo = [False]*n
cur = 0
i = 0
ans = []
while i < n:
    for j in range(min(m,n-i),0,-1):
        # print(i,j)
        if S[i+j] == "0":
            ans.append(str(j))
            i += j
            break
        if memo[i+j]:
            ans = -1
            break
        memo[i+j] = True
    if ans == -1:
        break
    # print(S[i:])
print(*ans[::-1]) if ans != -1 else print(-1)

Measured memory_bytes: 13376
#include<stdio.h>

int dp[50];

int fib(int n) {
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n-1) + fib(n-2);
}

int main() {
  int n,i;
  for(i = 0; i<50; i++) dp[i] = -1;

  scanf("%d\n", &n);
  printf("%d\n", fib(n));

  return 0;
}

Measured memory_bytes: 600
using System;

class Program
{
  static void Main()
  {
    string n =Console.ReadLine();
    string[] G =n.Split(' ');
    int x =int.Parse(G[0]);
    int y =int.Parse(G[1]);
    int a =x*(x-1)/2 + y*(y-1)/2;
    Console.WriteLine(a);
  }
}
    

Measured memory_bytes: 13140
abc = input().split(" ")
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

d = 0
if a==b:
    d=d+1
if b==c:
    d=d+1
if c==a:
    d=d+1
if d==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
dic_A = {0:1}
direction = 0
flag = True
for i in range(K):
    direction = A_list[direction]-1
    if direction in dic_A:
        dic_A[direction] += 1
        if dic_A[direction] >= 3:
            flag = False
            break
    else:
        dic_A[direction] = 1
if flag:
    print(direction+1)
    exit()
cnt = 0
dic_ans = {}
for k, v in dic_A.items():
    if v >= 2:
        cnt += 1
        dic_ans[k] = 1
ans = K - (len(dic_A) - cnt)
ans %= cnt
for k, v in dic_ans.items():
    if ans == 0:
        true = k
        break
    ans -= 1
print(true+1)


Measured memory_bytes: 36448
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace sandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            var consoleReader = new ConsoleReader(Console.In);
            var A = consoleReader.Int;
            var B = consoleReader.Int;
            Console.WriteLine(new[] { A + B, A * B, A - B }.Max());
        }
    }

    class ConsoleReader
    {
        private StringBuilder sb = new StringBuilder(4096);
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                sb.Clear();
                int current = textReader.Read();
                while (current > 0 && char.IsWhiteSpace((char)current)) { current = textReader.Read(); }
                while (current > 0 && !char.IsWhiteSpace((char)current)) { sb.Append((char)current); current = textReader.Read(); }
                return sb.ToString();
            }
        }


        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}


Measured memory_bytes: 13248
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};


int main(void){
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K % 2){
    cout << B - A << endl;
  }else{
    cout << A - B << endl;
  }

}


Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

h = (H/12 + (M/60)/12) * 360
m = (M/60) * 360
r = math.radians(h - m)
ans = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(r))

print(ans)

Measured memory_bytes: 9344
n = int(input())
s = input()
ans = 0
for i in range(10):
  for j in range(10):
    l = s.find(str(i))
    r = s.rfind(str(j))
    if l != -1 and r != -1 and l<r:
      ans += len(set(s[l+1:r]))
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 100000000
#define pi M_PI
char H[N];

int getChar(char ch){
    if(ch=='A'){
        return 1;
    }else if(ch=='C'){
        return 2;
    } else if( ch == 'G') {
        return 3;
    } else if( ch == 'T') {
        return 4;
    }
    return 0;
}
int getKey( char str[] )
{
    int i;
    int key = 0, base = 1;
    for ( i=0; '\0'!=str[i]; i++ ) {
        key += base*( getChar( str[i] ) );
        base *= 5;
    }
    return key;
}
 
int find( char str[] )
{
    if( 1 == H[ getKey( str ) ] ) {
        return 1;
    } else {
        return 0;
    }
}
 
void insert( char str[] )
{
    H[ getKey( str ) ] = 1;
    return;
}

int main(){
  int i, n;
    char str[14], com[9];
     
    scanf( "%d", &n );
    for ( i=0; i<n; i++ ) {
        scanf( "%s %s", com, str );
        if ( com[0] == 'i' ){
            insert( str );
        } else {
            if( find( str ) ){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 6948
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int fun(int n){
	return (n*n*n*n*n);
}

inline void solve(){
    int x;cin>>x;
    for (int i=0;i<500;i++){
    	for (int j=0;j<500;j++){
    		if (fun(i)-fun(j)==x) {
    			cout << i << " "<<j<<endl;
    			return;
    		}
    		if (fun(i)-fun(-j)==x) {
    			cout << i << " "<<-j<<endl;
    			return;
    		}if (fun(-i)-fun(j)==x) {
    			cout << -i << " "<<j<<endl;
    			return;
    		}
    	}
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
/*

*/


Measured memory_bytes: 3560
w,h,n = map(int,input().split())
stx = 0
sty = 0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        stx = max(stx,x)
    if a == 2:
        w = min(w,x)
    if a == 3:
        sty = max(sty,y)
    if a == 4:
        h = min(h,y)
if w-stx<=0 or h-sty<=0:
    ans = 0
else:
    ans = (w-stx)*(h-sty)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll N,K;
ll A[200005];
ll sosuu[200005];
bool found;
ll ans;
ll si;
priority_queue<ll> so[200005];
ll m;
map<ll,ll> mm;
char a;
int main() {
    cin >> a;
    if(a-'a'<26 && a-'a'>=0){
        cout << "a" << endl;
    }else{
        cout << "A" << endl;
    }
    
}


Measured memory_bytes: 9876
#include <bits/stdc++.h>
using namespace std;
int main() {
  double n,k;
  cin>>n>>k;
  double kotae=0;
  for(int i=1;i<=n;i++){
    double p=1;
    int kazu=i;
    while(kazu<k){
      p*=0.5;
      kazu*=2;
    }
    kotae+=p/(double)n;
  }
  cout<<fixed<<setprecision(12)<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))
li = [0] * N

li[0] = min(x, a[0])
for i in range(N-1):
  if li[i] + a[i + 1] > x:
    li[i + 1] = x - li[i]
  else:
    li[i + 1] = a[i + 1]
    
cnt = 0
for ai, lii in zip(a, li):
  cnt += ai - lii

print(cnt)

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

int main() {
    int n;
    cin >> n;
    map<string,long long> mp;
    string st[n];
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        st[i]=s;
        mp[s]++;
    }
    long long ans=0;
    for(auto s:st){
        ans+=(mp[s]-1LL)*(mp[s]-2LL)/2;
        mp[s]=0;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  
  deque<char> dq;
  for (int i = 0; i < N; i++) {
    dq.push_back(S[i]);
  } 
  
  
  vector<char> left;
  
  
  for (int i = 0; i < N; i++) {
    if (S[i] == '(') left.push_back('(');
    
    if (S[i] == ')') {
      if (left.size()) {
        left.pop_back();
      } else {
        dq.push_front('(');
      }
    }
  }
  
  for (int i = 0; i < left.size(); i++) {
    dq.push_back(')');
  }

  for (int i = 0; i < dq.size(); i++) {
    cout << dq[i];
  }
    
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;


ll a[maxn];
int main()
{
	ll n;
	cin >> n;
	n%=500;
	ll a;
	cin >> a;
	if(n<=a)
		cout << "Yes";
	else
		cout << "No";
}

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

int main() {
  string s;
  cin >> s;
  int ans;
  if(s=="SUN")
  ans=7;
  else if(s=="MON")
  ans=6;
  else if(s=="TUE")
  ans=5;
  else if(s=="WED")
  ans=4;
  else if(s=="THU")
  ans=3;
  else if(s=="FRI")
  ans=2;
  else 
  ans=1;
  cout << ans << endl;
}

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

signed main() {
    long long n, W, sum(0);
    cin >> n >> W;
    long long w[n], v[n];
    for (long long i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    long long dp[sum + 1];
    dp[0] = 0;
    for (long long i = 1; i <= sum; i++) {
        dp[i] = (long long)1e9 + 1;
    }
    for (long long i = 0; i < n; i++) {
        for (long long j = sum; j >= v[i]; j--) {
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    for (long long i = sum; i >= 0; i--) {
        if (dp[i] <= W) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll p[15];
bool query(ll x){
	cout << "? " << x << endl;
	char c;
	cin >> c;
	return c=='Y';
}
bool query(ll x,int d,ll y){
	if(x!=0ll)cout << "? " << x << d << y << endl;
	else if(d!=0ll)cout << "? " << d << y << endl;
	else cout << "? " << y << endl;
	char c;
	cin >> c;
	return c=='Y';
}
void find(ll x){
	cout << "! " << x << endl;
	exit(1);
}
int f(int dig,int L,ll offset){
	int l = (dig==0)?0:-1, r = 9;
	while(r-l>1){
		int mid = (l+r)/2;
		if(query(offset,mid,p[L-dig]-1ll))r=mid;
		else l = mid;
	}
	return r;
}
int main(){
	p[0]=1ll;
	for(int i=1;i<=10;i++)p[i]=p[i-1]*10ll;
	if(query(p[9])){
		int k = 1;
		while(!query(p[k]-1ll))k++;
		find(p[k-1]);
	}
	int l = 1, r = 10;
	while(r-l>1){
		int mid = (l+r)/2;
		if(query(p[mid-1]))l=mid;
		else r = mid;
	}
	ll os = 0ll;
	for(int i=0;i<l;i++){
		int d = f(i,l,os);
		//cout << "digit " << d << endl;
		os = os*10ll+(ll)d;
	}
	find(os);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

const int INF=1e+7;
const int MAX=6005;
char s[MAX];
int n,chk[MAX],lim;
vector<int> p[2],cut;
struct group{
    int idx;
    string part;
    bool operator<(const group &x){
        if(part!=x.part&&(part[0]=='b'||x.part[0]=='b')) return part>x.part;
        return idx<x.idx;
    }
};
group wtf[MAX];
int main(){
    scanf(" %d %s",&n,s);
    for(int i=0;i<2*n;i++) p[s[i]-'a'].push_back(i);
    cut.push_back(0);
    for(int i=0;i<n;i++) {
        chk[p[0][i]]=1,chk[p[1][i]]=1;
        lim=max(lim,max(p[0][i],p[1][i]));
        if(lim==2*i+1) cut.push_back(i+1);
    }
    for(int i=0;i<2*n;i++) chk[i]=0;
    for(int i=0;i<cut.size()-1;i++){
        wtf[i].idx=i;
        if(p[0][cut[i]]>p[1][cut[i]]){
            for(int j=cut[i+1]-1;j>=cut[i];j--){
                chk[p[0][j]]=1,chk[p[1][j]]=1;
                string tmp;
                for(int k=0;k<2*n;k++) if(chk[k]) tmp.push_back(s[k]);
                wtf[i].part=max(wtf[i].part,tmp);
            }
        }
        else{
            int pt=-1;
            for(int j=cut[i];j<cut[i+1];j++){
                if(pt<p[0][j]) pt=p[1][j], wtf[i].part.append("ab");
            }
        }
        for(int j=cut[i];j<cut[i+1];j++) chk[p[0][j]]=0,chk[p[1][j]]=0;
    }
    sort(wtf,wtf+(cut.size()-1));
    lim=-1;
    for(int i=0;i<cut.size()-1;i++) if(lim<wtf[i].idx) lim=wtf[i].idx, cout<<wtf[i].part;
    cout<<'\n';

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main() {
  int n, m, k, t, count = 0;
  scanf("%d%d", &n, &m);
  int l[m];
  for (size_t i = 0; i < m; i++) {
    l[i] = 0;
  }
  for (size_t i = 0; i < n; i++) {
    scanf("%d", &k);
    for (size_t j = 0; j < k; j++) {
      scanf("%d", &t);
      l[t-1]++;
    }
  }
  for (size_t i = 0; i < m; i++) {
    if (l[i] == n) {
      count++;
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int x=scan.nextInt(),a=scan.nextInt(),b=scan.nextInt();
		if(Math.abs(x-a)>Math.abs(x-b)) {
			System.out.println("B");
		}
		else {
			System.out.println("A");
		}

	}

}

Measured memory_bytes: 35612
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = b[a[0] - 1]
for i in range(1, n):
    ans += b[a[i] - 1]
    if a[i] - a[i-1] == 1:
        ans += c[a[i-1] - 1]

print(ans)


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long n = long.Parse(Console.ReadLine());
        string[] s = new string[n];
        for (int i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }

        var dic = new SortedDictionary<string, long>(StringComparer.OrdinalIgnoreCase);
        long max = 0;
        for (int i = 0; i < n; i++)
        {
            if (dic.ContainsKey(s[i]))
            {
                dic[s[i]] += 1;
                max = Math.Max(max, dic[s[i]]);
            }
            else
            {
                dic.Add(s[i], 1);
                max = Math.Max(max, dic[s[i]]);
            }
        }

        foreach (var d in dic.Where(x => x.Value == max))
        {
            Console.WriteLine(d.Key);
        }
    }
}


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

void solve() {
    string s;
    cin >> s;
    cout << s.substr(0,3) << endl;
}

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

    solve();

    return 0;
}

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

// N人の正直者・不親切な人の分布は2^N通り
// それぞれの状態に対して与えられた証言と矛盾しないかを検査して，矛盾しない場合の内の正直者の最大数を出力
// 0以上2^N未満の整数j = 1以上N以下の整数kに対して人kが正直者でjを2進数表記したときのk-1桁目が1

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}

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


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

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

string S;
int K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S>>K;
	FORR(c,S) {
		if(c=='a') continue;
		x='z'+1-c;
		if(x<=K) {
			c='a';
			K -= x;
		}
	}
	
	K %= 26;
	while(K--) {
		if(S.back()=='z') S.back()='a';
		else S.back()++;
	}
	cout<<S<<endl;
	
}


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


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


int main() {
  vector<int> n(4);
  int p1 = 0;
  int p2 = 0; 
  int p3 = 0; 
  int p4 = 0; 

  cin >> n.at(0) >> n.at(1) >> n.at(2) >> n.at(3);
  for(int i=0;i<4;i++){
   if(n.at(i)==1) p1=1;
   if(n.at(i)==7) p2=1;
   if(n.at(i)==9) p3=1;
   if(n.at(i)==4) p4=1;
  }
  if(p1+p2+p3+p4 == 4) cout << "YES" <<endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
//
//  abc153_Ibis_Monster.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define PI 3.14159265


int main(int argc, const char* argv[]) {

  ll h, n;
  std::cin >> h >> n;
  std::map<ll, ll> ab;

  for (int i = 0; i < n; i++) {
    ll a, b;
    std::cin >> a >> b;
    if((ab.count(a) && ab[a]>b) || !ab.count(a)) {
      ab[a] = b;
    }
    // std::cout << a << " " << ab[a] << std::endl;
  }
  ll INF = 1000000007;
  ll dp[h+1]; // min magic used to decrease H by i
  dp[0] = 0;
  for (int i = 1; i < h+1; i++) {
    dp[i] = INF;
    for (std::map<ll, ll>::iterator it = ab.begin(); it != ab.end(); it++) {
      ll a = it->first;
      ll b = it->second;
      if (i >= a) {
        dp[i] = min(dp[i], dp[i-a] + b);
        // std::cout << dp[i-a] + b << std::endl;
      }
      else {
        dp[i] = min(dp[i], b);
      }
    }
    // std::cout << "i: " << i << " dp: " << dp[i] << std::endl;
  }
  std::cout << dp[h] << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
struct UnionFind{
    vector<int> d;
    UnionFind(int n):d(n,-1){}
    int root(int x){
        if( d[x] < 0)return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x,int y){
        x = root(x),y = root(y);
        if(x == y)return false;
        if(d[x] > d[y])swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    int size(int x){
        return -d[root(x)];
    }
    bool issame(int x,int y){
        return root(x) == root(y);
    }

};
int main()
{
    int n,m;
    cin >> n >> m;
    vector<P> p(m);
    int ans = 0;
    rep(i,m){
        cin >> p[i].first >> p[i].second;
        p[i].first--;p[i].second--;
    }
    rep(i,m){
        UnionFind uf(n);
        int nota,notb;
        rep(j,m){
            //i本目の辺をつながない
            if(j == i){
                nota = p[i].first,notb = p[i].second;
                continue;
            }
            int a,b;
            a = p[j].first,b = p[j].second;
            
            uf.unite(a,b);
        }
        if(!uf.issame(nota,notb))ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
print(n * (n + 1) // 2)

Measured memory_bytes: 60012
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define pb push_back
#define mp make_pair
#define NMAX 20001

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int n;
int a[NMAX];
int main(){
    read(n);
    if(n==3){
        cout<<2<<" "<<5<<" "<<63;
        return 0;
    }
    if(n==4){
        cout<<2<<" "<<4<<" "<<3<<" "<<9;
        return 0;
    }
    if(n==5){
        cout<<2<<" "<<4<<" "<<6<<" "<<3<<" "<<9;
        return 0;
    }
    if(n==6){
        cout<<2<<" "<<4<<" "<<6<<" "<<12<<" "<<3<<" "<<9;
        return 0;
    }
    if(n<=15000){
        if(n%6==0||n%6==3){
            cout<<3<<" "<<9<<" "<<15<<" "<<21<<" "<<27<<" "<<33<<" ";
            for(int i=1;i<=n-6;i++) cout<<2*i<<" ";
            return 0;
        }
        if(n%6==1||n%6==4){
            cout<<3<<" "<<9<<" "<<15<<" "<<21<<" ";
            for(int i=1;i<=n-4;i++) cout<<2*i<<" ";
            return 0;
        }
        if(n%6==2||n%6==5){
            for(int i=1;i<=n-2;i++) cout<<2*i<<" ";
            cout<<3<<" "<<9;
            return 0;
        }
    }
    else{
        if(n%2==0){
            for(int i=1;i<=15000;i++) cout<<2*i<<" ";
            for(int i=0;i<=n-15000-1;i++){
                cout<<3+6*i<<" ";
            }
        }
        else{
            for(int i=1;i<=14999;i++) cout<<2*i<<" "; // sum%3==0
            for(int i=0;i<=n-14999-1;i++){ // con lai chan con 3
                cout<<3+6*i<<" ";
            }
        }
    }
}


Measured memory_bytes: 384
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    stock = ['dream', 'dreamer', 'erase', 'eraser']

    q = deque()
    q.append(S)
    while len(q) > 0:
        s = q.popleft()
        if len(s) == 0:
            return 'YES'

        if s[:5] in stock:
            q.append(s[5:])
        if s[:6] in stock:
            q.append(s[6:])
        if s[:7] in stock:
            q.append(s[7:])

    return 'NO'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3832
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int[] M = new int[2];
        int[] D = new int[2];
        for (int i=0; i<2; i++) {
            M[i] =  Integer.parseInt(sc.next());
            D[i] =  Integer.parseInt(sc.next());
        }
        sc.close();

        if (M[0]!=M[1])
            System.out.println("1");
        else
            System.out.println("0");
    }
}

Measured memory_bytes: 23764
/*
    Author:    DreamCat4er
    Created:   29.08.2020 15:57:29
*/
#include <bits/stdc++.h>
using namespace std;

const long long base = (long long)(1e9 + 7);

long long a[(int)(2e5 + 500)];
long long sf[(int)(2e5 + 500)];

long long mul(long long x, long long y) {
    return (x * y) % base;
}

void add_self(long long &x, long long y) {
    x += y;
    x %= base;
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = n - 1; i >= 0; --i)
        add_self(sf[i], (i + 1 == n ? 0 : sf[i + 1]) + a[i]);

    long long ans = 0;
    for (int i = 0; i < n - 1; ++i)
        add_self(ans, mul(a[i], sf[i + 1]));

    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifdef _LOCAL
        int t;
        cin >> t;
        for (int _t = 0; _t < t; ++_t) {
            cout << "Case " << _t << " :\n";
            solve();
            cout << "\n";
        }
    #else
        solve();
    #endif // _LOCAL

    return 0;
}

Measured memory_bytes: 6732
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}

int main() {
  int n;
  cin >> n;
  set<int> se;
  rep (i, n) {
    int tmp;
    cin >> tmp;
    auto itr = se.find(tmp);
    if (itr != se.end()) se.erase(itr);
    else se.insert(tmp);
  }
  cout << se.size() << endl;
  return 0;
}

Measured memory_bytes: 4864
#include <iostream>

int main()
{
    int h, w; std::cin >> h >> w;
    char a[110][110];

    // 入力
    for (int i = 0; i <= h + 1; i++) {
        for (int j = 0; j <= w + 1; j++) {
            if (i == 0 || i == h + 1) {
                a[i][j] = '#';
            } else if (j == 0 || j == w + 1) {
                a[i][j] = '#';
            } else {
                std::cin >> a[i][j];
            }
        }
    }

    // 出力
    for (int i = 0; i <= h + 1; i++) {
        for (int j = 0; j <= w + 1; j++) {
            if (j == w + 1) std::cout << a[i][j] << std::endl;
            else            std::cout << a[i][j];
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int a, b, x; cin >> a >> b >> x;
	if(a+b >= x && a <= x) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

fn main() {
    input! {
        _n: usize,
        m: usize,
        pys: [(usize,u64);m]
    }
    let mut mpys = pys.clone();
    mpys.sort();
    let mut prev = 1;
    let mut seq = 1;
    let mut m = HashMap::new();
    for (p,y) in mpys {
        if prev != p {
            seq = 1;
        }
        let id = format!("{:06}{:06}",p,seq);
        m.insert((p,y), id);
        prev = p;
        seq += 1;
    }
    for k in pys {
        let id = m.get(&k).unwrap();
        println!("{}", id);
    }
}


Measured memory_bytes: 22812
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int a,b;
			try {
				a = sc.nextInt();
				b = sc.nextInt();
			} catch (Exception e) {
				break;
			}

			int ans = a + b;

			String str = String.valueOf(ans);

			System.out.println(str.length());

		}

	}
}



Measured memory_bytes: 26240
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<stack>
#include<map>
#include<set>
#include<assert.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;


void solve() {
	int n, m; cin >> n >> m;
	vector<vector<int>> G(3*n);
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		rep(j, 3) {
			int k = j + 1; if (k == 3)k = 0;
			G[a + n * j].push_back(b + n * k);
		}
	}
	vector<int> dist(3 * n, mod);
	int s, t; cin >> s >> t; s--; t--;
	dist[s] = 0;
	queue<int> q;
	q.push(s);
	while (!q.empty()) {
		int id = q.front(); q.pop();
		rep(j, G[id].size()) {
			int to = G[id][j];
			if (dist[to] > dist[id] + 1) {
				dist[to] = dist[id] + 1;
				q.push(to);
			}
		}
	}
	//rep(i, 3 * n)cout << dist[i] << endl;
	int ans = dist[t];
	if (ans == mod)ans = -3;
		cout << ans/3 << endl;
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout<<fixed<<setprecision(10);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 17792
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define Mod LL(1e9+7)
using namespace std;
typedef long long LL;
const LL MAXN=LL(1e5+5);
LL n,ans,k;
bool t;
vector<LL>G[MAXN];
void Dfs(LL u,LL fa,LL d) {
    if(t)
        return;
    LL L=k-min(d,1LL*2);
    if(L+1<G[u].size()) {
        t=1;
        return;
    }
    for(LL i=0;i<G[u].size();i++) {
        LL v=G[u][i];
        if(v==fa) continue;
        Dfs(v,u,d+1);
        ans=(ans*L)%Mod;
        L--;
    }
}
int main(){
    scanf("%lld%lld",&n,&k);
    LL u,v;
    for(LL i=1;i<n;i++) {
        scanf("%lld%lld",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    if(G[1].size()>=k) {
        puts("0");
        return 0;
    }
    ans=k;
    Dfs(1,0,1);
    if(t) {
        puts("0");
        return 0;
    }
    printf("%lld\n",ans);
}


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

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

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

	string a; cin >> a;

	int n; cin >> n;

	int ans = 0;
	for (int i = 0;i < n;i++){
		string b; cin >> b;
		for (int i = 0;i < b.size();i++){
			bool f = true;
			for (int j = 0;j < a.size() && f;j++){
				if(b[(i+j)%b.size()] != a[j]) f = false;
			}
			if(f){ 
				ans++;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prime() {
    int u, minv;
    int d[MAX], p[MAX], color[MAX];
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }
    d[0] = 0;
    while (1) {
        minv = INFTY;
        u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[v] > M[u][v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != -1) {
            sum += M[i][p[i]];
        }
    }
    return sum;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int e;
            cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }
    cout << prime() << endl;
    return 0;
}


Measured memory_bytes: 3096