akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int h, w; cin >> h >> w;
    int data[h][w]; rep(i,h) rep(j,w) cin >> data[i][j];

    vector<vector<int>> ans(4,vector<int>());
    rep(i,h) rep(j,w){
        if(j == w-1){
            if(i == h-1) continue;
            if(data[i][j]%2 == 1){
                data[i][j]--;
                data[i+1][j]++;
                ans[0].push_back(i+1);
                ans[1].push_back(j+1);
                ans[2].push_back(i+2);
                ans[3].push_back(j+1);
            }
        }
        else if(data[i][j]%2 == 1){
            data[i][j]--;
            data[i][j+1]++;
            ans[0].push_back(i+1);
            ans[1].push_back(j+1);
            ans[2].push_back(i+1);
            ans[3].push_back(j+2);
        }
    }
    cout << ans[0].size() << endl;
    rep(i,ans[0].size()) cout << ans[0][i] << " " << ans[1][i] << " " << ans[2][i] << " " << ans[3][i] <<endl;
}

Measured memory_bytes: 6256
d = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(d))
T = list(int(input()) - 1 for i in range(d))

kaisai = [0] * 26
manzoku = 0
date = 0
for t in T:
    date += 1
    kaisai[t] = date
    manzoku += S[date - 1][t]

    for i in range(26):
        manzoku -= C[i] * (date - kaisai[i])
    
    print(manzoku)


Measured memory_bytes: 9052
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,dp[100100],c[100100][3],top,fa[100100];
long long ans=0;
struct node
{
	int x,y,id;
}a[100100];
struct edge
{
	node p,q;
	int w;
}e[300100];
bool cmp1(node a,node b)
{
	return a.x<b.x;
}
bool cmp2(node a,node b)
{
	return a.y<b.y;
}
bool cmp3(edge a,edge b)
{
	return a.w<b.w;
}
int getfa(int v)
{
	if(fa[v]==v) return v;
	fa[v]=getfa(fa[v]);
	return fa[v];
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp2);
	for(int i=2;i<=n;i++)
	{
		e[++top].p=a[i];
		e[top].q=a[i-1];
		e[top].w=a[i].y-a[i-1].y;
	}
	
	sort(a+1,a+n+1,cmp1);
	for(int i=2;i<=n;i++)
	{
		e[++top].p=a[i];
		e[top].q=a[i-1];
		e[top].w=a[i].x-a[i-1].x;
	}
	sort(e+1,e+top+1,cmp3);
	for(int i=1;i<=n;i++)
		fa[i]=i;
	int num=0,pnt=1;
	while(num<n-1)
	{
		for(int i=pnt;i<=top;i++)
			if (getfa(e[i].p.id)!=getfa(e[i].q.id))
			{
				pnt=i+1;
				fa[fa[e[i].p.id]]=fa[e[i].q.id];
				ans=ans+e[i].w;
				break;
			}
		num++;	
	}	
	cout<<ans<<endl;
	return 0;
}
/*3
1 5
3 9
7 8*/

Measured memory_bytes: 8448
import copy
N = int(input())
T = list(map(int,input().split()))
M = int(input())

res = []
for _ in range(M):
    tmp = copy.copy(T)
    P,X = map(int,input().split())
    tmp[P-1] = X
    res.append(sum(tmp))
for i in res:
    print(i)

Measured memory_bytes: 3444
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int main(void){
	int x=nextint();
	int k=0;
	for(int i=600; i<=2000; i+=200){
		k+=(x<i);
	}
	printf("%d\n", k);
}


Measured memory_bytes: 1604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
ll dp[110][110000];
int main(){
    ll n,mw;
    ll INF = 1e12;
    cin >> n>>mw;
    vector<int> v(n);
    vector<int> w(n);
    rep(i,n){
        cin >> w[i] >> v[i];
    }
    rep(i,n+1){
        rep(j,100010){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i,n){
        rep(j,100010){
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
            dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
        }
    }
    int ans = 0;
    rep(i,100010){
        if(dp[n][i]<=mw){
            ans = max(ans,i);
        }
    }
    cout << ans << endl;
return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

/*
18 26
*/
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;

    vector<set<int>> a(26);
    for (int i = 0; i < n; i++) {
        a[s[i] - 'a'].insert(i);
    }

    for (int i = 0; i < q; i++) {
        int type;
        cin >> type;
        if (type == 1) {
            int index;
            char new_c;
            cin >> index >> new_c;
            index--;
            a[s[index] - 'a'].erase(index);
            s[index] = new_c;
            a[s[index] - 'a'].insert(index);
        } else {
            int l, r;
            cin >> l >> r;
            l--, r--;
            int cnt = 0;
            for (int j = 0; j < 26; j++) {
                auto lower_it = a[j].lower_bound(l);
                auto upper_it = a[j].upper_bound(r);
                if (lower_it != upper_it)
                    cnt++;
            }
            cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 24196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 3005, K = 4;
vector<PII> row[N];
ll dp[2][N][K];
int val[N];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int r, c, k; cin >> r >> c >> k;
  while (k--) {
    int x, y, v; cin >> x >> y >> v;
    row[x].emplace_back(y, v);
  }

  for (int x = 1; x <= r; x++) {
    int cur = x & 1, prv = cur ^ 1;

    for (int y = 1; y <= c; y++) {
      val[y] = 0;
    }
    for (auto [y, v]: row[x]) {
      val[y] = v;
    }

    for (int y = 1; y <= c; y++) {
      for (int p = 0; p <= 3; p++) {
        dp[cur][y][p] = max({
          dp[cur][y - 1][p],
          dp[prv][y][p]
        });
        if (p) {
          dp[cur][y][p] = max({
            dp[cur][y][p],
            dp[cur][y][p - 1],
            dp[cur][y - 1][p - 1] + val[y],
            dp[prv][y][3] + val[y]
          });
        }
      }
    }
  }

  ll ans = 0;
  for (int p = 0; p <= 3; p++) {
    ans = max(ans, dp[r & 1][c][p]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int a, b;
	cin >> a >> b;
	if (a < 1 || a > 9 || b < 1 || b > 9) cout << -1 << endl;
	else cout << a * b << endl;	
	return 0;
}

Measured memory_bytes: 764
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include<climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main(void){
	ioboost;
	int r;cin >> r;
	cout << r*r << endl;


}

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

signed main() {
	int n, m, x, a[15][15], c[15], u[15];
	cin >> n >> m >> x;
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	}
	
	long long ans = 1e12;
	for (int S = 0; S < (1 << n); ++S) {
		memset(u, 0, sizeof u);
		long long t = 0;
		for (int i = 1; i <= n; i++) {
			if (!((S >> (i - 1)) & 1)) continue;
			for (int j = 1; j <= m; j++)
				u[j] += a[i][j];
			t += c[i];
		}
		bool f = 1;
		for (int i = 1; i <= m && f; i++)
			if (u[i] < x) f = 0;
		if (f) ans = min(ans, t);
	}
	cout << (ans == 1e12 ? -1 : ans) << endl;
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 550555;
const int L = 21;
const int M = 2155;

void solve() {
    ll r;
    cin >> r;
    
    cout << 2*PI*r;


}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int main() {
    int i,j;
    char a;

    scanf("%c", &a);
    if( isupper(a))
        printf("A\n");
    else
        printf("a\n");

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e5+10;
vector<int> vec[N];
int p[N],mol[N];
bool mark[N];
int cnt=1;
void dfs(int v){
    mark[v]=1;
    mol[v]=cnt;
    for(int u:vec[v])
        if(!mark[u])
            dfs(u);
}
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    while(m--){
        int a,b;cin>>a>>b;
        vec[a].pb(b);
        vec[b].pb(a);
    }
    for(int i=1;i<=n;i++)
        if(!mark[i])
            dfs(i),cnt++;
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=(mol[i]==mol[p[i]]);
    cout<<ans;
}



Measured memory_bytes: 9472
n = int(input())
s = str(input())
L = [[0]*2 for i in range(n+1)]
R = [[0]*2 for i in range(n+1)]

for i in range(n):
    L[i+1][0] = L[i][0]
    L[i+1][1] = L[i][1]
    if s[i] == 'E':
        L[i+1][0] += 1
    else:
        L[i+1][1] += 1

for i in reversed(range(n)):
    R[i][0] = R[i+1][0]
    R[i][1] = R[i+1][1]
    if s[i] == 'E':
        R[i][0] += 1
    else:
        R[i][1] += 1

ans = 10**18
for i in range(n):
    temp = L[i][1]+R[i+1][0]
    ans = min(ans, temp)
print(ans)


Measured memory_bytes: 80608
from collections import deque

S = input()
result_string = deque(S)
Q = int(input())
reverse_flag = 1
for idx in range(Q):
  new_in = input().split()
  if len(new_in) == 1:
    reverse_flag = -1*reverse_flag
  else:
    # 1 means right, -1 means left
    side_to_append = reverse_flag*(2*int(new_in[1])-3)
    if side_to_append == 1:
      result_string.append(new_in[2])
    else:
      result_string.appendleft(new_in[2])
if reverse_flag == -1: result_string.reverse()
print("".join(result_string))

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

int main(void){
    int a, b, made;
    cin >> a >> b;
    if (a > b){
        made = a;
    } else {
        made = b;
    }
    for (int k=0 ; k<made ; k++) {
        if (abs(a-k) == abs(b-k)) {
            cout << k << endl;
            exit(0);
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int n,m,l,A[101][101]={0},B[101][101]={0},i,j,k;
    long C[101][101]={0};
    scanf("%d %d %d",&n,&m,&l);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            scanf("%d",&A[i][j]);
        }
    }
    
    for (i = 0; i < m; i++) {
        for (j = 0; j < l; j++) {
            scanf("%d",&B[i][j]);
        }
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < l; j++) {
            for (k = 0; k < m; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < l; j++) {
            if (j < l-1) {
                printf("%ld ",C[i][j]);
            } else {
                printf("%ld",C[i][j]);
            }
            
        }
        printf("\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	string s;
	cin>>s;
	for (int i = 0; i < s.length(); ++i)
	{
		if(s[i]=='7'){cout<<"Yes"<<endl;return;}
	}
	cout<<"No"<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using L64 = int64_t;

/* {x,y}という表現で格納される[x^y] */
inline vector<pair<L64, int>> prime_factorize(L64 N) {
  vector<pair<L64, int>> res;
  for (int a = 2; a * a <= N; ++a) {
    if (N % a != 0) {
      continue;
    }
    int ex = 0;
    while (N % a == 0) {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

int main(void) {
  int N, max = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
    max = max < vec[i] ? vec[i] : max;
  }
  int a[max + 1];
  for (int i = 0; i < max + 1; i++) a[i] = 0;

  for (int i = 0; i < N; i++) {
    int b = vec[i];
    int c = b;
    while (b <= max) {
      a[b] += 1;
      b += c;
    }
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    if (a[vec[i]] == 1) {
      res++;
    }
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 7960
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    long long n, q;
    cin >> n >> q;
    vector<vector<long long>> as(n);
    for (int i = 0; i < q; i++) {
        int a, t, x;
        cin >> a >> t;
        if (a == 0) {
            cin >> x;
            as[t].push_back(x);
        } else if (a == 1) {
            for (int i = 0; i < as[t].size(); i++) {
                cout << as[t][i];
                if (i != as[t].size() - 1) {
                    cout << " ";
                }
            }
            cout << endl;
        } else {
            int k = as[t].size();
            for (int i = 0; i < k; i++) {
                as[t].pop_back();
            }
        }
    }
}


Measured memory_bytes: 8968
n,x,y=map(int,input().split())

x-=1
y-=1

dist=[0 for i in range(n)]
for i in range(n-1):
  for j in range(i+1,n):
    dist[min(j-i,abs(x-i)+1+abs(y-j))]+=1
for i in dist[1:]:
  print(i)

Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, a, b, ans=0;

	cin>>n>>a>>b;

	vll x(n);

	rep(i, n) cin>>x[i];

	repr(i, 1, n){
		ans+=min((x[i]-x[i-1])*a, b);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    string S;
    cin >> S;
    int num[4]={0};
    rep(i, 4){
        num[i] = S[i]-'0';
    }

    int pm = 0;
    rep(i, 1<<3){
        int ans = num[0];
        rep(j, 3){
            if ((i>>j)&1){
                ans += num[j+1];
            } else {
                ans -= num[j+1];
            }
        }
        if (ans == 7){
            pm = i;
            break;
        }
    }

    cout << num[0];
    rep(j,3){
        if ((pm>>j)&1)cout << "+"; 
        else cout << "-";
        cout << num[j+1];
    }
    cout << "=7" << endl;
}




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

int main(){
    int a,b;
    cin >> a >> b;

    int ans =-1;
    for(int x=10*b;x<10*(b+1);x++){
        if((8*x)/100 == a){
        ans = x;
        break;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    long long a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    long long sum1=a/c,sum2=b/c;
    if(a%c==0)
        sum1--;
    printf("%lld\n",sum2-sum1);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 200005;

int n, m, x, y, z, P[MAXN];
set<int> S;

int root(int v) {
    if (P[v] < 0) {
        return v;
    } else {
        P[v] = root(P[v]);
        return P[v];
    }
}

bool set_union(int v1, int v2) {
    int root_v1 = root(v1);
    int root_v2 = root(v2);

    if (root_v1 == root_v2) {
        return false;
    }

    if (P[root_v1] < P[root_v2]) {
        swap(root_v1, root_v2);
    }

    P[root_v2] = P[root_v1] + P[root_v2];
    P[root_v1] = root_v2;

    return true;
}

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

    for (int i = 0; i < n; i++) {
        P[i] = -1;
    }

    while (m--) {
        scanf("%d%d%d", &x, &y, &z);
        set_union(x - 1, y - 1);
    }

    for (int i = 0; i < n; i++) {
        S.insert(root(i));
    }

    printf("%d\n", sz(S));

    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  map<int,int> memo;
  rep(i,N){
    int x;cin >> x;
    ++memo[x];
  }
  vector<PII> v;
  for(auto it = memo.begin(), m_end = memo.end(); it != m_end; ++it){
    v.push_back((PII(it->first,it->second)));
  }
  sort(all(v));
  int res = 0;
  rep(i,v.size()){
    int count = v[i].second;
    if(i!=0) if(v[i].first == v[i-1].first+1) count += v[i-1].second;
    if(i!=v.size()-1) if(v[i+1].first == v[i].first+1) count += v[i+1].second;
    res = max(res,count);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3840
#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() {
  // const int C = 26;
  int D;
  cin >> D;

  vector<int> C(26);  // 0 to 25
  rep(i, 26) {
    cin >> C.at(i);
  }

  vector<vector<int>> S(D, vector<int>(26));  // 0 to 364, 0 to 25
  rep(i, D) {
    rep(j, 26) {
      cin >> S.at(i).at(j);
    }
  }

  int ans = 0;
  vector<int> L(26, 0);  // 0 to 25
  for (int d = 1; d <= D; d++) {
    // 1 to 365
    int t;  // 1 to 26
    cin >> t;
    L.at(t - 1) = d;

    ans += S.at(d - 1).at(t - 1);
    rep(i, 26) {
      ans -= C.at(i) * (d - L.at(i));
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans=max(x,y)*2*c;
    ans=min(ans,min(x,y)*2*c+(y>x?(y-x)*b:(x-y)*a));
    ans=min(ans,a*x+b*y);
    cout<<ans;
    return 0;
}

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

using namespace std;

int main() {
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  string res = "";
  for (int i = 0; i < n; i++) {
    res += s[i];
    res += t[i];
  }
  cout << res << '\n';
  return 0;
}


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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}

ll getinv(ll n) {
    return pw(n, mod - 2);
}

ll fac[N], invfac[N];

void init(int n) {
    fac[0] = invfac[0] = 1;
    for(int i = 1 ; i <= n ; ++ i) {
        fac[i] = fac[i - 1] * i % mod;
    }
    invfac[n] = pw(fac[n], mod - 2);
    for(int i = n - 1 ; i ; -- i) {
        invfac[i] = invfac[i + 1] * (i + 1) % mod;
    }
}
ll C(int n, int m) {
    return n < m || m < 0 ? 0 : fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
char s[N];
ll ans;

ll f(ll n) {
    return pw(3, n);
    ll r = 0;
    for(int i = 0 ; i <= n ; ++ i) {
        r += pw(2, i) * C(n, i) % mod;
        r %= mod;
    }
    return r;
}
void upd(ll &x, ll y) {
    x = (x + y) % mod;
}

int main() {
    init(N - 1);

    // for(int i = 1 ; i <= 10 ; ++ i) {
    //     cout << f(i) << endl;
    // }
    // exit(0);

    // for(int n = 0 ; n <= 100 ; ++ n) {
    //     int ans = 0;
    //     for(int a = 0 ; a <= n ; ++ a) {
    //         for(int b = 0 ; a + b <= n ; ++ b) {
    //             if((a + b) == (a ^ b)) {
    //                 assert((a & b) == 0);
    //                 ++ ans;
    //             }
    //         }
    //     }
    //     printf("%d, ", ans);
    // }

    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int x = 0;
    upd(ans, f(n - 1));
    for(int i = 1 ; i <= n ; ++ i) {
        // lcp: [1, i - 1]
        // s[i]=0
        // rest: [i + 1, n]
        if(i > 1 && s[i] == '1') {
            int y = n - i;
            upd(ans, pw(2, x) * f(y) % mod);
        }
        x += s[i] == '1';
    }
    upd(ans, pw(2, x));
    printf("%lld\n", ans);
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x = in.nextInt();

        int count = 1;
        int d = 0;
        for (int i = 0; i < n; i++) {
            int l = in.nextInt();
            d = d + l;
            if (d <= x) {
                count++;
            }
        }

        System.out.println(count);

    }
}


Measured memory_bytes: 22996
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
  vec<int, 2> G = make_v(4, 4, 0);
  for (int i = 0; i < 3; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a][b] = 1;
    G[b][a] = 1;
  }
  vector<int> ord(4);
  iota(ord.begin(), ord.end(), 0);
  bool res = false;
  do {
    bool ok = true;
    for (int i = 0; i + 1 < 4; i++) ok &= G[ord[i]][ord[i + 1]];
    res |= ok;
  } while (next_permutation(ord.begin(), ord.end()));
  cout << (res ? "YES" : "NO") << endl;
  return 0;
}


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

int main()
{
	int n,k=0;
	cin>>n;
	if(n%2==0||n%5==0)
	{
		cout<<"-1";
		return 0;
	}
	
	for(int i=1;i;i++)
	{
		k=(k*10+7)%n;
		if(k==0)
		{
			cout<<i;
			return 0;
		}
	}
}

Measured memory_bytes: 3636
#include <cstdio>
#include <numeric>
#include <cmath>
#include <algorithm>

template<typename _Tp>
constexpr _Tp floor(_Tp __x)
{ return __builtin_floor(__x); }

template<typename _Tp>
constexpr _Tp sqrt(_Tp __x)
{ return __builtin_sqrt(__x); }

template<int N>
struct sqrn
{
	constexpr static int max_sqrn = floor(sqrt(N));
	int value[max_sqrn + 1];

	sqrn() : value()
	{
		for (int i = 0; i <= max_sqrn; ++i)
		{
			value[i] = i * i;
		}
	}
};

sqrn<16000> sqr;

int main()
{
	int n, d;
	scanf("%d %d", &n, &d);
	int coord[10][10];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < d; ++j)
		{
			scanf("%d", coord[i] + j);
		}
	}

	int ans = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			int s = 0;
			for (int k = 0; k < d; ++k)
			{
				s += (coord[i][k] - coord[j][k]) * (coord[i][k] - coord[j][k]);
			}
			if (std::binary_search(sqr.value, sqr.value + sqr.max_sqrn, s))
			{
				++ans;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
from collections import deque
H, W = map(int, input().split())
s = ["#"*(W+2)] + ["#" + input() + "#" for _ in range(H)] + ["#"*(W+2)]
DH, DW = [0, 0, 1, -1], [1, -1, 0, 0]

def bfs(start):
	que = deque([start])
	dist = [[-1 for _ in range(W+2)] for _ in range(H+2)]
	dist[start[0]][start[1]] = 0
	num = 0

	while que:

		label = que.pop()
		h, w = label[0], label[1]
		
		for dh, dw in zip(DH, DW):
			hh, ww = h+dh, w+dw
			if s[hh][ww] == "." and dist[hh][ww] < 0:
				que.appendleft((hh, ww))
				dist[hh][ww] = dist[h][w] + 1
				num = max(num, dist[hh][ww])

	return num

ans = 0
for h in range(1, H+1):
	for w in range(1, W+1):
		if s[h][w] == ".":
			ans = max(ans, bfs((h, w)))
print(ans)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int countBoth(string a, string b) {
    int res = 0;
    for (char c = 'a'; c <= 'z'; ++c) {
        if (a.find(c) != string::npos && b.find(c) != string::npos) res++;
    }
    return res;
}

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

    int ans = 0;
    for (int i = 1; i < n; ++i) {
        string x = s.substr(0, i);
        string y = s.substr(i, n - i);
        ans = max(countBoth(x, y), ans);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static long Biscuit = 1;
	static long Coin = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int Coinlate = Integer.parseInt(sc.next());
		int Biscuitlate = Integer.parseInt(sc.next());
		sc.close();

		//boolean Exchangeflag = false;
		if(Biscuitlate - Coinlate>= 3) {
			//Exchangeflag = true;
		}else {
			System.out.println((Biscuit+n));
			return;
		}

		for (int i=0;i<n-1;i++) {
			if(Coin >= 1) {
				Coin--;
				Biscuit += Biscuitlate;
				continue;
			}
			if(Biscuit < Coinlate) {
				Biscuit++;continue;
			}
			if(Biscuit >= Coinlate) {
				Biscuit-=Coinlate;
				Coin ++;continue;
			}
		}
		if(Coin >= 1) {
			Coin--;
			Biscuit += Biscuitlate;
		}else {
			Biscuit++;
		}

		System.out.println(Biscuit);

	}

}

Measured memory_bytes: 22868
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

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

	if (N % 2 == 1) {
		No();
		return 0;
	}

	rep(i, N / 2) {
		if (S[i] != S[i + N / 2]) {
			No();
			return 0;
		}
	}

	Yes();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  998244353;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return -par[root(x)]; }
};


ll solve(const vector<ll> & r) {
  int n = r.size();
  vector<vector<ll>> dp(n+1, vector<ll>(2));
  vector<ll> cum(n+1);
  REP(i, n) cum[i+1] = cum[i] + r[i];
  ll ans = 0;
  dp[0][0] = 1;
  return 0;
}

signed main() {
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  vector<vector<ll>> dic('z' - 'a' + 1);
  int n = s.size();
  REP(i, n) {
    dic[s[i] - 'a'].push_back(i);
  }
  REP(i, 'z' - 'a' + 1) {
    int m = dic[i].size();
    REP(j, m) {
      dic[i].push_back(dic[i][j] + n);
    }
  }
  ll ans = 0;
  ll index = 0;
  REP(i, t.size()) {
    int c = t[i] - 'a';
    if(dic[c].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    index = *lower_bound(all(dic[c]), index) + 1;
    // cout << index << ":" << ni << endl;
    if(index >= n) {
      ans++;
      index -= n;
    }
  }
  cout << ans * n + index << endl;
  return 0; 
}


Measured memory_bytes: 2756
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  map<int,int> mp;
  rep(i,n){
    mp[i+a[i]]++;
  }
  ll ans = 0;
  rep(i,n){
    ans += mp[i-a[i]];
  }
  cout << ans;
  cout << endl;
  return 0;
}


Measured memory_bytes: 21084
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

ll GCD (ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

ll LCM (ll a, ll b) {
    ll g = GCD (a, b);
    return a * b / g;
}

ll count(ll a, ll b, ll n) {
    ll sub1 = n / a;
    ll sub2 = n / b;
    ll sub3 = n / LCM(a, b);
    return n - sub1 - sub2 + sub3;
}

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

    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    // cout << count(C, D, B) << "\n";
    // cout << count(C, D, A-1) << "\n";

    cout << count(C, D, B) - count(C, D, A-1) << "\n";

}

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

using namespace std;
int main()
{
    string s;
    char ch;
    while(ch!='\n')
    {
        ch=getchar();
        if(ch=='B') {if(s.size()) s.pop_back();}
        else s.push_back(ch);
    }
    puts(s.c_str());
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int arr[105], seq[105];
int main()
{
	int n, m, len = 0;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	for (int i = 0, ban = -1; i < m; i++)
	{
		int mn = -1;
		for (int j = 0; j < n; j++)
		{
			if (j != ban && (-1 == mn || arr[j] < arr[mn]))
				mn = j;
		}
		seq[len++] = ban = mn;
		arr[mn]++;
		for (int j = 0; j < n; j++)
		{
			if (arr[j] <= i + 1)
			{
				puts("-1");
				return 0;
			}
		}
	}
	printf("%d\n", (m + 1) * (n - 1) + 1);
	for (int i = 0; i <= m; i++)
	{
		int ban = i ? seq[i - 1] : -1, nxt = i == m ? -1 : seq[i];
		for (int i = 0; i < n; i++)
		{
			if (i != ban && i != nxt)
				printf("%d ", i + 1);
		}
		if (~nxt)
			printf("%d ", nxt + 1);
	}
	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        int a,b,c,d;
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        c = int.Parse(Console.ReadLine());
        d = a - b;
        while (d >= c)
            d = d - c;

        //標準入力
        //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
        //b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
        //c = int.Parse(str[1]);

        Console.Write("{0}", d);//改行なし出力
        //onsole.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,count=0,ans=0;
  cin>>n;
  vector<int> a(n),b(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  count+=a[0]+vec_sum(b);
  ans=count;
  rep(i,n-1){
    ans=max(ans,count+a[i+1]-b[i]);
    count+=a[i+1]-b[i];
  }
  cout<<ans<<endl;
}
///////////////////////////



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;

class info
{
	public:
	int inum;
	int p,y;
	int ans;
};

bool cmpi(const info &a,const info &b)
{
	return a.inum<b.inum;
}

bool cmp(const info &a,const info &b)
{
	if(a.p==b.p)
		return a.y<b.y;
	return a.p<b.p;
}

int main()
{
	int N,M;
	int P,Y;
	vector<info> v;
	
	cin >> N >> M;
	
	for(int i=0;i<M;i++)
	{
		cin >> P >> Y;
		v.push_back({i,P,Y,0});
	}
	
	sort(v.begin(),v.end(),cmp);
	
	for(int i=0,cnt=1;i<(int)v.size();i++,cnt++)
	{
		if(i!=0 && v[i-1].p!=v[i].p)cnt=1;
		v[i].ans=cnt;
	}
	
	sort(v.begin(),v.end(),cmpi);
	
	for(auto&& i:v)
		printf("%06d%06d\n",i.p,i.ans);
	return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll N = 1e6 + 10;
const ll mod = 1e9 + 7;

int mi_p[N];

ll binpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

ll inv(ll x) {
	return binpow(x, mod - 2);
}

void init() {
	for (int i = 2; i < N; i++) {
		if (mi_p[i]) continue;
		for (int j = i; j < N; j += i)
			mi_p[j] = i;
	}
}

int main() {
	init();
	int n; cin >> n;
	int a[n] = {};
	map<int, int> tot;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int x = a[i];
		while (x != 1) {
			int p = mi_p[x];
			int cnt = 0;
			while (x % p == 0) x /= p, ++cnt;
			tot[p] = max(tot[p], cnt);
		}
	}
	ll L = 1;
	for (auto pr : tot) {
		L = L * binpow(pr.first, pr.second) % mod;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += L * inv(a[i]) % mod, ans %= mod;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 7880
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;


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

    string s;
    cin >> s;

    int ans = 0;
    int curr = 0;
    rep(i, s.length()) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            ++curr;
        } else {
            ans = max(ans, curr);
            curr = 0;
        }
    }
    ans = max(ans, curr);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3588