akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>

#pragma warning(disable : 4996)

using namespace std;

int main()
{
	int H;

	while (true)
	{
		scanf("%d", &H);

		if (H == 0) { break; }

		vector<vector<int> > M(H, vector<int>(5));

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < 5; j++)
			{
				scanf("%d", &M[i][j]);
			}
		}

		int ret = 0;

		while (true)
		{
			for (int i = 0; i < H; i++)
			{
				for (int j = 5; j >= 3; j--)
				{
					for (int k = 0; k <= 5 - j; k++)
					{
						bool ok = (M[i][k] != 0);

						for (int l = k + 1; l < k + j; l++)
						{
							if (M[i][l - 1] != M[i][l] || M[i][l] == 0)
							{
								ok = false;
							}
						}

						if (ok)
						{
							ret += M[i][k] * j;

							for (int l = k; l < k + j; l++)
							{
								M[i][l] = 0;
							}
						}
					}
				}
			}

			bool ok = false;

			for (int rep = 0; rep < H; rep++)
			{
				for (int i = H - 1; i >= 1; i--)
				{
					for (int j = 0; j < 5; j++)
					{
						if (M[i][j] == 0 && M[i - 1][j] != 0)
						{
							M[i][j] = M[i - 1][j]; M[i - 1][j] = 0; ok = true;
						}
					}
				}
			}

			if (!ok) { break; }
		}

		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
bool T=false;

int main(){
    int X,N;cin>>X>>N;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    int ans=0,min=1e9;
    for (int i = 110; i >= -10; i--)
    {
        
        for (int j = 0; j < N; j++)
        {
            if(p[j]==i)goto Z;
        }
        if(min>=(abs(X-i))){
            min=abs(X-i);
            ans=i;
        }
        Z:;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main()
{
    int a,b;
    //printf("2333");
    scanf("%d %d",&a,&b);
    for(int i=b*10;i<=b*10+9;i++){
        if((int)(i*0.08)==a){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


Measured memory_bytes: 128
#2_B
def selection_sort(a,n):
    count = 0
    for i in range(n):
        minj = i
        m = n-1-i+1
        for j in range(m):
            k = i + j
            if a[k] < a[minj]:
                minj = k
        
        if minj!=i:
            minnum = a[minj]
            a[minj] = a[i]
            a[i] = minnum
            count += 1
    return a, count

n = int(input())
a = list( map(int, input().split()) )

arr, count = selection_sort(a, n)
res = str(arr[0])
for i in range(n-1):
    res += " " + str(arr[i+1])

print(res)
print(count)


Measured memory_bytes: 5600
import sys
input=sys.stdin.readline
n=int(input())
h=list(map(int,input().split()))
 
dp=[0]*n
dp[1]=abs(h[1]-h[0])
 
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
 
print(dp[-1])

Measured memory_bytes: 84992
n = int(input())
arr = list(map(int, input().split()))

def solve(arr, n):
	arr[0] -= 1
	for i in range(1, n):
		left = arr[i] - arr[i-1]
		if left < 0:
			return False
		if left != 0: arr[i] -= 1
	return True

print("Yes" if solve(arr, n) else "No")

Measured memory_bytes: 63984
n=gets.to_i
as=gets.split.map(&:to_i).sort
ai=as.pop
aj=10**9
half=ai/2.0
diffmin=10**9
as.each do |an|
  if (an-half).abs<diffmin
    aj=an
    diffmin=(an-half).abs
  end
end
puts [ai,aj].join(" ")


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s=="Sunny") {
    cout << "Cloudy" << endl;
  }
   if (s=="Cloudy") {
    cout << "Rainy" << endl;
  }
   if (s=="Rainy") {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 3616
import heapq


class PrimalDual:
    def __init__(self, n: int):
        """頂点数をnとする。"""
        self.INF = 10 ** 9 + 7
        self.n = n
        self.graph = [[] for _ in range(n)]

    def add_edge(self, _from: int, to: int, capacity: int, cost: int):
        """辺を追加
        1. _fromからtoへ向かう容量capacity、単位コストcostの辺をグラフに追加する。
        2. toから_fromへ向かう容量0、単位コスト-costの辺をグラフに追加する。
        """
        forward = [to, capacity, cost, None]
        forward[3] = backward = [_from, 0, -cost, forward]
        self.graph[_from].append(forward)
        self.graph[to].append(backward)

    def min_cost_flow(self, s: int, t: int, f: int) -> int:
        """s-tパス上に流量fを流すときの最小費用流を求める。
        計算量: O(|F||E|log|V|)
        """
        res = 0
        potential = [0] * self.n
        prv_v = [0] * self.n
        prv_e = [None] * self.n
        while f > 0:
            # ポテンシャルを用いたダイクストラ法
            dist = [self.INF] * self.n
            dist[s] = 0
            q = [(0, s)]  # q = [(sからのコスト, 現在地)]
            while q:
                cost, _from = heapq.heappop(q)
                if dist[_from] < cost:
                    continue
                for edge in self.graph[_from]:
                    to, capacity, cost, _ = edge
                    p_diff = potential[_from] - potential[to]
                    if capacity > 0 and dist[_from] + cost + p_diff < dist[to]:
                        dist[to] = dist[_from] + cost + p_diff
                        prv_v[to] = _from
                        prv_e[to] = edge
                        heapq.heappush(q, (dist[to], to))

            if dist[t] == self.INF:
                return -1
            for i in range(self.n):
                if dist[i] != self.INF:
                    potential[i] += dist[i]
            d = f
            v = t
            while v != s:
                d = min(d, prv_e[v][1])
                v = prv_v[v]
            f -= d
            res += potential[t] * d
            v = t
            while v != s:
                edge = prv_e[v]
                edge[1] -= d
                edge[3][1] += d
                v = prv_v[v]
        return res


n, k = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
INF = 10 ** 18


pd = PrimalDual(n + n + 2)

s = n + n
t = n + n + 1

pd.add_edge(s, t, INF, 0)
for i in range(n):
    pd.add_edge(s, n + i, k, 0)
    pd.add_edge(i, t, k, 0)
for i in range(n):
    for j in range(n):
        pd.add_edge(n + i, j, 1, -a[i][j])

ans = -pd.min_cost_flow(s, t, INF)

res = [["." for i in range(n)] for i in range(n)]
for i in range(n):
    for j, cap, cost, _ in pd.graph[n + i]:
        if 0 <= j <= n and cap == 0:
            res[i][j] = "X"

print(ans)
for r in res:
    print("".join(r))

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

#pragma GCC optimize ("-O2")
#define ll long long
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define testcase(t) int t;cin>>t;while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define what_is(x)  cerr << #x << " is " << x << endl;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

const int LIM=1e5+5,MOD=1e9+7;

int main(){

	IOS;

	string s;
	cin>>s;
	if(s.size()!=6){
		cout<<"No"<<endl;
		return 0;
	}
	if(s[2]==s[3] && s[4]==s[5]){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;

	






	return 0;
}
 










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
};
int lcm(int a, int b) {
  return a / gcd(a, b) * b;
};
int floor(int a, int b) {
  return (a + b - 1) / b;
};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
int dp[3001][3001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);

  int n, t, w = 0, v = 0, ind = -1;
  cin >> n >> t;
  vi a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, n) rep(j, t + 1) {
    if (j - a[i] < 0 or dp[i][j] > dp[i][j - a[i]] + b[i])
      dp[i + 1][j] = dp[i][j];
    else {
      dp[i + 1][j] = dp[i][j - a[i]] + b[i];
    }
  }
  int memo = dp[n][t];
  int k = t;
  vi use(n);
  for (int i = n - 1; i >= 0; i--) {
    if (dp[i + 1][k] != dp[i][k]) {
      k -= a[i];
      use[i] = 1;
    }
  }
  rep(i, n) {
    if (use[i]) {
      if (w < a[i]) {
        w = a[i];
        v = b[i];
        ind = i;
      } else if (w == a[i]) {
        if (b[i] > v) {
          v = b[i];
          ind = i;
        }
      }
    }
  }
  int ans = 0;
  rep(i,n){
    if (use[i]==0){
      chmax(ans, b[i]);
    }
  }
  memo = max(ans + dp[n][t - 1], memo);
  memset(dp, 0, sizeof(dp));
  rep(i, n) rep(j, t + 1) {
    if (j - a[i] < 0 or i == ind)
      dp[i + 1][j] = dp[i][j];
    else {
      dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i]] + b[i]);
    }
  }
  k = t;
  vi u(n);
  for (int i = n - 1; i >= 0; i--) {
    if (dp[i + 1][k] != dp[i][k]) {
      k -= a[i];
      u[i] = 1;
    }
  }
  ans = 0;
  rep(i, n) {
    if (u[i] == 0)
      chmax(ans, b[i]);
  }
  cout << max(dp[n][t - 1] + ans, memo) << en;
}

Measured memory_bytes: 38864
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// a[0] = 1
// a[i] = a[i - 1] * 2 + 1
vector<long long> a(51), b(51);
long long ans = 0;

long long f(int n, long long x) {
  if (x <= 0) {
    return 0;
  }
  if (n == 0) {
    return 1;
  }
  if (a[n] <= x) {
    return b[n];
  } else if (a[n - 1] + 2 <= x) {
    return b[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]);
  } else if (a[n - 1] + 1 <= x) {
    return b[n - 1];
  } else {
    return f(n - 1, x - 1);
  }
}

int main() {
  int n;
  long long x;
  cin >> n >> x;
  a[0] = 1;
  b[0] = 1;
  for (int i = 0; i < 50; i++) {
    a[i + 1] = a[i] * 2 + 3;
    b[i + 1] = b[i] * 2 + 1;
  }
  cout << f(n, x) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll H,W;
    cin >> H >> W;
    bool isSpace[H][W];
    ll way[H][W];
    for(ll yi = 0; yi < H; yi++){
        string s;
        cin >> s;
        for(ll xi = 0; xi < W; xi++){
            if(s[xi] == '.'){
                isSpace[yi][xi] = true;
            }else{
                isSpace[yi][xi] = false;
            }
            way[yi][xi] = 0;
        }
    }
    way[0][0] = 1;
    ll MOD = 1000000007;
    for(ll yi = 0; yi < H; yi++){
        for(ll xi = 0; xi < W; xi++){
            if(isSpace[yi][xi] == false || (yi == 0 && xi == 0)){
                continue;
            }
            ll u = 0;
            if(yi - 1 >= 0){
                u = way[yi - 1][xi];
            }
            ll l = 0;
            if(xi - 1 >= 0){
                l = way[yi][xi - 1];
            }
            way[yi][xi] = (u + l) % MOD;

        }
    }
    cout << way[H- 1][W-1] << endl;

}


Measured memory_bytes: 9088
h, w = map(int, input().split())
words = [0]*(h+2)
for i in range(1, h+1, 1):
    s = input()
    words[i] = s

for j in range(len(words)):
    if words[j] == 0:
        words[j] = '#'*(w+2)
    else:
        words[j] = '#'+words[j]+'#'

for ans in words:
    print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int main(){
  ll n;
  cin >> n;
  ll all = n*(n-1)/2;
  ll fill = n/2;
  cout << all - fill << endl;
  if(n%2==1){
    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        if(i+j==n)continue;
        cout << i << " " << j << endl;
      }
    }
  }
  else{
    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        if(i+j==n+1)continue;
        cout << i << " " << j << endl;
      }
    }
  }
  return 0;
}
  
  
  
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll d; cin >> d;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(d, vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin >> s[i][j];
    }
  }

  vector<ll> t(d, 0);
  
  ll res = 0;
  vector<ll> last(26, -1);
  rep(i,d) {
    ll ss = 0;
    rep(j,26) {
      if(chmax(ss, s[i][j])) {
	t[i] = j;
      }
    }
    res += s[i][t[i]];
    last[t[i]] = i;
    rep(j,26) {
      res -= c[j] * (i - last[j]);
    }
  }

  rep(i,d) cout << t[i]+1 << "\n";
  return 0;
}


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

int main()
{
	int A, B,num;

	cin >> A >> B;

	num = A * B;

	for (int i = 1;i < 4;i++) {
		if ((num*i) % 2 == 0) {
			cout << "No";
			break;
		}
		else {
			cout << "Yes";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<string.h>
using namespace std;
int main()
{
	int N, M, an = 0, count = 0;
	char s[110][20], t[110][20];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%s", s[i]);
	}
	scanf("%d", &M);
	for (int i = 0; i < M; i++) {
		scanf("%s", t[i]);
	}
	for (int i = 0; i < N; i++) {
		count = 1;
		for (int j = i + 1; j < N; j++) {
			if (strcmp(s[i], s[j]) == 0) {
				count++;
			}
		}
		for (int k = 0; k < M; k++) {
			if (strcmp(s[i], t[k]) == 0) {
				count--;
			}
		}
		if (count > an) {
			an = count;
		}
	}
	printf("%d", an);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
set<ll> st1,st2;
int main(){
  ll ans = 0;
  ll n;
  cin >> n;
  ull len1 = sqrt(n);
  rep(i,len1){
    if(n % (i+1) == 0){
      st1.insert(i+1);
      st1.insert(n / (i+1));
    }
  }
  ull len2 = sqrt(n-1);
  rep(i,len2){
    if((n-1) % (i+1) == 0){
      st2.insert(i+1);
      st2.insert((n-1) / (i+1));
    }
  }
  ll sum = 0;
  for(auto itr:st1){
    t1 = n;
    if(itr == 1){
      continue;
    }
    while(t1 % itr == 0){
      t1 /= itr;
    }
    t2 = t1 / itr;
    t1 -= t2 * itr;
    if(t1 == 1){
      ans++;
    }
  }
  for(auto itr:st2){
    auto x = st1.lower_bound(itr);
    if(*x != itr){
      ans++;
    }
  }
  cout << ans << endl;
}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    /*int a,b,c,d,f;
    cin>>a>>b>>c>>d>>f;
    int ar[10];
    ar[a]=1;
    ar[b]=2;
    ar[c]=3;
    ar[d]=4;
    ar[f]=5;
    cout<<ar[0]<<endl;*/
    /*int x,y;
    cin>>x>>y;
    if(y>=x*2&&y<=x*4&&y%2==0)cout<<"Yes\n";
    else cout<<"No\n";*/
    int x,n,p;
    cin>>x>>n;
    mii m;
    for(int i=0;i<n;i++){
        cin>>p;
        m[p]=1;
    }
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    int a=x;
    for(int i=1;i<=1000;i++){
        if(m[a]==0){
            cout<<a<<endl;
            return 0;
        }
        if(m[x]==0){
            cout<<x<<endl;
            return 0;
        }
        a--;
        x++;
    }
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int n;
VI k = {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};

int main()
{
    cin>>n;
    cout<<k[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

p = [(list(map(int, input().split())) + [0] + [i]) for i in range(m)]
p_sort = sorted(p, key=(lambda x:x[1]))

index_list = [1] * n
for i in range(m):
    p_sort[i][2] = index_list[p_sort[i][0] - 1]
    index_list[p_sort[i][0] - 1] += 1

p_sort = sorted(p, key = (lambda x:x[3]))

for i in range(m):
    string = str(p_sort[i][0]).zfill(6) + str(p_sort[i][2]).zfill(6)
    print(string)

Measured memory_bytes: 37364
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1000000007;


int main() {
	int a, b, ans=0;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

using Row = vector<int64>;
using Mat = vector<Row>;

int32 N;
vector<int32> G[112345];
int64 dp[112345][2] = {};

int64 dfs(int32 v, int32 p, int32 c){
	if(~dp[v][c]) return dp[v][c];
	dp[v][c] = 1;
	REP(i, G[v].size()){
		if(G[v][i] == p) continue;
		int64 x = 0;
		REP(j, (c^1)+1){
			x = (x + dfs(G[v][i], v, j))%mod;
		}
		dp[v][c] = dp[v][c] * x % mod;
	}
	return dp[v][c];
}

int main(void){
	memset(dp, -1, sizeof dp); cin >> N;
	REP(i, N-1){
		int32 x, y;
		cin >> x >> y; x--; y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	cout << (dfs(0, -1, 0)+dfs(0, -1, 1))%mod << endl;
}


Measured memory_bytes: 18944
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = s_input()

    len_n = len(n)

    count = 0

    for c in n:
        count += int(c)

    print('Yes' if count % 9 == 0 else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 73492
#!/usr/bin/env python3

line1 = input()
line2 = input()
sN, sX = line1.split()
N = int(sN)
X = int(sX)
sL = line2.split()
L = []
for sl in sL:
    L.append(int(sl))

D = 0

if D <= X:
    cnt = 1
else:
    cnt = 0

for l in L:
    D += l
    if D <= X:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  rep(i,x) cin >> a[i]; 
  rep(i,y) cin >> b[i]; 
  rep(i,x) cin >> c[i];

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());

  vector<ll> ab;

  rep(i,x) rep(j,y) ab.push_back(a[i] + b[j]);

  sort(ab.begin(), ab.end(), greater<ll>());

  int n = sz(ab);
  vector<ll> res;
  rep(i,min(n,k)) rep(j,min(z,k))  res.push_back(ab[i] + c[j]);

  sort(res.begin(), res.end(), greater<ll>());
  rep(i,k) cout << res[i] << endl;
  return 0;
}

Measured memory_bytes: 43368
#include <cstddef>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
namespace loquat {
using vertex_t = size_t;
}
namespace loquat {
namespace edge_param {
struct to_ {
	vertex_t to;
	explicit to_(vertex_t t = 0)
		: to(t)
	{ }
};
}
namespace detail {
template <typename T, typename... Params>
struct edge_param_wrapper : public T, edge_param_wrapper<Params...> {
};
template <typename T>
struct edge_param_wrapper<T> : public T {
	template <typename U>
	explicit edge_param_wrapper(U&& x)
		: T(std::forward<U>(x))
	{ }
};
}
template <typename... Params>
struct edge : public detail::edge_param_wrapper<edge_param::to_, Params...> {
	template <typename... Args>
	explicit edge(Args&&... args)
		: detail::edge_param_wrapper<edge_param::to_, Params...>(
			std::forward<Args>(args)...)
	{ }
};
}
namespace loquat {
template <typename EdgeType>
class adjacency_list {
public:
	using edge_type = EdgeType;
	using edge_list = std::vector<edge_type>;
private:
	std::vector<std::vector<EdgeType>> m_edges;
public:
	explicit adjacency_list(size_t n)
		: m_edges(n)
	{ }
	const edge_list& operator[](vertex_t u) const {
		return m_edges[u];
	}
	template <typename... Args>
	void add_edge(vertex_t from, Args&&... args){
		m_edges[from].emplace_back(std::forward<Args>(args)...);
	}
};
}
using namespace std;
using edge = loquat::edge<>;
int solve(int u, int p, const loquat::adjacency_list<edge>& g){
	int sum = 0, children = 0;
	for(const auto& e : g[u]){
		if(e.to == p){ continue; }
		++children;
		const int t = solve(e.to, u, g);
		if(t < 0){ return t; }
		sum += t;
	}
	if(sum >= 2){ return -1; }
	return (sum == 1 ? 0 : 1);
}
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	loquat::adjacency_list<edge> g(n);
	for(int i = 1; i < n; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		g.add_edge(a, b);
		g.add_edge(b, a);
	}
	const int t = (n % 2 == 1 ? -1 : solve(0, -1, g));
	cout << (t < 0 ? "First" : "Second") << endl;
	return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
const ll mod=1e9 + 7;
ll power(ll a,ll n)
{
        ll ans=1;
        a=a%mod;
        while(n>0)
        {
                if(n%2==1)
                {
                        ans=(ans*a)%mod;
                }
                n=n/2;
                a=(a*a)%mod;
        }
        return ans;
}

int main()
{
     string s;
     cin>>s;
     if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
     {
       cout<<"Bad";
     }
     else
     {
       cout<<"Good";
     }
}


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

using namespace std;

const int N = 105;
const int K = 100005;

int n, a[N], dp[K];

bool fun(int baki) {
  if (baki == 0) {
    return false;
  }
  if (dp[baki] != -1) {
    return dp[baki];
  }
  bool win = false;
  for (int i = 0; i < n; i++) {
    if (baki - a[i] >= 0) {
      if (!fun(baki - a[i])) {
        win = true;
      }
      if (win) break;
    }
  }
  return dp[baki] = win;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof dp);
  cout << (fun(k) ? "First" : "Second") << '\n';
  return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
vector<int>adj[MAX];
int lca[32][MAX];
int vis[MAX];
int depth[MAX],n;
void init(){
	for(int i=0;i<32;i++){
		for(int j=0;j<MAX;j++){
			lca[i][j]=-1;
		}
	}
}
void dfs(int s){
	vis[s]=1;
	for(int i=0;i<adj[s].size();i++){
		if(!vis[adj[s][i]]){
			lca[0][adj[s][i]]=s;
			depth[adj[s][i]]=depth[s]+1;
			dfs(adj[s][i]);
		}
	}
}
int find_lca(int u, int v){
	if(depth[u]<depth[v]){
		swap(u,v);
	}
	int dis=depth[u]-depth[v];
	while(dis>0){
		int r=log2(dis);
		u=lca[r][u];
		dis=dis-(1<<r);
	}
	if(u==v)
		return u;
	for(int i=31;i>=0;i--){
		if(lca[i][u]!=-1&&(lca[i][u]!=lca[i][v])){
			u=lca[i][u];
			v=lca[i][v];
		}
	}
	return lca[0][u];

}
void binary_lift(){
	for(int i=1;i<31;i++){
		for(int j=0;j<n;j++){
			if(lca[i-1][j]!=-1){
				lca[i][j]=lca[i-1][lca[i-1][j]];
			}
		}
	}
}
int main(){
	int m;
	cin>>n;
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int a;
			cin>>a;
			adj[i].push_back(a);
			adj[a].push_back(i);
		}
	}
	init();
	dfs(0);
	binary_lift();
	int q;
	cin>>q;
	while(q--){
		int x,y;
		cin>>x>>y;
		int l=find_lca(x,y);
		cout<<l<<"\n";
	}

}


Measured memory_bytes: 26576
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[]){
        try{
            BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
            String str=reader.readLine();
            StringTokenizer st=new StringTokenizer(str," ");
            String a,b;
            a=st.nextToken();
            b=st.nextToken();
            
            int an=Integer.parseInt(a);
            int bn=Integer.parseInt(b);
            
            System.out.println(an*bn+" "+2*(an+bn));
        }catch(IOException e){
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24072
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stdlib.h>
#include <stdint.h>

using namespace std;

int main()
{
	int N;
   //uintmax_t ;
 //long double ;
	  //string ;
	cin >> N;

	bool ok = false;
	for (size_t i = 0;i < 10;i++) {
		for (size_t j = i; j < 10; j++)
		{
			if (N == i * j) {
				ok = true;
			}
		}
	}

	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,k;
char s[200111];
char getst(int x,int dlt)
{
	if(x+dlt>n)return (n-x)%2+'A';
	else return ((s[x+dlt]-'A')^(dlt%2))+'A';
}
char ans[200111];
int main()
{
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	int dlt=0;
	bool f=0;
	while(k--)
	{
		if(dlt>=n)k%=2;
		if(((getst(1,dlt)-'A')^f)==0)
		{
			f^=1;
		}
		else
		{
			dlt++;
			f=0;
		}
/*		for(int i=1;i<=n;i++)ans[i]=getst(i,dlt);
		if(f)
		{
			ans[1]=((ans[1]-'A')^1)+'A';
		}
		printf("%s\n",ans+1);*/
	}
	for(int i=1;i<=n;i++)ans[i]=getst(i,dlt);
	if(f)
	{
		ans[1]=((ans[1]-'A')^1)+'A';
	}
	printf("%s\n",ans+1);
	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int main()
{
    int i;
    int sum=0;
    char n[1000]; 
    while(1){
        for(i=0;;i++){
            scanf("%c",&n[i]);
            if(n[i]=='\n') 
                break; 
        }
        sum=0;
        for(int j=0;j<i;j++){
            sum+=n[j]-'0';
        }
        if(sum==0)
            break;
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 2768
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$n = $this->lineIn();
		$a = $this->arrayIn();
	
		$ans = 0;

		$average = array_sum($a) / $n;

		$abuf = array();
		foreach($a as $v){
			$buf = abs($v - $average);
			$abuf[] = $buf;
			if(0 == $buf){
				echo $ans . "\n";
				return true;
			}else{
				$ans++;
			}
		}
		unset($v);
		
		sort($abuf);

		$ans = 0;
		foreach($a as $v){
			if($abuf[0] == abs($v - $average)){
				echo $ans . "\n";
				return true;
			}else{
				$ans++;
			}
		}
		unset($v);

		return false;
	}
}
?>

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

using i64 = int64_t;

constexpr double INF = 1e9;
constexpr double EPS = 1e-6;

struct Node{
    int num, tickets;
    double cost;
    bool operator<(const Node &obj)const{
        return cost > obj.cost + EPS;
    }
};

struct Edge{
    int from, to;
    double cost;
};

double mini[300][40]={0};

void init(){
    for(int i=0;i<300;++i){
        for(int j=0;j<40;++j){
            mini[i][j] = INF;
        }
    }
}

int main(){
    int n, m, p, a, b;
    while(cin >> n >> m >> p >> a >> b, n != 0){
        vector<int> v;
        for(int i=0;i<n;++i){
            int t;
            cin >> t;
            v.push_back(t);
        }
        vector<vector<Edge>> graph(m+1, vector<Edge>());
        for(int i=0;i<p;++i){
            int x, y;
            double z;
            cin >> x >> y >> z;
            graph[x].push_back({x, y, z});
            graph[y].push_back({y, x, z});
        }
        init();
        priority_queue<Node> que;
        mini[0][a] = 0;
        que.push({a, 0, 0});
        bool ok = false;
        while(!que.empty()){
            auto curr = que.top(); que.pop();
            if(curr.num == b){
                printf("%.10f\n", curr.cost);
                ok = true;
                break;
            }
            for(auto edge: graph[curr.num]){
                for(int i=0;i<n;++i){
                    if(curr.tickets & (1<<i))continue;
                    double newcost = curr.cost + (edge.cost / (double)v[i]);
                    int tickets = (curr.tickets | (1<<i));
                    if(mini[tickets][edge.to] < newcost + EPS)continue;
                    mini[tickets][edge.to] = newcost;
                    que.push({edge.to, tickets, newcost});
                }
            }
        }
        if(!ok) cout << "Impossible" << endl;
    }

    return 0;
}



Measured memory_bytes: 4648
unittest
{
	assert( [ "3" ].parse.expand.solve == "2\n1 3\n2 3" );
	
	assert( [ "4" ].parse.expand.solve == "4\n1 2\n1 3\n2 4\n3 4" );												// 追加ケース
	assert( [ "5" ].parse.expand.solve == "8\n1 2\n1 3\n1 5\n2 4\n2 5\n3 4\n3 5\n4 5" );							// 追加ケース
	assert( [ "6" ].parse.expand.solve == "12\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 6\n3 5\n3 6\n4 5\n4 6\n5 6" );		// 追加ケース
}



import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	// nが奇数のときは頂点aは頂点(n-a)以外に辺を張る。頂点nだけは他の頂点全部に辺を張る。
	// nが偶数のときは頂点aは頂点(n-a+1)以外に辺を張る。
	auto anss = new string[ ( n * ( n - 1 ) / 2 ) - ( n / 2 ) ];
	auto ansi = 0L;
	for( auto a = 1L; a <= n; a++ )
	{
		auto una = n - a + ( n % 2 == 0 );
		for( auto b = a + 1; b <= n; b++ )
		{
			if( b == una ) continue;
			anss[ ansi ] = format( "%s %s", a, b );
			ansi++;
		}
	}
	return format( "%s\n%s", ansi, anss.join( "\n" ) );
}


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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




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

    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <iomanip>
#include <queue>

#define PI 3.14159265358979
#define MOD 1000000007

//fixed << setprecision(15) <<

using namespace std;

int main(void) {
	string s, t;
	int n,l,m,max;
	bool flag = true;
	vector <long long int> e;
	cin >> s >> t;
	max = t.size();
	n = s.size() - t.size() + 1;
	for (int i = 0; i < n; i++) {
		m = 0;
		for (int j = 0; j < t.size(); j++) {
			if (s[i + j] != t[j]) {
				m++;
			}
		}
		if (max > m)max = m;
	}
	cout << max << endl;
	/*if(flag)cout << "Yes" << endl;
		else cout << "No" << endl;*/
	return 0;
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define F first
#define S second
#define MP make_pair
int main(){
long long int n,temp,now=0;
long long int ans=0;
map<long long int,long long int> m;
m.insert(MP(0,1));
scanf("%lld",&n);
while(n--){
scanf("%lld",&temp);
now+=temp;
if(m.find(now)!=m.end())ans+=m[now]++;
else m.insert(MP(now,1));
}
printf("%lld\n",ans);
}

Measured memory_bytes: 12672
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <ctime> 
using namespace std;

#define pb push_back
#define All(a) a.begin(), a.end()
#define met(a, b) memset(a, b, sizeof(a))
#define rep1(i, l, r) for(int i = l; i <= r; ++i)
#define rep2(i, l, r) for(int i = l; i < r; ++i) 
#define per(i, r, l) for(int i = r; i >= l; --i)
typedef long long ll;
typedef double db;
typedef long double ldb;
const int NIL = -1;
const int oo = 0x3f3f3f3f;
const ll INF = 2e18;
const db eps = 1e-8;
const db PI = acos(-1.0);
const int maxn = 2e5 + 7;

ll T[maxn];

inline ll read(void)
{
	ll x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{ if(ch == '-') f = -1; ch = getchar(); } 
	while(ch >= '0' && ch <= '9') {	x = (x << 1) + (x << 3) + ch - '0';	ch = getchar();	}
	return x * f;
}

inline void write(int x)
{
	if(x < 0) { putchar('-'); x = -x; }
    if(x >= 10) write(x/10); 
	putchar(x%10+'0'); 
}

int main(void)
{
	int n = read();
	rep1(i, 1, n)
	{
		ll v = read();
		T[i] = v - i;
	}
	sort(T+1, T+1+n);
	ll ans = 0;
	ll t = T[1];
	rep1(i, 2, n)
	{
		ans += T[i] - t;
	}
	ll tmp = ans;
	rep1(i, 2, n)
	{
		ll dis = T[i] - T[i-1];
		tmp += (i-1) * dis;
		tmp -= (n-i+1) * dis;
		ans = min(tmp, ans);
	}
	printf("%lld", ans);
	
	return 0;
} 

Measured memory_bytes: 1792
from collections import deque

S = list(input())
Q = int(input())
d = deque(S)
reverse_flg = False

for i in range(Q):
    try:
        x, f, c = input().split()
        f = int(f)
        if f == 1 and not reverse_flg:
            d.appendleft(c)
        elif f == 1 and reverse_flg:
            d.append(c)
        elif f == 2 and not reverse_flg:
            d.append(c)
        else:
            d.appendleft(c)
    except:
        reverse_flg = not reverse_flg

if reverse_flg:
    d.reverse()

print("".join(d))

Measured memory_bytes: 9460
A = [
    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(A[K - 1])


Measured memory_bytes: 2940
// Last Change: 08/01/2019 13:14:19.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  if (A + B < C) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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

int main() {
  string S;
  cin>>S;
  if(S.at(0)!=S.at(1)&&S.at(1)!=S.at(2)&&S.at(2)!=S.at(0))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <map> 
#include <set>
#include <ctime> 
#include <queue> 

#define LL long long

using namespace std;

const int N = 200000+10; 

int n;

struct edge{
	int u, v;
	edge *next;
}e[2*N], *point[N], *P=e;

void add_edge(int x, int y)
{
	edge *Q = ++P; ++P;
	P->u = x; P->v = y; P->next = point[x]; point[x] = P;
	Q->u = y; Q->v = x; Q->next = point[y]; point[y] = Q; 
}

int size[N], fa[N], rec[N];

void dfs(int x, int father)
{
	size[x] = 1;
	fa[x] = father;
	for(edge *j = point[x]; j; j=j->next)
		if(j->v != father)
			dfs(j->v, x),
			size[x] += size[j->v];
}

int main()
{

	scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int x, y; scanf("%d%d", &x, &y);
		add_edge(x, y);
	}
	dfs(1, -1);
	int cnt = 1, cur = rec[cnt] = n;
	while(cur != 1)
	{
		cur = fa[cur];
		rec[++cnt] = cur; 
	}
	int w = size[rec[cnt/2]], b = n-w;
	if(w>=b)
		printf("Snuke\n");
	else
		printf("Fennec\n");
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

string x="rsp";

int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[3];rep(i,0,2)cin>>a[i];
    string s;cin>>s;
    ll c[n];
    rep(i,0,n-1){
        rep(j,0,2){
            if(s[i]==x[j])c[i]=(j+2)%3;
        }
    }
    ll ans=0;
    rep(i,0,k-1){
        for(ll j=i;j<=n-1;j+=k){
            ans+=a[c[j]];
            if(j+k<=n-1&&c[j]==c[j+k])j+=k;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    int x=0,y=0;
    int t=0;
    int a,b,c;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&c,&a,&b);
        if(abs(x-a)+abs(y-b)>c-t)
        {
            printf("No");
            return 0;
        }
        if((abs(x-a)+abs(y-b))%2==0 &&(c-t)%2==1)
        {
            printf("No");
            return 0;
        }
        if((abs(x-a)+abs(y-b))%2==1 &&(c-t)%2==0)
        {
            printf("No");
            return 0;
        }
        x=a;y=b;t=c;
    }
    printf("Yes");
    return 0;
}

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

int main() {
  int N;
  int count=0;
  int b=1;
  cin >> N;
  vector<int> v(N);
  vector<int> check(N,0);
  for(int i=0;i<N;i++)cin >> v.at(i);
  while(b!=2){
    check.at(b-1)++;
    if(check.at(b-1)>1){
      count=-1;
      break;
    }
    count++;
    b=v.at(b-1);
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//lower_bound like o_set.find_by_order(val) strictly less then val
//upper_bound like o_set.order_of_key(MAX)– o_set.order_of_key(val)
//if u need multiset elements then use second parameter as time and think 
//typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int MAX=2e5+5;
const ll MM=1e16;
const ll mod=998244353;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}
vector<string> v;
void fun(string s,int index,int last,string a)
{
    if(index==s.length())
    {
        v.pb(a);return;
    }
    if(last==1)
    {
        fun(s,index+1,0,a+s[index]);
        int val=a[a.size()-1]-'0';
        char c='0'+val+1;
        a[a.size()-1]=c;
        fun(s,index+1,1,a);
    }
    else if(last==0)
    {
        fun(s,index+1,0,a+s[index]);
        char c='1';
        a+=c;
        fun(s,index+1,1,a);   
    }
    
    
}

void solve()
{
    ll n,m,i,j,k;
    cin>>n>>m>>k;
    if(n%k==0)
    cout<<(m/k)-(n/k)+1<<endl;
    else
    {
         cout<<(m/k)-(n/k)<<endl;
    }
    
    
}

int main()
{
  boost;
  ll t=1;
// cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 3612
N,S =list(map(int , input().split()))
A = []
B = []
for i in range(N):
    x,y=[int(i) for i in input().split()]
    A.append(x)
    B.append(y)
ans = 0
tar = S**2
for j in range (N):
    a = A[j]**2+B[j]**2
    if (tar>=a):
        ans += 1
print(ans)

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

int main(){
	int l,r,ans=2019;
	cin>>l>>r;

	if(r-l>=2019){
		cout<<0;
	}else{
		for(int i=l;i<=r-1;i++){
			
			for(int j=l+1;j<=r;j++){
				ans=min(ans,(i%2019)*(j%2019)%2019);
			}
		}
		cout <<ans<<endl;
	}
	
	
	return 0;
}



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

int main(){
  string s;
  cin >> s;
  int a,z;
  a = s.find("A");
  z = s.rfind("Z");
  cout << z-a+1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
 
static const int INF = 1145141919;
const long long INFL = 1LL<<60;
 
int main()
{
	int n, k;
	cin >> n >> k;
	long long int h[110000];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	long long int dp[110000];
	for (int i = 0; i < 110000; ++i)
	{
		dp[i] = INFL;
	}
	dp[0] = 0;
	for (int i = 1; i < n; ++i)
	{
		for (int j = 1; j <= min(k, i); ++j)
		{
			chmin(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1920