akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;



int main() {
    int d,d1,i,j,k;
    int c[26];
    int s[365][26];
    cin >> d;
    d1 = 0;
    for(i = 0; i < 26; ++i) cin >> c[i];
    for(i = 0; i < d; ++i) for(j = 0; j < 26; ++j) cin >> s[i][j];

    int arr[365] = {};

    int t1,t2,s1,s2, diff, count;
    count = 0;
    int max, loc;
    int a[26];
    for(int i = 0; i < 26; ++i) a[i] = 1;
    int b[26] = {};
    for(i = 0; i < 365; ++i) {
        for(j = 0; j < 26; ++j) {
            b[j] = s[i][j]+a[j]*c[j];
            a[j]++;
        }
        max = *max_element(b,b+26);
        loc = find(b,b+26,max)-b;
        arr[i] = loc;
        a[loc] = 1;
    }
    
    
    while(true) {
        label2:
        if(d1==d) break;
        for(i = 0; i < 26; ++i) {
            b[i] = s[d1][i]+a[i]*c[i];
            a[i]++;
        }
        max = *max_element(b,b+26);
        loc = find(b,b+26,max)-b;
        arr[i] = loc;
        a[loc] = 1;
        d1++;
        count = 0;


        label1:
        for(i = 0; i < d1; ++i) {
            for(j = 0; j < 26; ++j) {
                if(arr[i]==j) continue;
                if(count>1000*d1) goto label2;
                ++count;
                for(s1 = i+1; s1 < d; ++s1) {
                    if(arr[s1]==arr[i]) break;
                }
                for(t1 = i-1; t1 >= 0; --t1) {
                    if(arr[t1]==arr[i]) break;
                }
                for(s2 = i+1; s2 < d; ++s2) {
                    if(arr[s2]==j) break;
                }
                for(t2 = i-1; t2 >= 0; --t2) {
                    if(arr[t2]==j) break;
                }
                diff = s[i][j]-s[i][arr[i]]+(((s1-i)*(s1-i-1))/2+((i-t1)*(i-t1-1))/2-((s1-t1)*(s1-t1-1))/2)*c[arr[i]] + (-((s2-i)*(s2-i-1))/2-((i-t2)*(i-t2-1))/2+((s2-t2)*(s2-t2-1))/2)*c[j];
                if(diff>0) {
                    arr[i] = j;
                    goto label1;
                }
            }
        }
    }
    for(i = 0; i < d; ++i) {
        cout<<(arr[i]+1)<<"\n";
    }


    return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int min = 1000;
  for (int i = 0; i < S.size() - 2; i++) {
    string num = S.substr(i, 3);
    int ans = atoi(num.c_str());
    ans = 753 - ans;
    if (abs(ans) < min) min = abs(ans);
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
list($N, $T) = explode(" ", trim(fgets(STDIN)));
$t = explode(" ", trim(fgets(STDIN)));

$X = 0;

for ($i = 0; $i <= $N - 1; $i++) {
    if ($i == 0 || $t[$i - 1] + $T <= $t[$i]) {
        $X += $T;
    } else {
        $X +=  ($t[$i] - $t[$i - 1]);
    }
}

echo $X;

Measured memory_bytes: 23028
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    int N; string S; cin>>N>>S;
    int maximum = 0;
    for (int i = 0; i < N-1; ++i) {
        set<char> X;
        int cnt = 0;
        for (int j = 0; j <= i; ++j) {// Xをつくる
            X.insert(S[j]);
        }
        for (int j = i+1; j < N; ++j) {
            if(X.count(S[j])) {
                cnt++;
                X.erase(S[j]);
            }
        }
        maximum = max(maximum, cnt);
    }

    cout<<maximum<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    ll n = N, m = MOD, inv[n+1];
    rep2(i, 1, n){
        inv[i] = 1;
        ll e[31];
        e[0] = i;
        rep2(j, 1, 30) e[j] = (e[j-1]*e[j-1]) % m;
        ll k = m-2;
        int cnt = 0;
        while(k > 0){
            if(k % 2 == 1) inv[i] *= e[cnt], inv[i] %= m;
            k /= 2;
            cnt++;
        }
    }
    ll fac = 1;
    rep2(i, 1, N){fac *= i; fac %= MOD;}
    ll p[N];
    rep(i, N){p[i] = (fac*inv[i+1])%MOD;}
    ll sum[N];
    sum[0] = p[0];
    rep2(i, 1, N-1){sum[i] = (sum[i-1]+p[i])%MOD;}
    ll ans = 0;
    rep(i, N){
        ll s = sum[i]+sum[N-1-i]+(MOD-sum[0]);
        s %= MOD;
        ans += (A[i]*s)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int N;
    cin >> N;

    int ans = N / 2;
    if (N % 2 == 1) {
        ++ans;
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int m=0;
  vector<int> ans(n+1,0);
  for(int i=n;i>=1;i--){
    int sum=0;
    for(int j=i*2;j<=n;j+=i){
      sum+=ans[j];
    }
    //cout << "i=" << i << " sum=" << sum << endl;
    if(sum%2!=a[i]){
      m++;
      ans[i]=1;
    }
  }
  cout<<m<<endl;
  bool flg=false;
  for(int i=1;i<=n;i++){
    if(ans[i]){
      if(flg){
        cout<<' ';
      }
      cout<<i;
      flg=true;
    }
  }
  if(m){
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 4672
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  s <- T.getLine :: IO T.Text
  let
    t | s == T.pack "Sunny" = T.pack "Cloudy"
      | s == T.pack "Cloudy" = T.pack "Rainy"
      | otherwise = T.pack "Sunny"
  T.putStrLn t


Measured memory_bytes: 508
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
using namespace std;

#define INF ( 1 << 30 )
typedef pair < int , int > Pi;

int main()
{
  int N, Q;
  int stmp[1000000], comp[1000000], a;
  char buff[1024];
  scanf( "%d %d", &N, &Q);
  for(int i = 0 ; i < N ; i++ ){
    scanf( "%d", &stmp[i]);
    comp[i] = stmp[i];
  }
  sort( comp, comp + N);

  vector< int > sym;
  while(Q--){
    scanf("%s %d", buff, &a);
    if(*buff == 'A'){ //ADD

      sym.push_back(stmp[a - 1]);
      sort( sym.begin(), sym.end());

    } else if(*buff == 'R'){ //REMOVE

      sym.erase( lower_bound( sym.begin(), sym.end(), stmp[a - 1]));
      //      sort( sym.begin(), sym.end());

    } else { //CHECK

      int left = 0, right = INF;
      while(left != right){
        int center = ( left + right ) / 2;
        int pre = 0, BAN = 0;
        for(int i = 0 ; i < sym.size() ; i++ ){
          int p = distance( comp,lower_bound( comp, comp + N, sym[i] - center));
          BAN += max( p - pre, 0);
          pre = distance( comp, upper_bound( comp, comp + N, sym[i]));
        }
        BAN += max( N - pre, 0);
        if(BAN <= a) right = center;
        else left = center + 1;
      }
      if( left != INF) printf("%d\n", left);
      else puts("NA");

    }
  }
  return false;
}

Measured memory_bytes: 8884
s = input()
t = input()

n = len(s) ; m = len(t)

# dp[n+1][m+1]

dp = [[0 for i in range(m+1)] for j in range(n+1)]

for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1] == t[j-1]:
      dp[i][j] = 1 + dp[i-1][j-1]
    else:
      dp[i][j] = max(dp[i-1][j] , dp[i][j-1])
      
res = ""

i = n; j = m

while i>0 and j>0:
  if dp[i][j] == dp[i][j-1]:
    j-=1
  elif dp[i][j] == dp[i-1][j]:
    i-=1
  else:
    res = s[i-1] + res
    i-=1;j-=1

print(res)



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

int main(){
  std::string str;
  
  std::cin >> str;
  
  char ch = str.back();
  
  if ( ch == 's' ){
    str.append("es");
  }
  else{
    str.append("s");
  }
  
  std::cout << str;
  
}

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

int main() {
  int h, m;
  double a, b;
  cin >> a >> b >> h >> m;
 
  double x = abs((h*30+m*0.5)-(m*6));
  if(x>=180) x = 360-x;
  double pi = 3.141592653589793238;
  double ans = sqrt(a*a+b*b-2*a*b*cos(x/180*pi));
  
  cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 4164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp93 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var S = new string[N];

            var num_array = new int[5];

            for (int i = 0; i < N; i++) {
                S[i] = Console.ReadLine();
            }
            num_array[0] = S.Where(x => x[0] == 'M').Count();
            num_array[1] = S.Where(x => x[0] == 'A').Count();
            num_array[2] = S.Where(x => x[0] == 'R').Count();
            num_array[3] = S.Where(x => x[0] == 'C').Count();
            num_array[4] = S.Where(x => x[0] == 'H').Count();

            long ans = 0;

            for (int i = 0; i < 5; i++) {
                for (int j = i + 1; j < 5; j++) {
                    for (int k = j + 1; k < 5; k++) {
                        ans += (long)num_array[i] * num_array[j] * num_array[k];


                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  vi mt(10);
  REP(i, 10) cin >> mt[i];
  RSORT(mt);
  REP(i, 3) cout << mt[i] << endl;
}

Measured memory_bytes: 3020
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;

signed main(){
    ll n;
    cin >> n;
    ll cnt[1000001] = {};
    ll a[n] = {};

    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    
    rep(i,0,n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    
    sort(a,a+n);

    if(a[n-1] == 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    rep(i,0,n){
        if(cnt[1] > 0 && a[i] != 1) continue;

        bool flag = true;
        for(ll j = 1;j * j <= a[i];j++){
            if(j > 1 && a[i] % j == 0){
                if(cnt[j] || cnt[a[i]/j]){
                    flag = false;
                }
            }
            else if(cnt[a[i]] > 1){
                flag = false;
            }
            
        }

        if(flag){
            ans++;
        }
    }

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


Measured memory_bytes: 13032
#include <algorithm>
#include <iterator>
#include <iostream>
//#include <iomanip>
//#include <cstring>
//#include <cstdlib>
#include <string>
#include <vector>
//#include <queue>
//#include <cmath>
//#include <set>
using namespace std;
#ifdef LOCAL
#define DEBUGMSG()                                                              \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]" ;        \
}
#define DEBUGVAR(x)                                                             \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \
    cerr << "([" << typeid(x).name() << "]" << #x << ")" << x << endl ;         \
}
#define DEBUGARR(l, r)                                                          \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \
    copy(l, r, ostream_iterator<decltype(*l)>(cerr, " "));                      \
    cerr << endl ;                                                              \
}
#else
#define DEBUGMSG()
#define DEBUGVAR(x)
#define DEBUGARR(l, r)
#endif // LOCAL

typedef long long i64;

vector <i64> vec;
string str;
string t1, t2;
i64 ans = 0;

void DFS(string s)
{
    if(s.size() <= 0)
    {
        for(i64 x : vec)
            ans += x;
        return ;
    }

    for(string::iterator itr = s.begin(); itr != s.end(); itr++)
    {
        t1 = string(s.begin(), itr+1);
        t2 = string(itr+1, s.end());
        //DEBUGVAR(t1);
        //DEBUGVAR(t2);
        //DEBUGVAR(stol(t1));
        vec.push_back(stoll(t1));
        DFS(t2);
        vec.pop_back();
    }
}

int main()
{
    cin >> str ;
    DFS(str);
    cout << ans << endl ;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
#include <iostream>

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int32_t number_of_kujibiki;
  std::cin >> number_of_kujibiki;
  std::set<std::string> kujibiki_type;
  for (int32_t i = 0; i < number_of_kujibiki; ++i) {
    std::string type;
    std::cin >> type;
    kujibiki_type.insert(type);
  }
  std::cout << kujibiki_type.size() << std::endl;
  return 0;
}


Measured memory_bytes: 19184
n, k = map(int, input().split())
a = list(map(int, input().split()))
min_num = 10**9 + 10
count = 0

for i in range(0, n, k-1):
    check = a[i:i+k]
    num = min(a[i:i+k])
    if len(check) > 1:
        count += 1
    if num < min_num:
        min_num = num

print(count)

Measured memory_bytes: 13812
#include <algorithm>
#include <cstring>
#include <cstdio>
const int N=10005;
int a[N],b[N],c[N*4],low[N*4],dfn[N*4],stack[N*4],ls[N*4],rs[N*4],
	id[N*2],fst[N*4],n,m,nodes,tot,cnt,col,top;
bool u[N*4];
struct P{int x,id;}q[N*2];
bool cmp(P a,P b){
	return a.x<b.x;
}
struct Edge{int to,nxt;}e[N*120];
void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;
}
void build(int now,int l,int r){
	if (l==r){
		id[l]=now;
		return;
	}
	int mid=(l+r)>>1;
	build(ls[now]=++nodes,l,mid);
	build(rs[now]=++nodes,mid+1,r);
}
void add(int now,int l,int r,int x,int y,int z){
	if (x<=l && r<=y){
		addedge(z,now);
		return;
	}
	int mid=(l+r)>>1;
	if (x<=mid) add(ls[now],l,mid,x,y,z);
	if (y>mid) add(rs[now],mid+1,r,x,y,z);
}
void tarjan(int x){
	dfn[x]=low[x]=++cnt;
	u[stack[++top]=x]=1;
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (!dfn[y]){
			tarjan(y);
			low[x]=std::min(low[x],low[y]);
		}
		else if (u[y]) low[x]=std::min(low[x],dfn[y]);
	}
	if (low[x]==dfn[x]){
		++col;
		for (;stack[top]!=x;u[stack[top--]]=0) c[stack[top]]=col;
		c[x]=col;u[x]=0;top--;
	}
}
bool check(int mid){
	memset(fst,0,sizeof fst);
	tot=0;
	for (int i=1;i<=nodes;i++)
		if (ls[i]) addedge(i,ls[i]),addedge(i,rs[i]);
	for (int i=1,l=1,r=1;i<=m;i++){
		for (;q[l].x<=q[i].x-mid;l++);
		for (;r<m && q[r+1].x<q[i].x+mid;r++);
		if (l<i) add(1,1,m,l,i-1,id[q[i].id]);
		if (i<r) add(1,1,m,i+1,r,id[q[i].id]);
	}
	memset(dfn,0,sizeof dfn);
	memset(u,0,sizeof u);
	cnt=col=top=0;
	for (int i=1;i<=nodes;i++)
		if (!dfn[i]) tarjan(i);
	for (int i=1;i<=n;i++)
		if (c[id[a[i]]]==c[id[b[i]]]) return 0;
	return 1;
}
int main(){
	scanf("%d\n",&n);m=n*2;
	for (int i=1;i<=n;i++){
		scanf("%d%d",&q[i*2-1].x,&q[i*2].x);
		q[i*2-1].id=q[i*2].id=i;
	}
	std::sort(q+1,q+m+1,cmp);
	for (int i=1;i<=m;i++)
		if (!a[q[i].id]) a[q[i].id]=i;
			else b[q[i].id]=i;
	for (int i=1;i<=n;i++) q[q[a[i]].id=b[i]].id=a[i];
	nodes=1;build(1,1,m);
	int l=1,r=1000000000,ans=0;
	for (;l<=r;){
		int mid=(l+r)>>1;
		if (check(mid)) ans=mid,l=mid+1;
			else r=mid-1;
	}
	printf("%d\n",ans);
}

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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    string s, t;
    cin >> s >> t;
    int len = s.length();

    rep (i, len) {
        bool clear = true;
        rep (j, len) {
            if (s[j] != t[(i + j) % len]) {
                clear = false;
                break;
            }
        }
        if (clear) {
            print("Yes");
            return 0;
        }
    }
    print("No");

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


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

int main()
{
	int h, w;
	int pp[25][25] = {0};

	scanf("%d %d", &h, &w);
	for (int y = 0; y < h; y++)
	{
		for (int x = 0; x < w; x++)
			scanf("%d", &pp[y][x]);
	}

	int min_sum = 0;
	for (int y = 0; y < h; y++)
	{
		for (int x = 0; x < w; x++)
		{
			int sum = 0;
			for (int y2 = 0; y2 < h; y2++)
			{
				for (int x2 = 0; x2 < w; x2++)
				{
					int close = abs(x2 - x) < abs(y2 - y) ? abs(x2 - x) : abs(y2 - y);
					//cout << close << endl;
					sum += close * pp[y2][x2];
				}
			}
			min_sum = min_sum == 0 || (sum < min_sum) ? sum : min_sum;
		}
	}
	printf("%d\n", min_sum);
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
void pushback(string& s, char c){
    s.push_back(c);
}
void pushtop(string& s, char c){
    string tmp = "";
    tmp.push_back(c);
    s = tmp + s;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string S;
    cin>>S;
    int Q;
    cin>>Q;
    int cnt = 0;
    deque<string> deq;
    deq.push_back(S);
    while(Q--){
        int q;
        cin>>q;
        if(q == 1){
            cnt++;
        }
        else{
            int f;char c;
            cin>>f>>c;
            if(cnt % 2 == 0){
                if(f == 1){
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_front(tmp);
                }
                else{
                    //pushback(S, c);
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_back(tmp);
                }
            }
            else{
                if(f == 1){
                    //pushback(S, c);
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_back(tmp);
                }
                else{
                    //pushtop(S, c);
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_front(tmp);
                }
            }
        }
        /*
        for_each(deq.begin(), deq.end(), [](string x) {
            cerr << x;
        });
        cerr<<endl;
        */
    }
    if(cnt % 2 == 1){
        for_each(deq.rbegin(), deq.rend(), [](string& x) {
            if(x.size() > 1){
                reverse(all(x));
            }
            cout << x;
        });
        cout<<endl;
    }
    else{
        for_each(deq.begin(), deq.end(), [](string& x) {

            cout << x;
        });
        cout<<endl;
    }
}

Measured memory_bytes: 11728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,l,r,count=0,a[111111]={0};
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>l>>r;
    a[l]++;
    a[r+1]--;
  }
  for(int i=1;i<=n;i++){
    a[i]+=a[i-1];
    if(a[i]==m) count++;
  }
  cout<<count<<endl;
  return(0);
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
long i,sum=0,k, x, max, mini;

cin>> k >> x;
max=x;
mini=x;
for (i=1;i<=k;i++)
{
sum+=x;
if (x<mini)
{
mini=x;
}
if (x>max)
{
max=x;
}
cin >> x;
}
cout << mini << " " << max << " " << sum<< endl;
return 0;
}


Measured memory_bytes: 3096
N,M,X = map(int,input().split())
book = [list(map(int,input().split())) for _ in range(N)]

ans = 10**10
for i in range(1<<N):
    und = [0]*M
    price = 0
    for j in range(N):
        if (i>>j)&1 == 0:
            price += book[j][0]
            for k in range(M):
                und[k] += book[j][k+1]
    b = True
    for num in und:
        if num < X:
            b = False
    if b:
        ans = min(ans,price)
        
if ans == 10**10:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68984
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;


int n, m;
long long C, a[10005], b[100005];
int ans =0 ;

int main(int argc, const char * argv[]) {
//    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> C;
    for (int i = 1; i <= m; ++i)
        cin >> b[i];
    for (int i = 1; i <= n; ++i) {
        long long res = C;
        for (int j = 1; j <= m; ++j) {
            cin >> a[j];
            res += a[j] * b[j];
        }
        if (res > 0) ++ans;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 256
N=int(input())

import sys

if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
    sys.exit()


ANSLIST=[]


ANS=0
x=2
while ANS<=10**5:
   ANS= (1+x)*x//2
   ANSLIST.append(ANS)
   x+=1

if N in ANSLIST:
    print("Yes")
    x=ANSLIST.index(N)+2

    print(x+1)
    ANS=[[] for i in range(x+1)]


    LIST=[]
    y=1
    z=x
    while z>=0:
        LIST.append(y)
        y+=z
        z-=1

    #print(LIST)

    for j in range(x):
        for k in range(x-j):
            ANS[j].append(LIST[j]+k)
            ANS[j+k+1].append(LIST[j]+k)

    for i in range(x+1):
        print(x,end=" ")
        for j in range(x):
            print(ANS[i][j],end=" ")
        print()


else:
    print("No")


Measured memory_bytes: 12692
#include <stdio.h>

int main()
{
	char s[100001];
	int dp[100000];
	int N, Q, i, cnt = 1;
	scanf("%d %d", &N, &Q);
	scanf("%s", s);
	for (i = 0; i < N; i++)
		dp[i] = 0;
	for (i = 1; i < N; i++) {
		if (s[i - 1] == 'A' && s[i] == 'C')
			dp[i] = cnt++;
		else
			dp[i] = dp[i - 1];
	}
	for (i = 0; i < Q; i++) {
		int l, r;
		scanf("%d %d", &l, &r);
		printf("%d\n", dp[r - 1] - dp[l - 1]);
	}
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
using vd = vector<double>;

int main(){
	ll N;
	cin >>N;
	ll ans = 1e12;
	for(ll i = 1; i*i <= N; i++){
		if(N%i == 0){
			ans = min(ans, (N/i + i));
		}
	}
	cout << ans-2 << endl;
}


Measured memory_bytes: 3636
/*
[abc139] A - Tenki
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

string S, T;

ll solve() {
    int cnt = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == T[i]) {
            cnt++;
        }
    }

    return cnt;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);

    ll mn = 1000000000;
    for (ll i = 0; i < N; i++)
    {
        cin >> A[i];
        bitset<64> a(A[i]);
        ll two = 0;
        for (ll j = 0; j < 64; j++)
        {
            if (a[j] == 1) {
                two = j;
                break;
            }
        }
        mn = min(mn, two);
    }
    cout << mn << endl;
}


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

#define int long long
const int N = 2e5+5;
int a[N];

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

 	int n;
 	cin >> n;
 	int mini = 2e9, cnt = 0;
 	for(int i = 0 ; i < n; i++){
 	 	cin >> a[i];
 	 	if(mini >= a[i])
 	 		cnt++;
 	 	mini = min(mini, a[i]);
 	}
 	cout << cnt << endl;

 	return 0;
}

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

int main() {

    int N;
    cin >> N;
   /* vector<int>A(N);
    for (int i = 0; i < N; i++) { cin >> A.at(i); }
    */
  if(N<1200){cout<<"ABC"<<endl;}
  else if(1200<=N&&N<2800){cout<<"ARC"<<endl;}
  else{cout<<"AGC"<<endl;}

}
    

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

// 0-indexed
template <class T>
struct BIT {
  int treesize;
  vector<T> lst;
  // constructor
  BIT(int newn = 0) : treesize(newn), lst(newn + 1, 0) {}
  // a_place += num
  void add(int place, T num) {
    ++place;
    while (place <= treesize) {
      lst[place] += num;
      place += place & -place;
    }
  }
  // sum between [0,place)
  T sum(int place) {
    T res = 0;
    while (place > 0) {
      res += lst[place];
      place -= place & -place;
    }
    return res;
  }
  // sum [l,r)
  T sum(int left, int right) { return sum(right) - sum(left); }
};

int main() {
  int n, q;
  cin >> n >> q;
  BIT<long long> bit(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    bit.add(i, a);
  }
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t)
      cout << bit.sum(u, v) << endl;
    else
      bit.add(u, v);
  }

  return 0;
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  int A[Q];
  for(int i=0; i<Q; i++) cin >> A[i];
  
  vector<int> p(N, K-Q);
  for(auto a : A) p[a-1]++;
  for(auto num : p) cout << ((num > 0)? "Yes" : "No") << endl;
  
}

Measured memory_bytes: 1408
<?php
// E
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = 0; $i < $n; $i++) {
    $x[$i + $a[$i]][] = $i;
    $y[$i - $a[$i]][] = $i;
}
$ans = 0;
for ($i = 0; $i < $n; $i++) {
    if (!isset($x[$i]) || !isset($y[$i])) continue;
    $ans += count($x[$i]) * count($y[$i]);
}
echo $ans;

Measured memory_bytes: 180812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	cout << min(b/a,c) << endl;
}


Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc056/tasks/arc070_a
// simulation, greedy
import std.stdio;

void main() {
    const int maxn = 10^^5;
    int X;
    readf("%s\n", &X);

    long[] dist = new long[maxn + 5];
    for(int i = 1; i < maxn; i++)
        dist[i] = dist[i - 1] + i;

    for(int i = 0; i < maxn; i++)
        if(dist[i] >= X) {
            i.writeln;
            return;
        }
}



Measured memory_bytes: 3424
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <bitset>
#include <functional>

using namespace std;

#define FOR(i,n) 		for(int(i)=0;(i)<(int)(n);(i)++)
#define FORN(i,a,b,c) 	for(int(i)=a;i<(int)(b);i+=(c))
#define RES(x,nilai)	memset(x,nilai,sizeof(x));
#define pb              push_back
#define mp              make_pair
#define INF				1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline string IS(int a){
    char x[100];
    sprintf(x,"%d",a); string s = x;
    return s;
}

inline int SI(string a){
    char x[100]; int res;
    strcpy(x,a.c_str()); sscanf(x,"%d",&res);
    return res;
}

//==============================================

bool cmp(int x,int y) {return x>y;}

int n,arr[10100];

bool cek(long long n) {
	vector<int>v;
	while(n > 0) {
		v.pb(n%10);
		n/=10;
	}
	for(int i =0 ;i < v.size()-1;i++) {
		if (v[i] - v[i+1] != 1) return false;
	}
	return true;
}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("13.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for(int i = 0 ;i < n ;i++) {
		cin >> arr[i];
	}
	
	ll maks = -1;
	for(int i =0 ;i < n-1 ;i++) {
		for(int j = i+1; j<n; j++) {
			ll ans = arr[i]*arr[j];
			if (cek(ans)) {
				if (ans > maks) maks = ans;
			}
		}
	}
	cout << maks << endl;
	
    return 0;
}

Measured memory_bytes: 3248
let () =
  let read_seq () = List.map int_of_string (Str.split (Str.regexp " ") (read_line ())) in
  let _ = read_int () in
  let s = read_seq () in
  let _ = read_int () in
  let t = read_seq () in
  let linear_search x = List.fold_left (fun acc e -> acc || (if e = x then true else false)) false
  in
  Printf.printf "%d\n" (List.fold_left (fun acc e -> acc + (if linear_search e s then 1 else 0)) 0 t)

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s, t, u;
  cin >> s >> t >> u;
  if(s[s.size() - 1] == t[0] && t[t.size() - 1] == u[0]) cout << "YES" << "\n";
  else cout << "NO" << "\n";
}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, sum, tmp;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		
		n /= 4;
		sum = 0;
		for(int i = 0; i < n; i++){
			cin >> tmp;
			sum += tmp;
		}
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef long long ll;

int h, w;
int iy, ix, fy, fx;

int zero_one_bfs(const vector<string>& a)
{
    vector<vector<int>> dist(h, vector<int>(w, INT_MAX));
    vector<vector<bool>> visit(h, vector<bool>(w, false));
    deque<pii> dq;

    dist[iy][ix] = 0;
    dq.push_front({iy, ix});

    while (!dq.empty())
    {
        auto [y, x] = dq.front(); dq.pop_front();

        if (visit[y][x]) continue;
        if (y == fy && x == fx) return dist[y][x];

        visit[y][x] = true;
        for (int dy = -2; dy <= 2; dy++)
        {
            for (int dx = -2; dx <= 2; dx++)
            {
                if (dy == 0 && dx == 0) continue;

                auto [ny, nx] = make_pair(y+dy, x+dx);
                if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                if (visit[ny][nx] || a[ny][nx] == '#') continue;

                int d = (abs(dy)+abs(dx) != 1);
                if (dist[ny][nx] > dist[y][x]+d)
                {
                    dist[ny][nx] = dist[y][x]+d;
                    if (d == 0) dq.push_front({ny, nx});
                    else dq.push_back({ny, nx});
                }
            }
        }
    }
    return -1;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> h >> w;
    cin >> iy >> ix >> fy >> fx;
    iy--; ix--; fy--; fx--;

    vector<string> a(h); for (string& s : a) cin >> s;
    cout << zero_one_bfs(a) << endl;

    return 0;
}


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

int main() {
	int n,m;
	int a[55],b[55];
	cin >> n>> m;
	for(int i=0;i<m;i++) cin >> a[i] >> b[i];
	int num[55]={0};
	for(int i=0;i<m;i++){
		num[a[i]]++;
		num[b[i]]++;
	}
	for(int i=1;i<=n;i++){
		cout << num[i] << endl;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>

using namespace std;
int n, m;

const int INF = 1 << 29;

class edge
{
public:
	vector<int> E;
};

vector<edge> seito;
set<int> fris;

int main(void)
{
	while(cin >> n >> m && n && m)
	{
		fris.clear();
		seito.clear();
		seito.resize(n);
		for (int i = 0; i < m; i++)
		{
			int a, b;
			cin >> a >> b;
			a--; b--;
			seito[a].E.push_back(b);
			seito[b].E.push_back(a);
		}
		fris.insert(0);
		for (int i = 0; i < seito[0].E.size(); i++)
		{
			fris.insert(seito[0].E[i]);
			for (int j = 0; j < seito[seito[0].E[i]].E.size(); j++)
			{
				fris.insert(seito[seito[0].E[i]].E[j]);
			}
		}

		cout << fris.size() - 1 << endl;
	}
	return 0;
}

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

int main(){
    int n;
    string s;
    cin>>n>>s;
    long long r=0,g=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }

    int d=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int k=2*j-i;
            if(k<0||k>=n) continue;
            if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]) d++;
        }
    }
    cout<<r*g*b-d<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  while(n--) {
    string s;
    int out = 0;
    vector<int> rui(3);
    int ten = 0;
    while(out < 3) {
      // FOR(it,rui)
      //   cout << *it << " ";
      // cout << endl;
      cin >> s;
      if (s == "HIT") {
        if (rui[2]) ten++;
        rui[2] = rui[1];
        rui[1] = rui[0];
        rui[0] = 1;
      } else if (s == "HOMERUN") {
        REP(i,3) {
          ten += rui[i];
        }
        ten++;
        rui = vector<int>(3);
      } else
        out++;
    }
    cout << ten << endl;
  }
}

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

int main(){
	int N;
	cin >> N;
	if (N<105)
		cout << 0 << endl;
	else if (N<135)
		cout << 1 << endl;
	else if (N<165)
		cout << 2 << endl;
	else if (N<189)
		cout << 3 << endl;
	else if (N<195)
		cout << 4 << endl;
	else
		cout << 5 << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
int main(){
    int n,m;
    cin>>n>>m;
    int L, R;
    L = 1;
    R = 100010;
    rep(_, n){
        int l, r;
        cin >> l >> r;
        L = max(L, l);
        R=min(R, r);
    }
    if(R>=L)
    cout << R - L + 1 << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 3608
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	char c;
	cin >> c;

	if (c >= 'a') co('a');
	else co('A');


	Would you please return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define MOD (ll)(1e9+7)

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

#define N_MAX 210
ll dp[N_MAX][N_MAX];

int main(){
	ll n;
	cin>>n;
	vl c(n);
	REP(i,n){
		char x;
		cin>>x;
		c[i] = (x=='U'?1:(x=='D'?-1:0));
	}
	
	dp[0][0] = 1ll;
	REP(i,n)REP(u,n){
		if(c[i]==0){
			// no change
			dp[i+1][u] = dp[i][u];
		}else if(c[i]==1){
			// up
			// add
			dp[i+1][u+1] += dp[i][u];
			// swap
			dp[i+1][u] += dp[i][u]*u;
		}else if(c[i]==-1){
			// down
			// combinate
			if(u>0)
				dp[i+1][u-1] += dp[i][u]*u*u;
			// swap
			dp[i+1][u] += dp[i][u]*u;
		}
		dp[i+1][u] %= MOD;
		dp[i+1][u+1] %= MOD;
		if(u>0) dp[i+1][u-1] %= MOD;
	}
	cout << dp[n][0]%MOD << endl;
	return 0;
}

Measured memory_bytes: 1520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);

int main() {
  int N,K; cin >> N >> K;
  string S; cin >> S;
  int count = 0;
  for (int i = 1; i < N; i++) {
    if (S[i-1] != S[i]) count++;
  }
  
  cout << min(N-1,N-1-count+2*K) << endl;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  string s[1000];
  for(int i=0;i<a;i++) cin>>s[i];
  for(int i=0;i<a;i++){
    cout<<s[i]<<endl;
    cout<<s[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
a+=a
# dp[i][j]=iからjまでの区間連鎖行列積
INF=10**12
dp=[[INF]*(2*n+1) for i in range(2*n+1)]
ans=0
for i in range(n):
    for l in range(2*n-i):
        r=i+l
        if l==r:
            dp[l][r]=0
        else:
            for k in range(l,r):
                dp[l][r]=min(dp[l][k]+dp[k+1][r]+a[l][0]*a[k][1]*a[r][1],dp[l][r])


print(dp[0][n-1])


Measured memory_bytes: 6148
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    cin.ignore();
    vector<string> name(n);
    pair<double,string> pp[50];
    rep(i,n){
      int p,a,b,c,d,e,f,s,m;
      cin>>pp[i].second>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      int t=a+b+c+(d+e)*m;
      int in=f*s*m-p;
      pp[i].first=(double)in/t;
      pp[i].first*=-1;
    }
    sort(pp,pp+n);
    rep(i,n)cout<<pp[i].second<<endl;
    cout<<"#"<<endl;
  }
}

Measured memory_bytes: 3028
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
    int h, w, n, x = 0;
    int a[10010], c[10010];
    cin >> h >> w >> n;
    for(int i = 0; i < 10010; i++) a[i] = c[i] = 0;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        for(int j = x; j < x + a[i]; j++){
            c[j] = i + 1;
        }
        x += a[i];
    }
    for(int i = 0; i < h; i++){
        if(i % 2 == 1) sort(c + i * w, c + (i + 1) * w, greater<int>());
    }
    for(int i = 0; i < h * w; i++){
        cout << c[i];
        if((i + 1) % w == 0){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}
// O(HW + HWlogW)

Measured memory_bytes: 384
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)

a_max = 10000
dp_max = 100000000
dp = [dp_max] * (h + a_max + 1)
dp[0] = 0

for i in range(h):
    if dp[i] == dp_max:
        continue
    for j in range(n):
        a_current = a[j]
        b_current = b[j]
        if dp[i] + b_current < dp[i + a_current]:
            dp[i + a_current] = dp[i] + b_current

dp_min = dp_max
for i in range(h, h + a_max + 1):
    if dp[i] < dp_min:
        dp_min = dp[i]

print(dp_min)

Measured memory_bytes: 41580
//#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	vector<vector<int>> v(2, vector<int>(2019,0));
	int ans = 0;
	rep(i,s.size()){
		string s2; s2 = s[i];
		int k1 = stoi(s2);
		v[(i + 1)%2][k1]++;
		rep(j, 2019) {
			int k2 = k1 + j * 10;
			k2 = k2 % 2019;
			v[(i + 1)%2][k2] += v[i%2][j];
			v[i % 2][j] = 0;
			//if (v[i % 2][j] > 0) cout << k2 << endl;
		}
		ans += v[(i + 1)%2][0];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3740
MOD = 1000000007

n, m = gets.chomp.split.map(&:to_i)
a = Array.new(n+1,1)
m.times do
  i = gets.chomp.to_i
  a[i] = 0
end

cnt = [1,a[1]]

(2..(n+1)).each do |i|
  if a[i] == 0
    cnt[i] = 0
  else
    cnt[i] = (cnt[i-2] + cnt[i-1]) % MOD
  end
end

puts(cnt[n])

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string ans;
    rep(i, 0, tx - sx) ans.push_back('R');
    rep(i, 0, ty - sy) ans.push_back('U');
    ans.push_back('R');
    rep(i, 0, ty - sy + 1) ans.push_back('D');
    rep(i, 0, tx - sx + 1) ans.push_back('L');
    ans.push_back('U');
    ans.push_back('L');
    rep(i, 0, ty - sy + 1) ans.push_back('U');
    rep(i, 0, tx - sx + 1) ans.push_back('R');
    ans.push_back('D');
    rep(i, 0, tx - sx) ans.push_back('L');
    rep(i, 0, ty - sy) ans.push_back('D');
    cout << ans << endl;
    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  set<int> st;
  rep(i, n) st.insert(d[i]);
  cout << st.size() << endl;
}

Measured memory_bytes: 3636