akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i,n){
        int a; cin >> a;
        if (a == ans+1){
            ans++;
        }
    }
    if (ans == 0) cout << -1 << endl;
    else cout << n - ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> ans;
int sum = 2;
int main()
{
	scanf("%d", &n);
	if (n == 3)
	{
		printf("%d %d %d\n", 2, 5, 63);
		return 0;
	}
	ans = { 2, 3, 9};
	for (int i = 4; i <= 30000; i+=2)
	{
		if (ans.size() == n-1)
		{
			if ((sum + i) % 3 == 0)
			{
				ans.push_back(i);
				break;
			}
			else continue;
		}
		if (i > 29998-(n%2) && ans.size()%2 != n%2)
		{
			if ((sum + i) % 3 == 0)
			{
				ans.push_back(i);
				break;
			}
			else continue;
		}
		sum += i;
		ans.push_back(i);
	}
	for (int i = 15; ans.size() < n; i += 6)
	{
		ans.push_back(i);
	}
	for (int i = 0; i < ans.size(); i++)
	{
		printf("%d ", ans[i]);
	}
	printf("\n");
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
int X,A,B;
  
  scanf("%d",&X);
  scanf("%d",&A);
  scanf("%d",&B);
  
  X=X-A;
  do{
  
    X = X - B;
  
  }while(X>=0);
  
    
  printf("%d\n",X+B);

return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top,S[1000];

void push(int x){
	/* topを加入してからその位置へ挿入*/
	S[++top] = x;
}

int pop(){
	top--;
	/* topが指していた要素を返す*/
	return S[top+1];
}

int main(void)
{
	int a,b;
	top=0;
	char s[100];
	
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}else if( s[0] == '-' ){
			b=pop();
			a=pop();
			push(a-b);
		} else if ( s[0] == '*' ){
			a=pop();
			b=pop();
			push(a*b);
		} else {
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());

	return 0;
	
}



Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
int main(){
   long long n, m, i, a[100100], sum=0, ans=0;
   cin >> n >> m;
   for(i=0;i<m;i++){
      cin >> a[i];
      sum+=a[i];
   }
   ans=n-sum;
   if(ans<0) cout << -1 <<endl;
   else cout << ans <<endl;


   return 0;
}



Measured memory_bytes: 3652
from collections import deque


H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]


di = (1, 0, -1, 0)
dj = (0, 1, 0, -1)

def is_valid(i, j, d):
    ni = i + di[d]
    nj = j + dj[d]
    if not (0 <= ni < H and 0 <= nj < W):
        return False
    if S[i][j] == S[ni][nj]:
        return False
    return True


result = 0
visited = [[False] * W for _ in range(H)]
for i in range(H):
    for j in range(W):

        if visited[i][j]:
            continue
        visited[i][j] = True

        b = 0
        w = 0
        que = deque()
        que.append((i, j))
        while que:
            (ci, cj) = que.pop()
            if S[ci][cj] == '#':
                b += 1
            else:
                w += 1

            for d in range(4):
                if not is_valid(ci, cj, d):
                    continue
                ni = ci + di[d]
                nj = cj + dj[d]
                if visited[ni][nj]:
                    continue
                visited[ni][nj] = True
                que.append((ni, nj))

        result += b * w


print(result)



Measured memory_bytes: 51164
H,W,A,B = list(map(int, input().split()))

row = ''
for i in range(B):
    for j in range(A):
        row += '0'
    for j in range(W-A):
        row += '1'
    print(row)
    row = ''
for i in range(H-B):
    for j in range(A):
        row += '1'
    for j in range(W-A):
        row += '0'
    print(row)
    row = ''

Measured memory_bytes: 3956
import sys
input = sys.stdin.readline

a, b, q = map(int, input().split())
INF = 10 ** 11
s = [int(input()) for _ in range(a)] + [INF]
t = [int(input()) for _ in range(b)] + [INF]
x = [[int(input()), int(i), INF, INF, INF, INF] for i in range(q)]
x.sort(key=lambda x: x[0])
si = 0
ti = 0
for i in range(q):
    xi = x[i][0]
    while xi > s[si]:
        si += 1
    ls = abs(xi - s[si - 1])
    rs = abs(xi - s[si])

    while xi > t[ti]:
        ti += 1
    lt = abs(xi - t[ti - 1])
    rt = abs(xi - t[ti])

    x[i][2] = ls
    x[i][3] = rs
    x[i][4] = lt
    x[i][5] = rt

x.sort(key=lambda x: x[1])
for xi, i, ls, rs, lt, rt in x:
    ans = min(max(ls, lt),
              max(rs, rt),
              min(ls, rt) * 2 + max(ls, rt),
              min(rs, lt) * 2 + max(rs, lt))
    print(ans)

Measured memory_bytes: 45048
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vll vector<ll>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template<typename T>
void vecin(vector<T>& v, int n = 0){
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n-1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}
void print(string s){
    cout << s << endl;
}
struct edge{
    int to, from;
};

int main()
{
    ciosup;
    int n;
    cin >> n;
    vint a(n), b(n), c(n-1);
    vecin(a);
    vecin(b);
    vecin(c);
    ll ans = 0;
    REP(i, n)
    {
        if (i > 0){
            if (a[i-1] + 1 == a[i]){
                ans += c[a[i - 1] - 1];
            }
            ans += b[a[i] - 1];
        }
        else
        {
            ans += b[a[i] - 1];
        }
    }
    cout << ans << endl;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll L;
    cin >> L;
    vector<tll> answers;
    ll nodeIndex = 1;
    ll filled = 1; //半開
    while (filled * 2 <= L)
    {
        answers.emplace_back(nodeIndex, nodeIndex + 1, 0);
        answers.emplace_back(nodeIndex, nodeIndex + 1, filled);
        nodeIndex++;
        filled *= 2;
    }
    while (filled < L)
    {
        ll targetIndex = 1;
        ll targetValue = 1;
        while (targetValue <= L - filled)
        {
            targetValue *= 2;
            targetIndex++;
        }
        targetValue /= 2;
        targetIndex--;
        answers.emplace_back(targetIndex, nodeIndex, filled);
        filled += targetValue;
    }
    cout << nodeIndex << " " << answers.size() << " " << endl;
    for (auto answer : answers)
    {
        ll node1, node2, value;
        tie(node1, node2, value) = answer;
        cout << node1 << " " << node2 << " " << value << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
        using namespace std;
         
        int main()
        {
          string N;
          cin >> N;
          if(N == "SAT"){
            std::cout << 1 << std::endl;
          }else if(N == "FRI"){
            std::cout << 2 << std::endl;
          }else if(N == "THU"){
            std::cout << 3 << std::endl;
          }else if(N == "WED"){
            std::cout << 4 << std::endl;    
          }else if(N == "TUE"){
            std::cout << 5 << std::endl; 
          }else if(N == "MON"){
            std::cout << 6 << std::endl;  
          }else{
            std::cout << 7 << std::endl; 
          }
        }

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x[101][101]={};
  int r,c;
  int i,j;

  scanf("%d %d", &r, &c);
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf("%d",&x[i][j]);
      x[i][c] += x[i][j];
      x[r][j] += x[i][j];
      x[r][c] += x[i][j];
    }
  }
  for(i=0;i<r+1;i++){
    for(j=0;j<c+1;j++){
      printf("%d",x[i][j]);
      if(j==c){
        printf("\n");
      }
      else{
        printf(" ");
      }
    }
  }

  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C;
  cin>>A>>B>>C;
  for(int i=B;i<=C;i++)
    if(i%A==0)
    {
      puts("OK");
      return 0;
    }
  puts("NG");
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 2e5 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> g[N];
ll n,k,i,x,y;
bool lf(ll x,ll y){
    return x > y;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n;
    for (i = 1;i < n;i++){
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ll cc = 0,ans = 0;
    for (i = 1;i <= n;i++){
        cc += i;
        for (auto j : g[i]) if (j < i) cc -= j;
        ans += cc;
    }
    cout<<ans;
}



Measured memory_bytes: 15820
from collections import defaultdict
s = input()
d = defaultdict(list)
for i in range(len(s)):
    d[s[i]].append(i)
cnt= 10000000000
ans = 0
for x in d.values():
    ans = 0
    ans = max(ans, x[0])
    ans = max(ans, len(s)-1-x[-1])
    for i in range(len(x)-1):
        ans = max(ans, x[i+1]-x[i]-1)
    cnt = min(cnt, ans)
print(cnt)

Measured memory_bytes: 38384
#include <stdio.h>

int main()
{
	int N, L;
	scanf("%d %d", &N, &L);
	if (L >= 0) printf("%d\n", (L * 2 + N) * (N - 1) / 2);
	else if (L + N - 1 >= 0) printf("%d\n", (L * 2 + N - 1) * N / 2);
	else printf("%d\n", (L * 2 + N - 2) * (N - 1) / 2);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1712
#include<stdio.h>
int main(void)
{
	int n,k,x,y,z;
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&x);
	scanf("%d",&y);
	if(n>=k){
		z=k*x+(n-k)*y;
	}
	else{
		z=n*x;
	}
	printf("%d\n",z);
	
	return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    
    if (!K) return cout << (long)N * N << "\n", 0;
    
    long ans = 0;
    for (int b = K + 1; b <= N; b++) {
        ans += (b - K) * (N / b);
        ans += max(0, N % b - K + 1);
    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, i; cin >> n >> i;

    cout << n - i + 1 << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 998244353;
const int N = 100005;

int n, i, j, tab[N], ok[N], maxx, res;

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) {
	scanf("%d", &tab[i]);
	ok[tab[i]]++;
	maxx = max(maxx, tab[i]);
}
if (tab[0] != 0 || ok[0] > 1) {
	printf("0\n");
	return 0;
}
for (i=0;i<=maxx;i++) if (!ok[i]) {
	printf("0\n");
	return 0;
}
res = 1;
for (i=1;i<=maxx;i++) for (j=0;j<ok[i];j++) res = (res * 1LL * ok[i - 1]) % MOD;
printf("%d\n", res);
return 0;
}

Measured memory_bytes: 1024
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w,k=MI()
dp=[[0]*w for i in range(h+1)]
dp[0][0]=1
a=0
b=1
weight=[]
for i in range(100):
    weight.append(a+b)
    a,b=b,a+b
#print(weight)    
for i in range(h):
    for j in range(w):
        if 0<=j+1<w:
            left=max(j-1,0)
            right=max(w-j-3,0)
            dp[i+1][j+1]+=(dp[i][j]*weight[left]*weight[right])%mod
        if 0<=j<w:
            left=max(j-1,0)
            right=max(w-j-2,0)
            dp[i+1][j]+=(dp[i][j]*weight[left]*weight[right])%mod
        if 0<=j-1<w:
            left=max(j-2,0)
            right=max(w-j-2,0)
            dp[i+1][j-1]+=(dp[i][j]*weight[left]*weight[right])%mod
print(dp[-1][k-1]%mod)


    

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

int main() {
	int64_t	N;
	cin >> N;
	int64_t num;
	for (int i = sqrt(N); i > 0; i--)
	{
		if (N % i == 0)
		{
			num = N / i;
			break;
		}
	}
	int		digit;
	while (num)
	{
		num /= 10;
		digit++;
	}
	cout << digit << endl;
}


Measured memory_bytes: 256
N = int(input())
X = [i for i in range(N+1)]
Y = [[] for _ in range(N)]
B, W = [], []
ans = 0
for i in range(2 * N):
    c, a = input().split()
    a = int(a) - 1
    if c == "B":
        X = [X[i] + 1 if i <= a else X[i] - 1 for i in range(N+1)]
        B.append(a)
        ans += len([b for b in B if b > a])
    else:
        Y[a] = X[:]
        W.append(a)
        ans += len([b for b in W if b > a])

Z = [0] * (N+1)
for y in Y:
    for i in range(N+1):
        Z[i] += y[i]
    for i in range(1, N+1):
        Z[i] = min(Z[i], Z[i-1])

ans += Z[-1]
print(ans)

Measured memory_bytes: 85852
#include <stdio.h>

int main(void){

    long long int N;
    scanf("%lld", &N);
    long long int A[N];
    long long int a[N];
    int i;
    
    for (i = 0; i < N; i++)
        a[i] = 0;
    for (i = 0; i < N - 1; i++)
        scanf("%lld ", A + i);
    for (i = 0; i < N - 1; i++)
        a[A[i] - 1]++;
    for (i = 0; i < N; i++)
        printf("%lld\n", a[i]);
    return (0);
}

Measured memory_bytes: 4804
#include <iostream>
using namespace std;
int main() {

	int a, b, c;
	cin >> a >> b >> c;
	if (a != b && b != c && a != c) {
		cout << "3" << endl;
		goto end;
	}
	if (a == b && b == c) {
		cout << "1" << endl;
	}
	else {
		cout << "2" << endl;
	}

	end:

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int lcm(int x, int y){
    if(x<y) swap(x,y);
    int r = x%y , xy = x*y;
    while(r!=0){
        x = y;
        y = r;
        r = x%y;
    }
    return xy / y;
}

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

int main() {
    int x;
    cin >> x;
    int deg = x;
    int ans = 1;
    while (deg % 360 != 0) {
        deg += x;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main( void )
{
	long a, b;
	while(cin >> a >> b) {
		long aa, bb, cc;
		aa = a; bb = b;
		while(bb) {
			cc = aa % bb;
			aa = bb;
			bb = cc;
		}
		cout << aa << ' ' << a*(b/aa) << endl;
	}
	return 0;
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  ll x;
  cin >> x;
  if (x % 11 == 0)
    cout << x / 11 * 2 << endl;
  else if (x % 11 <= 6)
    cout << x / 11 * 2 + 1 << endl;
  else
    cout << x / 11 * 2 + 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int N, M;
  int T[110];
  int sum = 0;
  int ans[110];
  int i;
  
  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    scanf("%d", &T[i]);
 	sum += T[i];
  }
  
  scanf("%d", &M);
  for(i = 0; i < M; i++) {
    int P, X;
    scanf("%d %d", &P, &X);
    ans[i] = sum - T[P-1] + X;
  }
  
  for(i = 0; i < M; i++) printf("%d\n", ans[i]);
  
  return 0;
}

Measured memory_bytes: 128
/*
Author: Vishal Singh  
(singhvishal0304@gmail.com)

"The days that break you are the days that make you."

*/

#include <bits/stdc++.h>
using namespace std;

#define fastio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);

#define md 1000000007


#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r,c) vector<vector<lli>> v(r,vector<lli>(c));
#define fi first
#define se second
#define mem(arr,x) memset(arr,x,sizeof(arr))

lli power(lli a,lli b){
	if(b==0)
		return 1;
	if(b%2)
		return ((a%md)*(power(a,b-1)))%md;
	else
	{
		lli x=power(a,b/2);
		return (x*x)%md;
	}
}

lli numCuts(vector<lli>& a,lli mid){
	int n=a.size();
	lli sum=0;
	for(int i=0;i<n;i++){
		lli x=a[i]/mid;
		if(a[i]%mid)
		x++;
		sum+=x-1;
	}
	return sum;
}
lli bin_search(vector<lli>& a,lli l,lli r,lli k){
	if(l<r){
		lli mid=l+(r-l)/2;
		if(numCuts(a,mid)>k)
			return bin_search(a,mid+1,r,k);
		return bin_search(a,l,mid,k);
	}
	return l;
}

void solve(){
	lli n,k;
	cin>>n>>k;
	vector<lli> a(n);
	lli r=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		r=max(r,a[i]);
	}
	lli ans=bin_search(a,1,r,k);
	cout<<ans<<endl;

}


int main()
{	
    fastio();
	int t;
	
	t=1;
	while(t--){
		solve();
	}

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

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

  rep(i, n + 1) {
    rep(j, n - i + 1) {
      int k = n - i - j;
      if (i * 10000 + j * 5000 + k * 1000 == y) {
        cout << i << ' ' << j << ' ' << k;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string>
#include<iostream>
using  namespace std;
int main()
{
    string q;
    cin>>q;
    for(int i=q.size()-2; i>0; i--)
    {


        if((i)&1)
            continue;
        int kai=0,jie=(i+1)/2;
        while(kai!=(i+1)/2)
        {
            if(q[kai]!=q[jie])
                break;
            kai++;
            jie++;
        }
        if(kai==(i+1)/2)
        {
            printf("%d\n",i);
            return 0;

        }

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  1e5 + 10;  
#define FI first
#define SE second
typedef pair<int, int>pii;
int num[N];
ll tmp[N], n;
bool judge(int cnt, int a, int b)
{
	int d = a - b;
	int lcnt = cnt;
	for (int i = 0; i < n; i++)
	{
		tmp[i] = num[i];
		tmp[i] -= (ll)cnt*b;
		if (tmp[i] <= 0)
			return true;
		int ct = tmp[i] / d + (tmp[i]%d?1:0);
		if (ct > lcnt)
			return false;
		lcnt -= ct;
	}
	return true;
}	
int main()  
{  
  // freopen("in.txt","r",stdin);
   int  a, b;
   while (~scanf("%d%d%d", &n, &a, &b))
   {
   
   	for (int i = 0; i < n; i++)
   	{
   		scanf("%d", num + i);
   	}
   	sort(num, num + n, greater<int>());
   	int l = 0, r = 1e9 + 10;
   	while (l < r)
   	{
   		int mid = l + ((r - l)>>1);
   		if (judge(mid, a, b))
   			r = mid;
   		else
   			l = mid + 1;
   	}
   	printf("%d\n", l);
   }
   
   return 0;  
}  

Measured memory_bytes: 1408
N, *AB = map(int, open(0).read().split())

A = sorted(AB[::2])
B = sorted(AB[1::2])

if N % 2 == 1:
    L = A[N // 2]
    R = B[N // 2]
else:
    L = A[N // 2 - 1] + A[N // 2]
    R = B[N // 2 - 1] + B[N // 2]

print(R - L + 1)

Measured memory_bytes: 55380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s;
    cin>>s;
    string oris=s;
    reverse(s.begin(),s.end());
    string revs=s;
    int ans=0;
    rep(i,0,s.size()/2){
        if(oris[i]!=revs[i]) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

int p[300010];
ll a[600],acnt;
ll b[600],bcnt;

int main(){
	p[1]=1;
	for(int i=6,mmm=5;i<300005;i+=mmm^=7)if(!p[i])for(int j=6,nnn=5;i*j<300005;j+=nnn^=7)p[i*j]=1;
	ll n;
	while(scanf("%lld",&n),n!=1){
		acnt=bcnt=0;
		printf("%lld:",n);
		for(int i=1,mmm=2;i*i<=n;i+=mmm^=7)if(n%i==0){
			if(i*i!=n&&!p[i])a[acnt++]=i;
			if(!p[n/i])b[bcnt++]=n/i;
		}
		rep(i,0,acnt)printf(" %lld",a[i]);
		rep(i,0,bcnt)printf(" %lld",b[bcnt-1-i]);
		puts("");
	}
}


Measured memory_bytes: 2952
#include <bits/stdc++.h>
using namespace std;
int h, w, a, b;
int main () {
	scanf("%d%d%d%d", &h, &w, &a, &b);
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (i <= b && j <= a) printf("1");
			else if (i > b && j > a) printf("1");
			else printf("0");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
vector <pii> b[N];
int a[N][N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	int k; sc(k);
	if (k<=500)
	{
		pr(k);
		for (int i=1; i<=k; i++,putchar('\n'))
			for (int j=1; j<=k; j++)
				printf ("%d ",i);
	}
	else
	{
		int n=500;
		pr(n);
		for (int i=1; i<=n; i++)
			for (int j=1; j<=n; j++)
				a[i][j]=(i+j<=n+1)?(i+j-1):(i+j-n-1),b[a[i][j]].pb (mp(i,j));
		for (int i=n+1; i<=k; i++)
		{
			int id=i-n;
			for (int j=1; j< (int)b[id].size (); j+=2)
				a[b[id][j].fi][b[id][j].se]=i;
		}
		for (int i=1; i<=n; i++,putchar('\n'))
			for (int j=1; j<=n; j++)
				printf ("%d ",a[i][j]);

	}

    return 0;
}


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

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

int main(){
  vector<char> alp = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  ll n;
  cin >> n;

  string ans;

  while(n>0){
    //cout << n << endl;
    int x = n%26-1;
    if(x==-1) x=25;
    ans += alp.at(x);
    if(n%26==0) n = n/26-1;
    else n/= 26;
  }
  
  rep(i,ans.size()) cout << ans.at(ans.size()-1-i);
  //cout << ans;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


int N, M;
vector<pint> city[100000];  //(yeah, index)
ll number[100000];

signed main(){
    cin >> N >> M;
    int p, y;
    REP(i, M){
        cin >> p >> y;
        city[p - 1].push_back(pint(y, i));
    }
    REP(i, N){
        sort(ALL(city[i]));
    }
    REP(i, N){
        REP(j, city[i].size()){
            number[city[i][j].second] = (ll)(i + 1) * 1000000 + (j + 1);
        }
    }
    REP(i, M){
        printf("%012lld\n", number[i]);
    }
    return 0;
}

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


typedef vector<int> vi;    
   

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vi a(n + 3);
        rep(i, n) in >> a[i + 1];

        bool ans = false;
        int i = 1;
        int j = a[i];
        int res = 1;
        while (j) {
            if (j == 2) {
                ans = true;
                break;
            }
            a[i] = 0;
            i = j;
            j = a[i];
            res++;
        }

        out << (ans ? res : -1) << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

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

    int n = s.length();
    int flag = 0;
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            string t = s;
            string k = t.erase(i, j - i);
            if(k == "keyence"){
                flag = 1;
                break;
            }
        }

        if(flag == 1){
            break;
        }
    }

    if(flag == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
const ll mod = 1e9+7;
const int sz = 62;
#define afdafafafdafaf y1;
int n,m;
char ch[maxn];

int main()
{
    scanf("%d%d", &n, &m);
    scanf("%s", ch);
    int ins=0;
    for(int i=0;i<n;i++){
        if(i==0 || ch[i] != ch[i-1]){
            ins++;
        }
    }
    ins = max(1, ins - m*2);
    printf("%d\n", n-ins);

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
	int d,r,a,b;
	double a1,b1,f;
	scanf("%d" "%d",&a,&b);
	a1 =a;
	b1 =b;
	d = a / b;
	r = a % b;
	f = a1 / b1;
	printf("%d %d %.5f\n",d,r,f);
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  vector<int> A(N); cin >> A;
  map<int, int> m;
  rep(i, N) {
    m[i - A[i]]++;
  }
  ll ans = 0;
  rep(i, N) {
    ans += m[A[i] + i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 21156
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
vector<pair<pair<int,int>,int> >a;
int main(){
	int l;
	cin>>l;
	vector<int>v;
	int t=0;
	while(l){
		if(l%2)v.push_back(t);
		l/=2;
		t++;
	}
	int n=v.back()+1;
	for(int i=1;i<n;i++)
	{
		a.push_back(make_pair(make_pair(i,i+1),0));
		a.push_back(make_pair(make_pair(i,i+1),(1<<(i-1))));
	}
	int sum=1<<v.back();
	for(int i=(int)v.size()-2;i>=0;i--){
		int y=v[i]+1;
		a.push_back(make_pair(make_pair(y,n),sum));
		sum+=1<<v[i];
	}
	cout<<n<<" "<<a.size()<<endl;
	for(int i=0;i<a.size();i++)
		cout<<a[i].first.first<<" "<<a[i].first.second<<" "<<a[i].second<<endl;
	
}

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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    vector<unsigned long> A, F;
    A.reserve(N);
    F.reserve(N);
    copy_n(istream_iterator<unsigned long>(cin), N, back_inserter(A));
    copy_n(istream_iterator<unsigned long>(cin), N, back_inserter(F));
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    const auto f = [&N, &A, &F, &K](unsigned long x) -> bool{
        unsigned long cnt{0};
        for(unsigned long i = 0; i < N; ++i){
            cnt += A[i] - min(A[i], x / F[i]);
            if(cnt > K)return false;
        }
        return true;
    };
    if(f(0))return 0 & puts("0");
    unsigned long r{0}, l{0};
    for(unsigned long i = 0; i < N; ++i)l = max(l, A[i] * F[i]);
    while(r + 1 < l){
        auto m = (r + l) / 2;
        (f(m) ? l : r) = m;
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <climits>
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int countC(vector<pair<int, int>>& xy, int xbegin, int xend, int ybegin, int yend) {
	int c = 0;
	for (auto i : xy) {
		if (i.first >= xbegin && i.first <= xend && i.second >= ybegin && i.second <= yend) {
			c++;
		}
	}
	return c;
}

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

	vector<pair<int, int>> xy(n);

	for (auto& i : xy) {
		int x, y;
		cin >> x >> y;
		i = make_pair(x, y);
	}

	sort(begin(xy), end(xy));


	long long ans = LLONG_MAX;

	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			int ybegin = xy[i].second;
			int yend = xy[j].second;
			if (ybegin > yend) swap(ybegin, yend);
			if (countC(xy, INT_MIN, INT_MAX, ybegin, yend) < k) continue;

			long long yl = yend - ybegin;
			long long xl = xy[n - 1].first - xy[0].first;

			for (int ix = 0; ix < n - k + 1; ix++) {
			    int c = 0;
			    int ie = ix - 1;
				while (c < k && ie < n - 1) {
					ie++;
					if (xy[ie].second >= ybegin && xy[ie].second <= yend) c++;	
				}
				if (c >= k) {
					int xt = xy[ie].first - xy[ix].first;
					if (xl > xt) xl = xt;
				}
			}

			long long anst = xl * yl;
			if (ans > anst) ans = anst;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define INF 10000000000LL

#define MAX_V 1010
#define INF 10000000000LL

double m[MAX_V][MAX_V];
double mn[MAX_V];
int dijflag[MAX_V];

void dijk(int start, int V){
  for(int i = 0; i < MAX_V; i++)mn[i] = 1.*INF;
  for(int i = 0; i < MAX_V; i++)dijflag[i] = 0;
  mn[start] = 0;
  for(;;){
    int v = -1;
    for(int i = 0; i < V; i++){
      if(dijflag[i] == 0){
        if(v == -1){
          v = i;
        }
        else{
          if(mn[i] < mn[v]){
            v = i;
          }
        }
      }
    }
    if(v == -1)break;
    dijflag[v] = 1;
    for(int i = 0; i < V; i++){
      if(mn[i] > mn[v] + m[v][i]){
        mn[i] = mn[v] + m[v][i];
      }
    }
  }
}

int main() {
	ll x0,y0,x1,y1;
	cin>>x0>>y0>>x1>>y1;
	ll n;
	cin>>n;
	vector<ll> vx;
	vector<ll> vy;
	vector<ll> vr;
	vx.pb(x0);
	vx.pb(x1);
	vy.pb(y0);
	vy.pb(y1);
	vr.pb(0);
	vr.pb(0);
	rep(i,0,n){
		ll a,b,c;
		cin>>a>>b>>c;
		vx.pb(a);
		vy.pb(b);
		vr.pb(c);
	}
	rep(i,0,vx.sz){
		rep(j,0,vx.sz){
			double d = max(0.,pow(1.*(vx[i]-vx[j])*(vx[i]-vx[j])+(vy[i]-vy[j])*(vy[i]-vy[j]),0.5)-vr[i]-vr[j]);
			m[i][j] = d;
		}
	}
	dijk(0,vx.sz);
	printf("%20.20f\n", mn[1]);
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    cout << "A" << s[1][0] << "C" << endl;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N;
  string s;
  cin >> N >> s;

  vector<int> dp(N), tmp(N);
  dp[0] = 1;

  for (int i = 0; i + 1 < N; i++) {

    if (s[i] == '<') {
      tmp[0] = 0;
      for (int j = 1; j <= i + 1; j++) {
        tmp[j] = (tmp[j - 1] + dp[j - 1]) % MOD;
      }
    } else {
      tmp[i + 1] = dp[i + 1];
      for (int j = i; j >= 0; j--) {
        tmp[j] = (tmp[j + 1] + dp[j]) % MOD;
      }
    }

    swap(dp, tmp);
  }

  int ans = 0;
  for (int x : dp) {
    ans = (ans + x) % MOD;
  }

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


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    std::vector<int> D;
    for(int i = 1; i < N; i++){
        D.push_back(0);
    }
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            if(i <= X){
                if(j >= Y){
                    int dis = X - i + j - Y + 1;
                    D.at(dis-1) = D.at(dis-1) + 1;
                } else {
                    int dis = std::min(j-i, X-i+Y-j+1);
                    D.at(dis-1) = D.at(dis-1) + 1;
                }
            } else {
                if( j <= Y ){
                    int dis = std::min(j-i, i-X+Y-j+1);
                    D.at(dis-1) = D.at(dis-1)+1;
                } else {
                    int dis = std::min(j-i, i-X+j-Y+1);
                    D.at(dis-1) = D.at(dis-1)+1;
                }
            }
        }
    }
    for(int i = 0; i < N-1; i++){
        cout << D.at(i) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 5;
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll a, b;
    cin >> a >> b;
    cout << (a > 8 || b > 8 ? ":(" : "Yay!");
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by sonetsuyoshi on 2016/07/31.
 */
public class Main {

    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] counts = new int[N];

        for(int i = 0; i < M; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            counts[a]++;
            counts[b]++;
        }

        for(int count: counts) System.out.println(count);
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define ll long long
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=true;

set<string>se;

void divide(string s){
  string a;
  a=s[0];
  s.erase(s.begin());
  while(s.size()){
    se.insert(a+s);
    se.insert(s+a);
    reverse(all(a));
    //if(debug)cout<<s<<"+"<<a<<endl;
    se.insert(s+a);
    se.insert(a+s);
    reverse(all(s));
    se.insert(s+a);
    se.insert(a+s);
    reverse(all(a));
    //if(debug)cout<<s<<"+"<<a<<endl;
    se.insert(s+a);
    se.insert(a+s);
    reverse(all(s));
    a=a+s[0];
    s.erase(s.begin());
    //cout<<s<<endl;
  }
}


int main(){
  int m;
  string s;
  cin>>m;
  rep(i,m){
    cin>>s;
    divide(s);
    cout<<se.size()<<endl;
    se.clear();
  }

  return 0;
}

Measured memory_bytes: 3256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define nmod         -1000000007
#define N            1000000//31630=sqrt(pow(10,9))
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
//bool pf[N+1ll];
//vec prim;
//void sieve()
//{
//    repi(i,0,N)
//    pf[i]=true;
//	pf[0] = pf[1] = false;
//    for (int i = 2; i <= N; i++) {
//        if (pf[i]) 
//		{
//            prim.push_back(i);
//            for (int j = i + i; j <= N; j+=i) {
//                pf[j] = false;
//            }
//        }
//    }
//}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS; 
    while(TESTS--)
    {
    	ll m,i,l,h,j,mx,my,ans,d,n,r,g,b,e,f;
    	cin>>m;
    	cout<<fixed<<setprecision(10);
    	lld k=3.141592653;
    	k=k*(2.00)*(m*1.00);
    	cout<<k;
    	
    	
    	
    	
		
	}
	return 0;
} 

Measured memory_bytes: 3820
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
  int x, a, b;
  std::cin >> x >> a >> b;
  std::cout << (std::abs(x - a) < std::abs(x - b) ? 'A' : 'B') << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
int n;
ll a, b, h[100009];

bool sc(ll l)
{
	ll r = 0;
	for (int i = 0; i < n; i++) {
		ll th = h[i] - (b * l);
		if (th > 0)
			r += (th - 1) / (a - b) + 1;
	}
	return (r <= l);
}

ll bs(ll s, ll e)
{
	ll md = (s + e) / 2;
	if (s >= e) return md;
	if (sc(md)) return bs(s, md);
	else return bs(md + 1, e);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	cout << bs(0, 1000000009LL) << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include<stack>
#include<string>
#include<algorithm> 
#include <set>
#include<list>
using namespace std;
#define F first
#define S second
#define li long long int 
#define ld long double
#define pb push_back
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	li L, R, d; cin >> L >> R >> d; li c = 0;
	for (li i = L; i <= R; i++)
	{
		if (i % d == 0)
			c++;
	}
	cout << c;

	return 0;
}

Measured memory_bytes: 3620
from collections import deque

n , m = map(int, input().split())
maze = [['#']+list(input())+['#'] for i in range(n)]
maze = [['#']*(m+2)]+maze+[['#']*(m+2)]

step = [(0,1),(1,0),(-1,0),(0,-1)]

costma=0
for i in range(1,n+1):
    for j in range(1,m+1):
        v = [[0]*(m+2) for i in range(n+2)]
        d = deque()
        d.append((i,j,0))
        v[i][j]=1
        while d:
            y,x,cost=d.popleft()
            if maze[y][x]=='.':
                for dy,dx in step:
                    if maze[y+dy][x+dx]=='.' and v[y+dy][x+dx]==0:
                        v[y+dy][x+dx]=1
                        d.append((y+dy,x+dx,cost+1))
                        costma=max(cost+1,costma)
print(costma)


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

int main(){
  ll n,k,d,a,i,j,ans;
  cin >> n >> k;
  ll p[n+1];
  for(i=0;i<=n;i++){
    p[i]=0;
  }
  for(i=1;i<=k;i++){
    cin >> d;
    for(j=1;j<=d;j++){
      cin >> a;
      p[a]+=1;
    }
  }
  ans=0;
  for(i=1;i<=n;i++){
    if(p[i]==0)ans+=1;
  }
  cout << ans;
}

Measured memory_bytes: 3640
using System;
     
    namespace abc076_b
    {
        class Program
        {
            static void Main(string[] args)
            {
                int n = int.Parse(Console.ReadLine());
                int k = int.Parse(Console.ReadLine());
                int ret = 1;
                for (int i = 0; i < n; i++)
                {
                    if (ret < k) ret *= 2;
                    else ret += k;
                }
                Console.WriteLine(ret);
            }
        }
    }

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

namespace abc152_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(input[0]);
            int b = Convert.ToInt32(input[1]);


            string strA = Convert.ToString(b);
            for (int i = 0; i < a - 1; i++)
            {
                strA += Convert.ToString(b);
            }
            string strB = Convert.ToString(a);
            for (int i = 0; i < b - 1; i++)
            {
                strB += Convert.ToString(a);
            }
            if (strA.CompareTo(strB) <= 0)
            {
                Console.WriteLine(strA);
            }
            else
            {
                Console.WriteLine(strB);
            }
        }
    }
}


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

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

    int ans[2] = {0};
    rep(i, n) {
        string s, t;
        cin >> s >> t;

        if (s == t)
            ans[0]++, ans[1]++;
        else
            ans[s < t] += 3;
    }

    cout << ans[0] << " " << ans[1] << endl;

    return 0;
}


Measured memory_bytes: 3152