akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
constexpr ll mod = 1000000007;

ll N, M;
ll a[100010];
ll dp[100010];

int main()
{
  scanf( "%lld%lld", &N, &M );
  rep( i, M )
    scanf( "%lld", a+i );

  int p = 0, q = 0;

  if( a[0] == 1 )
    ++q;

  dp[0] = 1;

  rep( i, N )
  {
    if( i+1 <= N && a[p] != i+1 )
      dp[i+1] = (dp[i+1]+dp[i]) % mod;
    if( a[p] == i+1 )
      ++p;
    
    if( i+2 <= N && a[q] != i+2 )
      dp[i+2] = (dp[i+2]+dp[i]) % mod;
    if( a[q] == i+2 )
      ++q;
  }

  printf( "%lld\n", dp[N] );

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n , k ; cin>>n>>k;
    int a = n - (k - 1) - 1;
    if(k == 1)a = 0;
    cout<<a<<endl;

}

Measured memory_bytes: 256
import java.util.*;
class Main{

    public static void main(String args[]){
	int w,n;
	int[][] Edge;
	int[] Ans;
	Scanner in = new Scanner(System.in);
	String[] s;

	w = in.nextInt();
	n = in.nextInt();
	Edge = new int[w+1][2];
	Ans = new int[w+1];
	for(int i=0;i<n;i++){
	    s = in.next().split(",");
	    Edge[i][0] = Integer.valueOf(s[0]).intValue();
	    Edge[i][1] = Integer.valueOf(s[1]).intValue();	   
	}
    
	int here;
	for(int i=1;i<=w;i++){
	    here = i;
	    for(int j=0;j<w;j++){
		if(Edge[j][0] == here)here = Edge[j][1];
		else if(Edge[j][1] == here)here = Edge[j][0];
	    }
	    Ans[here-1] = i;
	}

	for(int i=0;i<w;i++)System.out.println(Ans[i]);

    }



}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int z = 0,o = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '0') z++;
        else o++;
    }    
    cout << min(o,z)*2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int prime_check(int num)
{
	int i;
	if(num < 2) return 0;
	if(num == 2) return 1;
	if(!(num%2)) return 0;

	for(i=3;i*i<=num;i+=2){
		if(!(num%i)) return 0;
	}
	return 1;
}

int main(){
	int N;
	long long int input_number;
	int i;
	int number_of_prime = 0;

	scanf("%d",&N);

	for(i=1;i<=N;i++){
		scanf("%ld",&input_number);
		if(prime_check(input_number) == 1){
			number_of_prime++;
		}
	}
	printf("%d\n",number_of_prime);

	return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
a = int(input())
c = [int(input()) for i in range(a)]

import fractions
#最小公倍数を順次求めていく
def lcm(x,y):
    return x*y//fractions.gcd(x,y)
ret = 1
for i in c:
    ret = lcm(ret,i)
print(ret)

Measured memory_bytes: 5556
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
#define MOD 1000000007
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    rep(i,0,n)cin>>l[i];
    ll ans=0;
    sort(l.begin(),l.end());
    rep(i,0,n-2){
        rep(j,i+1,n-1){
            int sum=l[i]+l[j];
            rep(k,j+1,n)if(sum>l[k])ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,sum[200001],f[200001],cnt,q[200001];
void solve(ll x,ll y){
	if(!x)return;
	ll now=upper_bound(q+1,q+cnt+1,x)-q-1;
	if(!now)sum[1]+=y,sum[x+1]-=y;
	 else{
	 	f[now]+=x/q[now]*y;
	 	solve(x%q[now],y);
	 }
}
int main(){
	ll i,t;
	scanf("%lld%lld",&n,&m);
	cnt=1;q[1]=n;
	for(i=1;i<=m;i++){
		scanf("%lld",&t);
		while(cnt&&t<=q[cnt])cnt--;
		q[++cnt]=t;
	}
	f[cnt]=1;
	for(i=cnt;i>1;i--)f[i-1]+=q[i]/q[i-1]*f[i],solve(q[i]%q[i-1],f[i]);
	sum[1]+=f[1];sum[q[1]+1]-=f[1];
	for(i=1;i<=n;i++)printf("%lld\n",sum[i]+=sum[i-1]);
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;

    int S = 0, M = 0;
    for(int i=0;i<N;i++){
        int p;
        cin >> p;
        S += p;
        M = max(M,p);
    }
    int ans = S-M /2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define P pair<int, int>
#define chmin(x, y) x = min(x, y)

int main()
{
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if ((v - w) * t - abs(a - b) >= 0)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e3 + 44;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

string s[N];

long long dp[N][N];

int main () {
	boost;
	int n, m;
	cin >> n >> m;
	for (int i = 0 ; i < n ; ++ i)
		cin >> s[i];
	dp[0][0] = (s[0][0] == '.');
	for (int i = 0 ; i < n ; ++ i) {
		for (int j = 0 ; j < m ; ++ j) {
			if (!i && !j) continue;
			if (s[i][j] == '#') continue;
			else if (!i) dp[i][j] = dp[i][j - 1];
			else if (!j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[n - 1][m - 1];
}

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

using namespace std;

int main(void) {
	int N,K;
	cin >> N >> K;
	vector<int> tree(N);
	for (int i = 0; i < N; ++i) {
		cin >> tree[i];
	}
	sort(tree.begin(),tree.end());
	int res = (1 << 30);
	for (int i = 0; i < N-K+1; ++i) {
		res = min(tree[N-i-1]-tree[N-K-i],res);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
n = int(input())
ints = [int(num) for num in list(input().split())]
res = []
for x in range(min(ints), max(ints)+1):
    total = 0
    for num in ints:
        total += (x - num)**2
    
    res.append(total)

ans = min(res)
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int cnt_digits(ll X){
	int cnt=0;
	while(X>0){
		X/=10;
		cnt++;
	}
	return cnt;
}

int main() {
	ll N;
	cin>>N;
	int ans=cnt_digits(N);
	for (ll A = 1; A*A <= N; ++A){
		if(N%A==0){
			ll B=N/A;
			int C=max(cnt_digits(A),cnt_digits(B));
			ans=min(ans,C);
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;


long f(long x, const vector<long> &a){
  long c = 0;
  for(auto& i:a){
    c += x % i;
  }
  return c;
}

int main(){
  int n;
  cin >> n;
  vector<long> a(n);
  long mul = 0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    mul += a[i]-1;
  }
  cout << mul << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 13;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* struct for mod Calculation*/
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    int L = S.size();

    // dp[i桁目][(sum(i桁目まで)%13]
    vector<vector<ll> > dp(L + 1, vector<ll>(mod));
    dp[0][0] = 1;

    for (int i = 0; i < L; i++) {
        mint pow10 = 10;
        ll n = L - 1 - i;
        pow10 = pow10.pow(n);
        for (int j = 0; j < mod; j++) {
            for (int k = 0; k <= 9; k++) {
                // S[i] == '?' -> 0 ~ 9
                // S[i] == x -> only x
                if (S[i] != '?' && (S[i] - '0') != k) continue;
                // a === b mod p, c === d mod p => ac === bd mod p
                mint r = (mint)k * pow10;
                // Dpの遷移
                dp[i+1][(j+r.x) % mod] += dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[L][5] % MOD << '\n';
}

Measured memory_bytes: 13568
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    M,D = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    count=0
    for m in range(1,M+1):
        for d in range(1,D+1):
            if d%10>=2 and d//10>=2 and m==(d%10)*(d//10):
                count+=1
    print(count)




if __name__ == "__main__":
    main()

Measured memory_bytes: 39408
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
const int maxn = 2e5 + 10;
int h[maxn];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h, h + n);
  reverse(h, h + n);
  ll res = 0;
  for (int i = k; i < n; i++) {
    res += h[i];
  }
  cout << res << endl;
  return 0;

}


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

void prime();
bool num[10001];

int main(){
	int m, count;
	prime();
	while(cin >> m){
		count = 0;
		for(int i = 1; i <= m; i++){
			if(num[i] && num[m - i + 1]){
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

void prime(){
	for(int i = 0; i < 10001; i++){
		num[i] = true;
    	}
    	num[0] = false;
    	num[1] = false;
	for(int i = 2; i <= 100; i++){
        	for(int j = i*2; j <= 10001; j += i){
            		if(!num[j]){
                		continue;
            		}
            		num[j] = false;
        	}
    	}
}

Measured memory_bytes: 1168
alist=[int(i) for i in input().split()]
alist.sort()
a=alist[0]
b=alist[1]
c=alist[2]
if (c-a) %2 !=0 and (c-b)%2 !=0:
	print((c-a) //2+(c-b) //2+1)
elif (c-a) %2 !=0 or (c-b)%2 !=0:
	print((c-a) //2+(c-b) //2+2)
else:
	print((c-a) //2+(c-b) //2)

Measured memory_bytes: 3064
n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
ans=10**18
for i in range(1<<n):
  rikai=[0]*m
  money=0
  for j in range(n):
    if i&(1<<j):
      money+=a[j][0]
      for k in range(1,m+1):
        rikai[k-1]+=a[j][k]
  ok=True
  for r in rikai:
    if r<x:
      ok=False
      break
  if ok:
    ans=min(money,ans)

if ans==10**18:
  print(-1)
else:
  print(ans)



Measured memory_bytes: 9152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long X){
  ull i=0,cur=100ULL;
  while(cur<X){
    cur=cur+cur/100ULL;
    ++i;
  }
  cout<<i<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int A, B;
    io.read(A, B);
    int ans = 0;
    if(A > B) {
        ans += A;
        A--;
    }
    else {
        ans += B;
        B--;
    }
    if(A > B) {
        ans += A;
        A--;
    }
    else {
        ans += B;
        B--;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n,m = gets.split(" ").map(&:to_i)
a = []
b = []
n.times do
  a<<gets.split(" ").map(&:to_i)[0,m]
end
m.times do
  b<<gets.to_i
end
n.times do |i|
  puts [a[i],b].transpose.map{|t| t.inject(:*)}.inject(:+)
end

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

#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>
#include <iomanip>

//usings
using namespace std;

#define PI 3.14159265358979323846264338327950288419716939937510

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    void solve(int lh, int lm, int h, int m) {
        long double hd = (h + m / 60.0) * 30, md = m * 6.0;
        long double angle = md + 360.0 - hd;
        while(angle > 360) angle -= 360;
        if(angle > 180) angle = 360.0 - angle;
        //cout << "show angle: " angle << endl;
        double radian = angle * M_PI / 180.0000;
        double ans = sqrt(pow(lh, 2.0) + pow(lm, 2.0) - 2.0 * lh * lm * cos(radian));
        cout << fixed << setprecision(15) << ans <<endl;
    }
};

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    Solution sol;
	sol.solve(a, b, h, m);
}

Measured memory_bytes: 4232
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <random>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, a;
int main() {
  cin >> n >> a;
  auto ans = n%500<=a ? "Yes" : "No";
  cout << ans << '\n';
  return 0;
}


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

int main()
{
    int i,cnt=0,n;
    string s;
    cin>>n>>s;
    for(i=2; i<n; i++)
    {
        if(s[i-2]=='A' && s[i-1]=='B' && s[i]=='C')
            cnt++;
    }
    cout<<cnt<<"\n";
    return 0;
}


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

int main(){
	int N, K;
	bool f = false;
	
	cin >> N >> K;
	if(N % 2 == 0 && K <= N / 2) f = true;
	if(N % 2 == 1 && K <= N / 2 + 1) f = true;
	if(f) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

# define FILE
using namespace std;

const int N = 1e5 + 100;

int n, a[N];

int main()
{
    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif // FILE
    ios_base::sync_with_stdio( false );
    cin >> n;
    for( int i = 1; i <= n; i ++ ){
        cin >> a[i];
    }
    for( int i = 2; i <= n; i ++ ){
        if( a[i] == a[i-1]-1 ) a[i]++;
    }
    bool t= false;
    for( int i = 2; i <= n; i ++ ){
        if( a[i] < a[i-1] ) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
bool visited[200001];
int value[200001];
int main(){
	long long N,K;
  cin >> N >> K;
  for(int i = 1; i <= N; i++){
    cin >> value[i];
  }
  int curr = 1;
  int counter1 = 0;
  while(1==1){
    if(visited[curr]){
      break;
    }
    visited[curr] = true;
    curr = value[curr];
    counter1++;
  }
  int starter;
  starter = curr;
  curr = 1;
  int counter2 = 0;
  while(curr != starter){
    counter2++;
    curr = value[curr];
  }
  
  if(K <= counter2){
    curr = 1;
    for(int i = 0; i < K; i++){
      curr = value[curr];
    }
  }else{
    curr = starter;
    for(int i = 0; i < (K-counter2)%(counter1-counter2); i++){
      curr = value[curr];
    }
  }
  cout << curr;
}

Measured memory_bytes: 4532
lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
W = array[1..N+1]

if W.uniq.length != N
  puts 'No'
else
  ans = true
  W.each_cons(2) do |phrase|
    ans = false if phrase.first.split("").last != phrase.last.split("").first
  end

  if ans
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
#define fst first
#define snd second

int dist(string a, string b) {
  int ans = 0;
  for (int i = 0; i < (int) b.size(); i++) {
    if (a[i] != b[i]) ans++;
  }
  return ans;
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  string s, t; cin >> s >> t;
  int ans = t.size();
  for (int i = 0; i <= s.size() - t.size(); i++) {
    ans = min(ans, dist(t, s.substr(i, t.size())));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3608
/*
 *  B - Buffet
 * author: roy4801
 * (C++)
 */
#include <bits/stdc++.h>

using namespace std;

#define PROB "B"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PPB pop_back
#define PF push_front
#define PPF pop_front
#define N 20
int n;
int a[N+5], b[N+5], c[N+5];
int pre, ans;
int main()
{
	#ifdef DBG
	freopen("./testdata/" PROB TESTC ".in", "r", stdin);
	freopen("./testdata/" PROB ".out", "w", stdout);
	#endif
	while(cin >> n)
	{
		pre = ans = 0;
		for(int i = 1; i <= n && cin >> a[i]; i++);
		for(int i = 1; i <= n && cin >> b[i]; i++);
		for(int i = 1; i <= n-1 && cin >> c[i]; i++);

		for(int i = 1; i <= n; i++)
		{
			if(pre+1 == a[i])
				ans += c[pre];
			ans += b[a[i]];
			pre = a[i];
		}
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n, m, x = map(int, input().split())
    al = list(map(int, input().split()))

    left = 0
    right = 0
    for i in al:
        if i < x:
            left += 1
        elif x < i:
            right += 1

    print(min(left, right))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int N,K;
    cin>>N>>K;
    int ans=0;
    vector<int>X(N);
    rep(i,N){
        cin>>X[i];
        ans+=min(X[i],K-X[i])*2;
    }
    cout<<ans<<endl;
}


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


int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF){
    if(a+b==15)printf("+\n");
    else if(a*b==15)printf("*\n");
    else printf("x\n");}
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
L = [[i] + list(map(int, input().split())) for i in range(m)]

L = sorted(L, key = lambda x: x[2])
L = sorted(L, key = lambda x: x[1])

ans = [0] * m
temp = 1

for i in range(len(L)):
    kami = str(L[i][1]).rjust(6, "0")
    shimo = str(temp).rjust(6, "0")
    ans[L[i][0]] = kami+shimo

    if i < (m-1) and L[i][1] != L[i+1][1]:
        temp = 1
    else:
        temp += 1

for a in ans:
    print(a)

Measured memory_bytes: 31760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string a;
  cin >> a;

  map<char, ll> ma;
  for (auto&& i : a) {
    ma[i]++;
  }

  ll ans = 1;
  for (char i = 'a'; i <= 'z'; i++) {
    for (char j = i+1; j <= 'z'; j++) {
      ans += ma[i] * ma[j];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define fio     ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define pi      3.14159265
#define ll      long long
#define repe    ll tc,cas=0;cin>>tc;while(tc--)
#define op      freopen("output.txt", "w", stdout);

#define maxn 10000010
using namespace std;

int main()
{
    fio;
    char s;
    cin>>s;

    if(s=='A')
        cout<<'T'<<endl;
    else if(s=='T')
        cout<<'A'<<endl;
    else if(s=='G')
        cout<<'C'<<endl;
    else if(s=='C')
        cout<<'G'<<endl;


    return 0;
}


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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

#define dodebug(i, n, arr)	for(int i=0;i<n;++i)	cout<<arr[i]<<" ("<<i<<")\n";

ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

	int n, cap;
	cin>>n>>cap;

	vector<ll> dp(cap+1, 0);//the maximum value we can get with atmost i weight is dp[i]

	int w;
	ll v;
	for(int i=0;i<n;++i){
		cin>>w>>v;
		for(int i=cap;i-w>=0;--i)	dp[i] = max(dp[i], dp[i-w] + v);
	}
	
	ll ans = 0;
	// for(int i=0;i<=cap;++i)		ans = max(ans, dp[i]);
	// for(auto i:dp)	cout<<i<<" ";
	// cout<<'\n';

	cout<<dp[cap]<<'\n';

	return 0;
}

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

//Water Pipe Construction
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int s = sc.nextInt();
			int g1 = sc.nextInt();
			int g2 = sc.nextInt();
			if(n==0)break;
			int[][] cost = new int[n+1][n+1];
			for(int[]c:cost)Arrays.fill(c, Integer.MAX_VALUE);
			while(m--!=0){
				int a = sc.nextInt();
				int b = sc.nextInt();
				cost[a][b]=sc.nextInt();
			}
			int[][] wf = new int[n+1][n+1];
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					wf[i][j] = cost[i][j];
			for(int i=1;i<=n;i++)wf[i][i]=0;
			for(int k=1;k<=n;k++){
				for(int i=1;i<=n;i++){
					for(int j=1;j<=n;j++){
						if(wf[i][k]!=Integer.MAX_VALUE && wf[k][j]!=Integer.MAX_VALUE)
							wf[i][j] = Math.min(wf[i][j], wf[i][k]+wf[k][j]);
					}
				}
			}
			int min = Integer.MAX_VALUE;
			for(int k=1;k<=n;k++){
				if(wf[s][k]!=Integer.MAX_VALUE && wf[k][g1]!=Integer.MAX_VALUE && wf[k][g2]!=Integer.MAX_VALUE){
					min = Math.min(min, wf[s][k]+wf[k][g1]+wf[k][g2]);
				}
			}
			System.out.println(min);
		}
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> P;
const double EPS = 1e-9;
int main(){
	int N;
	cin >> N;
	while(N--){
		P a,b,c,d;
		cin >> a.real() >> a.imag() >> b.real() >> b.imag() >> c.real() >> c.imag() >> d.real() >> d.imag();
		P one = b-a;
		P two = d-c;
		cout << (one.imag()/one.real() == two.imag()/two.real()?"YES":"NO") << endl;	
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define M (((long long)1e9)+7)
int main() {
    // your code goes here
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("res.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
   	int ct=0,n;
   	cin>>n;
   	bool a=false;
   	for(int i=0;i<n;i++)
   	{
   		int x,y;
   		cin>>x>>y;
   		if(x==y)	ct++;
   		else	ct=0;
   		if(ct==3)	a=true;
   	}
   	cout<<(a?"Yes":"No");
   	return 0;
}

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

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

	vector<int> c(26+1);
	for (int i=1;i<=26;++i)
	{
		cin >> c[i];
	}

	vector<vector<int>> s(d+1,vector<int>(26+1));
	for (int i=1;i<=d;++i)
	{
		for (int j=1;j<=26;++j)
		{
			cin >> s[i][j];
		}
	}
	vector<int> t(d+1);
	for (int i=1;i<=d;++i)
	{
		cin >> t[i];
	}

	int m;
	cin >> m;
	vector<pair<int,int>> q(m);

	for (int i=0;i<m;++i)
	{
		int dd,qq;
		cin >> dd >> qq;
		q[i]=make_pair(dd,qq);
	}

	vector<int> last(26+1);
	vector<set<int>> hh(26+1);
	for (int i=1;i<=26;++i)
	{
		last[i]=0;
		hh[i].insert(0);
		hh[i].insert(d+1);
	}


	int64_t score=0;
	for (int i=1;i<=d;++i)
	{
		score+=s[i][t[i]];
		last[t[i]]=i;
		hh[t[i]].insert(i);
		for (int j=1;j<=26;++j)
		{
			score-=c[j]*(i-last[j]);
		}
		//cout << score << endl;
	}

	for (int i=0;i<m;++i)
	{
		int dd=q[i].first;
		int qq=q[i].second;

		score-=s[dd][t[dd]];
		score+=s[dd][qq];
		auto it=hh[t[dd]].find(dd);
		auto prev=it;
		--prev;
		auto next=it;
		++next;
		score-=(dd-*prev)*(*next-dd)*c[t[dd]];

		hh[t[dd]].erase(dd);
		t[dd]=qq;

		hh[qq].insert(dd);
		it=hh[qq].find(dd);
		prev=it;
		--prev;
		next=it;
		++next;
		score+=(dd-*prev)*(*next-dd)*c[qq];

		cout << score << endl;
	}


}






Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n, m, a;
    cin >> n >> m;
    vector<ll> b(n+100, 0);
    rep1(i, m){
        cin >> a;
        b[a]++;
    }
    vector<ll> dp(n+100, 0);
    dp[0] = 1;
    rep1(i, n){
        rep2(j, 1, 3){
            if (b[i+j]) continue;
            dp[i+j] += dp[i];
            dp[i+j] %= MOD;
        }
    }
    cout << dp[n] << endl;
    return 0;
    //printf("%.12f", ans);
}

Measured memory_bytes: 4808
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

template <typename T>
void chmin(T& x, T y) {
    x = min(x, y);
}

template <typename T>
void chmax(T& x, T y) {
    x = max(x, y);
}

ll csum(ll x, ll y) {
    if (x > 0 && y > 0 && x > LL_MAX - y) {
        return LL_MAX;
    }
    if (x < 0 && y < 0 && x < LL_MIN - y) {
        return LL_MIN;
    }
    return x + y;
}

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

struct Basis {
	ll bit;
	ull vec;
};

ull residue(ull vec, vector<Basis>& basis) {
	for (Basis& b : basis) {
		if (vec & ((ull)1 << b.bit)) {
			vec ^= b.vec;
		}
	}
	return vec;
}

int main() {
	ll T;
	cin >> T;
	rep(t,0,T) {
		ll N;
		cin >> N;
		vector<ull> A(N);
		rep(i,0,N) {
			cin >> A[i];
		}
		string S;
		cin >> S;
		vector<Basis> basis;
		bool solved = false;
		rrep(i,N,0) {
			if (S[i] == '0') {
				ull res = residue(A[i], basis);
				if (res) {
					ll bit = 0;
					while ((res & ((ull)1 << bit)) == 0) {
						bit++;
					}
					basis.push_back(Basis{bit, res});
				}
			} else {
				if (residue(A[i], basis) != 0) {
					cout << 1 << endl;
					solved = true;
					break;
				}
			}
		}
		if (solved) {
			continue;
		}
		cout << 0 << endl;
	}
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  int ans = 0;
  int memo = 1;
  for (int i = 0; i < N - 1; i++) {
    for (int j = memo; j < N; j++) {
      ans += (d.at(i) * d.at(j));
    }
    memo++;
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  for (int i = 1; i < N; i++) {
    int a;
    cin >> a;
    A[a - 1]++;
  }

  for (int i = 0; i < A.size(); i++) cout << A[i] << endl;

  return 0;
}

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

class Main {

    void solve(){

	Scanner sc = new Scanner( System.in );
	int c = 0, n = sc.nextInt();

	while ( n > 1 ) {
	    n >>= 1;
	    ++c;
	}

	System.out.println( 1<<c );
    }

    public static void main( String[] a ) { new Main().solve(); }
}



Measured memory_bytes: 26288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num[90];
int main(){
	num[0]=2;
	num[1]=1;
	for(int i=2;i<=86;i++){
		num[i]=num[i-1]+num[i-2];
	}
	int n;
	while(cin>>n){
		cout<<num[n]<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    
    string s;
    cin >> s;
    if (s.size() == 2)  
        cout << s << endl;
    else    for (int i = s.size()-1; i >= 0; --i)   cout << s[i];
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


ll MOD = 1000000007;


int main() {
	int N, W;
	cin >> N >> W;
	vector<int> v(N);
	vector<int> w(N);
	rep(i, N) {
		cin >> v[i] >> w[i];
	}
	vector<vector<int>> dp(N+1);
	rep(i, N+1) {
		dp[i].resize(W + 1);
		rep(j, W + 1) dp[i][j] = 0;
	}
	repi(i, 1, N + 1) {
		rep(j, W + 1) {
			if (j - w[i - 1] < 0) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]), dp[i][j - w[i - 1]] + v[i - 1]);
		}
	}
	int res = 0;
	rep(i, W + 1) res = max(res, dp[N][i]);
	cout << res << endl;
	return 0;
}



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

int main(){

    int N;
    string S;
    cin>>N>>S;
    vector<int> T(N);
    for(int i=1;i<N;i++){
        if(S.at(i)=='E') T.at(0)++;
    }
    for(int i=1;i<N;i++){
        T.at(i)=T.at(i-1);
        if(S.at(i-1)=='W') T.at(i)++;
        if(S.at(i)=='E') T.at(i)--;
    }
    sort(T.begin(),T.end());
    cout<<T.at(0)<<endl;
}
    


Measured memory_bytes: 1796
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main () {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i).first;
    a.at(i).second = i;
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n; i += 2) {
    ans += (abs(a.at(i).second - i)) % 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

int main() {
	int a, l;
	while(cin >> a >> l, a|l) {
		vector<int> line; // array of a
		set<int> chk; // for search

		//add a0
		line.push_back(a);
		chk.insert(a);

		FOR(j, 1, 21) {
			vector<int> v;
			int n = line[j-1];
			REP(i, l) {
				v.push_back(n % 10);
				n /= 10;
			}

			//min
			sort(v.begin(), v.end());
			int mi = 0;
			REP(i, l) {
				mi += v[i]; 
				if(i != l-1) mi *= 10;
			}

			//max
			reverse(v.begin(), v.end());
			int ma = 0;
			REP(i, l) {
				ma += v[i];
				if(i != l-1) ma *= 10;
			}

			//find
			if(chk.count(ma - mi)) {
				int p;
				REP(i, line.size())
					if(line[i] == ma - mi) p = i;
				cout << p << ' ' << ma - mi << ' ' << j - p << endl; 
				break;
			}
			else {
				line.push_back(ma - mi);
				chk.insert(ma - mi);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  std::string s,t;
  std::cin>>s>>t;

  ll ans=0;

  rep(i,0,3)if(s[i]==t[i])ans++;

  std::cout<<ans;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
using namespace std;
int beishu(int cifang , int shu)
{
    long long int sum = 1;
    for (int i = 1;i <= cifang;i++)
        sum *= shu;
    return sum;
}
int weishu(int x)
{
    int num=0;
    while(x)
    {
        num++;
        x/=10;
    }
    return num;
}
int main()
{
    int a,b;
    cin>>a>>b;
    long long int s;
    s=a*beishu(weishu(b),10);
    s+=b;
    int g=sqrt(s);
    if (g*g==s)
        cout<<"Yes\n"; 
    else
        cout<<"No\n"; 
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  
  long int a,b,c,d;
  scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
  
  long int n[4];
  int i,j;
  long int t;
  
  n[0]=a*c;
  n[1]=a*d;
  n[2]=b*c;
  n[3]=b*d;
  
  for(i=0;i<4;i++){
    for(j=i;j<4;j++){
      if(n[j]<n[i]){
        t=n[i];
        n[i]=n[j];
        n[j]=t;
      }
    }
  }
  
  printf("%ld\n",n[3]);
  
  return 0;
  
}

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

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

int main() {
	int n, q; cin >> n >> q;
	vector<int64_t> a(n); for(int i = 0; i < n; ++i) cin >> a[i];
	SegmentTree<int64_t> seg(n, 0, [](int64_t lhs, int64_t rhs){return lhs + rhs;});
	SegmentTree<int64_t> seg_part(n, 0, [](int64_t lhs, int64_t rhs){return lhs + rhs;});
	for(int i = 0; i < n; ++i) {
		seg.replace(i, a[i]);
		if(n % 2 == 0) {
			if(i % 2 == 1) seg_part.replace(i, a[i]);
		} else {
			if(i % 2 == 0) seg_part.replace(i, a[i]);
		}
	}
	while(q--) {
		int x; cin >> x;
		int ok = n - 1, ng = 0;
		while(abs(ok - ng) > 1) {
			int y = (ok + ng) / 2;
			int Ay = a[y];
			int ta = n - y;
			int ao = upper_bound(a.begin(), a.end(), Ay) - lower_bound(a.begin(), a.end(), x - abs(x - Ay));
			if(ta <= ao) {
				ok = y;
			} else {
				ng = y;
			}
		}
		cout << seg.get(ok, n) + seg_part.get(0, max(0, 2 * ok - n)) << '\n';
	}
	return 0;
}

Measured memory_bytes: 6656
s=int(input())
if s<=2:
    print(0)
    exit()
ans=0
mod=10**9+7
f=[1,1]
for i in range(2,s+5):
    f.append(f[-1]*i%mod)

def inv(x):
    return pow(x,mod-2,mod)

def h(n,m):
    return f[n+m-1]*inv(f[n])*inv(f[m-1])

for i in range(1,s//3+5):
    s2=s-i*3
    if s2<0:
        break
    ans+=h(s2,i)%mod
print(ans%mod)

Measured memory_bytes: 9136
#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <functional>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)

using namespace std;

char buf[1024];

int main() {
  int k, s;

  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d %d", &k, &s);

  auto sum = k + s;
  auto diff = k - s;
  auto kakeru = k * s;

  auto max = 0;

  if (sum > diff) {
    max = sum;
  } else {
    max = diff;
  }

  if (max > kakeru) {
  } else {
    max = kakeru;
  }

  cout << max << endl;
}



Measured memory_bytes: 256
n = int(input())
spot = [0] + list(map(int, input().split())) + [0]
mlst = []
plst = []
dissum = 0
for i in range(1, n + 1):
  mlst.append(abs(spot[i + 1] - spot[i]) + abs(spot[i] - spot[i - 1]))
  plst.append(abs(spot[i + 1] - spot[i - 1]))
  dissum += abs(spot[i] - spot[i - 1])
dissum += abs(spot[n])
for i in range(n):
  print(dissum - mlst[i] + plst[i])

Measured memory_bytes: 21656
import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False

def ddprint(x):
  if DBG:
    print(x)

BIG = 999999


# # # # main start

n,m = inm()
fff = 2**n - 1
dp = [BIG] * (2**n)
a = []
s = []
for i in range(m):
  aa,bb = inm()
  c = inl()
  ss = 0
  c = [x-1 for x in c]
  for cc in c:
    ss |= (1<<cc)
  a.append(aa)
  s.append(ss)

dp = [BIG] * (2**n)
dp[0] = 0

for i in range(m):
  aa = a[i]
  ss = s[i]
  for j in range(2**n):
    dp[j|ss] = min(dp[j|ss], dp[j]+aa)

v = dp[2**n-1]
print(-1 if v>=BIG else v)


Measured memory_bytes: 49624
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define MAX 100000
using namespace std;

int curtime = 0, isVisited[MAX] = {}, prenum[MAX], lowest[MAX], ctop[MAX];
vector<int> cton[MAX];

void dfs(int curnode);

int main() {
	int i, j, v, e, s, t;
	cin >> v >> e;
	for (i = 0; i < e; i++) {
		cin >> s >> t;
		cton[s].push_back(t);
		cton[t].push_back(s);
	}

	dfs(0);

	int cnt = 0;
	for (i = 1; i < v; i++) {
		if (ctop[i] == 0)cnt++;
	}
	if (cnt > 1)cout << 0 << endl;

	int toOut[MAX] = {};
	for (i = 1; i < v; i++) {
		if (ctop[i] == 0)continue;
		if (prenum[ctop[i]] <= lowest[i])toOut[ctop[i]] = 1;
	}

	for (i = 1; i < v; i++) {
		if (toOut[i] == 1)cout << i << endl;
	}

	return 0;
}

void dfs(int curnode) {
	isVisited[curnode] = 1;
	prenum[curnode] = ++curtime;
	lowest[curnode] = prenum[curnode];
	for (vector<int>::iterator itv = cton[curnode].begin(); itv != cton[curnode].end(); itv++) {
		if (isVisited[*itv] == 0) {
			ctop[*itv] = curnode;
			dfs(*itv);
			lowest[curnode] = min(lowest[curnode], lowest[*itv]);
		} else if (*itv != ctop[curnode]) {
			lowest[curnode] = min(lowest[curnode], prenum[*itv]);
		}
	}
}

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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> vec(n);
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  
  int s = 0;
  int count = 1;
    
  for(int i = 0; i < n; i++){
    s+= vec.at(i);
    if(s <= x){
      count++;
    }
    else{
      break;
    }
  }
  cout << count;
}

Measured memory_bytes: 256
import math
import copy
import sys

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

# a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
# inputList = []
# inputNumList = []
# for i in range(a):
#     inputNum = input()
#     inputNumList = list(inputNum)
#     inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

a = str(inputa[0])
inputList = list(a)

flg = True

if inputList[0] != "A":
    flg = False

cntC = 0
for i in range(2, len(inputList)-1, 1):
    if inputList[i] == "C":
        cntC += 1

if cntC != 1:
    flg = False

for i in range(len(inputList)):
    if inputList[i] != "A" and inputList[i] != "C":
        if inputList[i].islower() == False:
            flg = False

if flg:
    print("AC")
else:
    print("WA")





Measured memory_bytes: 3444
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 100006;

i64 n;
i64 a[MAXN];


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    i64 c = 0;

    for (i64 i = 2; i < MAXN; i++) {
        if (a[i]) {
            continue;
        }
        if (!a[i] && i >= n) {
            cerr << c << endl;
            cout << i << endl;
            return 0;
        }

        i64 j = 2;
        while (j * i < MAXN) {
            c += 1;
            a[j * i] = 1;
            j += 1;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
import sys
import math

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	a, b , h, m = tin()
	#s = input()
	pi=3.14159265358979633
	tan = ((30 * h + 0.5*m)*2*pi)/360
	tyou = (6 * m*2*pi)/360
	tan_x = math.cos(tan)*a
	tan_y = math.sin(tan)*a
	tyou_x = math.cos(tyou)*b
	tyou_y = math.sin(tyou)*b
	r2 = (tan_x-tyou_x)**2
	r2 += (tan_y - tyou_y)**2
	ret = r2**0.5
	print(ret)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62904