akhauriyash/Code-Regression huggingface dataset:
n, x = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()])

ans = 0
for i in range(n):
    if A[i] <= x:
        if i == n - 1:
            if x == A[i]:
                ans += 1
        else:
            x -= A[i]
            ans += 1
    else:
        break
print(ans)


Measured memory_bytes: 61860
import sys

def solve():
    A, B, C, X, Y = map(int, input().split())
    C *= 2
    if X > Y:
        X, Y = Y, X
        A, B = B, A
    
    minCost = A * X + B * Y
    allC = Y * C
    XCYB = X * C + (Y - X) * B
    print(min(minCost, min(allC, XCYB)))
   
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

int main(void) {
	ll N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	sort(A.begin(), A.end());

	for (int i = 1; i < N; i++) {
		if (A[i - 1] == A[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

}



Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    char s[100][11];
    int n;cin>>n;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<n;i++){if(s[i][strlen(s[i])-1]!=s[i+1][0]&&i!=n-1){cout<<"No";return 0;}for(int j=0;j<n;j++)if(strcmp(s[i],s[j])==0&&i!=j){cout<<"No";return 0;}}
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
n, price = map(int, input().split())
ans = [-1, -1, -1]
for x in range(n+1):
    for y in range(n+1):
        z = n - x - y
        if z < 0:
            continue
        if 10000 * x + 5000 * y + 1000 * z == price:
            ans = [x, y, z]
            print(*ans)
            sys.exit()
print(*ans)

Measured memory_bytes: 3060
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005


signed main(){
	fast
	string s;
	cin>>s;
	int n = s.size();
	// int mp = {7, 3, 12, 8, 4, 13, 9, 5, 1, 10};
	// int ord = {8, 1, 4, 7, 0, 3, 6, 9, 2, 5};

	int dp[n+2][14];
	For(i, 0, n+1){
		For(j, 0, 13){
			dp[i][j] = 0;
		}
	}
	dp[0][0]=1;
	For(i, 0, n){
		For(j, 0, 13){
			if(dp[i][j]){
				if(s[i]=='?'){
					For(k, 0, 10){
						int val = (10*j + k)%13;
						dp[i+1][val] += dp[i][j];
						dp[i+1][val]%=MOD;
					}				
				}else{
					int nex = s[i]-'0';
					int val = (10*j + nex)%13;
					dp[i+1][val] += dp[i][j];	
					dp[i+1][val]%=MOD;
				}
			}
		}
	}

	// For(i, 0, n+1){
	// 	For(j, 0, 13){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<dp[n][5]<<endl;

    return 0;
}
    



Measured memory_bytes: 11472
using System;
using System.Collections.Generic;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine().Split(' ')[0]);
            var inputSs = new List<string>();

            for(int i = 0;i<N;i++)
            {
                inputSs.Add(Console.ReadLine());
            }

            var ans = string.Join("", inputSs.OrderBy(s => s));
            Console.WriteLine(ans);
        }
    }

Measured memory_bytes: 11548
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, a, b; cin >> n >> a >> b;
  vector<int> x(n); REP(i, n) cin >> x[i];
  long long ans = 0;
  REP(i, n - 1) {
    long long tmp = x[i + 1] - x[i];
    if (tmp * a > b) ans += b;
    else ans += tmp * a;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    for(int i=0;i<a.length();i++)
    {
        if(a[i]==',')
            {
                a[i]=' ';
            }
    }
    cout<<a;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main() {
	int n, m, i, p[111111],x,y,ans=0;
	cin >> n >> m;
	UnionFind tree(n+1);
	for (i = 1; i <= n; i++)
		cin >> p[i];
	for (i = 0; i < m; i++) {
		cin >> x >> y;
		tree.unite(x, y);
	}
	for (i = 1; i <= n; i++)
		if (tree.same(i, p[i]))
			ans++;
	cout << ans << endl;
}

Measured memory_bytes: 1024
n,c,k=map(int,input().split())
T=sorted([int(input()) for i in range(n)])+[float("inf")]

start,ans,cnt=T[0],0,0
for i in range(n+1):
    if start+k<T[i] or cnt+1>c:
        ans +=1
        cnt=0
        start=T[i]
    cnt +=1

print(ans)

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const int MAX = 10000007;

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

	int n; cin >> n;
	vi v(n); FOR(i, n) cin >> v[i];

	int mini = 1e9;
	ll now = 1000;
	for(int i = 0; i < n; i++){
		mini = min(v[i], mini);

		if(v[i] > mini){
			ll k = now/mini;
			now = now%mini + 1LL * k * v[i];
			mini = v[i];
		}
	}

	cout << now << '\n';

	return 0;
}


Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {
 
  public struct City{
    public long num;
    public City(long n){
      num = n;
    }
 
  }
 
  public static void Main (string[] args) {
    var temp = Console.ReadLine().Split(' ');
    var A = int.Parse(temp.ElementAt(0));
    var B = int.Parse(temp.ElementAt(1));
    var K = int.Parse(temp.ElementAt(2));
    var ans = 0;
    for(var i = Math.Min(A, B); i >= 1; i--){
      ans += A % i == 0 && B % i == 0 ? 1 : 0;
      if(ans == K) {
        ans = i;
        break;
      }
    }
    
    Console.WriteLine(ans);
  }
  public static long Euclidean(long a, long b){
    if(a % b == 0){return b;}
    return Euclidean(b, a % b);
  }
}

Measured memory_bytes: 13268
#include <iostream>
#include <cmath>

using namespace std;
#define PI 3.141592

int main()
{
	int value,value_2;
	char c;
	double x=0.0,y=0.0,angle = 90;

	while(cin >> value >> c >> value_2)
	{
		if(value == 0 && value_2 == 0) break;

		x += cos(angle*PI/180)*value;
		y += sin(angle*PI/180)*value;
		angle -= value_2;
	}
	cout << (int)x << endl << (int)y << endl;
}

Measured memory_bytes: 1164
S = list(map(int, input().split()))
N = S[0]
A = S[1]
B = S[2]
combi = 0
if(A > B):
    print(0)
elif(N == 1):
    combi = 1 if (A == B) else 0
    print(combi)
else:
    cand = N - 2
    combi = (cand * B) - (cand * A) + 1
    print(combi)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			out.println(s.replace(",", " "));
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int mod=(1e9)+7;
int n,m,a[100010],dp[100010];
int vis[100010],s;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	read(m);
	memset(vis,1,sizeof(vis));
	int x;
	while (m--) {
		read(x); vis[x]=0;
	}
	dp[0]=1;
	for (int i=1;i<=n;i++) {
		if (!vis[i]) continue;
		dp[i]=(dp[i-1]+dp[i-2])%mod;
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 105
#define INF 1000000001
typedef pair< double ,int> P;

struct edge {
  int to;
  int cap;
  int rev;
  double cost;
};

int V;
vector<edge> G[MAX_V];
double h[MAX_V];
double dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init_edge(){
  for(int i=0;i<MAX_V;i++)G[i].clear();
}

void add_edge(int from,int to,int cap,double cost){
  G[from].push_back((edge){to,cap,(int)G[to].size(),cost});
  G[to].push_back((edge){from,0,(int)G[from].size()-1,-cost});
}

double min_cost_flow(int s,int t,int f){
  double eps = 1e-5;
  double res = 0;
  fill(h,h+V,0.0);
  
  while(f>0){
    
    priority_queue< P, vector<P>, greater<P> >  que;
    fill( dist, dist+V , (double)INF );
    dist[s]=0;
    que.push(P(0,s));

    // fill ( prevv , prevv + V , s );
    
    while(!que.empty()){
      P p = que.top(); que.pop();
      int v = p.second;
      if(dist[v]+eps < p.first)continue;
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&dist[e.to] > eps+dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }

        
    //  if(dist[t] == INF){
    if( dist[t] > INF - eps ){
      return -1;
    }
    for(int v=0;v<V;v++)h[v]+=dist[v]; 

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
  
    f-=d;

    res+=d*h[t];

    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }

  }
  return res;
}

typedef vector< double > vec;
typedef vector<vec> mat;


vec gauss_jordan(const mat&A,const vec&b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];
  for(int i=0;i<n;i++)B[i][n]=b[i];
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)
      if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);
    if(abs(B[i][i])< 0.0000001 )return vec();
    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];
    for(int j=0;j<n;j++){
      if(i!=j)
        for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
    }
  }
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

int N,si,ti,F;
int M;

int main(){
  int T;
  cin>>T;
  while(T--){

    init_edge();
    cin>>N>>si>>ti>>F;
    
    mat A( N , vec(N) );
    vec B( N );
    
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++)scanf("%lf",&A[i][j]);
      scanf("%lf",&B[i]);
    }
    
    vec C=gauss_jordan(A,B);
    
    for(int i=0;i<N;i++){
      
      cin>>M;
      vector<int> d(M);
      vector<int> f(M);
      for(int j=0;j<M;j++)scanf("%d",&d[j]);
      for(int j=0;j<M;j++)scanf("%d",&f[j]);
      
      for(int j=0;j<M;j++){
        add_edge(i,d[j],f[j], abs(C[i]-C[d[j]]) );
        
      }
    }
    V=N;
    double ans=min_cost_flow(si,ti,F);
    if(ans<=-1.0){
      cout<<"impossible"<<endl;
    }else{
      printf("%.10f\n",ans);
    }
  }
  return 0;
}

Measured memory_bytes: 2116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int R = scanner.nextInt();
		
		if((0<= R)&&(R<1200)) {
			System.out.print("ABC");
		}else if((1200<= R)&&(R<2800)){
			System.out.print("ARC");
		}else {
			System.out.print("AGC");
		}
	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

signed main(){
  Int T;
  cin>>T;

  cout<<fixed<<setprecision(12);
  while(T--){
    double width;
    Int n;
    cin>>width>>n;
    vector<double> w(n);
    for(Int i=0;i<n;i++) cin>>w[i];

    using P = pair<double, double>;
    Int s=1<<n;
    vector<double> sum(s,0);
    for(Int b=0;b<s;b++)
      for(Int i=0;i<n;i++)
	if((b>>i)&1) sum[b]+=w[i];

    function<vector<P>(Int, double)> dfs=[&](Int b,double pos){
      vector<P> res;      
      if(__builtin_popcount(b)==1){
	res.emplace_back(pos,pos);
	return res;
      }
      for(Int nb=b;nb;nb=(nb-1)&b){
	if(nb==b) continue;
	assert(nb&&(nb^b));
	double x=sum[nb],y=sum[nb^b];
	double aa=1.0/(1.0+x/y);
	double bb=1.0-aa;
	auto l=dfs(nb,pos-aa);
	auto r=dfs(nb^b,pos+bb);
	for(auto p:l) 
	  for(auto q:r)
	    res.emplace_back(min({p.first,q.first,p.second,q.second}),
			     max({p.first,q.first,p.second,q.second}));
      }
      return res;
    };
    
    double ans=-1; 
    auto v=dfs(s-1,0);
    for(auto p:v) if(p.second-p.first<width) chmax(ans,p.second-p.first);
    
    if(ans<0) cout<<"-1"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}



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

int main()
{
	int n;
	while (cin >> n, n) {
		set<int> taro, hanako;
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x; x--;
			taro.insert(x);
		}
		for (int i = 0; i < n * 2; i++) {
			if (!taro.count(i)) {
				hanako.insert(i);
			}
		}
		int top = -1, b = 1;
		while (!taro.empty() && !hanako.empty()) {
			if (top == -1) {
				if (b) {
					auto x = *taro.begin();
					top = x;
					taro.erase(x);
				}
				else {
					auto x = *hanako.begin();
					top = x;
					hanako.erase(x);
				}
			}
			else {
				if (b) {
					auto it = taro.upper_bound(top);
					if (it == taro.end()) {
						top = -1;
					}
					else {
						top = *it;
						taro.erase(it);
					}
				}
				else {
					auto it = hanako.upper_bound(top);
					if (it == hanako.end()) {
						top = -1;
					}
					else {
						top = *it;
						hanako.erase(it);
					}
				}
			}
			b = 1 - b;
		}
		cout << hanako.size() << endl;
		cout << taro.size() << endl;
	}
	return 0;
}



Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int N,M;
	while(cin>>N>>M&&N){
		int h[1501],w[1501];
		set<int> s,tmps;
		map<int,int> allh,allw;
		int ans=0,k;
		REP(i,0,N){
			cin>>h[i];
			k=0;
			for(int j=i;j>=0;j--){
				k+=h[j];
				allh[k]++;
				tmps.insert(k);
			}
		}
		REP(i,0,M){
			cin>>w[i];
			k=0;
			for(int j=i;j>=0;j--){
				k+=w[j];
				if(tmps.find(k)!=tmps.end()){
					allw[k]++;
					s.insert(k);
				}
			}
		}
		for(auto itr=s.begin();itr!=s.end();itr++){
			ans+=allh[*itr]*allw[*itr];
		}
		p(ans);
	}

	return 0;
}

Measured memory_bytes: 47756
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <bitset>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 + 10, MOD = 1e9 + 7;

char grid[2][2000];

int main() {
    fastInp;

    ll n;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> grid[0][i];
    }

    for (int i = 0; i < n; i++) {
        cin >> grid[1][i];
    }

    ll ans = 3;
    ll flag = 0;

    if (grid[1][0] != grid[0][0]) flag = 1;
    for (int i = 0; i < n; i++) {
        if (grid[1][i] == grid[0][i]) {
            if (flag == 1) ans *= 2;
            flag = 1;
        }
        else {
            if (flag == 1) {
                ans *= 2;
            }
            else if (flag == 0){
                ans *= 3;
            }
            flag = 0;
            i++;
        }
        ans %= MOD;
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

int main()
{
    lint A, B, N;
    cin >> A >> B >> N;
    lint ret = 0;
    FOR(y, 1, 2e6)
    {
        lint x = (B * y + A - 1) / A;
        if (x > N) continue;
        ret = max(ret, A * x / B - x / B * A);
    }
    FOR(x, 1, min<lint>(N, 1e6) + 1)
    {
        ret = max(ret, A * x / B - x / B * A);
    }
    cout << ret << '\n';
}


Measured memory_bytes: 3592
N,K= map(int, input().split())
A = list(map(int, input().split()))

A.sort()

mod = int(1e9+7)
AM = []
AP = []
AZC = 0
for a in A:
  if a < 0:
    AM.append(a)
  elif a == 0:
    AZC += 1
  else:
    AP.append(a)

#print(AM)
#print(AP)
#print(AZC)
# zero選ばないとだめならゼロ
if N-K < AZC:
  print(0)
  exit(0)

if N == K:
  wk = 1
  for a in A:
    wk *= a
    wk %= mod
  print(wk)
  exit(0)
  
# minusしか選べないケースってあるの？
# AMしかなくて、Kがodd
# zeroが一つでもあればZERO
if len(AP) == 0 and K%2 == 1:
  if AZC > 0:
    print(0)
  else:
    wk = 1
    for i in range(K):
      wk *= AM[-1-i]
      wk %= mod
    print(wk)
  exit(0)  
   
# plusを狙える
# K odd -> plus max 1
# K even -> ２個いちで選んで行ってMAXを
wk = 1
if K%2 == 1:
  wk *= AP.pop(-1)
  wk %= mod
  
K = K // 2
mi, pi = 0, 0
AP = AP[::-1]
while K>0:
  mwk = AM[mi] * AM[mi + 1] if mi + 1 < len(AM) else 0
  pwk = AP[pi] * AP[pi + 1] if pi + 1 < len(AP) else 0
  if mwk <= pwk:
    wk *= pwk % mod
    pi += 2
  else:
    wk *= mwk % mod
    mi += 2
  #print(wk)
  wk %= mod
  K -= 1
print(wk)


Measured memory_bytes: 31904
n = int(input())
aa = [int(a) for a in input().split()]

s = sum(aa)
remove = (n+1) * n // 2
if s % remove != 0:
    print('NO')
else:
    k = s // remove
    diffs = [aa[i+1] - aa[i] for i in range(n-1)] + [aa[0] - aa[-1]]
    diffs = [d - k for d in diffs]
    if all(d <= 0 and d % n == 0 for d in diffs):
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 14260
# 竹1, 2, 3, 使わない の4種類
# 4 ** 8 = 65536

import itertools
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]

INF = 10 ** 18
answer = INF

for pattern in itertools.product(range(4), repeat=N):
    X = [0] * 4
    MP = 0
    for take, length in zip(pattern, L):
        if take == 3:
            continue
        if X[take] != 0:
            MP += 10
        X[take] += length
    if X[0] == 0 or X[1] == 0 or X[2] == 0:
        continue
    MP += abs(X[0]-A)
    MP += abs(X[1]-B)
    MP += abs(X[2]-C)
    answer = min(MP, answer)
print(answer)

Measured memory_bytes: 3064
s = input()
if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
  print("Yes")
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[3]:
  print("Yes")
elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]:
  print("Yes")
else:
  print("No")
                                                 

Measured memory_bytes: 8988
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll p[3] = {3, 5, 7};

bool is_753(ll x, int a=0, int b=0, int c=0) {
	if (x == 0) return a && b && c;
	ll m = x % 10;
	if (m == 3) return is_753(x/10, a+1, b, c);
	else if (m == 5) return is_753(x/10, a, b+1, c);
	else return is_753(x/10, a, b, c+1);
}

void solve() {
	ll n;
	cin >> n;
	queue<ll> q;
	rep(i,3) {
		q.push(p[i]);
	}
	ll ans = 0;
	while (!q.empty()) {
		ll t = q.front(); q.pop();
		if (t <= n) {
			if (is_753(t)) ans++;
			for (int i = 0; i < 3; i++) {
				ll m = t * 10 + p[i];
				q.push(m);
			}
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 3804
#include <algorithm>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>
using namespace std;

#define llong long long

int main() {
  llong n, p, q;
  cin >> n >> p >> q;
  vector<llong> c(n);
  vector<llong> cp(n);  // cp[i] = c[i]+p*i;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    cp[i] = c[i] + p * i;
  }

  sort(cp.begin(), cp.end());
  vector<llong> cpr(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cpr[i] = cpr[i - 1] + cp[i - 1];
  }

  llong sc = accumulate(c.begin(), c.end(), 0LL);

  llong ret = (llong)-1e18;
  for (llong k = 0; k <= n; k++) {
    ret = max(ret, sc - cpr[k] + k * p * (q + k - 1));
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 14464
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
R = sorted(R, reverse=True)[:X+Y]

print(sum(sorted(P+Q+R, reverse=True)[:X+Y]))


Measured memory_bytes: 22560
#include<stdio.h>

int main(void){
	int N,A,B;
	int max,min;
	scanf("%d%d%d",&N,&A,&B);
	if(A<B){
		if(A>(N-B)){
			max=A;
			min=A-(N-B);
			printf("%d %d\n",max,min);
		}else{
			max=A;
			min=0;
			printf("%d %d\n",max,min);
		}
	}else{
		if(B>(N-A)){
			max=B;
			min=B-(N-A);
			printf("%d %d\n",max,min);
		}else{
			max=B;
			min=0;
			printf("%d %d\n",max,min);
		}
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    vi a(3);
    for(int i=0;i<3;i++) cin>>a[i];
    sort(a.begin(),a.end());
    int ans=0;
    ans+=a[2]-a[1];
    a[0]+=a[2]-a[1];
    if((a[2]-a[0])%2==0)
        ans+=(a[2]-a[0])/2;
    else{
        ans+=(a[2]-a[0])/2+2;
    }
    print(ans);
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const long long P=1e9+7;
long long fa[100010],inv[100010],ans1,ans2;
int a[100010],c[100010],n,i,x,y;
long long sqr(long long a){return a*a%P;}
long long C(int n,int k)
{
	if (n<k) return 0;
	return fa[n]*inv[k]%P*inv[n-k]%P;
}
long long poww(long long a,long long n)
{
	if (n==0) return 1;
	if (n%2==0) return sqr(poww(a,n/2));
	return sqr(poww(a,n/2))*a%P;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n+1;i++) scanf("%d",&a[i]);
	fa[0]=inv[0]=1;
	for (i=1;i<=n+1;i++)
	{
		fa[i]=fa[i-1]*(long long)i%P;
		inv[i]=inv[i-1]*poww(i,P-2)%P;
	}
	for (i=1;i<=n+1;i++)
	{
		if (c[a[i]]==0) c[a[i]]=i;
		else
		{
			x=c[a[i]];
			y=i;//x<y:duplicated number
			break;
		}
	}
	int pos1=x-1,pos2=n+1-y;
	for (i=1;i<=n+1;i++)//C(n+1,i)-????x/y????????,distict numbers!(order is alreday determined!)
	{
		ans1=C(n+1,i);
		//printf("%lld\n",ans1);
		ans2=C(pos1+pos2,i-1);//sigma C(pos1,j)*C(pos2,i-1-j)
		printf("%lld\n",(ans1-ans2+P)%P);
	}
}

Measured memory_bytes: 3456
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 1e6 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n;
int ch[MAXN][26];
int mark[MAXN];
int siz=0;

void Insert(char *s){
    int i=0,u=0;
    for(;s[i]!='\0';i++){
        int idx=s[i]-'A';
//        printf("s[i] = %c , idx = %d\n",s[i],idx);
        if(ch[u][idx]==0){
            ch[u][idx]=++siz;
        }
        u=ch[u][idx];
    }
//    printf("i = %d , s[i] = %c , mark[%d] = 1\n",i,s[i],u);
    mark[u]=1;
}

int Find(char *s){
    int i=0;
    int u=0;
    for(;s[i]!='\0';i++){
        int idx=s[i]-'A';
        if(!ch[u][idx]) return false;
        u=ch[u][idx];
    }
//    printf("u  = %d , mark[u] = %d\n",u,mark[u]);
    return mark[u];
}

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        char a[100],b[100];
        scanf("%s%s",a,b);
        if(a[0]=='i') Insert(b);
        else printf("%s\n",Find(b) ? "yes" : "no");
    }
}

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






Measured memory_bytes: 39308
#include <iostream>

using namespace std;

int main(){
        long long N,M,K,sum=0,ans,flag=0;
        cin >> N >> M >> K;
        long long i=0,j=0;
        for(i=0;i<=N;i++){
                sum = i*M;
                if(sum==K)flag=1;
                for(j=1;j<=M;j++){
                         ans = sum+N*j-i*j*2;
                        if(ans==K)flag=1;
                }
        }
        if(flag==1){
                cout << "Yes" << endl;
        }else{
                cout << "No" << endl;
        }
        return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC136
{
    class D
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            long[] res = new long[S.Length];
            long r = 0;
            long l = 0;

            int indexR = 0;
            int indexL = 0;

            for (int i = 0; i < S.Length - 1; i++)
            {
                if (S[i] == 'R') r++;
                if (S[i] == 'L') l++;

                if (i + 1 == S.Length - 1) { l++; }

                if (S[i] == 'R' && S[i + 1] == 'L')
                {
                    indexR = i;
                    indexL = i + 1;
                }

                if ((S[i] == 'L' && S[i + 1] == 'R') || i + 1 == S.Length - 1)
                {
                    if ((r + l) % 2 == 0)
                    {
                        res[indexR] = (r + l) / 2;
                        res[indexL] = (r + l) / 2;
                    }
                    else if ((r + l) % 2 != 0)
                    {
                        if (r <= l && l % 2 == 0)
                        {
                            res[indexR] = (r + l) / 2 + 1;
                            res[indexL] = (r + l) / 2;
                        }
                        else if (r <= l && l % 2 == 1)
                        {
                            res[indexR] = (r + l) / 2;
                            res[indexL] = (r + l) / 2 + 1;
                        }


                        if (l <= r && r % 2 == 0)
                        {
                            res[indexR] = (r + l) / 2;
                            res[indexL] = (r + l) / 2 + 1;
                        }
                        else if (l <= r && r % 2 == 1)
                        {
                            res[indexR] = (r + l) / 2 + 1;
                            res[indexL] = (r + l) / 2;
                        }
                    }

                    r = 0;
                    l = 0;

                }
            }

            foreach (var item in res)
            {
                Console.Write(item);
                Console.Write(' ');
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 13348
// inputに入力データ全体が入る
function Main(input) {
	input = input.split(" ");
  	input.sort();
  	console.log(Number(input[0]) + Number(input[1]));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

namespace App01
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int P = int.Parse(str[0]);
            int Q = int.Parse(str[1]);
            int R = int.Parse(str[2]);
            int result = 0;

            int PQ = P + Q;
            int QR = Q + R;
            int RP = R + P;

            result = PQ;

            result = Math.Min(result, QR);
            result = Math.Min(result, RP);

            Console.WriteLine($"{result}");
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main(){
    int n,m, l, r;
    int minimum=0, maximum=100001;
    cin >> n >> m;

    for(int i=0;i<m;i++){
        cin >> l >> r;
        minimum = max(minimum, l);
        maximum = min(maximum, r);
    }
    cout << max(0, maximum - minimum + 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll m = 0;
    ll n, a;
    cin>>n>>a;
    m = max(m, a);
    vector<ll> x(n);
    for(ll i=0;i<n;++i){
        cin>>x[i];
        m = max(m, x[i]);
    }

    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(n+1, vector<ll>(n*m+10, 0)));
    for(ll i=0;i<=n;++i){
        dp[i][0][0] = 1;
    }
    for(ll i=1;i<=n;++i){
        for(ll j=1;j<=n;++j){
            for(ll k=1;k<=n*m;++k){
                if(k >= x[i-1]){
                    dp[i][j][k] += dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
                }else{
                    dp[i][j][k] += dp[i-1][j][k];
                }
            }
        }
    }

    ll ans = 0;
    for(ll i=1;i<=n;++i){
        ans += dp[n][i][i*a];
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 55500
n = int(input())
graph = [-1] + [list(map(int, input().split())) for _ in range(n)]
seen = [False]*(n+1)
seen[0] = True
d = [-1]*(n+1)
f = [-1]*(n+1)
time = 0


def dfs(v):
    global time
    time += 1
    d[v] = time
    seen[v] = True
    k = graph[v][1]
    if k > 0:
        for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
    time += 1
    f[v] = time

v = 0
while v <= n:
    if seen[v] is False:
        dfs(v)
    
    v += 1

for i in range(1, n+1):
    print(i, d[i], f[i])


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

class Bmondai
{
    static void Main()
    {
        var line = new List<int>();
        var min = int.MaxValue;
        var minIndex = 0;
        for (int i=0;i<5;++i)
        {
            var a = Int32.Parse(Console.ReadLine());
            line.Add(a);
            var ten = a % 10;
            if (ten !=0 && ten < min)
            {
                min = ten;
                minIndex = i;
            }
            if(ten != 0)
            {
                line[i] += (10 - ten);
            }
        }
        var ans = line.Sum()-(min!=int.MaxValue?10-min:0);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
import sys
 

A,B = sys.stdin.readline().strip().split()
A = int(A)
B = int(B)

def g(x):
    if(x%4==0):
        return x
    else:
        y=int(x/4)*4
        int_y = y
        for i in range(x%4):
            y = y^(int_y+i+1)
        return y

if(A>0):
    a = g(A-1)
else:
    a = g(A)
b = g(B)

ans = a^b
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
using namespace std;
char map[1005][1005];
int n,m,tot;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
void dfs(int x,int y,char ch)
{
	map[x][y]=0;
	for(int i=0;i<4;i++)
	{
		int xx=x+dx[i],yy=y+dy[i];
		if(xx<n&&xx>=0&&yy<m&&yy>=0&&map[xx][yy]==ch)
		  dfs(xx,yy,ch);
	}
}
int main()
{
	while(scanf("%d%d",&n,&m),n|m){
	for(int i=0;i<n;i++)
	  scanf("%s",map[i]);
	for(int i=0;i<n;i++)
	  for(int j=0;j<m;j++)
	    if(map[i][j]!=0){
			dfs(i,j,map[i][j]);
			tot++;
		}
	printf("%d\n",tot);
	tot=0;
	}
	return 0;
}

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

const ll mod = 1e18 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}

int main()
{
    int n, k;
    cin >> n >> k;
    
    map <int,int> mp;
    ll ans = 0;
    for(int i = 1; i <= n; i++) mp[i%k]++;
    for(auto x:mp){
        if(x.first%k == 0 || (2*x.first)%k == 0){
           ans += 1LL*(expo(1LL*x.second, 3LL));
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=200000+10,MAXM=4000+10,Mod=1e9+7,base=2001;
int n;
ll f[MAXM][MAXM],ans,fac[MAXN],inv[MAXN];
struct node{
	int A,B;
};
node BBQ[MAXN];
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline ll qexp(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=res*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}
	return res;
}
inline void init()
{
	fac[0]=1;
	for(register int i=1;i<MAXN;++i)fac[i]=1ll*fac[i-1]*i%Mod;
	inv[MAXN-1]=qexp(fac[MAXN-1],Mod-2);
	for(register int i=MAXN-2;i>=0;--i)inv[i]=1ll*inv[i+1]*(i+1)%Mod;
}
inline ll C(int n,int m)
{
	return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main()
{
	read(n);init();
	for(register int i=1;i<=n;++i)
	{
		int A,B;read(A);read(B);
		BBQ[i]=(node){A,B};f[-A+base][-B+base]++;
	}
	for(register int i=1;i<=(base<<1);++i)
		for(register int j=1;j<=(base<<1);++j)(f[i][j]+=(f[i-1][j]+f[i][j-1])%Mod)%=Mod;
	for(register int i=1;i<=n;++i)(ans+=(f[BBQ[i].A+base][BBQ[i].B+base]-C(BBQ[i].A*2+BBQ[i].B*2,BBQ[i].A*2)+Mod)%Mod)%=Mod;
	write(1ll*ans*qexp(2,Mod-2)%Mod,'\n');
	return 0;
}


Measured memory_bytes: 130304
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) cout << (#x) <<"="<< x << endl;
#define bug2( x , y ) cout << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;
#define bug3( x , y , z ) cout << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;
#define bug4( x , y , z , w) cout << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;
#define bugn( x , n ){ cout<<(#x)<<":";for(int i=0;i<n;i++)cout<<(#x)<<"["<<i<<"]:"<< x[i] << "    "; cout<<endl;}
#define bugnm( x , n , m ){ cout<<(#x)<<endl;for(int i=0;i<n;i++){ cout<<"Row #"<<i<<":"; for(int j=0;j<m;j++) cout<<x[i][j]<<"     "; cout << endl;}}
using namespace std;	


const int MOD = 1e9+7;
int RangeSum(int n){
	return n * ( n + 1)/2;
}
int32_t main()
{
    IOS
    int n,k;cin>>n>>k;
    int ans = 0;
    for(int i=k;i<=n+1;i++){
		int minsum =  RangeSum(i-1);
		int maxsum =  RangeSum(n) - RangeSum(n-i);
		minsum%=MOD;
		maxsum%=MOD;
		ans+=  ( maxsum - minsum + 1 +MOD )%MOD;
		ans%= MOD;
		//bug3(i,minsum,maxsum);
	}
	cout << ans << endl;
   
}

				
			
	

	
			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 3648
#include<stdio.h>

main(){

  int i,j,k,n,key,length[100];

  scanf("%d",&n);

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

  for(i = 0; i < n; i++){
    if(i < n-1){
      printf("%d ",length[i]);
    } else {
      printf("%d\n",length[i]);
    }
  }

  for(i = 1 ; i < n; i++){
    key = length[i];
    j = i - 1;
  
  while(j >= 0 && length[j] > key){
      length[j+1] = length[j];
      j = j - 1;
      length[j+1] = key;
    } 

    for(k = 0; k < n; k++){
      if(k < n-1){
	printf("%d ",length[k]);
      } else {
	printf("%d",length[k]);
      }
    }

    printf("\n");

  }
  return 0;
}

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

using namespace std;

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

    vector<pair<int, int>> vt;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        vt.emplace_back(make_pair(x, y));
    }

    sort(vt.begin(), vt.end());
    for (auto x:vt) {
        cout << x.first << " " << x.second << endl;
    }
    return 0;
}


Measured memory_bytes: 3884
import scala.collection.mutable
import scala.io.StdIn._

object Main extends App {
  val Array(n, k) = readLine().split(" ").map(_.toInt)
  val a = readLine().split(" ").map(_.toInt)
  var seq = mutable.Seq.fill(n)(0)

  a.foreach(i => seq(i - 1) += 1)
  seq = seq.filterNot(_ == 0).sorted
  println(seq.slice(0, seq.length - k).sum)
}


Measured memory_bytes: 54308
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int n,ans;

int main (){
	scanf("%d",&n);
  	for(int i = 1;i <= n;i++){
      if(360 * i % n == 0){
        printf("%d\n",360*i/n);
        return 0;
      }
    }
  return 0;
}


Measured memory_bytes: 3824
#include<iostream>
#include<cstdio>
using namespace std;
int field[8][8];
void bomb(int x,int y);
int main(){
	int n;
	cin >>n;
	for(int i=1; i<=n; i++){
		for(int y=0;y<8;y++){
			for(int x=0;x<8;x++){
				scanf("%1d",&field[x][y]);
			}
		}
		int px,py;
		cin >>px>>py;
		bomb(px-1,py-1);
		cout <<"Data "<<i<<":"<<endl;
		for(int y=0;y<8;y++){
			for(int x=0;x<8;x++){
				cout <<field[x][y];
			}
			cout <<endl;
		}
	}
	return 0;
}
void bomb(int x,int y){
	field[x][y] = 0;
	for(int i=1; i<4; i++){
		if(x-i>=0){if(field[x-i][y]){bomb(x-i,y);}}
		if(x+i<=7){if(field[x+i][y]){bomb(x+i,y);}}
		if(y-i>=0){if(field[x][y-i]){bomb(x,y-i);}}
		if(y+i<=7){if(field[x][y+i]){bomb(x,y+i);}}
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &in, vector<T> &vec) {
    for (auto &e : vec) in >> e;
    return in;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    i64 a, b;
    read(a, b);
    print(max({ a + b, a - b, a * b}));

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n = Integer.valueOf(sc.nextLine());
			int[] ans = new int[4];

			for (int i =0; i < n; i++) {
				String line = sc.nextLine();

				if (line.equals("AC")) {
					ans[0]++;
				} else if (line.equals("WA")) {
					ans[1]++;
				} else if (line.equals("TLE")) {
					ans[2]++;
				} else if (line.equals("RE")) {
					ans[3]++;
				}
 			}

			System.out.println("AC x " + ans[0]);
			System.out.println("WA x " + ans[1]);
			System.out.println("TLE x " + ans[2]);
			System.out.println("RE x " + ans[3]);


		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;


int main(){
    ll n;
    cin >> n;
    vector<ll>a(5);
    rep(i, 0, 5)cin >> a[i];
    sort(a.begin(),a.end());
    ll ans = (n+a[0]-1)/a[0]+4;
    cout << ans << endl;
}

Measured memory_bytes: 3628
"""
AtCoder Beginner Contest 157  E - Simple String Queries

文字列Sに対して、
クエリ1：i番目の文字をcに変更
クエリ2：S[l~r]に何種類の文字があるか

各クエリについて、律儀に文字を変えて、l~rについて何種類あるか調べると間に合わないはず。

~~~ABCCDC~~~
        ↑を別の文字にした時に、最後に出てくるCがその二個左、のような情報をちゃんと残したい。
→ 最後の位置が知りたいとかではなく、lとrを指定した時に、その間にあるかが知りたい（具体的な位置が知りたいわけではない）
　そうするt、a〜zについて、l~rに存在するか、みたいな確認ができそう

N <= 5 * 10**5
Q <= 2 * 10**4
なので、bisect使えば間に合うのか？よくわからん

Sとしてではなく、現時点で何文字目がなになのかも持っておいたほうが楽か。

"""

import bisect

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

# 現時点でどこに何があるか
cS = [""] * N
# ある文字の位置
char_idxs = [[]for _  in range(26)]

# i番目は文字s、を保存
for i,s in enumerate(S):
    cS[i] = s
    char_idxs[ord(s) - 97].append(i)

query = [tuple(map(str, input().split())) for _ in range(Q)]




for q,a,b in query:
    
    # q == 1の時、a番目の文字をbに置き換え
    if q == "1":
        # 現時点の文字と置き換え後が同じなら何もしない
        if cS[int(a) - 1] == b:
            continue
        else:
            #print("---", char_idxs[ord(cS[]) - 97], int(a)-1, bisect.bisect_right(char_idxs[ord(b) - 97], int(a)-1))
            # a番目の文字を書き換える

            
            idx = bisect.bisect_right(char_idxs[ord(cS[int(a)-1]) - 97], int(a)-1)
            # idxの左の値がa番目であれば、それを消す
            if char_idxs[ord(cS[int(a)-1]) - 97][idx-1] == int(a)-1:
                # delの方が早いか？
                char_idxs[ord(cS[int(a)-1]) - 97][idx-1:idx] = []
            
            # bの文字がa番目にあるよ、を保存
            bisect.insort_right(char_idxs[ord(b) - 97], int(a) - 1)

            # 置き換え
            cS[int(a) - 1] = b

    # q == 2の時、範囲の文字種の個数を調べる
    else:
        cnt = 0
        for i in range(26):
            # そもそもその文字が文字列全体になければ考えない
            if len(char_idxs[i]) == 0: continue
            # bisect_leftで a-1 を入れられる場所を探して、その時に右にある値がb-1以下であれば含まれる
            l = bisect.bisect_left(char_idxs[i], int(a)-1)
            #r = bisect.bisect_right(char_idxs[i], int(b)-1)

            # char_idxs[i][l]はa-1より右に文字種iが初めて出てくる位置なので、それがb-1を含む右側にあればOK
            if l < len(char_idxs[i]) and char_idxs[i][l] <= int(b)-1:
                cnt += 1

        print(cnt)




Measured memory_bytes: 33372