akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
int n,p[100010],m,x,r[100010],v[100010],beg[100010],cnt1,cnt2;
long long a[100010],k,ans[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%lld",a+i),a[i-1]=a[i]-a[i-1],p[i-1]=i-1;
	scanf("%d%lld",&m,&k);
	for(int i=1;i<=m;++i)scanf("%d",&x),p[x]^=p[x-1],p[x-1]^=p[x],p[x]^=p[x-1];
	for(int i=0;i<n;++i)if(!r[i]){
		v[beg[++cnt2]=++cnt1]=i;r[i]=cnt2;
		for(int j=p[i];j!=i;j=p[j])v[++cnt1]=j,r[j]=cnt2;
	}beg[cnt2+1]=n+1;
	for(int i=1;i<=cnt2;++i){
		int len=beg[i+1]-beg[i];
		for(int j=beg[i];j<beg[i+1];++j)ans[v[j]]=v[(j-beg[i]+k)%len+beg[i]];
	}
	ans[0]=a[ans[0]];for(int i=1;i<n;++i)ans[i]=a[ans[i]]+ans[i-1];
	for(int i=0;i<n;++i)printf("%lld.0\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4480
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
x = [0 for _ in range(k + 1)]

ans = 0
for i in range(k, 0, -1):
    x[i] = pow(k // i, n, MOD)
    t = 0
    for j in range(2 * i, k + 1, i):
        x[i] -= x[j]
        x[i] %= MOD
    ans += i * x[i] % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 11400
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class DClassified {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        fr(i,n){
            for(int j=i+1;j<n;++j){
                int k=i^j,l=1;
                while((k&1)==0) k>>=1,++l;
                out<<l<<" ";
            }
            out<<endl;
        }
    }
};

int main() {
    DClassified solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

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

typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _ % MOD
#define __ %= MOD

#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))

#define swap(a, b) \
	{              \
		a = a + b; \
		b = a - b; \
		a = a - b; \
	}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

#define pv(a)                                 \
	{                                         \
		rep(i, a.size()) cout << a[i] << " "; \
		cout << endl;                         \
	}
#define mark(v) cout << "Here--" << v << endl;

const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y & 1)
			res = res * x;
		y = y >> 1;
		x = x * x;
	}
	return res;
} // modular exponent

int main()
{
	ios_base::sync_with_stdio(false); // don't use printf and scanf
	cin.tie(NULL);					  // cout<<fixed<<setprecision
	string s;
	cin >> s;
	ll n = s.size();
	ll sum = 0;
	for (int i = 1; i < s.size(); i += 2)
	{
		s.insert(s.begin() + i, '#');
	}

	rep(m, (1 << n - 1))
	{
		string temp = s;
		rep(j, n - 1)
		{
			if ((1 << j) & m)
			{
				temp[s.size() - 2 - 2 * j] = '+';
			}
		}
		vector<string> str;
		int i = 0;
		string l;
		while (i < temp.size())
		{

			if (temp[i] == '#')
				i++;
			else if (temp[i] != '#' && temp[i] != '+')
			{
				l.push_back(temp[i]);
				i++;
			}
			else if (temp[i] == '+')
			{
				i++;
				str.push_back(l);
				l.clear();
			}
		}
		str.push_back(l);
		l.clear();
		ll t = 0;
		for (auto f : str)
		{
			t += stoll(f);
		}
		sum += t;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3648
a = [list(map(int, input().split())) for i in range(3)]
for j in range(int(input())):
  b = int(input())
  for h in range(3):
    for k in range(3):
      if a[h][k] == b:
        a[h][k] = 0

ans = 'No'        
for m in range(3):
  if a[m][0] == a[m][1] == a[m][2]:
    ans = 'Yes'
  if a[0][m] == a[1][m] == a[2][m]:
    ans = 'Yes'
if a[0][0] == a[1][1] == a[2][2]:
  ans = 'Yes'
if a[0][2] == a[1][1] == a[2][0]:
  ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:2
*Problem:E - 木と整数 / Integers on a Tree
*Date:2018-10-20
*Algorithm:Teacher's DFS
*Stats:Unknown*/

bool debug=false;

int n,k;
vector<int> nei[100005];
int l[100005],r[100005];
int id[100005];

const int MAX=1E9+7;

void dfs(int pos,int par){
	
	//cout<<pos<<"-"<<id[pos]<<endl;
	l[pos]=-MAX-1;
	r[pos]=MAX+1;
	if(id[pos]!=-1){
		
		l[pos]=r[pos]=id[pos];
	}
	
	for(int i=0;i<nei[pos].size();i++){
		int to=nei[pos][i];
		if(to!=par){
			dfs(to,pos);
			
			if(l[to]<-MAX/2){
				//bad
				continue;	
			}
			
			if(l[pos]<-MAX/2){
				l[pos]=l[to]-1;
				r[pos]=r[to]+1;
			}else{
				if(abs(l[pos])%2==abs(l[to])%2){
					puts("No");
					exit(0);
				}
				
				l[pos]=max(l[pos],l[to]-1);
				r[pos]=min(r[pos],r[to]+1);
			}
		}
	}
	
	if(l[pos]>r[pos]){
		puts("No");
		exit(0);
	}
}

void gen(int pos,int par){
	if(pos==0 && id[pos]==-1){
		id[pos]=l[pos];
	}
	
	for(int i=0;i<nei[pos].size();i++){
		int to=nei[pos][i];
		if(to!=par){
			if(id[to]==-1){
				if(l[to]<=id[pos]-1 && id[pos]-1<=r[to]){
					id[to]=id[pos]-1;
				}else{
					id[to]=id[pos]+1;
				}
			}
			
			gen(to,pos);
		}
		
		
	}
}

int main(int argc,char* argv[]){
	
	memset(id,-1,sizeof(id));
	
	qi;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	
	cin>>k;
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		a--;
		id[a]=b;
	}
	
	dfs(0,-1);
	
//	for(int i=0;i<n;i++){
//		cout<<l[i]<<" "<<r[i]<<endl;
//	}
	gen(0,-1);
	cout<<"Yes"<<endl;
	for(int i=0;i<n;i++){
		cout<<id[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 15360
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int MAXN = 100500;

int main()
{                                                     
	ios_base::sync_with_stdio(0);
	
    string s;
    cin >> s;
    int ans = 0;
    int l = 0, r = (int)s.size() - 1;

    while (l < r)
    {
        int dl = 0;
        int dr = 0;

        while (l != r && s[l] == 'x')
        {
            l++;
            dl++;
        }
        while (l != r && s[r] == 'x')
        {
            r--;
            dr++;
        }

        if (l == r)
        {
            if (s[l] != 'x')
            {
                ans += abs(dl - dr);
            }
            break;
        }

        if (s[l] != s[r])
        {
            ans = -1;
            break;
        }
        
        ans += abs(dl - dr);
        l++;
        r--;
    }

    cout << ans << '\n';
	return 0;
}


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

namespace JOIquestion4s
{
	class _2011Q3
	{
		static void Main()
		{
			int N = int.Parse(Console.ReadLine());
			string[] buff = Console.ReadLine().Split(' ');
			int pizzaPrice = int.Parse(buff[0]);
			int toppingPrice = int.Parse(buff[1]);
			int pizzaCal = int.Parse(Console.ReadLine());
			List<int> toppingCal = Enumerable.Range(1, N).Select(x => int.Parse(Console.ReadLine())).ToList();
			toppingCal = toppingCal.OrderByDescending(x => x).ToList();

			int cal = pizzaCal;
			int price = pizzaPrice;
			int ans = 0;
			for (int i = 0; i < N; i++)
			{
				double val = (double)cal / (price);
				double val2 = (double)(cal + toppingCal[i]) / (price + toppingPrice);
				cal += toppingCal[i];
				price += toppingPrice;
				if (val > val2)
					break;
				ans = (int)val2;
			}
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 10040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int A , B , C , D;
cin >> A >> B >> C >> D ;
while ( 1 == 1) {
  C -= B;
  if ( C <= 0) {
    break;}
  A -= D;
  if ( A <= 0) {
    break;}
}
  
if ( A <= 0 ) {
  cout << "No" << endl;}
else { cout << "Yes" << endl;} 
}

Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
cnt = 0
for i in range(n):
    if a[a[i] - 1] == i + 1:
        cnt += 1
print(cnt // 2)


Measured memory_bytes: 12388
#include <iostream>

using namespace std;
int main(int argc, char const *argv[])
{
	int a,b,c;

	cin>>a>>b>>c;

	if(a<=c){
		if(c<=b){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}

	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>

int main() {
  int a, b;
  std::cin >> a >> b;
  int d = a / b;
  int r = a % b;
  double f = double(a) / double(b);
  std::cout << d << " " << r << " " << std::fixed << std::setprecision(5) << f << std::endl;
}

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

int main() {
  int n;
  cin >> n ;
  
  vector<int> vec(n);
 
  for (int i=0; i<n; i++) {
    int a;
    cin >> a;
    vec.at(i) = a - 1;
  }
  int b = 0;  
  for (int i=1; i<=n; i++) {
    b = vec.at(b);
    if ( b == 1){
      cout << i << endl;
      break;
    }
    else if ( i == n) cout << -1 << endl;
  }
 }
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 
int cnt[110];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N; cin >> N;

  vector<int> a(N);
  set<int> st;
  int mi = INT_MAX;
  REP(i,N) {
    cin >> a[i];
    cnt[a[i]]++;
    mi = min(mi, a[i]);
    st.insert(a[i]);
  }
  if(cnt[mi] == 1){
    //mi~mi*2まで存在
    bool f = true;
    for(int i=mi; i<=mi*2; i++){
      if(cnt[i] == 0) f = false;
    }
    for(int i=mi*2+1; i<=N; i++){
      if(cnt[i]) f = false;
    }
    if(f){
      cout << "Possible" << endl;
    }else{
      cout << "Impossible" << endl;
    }
  }else if(cnt[mi] == 2){
    //mi~mi*2-1まで存在
    bool f = true;
    for(int i=mi; i<=mi*2-1; i++){
      if(cnt[i] == 0) f = false;
    }
    for(int i=mi*2; i<=N; i++){
      if(cnt[i]) f = false;
    }
    if(f){
      cout << "Possible" << endl;
    }else{
      cout << "Impossible" << endl;
    }
  }else{
    cout << "Impossible" << endl;
  }


  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

ll binomial(int n, int r) {
    ll res = 1;
    for (int i = 1; i <= r; ++i) {
        res *= n - r + i;
        res /= i;
    }
    return res;
}

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

    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    for (int i = 0; i < N; ++i)
        cin >> v[i];

    sort(v.rbegin(), v.rend());
    int mcnt = 1;
    ll msum = 0, sum = 0, cnt = 0;
    for (int i = 0; i < N; ++i) {
        sum += v[i];
        if (i + 1 < A || i + 1 > B)
            continue;
        ll tmp1 = (i + 1) * msum, tmp2 = mcnt * sum;
        if (tmp1 <= tmp2) {
            auto itr1 = lower_bound(v.rbegin(), v.rend(), v[i]);
            auto itr2 = upper_bound(v.rbegin(), v.rend(), v[i]);
            int n = itr2 - itr1;
            int r = itr2 - v.rbegin() - (N - i - 1);
            if (tmp1 < tmp2)
                cnt = binomial(n, r);
            else
                cnt += binomial(n, r);
            mcnt = i + 1;
            msum = sum;
        }
    }

    printf("%.6lf\n", (double)msum / mcnt);
    printf("%lld\n", cnt);
    return 0;
}


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

int main() {
  int N,i,sum;
  cin>>N;
  int a[101];
  for(i=0;i<N;i++){
    cin>>a[i];
  }
  i=0;
  sort(a, a + N, greater<int>());
  sum=0;
  for(i=0;i<N;i++){
    if(i%2==0){
      sum=sum+a[i];
    }else{
      sum=sum-a[i];
    }
  }
  cout<<sum<<endl;
}


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

void solve()
{
	int a[3], k;
	for(auto&& i : a)
	{
		cin >> i;
	}
	cin >> k;
	sort(rbegin(a), rend(a));
	while(k--)
	{
		a[0] *= 2;
	}
	cout << accumulate(begin(a), end(a), 0) << "\n";
}

int main()
{
	solve();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace DPL3_C_Largest_Rectangle_in_a_Histogram
{
	class Program
	{
		const int Sentinel = -1;

		static void Main ( string[] args )
		{
			int count = int.Parse (Console.ReadLine ());
			List<int> input = new List<int> (Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse));
			input.Add (Sentinel);

			Stack<Rectangle> stack = new Stack<Rectangle> (count);
			long maxArea = 0;

			for (int lp = 0; lp <= count; lp++)
			{
				Rectangle rect = new Rectangle (input[lp], lp);

				//1.スタックが空の場合
				if (stack.Count == 0)
				{
					//スタックにrectを追加する
					stack.Push (rect);
				}
				//2.rectの高さがスタックのトップより高い場合
				else if (stack.Peek ().Height < rect.Height)
				{
					//スタックに追加する
					stack.Push (rect);
				}
				//3.等しい場合
				else if (stack.Peek ().Height == rect.Height)
				{
					//Nothing
				}
				//4.rectの高さがスタックのトップより低い場合
				else if (stack.Peek ().Height > rect.Height)
				{
					Rectangle previousRect = null;

					//スタックが空ではなく、スタックのトップの高さがrectの高さ未満になるまで
					do
					{
						//スタックから取り出し面積を更新する
						previousRect = stack.Pop ();
						long size = lp - previousRect.Position;
						long area = previousRect.Height * size;

						maxArea = Math.Max (maxArea, area);

					} while (stack.Count != 0 && stack.Peek ().Height >= rect.Height);

					//スタックに追加する
					//ただし、positionは最後にスタックから取り出した長方形のpositionと同じにする
					rect = new Rectangle (rect.Height, previousRect.Position);
					stack.Push (rect);
				}
			}

			Console.WriteLine (maxArea);
		}
	}

	class Rectangle
	{
		public Rectangle ( int height, int position )
		{
			this.Height = height;
			this.Position = position;
		}

		public int Height { private set; get; }
		public int Position { private set; get; }
	}
}



Measured memory_bytes: 24192
import java.util.Scanner;
import java.util.PriorityQueue;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		PriorityQueue<Integer> p=new PriorityQueue<>(Collections.reverseOrder());
		for(int i=0; i<n; i++){
			p.add(sc.nextInt());
		}
		for(int i=0; i<m; i++){
			int a=p.poll();
			p.add(a/2);
		}
		long sum=0;
		for(int i=0; i<n; i++){
			sum+=p.poll();
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 58352
// 2015/03/05 Tazoe

#include <iostream>
using namespace std;

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

	for(int i=0; i<N; i++){
		int K, P;
		cin >> K >> P;

		int w = K%P;

		if(w==0){
			cout << P << endl;
		}
		else{
			cout << w << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int A;
int dp[2007];
int answer(int R)
{
    if(R==0) return 1;
    if(dp[R]!=-1) return dp[R];
    int ways = 0;
    for(int i=3;i<=A;i++)
    {
        if(i<=R)
            ways = (ways+answer(R-i))%mod;
    }
    return dp[R]=ways;
}
int main()
{
    #ifdef TarekHasan
        freopen("input.txt","r",stdin);
    #endif // TarekHasan
    cin >> A;
    memset(dp,-1,sizeof(dp));
    cout << answer(A) << endl;
    return 0;
}


Measured memory_bytes: 3592
n, m = map(int, input().split())
ls0 = [input().rstrip() for _ in range(n)]
ls1 = [input().rstrip() for _ in range(m)]
ok = True
for i in range(n - m):
    for j in range(n - m):
        ok = True
        for k in range(m):
            for l in range(m):
                if ls0[i + k][j + l] != ls1[k][l]:
                    ok = False
                    break
            if not ok:
                break
        if ok:
            break
    if ok:
        break
if ok:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
from collections import deque
s = input()
k = int(input())
a = ord("a")
l = deque(list())
l1 = []
for i in range(len(s)):
  s1 = s[i]
  l.append(((a+26)-ord(s1))%26)
#print(l)
while k!=0:
    if len(l)!=0:
        t = l.popleft()
        if k>=t:
            l1.append("a")
            k -= t
        else:
          if t=="a":
            l1.append(t)
          else:
            l1.append(chr((ord('a')-t+26)))
    else:
      k %= 26
      l1[-1] = chr(int(ord(l1[-1])+k))
      k = 0
l2 = []
if len(l)>=1:
  for t in l:
    t %= 26
    if t==0:
      l2.append("a")
    else:
      l2.append(chr((ord('a')-t+26)))
  l1 += l2
print("".join(l1))

Measured memory_bytes: 5944
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int N,ansc=0,ans=1;
    cin >> N;
    for(int i = 1; i<=N; i++){
        if(i%2!=0) continue;
        int t = i;
        int c = 0;
        for(;;){
            if(t%2!=0) break;
            t/=2;
            c++;
        }
        if(ansc<c){
            ans=i;
            ansc=c;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-21 16:17:12
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template <class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { int flag = 0; for (auto e : vec) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { int flag = 0; for (auto e : st) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { int flag = 0; for (auto e : mp) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& e : vec) is >> e; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

inline int fast_gcd(int x, int y) {
  assert(x >= 0 && y >= 0);
  int shift;
  if (x == 0) return y;
  if (y == 0) return x;
  shift = __builtin_ctz(x || y);
  x >>= __builtin_ctz(x);
  do {
    y >>= __builtin_ctz(y);
    if (x > y) {
      int t = y;
      y = x;
      x = t;
    }
    y -= x;
  } while (y);
  return x << shift;
}

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

  int k; cin >> k;
 
  int64 ans = 0;
 
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c <= k; ++c) {
        ans += gcd(a, gcd(b, c));
      }
    }
  }
 
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	bool p,w,g,y;
	p = w = g = y = false;
	for (int i = 1;i <= n;i++)
	{
		char c;
		cin >> c;
		if (c == 'P') p = true;
		if (c == 'W') w = true;
		if (c == 'G') g = true;
		if (c == 'Y') y = true;
	}
	if (p && w && g && y)
		cout << "Four" << endl;
	else
		cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
typedef long long ll;
int n;
char s[N];
int main(){
	scanf("%s",s),n=strlen(s);
	for(int i=0;i<n-1;i++)if(s[i]=='A'&&s[i+1]=='C')return puts("Yes"),0;
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,ans=0;
    cin >> N;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    for(int i=0;i<N;i++){
        if(i%2==0){
            ans+=vec[i];
        }else{
            ans-=vec[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    anser = 1
    for a in A:
        anser *= a
        if anser > 1000000000000000000:
            print(-1)
            return

    print(anser)

main()


Measured memory_bytes: 84776
import math
N,K,Q=map(int,input().split())
A=[]
for i in range(Q):
    A.append(int(input()))
score=[]
for i in range(N):
    score.append(K)

for i in range(Q):
    score[A[i]-1]+=1

for s in score:
    if(s-Q>0):
        print("Yes")
    else:
        print("No")



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

int main(){
  
  string S; cin >> S;
  
  if(S[0] == S[1] || S[0] == S[2] || S[1] == S[2]){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  
  return 0;
  
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

bool is_prime(int n){
  if(n == 2) return true;
  if(n%2 == 0) return false;
  for(int i = 3; i*i < n; i++){
    if(n%i == 0) return false;
  }
  return true;
}

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

  for(int i = X; i < 200000; i++){
    if(is_prime(i)){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll a, b;
    cin >> a >> b;
    if (a >= 13)
        cout << b << endl;
    else if (a >= 6)
        cout << b / 2 << endl;
    else
        cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]) {

    bool all_visited = true;

    for (int i = 0; i < N; ++i) {
        if (visited[i] == false) {
            all_visited = false;
        }
    }

    if (all_visited) {
        return 1;
    }

    int ret = 0;

    for (int i = 0; i < N; ++i) {
        if (graph[v][i] == false) {
            continue;
        }
        if (visited[i]) {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

int main() {

    int N, M;
    cin >> N >> M;

    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        graph[A - 1][B - 1] = true;
        graph[B - 1][A - 1] = true;
    }

    bool visited[nmax];
    for (int i = 0; i < N; ++i) {
        visited[i] = false;
    }

    visited[0] = true;

    cout << dfs(0, N, visited) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <iomanip>
#include <utility>

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int n;
double t, b[1000], a;
vector <pair <double, int>> p;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("arithm.in", "r", stdin);
	//freopen("arithm.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> t >> a;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		double temp = t - b[i] * 0.006;
		if (temp >= 0 && a >= 0)
			p.pb(mp(abs(temp - a), i));
		if (temp >= 0 && a < 0)
			p.pb(mp(temp - a, i));
		if (temp < 0 && a >= 0)
			p.pb(mp(a - temp, i));
		if (temp < 0 && a < 0)
		{
			double x = -temp, y = -a;
			p.pb(mp(abs(x - y), i));
		}
		//p.pb(mp(abs((t - b[i] * 0.006) - a), i));
	}
	sort(p.begin(), p.end());
	cout << p[0].second + 1;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
	int H, W;
	int i, j;

	while (1)
	{
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0)
			break;
	
		for (i = 0; i < H / 2; i++)
		{	
			for (j = 0; j < W / 2; j++)
				printf("#.");
			if (W % 2 == 1)
				putchar('#');
			putchar('\n');
			
			for (j = 0; j < W / 2; j++)
				printf(".#");
			if (W % 2 == 1)
				putchar('.');
			putchar('\n');
		}
		
		if(H % 2 == 1)
			{
				for (j = 0; j < W / 2; j++)
					printf("#.");
				if (W % 2 == 1)
					putchar('#');
				putchar('\n');
			}
		
		putchar('\n');
	}	
	return 0;
} 

Measured memory_bytes: 588
# crossing point of line p0-p1 and p2-p3
def Line_Line(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y):
    retx = ((p0y-p2y)*(p0x-p1x)*(p2x-p3x) - p0x*(p2x-p3x)*(p0y-p1y) + p2x*(p2y-p3y)*(p0x-p1x)) \
        / ((p2y-p3y)*(p0x-p1x)-(p2x-p3x)*(p0y-p1y))
    if p0x != p1x:
        rety = (p0y-p1y)*(retx-p0x)/(p0x-p1x) + p0y
    else:
        rety = (p2y-p3y)*(retx-p2x)/(p2x-p3x) + p2y
    return retx, rety

# line: p0-p1
# center : (cx, cy), radius: cr
def Circle_Line(p0x, p0y, p1x, p1y, cx, cy, cr):
    tan_p = (-p1y+p0y, p1x-p0x)
    nearestx, nearesty = Line_Line(p0x, p0y, p1x, p1y, cx, cy, cx+tan_p[0], cy+tan_p[1])
    distance = ((nearestx-cx)**2+(nearesty-cy)**2)**0.5
    p_e = ((p1x-p0x)/(tan_p[0]**2+tan_p[1]**2)**0.5, (p1y-p0y)/(tan_p[0]**2+tan_p[1]**2)**0.5)
    near_to_ret = (cr**2-distance**2)**0.5
    return [
        (nearestx + near_to_ret*p_e[0], nearesty + near_to_ret*p_e[1]),
        (nearestx - near_to_ret*p_e[0], nearesty - near_to_ret*p_e[1]),        
        ]


# center : (c0x, c0y), radius: c0r
def Circle_Circle(c0x, c0y, c0r, c1x, c1y, c1r):
    d = ((c0x-c1x)**2+(c0y-c1y)**2)**0.5
    if not abs(c0r-c1r) <= d <= c0r+c1r:
        return []
    mid_p = (
        ((c0r**2-c1r**2+d**2)*c1x+(c1r**2-c0r**2+d**2)*c0x)/(2*d**2),
        ((c0r**2-c1r**2+d**2)*c1y+(c1r**2-c0r**2+d**2)*c0y)/(2*d**2)
    )
    vx = c0y - c1y
    vy = c1x - c0x
    return Circle_Line(mid_p[0], mid_p[1], mid_p[0]+vx, mid_p[1]+vy, c0x, c0y, c0r)


import sys
input = sys.stdin.readline
from math import sqrt
eps = 10**(-9)

N, K = map(int, input().split())
XYC = [list(map(int, input().split())) for _ in range(N)]

l = 0
r = 10**8
while r-l > 0.00000001:
    D = (l+r)/2
    Points = []
    for i, (x0, y0, c0) in enumerate(XYC):
        Points.append((x0, y0))
        for j, (x1, y1, c1) in enumerate(XYC):
            if i >= j: continue
            for px, py in Circle_Circle(x0, y0, D/c0, x1, y1, D/c1):
                Points.append((px, py))

    ok = False
    for px, py in Points:
        count = 0
        for x, y, c in XYC:
            if c*((x-px)**2+(y-py)**2)**0.5 <= D+eps:
                count += 1
        if count >= K:
            ok = True
            break
        
    if ok:
        r = D
    else:
        l = D

print(r)

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


typedef long long ll;

ll ub;
bitset <10000010> prime;
vector <ll> primelist ;


void sieve(ll n) {
	prime.set (); // set all bits to 1
	prime [0] = prime [1] = 0; // 0 and 1 are not primes

	for (ll i = 4; i <= n; i += 2) { // even > 2 is not prime
		prime[i] = 0;
	}

	for (ll i = 3; (i * i) <= n; i += 2) { // the odd numbers are primes?
		if (prime[i]) { // i is still marked as prime?
			for (ll j = i * i; j < n; j += i) {
				prime[j] = 0; // multiples of i are not primes
			}
		}
	}

	for (ll i = 2; i <= n; i++) { // create list of primes in [0..ub]
		if (prime[i]) {
			primelist.push_back(i);
		}
	}
}

bool isPrime( ll n )
{
	// O(1) for numbers n <= ub!
	if (n <= ub) return prime[n];

	// takes a little longer if n > ub!
	for (int i = 0; i < (int) primelist .size (); i++) {
		if (n % primelist [i] == 0) {
			return false;
		}
	}

	return true;
}

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

	ll x;
	cin >> x;

	ub = 100500;
 	sieve(ub);

 	if(isPrime(x)) cout << x << endl;
 	else 
 	{
 		ll a;
 		for (a = x; true; ++a)
 		{
 			if(isPrime(a)){
 				break;
 			}
 		}

 		cout << a << endl;
 	}

    return 0;
}

Measured memory_bytes: 4976
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int k,x;
    cin>>k>>x;
    k--;
    for(int i=x-k;i<=x+k;i++)
        cout<<i<<" ";
    cout<<endl;



}
//Alhamdulillah








Measured memory_bytes: 3576
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a>=b){
      System.out.println("delicious");
    }else if(a+x>=b){
      System.out.println("safe");
    }else{
      System.out.println("dangerous");
    }
  }
}

Measured memory_bytes: 23632
#include <iostream>
#include<math.h>
#include <limits>
#include <iomanip>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)



int main() {
	double X, Y, Z;
	double L;
	cin >> L;
	



	cout << fixed << setprecision(10);
	cout << L*L*L/27 << endl;
return 0;
} 

Measured memory_bytes: 256
# Paper
class Paper
  attr_reader :grids

  def initialize(x, y)
    @x, @y, @grids = x, y, Array.new(x) { Array.new(y, 0) }
  end

  def dye(x, y, size)
    case size
    when 1
      dense(x, y)
      dense(x, y - 1)
      dense(x + 1, y)
      dense(x, y + 1)
      dense(x - 1, y)
    when 2
      dense(x, y)
      dense(x, y - 1)
      dense(x + 1, y - 1)
      dense(x + 1, y)
      dense(x + 1, y + 1)
      dense(x, y + 1)
      dense(x - 1, y + 1)
      dense(x - 1, y)
      dense(x - 1, y - 1)
    when 3
      dense(x, y)
      dense(x, y - 1)
      dense(x + 1, y - 1)
      dense(x + 1, y)
      dense(x + 1, y + 1)
      dense(x, y + 1)
      dense(x - 1, y + 1)
      dense(x - 1, y)
      dense(x - 1, y - 1)
      dense(x, y - 2)
      dense(x + 2, y)
      dense(x, y + 2)
      dense(x - 2, y)
    end
  end

  def graph
    @grids.transpose.each do |row|
      puts row.join(' ')
    end
  end

  def dense(x, y, density = 1)
    @grids[x][y] += density if exists?(x, y)
  end

  def exists?(x, y)
    0 <= x && x <= @x - 1 && 0 <= y && y <= @y - 1
  end
end

paper = Paper.new(10, 10)

while line = gets
  x, y, size = line.chomp.split(',').map(&:to_i)
  paper.dye(x, y, size)

end

while_grids_sum = 0
paper.grids.each do |item|
  while_grids_sum += item.select { |x| x == 0 }.size
end

max_dense = 0
paper.grids.each do |item|
  max_dense = [max_dense, item.max].max
end

puts while_grids_sum
puts max_dense

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

int main() {
    string s;
    cin>>s;
    int ans=0;
    char t='A';
    for (int i = 0; i < s.size(); ++i) {
        if(s[i]<=t)++ans;
        t=s[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3208
#include<stdio.h>
 
//main
int main(){
  int i,j,n,c,t,s,e=0;
  int r[10][10]; //set
 
  //loop
  while(1){
    scanf("%d",&n); //input
    if(n==0){  //error
      break;
    }
    e++;
 
    //init
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
    r[i][j]=0;
      }
    }
    c=1;
 
    if(n==1){
      printf("Case %d:\n",e);
      printf("%3d\n",1);
    }
     
     
    //main algorhythm start
     
    else{  //n>=2
      i=-1;
      j=0;
      while(1){  //left up loop
    if(i==n-1){
      break;
    }
    i++;
    r[i][j]=c++;
    s=i;
    for(t=0;t<s;t++){
      j++;
      i--;
      r[i][j]=c++;
    }
    if(j==n-1){
      break;
    }
    j++;
    r[i][j]=c++;
    s=j;
    for(t=0;t<s;t++){
      j--;
      i++;
      r[i][j]=c++;
    }
      }
      if(i==0){  //right down prepare
    i++;
    r[i][j]=c++;
    s=n-i-1;
    for(t=0;t<s;t++){
      i++;
      j--;
      r[i][j]=c++;
    }
      }
      while(1){  //right down loop
    j++;
    r[i][j]=c++;
    if(c-1==n*n){
      break;
    }
    s=n-j-1;
    for(t=0;t<s;t++){
      i--;
      j++;
      r[i][j]=c++;
    }
    i++;
    r[i][j]=c++;
    if(c-1==n*n){
      break;
    }
    s=n-i-1;
    for(t=0;t<s;t++){
      i++;
      j--;
      r[i][j]=c++;
    }
      }
       
      //main alogorhythm end
       
       
      //output
      printf("Case %d:\n",e);
      for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%3d",r[i][j]);
    }
    printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 616
N, D, X = map(int, input().split())
INF = 10 ** 5
dp = [0] * (INF + 1)
P = [tuple(map(int, input().split())) for _ in range(D)]
for i in range(X + 1):
    dp[i] = i
ans = X
for d in range(D - 1):
    for i in range(ans + 1):
        dp[i] = i
    tmp = ans
    for i in range(N):
        for j in range(P[d][i], ans + 1):
            dp[j] = max(dp[j], dp[j - P[d][i]] + P[d + 1][i])
            tmp = max(tmp, dp[j])
    ans = tmp
print(ans)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int N; cin >> N;
VI a(N); rep(i, 0, N) cin >> a[i];

if (*max_element(ALL(a)) == 0){
    cout << "0\n";
    return 0;
}
vector<bool> b(N+1, false);
Rrep(i, N, 1){
    int f = 0;
    for (int j = 1; i*j <= N; ++j) 
        if (b[i*j]) ++f;
    if (a[i-1]) {
        if (f%2 == 0) b[i] = true;
    }
    else{
        if (f%2) b[i] = true;
    }
}
cout << accumulate(ALL(b), 0) << endl;
rep(i, 1, N+1) if (b[i]) cout << i << ' ';
cout << endl;
}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{


string s;
cin >> s;
int pa = -1 ,c = 0 ;
for(int i=0; i<s.size(); i++)
{
    if(pa==-1 && s[i]=='A')
        pa = i;
    if(s[i]=='Z')c = i;
}

cout << c - pa + 1 << endl;



}


Measured memory_bytes: 3732
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

const long long MOD = 1000000007;


template <typename T> class Factorial {
  public:
    vector<T> fact;
    vector<T> factinv;
    Factorial(int N);
    static T bipow(T c, T n);
    static T square(T n);
    T conv(T n, T m) const;
    T perm(T n, T m) const;
};

template <typename T> Factorial<T>::Factorial(int N) : fact(N+1), factinv(N+1) {
  fact[0] = 1;
  for (int i = 1; i < N+1; i++) {
    fact[i] = fact[i-1]*static_cast<T>(i)%MOD;
  }
  factinv[N] = bipow(fact[N], MOD-2);
  for (int i = N; i > 0; i--) {
    factinv[i-1] = factinv[i]*static_cast<T>(i)%MOD;
  }
}

template <typename T> T Factorial<T>::bipow(T c, T n) {
  if (n == 0) {
    return 1;
  } else if(n == 1) {
    return c;
  } else if(n%2 == 0) {
    return square(bipow(c, n/2))%MOD;
  } else {
    return (static_cast<T>(c)*square(bipow(c, (n-1)/2)))%MOD;
  }
}

template <typename T> T Factorial<T>::square(T n) {
  return static_cast<long long>(n)*n%MOD;
}

template <typename T> T Factorial<T>::conv(T n, T m) const {
  if (n < m) {
    return 0;
  }
  return (((static_cast<long long>(fact[n])*factinv[m])%MOD)*factinv[n-m])%MOD;
}

template <typename T> T Factorial<T>::perm(T n, T m) const {
    if (n < m) {
      return 0;
    }
    return (static_cast<long long>(fact[n])*factinv[n-m])%MOD;
  }

void solve(long long N, std::vector<long long> x){
  vector<long long> v(N-1);
  vector<long long> s(N-1);
  Factorial<long long> f(static_cast<int>(N)+1);
  for (int i = 0; i < N-1; ++i) {
    s[i] = x[i+1] - x[i];
  }
  v[0] = 1LL;
  long long t, k;
  long long ret = 0LL;
  k = f.fact[N-1];
  for (long long i = 0; i < N - 2; ++i) {
    ret += (((v[i] * k % MOD ) * s[i] ) % MOD);
    ret %= MOD;

    v[i+1] = (v[i] * (i+2)) % MOD;
    v[i+1] += f.fact[i+1];
    v[i+1] %= MOD;
    // std::cout << v[i] << std::endl;
    // std::cout << k << std::endl;
    k *= f.factinv[i+2];
    k %= MOD;
    k *= f.fact[i+1];
    k %= MOD;
  }
  // std::cout << v[N-2] << std::endl;
  // std::cout << k << std::endl;
  ret += (((v[N-2] % MOD ) * s[N-2] ) % MOD);
  ret %= MOD;
  std::cout << ret << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> x(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&x[i]);
  }
  solve(N, std::move(x));
  return 0;
}


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

int main(){
    string s;
    cin>>s;
    sort(begin(s),end(s));
  int N;
  if(s.find("p")==string::npos){
    N=0;
  }else{
    N=s.size()-s.find("p");
  }
   int ans=s.size()/2;
   cout<<ans-N<<endl;
}

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

using namespace std;

#define int long long

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

#ifdef DBG
#define log(item) cout<<#item<<" "<<item<<endl
#else
#define log(item)
#endif

typedef vector<int> VI;
typedef pair<int, int> PII;

//-------------------

int N;
int a, b, c;

int calc(string str){
    int ans = 0;
    REP(i, str.size()){
        if(i == 0) continue;
        if(str[i] == 'B' && str[i - 1] == 'A'){
            ans++;
        }
    }
    return ans;
}

signed main(){
    cin >> N;

    int ans = 0;

    REP(i, N){
        string str;
        cin >> str;
        bool b_ = str[0] == 'B' ? 1 : 0;
        bool a_ = str[str.size() - 1] == 'A' ? 1 : 0;
        if(a_ && b_){
            c++;
        }
        else if(a_){
            a++;
        }
        else if(b_)
        {
            b++;
        }
        ans += calc(str);
    }
    log(ans);
    log(a);
    log(b);
    log(c);

    ans += c == 0 ? 0 : c - 1;

    if(c != 0 && a > 0){
        a--;
        ans += 1;
    }
    if(c != 0 && b > 0){
        b--;
        ans += 1;
    }

    ans += min(a, b);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a;
    string ans;
    cin>>a;
    if(a==3||a==5||a==7)ans="YES";
    else ans="NO";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] rec = new int[26];
        for(int i=0;i<s.length();i++){
            rec[s.charAt(i)-'a']++;
        }
        String ans = "Yes";
        for(int i=0;i<26;i++){
            if(rec[i]%2==1) ans = "No";
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
vector<ll> A,B,C;
ll dp[100005][2][2][2],n;
ll solve(int i, int a, int b, int c)
{
    if(i==n) return 0;
    ll &ans = dp[i][a][b][c];
    if(~ans) return ans;
    if(a) ans = max(ans, A[i]+solve(i+1, 0, 1, 1));
    if(b) ans = max(ans, B[i]+solve(i+1, 1, 0, 1));
    if(c) ans = max(ans, C[i]+solve(i+1, 1, 1, 0));
    return ans;

}

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

    ll x,y,z,k;
    cin>>n;
    k=n;
    while(k--)
    {
        cin>>x>>y>>z;
        A.push_back(x);
        B.push_back(y);
        C.push_back(z);
    }
    A.push_back(0);
    B.push_back(0);
    C.push_back(0);
    memset(dp, -1, sizeof dp);
    cout<<solve(0, 1, 1, 1)<<endl;
} 


Measured memory_bytes: 16864
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  int a = 0,b = 0;
  REP(i,n){
    if(s[i] == '1') a++;
    else b++;
  }

  int ans;
  if(a == 0 || b == 0) ans = 0;
  else ans = 2*min(a,b);
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3736
N = int(input())
AAA = sorted([int(i) for i in input().split()])
BBB = sorted([int(i) for i in input().split()])
CCC = sorted([int(i) for i in input().split()])

def upper_bound(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right = mid

def lower_bound(T,SSS):#スライスの値を返す。同じ値があったら左寄りに出す
    left = 0 #SSS[left]はTと同じかそれより小さい
    right = len(SSS)-1 #SSS[right]はTより真に大きい

    if T<=SSS[left]:
        return 0
    if T>SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<T:
            left = mid
        else:
            right = mid

ans=0
lenCCC = len(CCC)
for B in BBB:
    nA = lower_bound(B,AAA)
    nC = lenCCC-upper_bound(B,CCC)
    ans+=nA*nC
print(ans)

Measured memory_bytes: 24180
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string w;
    cin>>w;
    map<char,int>mp;
    int n=w.size();
    bool ok=true;
    for(int i='a'; i<='z'; ++i){
        int cnt=0;
        rep(j,n){
            if(w[j]==i)cnt++;
        }
        if(cnt%2==1)ok=false;
    }
    cout<<(ok==true?"Yes":"No")<<endl;
}


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

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll a,b;cin>>a>>b;
    ll d = gcd(a,b);
    ll res = 1;
    if(d%2==0){
    	res++;
    	while(d%2 == 0) d/=2;
    }
	for(ll i = 3; i <= sqrt(d); i+=2){
		if(d%i == 0) res++;
		while(d%i == 0){
			d/=i;
		}
	}

	if(d>1) res++;

	cout<<res;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

typedef long long ll;
#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

int main(){
	int H, W;
	cin >> H >> W;

	string S[50];
	for(int i = 0; i < H; ++i){
		cin >> S[i];
	}

	int dir[9][2] = {
		{-1, -1}, {-1, 0}, {-1, 1},
		{ 0, -1}, { 0, 0}, { 0, 1},
		{ 1, -1}, { 1, 0}, { 1, 1},
	};

	for(int i = 0; i < H; ++i){
		string ans = "";
		for(int j = 0; j < W; ++j){
			int count = 0;
			if(S[i][j] == '.'){
				for(int k = 0; k < 9; ++k){
					if((i + dir[k][0]) >= 0 && (i + dir[k][0]) < H && (j + dir[k][1]) >= 0 && (j + dir[k][1]) < W){
						if(S[i + dir[k][0]][j + dir[k][1]] == '#'){
							count++;
						}
					}
				}
				ans += to_string(count);
			} else {
				ans += '#';
			}
		}
		S[i] = ans;
	}

	for(int i = 0; i < H; ++i){
		cout << S[i] << endl;
	}
}


Measured memory_bytes: 512