akhauriyash/Code-Regression huggingface dataset:
N = int(input())
Ds = list(map(int, input().split()))
M = int(input())
Ts = list(map(int, input().split()))
nsD = {}
for D in Ds:
  if D not in nsD: nsD[D] = 0
  nsD[D] += 1
nsT = {}
for T in Ts:
  if T not in nsT: nsT[T] = 0
  nsT[T] += 1
ok = True
for T in nsT:
  nT = nsT[T]
  if T not in nsD or nT > nsD[T]:
    ok = False
    break
if ok:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 56788
#include<bits/stdc++.h>
using namespace std;
int main(){
	char ch;
	cin>>ch;
	if(ch=='A') cout<<'T';
	else if(ch=='T') cout<<'A';
	else if(ch=='C') cout<<'G';
	else if(ch=='G') cout<<'C';
	return 0;
}

Measured memory_bytes: 508
<?php
$numbers = fgets(STDIN);
$n = intval($numbers);

//二進法へ変換
$nn = decbin($n). "\n";

for ($i = strlen($nn); $i <= 32; $i++) { 
        $nn = '0' . $nn;
}
print $nn;
// print "\n";

$n2 = '';
for ($i=0; $i < 32; $i++) { 
    if(substr($nn, $i, 1) == 0){
        $n2 .= '1';
    } else {
        $n2 .= '0';
    }
}
print $n2;
print "\n";

$n3 = substr($nn, 1, 31);
print $n3 . '0';
print "\n";

$n4 = substr($nn, 0, 31);
print '0' . $n4;
print "\n";


Measured memory_bytes: 9208
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int time, hour, minute, second;
    
    cin >> time ;
    
    minute = time / 60;
    second = time % 60;
    
    hour = minute / 60;
    minute = minute % 60;
    
    printf("%d:%d:%d\n", hour, minute, second);
    
    return 0;
}

Measured memory_bytes: 1144
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum, ans[2], dp[10000][10000],a[200000], b[2000000];
string str, ss, dd;
bool f,ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	if (a[n - 1] != 2) {
		cout << -1 << endl;
		return 0;
	}
	ans[0] = 2, ans[1] = 2;
	Mfor(i, n) {
		if (ans[1] >= a[i]) {
			ans[0] = a[i] * (ans[0] / a[i] + (ans[0] % a[i] == 0 ? 0 : 1));
			ans[1] = a[i] * (ans[1] / a[i]) + a[i] - 1;
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}
	LL A[2] = { ans[0],ans[1] };
	rep(i, n) {
		A[1] -= A[1] % a[i];
		A[0] -= A[0] % a[i];
	}
	if (A[1] != 2 || A[0] != 2) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans[0] << " " << ans[1] << endl;
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[100+5];
 int n,sum;
 int count1;
 
 void dfs(int i,int x,int m)
 {
   if(x>sum) return;
   if((i==n))
   {
     //for(int i=0;i<n;i++) cout<<arr[i]<<" ";
     //cout<<endl;
     if(sum==x&&m==3)
     {
       count1++;
       //for(int i=0;i<n;i++) cout<<arr[i]<<" ";
       //cout<<endl;
     }
     return;            
   }
   dfs(i+1,x+arr[i],m+1);
   dfs(i+1,x,m);    
   return;
 }

 int main()
 {
   while(cin>>n>>sum&&(n||sum))
   {
     count1=0;
     for(int i=0;i<n;i++) arr[i]=i+1;
     for(int i=0;i<n;i++)
     {
       for(int j=i+1;j<n;j++)
       {
         for(int k=j+1;k<n;k++)
         {
           if((arr[i]+arr[j]+arr[k])==sum) count1++;        
         }        
       }        
     }                    
     cout<<count1<<endl;
   }
   //while(1);
   return 0;
 }
 

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

int main(void){
  char c;
  while((c=getchar()) != '\n'){
    for(int i=0;i<3;i++){
      if(c=='A') c='Z';
      else c--;
    }
    printf("%c",c);
  }
  printf("\n");
  return 0;
}



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

using namespace std;

#define ll long long
#define uint unsigned int

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

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

    vector<int> q;
    for (const auto& el : a) {
        q.push_back(el.second);
    }

    sort(q.rbegin(), q.rend());

    int sum = 0;
    for (int i = k; i < (int)q.size(); ++i) {
        sum += q[i];
    }

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

    return 0;
}


Measured memory_bytes: 10748
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int l[100002], r[100002];
    int lmax = 0, rmin = n;
    for(int i = 0; i < m; i++){
        cin >> l[i] >> r[i];
        lmax = max(lmax, l[i]);
        rmin = min(rmin, r[i]);
    }
    cout << max(0, rmin - lmax + 1) << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e5+5;

int main()
{
    LL N;
    while(scanf("%lld",&N)!=EOF)
    {
        LL h,n,t1,t2;
        bool flag=false;
        for(h=1;h<=3500;h++)
        {
            for(n=1;n<=3500;n++)
            {
                t1=N*h*n;
                t2=4*h*n-n*N-h*N;
                if(t1>0&&t2>0&&t1%t2==0)
                {
                    printf("%lld %lld %lld\n",h,n,t1/t2);
                    flag=true;
                    break;
                }
            }
            if(flag) break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;

int main(){
    ll x=0,y=0,d=0,n,h,w,k,m,max=-100,ans=0,ptr=0,sum=0;
    string s,s1,s2;
    bool f=true;

    cin >> n >> m;
    vector<pair<ll, ll> > a(n);
    rep(i,n){
        cin >> x >> y;
        a[i]= make_pair(x,y);
	}
    sort(ALL(a));
    for(int i=0; i<n;i++){

        if(sum + a[i].second <= m){
            sum += a[i].second;
            ans += (a[i].first) * (a[i].second);
        }
        else{
            d = m-sum; 
            sum += d;
            ans += (a[i].first) * d;
        }
        if(sum==m) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define VV vector<vector<int>>

const ll MOD = 1000000007;
const ll base = 998244353;
const ll MOD2 = 2111211121;
const ll base2 = 1222122211;
const VV CC(26, vector<int>(26, 0));

map<pair<int, int>, int> convert;
int G[400010][26];
int R[400010];
int T[400010];
char P[400010];
int dat[100010];
int fans[100010];
vector<pair<int, VV>> query[100010];

int dfs(int c) {
	int ans = 0;
	for (auto i : G[c]) {
		if (i < 0)continue;
		ans += dfs(i);
	}
	T[c] += ans;
	return T[c];
}

void accend(int x, char c, VV& gr) {
	for (int j = 0;j < 26;j++) {
		if (G[x][j] < 0)continue;
		gr[c - 97][j] += T[G[x][j]];
	}
	if (x == 0)return;
	accend(R[x], P[x], gr);
}

int main(){
	int N, Q, ss, k, num = 0, fn, hn, v, p;
	cin >> N;
	string S;
	ll has, fmr, has2, fmr2;
	for (int i = 0;i < 400010;i++) {
		for (int j = 0;j < 26;j++) {
			G[i][j] = -1;
		}
	}
	for (int i = 0;i < N;i++) {
		cin >> S;
		ss = S.size();
		has = has2 = 0;
		for (int j = 0;j < ss;j++) {
			fmr = has;
			fmr2 = has2;
			has *= base;
			has2 *= base2;
			has += (ll)S[j];
			has2 += (ll)S[j];
			has %= MOD;
			has2 %= MOD2;

			if (convert.count({ fmr,fmr2 }))fn = convert[{fmr, fmr2}];
			else {
				convert.insert({ {fmr,fmr2},num });
				fn = num;
				num++;
			}

			if (convert.count({ has, has2 }))hn = convert[{has, has2}];
			else {
				convert.insert({ { has,has2 }, num });
				hn = num;
				num++;
			}

			G[fn][S[j] - 97] = hn;

			R[hn] = fn;

			P[hn] = S[j];
		}
		T[hn] = 1;
		dat[i] = hn;
	}
	dfs(0);
	cin >> Q;
	VV RVS = CC;
	for (int i = 0;i < Q;i++) {
		cin >> k;
		k--;
		cin >> S;
		for (int x = 0;x < 26;x++) {
			for (int y = x + 1;y < 26;y++) {
				RVS[S[x] - 97][S[y] - 97] = 1;
			}
		}
		query[k].push_back(make_pair(i, RVS));
		RVS = CC;
	}

	VV CCS;
	for (int i = 0;i < N;i++) {
		CCS = CC;
		k = dat[i];
		accend(R[k], P[k], CCS);
		for (auto j : query[i]) {
			tie(v, RVS) = j;
			p = T[k] - 1;
			for (int x = 0;x < 26;x++) {
				for (int y = 0;y < 26;y++) {
					if (x == y)continue;
					if (RVS[x][y] == 0)continue;
					p += CCS[x][y];
				}
			}
			fans[v] = p;
		}
	}
	for (int i = 0;i < Q;i++) {
		cout << N - fans[i] << endl;
	}
}

Measured memory_bytes: 441844
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();

int main() {
  unsigned long long h;
  scanf("%llu", &h);
  unsigned long long w;
  scanf("%llu", &w);

  unsigned long long c = 0;

  if (w == 1 || h == 1) {
    c = 1;
  } else if (w % 2 == 0 || h % 2 == 0) {
    c = w * h / 2;
  } else {
    c = w * h / 2 + 1;
  }

  printf("%llu\n", c);
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc082/tasks/arc087_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    unordered_map<int, int> mp;
    REP(i, N) {
        int t;
        cin >> t;
        mp[t]++;
    }
    int ans = 0;
    for (auto &x : mp) {
        if (x.first <= x.second) {
            ans += x.second - x.first;
        } else {
            ans += x.second;
        }
    }
    cout << ans << endl;
}
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int N; cin >> N;

  vector <int> A(N);
  int ans = 0, Q = 0;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    ans += abs(A[i]);

    if (A[i] < 0) Q++;
  }
  sort(A.begin(), A.end());


  if (Q != 0 && Q != N){
    cout << ans << endl;
  }else if(Q == 0){
    cout << ans - 2 * A[0] << endl;
    Q++;
  }else if(Q == N){
    cout << ans + 2 * A[N - 1] << endl;
    Q--;
  }

  int now = A[0];
  for (int i = Q; i < N - 1; i++){
    cout << now << " " << A[i] << endl;
    if (i != N - 1) now = now - A[i];
  }
  
  for (int i = 0; i < Q; i++){
    if (i == 0){
      cout << A[N - 1] << " " << now << endl;
      now = A[N - 1] - now;
    }else{
      cout << now << " " << A[i] << endl;
      now = now - A[i];
    }
  }
  

    

  return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>

int main(){
    int a,b;
    char op;
    int ans;
    
    while(1){
        scanf("%d %c %d", &a,&op,&b);
        if (op == '?'){
            break;
        }
        
        switch(op){
            case '+': 
                ans = a + b;
                break;
            case '-':
                ans = a - b;
                break;
            case '*':
                ans = a * b;
                break;
            case '/':
                ans = a / b;
                break;
        }
        
        printf("%d\n", ans);
    }
    return 0;
}
            
             

Measured memory_bytes: 600
using System;

public class Test
{
	static public void Main( )
	{
		const int S = 0;
		const int H = 1;
		const int C = 2;
		const int D = 3;		
		int n = int.Parse( Console.ReadLine() );
		int[,] shcd = new int[4, 13] {
			{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
			{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
			{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
			{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },};
		for( int i=0; i<n; i++ ) {
			string[] strs = Console.ReadLine().Split( ' ' );
			int val = 0;
			switch( strs[0] ) {
				case "S":val = S;
					break;
				case "H":val = H;
					break;
				case "C":val = C;
					break;
				case "D":val = D;
					break;
			}
			shcd[ val, int.Parse( strs[1] )-1 ] = 1;
		}
		for( int i=0; i<4; i++ ) {
			for( int j=0; j<13; j++ ) {
				if( S == i && 0 == shcd[S,j] ) {
					Console.WriteLine( "S "+(j+1) );
				} else if( H == i && 0 == shcd[H,j] ) {
					Console.WriteLine( "H "+(j+1) );
				} else if( C == i && 0 == shcd[C,j] ) {
					Console.WriteLine( "C "+(j+1) );
				} else if( D == i && 0 == shcd[D,j] ) {
					Console.WriteLine( "D "+(j+1) );
				}
			}
		}
	}
}

Measured memory_bytes: 5708
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int n;
ll dp[1000][1000];
bool used[1000][1000];

int main(){
	cin >> n;
	rep(i, n) {
		rep(j, n) {
			cin >> dp[i][j];
			used[i][j] = true;
		}
	}
	bool f = true;
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				if (dp[i][j] > dp[i][k] + dp[j][k])f = false;
				else if (dp[i][j] == dp[i][k] + dp[j][k]) {
					if (i != k&&j != k)used[i][j] = false;
				}
			}
		}
	}
	if (f == 0)cout << -1 << endl;
	else {
		ll sum = 0;
		rep(i, n) {
			FOR(j, i + 1, n) {
				if (used[i][j])sum += dp[i][j];
			}
		}
		cout << sum << endl;
	}
}

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

int main()
{
  string s,ans;
  cin>>s;
  for(int i=0;i<3;i++)
  {
    if(s.at(i)==s.at(i+1))
    {
      ans="Bad";
      cout<<ans<<endl;
      break;
    }
  }
  if(ans!="Bad")
  {
    cout<<"Good"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
ll dp[3020][3020][5];
ll a[3020][3020];
int main()
{
    int r,c,k;
    cin>>r>>c>>k;
    for(int i=0; i<k; i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        a[x][y]=z;
    }
    for(int i=1; i<=r; i++)
    {
        for(int j=1; j<=c; j++)
        {
            if(j==1)
            {
                dp[i][j][3]=dp[i-1][1][3]+a[i][j];
                dp[i][j][2]=dp[i-1][1][3]+a[i][j];
                dp[i][j][1]=dp[i-1][1][3]+a[i][j];
                dp[i][j][0]=dp[i-1][1][3];
                continue ;
            }
            dp[i][j][0]=max(dp[i][j-1][0],dp[i-1][j][3]);
            for(int k=1; k<=3; k++)
            {
                dp[i][j][k]=max(dp[i][j-1][k],dp[i][j-1][k-1]+a[i][j]);
                dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][3]+a[i][j]);
            }

        }
    }
    cout<<dp[r][c][3]<<endl;
    return 0;
}


Measured memory_bytes: 427864
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define rep(i, n) for(int i=0;i<n;i++)

int main() {
  string s;
  cin >> s;
  bool a=false;
  bool b=false;
 if(s.at(0)=='0'&&s.at(1)!='0') a=1;
  if(s.at(0)=='1' && (s.at(1)=='0' ||s.at(1)=='1' ||s.at(1)=='2')){
	a=1;
 }
  if(s.at(2)=='0'&& s.at(3)!='0') b=1;
    if(s.at(2)=='1' && (s.at(3)=='0' ||s.at(3)=='1' ||s.at(3)=='2')){
	b=true;
 }
  if(a && b) cout <<"AMBIGUOUS" << endl;
  else if(a) cout << "MMYY" <<endl;
  else if(b) cout << "YYMM" <<endl;
  else cout <<"NA" <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int N;	cin>>N;
	int check=1;
	rep(i,0,N){
		int a;cin>>a;
		if(a==check) check++;
	}
	int ans=-1;
	if(check>1){
		ans=N-check+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
int main(){

  int n,i,j,flag,v,k,count = 0;

  scanf("%d",&n);

  int A[n];

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

  flag = 1;

  i = 0;


  while(flag){

    flag = 0;
   
    for(j=n-1;j>=i+1;j--){
      if(A[j] < A[j-1]){
	v = A[j];
	A[j] = A[j-1];
	A[j-1] = v;
	flag = 1;
	count++;
      }
    
    }
    i++; 
   
  }

  for(i=0;i<n;i++){
    printf("%d",A[i]);

    if(i<n-1){
      printf(" ");
    }

    else{
      printf("\n");
    }
  }

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



Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
char g;
char f[4][13],a,pp;
int v[4][13],tt[100];
main(){
  tt['T']=10;tt['J']=11;tt['Q']=12;tt['K']=13;tt['A']=14;
  while(scanf("%c%c",&g,&pp),g!='#'){
    for(int i=0;i<4;i++)
      for(int j=0;j<13;j++){
          scanf("%c%c%c",&a,&f[i][j],&pp);
          if(a>='0'&&a<='9')v[i][j]=a-'0';
          else v[i][j]=tt[(int)a];
        }
    int lead=0,score[2]={};
    for(int i=0;i<13;i++){
      int w=-1,ws=-1;
      for(int j=0;j<4;j++){
        int sc=v[j][i];
        if(f[j][i]==g)sc+=100;
        if(f[j][i]!=g&&f[j][i]!=f[lead][i])continue;
        if(sc>ws)ws=sc,w=j;
      }
      lead=w;
      score[w%2]++;
    }
  if(score[0]>score[1])cout<<"NS "<<score[0]-6<<endl;
  else cout<<"EW "<<score[1]-6<<endl;
  }
}

Measured memory_bytes: 3220
#include <stdio.h>

int main(void)
{
    int D, N;
  
    scanf("%d %d", &D, &N);
    
    if(D==0)
        printf("%d\n", N+N/100);
    else if(D==1)
        printf("%d\n", 100*(N+N/100));
    else
        printf("%d\n", 10000*(N+N/100));
        

    //system("pause");
    
    return 0;
}

Measured memory_bytes: 128
n = input()
op_cnt = len(n) - 1  
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt 
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  
    formula = ""
    for p_n, p_o in zip(n, op + [""]): 
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>

using namespace std;

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

	const int N = 13;
	long long dp[N];
	long long tempDp[N];
	for (int i = 0; i < N; ++i) {
		dp[i] = 0;
		tempDp[i] = 0;
	}
	dp[0] = 1;

	const long long mod = 1000000007;
	long mul = 1;
	for (int i = S.length() - 1; 0 <= i;--i) {

		for (int l = 0; l < N; ++l)tempDp[l] = 0;
		
		if (S[i] == '?') {
			for (int j = 0; j < 10;++j) {
				for (int k = 0; k < N;++k) {
					int target = ((j*mul) % N + k) % N;
					tempDp[target] += dp[k];
					tempDp[target] %= mod;
				}
			}
		}
		else {
			int j = (int)(S[i] - '0');
			//それぞれのkに対して余りを足した場合の更新をかける
			for (int k = 0; k < N;++k) {
				int target = ((j*mul) % N + k) % N;
				tempDp[target] += dp[k];
				tempDp[target] %= mod;
			}
		}
		mul *= 10;
		mul %= N;
		for (int l = 0; l < N; ++l)dp[l] = tempDp[l];
	}
	cout << dp[5] << endl;
}


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

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

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

fn main() {
    input!(
        s: chars
    );
    let out = if (s[0] == s[1]) && (s[1] == s[2]) {
        "No"
    } else {
        "Yes"
    };
    println!("{}", out);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V  = vector<T>;
template<class T = int> using VV = V< V<T> >;
struct QU {
  V<> par;
  QU(int n) { par.resize(n); iota(par.begin(), par.end(), 0); }
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) { par[find(x)] = find(y); }
};
int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  QU qu(n);
  for (int i = 0; i < q; i++) {
    int c, x, y; cin >> c >> x >> y;
    if (c) cout << qu.same(x, y) << '\n';
    else qu.unite(x, y);
  }
}


Measured memory_bytes: 3224
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

vector<ll> even_to[100005];
vector<ll> odd_to[100005];
ll ans[100005];

void dfs(ll v, ll p = -1) {
    debug("dfs", v, p);
    for (ll u : even_to[v]) {
        if (u == p) continue;
        if (ans[u] != 0) continue;
        ans[u] = ans[v];
        dfs(u, v);
    }

    for (ll u : odd_to[v]) {
        if (u == p) continue;
        if (ans[u] != 0) continue;
        ans[u] = -ans[v];
        dfs(u, v);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    REP(i, N-1) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        if (w % 2 == 0) {
            even_to[u].push_back(v);
            even_to[v].push_back(u);
        } else {
            odd_to[u].push_back(v);
            odd_to[v].push_back(u);
        }
    }

    ans[0] = 1;
    dfs(0);
    REP(i, N) {
        if (ans[i] == 1) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 12544
#include <iostream>

using namespace std;
int check(int k, int a, int b)
{
    int c=b%k;
    int d=a%k;
    if(c == 0 || d==0)
     return 1;
    if(b-c>a)
     return 1;
    else
     return 0;
}

int main()
{
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    if(check(k,a,b)==1)
     cout<<"OK";
    else
     cout<<"NG";
    return 0;
}


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

using namespace std;


typedef pair <long long ,long long>	PII;
typedef vector <int>	VI;
typedef vector <PII>    VII;
typedef priority_queue<PII,vector<PII>,greater<PII>> pairMinHeap;
typedef priority_queue<PII> pairMaxHeap;
typedef priority_queue<long long ,vector<long long>,greater<long long>> minHeap;
typedef priority_queue<long long> maxHeap;

#define what_is(x) cerr <<#x<<" is "<<x<<endl;
#define wis(x,y) cerr <<#x<<" is "<<x<<" and "<<#y<<" is "<<y<<endl;
#define getarr(n,d) for(int i=0;i<n;i++)cin>>d[i];
#define getgraph(n,g) for(int i=1;i<n;i++){int a,b;cin>>a>>b;a--;b--;g[a].push_back(b);g[b].push_back(a);}
#define getpartree(n,tree) for(int i=1;i<n;i++){int a;cin>>a;tree[a-1].push_back(i);}

struct POS{
    int x=0,y=0;
    POS():x(0),y(0){}
    POS(int _x,int _y):x(_x),y(_y){}
};

struct triple{
    int f,s,t;
    triple():f(0),s(0),t(0){}
    triple(int _f,int _s,int _t):f(_f),s(_s),t(_t){}
};

const int INF = 1e9+9;
const long long LINF = 1e17+9;
const long long MD=998244353 ;

inline long long po(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1)ans = (ans*a)%MD;
        a = (a*a)%MD;
        b/=2;
    }
    return ans;
}


const int N=2e5+33;

long long n,m,k,t;
long long arr[N];
string s;


int main() {
	ios_base::sync_with_stdio(false);cout.tie(nullptr);cin.tie(nullptr);cout << fixed;cout << setprecision(10);
    cin>>n>>m>>k;
    cout<<(n-m+1)*(n-k+1);

    return 0;
}


Measured memory_bytes: 256
void main() {
    string[] tmp = readln.split;
    int a = tmp[0].to!int, b = tmp[2].to!int;
    string op = tmp[1];
    writeln(op == "+" ? a + b : a - b);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [i for i, j in ab]
b = [j for i, j in ab]
a.sort()
b.sort()

if n % 2 == 1:
    print(abs(b[n//2] - a[n//2]) + 1)
else:
    t = [a[n // 2], a[n // 2 - 1], b[n // 2], b[n // 2 - 1]]
    print(int(abs((t[0] + t[1]) / 2 - (t[2] + t[3]) / 2) / 0.5) + 1)

Measured memory_bytes: 49200
/*
Stay innocent, be naive. 
But still dream big. 
Dream big to the point that it is beyond your ability and endeavour to achieve it. 
So dream big and don’t lose your innocence.
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         HashMap<String, Integer> map = new HashMap<String, Integer>();
         for(int i=0; i < N; i++)
         {
            char[] c = infile.readLine().toCharArray();
            sort(c);
            StringBuilder sb = new StringBuilder();
            for(char x: c)
               sb.append(x);
            String key = sb.toString();
            if(!map.containsKey(key))
               map.put(key, 0);
            map.put(key, map.get(key)+1);
         }
         long res = 0L;
         for(String k: map.keySet())
         {
            long num = map.get(k);
            res += num*(num-1)/2;
         }
         System.out.println(res);
      }
      public static void sort(char[] arr)
      {
         //stable heap sort
         PriorityQueue<Character> pq = new PriorityQueue<Character>();
         for(char a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }

Measured memory_bytes: 54456
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	vector<int>V;
	V.push_back(A);
	V.push_back(B);
	V.push_back(C);
	sort(V.begin(), V.end());
	int a;
	a= V[2] - V[0];
	int b;
	b= V[2] - V[1];
	if (a % 2 == b % 2)
		cout << (a + b) / 2 << endl;
	else
		cout << (a + b + 1) / 2 + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int n,a[100],ans=0;
cin >> n;
for(int i=0;i<n;i++)cin >> a[i];
for(int i=0;i<n;i++){
for(int j=n-1;j>=i+1;j--){
if(a[j]<a[j-1]){
	swap(a[j],a[j-1]);
ans++;}}
}
for(int i=0;i<n;i++){
if(i==n-1)cout << a[i] << "\n";
else cout << a[i] << " ";
}
cout << ans << "\n";
return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y)
{
    if (y < 0) {
        return dceil(-x, -y);
    }
    if (x < 0) {
        return -dfloor(-x, y);
    }
    return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y)
{
    if (y < 0) {
        return dfloor(-x, -y);
    }
    if (x < 0) {
        return -dceil(-x, y);
    }
    return x / y;
}

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

    int64_t rt, ra;
    rep(i, n)
    {
        int t, a;
        cin >> t >> a;

        if (i == 0) {
            rt = t;
            ra = a;
        } else {
            int64_t x = 0;
            x = max(x, dceil(rt, t));
            x = max(x, dceil(ra, a));
            rt = x * t;
            ra = x * a;
        }
    }
    int64_t result = rt + ra;
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	static int cnt = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int A[] = new int[n];
		for (int i = 0; i < n; i++)
			A[i] = sc.nextInt();

		sc.close();

		mergeSort(A, 0, n);
		StringBuilder sb = new StringBuilder(11 * n).append(A[0]);
		IntStream.range(1, n).forEach(t -> sb.append(' ').append(A[t]));
		System.out.println(sb.append('\n').append(cnt).toString());
	}

	static void merge(int[] A, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int L[] = new int[n1 + 1];
		int R[] = new int[n2 + 1];

		IntStream.range(0, n1).forEach(i -> L[i] = A[left + i]);
		IntStream.range(0, n2).forEach(i -> R[i] = A[mid + i]);
		L[n1] = R[n2] = Integer.MAX_VALUE; // TODO SENTINEL
		int i = 0, j = 0;
		for (int k = left; k < right; k++) {
			cnt++;
			if (L[i] <= R[j]) {
				A[k] = L[i];
				i++;
			} else {
				A[k] = R[j];
				j++;
			}
		}
	}

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


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

bool contain(string &str, char c){
    return str.find(c) != string::npos;
}

int main()
{
    string answer;

    for(int i = 0; i < 3; i++){
        string s;
        cin >> s;
        answer += s[i];
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

map<ll,ll> f;
ll so(ll P) {
    ll Q = P;
    ll cnt = 0;
    for (ll i = 2; i*i <= P; i++) {
        while (Q % i == 0) {
            Q /= i;
            f[i]++;
            cnt++;
        }
        if (Q == 0) break;
    }
    return cnt;
}

int main() {
    ll N, P; cin >> N >> P;
    if (N == 1) {
        cout << P << endl;
        return 0;
    }
    ll cnt = so(P);
    if (cnt == 0 || N > cnt) {
        cout << 1 << endl;
        return 0;
    } else {
        ll g = 1;
        for (auto [u,v] : f) {
            g = g * (ll)pow(u, v/N);
        }
        cout << g << endl;
    }
}


Measured memory_bytes: 4032
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
long long  n,m;
using namespace std;
int main()
{
	while(cin>>n>>m){
		if(n>=m/2)
		 cout<<m/2<<endl;
		else
		cout<<n+(m-2*n)/4<<endl;
		 
	}

}

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

int main() {
  int n, m;
  cin >> n >> m;
  multiset<int> arr;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    arr.insert(-a);
  }
  for (int j = 0; j < m; ++j) {
    int new_element = abs(*arr.begin()) / 2;
    arr.erase(arr.begin());
    arr.insert(-new_element);
  }
  long long ans = 0;
  for (auto a : arr) {
    ans -= a;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
/*
author:Rahul Chocha
school of eng. and applied science
*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define MAXI INT_MAX
#define MINI INT_MIN
#define din(t) long long t; cin >> t;
#define fi(i, l, r, d) for (i = l; i < r; i += d)
#define fd(i, l, r, d) for (i = l - 1; i >= r; i -= d)
#define pb push_back
#define mp make_pair


void speed_up()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
void Inp_Out(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("A.01.inp", "r", stdin);
    // for writing output to output.txt
    //freopen("A.01.out", "w", stdout);
    #endif
}

int main()
{   

   	speed_up();
   	//Inp_Out();
	din(n)
	ll i;
	map<string,ll>m;
	string s;
	m["AC"]=0;
	m["TLE"]=0;
	m["WA"]=0;
	m["RE"]=0;
	fi(i,0,n,1){
		cin>>s;
		m[s]++;
	}
	cout<<"AC x " <<m["AC"]<<"\n";
	cout<<"WA x " <<m["WA"]<<"\n";
	cout<<"TLE x " <<m["TLE"]<<"\n";
	cout<<"RE x " <<m["RE"]<<"\n";

} 


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

#pragma region  // {{{

#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
#define rep(i, begin, end) for (int64_t i{begin}, i##_end{end}; i < i##_end; ++i)
#define repc(i, begin, last) for (int64_t i{begin}, i##_last{last}; i <= i##_last; ++i)
#define repr(i, begin, last) for (int64_t i{begin}, i##_last{last}; i >= i##_last; --i)
#define let const auto
using i64 = std::int64_t;
using u64 = std::uint64_t;

constexpr int32_t INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

void ioSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(11);
    std::cerr << std::fixed << std::setprecision(11);
    std::clog << std::fixed << std::setprecision(11);
}

template <class T>
std::istream& operator,(std::istream& is, T& rhs) {
    return is >> rhs;
}

#define var(type, ...) \
    type __VA_ARGS__;  \
    std::cin >> __VA_ARGS__

inline void println() {
    std::cout << '\n';
}
template <class Head, class... Tail>
inline void println(Head&& head, Tail&&... tail) {
    std::cout << head << " " + (!sizeof...(tail));
    println(std::forward<Tail>(tail)...);
}

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

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

#pragma endregion  // }}}

// constexpr int MOD = int(1e9) + 7;
// constexpr int MOD = 998244353;

signed main() {
    ioSetup();

    var(i64, a, b, c, d);

    i64 ans = -LINF;
    for (let x : vector<i64>{a, -1, 0, 1, b}) {
        for (let y : vector<i64>{c, -1, 0, 1, d}) {
            if (a <= x && x <= b && c <= y && y <= d) {
                chmax(ans, x * y);
            }
        }
    }

    println(ans);

    return 0;
}


Measured memory_bytes: 3652
N,T = map(int,input().split())
li = []

for i in range(N):
  li.append(int(input()))

newLi = sorted(li)

for x in newLi:
  T -= x

count = 0
while(True):
  if T - newLi[0] < 0:
    break
  T -= newLi[0]
  count += 1

print(N + count)

Measured memory_bytes: 3064
#!/usr/bin/env python
# coding: utf-8

# In[8]:


N = int(input())
S = input()


# In[19]:


ans = 0
for i in range(10):
    str_i = str(i)
    i_index = S.find(str_i)
    if i_index == -1:
        continue
    for j in range(10):
        str_j = str(j)
        j_index = S.find(str_j, i_index+1)
        if j_index == -1:
            continue
        for k in range(10):
            str_k = str(k)
            k_index = S.find(str_k, j_index+1) 
            if k_index != -1:
                ans += 1
print(ans)


# In[ ]:






Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    bool ok = true;
    rep(i, n - 1) if (s[i][s[i].size() - 1] != s[i + 1][0]) ok = false;
    sort(all(s));
    rep(i, n - 1) if (s[i] == s[i + 1]) ok = false;
    cout << (ok ? "Yes" : "No") << endl;
}

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

#define rep(i,m,n) for(int i=m;i<n;i++)
#define pb push_back
#define ll long long 
#define out(n) cout<<#n<<' = '<<'\n'

using namespace std;

const int maxn=1e5;
int a[maxn];

int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    rep(i,0,m) cin>>a[i],sum+=a[i];
    if(n-sum<0)
        cout<<"-1";
    else
        cout<<n-sum;
    return 0;
}

Measured memory_bytes: 3636
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *X = map(int, read().split())

    A = [abs(x - X[0]) for x in X]

    ans = INF
    for i in range(N - K + 1):
        if ans > min(abs(X[i]), abs(X[i + K - 1])) + A[i + K - 1] - A[i]:
            ans = min(abs(X[i]), abs(X[i + K - 1])) + A[i + K - 1] - A[i]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20044
#include <cstdio>

int main() {
    char s[10];
    scanf("%s", s);
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    for (auto i = 0; i < 2; i++) {
        for (auto j = 0; j < 2; j++) {
            for (auto k = 0; k < 2; k++) {
                if (a + (i?-b:b) + (j?-c:c) + (k?-d:d) == 7) {
                    printf("%c%c%c%c%c%c%c=7\n", s[0], i?'-':'+', s[1], j?'-':'+', s[2], k?'-':'+', s[3]);
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

h,w,k= map(int, input().split())
s = [list(input().strip()) for i in range(h)]

for i in range(h):
    for j in range(w):
        s[i][j]=int(s[i][j])

for i in range(h):
    for j in range(1,w):
        s[i][j]+=s[i][j-1]

for i in range(w):
    for j in range(1,h):
        s[j][i]+=s[j-1][i]


s=[[0]*w]+s
for i in range(h+1):
    s[i]=[0]+s[i]

ans=float('inf')
#bit 全探索
for i in range(2**(h-1)):
    line=[]
    for j in range(h-1):
        if (i>>j)&1:
            line.append(j+1)
    cnt=len(line)
    line=[0]+line+[h]
    x=0
    flag=True
    for k1 in range(1,w+1):
        v=0
        for l in range(len(line)-1):
            # どう分割してもダメな奴に✖︎のフラグ立てる
            if s[line[l+1]][k1]-s[line[l+1]][k1-1]-s[line[l]][k1]>k:
                flag=False
            v=max(s[line[l+1]][k1]-s[line[l+1]][x]-s[line[l]][k1]+s[line[l]][x],v)

        if v<=k:
            continue
        else:
            cnt+=1
            x=k1-1
    if flag:
        ans=min(cnt,ans)
print(ans)

Measured memory_bytes: 46300
//Golden Coins

#include<iostream>
using namespace std;

int main (){
    int X,a,b,ans;
    cin >> X;
    a = X / 500;
    a = a * 1000;
    b = (X % 500) /5;
    b = b * 5;
    ans = a + b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
 
#define ll long long
#define mod 1000000007
 
void ans(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    ll ans=0;
    for(int i=0;i<n-1;i++){
        ll x=arr[i+1]-arr[i];
        ans+=min(a*x,b);
    }
    cout<<ans;
}
 
int main() {
    ans();
}

Measured memory_bytes: 4396
#include <stdio.h>

int dp[50];

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

int main(){
  int n,i;
  for(i=0;i<50;i++)dp[i]=-1;
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}



Measured memory_bytes: 2052
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                void solve(){
                        ll n;
                        cin>>n;
                        if(n&1){
                                cout<<0;
                                return ;
                        }
                        n=(n/5)*5;
                        ll k=10,cnt=1;
                        ll ans=0;
                        while(k<=n && k>0){
                                ans+=(n/k);
                                k*=5;
                                // cnt++;
                                // k
                        }
                        cout<<ans;
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //printf("Case #%d: ", i);
                                solve();
                         }
        return 0; 
}         
 

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

int l, n;
int a[400000];
int main() {
  cin >> l >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i + n] = a[i] + l;
  }
  
  int mn = 1e9;
  for (int i = 0; i < n; ++i) {
    mn = min(mn, a[i + n - 1] - a[i]);
  }
  cout << mn << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

    string S;
    cin >> S;

    int ans = 0;
    for (int i = 0; i < N - 1; i++)
    {
        if (S[i] != S[i + 1])
        {
            ans++;
        }
    }
    ans++;
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;
int main() {
   int n,q,i,j=0,k,ans=0,temp2=0;
   string s;
   cin>>n>>q>>s;
   vector<int> l(q),r(q);
   map<int,int> chizu;

   for(i=0;i<q;i++){
       cin>>l[i]>>r[i];
   }

    for(j=0;j<n;j++){
        if(s[j]=='A'&&s[j+1]=='C'){
            chizu[j]=chizu[j-1]+1;
        }else{
            chizu[j]=chizu[j-1];
        }

    }

    for(i=0;i<q;i++) {


        cout << chizu[r[i]-2]-chizu[l[i]-2]<< endl;
    }

        //std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int main (){
    int N, M;
    cin>>N>>M;
    priority_queue<int> A;

    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        A.push(a);
    }
    for(int i=0;i<M;i++){
        A.push(A.top()/2);
        A.pop();
    }

    long long ans=0;
    for(int i=0;i<N;i++){
        ans+=A.top();
        A.pop();
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,l;
string s[125];

int main(){

cin>>n>>l;
REP(i,n)cin>>s[i];
sort(s,s+n);
REP(i,n)cout<<s[i];
cout<<endl;

  return 0;
}


Measured memory_bytes: 256