akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1L<<29)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  string s, ans;
  int K;
  cin >> s >> K;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a') continue;
    int dist = 'z' - s[i] + 1;
    if (dist <= K) {
      K -= dist;
      s[i] = 'a';
    }
  }
  if (K != 0) {
    K = K % 26;
    int dist = 'z' - s[s.size()-1] + 1;
    if (K >= dist) s[s.size()-1] = 'a' + (K - dist);
    else s[s.size()-1] += K;
  }
  cout << s << endl;
  return 0; 
}


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

#define int 		long long
#define vi 			vector <int>
#define si 			set <int>
#define pii 		pair<int,int>
#define fr(n) 		for(__typeof(n) i=0;i<n;i++)
#define rep(i,a,b) 	for(__typeof(b) i=a;i<b;i++)
#define repi(i,b,a) for(__typeof(a) i=b;i>=a;i--)
#define tr(a) 		for(auto it=a.begin();it!=a.end();it++)
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define FAST 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

int n,ans[10001];
bool dp[102][102][102];

void fun(int x,int y,int z)
{
	int t=x*x + y*y + z*z + x*y + y*z + z*x;
	if(t<0 or t>n)
		return;
	if(dp[x][y][z]==true)
		return;
	dp[x][y][z]=true;
	if(ceil(t)==floor(t))
		ans[t]++;
	fun(x+1,y,z);
	fun(x,y+1,z);
	fun(x,y,z+1);
}

void solve()
{
	cin>>n;
	memset(ans,0,sizeof(ans));
	fr(102)
	{
		rep(j,0,102)
		{
			rep(k,0,102)
			{
				dp[i][j][k]=false;
			}
		}
	}
	fun(1,1,1);
	rep(i,1,n+1)
	{
		cout<<ans[i]<<endl;
	}
}

signed main()
{
	FAST
	int test=1;
	//cin>>test;
	while(test--)
	{
		solve();
	}
	cerr<<endl<<"Time elapsed : "<<time_passed<<endl;
	return 0;
}

Measured memory_bytes: 4912
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
if a[-1] - a[0] > 1:
  print("No")
  exit(0)

if a[0] == a[-1]:
  if a[0] == N - 1:
    print("Yes")
    exit(0)
  if N // a[0] >= 2:
    print("Yes")
  else: print("No")
  exit(0)

table = [0] * N
for i in range(N):
  if a[i] == a[0]: table[i] = i + 1
l = max(table) + 1
r = l + table.count(0) // 2

if a[-1] in range(l, r): print("Yes")
else: print("No")

Measured memory_bytes: 52752
#include<bits/stdc++.h>
using namespace std;
int p[200005],q[200005],a[200005],b[200005];
pair<int,int>seg[2][1000005];
struct node
{
	int l,r,mno,mne,t;
}prt[200005];
node dvd(int l,int r,int mno,int mne,int t)
{
	node ans;
	ans.l=l;ans.r=r;ans.mno=mno;ans.mne=mne;ans.t=t;
	return ans;
}
void build(int x,int l,int r)
{
	if(l==r)
	{
		seg[0][x]=make_pair(a[l],l);
		seg[1][x]=make_pair(b[l],l);
		return;
	}
	int md=(l+r)/2;
	build(x*2,l,md);
	build(x*2+1,md+1,r);
	seg[0][x]=min(seg[0][x*2],seg[0][x*2+1]);
	seg[1][x]=min(seg[1][x*2],seg[1][x*2+1]);
}
pair<int,int> qry(int x,int l,int r,int ll,int rr,int t)
{
	if(ll>r||rr<l)return make_pair(1e9+7,-1);
	if(l<=ll&&r>=rr)return seg[t][x];
	int md=(ll+rr)/2;
	return min(qry(x*2,l,r,ll,md,t),qry(x*2+1,l,r,md+1,rr,t));
}
int n,cc;
set<pair<int,int> >s;
void doit(int l,int r,int t)
{
	if(l>r)return;
	int mno,mne;
	if(t==1)
	{
		mno=qry(1,l,r,1,n,0).second;
		mne=qry(1,mno,r,1,n,1).second;
	}
	else
	{
		mno=qry(1,l,r,1,n,1).second;
		mne=qry(1,mno,r,1,n,0).second;
	}
	prt[++cc]=dvd(l,r,mno,mne,t);		
	s.insert(make_pair(p[mno],cc));
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)a[i]=b[i]=1e9+7;
	for(int i=1;i<=n;i++)if(i&1)a[i]=p[i];else b[i]=p[i];
	build(1,1,n);
	int mno=qry(1,1,n,1,n,0).second;
	int mne=qry(1,mno,n,1,n,1).second;
	cc=1;
	prt[cc]=dvd(1,n,mno,mne,1);
	s.insert(make_pair(p[mno],cc));
	for(int i=1;i<=n;i+=2)
	{
		set<pair<int,int> >::iterator it=s.begin();
		int x=it->second;
		s.erase(it);
		q[i]=p[prt[x].mno];
		q[i+1]=p[prt[x].mne];
		int t=prt[x].t;
		doit(prt[x].l,prt[x].mno-1,t);
		doit(prt[x].mno+1,prt[x].mne-1,t^1);
		doit(prt[x].mne+1,prt[x].r,t);
	}
	for(int i=1;i<=n;i++)printf("%d ",q[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 21888
#include <iostream>
#include <string>

using namespace std;

struct SE {
	int from;
	int to;
};

string s;
int A = 0;
int k = 0;
int L[10001];
SE se[10001];
int area;
int depth;
int length;

int tobasu(int from) {
	int i = from;
	while (i < length && s[i] != '\\') {
		++i;
	}
	return i;
}

int reverse_tobasu(int from, int to) {
	int i = from;
	while (to <= i && s[i] != '/') {
		--i;
	}
	return i;
}

int calc_area(int from, int to) {
	int d = 0;
	int a = 0;
	for (int l = from; l <= to; ++l) {
		if (s[l] == '\\') {
			a += (d + 1);
			d += 2;
		}
		else if (s[l] == '_') {
			a += d;
		}
		else {
			a += (d - 1);
			d -= 2;
		}
	}
	return a / 2;
}

int main() {
	int k2;
	cin >> s;
	length = s.size();
	int i = tobasu(0);

	if (i == length) {
		cout << 0 << endl;
		cout << 0 << endl;
		return 0;
	}

	int from, to;
	depth = 0;
	from = i;
	bool flag = false;

	while (i < length) {
		if (s[i] == '\\') {
			++depth;
		}
		else if (s[i] == '/') {
			--depth;
			flag = true;
		}

		if (depth == 0) {
			to = i;
			++k;
			se[k].from = from;
			se[k].to = to;
			++i;
			i = tobasu(i);
			from = i;
			flag = false;
		}
		else {
			++i;
		}
	}
	if (flag == false) {
		;
	}
	else {
		k2 = k;
		int from_here = from;
		i = length - 1;
		i = reverse_tobasu(i, from_here);
		depth = 0;
		to = i;
		while (from_here <= i) {
			if (s[i] == '/') {
				++depth;
			}
			else if (s[i] == '\\') {
				--depth;
			}

			if (depth == 0) {
				from = i;
				++k;
				se[k].from = from;
				se[k].to = to;
				--i;
				i = reverse_tobasu(i, from_here);
				to = i;
			}
			else {
				--i;
			}
		}
		int k3 = k - k2;
		k3 = k3 / 2;
		for (int k4 = 1; k4 <= k3; ++k4) {
			SE temp = se[k2 + k4];
			se[k2 + k4] = se[k - k4 + 1];
			se[k - k4 + 1] = temp;
		}
	}



	for (int j = 1; j <= k; j++) {
		L[j] = calc_area(se[j].from, se[j].to);
		A += L[j];
	}


	cout << A << endl;
	cout << k;
	for (int j = 1; j <= k; j++) {
		cout << " " << L[j];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
	ll L,R;
	cin>>L>>R;
	ll ans=INF;
	for(ll i=L;i<=min(R,L+2019);i++){
		for(ll j=i+1;j<=min(R,L+2019);j++){
			ans=min(ans,(i%2019)*(j%2019)%2019);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int &i : h)
  {
    cin >> i;
  }
  int count = 1;
  bool b;
  for (int i = 1; i < n; i++)
  {
    b = true;
    for (int j = 0; j < i; j++)
    {
      if (h.at(j) > h.at(i))
      {
        b = false;
      }
    }
    if(b)
      count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<cmath>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    int a;
    cin >> a;
    string s;
    cin >> s;
    
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
}



Measured memory_bytes: 256
term=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a=int(input())-1
print(str(term[a]))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int A,B,n,a[N],b[N];

int main(){
	A=read(),B=read(),n=read();
	int mn1=1e9,mn2=1e9;
	For(i,1,A) a[i]=read(),mn1=min(mn1,a[i]);
	For(i,1,B) b[i]=read(),mn2=min(mn2,b[i]);
	ll ans=mn1+mn2;
	For(i,1,n){
		int x=read(),y=read(),z=read();
		ans=min(ans,(ll)a[x]+b[y]-z);
	}
	printf("%lld\n",ans);
}

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

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

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

  int b[m];
  for ( i = 0 ; i < m ; i++ ){
    scanf("%d", &b[i]);
  }

  int c[n],sum;
  sum = 0;
  for ( i = 0 ; i < n ; i++ ){
    for ( j = 0 ; j < m ; j++ ){
      sum = sum + A[i][j] * b[j];
    }
    c[i] = sum;
    sum = 0;
  }

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

  return 0;
  
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
int main()
{
	char a[3],b[3];
	cin>>a;
	cin>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
	{
		printf("YES\n");
		return 0;
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
ans=0
for d in range(61):
    n_1 = 0
    for a in A:
        if (a>>d)&1 == 1:
            n_1 += 1
    n_0 = n - n_1
        
    ans += n_0*n_1 * 2**d
    ans %= 10**9+7
print(ans)

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

int cnt, a[1000100];

void insertionSort(int a[],int n, int g){
	int v,j;
	for(int i = g; i < n; i++){
		v = a[i];
		j = i-g;
		while(j >= 0 && a[j] > v){
			a[j+g]=a[j];
			j-=g;
			cnt++;
		}
		a[j+g] = v;
	}
}

void shellSort(int a[], int n){
	int m=0,temp=n,j=1, G[100] = {};
	for(int i = 1; ; i++){
		G[i] = 3*G[i-1]+1;
		//cout<<i<<"== "<<G[i]<<endl;
		if(G[i] > n)break;
		j++;
	}
	j--;
	cout<<j<<endl;
	for(int i = j,k=0; i; i--){
		if(k++)cout<<" ";
		cout<<G[i];
	}cout<<endl;
	for(int i = j; i; i--){
		insertionSort(a,n, G[i]);
	}
}

signed main(){
	int n;
	cin>>n;
	for(int i = 0; i < n; i++)
		cin>>a[i];
	shellSort(a,n);
	cout<<cnt<<endl;
	for(int i = 0; i < n; i++)
		cout<<a[i]<<endl;
	
	
	return 0;
}


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

using namespace std;

typedef long long ll;

int N;
int A[20];
int x[20][20];
int y[20][20];
int ans = 0;

int counter(int bit){
	int count = 0;
	while(bit !=0 ){
		count += (bit%2);
		bit /= 2;
	} 
	return count;
}

int main(){
	
	cin >> N;
	for (int i = 1; i <= N; i++){
		cin >> A[i];
		for (int j = 1; j <= A[i] ; j++){
			cin >> x[i][j] >> y[i][j];
		}
	}

	for (int bit = 0; bit < (1<<N); bit++){
		//cout << bitset<15>(bit) << endl;
		bool ok = true;
		for (int i = 1; i <=N ; i++){
			if(!(bit & (1 << (i-1)))) continue;
			for (int j = 1; j <= A[i] ; j++){
				if( (y[i][j]==1 && (bit & (1<<(x[i][j]-1))) == 0) | 
					(y[i][j]==0 && (bit & (1<<(x[i][j]-1))) != 0) )
					ok = false;
			}
		}
		if(ok){ 
			ans = max(ans, counter(bit));
			//cout << "true!!" << endl;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

const int MOD = 1e9 + 7;

int main() {
	int h, w;
	cin >> h >> w;
	int pd[h][w];
	char matrix[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> matrix[i][j];
		}
	}
	memset(pd, 0, sizeof pd);
	pd[0][0] = 1;
	for (int i = 1; i < h; i++)
		if (matrix[i][0] == '.')
			pd[i][0] = pd[i - 1][0];
	for (int i = 1; i < w; i++)
		if (matrix[0][i] == '.')
			pd[0][i] = pd[0][i - 1];
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (matrix[i][j] == '.')
				pd[i][j] = (pd[i - 1][j] % MOD + pd[i][j - 1] % MOD) % MOD;
		}
	}
	cout << pd[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 5120
N = int(input())
H = list(map(int,input().split()))
if N == 1:
    print("Yes")
    exit()

for i in range(N-2,-1,-1):
    if H[i] > H[i+1]:
        H[i] -= 1
    if H[i] > H[i+1]:
        print("No")
        exit()

print("Yes")

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

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int N = fs.nextInt();
		int M = fs.nextInt();
		int[] req = new int[M];
		for(int i = 0; i < M; i++) {
			int k = fs.nextInt();
			while(k-->0) {
				int x = fs.nextInt()-1;
				req[i] |= 1 << x;
			}
		}
		int res =0;
		int[] p = fs.nextIntArray(M);
		for(int mask = 0; mask < (1<<N); mask++) {
			boolean good = true;
			for(int i = 0; i < M; i++) {
				int cnt = 0;
				for(int j = 0; j < N; j++) {
					int on = (1<<j)&mask;
					if(on == 0) continue;
					on = (1<<j) & req[i];
					if(on == 0) continue;
					cnt++;
				}
				good &= (cnt%2) == p[i];
			}
			if(good) res++;
		}
		out.println(res);
		
		out.close();
	}
	
	class X implements Comparable<X>{
		String name;
		int id, score;
		X(String s, int a, int b) {
			name = s;
			id = a; score = b;
		}
		public int compareTo(X x) {
			int comp = name.compareTo(x.name);
			if(comp == 0) comp = Integer.compare(x.score, score);
			return comp;
		}
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

constexpr int mod = 1000000007;
struct mint {
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint &operator+=(const mint &a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};
ostream &operator<<(ostream &os, const mint &m) {
  os << m.x;
  return os;
}

mint factorial(int k) {
  mint sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}

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

  ll n, m;
  cin >> n >> m;

  if (abs(n - m) >= 2)
    cout << 0 << endl;
  else {
    mint ans = 0;
    mint mint_n = factorial(n);
    mint mint_m = factorial(m);
    if (n - m == 0)
      ans = mint_n * mint_m * 2;
    else
      ans = mint_n * mint_m;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
L,R = map(int,input().split())
MOD = 2019
ans = (MOD-2)*(MOD-1)
for i in range(L, min(R, L + 2019)):
    for j in range(i+1, min(R, L+2019) + 1):
        ans = min(ans,((i % MOD) * (j % MOD)) % MOD)
        if ans == 0:
            break
print(ans)

Measured memory_bytes: 3188
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//文字列の入力
		String S = sc.next();
      	//Z番目-A番目+1をしたい
      	//特定の文字が何番目に出るか
      	int a = S.indexOf("A");
      	int z = S.lastIndexOf("Z");
     	 System.out.println(z-a+1);
        }
}

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

#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;


void solveBruteForce()
{

}

void solveOptimized()
{
	int a[5] = {0};
	int x;
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
			x = i + 1;
	}
	cout << x;
}

void solve()
{
	// solveBruteForce();
	solveOptimized();
}

int main()
{


	ios_base::sync_with_stdio(false);
	cin.tie(0);

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

	return 0;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N, H, W;
  cin >> N >> H >> W;
  int ans = 0;
  rep(i, N)
  {
    int A, B;
    cin >> A >> B;
    if(A >= H && B >= W)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int f(int x) {
	return x*x;
}

int main() {
	int d;
	while(cin >> d) {
		int ans = 0;
		for(int x = d; x < 600; x += d) {
			ans += d*f(x);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll h, w;
  cin >> h >> w;
  vector<ll> a(h), b(w), c(h*w+1), d(h*w+1), y(h*w+1), x(h*w+1);
  REP(i, h) cin >> a[i], c[a[i]]++, y[a[i]] = i;
  REP(i, w) cin >> b[i], d[b[i]]++, x[b[i]] = i;

  REP(i, h*w) {
    if(c[i+1] >= 2 || d[i+1] >= 2) {
      cout << 0 << endl;
      return 0;
    }
  }

  vector<ll> cnt(h*w+1);
  REP(i, h) REP(j, w) {
    cnt[min(a[i], b[j])]++;
   }

//  REP(i, h) {
//    REP(j, w) {
//      cout << min(a[i], b[j]) << " ";
//    }
//    cout << endl;
//  }

  // i行目のa[i]以上の個数
  vector<ll> e(h);
  REP(i, h) {
    REP(j, w) {
      if(a[i] <= b[j]) e[i]++;
    }
  }
  vector<ll> f(w);
  REP(i, h) {
    REP(j, w) {
      if(b[j] <= a[i]) f[j]++;
    }
  }

  ll now = 0, ret = 1;
  for(ll i=h*w; i>=1; --i) {
    // cout << i << endl;
    (now += cnt[i]) %= MOD;
//    cout << i << " " << now;

    if(c[i] == 1 && d[i] == 1) {
      // cout << "a" << endl;
      (now += MOD-1) %= MOD;
//      cout << " a=" << now;
    } else if(c[i] == 1) {
      (ret *= e[y[i]]) %= MOD;
      (now += MOD-1) %= MOD;
//      cout << " b";
    } else if(d[i] == 1) {
      (ret *= f[x[i]]) %= MOD;
      (now += MOD-1) %= MOD;
//      cout << "c ";
    } else {
//       cout << " d";
      (ret *= now) %= MOD;
      (now += MOD-1) %= MOD;
    }
    if(ret <= 0) {
      cout << 0 << endl;
      return 0;
    }
//    cout << " " << ret << endl;
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 39424
#include <cstdio>
 
inline int min(const int &a, const int &b) {
    return a < b ? a : b;
}
 
#define siz 10000000
 
char buf[siz], *bit = buf;
 
inline int nextInt(void) {
    register int ret = 0;
    register int neg = false;
     
    for (; *bit < '0'; ++bit)
        if (*bit == '-')neg ^= true;
     
    for (; *bit >= '0'; ++bit)
        ret = ret * 10 + *bit - '0';
     
    return neg ? -ret : ret;
}
 
#define inf 2147483647
 
int n, m, mini[400005];
 
int find(int t, int l, int r, int x, int y) {
    if (x <= l && r <= y)
        return mini[t];
    int mid = (l + r) >> 1;
    if (y <= mid)
        return find(t << 1, l, mid, x, y);
    if (x > mid)
        return find(t << 1 | 1, mid + 1, r, x, y);
    else
        return min(
            find(t << 1, l, mid, x, mid),
            find(t << 1 | 1, mid + 1, r, mid + 1, y)
        );
}
 
void update(int t, int l, int r, int x, int y) {
    if (l == r)mini[t] = y;
    else {
        int mid = (l + r) >> 1;
        if (x <= mid)
            update(t << 1, l, mid, x, y);
        else
            update(t << 1 | 1, mid + 1, r, x, y);
        mini[t] = min(mini[t << 1], mini[t << 1 | 1]);
    }
}
 
signed main(void) {
    fread(buf, 1, siz, stdin);
 
    n = nextInt();
    m = nextInt();
 
    for (int i = 0; i <= (n << 2); ++i)mini[i] = inf;
 
    for (int i = 1; i <= m; ++i) {
        int c = nextInt();
        int x = nextInt();
        int y = nextInt();
        if (c)  // find(x, y)
            printf("%d\n", find(1, 1, n, x + 1, y + 1));
        else    // update(x, y)
            update(1, 1, n, x + 1, y);
    }
 
//  system("pause");
}


Measured memory_bytes: 5592
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;

int to[100005],nxt[100005],hed[100005] = {0},ec = 0;
void add_edge(int f,int t){
	ec ++; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

int n,k,a[100005],ans = 0;

int dfs(int v,int dep){
	int tmp = dep;
	for(int i = hed[v];i;i = nxt[i]){
		tmp = max(tmp,dfs(to[i],dep + 1));
	}
	if(a[v] != 1 && tmp - dep == k - 1){
		a[v] = 1;
		ans ++;
		return -1;
	}
	return tmp;
}

int main(){
	scanf("%d %d",&n,&k);
	scanf("%d",&a[1]); if(a[1] != 1) ans ++; a[1] = 1;
	for(int i = 2;i <= n;i ++){
		scanf("%d",&a[i]);
		add_edge(a[i],i);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

//

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>

int main(void){
	int x,a,b;
    std::cin>>x>>a>>b;
    x-=a;
    std::cout<<x%b<<std::endl;
    return 0;
}


Measured memory_bytes: 256
#

import sys
input=sys.stdin.readline

def main():
    N=input().strip("\n")
    K=int(input())
    # dp[i][j][k]=i桁目 j: nonzero数　k:N以下確定か
    dp=[[[0]*(2) for i in range(K+1)] for j in range(len(N))]
    dp[0][0][1]=1
    dp[0][1][1]=int(N[0])-1
    dp[0][1][0]=1
    for i in range(len(N)):
        dp[i][0][1]=1
    for i in range(1,len(N)):
        d=int(N[i])
        for j in range(1,K+1):
            if d!=0:
                dp[i][j][1]=dp[i-1][j-1][1]*9+dp[i-1][j-1][0]*(d-1)
                # nonzeroを使う場合i-1で既にN以下確定なら好き勝手できる*9
                
                dp[i][j][1]+=dp[i-1][j][1]+dp[i-1][j][0]
                # zeroを使う場合
                
                dp[i][j][0]=dp[i-1][j-1][0]
                # d未満とったら確定するため。
            else:
                dp[i][j][1]=dp[i-1][j-1][1]*9+dp[i-1][j][1]                
                dp[i][j][0]=dp[i-1][j][0]
    print(sum(dp[len(N)-1][K]))
    
        
    
if __name__=="__main__":
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
int main(){
    cout << fixed << setprecision(10);
    ll n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    vector<vector<ll>> dp(n+10,vector<ll>(2,-1*inf - 10));
    dp[0][0] = 0;
    rep(i,n){
        chmax(dp[i+1][0], max(dp[i][0] + v[i], dp[i][1] - v[i]));
        chmax(dp[i+1][1], max(dp[i][0] - v[i], dp[i][1] + v[i]));
    }
    cout << dp[n][0] << endl;
    return 0;
}

Measured memory_bytes: 9044
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	string str; cin >> str;
	
	vector<int>a,b;
	
	for (int i = 0; i < str.size(); i++) {
		a.push_back(str[i]);
	}
	b = a;

	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());

	if (b.size() == a.size()) cout << "yes";
	else cout << "no";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;

int main (void) {
  int N, M;
  cin >> N >> M;
  vector<bool> a(N + 1);
  for (int i = 0; i < M; i++) {
    int in;
    cin >> in;
    a[in] = true;
  }
  vector<int> dp(N + 1);
  dp[0] = 1;
  if (!a[1])
    dp[1] = 1;

  for (int i = 2; i <= N; i++) {
    // dangerous
    if (a[i - 1]) {
      if (a[i - 2]) {
        dp[i] = 0;
      } else {
        dp[i] = dp[i - 2] % mod;
      }
    } else {
      if (a[i - 2]) {
        dp[i] = dp[i - 1] % mod;
      } else {
        dp[i] = ((dp[i - 1] % mod) + (dp[i - 2] % mod)) % mod;
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
from io import StringIO
import unittest
import os


# 実装を行う関数
def resolve():
    # 数値取得サンプル
    #   1行N項目 x, y = map(int, input().split())
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]
    n = int(input())

    testimonies = [[] for i in range(n + 1)]
    for i in range(n):
        a = int(input())
        testimonies[i+1] = [list(map(int,input().split())) for i in range(a)]

    ans = 0
    # パターン数分ループ。
    for i in range(1 << n):

        unable = False
        # 初期値:一番左の桁の値。
        # result = int(abcd[0:1])
        # パターン数(2進数)の桁数ループ。
        a = 0
        for j in range(n):
            # 嘘つきの発言は評価しない
            if not i & 1 << j:
                continue

            a += 1

            # 正直者の発言は評価する
            for testimony in testimonies[j+1]:

                # 発言の対象者の状態を取得するために必要なビットシフト数を取得
                #  = 1人目は1桁目(ビットシフト0)。2人目は2桁目(ビットシフト1)。となるので-1しておく。
                target = testimony[0] - 1
                # targetは正直だ!　と言っているがtargetが嘘つき => このパターンはありえないので次のパターンへ。
                if testimony[1] == 1 and not i & 1 << target:
                    unable = True
                    break
                # targetは嘘つきだ!　と言っているがtargetは正直 => このパターンはありえないので次のパターンへ。
                elif testimony[1] == 0 and i & 1 << target:
                    unable = True
                    break

            # ありえないパターンと判明した場合、検証を中断して次のパターンへ。
            if unable:
                break

        if unable:
            continue

        ans = max(ans, a)

    print(ans)

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1
2 1
1
1 1
1
2 0"""
        output = """2"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """2
1
2 0
1
1 0"""
        output = """1"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 58732
N,Q = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(N-1)]
px = [list(map(int,input().split())) for i in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p,x in px:
    value[p] += x
    
q = [(1,0)]
while q:
    x,parent = q.pop()
    value[x] += value[parent]
    for y in graph[x]:
        if y == parent:
            continue
        q.append((y,x))
 
answer = ' '.join(map(str,value[1:]))
print(answer)

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

#define MAXN (510)

int n, ans;
int ansr[MAXN], ansc[MAXN];
char str[MAXN];

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; ++ i){
		scanf("%s", str);
		for(int j = 0; j < n; ++ j){
			ansr[i] += str[j] == '#';
			ansc[j] += str[j] == '#';
			ans += str[j] == '#';
		}
	}
	if(!ans) return printf("-1\n"), 0;
	ans = INT_MAX;
	for(int i = 0; i < n; ++ i){
		ans = std::min(n - ansr[i] + !ansc[i], ans);
	}
	ans += n;
	for(int j = 0; j < n; ++ j){
		if(ansc[j] == n){
			-- ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

	int N;
	cin >> N;
	vector<int>	dp(N+5);
	for(int i = 1; i <=N; i++) dp[i] = INF32;

	for(int i = 1; i <= N; i++){
		for(int pow = 1; pow <= i; pow*=6){
			dp[i] = min(dp[i], dp[i-pow]+1);
		}
		for(int pow = 1; pow <= i; pow*=9){
			dp[i] = min(dp[i], dp[i-pow]+1);
		}
	}

	cout << dp[N] << endl;
}


Measured memory_bytes: 3716
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    double ND[10][10];
    int n, d, check, count = 0;
    double sum, root;
    cin >> n >> d;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < d;j++){
            cin >> ND[i][j];
        }
    }
    for(int i = 0;i < n;i++) {
        for (int j = i + 1; j < n; j++) {
            sum = 0;
            for (int k = 0; k < d; k++) {
                sum += (ND[i][k] - ND[j][k]) * (ND[i][k] - ND[j][k]);
            }
            root = sqrt(sum);
            check = root;
            if (check == root) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    a,b = map(int,input().split())
    s.append([b,a])
s.sort()
t = 0
ts = 0
for i in s:
    ts = i[0]
    t += i[1]
    if t>ts:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 38264
#include <stdio.h>

#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

int main()
{
    int q;
    int c, a, n;
    int i, j;

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        int ans = 0;
        scanf("%d %d %d", &c, &a, &n);
        
        int speed, ant, sin;

        for (speed = 0; speed <= 333; speed++) {
            for (ant = 0; ant <= 500; ant++) {
                if (c >= (speed * 3 + ant * 2) &&
                    a >= ant) {
                    sin = min(c - (speed * 3 + ant * 2), min(a - ant, n));
                    ans = max(ans, sin + speed + ant);
                }
            }
        }
        printf("%d\n", ans);
    }


    return 0;
}



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

int main(void){
  string str;
  int ln;
  cin>>str;
  ln=str.size()-1;
  if(str.at(ln)=='s'){
    cout <<  str + "es" << endl;
  }else{
    cout << str + "s" << endl;
  }
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		int ans = 0;
		int num = a[0];
		int count = 1;
		for(int i=1;i<n;i++) {
			if(num==a[i]) {
				count++;
			}else {
				if(count<num) {
					ans += count;
				}else {
					ans += count - num;
				}
				num = a[i];
				count = 1;
			}
		}
		if(count<num) {
			ans += count;
		}else {
			ans += count - num;
		}
		System.out.println(ans);
		in.close();
	}

}


Measured memory_bytes: 50444
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<30;
const ll mod = 1000000007;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

int main() {
  int n; cin >> n;
  unordered_map<string,int> mp;
  rep(i,n) {
    string s; cin >> s;
    SORT(s);
    mp[s]++;
  }

  ll ans = 0;
  for (auto& p : mp) {
    int s = p.second;
    ans += (ll)s*(s-1)/2;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10660
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                 

using namespace std;
#define ll long long

int main(){
  ll N;
  cin >> N;
  int digit = floor(log10l(N)) + 1;
  if((N + 1) % (ll)pow(10, digit-1) == 0)
    cout << 9 * (digit-1) + N / (ll)pow(10, digit-1) << endl;
  else
    cout << 9 * (digit-1) + N / (ll)pow(10, digit-1) - 1 << endl;
  return 0;
}


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

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

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

int cnt[10000005];

void divisor()
{
    for(int i=1;i<=10000005;i++)cnt[i]=1;
    for(int i=2;i<=10000000;i++){
        for(int j=i;j<=10000000;j+=i)
            cnt[j]++;
    }
}

int main()
{
    /*divisor();
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
        ans+=(i*cnt[i]);
    cout<<ans<<endl;*/
    ll a,ans;
    cin>>a;
    ans=a+(a*a)+(a*a*a);
    cout<<ans<<endl;
}



Measured memory_bytes: 3592
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int w[]=new int[N];
        int v[]=new int[N];

        long dp[][] = new long[N][1000*N+1];//重さが入る

        int sum_v = 1000*N;

        for(int i=0;i<N;i++){
            w[i]=sc.nextInt();
            v[i]=sc.nextInt();
        }

        for(int i=0;i<N;i++)dp[i][0]=0;
        for(int i=1;i<=v[0];i++)dp[0][i] = w[0];
        for(int i=v[0]+1;i<sum_v+1;i++)dp[0][i] = W+1;

        for(int i=1;i<N;i++){
            for(int j=1;j<=v[i];j++)dp[i][j]=Math.min(dp[i-1][j],w[i]);
            for(int j=v[i]+1;j<sum_v+1;j++){
                dp[i][j]=Math.min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            }
        }


        /*
        for(int i=0;i<N;i++){
            for(int j=0;j<sum_v+1;j++) System.out.print(dp[i][j]+" ");
            System.out.println();
        }
        
         */


        long ans = Long.MIN_VALUE;

        for(int i=0;i<N;i++)for(int j=0;j<sum_v+1;j++){
            if(dp[i][j]<=W){
                ans = Math.max(ans,j);
            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 127544
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
	int a, b; cin >> a >> b;
	if (a % 2 == 1 && b % 2 == 1)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
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.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

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

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] l = in.nextIntArray(2*n);
			Arrays.sort(l);

			int sum = 0;
			for (int i = 0; i < n; i++) {
				sum += Math.min(l[2*i], l[2*i+1]);
			}

			out.println(sum);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 24788
N=int(input())
tmplist=list(map(int,input().split(" ")))
tmplist.sort()
tmplist.reverse()
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
res=tmplist[0]
for a in range(1,N):
    res=gcd(tmplist[a],res)
print(res)


Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


int main(int argc, char const *argv[]) {
  int n;
  ll h;
  cin >> n >> h;
  vector<ll> a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(all(a),greater<ll>());
  sort(all(b),greater<ll>());
  ll ans=(h+a[0]-1)/a[0];

  for(int i=0; i<n; i++){
    h-=b[i];
    int tmp;
    if(h<=0) tmp=0;
    else tmp=(h+a[0]-1)/a[0];
    chmin(ans,i+1+tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
using ll = long long;

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n) : x(n, 0) { }
  T sum(int i, int j) {
    if (i == 0) {
      T S = 0;
      for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
      return S;
    } else return sum(0, j) - sum(0, i-1);
  }
  void add(int k, T a) {
    for (; k < x.size(); k |= k+1) x[k] += a;
  }
};

int main() {
  int N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll sum = 0;
  vector<ll> B(N + 1);
  B[0] = K;
  for (int i = 0; i < N; i++) {
    sum += A[i];
    B[i+1] = sum - K * i;
  }
  map<ll, int> mp;
  for (auto x : B) {
    mp[x] = 0;
  }
  int id = 0;
  for (auto &ps: mp) {
    ps.second = id++;
  }
  fenwick_tree<ll> bit(id);
  ll res = 0;
  for (int i = 0; i < N; i++) {
    bit.add(mp[B[i]], 1);
    res += bit.sum(0, mp[B[i+1]]);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 17408