akhauriyash/Code-Regression huggingface dataset:
// Problem : E - Simple String Queries
// Contest : AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <cstdio>
#include <cstring>
char s[500005],ch[5];
int res[2000005][35],ans[35];
void merge(int root)
{
 for(int i=0;i<=25;i++)
  ans[i]+=res[root][i];
}
void update(int root,int l,int r,int p,int x,int op)
{
 if(r<p||p<l)return;
 if(op)res[root][s[p]]--;
 res[root][x]++;
 if(l==r)return;
 int mid=(l+r)>>1;
 update(root<<1,l,mid,p,x,op);
 update(root<<1|1,mid+1,r,p,x,op);
}
void query(int root,int cl,int cr,int l,int r)
{
 if(cr<l||r<cl)return;
 if(l<=cl&&cr<=r)
 {
  merge(root);
  return;
 }
 int mid=(cl+cr)>>1;
 query(root<<1,cl,mid,l,r);
 query(root<<1|1,mid+1,cr,l,r);
}
int main()
{
 int n,q;
 scanf("%d",&n);
 scanf("%s",s+1);
 for(int i=1;i<=n;i++)
  s[i]-='a',update(1,1,n,i,s[i],0);
 scanf("%d",&q);
 while(q--)
 {
  int op;
  scanf("%d",&op);
  if(op==1)
  {
   int p;
   scanf("%d",&p);
   scanf("%s",ch);
   ch[0]-='a';
   update(1,1,n,p,ch[0],1);
   s[p]=ch[0];
  }
  else
  {
   memset(ans,0,sizeof(ans));
   int l,r,cnt=0;
   scanf("%d%d",&l,&r);
   query(1,1,n,l,r);
   for(int i=0;i<=25;i++)
    cnt+=(ans[i]>0);
   printf("%d\n",cnt);
  }
 }
 return 0;
}

Measured memory_bytes: 146048
# include <iostream>
# include <algorithm>
# include <vector>
using namespace std;
# define ll long long

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  vector<int> num(n*3);
  for(int i=0; i<n*3; i++) cin >> num[i];
  sort(num.rbegin(), num.rend());
  
  for(int i=1; i<2*n; i+=2) ans += num[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
ll n;
ll a,b,c;
ll A,B;
int main()
{
        cin>>n;
        cin >> A >> B;
        for(ll i=1;i<=n;i++) {
                        ll x;
                cin >> x;
                if(x <= A) a++;
                else if(x <= B) b++;
                else c++;
        }
        //cout << a << " " << b << " " << c << endl;
        ll ans = min(a , min(b,c));
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
long long K;


typedef int VAL;
const int MAX_B = 410000;

int SIZE_B;
struct BIT {
	VAL dat[MAX_B + 1];

	void init(int n = 1) {
		SIZE_B = n;
		for (int i = 0; i <= SIZE_B; ++i) dat[i] = 0;
	}

	inline void add(int a, VAL x) {
		for (int i = a; i <= SIZE_B; i += i & -i)
			dat[i] = dat[i] + x;
	}

	inline VAL sum(int a) {
		VAL res = 0;
		for (int i = a; i > 0; i -= i & -i)
			res = res + dat[i];
		return res;
	}

	inline VAL sum(int a, int b) {
		return sum(b - 1) - sum(a - 1);
	}

	void print() {
		for (int i = 1; i <= SIZE_B; ++i) cout << sum(i, i + 1) << ",";
		cout << endl;
	}
};

BIT bit;



long long sum[MAX_B];
long long con[MAX_B];

int main() {
	while (cin >> N >> K) {
		sum[0] = 0;
		for (int i = 0; i < N; ++i) {
			long long a;
			cin >> a;
			a -= K;
			sum[i + 1] = sum[i] + a;
		}
		++N;

		map<long long, int> ma;
		for (int i = 0; i < N; ++i) {
			ma[sum[i]] = 0;
		}
		int iter = 1;
		for (map<long long, int>::iterator it = ma.begin(); it != ma.end(); ++it) {
			it->second = iter++;
		}

		for (int i = 0; i < N; ++i) {
			con[i] = ma[sum[i]];
		}


		long long res = 0;
		bit.init(N);
		for (int j = 0; j < N; ++j) {
			long long tmp = bit.sum(1, con[j] + 1);
			res += tmp;
			bit.add(con[j], 1);
		}

		cout << res << endl;
	}
}











Measured memory_bytes: 19200
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n, a[100000];
    long long ans = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a, a+n);
    if(n%2 == 0){
        ans = 0;
        for(int i=0;i<n/2;i++){
            ans -= a[i]*2;
        }
        ans += a[n/2-1] - a[n/2];
        for(int i=n/2;i<n;i++){
            ans += a[i]*2;
        }
    }else{
        long long v = 0;
        for(int i=0;i<n/2;i++){
            v -= a[i]*2;
        }
        for(int i=n/2;i<n;i++){
            v += a[i]*2;
        }
        v -= a[n/2] + a[n/2+1];
        ans = v;
        
        
        v = 0;
        for(int i=0;i<=n/2;i++){
            v -= a[i]*2;
        }
        v += a[n/2-1] + a[n/2];
        for(int i=n/2+1;i<n;i++){
            v += a[i]*2;
        }
        ans = max(ans, v);
    }
    
    cout << ans << endl;
}


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

class Program {
    static Scanner cin = new Scanner();

    static void Main(string[] args) {
        var S = Console.ReadLine().Split().ToArray();
        Console.WriteLine(S.Contains("1") && S.Contains("9") && S.Contains("7") && S.Contains("4") ? "YES" : "NO");
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>

#define int64 long long int

using namespace std;

char * caesar(char *);

int main()
{
	int i, c;
	char str[128];
	
	i = 0;
	while((c = getchar()) != EOF){
		if(c != '\n'){
			str[i] = c;
			i++;
		} else {
			str[i] = 0;
			cout << caesar(str) << '\n';
			i = 0;
		}
	}

	return 0;
}

char * caesar(char *str){
	int len, i;
	len = strlen(str);
	while(1){
		for(i=0; i<len; i++){
			if(str[i] >= 'b' && str[i] <= 'z')
				str[i]--;
			else if(str[i] == 'a')
				str[i] = 'z';
		}
		for(i=0; i<len; i++){
			if(str[i] == 't' && str[i+1] == 'h'){
				if(str[i+2] == 'e' ||
					(str[i+2] == 'i' && str[i+3] == 's') ||
					(str[i+2] == 'a' && str[i+3] == 't'))
					return str;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1088
#include<stdio.h>
#define max 50100
int main()
{
	char furui[max];
	int n=2,i,input,ans1,ans2;
	
	for(i=0;i<max;i++)
	{
		furui[i]=1;
	}
	furui[0]=0;
	while(n<=max)
	{
		if(furui[n-1]==1)
		{
			for(i=n*2;i<=max;i+=n)
			{
				furui[i-1]=0;
			}
		}
		n++;
	}
		
	while(scanf("%d",&input)!=EOF)
	{
		for(i=1;i<max+1;i++)
		{
			if(furui[i-1]==1&&i>input)
			{
				ans2=i;
				for(i=ans2;i>0;i--)
				{
					if(furui[i-1]==1&&i<input)
					{
						ans1=i;
						break;
					}
				}
				
				break;
			}
		}
		printf("%d %d\n",ans1,ans2);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

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

Measured memory_bytes: 596
#include <stdio.h>

int main(void){
  int i,j,k,l;
  int data[30]={0};

  for(i=0;i<28;i++){
    scanf("%d",&k);
    data[k-1]=1;
  }
  for(i=0;i<30;i++){
    if(data[i]==0){
      printf("%d\n",i+1);
    }
  }
  return(0);
}

Measured memory_bytes: 592
#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;
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; }

ll MOD = 1000000007;

int main(void){
  int x[5];
  rep(i,5){
    cin >> x[i];
    if(x[i] == 0) cout << i+1 << endl;
  }
  return 0;
}


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

int n,m,q,ans=0;
vector<int> a,b,c,d;

void dfs(vector<int> A){
    if((int)A.size()==n+1){
        int sum=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i]) sum+=d[i];
        }
        ans=max(ans,sum);
        return;
    }
    
    A.push_back(A.back());
    while(A.back()<=m){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin>>n>>m>>q;
    a=b=c=d=vector<int>(q);
    rep(i,q) cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(vector<int>(1,1));
    cout<<ans;
}

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
  map<char, char> m;
  map<char, char> mm;

  for(int i=0; i<S.size(); i++) {
    auto it = m.find(T[i]);
    auto itt = mm.find(S[i]);
    if(it == m.end() and itt == mm.end()) {
      m[T[i]] = S[i];
      mm[S[i]] = T[i];
    } else {
      if(it->second != S[i] or itt->second != T[i]) {
	std::cout << NO << std::endl;
	return ;
      }
    }
  }

  std::cout << YES << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
  return 0;
}


Measured memory_bytes: 1160
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    double a = in.nextFloat();
    double b = in.nextFloat();
    double x = in.nextFloat();
    if(a * a * b / 2 < x) {
      double t = (2 / a) * (b - (x / (a * a)));
      System.out.printf("%.10f", Math.toDegrees(Math.atan(t)));
      return;
    }
    double t = (a * b * b) / (2 * x);
    System.out.printf("%.10f", Math.toDegrees(Math.atan(t)));
  }
}


Measured memory_bytes: 23380
#include<cstdio>
#include<algorithm>
using namespace std;
const int Mod=1e9+7;
typedef long long ll;
int n,m,k,u,v,cnt,bcc[410],dfn[410],low[410],C[1100][1100],dt,ans;
int st[410],top;
bool vis[410];
int edgenum=1,vet[410],Next[410],Head[110];
int gcd(int a,int b){ return a%b==0?b:gcd(b,a%b);}
void addedge(int u,int v){
    vet[++edgenum]=v;
    Next[edgenum]=Head[u];
	Head[u]=edgenum;
}
int qpow(int x,int a){
    int res=1;
    while (a){
        if (a&1) res=(ll)res*x%Mod;
        x=(ll)x*x%Mod; a>>=1;
    }
    return res;
}
int polya(int n){
	int ret=0;
	for (int i=1;i<=n;i++) ret=(ret+qpow(k,gcd(i,n)))%Mod;
	return (ll)ret*qpow(n,Mod-2)%Mod;
}
void tarjan(int u){
	dfn[u]=low[u]=++dt;
	st[++top]=u;
	int v;
	for(int e=Head[u];e;e=Next[e]){
		v=vet[e];
		if (!dfn[v]){
			tarjan(v);
			if (low[v]>=dfn[u]){
                cnt=0; 
                do{ bcc[++cnt]=st[top];} while (st[top--]!=v);
                bcc[++cnt]=u;
                for (int i=1;i<=cnt;i++) vis[bcc[i]]=true;
                int m=0;
                for (int i=1;i<=cnt;i++)
                	for (int j=Head[bcc[i]];j;j=Next[j])
                		if (vis[vet[j]]) m++;
                m>>=1;
                if (m<cnt) ans=(ll)ans*k%Mod;
                if (m==cnt) ans=(ll)ans*polya(cnt)%Mod;
                if (m>cnt) ans=(ll)ans*C[m+k-1][k-1]%Mod;
                for (int i=1;i<=cnt;i++) vis[bcc[i]]=false;
			}
            low[u]=min(low[u],low[v]);
		} else low[u]=min(low[u],dfn[v]);
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	C[0][0]=1;
	for (int i=1;i<=1000;i++){
		C[i][0]=1;
		for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;
	}
    ans=1;
    for (int i=1;i<=n;i++)
        if (!dfn[i]) tarjan(i);
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4480
def main():
    N = int(input())
    P = [int(p) for p in input().split()]
    mi = N + 1
    cnt = 0
    for i in range(N):
        if P[i] < mi:
            mi = P[i]
            cnt += 1
    print(cnt)
if __name__ == "__main__":
    main()

Measured memory_bytes: 25768
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;
const int pl=13000;

int h,w,a[90][90],b[90][90],dp[82][82][28000]={},res=99999;
string str;
int main() {
	cout << fixed << setprecision(18);
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>b[i][j];
            b[i][j]-=a[i][j];
            
        }
        
    }
    

    dp[0][0][pl+b[0][0]]=1;
    dp[0][0][pl-b[0][0]]=1;
    for(int i=1;i<=h+w-2;i++){
        for(int j=min(h-1,i);j>=0&&i-j<=w-1;j--){
            if(j==0){
                for(int p=-80*i;p<=i*80;p++){
                    dp[j][i-j][p+b[j][i-j]+pl]=max(dp[j][i-j-1][p+pl], dp[j][i-j][p+b[j][i-j]+pl]);
                    dp[j][i-j][p-b[j][i-j]+pl]=max(dp[j][i-j-1][p+pl], dp[j][i-j][p-b[j][i-j]+pl]);
                }
            }else if(i-j==0){
                for(int p=-80*i;p<=i*80;p++){
                    dp[j][i-j][p+b[j][i-j]+pl]=max(dp[j-1][i-j][p+pl], dp[j][i-j][p+b[j][i-j]+pl]);
                    dp[j][i-j][p-b[j][i-j]+pl]=max(dp[j-1][i-j][p+pl], dp[j][i-j][p-b[j][i-j]+pl]);
                }
            }else{
                for(int p=-80*i;p<=i*80;p++){
                    dp[j][i-j][p+b[j][i-j]+pl]=max(dp[j][i-j-1][p+pl], dp[j][i-j][p+b[j][i-j]+pl]);
                    dp[j][i-j][p+b[j][i-j]+pl]=max(dp[j-1][i-j][p+pl], dp[j][i-j][p+b[j][i-j]+pl]);
                    dp[j][i-j][p-b[j][i-j]+pl]=max(dp[j][i-j-1][p+pl], dp[j][i-j][p-b[j][i-j]+pl]);
                    dp[j][i-j][p-b[j][i-j]+pl]=max(dp[j-1][i-j][p+pl], dp[j][i-j][p-b[j][i-j]+pl]);
                }
            }
        }
    }
    for(int i=0;i<=2*pl;i++){
        if(dp[h-1][w-1][i]==1){
            //cout<<i-pl<<" ";
            res=min(abs(pl-i),res);
        }
    }
    cout<<res;
} 


Measured memory_bytes: 717312
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	
  int N;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    string S;
	  cin >> S;
      if(S == "Y"){
        cout << "Four" << endl;
        return 0;
      }
  }
      cout << "Three" << endl;
}
  

Measured memory_bytes: 3628
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 19, Mod = 1e9 + 7;
int n, m, q, A[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= n; i ++)
        cin >> A[i], cnt += A[i];
    int cc = 0;
    for (int i = 1; i <= n; i ++)
        if (A[i] * 4LL * m >= cnt)
            cc ++;
    if (cc >= m)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

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

	if (a == 2 && b == 2) cout << "Yes" << endl;
	else if ((a == 4 || a == 6 || a == 9 || a == 11) && (b == 4 || b == 6 || b == 9 || b == 11)) cout << "Yes" << endl;
	else if ((a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12) && (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		if (A >= 13) {
			System.out.println(B);
		} else if (6 <= A && A <= 12) {
			System.out.println(B / 2);
		} else if (A <= 5) {
			System.out.println("0");
		}
	}
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
const int maxn=200010;
vector<int> edge[maxn];
int i,j,k,n,m,q,val[maxn];
inline void dfs(int now,int fa) {
    val[now]+=val[fa];
    for(int i=0;i<edge[now].size();i++)
        if(edge[now][i]!=fa)dfs(edge[now][i],now);
}
int main() {
	cin>>n>>q;
    for (int i = 1;i < n;i++) {
        int x,y;
      	scanf("%d%d",&x,&y);
        edge[y].push_back(x);
        edge[x].push_back(y);
    }
    for (i=1;i<=q;i++) {
		int x,y;
        scanf("%d%d",&x,&y);
        val[x]+=y;
    }
    dfs(1,0);
    printf("%d",val[1]);
    for (i=2;i<=n;i++) printf(" %d",val[i]);
    return 0;
}

Measured memory_bytes: 21760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S;
  cin>>S;
  int x = 700;
  if(S[0]=='o'){
  x +=100;
  }if(S[1]=='o'){
  x +=100;
  }if(S[2]=='o'){
  x +=100;
  }
  cout<<x<<endl;  
}

Measured memory_bytes: 256
const main = input => {
  const num = Number(input);
  const ALPHA = "abcdefghijklmnopqrstuvwxyz".split("");
  const genIndices = (x, arr) => {
    const rem = (x - 1) % 26 + 1;
    const div = (x - rem) / 26;
    if (div === 0) {
      return [rem].concat(arr);
    }
    return genIndices(div, [rem].concat(arr));
  }
  const alphas = genIndices(num, []).map(i => ALPHA[i - 1]);
  console.log(alphas.join(""));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29484
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[100001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, A[100001];
	long long M;
	scanf("%d %lld", &N, &M);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	merge_sort(A, N);
	
	if (M == 1) {
		printf("%d\n", A[N-1] * 2);
		fflush(stdout);
		return 0;
	} else if (M == (long long)N * N) {
		for (i = 0, M = 0; i < N; i++) M += A[i];
		printf("%lld\n", (long long)M * N * 2);
		fflush(stdout);
		return 0;
	}
	
	int j, l[2] = {A[0] * 2, A[0] * 2}, r[2] = {A[N-1] * 2, A[N-1] * 2}, m;
	long long count;
	while (l[0] < r[0]) {
		m = (l[0] + r[0]) / 2;
		count = 0;
		for (i = 0, j = N; i < N; i++) {
			for (; j > 0 && A[i] + A[j-1] >= m; j--);
			count += N - j;
		}
		
		if (count <= M) r[0] = m;
		else l[0] = m + 1;
	}
	while (l[1] < r[1]) {
		m = (l[1] + r[1] + 1) / 2;
		count = 0;
		for (i = 0, j = N; i < N; i++) {
			for (; j > 0 && A[i] + A[j-1] >= m; j--);
			count += N - j;
		}
		
		if (count <= M) r[1] = m - 1;
		else l[1] = m;
	}
	
	long long ans = 0, sum = 0;
	for (i = 0, j = N, count = 0; i < N; i++) {
		for (; j > 0 && A[i] + A[j-1] >= l[0]; j--) sum += A[j-1];
		ans += sum + (long long)A[i] * (N - j);
		count += N - j;
	}
	printf("%lld\n", ans + (M - count) * l[1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2508
n = gets.to_i
s_array = n.times.map{gets.chomp}
first_b = 0
last_a = 0
both = 0
cnt = 0
s_array.each do|s|
  (0..s.size-2).each do|i|
    if s.slice(i,2) == "AB"
      cnt += 1
    end
  end
  if s[0] == "B" && s[-1] == "A"
    both += 1
  elsif s[0] == "B"
    first_b += 1
  elsif s[-1] == "A"
    last_a += 1
  end
end

if both == 0
  cnt += [first_b,last_a].min
else
  if first_b + last_a > 0
    cnt += both + [first_b,last_a].min
  else
    cnt += both - 1
  end
end

puts cnt

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

int main() {
    int n;cin>>n;
    string s;cin>>s;
    int ans = 0;
    int tmp = 0;
    rep(i,n){
        if(s[i]=='I'){
            ++tmp;
            ans=max(ans,tmp);
        }
        else --tmp;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }

  vector<int> v;
  v.pb(a[0]);

  for(int i=1;i<n;i++){
    auto Iter = lower_bound(v.begin(),v.end(),a[i]);
    if(Iter==v.begin()){
      v.insert(v.begin(),a[i]);
    }else{
      Iter--;
      *Iter = a[i];
    }
  }
  cout<<v.size()<<endl;

 

  return 0;
}

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

using LL = long long;
using P = pair<LL,int>;

int N;
vector<P>G[123456];
LL dist[123456];
void dp(int v,int las,LL dis){
	dist[v]=dis;
	for(P p : G[v]){
		if(p.second==las)continue;
		dp(p.second,v,dis+p.first);
	}
}

int main() {
	cin>>N;
	for(int i=1;i<N;++i){
		LL u,v,w;
		cin>>u>>v>>w;
		--u;--v;
		G[u].push_back({w,(int)v});
		G[v].push_back({w,(int)u});
	}
	dp(0,-1,0);
	for(int i=0;i<N;++i){
		cout<<dist[i]%2<<endl;
	}
	return 0;
}

Measured memory_bytes: 10752
N = int(input())
MOD = 10 ** 9 + 7

M = len(bin(N)) - 2
dp = [[0] * 3 for _ in range(M + 1)]
dp[0][0] = 1

for i in range(M) :
    if N >> (M - i - 1) & 1 :
        dp[i + 1][0] = dp[i][0] % MOD
        dp[i + 1][1] = (dp[i][0] + dp[i][1]) % MOD
        dp[i + 1][2] = (dp[i][1] * 2 + dp[i][2] * 3) % MOD
    else :
        dp[i + 1][0] = (dp[i][0] + dp[i][1]) % MOD
        dp[i + 1][1] = dp[i][1] % MOD
        dp[i + 1][2] = (dp[i][1] + dp[i][2] * 3) % MOD
        
print(sum(dp[-1]) % MOD)

Measured memory_bytes: 38384
def poor(a, b, c)
  if a == b && b == c && c == a
    puts "No"
  elsif a == b || b == c || c == a
    puts "Yes"
  else
    puts "No"
  end
end

a, b, c = gets.chomp.split(" ").map(&:to_i)
poor(a, b, c)

Measured memory_bytes: 1788
#include<iostream>
#include<array>
#include<algorithm>

int main() {
	std::array<int, 4> ar;

	for (int& x : ar) {
		std::cin >> x;
	}

	if ((std::abs(ar[0] - ar[1] )<= ar[3] && std::abs(ar[1] - ar[2] )<= ar[3])||(std::abs(ar[0]-ar[2])<=ar[3])) {
		std::cout << "Yes" << std::endl;
		exit(0);
	}

	std::cout << "No" << std::endl;



	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//purplesun
const int B=1e5+10;
const int N=B*2;
int dat[N],a[N],b[N],n;
ll m;
//
void add(int x){
    while(x<N){
        dat[x]++;
        x+=x&-x;
    }
}
int get(int x){
    int ans=0;
    while(x>0){
        ans+=dat[x];
        x-=x&-x;
    }
    return ans;
}
bool check(int x){
    memset(dat,0,sizeof(dat));
    rep(i,n)b[i]=(a[i]>=x)?1:-1;
    ll res=0;
    int pre=0;
    add(pre+B);
    rep(i,n){
        pre+=b[i];
        res+=get(pre+B);
        add(pre+B);
    }
    return res>=m;
}
int main(){
    n=getint();
    m=(1ll*n*(n+1)/2ll+1)/2ll;
    int l=0,r=1;
    rep(i,n){
        a[i]=getint();
        r=max(r,a[i]+1);
    }
    while(r-l>1){
        int mid=(l+r)>>1;
        if(check(mid))l=mid;
        else r=mid;
    }
    printf("%d\n",l);
	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    ll ans = 0, sum = 0;
    ll right = 0;
    rep(left, n) {
        while (right < n && (sum ^ a[right]) == sum + a[right]) {
            sum += a[right];
            right++;
        }
        ans += right - left;
        if (left == right) {
            right++;
        } else {
            sum -= a[left];
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll res[2002][2002],res2[2002][2002];
signed main() {
    SS(int,N,K)
    SS(string,S)
    
    vector<int> nums;
    if (S[0] == '0') nums.push_back(0); // 先頭が 0 だったら
    for (int i = 0; i < S.size();) {
        int j = i;
        while (j < S.size() && S[j] == S[i]) ++j; // S[i] の数値がどこまで続くか
        nums.push_back(j - i);
        i = j;
    }
    if (S.back() == '0') nums.push_back(0); // 最後尾が 0 だったら
    
    vector<int> sums(nums.size() + 1, 0);
    rep(i,nums.size()) sums[i+1] = sums[i] + nums[i];

    int res = 0;
    for (int l = 0; l < sums.size(); l += 2) {
        int r = l + K*2+1;
        if (r >= sums.size()) r = sums.size() - 1;
        chmax(res, sums[r] - sums[l]);
    }
    cout << res << endl;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  string s,a;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]!=','){
      a[i]=s[i];
    }else{
      a[i]=' ';
    }
  }
  for(int i=0;i<s.size();i++){
    cout<<a[i];
  }
  cout<<"\n";
}
      
     

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if(e-a>k){
    cout << ":(";
  }else{
    cout << "Yay!";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rrep(i,a,b) for(int i = a; i >=b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using ii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pil = pair<int,ll>;
using vvi = vector<vi>;
using vpi = vector<ii>;

const int N = 100100;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	ll a[5];
	rep(i,0,4)cin>>a[i];
	ll uin = *min_element(a,a+5);
	ll ans = (n - 1)/ uin 	;
	cout<<(ans + 5)<<nl;	
	return 0;
}



Measured memory_bytes: 3660
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void B_task();

int main()
{
	B_task();
	fflush(stdout);
	return 0;
}

static void B_task()
{
	char szS[100] = { 0 };

	getstring(szS);

	int N = strlen(szS);
	int orgN = N;
	bool isOk = true;
	for (int i = 0; i < N; i++) {
		if (szS[i] != szS[N - i - 1]) {
			isOk = false;
			break;
		}
	}
	N = (N - 1) / 2;
	for (int i = 0; i < N; i++) {
		if (szS[i] != szS[N - i - 1]) {
			isOk = false;
			break;
		}
	}

	N = (orgN + 3) / 2;
	for (int i = (orgN + 3) / 2; i < N; i++) {
		if (szS[i] != szS[orgN - i - (orgN + 3) - 1]) {
			isOk = false;
			break;
		}
	}
	printf("%s\n", isOk ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s.substr(0, 4) + " " + s.substr(4) << endl;
    return 0;
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

#define vv vector

struct UnionFind{
    vector<int> nxt;
    vector<int> numm;
    void init(int x){
        nxt.clear();
        numm.assign(x, 1);
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    int size(int x){
        return numm[x];
    }
    inline void unite(int x,int y){
        if(find(x)==find(y))
            return;
        numm[find(x)] += numm[find(y)];
        nxt[find(y)] = find(x);
    }
};


ll N,M;
vv<ll> abv[202020];
ll mk[202020];
ll i, j, k;

int main(){
    scanf("%lld%lld", &N,&M);
    UnionFind uf;
    uf.init(N + 7);
    rep(i,0,M){
        ll a, b;
        scanf("%lld%lld", &a,&b);
        uf.unite(a, b);
    }
    ll ans = 0;
    rep(i,0,N){
        ans = max(ans,(ll)uf.numm[i + 1]);
    }
    
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 9576
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	int k = 0;

	cin >> s;

	for (int i = 0; i < (int)s.size(); i++)
		if (s[i] == '0')
			k++;

	cout << min(k, (int)s.size() - k) * 2 << endl;
	
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll h,a;
	cin >> h >> a;
	cout << (h+a-1)/a << endl;
	return 0;
}


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

int main()
{
    string s, t;
    cin >> s >> t;

    vector<int> sChar(26, -1), tChar(26, -1);
    int n = s.size();
    bool ok = true;
    rep (i, n)
    {
        if (sChar[t[i] - 'a'] == -1)
            sChar[t[i] - 'a'] = s[i] - 'a';
        else if (sChar[t[i] - 'a'] != s[i] - 'a')
            ok = false;
        if (tChar[s[i] - 'a'] == -1)
            tChar[s[i] - 'a'] = t[i] - 'a';
        else if (tChar[s[i] - 'a'] != t[i] - 'a')
            ok = false;
    }

    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3876
n = int(input())

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1


while True:
  if is_prime(n):
    print(n)
    break
  else:
    n += 1

Measured memory_bytes: 3060
K=38
#K=int(input())
N=K**2-K+1

print(N,K)
_res=[[-1 for j in range(K-1)] for i in range((K-1)**2)]
rest=[[-1 for j in range(K-1)] for i in range(K-1)]

id=K
start=0
while N>id:
    for j in range(K-1):
        _res[(K-1)*j+(start+j*((id-1)//(K-1)))%(K-1)][(id-1)//(K-1)-1]=id
    id+=1
    start=(start+1)%(K-1)

rest=[[_res[j][i] for j in range(K-1)] for i in range(K-1)]

ans=[[i for i in range(K)]]
for i in range(K-1):
    for j in range(K-1):
        tmp=[i]+_res[(K-1)*i+j]
        ans.append(tmp)
for i in range(K-1):
    tmp=[K-1]+rest[i]
    ans.append(tmp)

for i in range(N):
    ans[i]=[ans[i][j]+1 for j in range(K)]

for i in range(N):
    print(*ans[i])

def check():
    ids=[[] for i in range(N)]
    for i in range(N):
        ans[i].sort()
        if ans[i][0]<0 or ans[i][-1]>N-1:
            exit(print("WA1"))
        for j in range(1,K):
            if ans[i][j]==ans[i][j-1]:
                exit(print("WA2"))
        for j in range(K):
            ids[ans[i][j]].append(i)
    for i in range(N):
        if len(ids[i])!=K:
            exit(print("WA3"))
    p=set([])
    for i in range(N):
        for j in range(len(ids[i])):
            for k in range(j):
                a,b=ids[i][j],ids[i][k]
                if (a,b) in p:
                    print("WA4")
                    print(ans[a])
                    print(ans[b])
                    exit()

                p.add((a,b))

#check()


Measured memory_bytes: 76144
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
ll fastpower(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y&1)
        res*=x;

        y>>=1;
        x=x*x;
    }
    return res;
}

void swap(ll &a,ll &b)
{
    a ^= b; 
    b ^= a; 
    a ^= b;
}
int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    int j=0,k=0;
    string ans="";
    for(int i=0;i<2*s.size();++i)
    {
        if(i%2==0)
        ans+=s[j++];
        else
        ans+=t[k++];
    }
    cout<<ans;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:
ll n;
ll ans=0;
void dfs(ll x, int a, int b, int c) {
  if(x > n) return;
  if(a && b && c) ans++;
  dfs(10*x+3, 1, b, c);
  dfs(10*x+5, a, 1, c);
  dfs(10*x+7, a, b, 1);
}

int main() {
  cin >> n;
  dfs(0, 0, 0, 0);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#define For(i,n) for(int i=0;i<n;i++) 
using namespace std; 
const int maxn=1e5+5;
typedef long long ll;
int a[maxn];
int main()
{
int n,d,x;
cin>>n>>d>>x;
int ans=0;
For(i,n) cin>>a[i],ans+=(d-1)/a[i]+1;
ans+=x;
cout<<ans<<endl;
system ("pause");
return 0;
}

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

int main()
{
	int n, a, min, max;
	long sum;
	
	cin >> n;
	cin >> a;
	min = max = sum = a;

	while (--n) {
		cin >> a;
		sum += a;
		if (a < min)
			min = a;
		else if ( a > max)
			max = a;
	}
		
	cout << min << ' ' << max << ' ' << sum << endl;
	
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
  string s;
  cin >> s;
  int ans = 0;
  int n = s.size();
  rep(i,n){
    if(s.at(i) == 'R'){
      int num = 1;
      for(int j = i+1; j < n; j++){
        if(s.at(j) == 'R') num++;
        else break;
      }
      if(num > ans ) ans = num;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

struct UnionFind {
  vector<int> p;

  UnionFind(int n = 0) : p(n, -1) {}

  int find(int x) {
    if (p[x] < 0) return x;
    return p[x] = find(p[x]);
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) return false;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return -p[find(x)]; }
};

int deg[100005];
vector<int> block[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  UnionFind uf(n);
  // vector<int> deg(n);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    ++deg[a];
    ++deg[b];
    uf.unite(a, b);
  }

  // vector<int> block[n];

  rep(i, k) {
    int c, d;
    cin >> c >> d;
    --c, --d;
    block[c].push_back(d);
    block[d].push_back(c);
  }

  rep(i, n) {
    int ans = uf.size(i) - deg[i] - 1;
    for (int v : block[i]) {
      if (uf.same(i, v)) --ans;
    }

    cout << ans << (i == n - 1 ? '\n' : ' ');
  }

  return 0;
}


Measured memory_bytes: 6784
#ABC096-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
S=[S() for i in range(h)]
ret=True
#grid周り探索
for i in range(h):
    for j in range(w):
        if S[i][j]==".":
            continue
        ans=False
        for ti in [-1,1]:
            if 0<=i+ti<h:
                if S[i+ti][j]=="#":
                    ans=True
        for tj in [-1,1]:
             if 0<=j+tj<w:
                if S[i][j+tj]=="#":
                    ans=True
        if not ans:
            ret=False
if ret:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 40176
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

void find_nearest_d(vector<int64_t> &s, vector<int64_t> &t, vector<int64_t> &d) {
  for (int i = 0; i < s.size(); i++) {
    auto it = lower_bound(t.begin(), t.end(), s[i]);
    int64_t mind = INT64_MAX;
    if (it == t.end()) {
      mind = min({mind, abs(*(it-1) - s[i])});
    } else {
      if (it == t.begin()) {
        mind = min({mind, abs(*it - s[i])});
      } else {
        mind = min({mind, abs(*(it-1) - s[i]), abs(*it - s[i])});
      }
    }
    d[i] = mind;
  }
}

int64_t find_greater_min(vector<int64_t> &s, vector<int64_t> &ds, int64_t x) {
  auto it = lower_bound(s.begin(), s.end(), x);
  auto it2 = s.begin();
  if (it == s.end()) {
    it2 = it-1;
  } else {
    it2 = it;
  }
  return abs(x-*it2) + ds[it2-s.begin()];
}

int64_t find_lower_min(vector<int64_t> &s, vector<int64_t> &ds, int64_t x) {
  auto it = lower_bound(s.begin(), s.end(), x);
  auto it2 = s.begin();
  if (it == s.begin()) {
    it2 = it;
  } else {
    it2 = it-1;
  }
  return abs(x-*it2) + ds[it2-s.begin()];
}

int main() {
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<int64_t> s(A);
  vector<int64_t> t(B);
  vector<int64_t> x(Q);
  for (int i = 0; i < A; i++)
    cin >> s[i];
  for (int i = 0; i < B; i++)
    cin >> t[i];
  for (int i = 0; i < Q; i++)
    cin >> x[i];

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  vector<int64_t> ds(A);
  vector<int64_t> dt(B);
  find_nearest_d(s, t, ds);
  find_nearest_d(t, s, dt);

  for (int i = 0; i < Q; i++) {
    cout << min({find_lower_min(s, ds, x[i]), find_greater_min(s, ds, x[i]),
                 find_lower_min(t, dt, x[i]), find_greater_min(t, dt, x[i])}) << endl;
  }
  return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	UL N;

	void Solve2(string S, char p) {
		if (S.size() == N) { cout << S << endl; return; }
		for (char c = 'a'; c < p; c++) Solve2(S + c, p);
		Solve2(S + p, p + 1);
	}

	void Solve() {
		cin >> N;
		Solve2("", 'a');
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

bool OK(int x){
	return 0 < x && x <= 12;
}

int main(){
	int S1, S2;
	scanf("%2d%2d", &S1, &S2);
	if(OK(S1) && OK(S2)){
		printf("AMBIGUOUS\n");
	}
	else if(OK(S1)){
		printf("MMYY\n");
	}
	else if(OK(S2)){
		printf("YYMM\n");
	}
	else{
		printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 256