akhauriyash/Code-Regression huggingface dataset:
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a >= 0 and b-a <= 1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

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

// マクロ
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

int main() {

	char c;
	cin >> c;
	cou((char)(c + 1));

}

Measured memory_bytes: 256
def examA():
    S = SI()
    N = len(S)
    if N<26:
        d = defaultdict(bool)
        for s in S:
            d[s] = True
        for a in alphabet:
            if not d[a]:
                ans = S + a
                print(ans)
                return
    keep = []
    for i in range(N-1)[::-1]:
        keep.append(S[i+1])
        if S[i]<S[i+1]:
            break
    #print(keep)
    n = len(keep)
    c = "zz"
    for s in keep:
        if s>S[(N-n-1)]:
            c = min(c,s)
    if c=="zz":
        print(-1)
        return
    ans = S[:(N-n-1)] + c
    print(ans)
    return

def examB():
    N = I()
    if N==3:
        print("2 5 63")
        return
    if N%2==0:
        ans = [2, 4, 3, 9]
        now = 4
        cur = 10
    else:
        ans = [2, 4, 3, 9]
        now = 4
        cur = 10
    while(cur<=30000):
        if N-1<=now:
            break
        ans.append(cur)
        ans.append(cur-2)
        cur += 6; now += 2
    cur = 21
    while(cur<=30000):
        if N-1<=now:
            break
        ans.append(cur)
        ans.append(cur-6)
        cur += 12; now += 2
    for i in range(N-now):
        cur = (i+1)*6
        ans.append(cur)
    print(" ".join(map(str,ans)))
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Measured memory_bytes: 5744
#include <iostream>
#include <iomanip>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)
typedef long long ll;

int main()
{
    int x;
    cin >> x;
    ll sum = 0, cnt = 1;
    while (sum < x)
    {
        sum += cnt++;
    }
    cout << cnt - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import math
import sys
input=sys.stdin.readline
n,d,a=map(int,input().split())
xh=[list(map(int,input().split())) for i in range(n)]
xh.sort()
x=[xh[i][0] for i in range(n)]
h=[xh[i][1] for i in range(n)]
g=[0]*n
cnt=0
for i in range(n):
    if h[i]>0:
        m=math.ceil(h[i]/a)
        cnt+=m
        k=bisect.bisect_right(x,x[i]+2*d,lo=i)
        if i!=n-1:
            g[i]-=m*a
            if k<n:
                g[k]+=m*a
            g[i+1]+=g[i]
            h[i+1]+=g[i+1]
    else:
        if i!=n-1:
            g[i+1]+=g[i]
            h[i+1]+=g[i+1]
print(cnt)


Measured memory_bytes: 69908
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define _USE_MATH_DEFINES
#include <math.h>

#define MAX_N 50001
bool IsPrime[MAX_N];

void q56() {
	memset(IsPrime, 1, sizeof(IsPrime));
	IsPrime[0] = false;
	IsPrime[1] = false;
	for (int i = 0; i < sqrt(MAX_N); i++) {
		if (!IsPrime[i]) continue;
		for (int j = i * 2; j < MAX_N; j += i) {
			IsPrime[j] = false;
		}
	}
	int n;
	for (; cin >> n;) {
		if (!n) break;
		int cnt = 0;
		for (int i = 0; i < (double)(n+1)/2; i++) {
			if (IsPrime[i] && IsPrime[n - i]) cnt++;
		}
		cout << cnt << endl;
	}
}
int main() {
	q56();
	return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	string S[5];
	S[0]="Sunny";
	S[1]="Cloudy";
	S[2]="Rainy";
	string T;
	cin>>T;
	if(T==S[0]){
		cout<<S[1]<<endl;
	}
	else if(T==S[1]){
		cout<<S[2]<<endl;
	}
	else{
		cout<<S[0]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define endl '\n'
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;


int32_t main(){
    vaibhavv06;
	int n,k; cin>>n>>k;
    // int dp[k+1]={0};
    vector<int> dp(k+1);
    dp[0]=1;
    for(int child = 0;child<n;child++){
        int upto; cin>>upto;
        // int fake[k+1]={0};
        vector<int> fake(k+1);
        for(int used=k;used>=0;used--){
            int temp = dp[used];
            int l = used+1;
            int r = used + min(upto,k-used);
            if(l<=r){
                fake[l]+=temp;
                if(fake[l]>MOD) fake[l]-=MOD;
                if(r+1<=k){
                    fake[r+1]-=temp;
                    if(fake[r+1]<0) fake[r+1]+=MOD;
                }
            }
        }
        int prefix = 0;
        for(int i=0;i<=k;i++){
            prefix+=fake[i];
            prefix%=MOD;
            dp[i]+=prefix;
            dp[i]%=MOD;
        }
    }
    cout<<dp[k]<<endl;
}

Measured memory_bytes: 1792
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A,B,C=get_i
puts C-(A-B)<0 ? 0 : C-(A-B)

Measured memory_bytes: 1788
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <iomanip>
#include <cassert>
 
using namespace std; 

const double PI=3.14159265358979323846264;

long long gcd(long long x,long long y){
	return y==0?x:gcd(y,x%y);
}


int main(){
	
	string s;
	cin>>s;
 
	int res=0,g=0,p=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='g'){
			if(g>p) p++,res++;
			else g++;
		}else{
			if(g>p) p++;
			else g++,res--;
		}
	}
	cout<<res<<endl;

	return 0;
 
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, cx, cy, ch, flag, hi;
	vector<int> x, y, h;

	cin>> n;
	x.resize(n);
	y.resize(n);
	h.resize(n);

	for(int i=0;i<n;i++){
		cin>> x[i] >> y[i] >> h[i];
		if(h[i]!=0) hi=i;
	}

	for(int cx=0;cx<=100;cx++){
	for(int cy=0;cy<=100;cy++){
		ch=h[hi]+abs(x[hi]-cx)+abs(y[hi]-cy);

		//if(ch<1) continue;
			//cout<< cx << " " << cy << " " << ch << endl;
		flag=0;

		for(int i=0;i<n;i++){
			if(ch!=h[i]+abs(x[i]-cx)+abs(y[i]-cy) && h[i]!=0){
				flag=1;
				break;
			}
			if(h[i]==0 && abs(x[i]-cx)+abs(y[i]-cy)<ch){
				flag=1;
				break;
			}
		}

		if(flag==0){
			cout<< cx << " " << cy << " " << ch << endl;
			return 0;
		}
	}
	}
			
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string str; cin >> str;
	int sum = 0;
	for(auto &x : str){
		int c = (x-'0');
		sum += c;
		sum %= 9;
	}
	if(sum < 0)sum += 9;
	if(sum == 0){
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3732
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())

L = [0]*(M+1)

for i in range(N):
    x = list(map(int, input().split()))
    # k = x[0]
    A = x[1:]
    for a in A:
        L[a] += 1

ans = 0
for i in range(1, M+1):
    if L[i] == N:
        ans += 1
print(ans)


Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
ll ans=0;
string str;
void dfs(int depth,ll sum,string ss){
  if(depth==str.size()){
    ll sum2=0;
    ll te=1;
    for(int i=ss.size()-1;i>=0;i--){
      //cout<<1111111<<endl;
      sum2+=(ll)(ss[i]-'0')*te;
      te*=10;
    }
    sum+=(ll)sum2;
    ans+=(ll)sum;
    //cout<<sum<<endl;
    return;
  }
  dfs(depth+1,sum,ss+str[depth]);
  ll sum2=0;
  ll te=1;
  for(int i=ss.size()-1;i>=0;i--){
    sum2+=(ll)(ss[i]-'0')*te;
    te*=10;
  }
  string str2=str.substr(depth,1);
  //cout<<ss<<" "<<str2<<endl;
  dfs(depth+1,sum+sum2,str2);
}
int main(){
  cin>>str;
  dfs(0,0,"");
  cout<<(ll)ans/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
#include <algorithm>

int N = 100000;

using namespace std;
int main(){
  string s;
  int q;
  vector<int> t(N), f(N);
  vector<string> c(N);
  cin >> s >> q;
  t.resize(q), f.resize(q), c.resize(q);
  for(int i = 0; i < q; i++){
    cin >> t[i];
    if(t[i] == 2){
      cin >> f[i] >> c[i];
    }
  }

  bool back = false;
  for(int i = 0; i < q; i++) {
    if(t[i] == 1) {
      back = !back;
    } else {
      if(back == f[i]-1) {
        s = c[i] + s;
      } else {
        s = s + c[i];
      }
    }
  }

  if(back) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 14400
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
const int limit = 50;
int h;
int w;
string s[limit];
int ans = 0;
bool goal = false;
bool visited[limit][limit];
struct node {
  int x;
  int y;
  int cnt;
};
void bfs (int sx, int sy) {
  queue<node> q;
  node n;
  n.x = sx;
  n.y = sy;
  n.cnt = 1;
  q.push(n);

  while (!q.empty()) {
    node n;
    n = q.front();
    q.pop();
    int x = n.x;
    int y = n.y;
    if (x == w - 1 && y == h - 1) {
      goal = true;
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (s[i][j] == '.') cnt++;
        }
      }
      ans = cnt - n.cnt;
      break;
    }

    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      node nn;
      nn.x = nx;
      nn.y = ny;
      nn.cnt = n.cnt + 1;
      if (0 <= nx && nx < w && 0 <= ny && ny < h) {
        if (!visited[ny][nx] && s[ny][nx] == '.') {
          visited[ny][nx] = true;
          q.push(nn);
        }
      }
    }
  }
}

int main (void) {
  cin >> h >> w;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      visited[i][j] = false;
    }
  }

  for (int i = 0; i < h; i++) cin >> s[i];

  visited[0][0] = true;
  bfs(0, 0);

  if (goal) cout << ans << endl;
  else cout << -1 << endl;

  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

pii ppa[MAXN], ppb[MAXN];
int used[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d%d", &ppa[i]._1, &ppa[i]._2);
	}
	REP(i, 0, n) {
		scanf("%d%d", &ppb[i]._1, &ppb[i]._2);
	}
	sort(ppa, ppa + n);
	int ans = 0;
	for(int i = n - 1; i >= 0; i--) {
		int ind = -1;
		REP(j, 0, n) {
			if (!used[j] && ppb[j]._1 > ppa[i]._1 && ppb[j]._2 > ppa[i]._2) {
				if (ind == -1 || ppb[j]._2 < ppb[ind]._2) {
					ind = j;
				}
			}
		}
		if (ind != -1) {
			ans++;
			used[ind] = 1;
		}
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if t[0]*a[0]+t[1]*a[1]==t[0]*b[0]+t[1]*b[1]:
  print("infinity")
else:
  if t[0]*a[0]>t[0]*b[0]:
    if t[0]*a[0]+t[1]*a[1]>t[0]*b[0]+t[1]*b[1]:
      print(0)
    else:
      d=(t[0]*b[0]+t[1]*b[1])-(t[0]*a[0]+t[1]*a[1])
      c=t[0]*a[0]-t[0]*b[0]
      if c%d==0:
        print(c//d*2)
      else:
        print(c//d*2+1)
  else:
    if t[0]*a[0]+t[1]*a[1]<t[0]*b[0]+t[1]*b[1]:
      print(0)
    else:
      d=(t[0]*a[0]+t[1]*a[1])-(t[0]*b[0]+t[1]*b[1])
      c=t[0]*b[0]-t[0]*a[0]
      if c%d==0:
        print(c//d*2)
      else:
        print(c//d*2+1)
    
      

Measured memory_bytes: 3064
#include <iostream>
#define M 10000000
using namespace std;
int n,i,j;
bool prime[M];
void sieve(){
	for(i=0;i<M;i++){
		prime[i] = true;
	}
	prime[0] = false;
	prime[1] = false;

	for(i=2;i<M;i++){
		if(prime[i]){
			for(j=2*i;j<M;j+=i) prime[j] = false;
		}
	}
}
int main(){
	sieve();
	while(cin >> n){
		if(!n) break;
		int ans = 0;
		for(i=1;i<=n;i++){
			if(prime[i+n]) ans++;
		}
		cout << ans <<endl;
	}
	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<char> S(N); for (int i = 0; i < N; i++) cin >> S[i];

    vector<int> W(N + 1), E(N + 1);
    W[0] = 0; E[0] = 0;
    int w = 0, e =0;

    for (int i = 0; i < N; i++){
        if (S[i] == 'W')  w ++;
        W[i + 1] = w;
        
        if (S[i] == 'E')  e ++;
        E[i + 1] = e;
        
    }

    int ans = min(E[N] - E[1], W[N - 1]);

    for (int i = 1; i <= N - 2; i++){
        ans = min(ans, W[i] + E[N] - E[i + 1]);
    }

    cout << ans << endl;
}

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

using namespace std;

int main(void) {
	int n, m;
	scanf("%d%d", &n, &m);
	int h[n];
	vector<set<int>> connected(n, set<int>());
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}

	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		connected.at(a).insert(b);
		connected.at(b).insert(a);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int highest = 0;
		for (auto j : connected.at(i)) {
			highest = max(highest, h[j]);
		}
		ans += h[i] > highest;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 17724
#include<iostream>

using namespace std;

int main(){
 int a,b;
  
  cin >> a >> b;
 
  if(a==1) a+=13;
  if(b==1) b+=13;
  
  if(a>b) cout << "Alice" << endl;
  else if(a<b) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}


Measured memory_bytes: 256
n = "0" + input()

ans = 0
n_dig = len(n) # Nの桁数

carry = 0
d_next = int(n[n_dig - 1])

for i in range(n_dig - 1, 0, -1):  # n[0]はダミーなのでn[1]で止める
    d = d_next
    d_next = int(n[i - 1])

    if carry + d <= 4 or (carry + d == 5 and d_next <= 4):
        ans += d + carry
        carry = 0  # 繰り上がり
    else:
        ans += 10 - d - carry
        carry = 1

print(ans + carry)


Measured memory_bytes: 54384
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<char,int> w;
  for(int i=0;i<4;i++){
    char c;
    cin>>c;
    w[c]++;
  }
  bool f=1;
  for(auto c:w)
    if(c.second!=2)
      f=0;
  cout<<(f?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main
{public static void main(String args[])
{Scanner scan = new Scanner(System.in);
 int n = scan.nextInt();
 int m = scan.nextInt();
 if(n==m)
 {System.out.println("Yes");
 }else
 {System.out.println("No");

 }
}
}

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

signed main(){
  int n;
  cin >> n;
  
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  
  vector<vector<int>> t(n,vector<int>(26));
  
  int ans = 0;
  map<vector<int>,int> memo;
  rep(i,n){
    vector<int> num(26);
    rep(j,s[i].size()) num[ s[i][j] - 'a' ]++;
    memo[num]++;
    t[i] = num;
  }
  
  rep(i,n){
    int j = memo[ t[i] ];
    ans += j*(j-1)/2;
    memo[ t[i] ] = 0;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 61184
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };


const int N=200001;
int check(int n,int d)
{
    if((n%d)==1)
        return 1;
    else if(!(n%d))
    {
       while(!(n%d))
       {
           n=n/d;
       }
        if((n%d)==1)
            return 1;
        else
            return 0;
    }
    else
        return 0;
}

void solve()
{
    int n;
    cin>>n;
    int sq=sqrt(n);int ans=0;
    for(int i=1;i<=sq;i++)
    {
        if(!(n%i))
        {
            int d=n/i;
            if(d>(sq))
            {
                ans=ans+check(n,d);
            }
        }
    }
    for(int i=1;i<=sqrt(n-1);i++)
    {
        if(!((n-1)%i))
        {
            int d=(n-1)/i;
            if(d>sq)
            {
                ans=ans+check(n,d);
            }
        }
    }
    for(int i=2;i<=sq;i++)
    {
        ans=ans+check(n,i);
    }
    cout<<ans<<endl;
    
    
}



int32_t main()
{
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
   // cin>>t;
    
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

def get_renzokuomote(goal, now_num):
    count = 0
    while now_num < goal:
        now_num *= 2
        count += 1
    return count



def main():
    n, k = map(int, input().split())
    sss = list(input())
    sss[k - 1] = sss[k - 1].lower()
    print(''.join(sss))





if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
#include<stdio.h>
int a[400005], b[400005];
int h[400005], l;
int comp_h(int x, int y)
{
	if (a[h[x]] > a[h[y]])
		return 1;
	else
		return -1;
}
void swap_h(int x, int y)
{
	int f = h[x];
	h[x] = h[y];
	h[y] = f;
	return;
}
void push(int ne)
{
	h[l] = ne;
	int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n - 1; i++)
	{
		i *= 2;
		scanf("%d %d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		a[i + 1] = b[i];
		b[i + 1] = a[i];
		i /= 2;
	}
	l = 0;
	for (i = 0; i < 2 * n - 2; i++)
		push(i);
	int c[400005];
	for (i = 0; i < 2 * n - 2; i++)
		c[i] = pop();
	c[2 * n - 2] = 2 * n - 2;
	a[2 * n - 2] = -1;
	int depth[200005];
	for (i = 0; i < n; i++)
		depth[i] = -1;
	int min, mid, max;
	int q[200005];
	depth[0] = 1;
	q[0] = 0;
	l = 1;
	while (l > 0)
	{
		l--;
		i = q[l];
		min = -1;
		max = 2 * n - 2;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (a[c[mid]] < i)
				min = mid;
			else
				max = mid;
		}
		while (a[c[max]] == i)
		{
			if (depth[b[c[max]]] < 0)
			{
				depth[b[c[max]]] = depth[i] + 1;
				q[l] = b[c[max]];
				l++;
			}
			max++;
		}
	}
	int s = 0;
	for (i = 0; i < n; i++)
		if (depth[s] < depth[i])
			s = i;
	for (i = 0; i < n; i++)
		depth[i] = -1;
	depth[s] = 1;
	q[0] = s;
	l = 1;
	while (l > 0)
	{
		l--;
		i = q[l];
		min = -1;
		max = 2 * n - 2;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (a[c[mid]] < i)
				min = mid;
			else
				max = mid;
		}
		while (a[c[max]] == i)
		{
			if (depth[b[c[max]]] < 0)
			{
				depth[b[c[max]]] = depth[i] + 1;
				q[l] = b[c[max]];
				l++;
			}
			max++;
		}
	}
	max = 0;
	for (i = 0; i < n; i++)
		if (max < depth[i])
			max = depth[i];
	if ((max + 1) % 3 > 0)
		printf("First\n");
	else
		printf("Second\n");
	return 0;
}

Measured memory_bytes: 9380
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		while(true) {
			if(list.contains(num)) break;
			list.add(num);
			num = num % 2 == 0 ? num/2 : num*3 + 1;
		}
		System.out.println(list.size()+1);
	}
}

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

decltype(0) main () {
  int n; cin >> n;
  string s; cin >> s;
  map<char,int> mm;
  for (char c : s) {
    if(mm.find(c) == mm.end()) {
      mm[c] = 1;
    } else {
      mm[c]++;
    }
  }
  int num = 1;
  for (pair<char,int> entry : mm) {
    num = (num*(entry.second+1))%1000000007;
    //num += entry.second;
  }
  cout << (num+1000000006)%1000000007 << endl;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){

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

	for (j = 0; j < m; j++) {
		scanf("%d", &b);
		for (i = 0; i < n; i++) {
			C[i] += b * A[i][j];
		}
	}
	for (i = 0; i < n; i++) {
		printf("%d\n", C[i]);
	}
    return 0;
}


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

int main(){
  int times, plus, num = 1;
  cin >> times >> plus;
  rep(i, times){
    if(num * 2 < num + plus)
      num *= 2;
    else
      num += plus;
  }
  
  cout << num << endl;
}
    

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d[i];
  
  sort(d.begin(), d.end());
  int x = 1;
  for (int i = 1; i < N; i++) {
    if (d[i] > d[i - 1])
      x++;
  }
  cout << x << endl;
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  cin >> N;
  string s;
  ll ans = 0;
  ll same = 0;
  ll aonly = 0;
  ll bonly = 0;
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s[0] == 'B' && s[s.size()-1] == 'A') same++;
    if (s[0] != 'B' && s[s.size()-1] == 'A') aonly++;
    if (s[0] == 'B' && s[s.size()-1] != 'A') bonly++;
    for (int j = 0; j < s.size() - 1; j++) {
      if (s[j] == 'A' && s[j+1] == 'B') ans++;
    }
  }  

  if (aonly > 0 || bonly > 0) {
    ans += same + min(aonly, bonly);
  } else if (same > 0) {
    ans += same - 1;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	while(N>0){
	    if(N%10==7){
	        cout << "Yes" << endl;
	        return 0;
	    }
	    N /= 10;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3596
let () = Scanf.scanf "%d %d\n" @@ fun n t ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let maximum = Array.make n (as_.(n - 1), n - 1) in
  for i = n - 2 downto 0 do
    maximum.(i) <-
      if as_.(i) < fst maximum.(i + 1) then maximum.(i + 1)
      else (as_.(i), i)
  done;
  Array.to_list as_
  |> List.mapi (fun i a -> (fst maximum.(i) - a, snd maximum.(i)))
  |> List.fold_left (fun (maximum, is) (d, i) ->
      match compare d maximum with
      | -1 -> (maximum, is)
      | 0 ->  (d, i :: is)
      | 1 ->  (d, [i])) (min_int, [])
  |> snd
  |> List.sort_uniq compare
  |> List.length
  |> Printf.printf "%d\n"

Measured memory_bytes: 17024
s = input()
n = len(s)
o = ['+' for i in range(n - 1)]
os = ''
for i in range(2 ** (n-1)):
    for j in range(n):
        if ((i >> j) & 1):
            o[j] = '-'
    for k in range(len(o)):
        if k == 0:
            p = int(s[k])
            os += s[k]
            pass
        if o[k] == '+':
            p += int(s[k + 1])
            os += '+'
            os += s[k+1]
        elif o[k] == '-':
            os += '-'
            os += s[k+1]
            p -= int(s[k+1])
    if p == 7:
        print(os + '=7')
        break
    os = ''
    o = ['+' for i in range(n-1)]

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    
    int max = 0;
    for (int i = 1; i < N-1; i++) {
      int num = calc(S, i);
      if (num > max) {
        max = num;
      }
    }
    
    System.out.println(max);
  }
  
  private static int calc(String s, int pos) {

    int[] left = new int[26];
    for (int i = 0; i <= pos-1; i++) {
      left[s.charAt(i) - 'a'] = 1;
    }

    int ret = 0;
    for (int i = pos; i < s.length(); i++) {
      if (left[s.charAt(i) - 'a'] == 1) {
        left[s.charAt(i) - 'a'] = 0;
        ret++;
      }
    }

    return ret;
  }
}

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

#define fst() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
typedef long long ll;

int main()
{
  fst();
  int c[3][3];
  int i,j;
  f(i,0,3)
  {
    f(j,0,3)
    {
      cin>>c[i][j];
    }
  }
  if((c[1][0]-c[0][0])==(c[1][1]-c[0][1]) && (c[1][1]-c[0][1])==(c[1][2]-c[0][2])  && (c[2][0]-c[0][0])==(c[2][1]-c[0][1]) &&
  (c[2][1]-c[0][1])==(c[2][2]-c[0][2]) &&
    (c[0][0]-c[1][0])==(c[0][1]-c[1][1]) && (c[0][1]-c[1][1])==(c[0][2]-c[1][2])) cout<<"Yes";
  else cout<<"No";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int maxn=1e6;
const int maxv=1e9;
int n;
int x[maxn],l[maxn];

int main() {
    cin >> n;
    P ps[maxn];
    for(int i=0;i<n;i++){
        cin >> x[i] >> l[i];
        ps[i]=make_pair(x[i]+l[i],x[i]-l[i]);
    }
    sort(ps,ps+n);
    int cur=-maxv;
    int ans=0;
    for(int i=0;i<n;i++){
        if(cur<=ps[i].second){
            ans++;
            cur=ps[i].first;
        }
    }
    cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  cout << "A" << s2[0] << "C" << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<cmath>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<stdio.h>
#include<queue>
#define pb push_back
#define ppb pop_back
#define nd second
#define st first
#define ll long long
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
int a,b,c,x,y;
int main()
{
  cin>>a>>b>>c>>x>>y;
  int ans=0;
  if(x<=y)
  {
    ans=min(a*x+b*y,b*(y-x)+2*x*c);
    ans=min(ans,2*y*c);
  }
  else
  {
    ans=min(a*x+b*y,a*(x-y)+2*y*c);
    ans=min(ans,2*x*c);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        a.push_back(x);
    }

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int k;
        cin >> k;
        int ub,lb;
        ub = upper_bound(a.begin(), a.end(), k) - a.begin();
        lb = lower_bound(a.begin(), a.end(), k) - a.begin();
        cout << lb << " " << ub << "\n";
    }
    return 0;
}


Measured memory_bytes: 3484
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        int K;
        String Str;


        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            K = sc.nextInt();
            Str = sc.next();
        }
        long result = 0;
        long count = 0;
        long happy =0;
        for(int i = 0;i < N-1;i++){
            if(Str.charAt(i) != Str.charAt(i+1)){
                count++;
            }else{
                happy++;
            }
        }
        if( 2* K < count){
            happy += 2*K;
        }else{
            happy += count;
        }
        System.out.println(happy);
    }


}


Measured memory_bytes: 26156
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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


	int N;
	cin >> N;
	vector<int>A(N);
	int sum = 0;
	rep(i, N) {
		cin >> A[i];
		sum += A[i];
	}

	int onestep = 0;
	for (int i = 1; i <= N; i++)onestep += i;
	if (sum%onestep) {
		cout << "NO"<<endl;
		return 0;
	}
	int step = sum / onestep;
	vector<int>dA(N);
	rep(i, N)dA[i] = A[(i + 1) % N] - A[i] - step;
	rep(i, N) {
		if (0 < dA[i]) {
			cout << "NO" << endl;
			return 0;
		}
		if (dA[i] == 0)continue;
		if((-dA[i]) % N) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 1792
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main()

{
    IOS;
    //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);
     int a;
     cin>>a;
     int b,c;
     cin>>b>>c;
     rep1(i,b,c){
        if(i%a==0){
            cout<<"OK"<<endl;
            return 0;
        }
     }
     cout<<"NG"<<endl;

     return 0;

}
///Alhamdulillah


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

int main(){
string str;
cin>>str;
int N;
N=str.size();
vector<char> vec(N);
bool A=true;int j=(N+3)/2;
for(int i=1;i<N+1;i++){vec[i]=str.at(i-1);
;}
  for(int i=1;i<=N;i++){if(vec[i]!=vec[N+1-i]){A=false;}
;}
for(int i=1;i<=(N-1)/2;i++){if(vec[i]!=vec[(N+1)/2-i]){A=false;}
;}
for(int i=j;i<=N;i++){if(vec[i]!=vec[j+N-i]){A=false;}
;}
if(A)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

ll pow(ll k, ll n) {
  if (k == 0) return 0;
  if (n == 0) return 1;
  
  int i = 0;
  while (i < n) {
    k *= k;
    i++;
  }
  return k;
}

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

  int b, p;
  int ans = 1;
  for (b = 1; b <= X; b++) {
    for (p = 2; p <= X ; p++) {
      if (pow(b,p)<=X)
        ans = max(ans, (int)pow(b,p));
      else
        break;
    }
  }

  cout << ans <<endl;
}

Measured memory_bytes: 384
import Control.Applicative
import Data.Function
import Control.Monad
import Data.List
import Data.Char

shuffle s [] = s
shuffle s (h:hs) = shuffle ((drop h s) ++ (take h s)) hs

main :: IO ()
main = fix $ \loop -> do
    s <- getLine
    unless (s == "-") $ do
        m <- readLn
        hs <- replicateM m readLn
        putStrLn $ shuffle s hs
        loop


Measured memory_bytes: 4180
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;
 
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}
 
use std::cmp::{min, max};
use std::num;
use std::collections::HashMap;
use std::collections::HashSet;

fn main() {
    
    // はじめに，使用されている文字のマッチング
    
    // tに使われている文字ごとにloopを回してindexのサーチ
    
    let m = read::<usize>();
    let d = read::<usize>();
    
    let mut ans = 0;
    
    'outer: for i in 2..10 {
        for j in 2..10 {
            if i*10 + j > d {break;}
            if i * j <= m {ans += 1;}
        }
    }
    
    println!("{:?}", ans);

}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define TO_STRING(a) #a
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }
template<class T> void MSG(T a){ cout << TO_STRING(a) << " = " << a << endl; }


int main()
{
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vint d(n);
	
	rep(i, n)
		cin >> d[i];
	
	sort(ALL(d), greater<int>());
	
	rep(i, n)
	{
		if((c + d[i]) / (a + b) >= c / a)
			c += d[i], a += b;
		else
			break;
	}
	
	cout << c / a << endl;
}

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

int main() {
	int h[300], w[300], count = 0, flag = 0;
	do {
		cin >> h[count] >> w[count];
		++count;
	} while (h[count-1] != 0 && w[count-1] != 0);

	count = 0;
	while (h[count] != 0 && w[count] != 0) {
		for (int i = 0; i < h[count]; ++i) {
			for (int n = 0; n < w[count]; ++n) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
		++count;
	}

}


Measured memory_bytes: 3088
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = b[0]
t2 = b[-1]
count = 0

half = n // 2

if n >= 2:
  for i in range(half):
    if a[i] > b[i]:
      count += b[i]
    else:
      count += a[i]
      b[i] -= a[i]
      if a[i+1] > b[i]:
        count += b[i]
        a[i+1] -= b[i]
      else:
        count += a[i+1]
        a[i+1] = 0

    if a[-1-i] > b[-1-i]:
      count += b[-1-i]
    else:
      count += a[-1-i]
      b[-1-i] -= a[-1-i]
      if a[-2-i] > b[-1-i]:
        count += b[-1-i]
        a[-2-i] -= b[-1-i]
      else:
        count += a[-2-i]
        a[-2-i] = 0

if n % 2 == 1:
  t = a[half] + a[half+1]
  if t > b[half]:
    count += b[half]
  else:
    count += t

print(count)


Measured memory_bytes: 82148
#include <stdio.h>

int main(void) {
  int n,x,i,j,k;
  int cont;
  while(1){
    scanf("%d %d",&n,&x);
    if((n+x)==0)
      break;
    cont=0;
    for(i=1;i<=(n-2);i++)
      for(j=2;j<=(n-1);j++)
	for(k=3;k<=n;k++)
	  if((i+j+k)==x&&i<j&&j<k)
	    cont++;
    printf("%d\n",cont);
  }
  return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
struct edge {
    ll to, cost;
};
struct Gragh {
    vector<vector<edge>> G;
    ll N;
    vl visited;
    vl active;
    ll isloop = 0;
    vl toposo;
    void init(ll n) {
        N = n;
        G.resize(N);
        visited = vl(N, 0);
    }

    void add(ll a, ll b, ll c = 1) { G[a].push_back((edge){b, c}); }

    void resetv(void) { visited = vl(N, 0); }

    vl Dijkstra(ll r) {
        vl cost(N, INF);
        resetv();
        priority_queue<PP, vector<PP>, greater<PP>> pq;
        ll a, b = r;
        cost[b] = 0;
        visited[b] = 1;

        for(edge i : G[b]) {
            if(cost[b] + i.cost < cost[i.to]) {
                pq.push(make_pair(cost[b] + i.cost, i.to));
            }
        }
        while(!pq.empty()) {
            a = pq.top().first;
            b = pq.top().second;
            pq.pop();
            if(visited[b] == 1)
                continue;
            visited[b] = 1;
            cost[b] = a;
            for(edge i : G[b]) {
                if(cost[b] + i.cost < cost[i.to]) {
                    pq.push(make_pair(cost[b] + i.cost, i.to));
                }
            }
        }

        return cost;
    }
};

int main() {
    char PA;
    cin >> h >> w;
    ll C[22][22];
    rep(i, h) {
        rep(j, w) { C[i][j] = 1; }
    }

    rep(i, h) {
        rep(j, w) {
            cin >> PA;
            if(PA == '.')
                C[i][j] = 0;
        }
    }

    Gragh G;
    G.init(h * w);
    rep(i, h) {
        rep(j, w) {
            if(i > 0 && C[i][j] == 0 && C[i - 1][j] == 0)
                G.add(i * w + j, (i - 1) * w + j);
            if(i < h - 1 && C[i][j] == 0 && C[i + 1][j] == 0)
                G.add(i * w + j, (i + 1) * w + j);
            if(j > 0 && C[i][j] == 0 && C[i][j - 1] == 0)
                G.add(i * w + j, i * w + j - 1);
            if(j < w - 1 && C[i][j] == 0 && C[i][j + 1] == 0)
                G.add(i * w + j, i * w + j + 1);
        }
    }

    rep(i, h * w) {
        vl A = G.Dijkstra(i);
        rep(j, h * w) {
            if(A[j] != INF)
                ans = max(ans, A[j]);
        }
    }

    cout << ans << endl;
}

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

int n,x[5010],y[5010];
int tote,FIR[5010],TO[5010],NEXT[5010];
bool vis[5010];

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

bool dfs(int u)
{
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (!dfs(v)) return 0;
	}
	memset(vis,0,sizeof(vis));
	vis[0]=1;
	int i,S0=0,S1=0;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		S0+=min(x[v],y[v]);
		S1+=max(x[v],y[v]);
		int tmp=abs(x[v]-y[v]);
		for (i=x[u]-tmp;i>=0;i--)
			vis[i+tmp]|=vis[i];
	}
	if (S0>x[u]) return 0;
	for (i=x[u]-S0;i>=0;i--)
		if (vis[i]) {y[u]=S1-i; break;}
	return 1;
}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,f;
	scanf("%d",&n);
	for (i=2;i<=n;i++)
	{
		scanf("%d",&f);
		addedge(f,i);
	}
	for (i=1;i<=n;i++)
		scanf("%d",&x[i]);
	puts(dfs(1)?"POSSIBLE":"IMPOSSIBLE");
}


Measured memory_bytes: 256
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
  int x=sc.nextInt();
  int ans=0;

  System.out.println(lcm(360,x)/x);
}

 static int gcd(int a, int b) 
    { 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
    } 
      
    // method to return LCM of two numbers 
    static int lcm(int a, int b) 
    { 
        return (a*b)/gcd(a, b); 
    } 
}

Measured memory_bytes: 35792
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split())) 
c = list(map(int,input().split()))

ans = sum(b)
for i in range(N-1):
  if a[i] +1 == a[i+1]:
    ans += c[a[i]-1]

print(ans)


Measured memory_bytes: 38384