akhauriyash/Code-Regression huggingface dataset:
n, m, k = gets.split.map(&:to_i)
res = []
n.succ.times { |i|
  p = i * m
  m.succ.times { |j|
    q = n * j
    res << p + q - 2 * (i * j)
  }
}
puts res.include?(k) ? :Yes : :No

Measured memory_bytes: 11644
#include <iostream>
using namespace std;
int main(void){
    int n,ans=0,co=0;
    int a[101];
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
        if(a[i-1]==a[i]){
            co++;
            if(co%2==1)ans++;
        }
        else co=0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math

def main():
    for i in range(N):
        for j in range(i,N):
            if S[i][j]!=S[j][i]:
                return(0)
    return(1)

N=int(input())
S=[list(input()) for i in range(N)]
count=0


for i in range(N):
    if main():
        count+=N
    for m in range(N):
        a=S[m].pop()
        S[m].insert(0,a)
print(count)


Measured memory_bytes: 45164
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N,M,K;
int c[1<<17];
vector<pair<int,pair<int,int> > >Es;
main()
{
	cin>>N>>M>>K;
	for(int i=0;i<N;i++)cin>>c[i];
	for(int i=0;i<M;i++)
	{
		int a,b,w;cin>>a>>b>>w;
		a--,b--;
		Es.push_back(make_pair(w,make_pair(a,b)));
	}
	sort(Es.begin(),Es.end());
	long ans=0;
	UF uf(N+K);
	int ec=0;
	for(pair<int,pair<int,int> >e:Es)
	{
		int a=e.second.first,b=e.second.second;
		if(c[a]==0)a=K+a;
		else a=c[a]-1;
		if(c[b]==0)b=K+b;
		else b=c[b]-1;
		if(ec<K-1&&uf.unite(a,b))
		{
			ec++;
			ans+=e.first;
		}
	}
	cout<<(ec<K-1?-1L:ans)<<endl;
}


Measured memory_bytes: 3444
from operator import itemgetter
import collections
r,c,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
e1=[];e2=[];e3=[];e4=[]
for i in range(n):
  if (l[i][0]==0 or l[i][0]==r or l[i][1]==0 or l[i][1]==c) and (l[i][2]==0 or l[i][2]==r or l[i][3]==0 or l[i][3]==c):
    if l[i][0]==0 and l[i][1]!=c:
      e1.append([i+1,l[i][0],l[i][1]])
    elif l[i][1]==c and l[i][0]!=r:
      e2.append([i+1,l[i][0],l[i][1]])
    elif l[i][0]==r and l[i][1]!=0:
      e3.append([i+1,l[i][0],l[i][1]])
    else:
      e4.append([i+1,l[i][0],l[i][1]])
    if l[i][2]==0 and l[i][3]!=c:
      e1.append([i+1,l[i][2],l[i][3]])
    elif l[i][3]==c and l[i][2]!=r:
      e2.append([i+1,l[i][2],l[i][3]])
    elif l[i][2]==r and l[i][3]!=0:
      e3.append([i+1,l[i][2],l[i][3]])
    else:
      e4.append([i+1,l[i][2],l[i][3]])
e1=sorted(e1,key=itemgetter(2))
e2=sorted(e2,key=itemgetter(1))
e3=sorted(e3,key=itemgetter(2))
e4=sorted(e4,key=itemgetter(1))
e3.reverse()
e4.reverse()
e=e1+e2+e3+e4

q=[]
q=collections.deque(q)
for i in range(len(e)):
  if len(q)==0:
    q.append(e[i][0])
  else:
    if q[-1]==e[i][0]:
      q.pop()
    else:
      q.append(e[i][0])
if len(q)==0:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 107096
#ABC83, B - some sums

n, a, b = [int(el) for el in input().split(' ')]

total = 0
for i in range(1, n+1):
    some_sum =  sum([int(s) for s in list(str(i))])
    if a <= some_sum <= b:
        total += i
print(total)


Measured memory_bytes: 3064
#include <iostream>

int main() {
  int k;
  std::string s;
  std::cin >> k >> s;
  if (s.size() <= k) {
    std::cout << s << std::endl;
    return 0;
  }
  std::string t = s.substr(0, k);
  std::cout << t << "..." << std::endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=1e5+5;
const int mod=1e9+7;
const ll oo=1e18+5;
 
// dp[step][i] is the number of ways with length is step and the end node is i 
// if(!dp[step-1][i]) -> dp[step][i]=0
// else dp[step][i]+=dp[step-1][i]
// opt

// dp[i] is the number of ways with the end node is i
ll n,k;

void add_self(int& a,int b){
	a+=b;
	if(a>=mod) a-=mod;
}

int mul(int a,int b){
	return 1ll*a*b%mod;
}

struct matrix{
	vector<vector<int>> mat; 
	matrix(){
		mat.resize(n,vector<int>(n));
	}
	matrix operator*(const matrix& b) const {
		matrix c;
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				for(int k=0;k<n;++k){
					add_self(c.mat[i][j],mul(this->mat[i][k],b.mat[k][j]));    
				}
			}
		}
		return c;
	}
};
		

void show_matrix(matrix a){
	for(int i=0;i<10;++i) cout<<"-";cout<<endl;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cout<<a.mat[i][j]<<" ";
		}
		cout<<endl;
	}
	for(int i=0;i<10;++i) cout<<"-";cout<<endl;	
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	cin>>n>>k;
	vector<vector<int>> a(n,vector<int>(n));
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cin>>a[i][j];
		}
	}
	
	matrix init;
	// init matrix 
	for(int i=0;i<n;++i){
		init.mat[i][i]=1;
	}
	
	// show_matrix(init);
	
	// pow 
	
	matrix ans;
	ans.mat=a;
	
	// show_matrix(ans);
	
	while(k){
		if(k%2){
			init=init*ans;
		}
		ans=ans*ans;
		// cout<<"in solve"<<endl;
		// show_matrix(ans);
		k/=2;
	}
	
	// show_matrix(ans);
	
	int tot=0;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			add_self(tot,init.mat[i][j]);
		}
	}
	cout<<tot;
	return 0;
}


Measured memory_bytes: 256
n = int(input())

chk = 0
pts = []
for i in range(n):
    x, y = map(int, input().split())
    if i == 0:
        chk = (x+y) % 2
    elif chk != (x+y) % 2:
        print(-1)
        exit()
    pts.append((x, y))

if chk:
    m = 35
    d = [2**i for i in range(35)]
else:
    m = 36
    d = [1] + [2**i for i in range(35)]

ans = []

for i in range(n):
    x, y = pts[i]
    pos = ['']*36
    u, v = x+y, x-y
    for j in range(35, -1, -1):
        if j == 35 and chk:
            continue
        if u >= 0 and v >= 0:
            u -= d[j]
            v -= d[j]
            pos[j] = 'R'
        elif u < 0 and v >= 0:
            u += d[j]
            v -= d[j]
            pos[j] = 'D'
        elif u <= 0 and v < 0:
            u += d[j]
            v += d[j]
            pos[j] = 'L'
        elif u > 0 and v < 0:
            u -= d[j]
            v += d[j]
            pos[j] = 'U'
    ans.append(''.join(pos))

print(m)
print(*d)

for x in ans:
    print(x)


Measured memory_bytes: 45040
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define INF 3000000000000001
#define ll_max 9000000000000000001
#define mod 1000000007
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 100001;
const ll M = 1;

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m = 0, x = 0, y = 0, k, W, H;
        cin >> n >> m;
        for(int i = 0; i < m; i++)
        {
            cin >> y;
            x += y;
        }
        if(n <= x)
        cout << "Yes" << "\n";
        else cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;

int color[12][12];
int ourx, enemyx;

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

	ll n;
	cin >> n;
	vi v(n);
	rep(i, n) cin >> v[i];
	/*if (n == 2) {
		cout << max(v[0], v[1]) << " " << min(v[0], v[1]) << endl;
		return 0;
	}*/
	sort(all(v));
	ll ans = M,ansx=0,ansy=0;
	double x = v[v.size() - 1] * 1.000 / 2;
	rep(i, n-1) {
		if (abs(x - v[i]) < ans) {
			ansy = i;
			ans = abs(x - v[i]);
		}
	}
	cout << v[v.size() - 1] << " " << v[ansy] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; ll start = 0;
//***********//
int main() {
	cin >> N;
	string S;
	cin >> S;
	vl R, G;
	vl B(N);
	ll sum = 0;
	for (i = 0; i < N; i++) {
		if (S[i] == 'R') {
			R.push_back(i);
		}
		else if (S[i] == 'G') {
			G.push_back(i);
		}
		else {
			B[i] = 1;
			sum++;
		}
	}
	for (i = 0; i < R.size(); i++) {
		for (j = 0; j < G.size(); j++) {
			ll pre = sum;
			ll P = max(R[i], G[j]);
			ll Q = min(R[i], G[j]);
			ll D = P - Q;
			if (Q - D >= 0) {
				if (B[Q - D])pre--;
			}
			if (P + D < N) {
				if (B[P+D])pre--;
			}
			if (D % 2 == 0) {
				if (B[Q + D / 2])pre--;
			}
			ans += pre;
		}
	}
	cout << ans;
}


Measured memory_bytes: 3716
s = input()
if s[0] == "A" and s[2:-1].count("C") == 1:
    for i in range(len(s)):
        if s[i] != "A" and s[i] != "C":
            if s[i] != s[i].lower():
                print("WA")
                exit()
    print("AC")
else:
    print("WA")


Measured memory_bytes: 2940
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
    
Q=[0]*N
for i in range(M):
    if H[A[i][0]-1]>=H[A[i][1]-1]:
        Q[A[i][1]-1]=-10**5
    if H[A[i][0]-1]<=H[A[i][1]-1]:
        Q[A[i][0]-1]=-10**5
n = sum(x>=0 for x in Q)
print(n)

Measured memory_bytes: 32016
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)

class Point{
public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x+p.x,y+p.y); }
  Point operator - (Point p) { return Point(x-p.x,y-p.y); }
  Point operator * (double a) { return Point(a*x,a*y); }
  Point operator / (double a) { return Point(a/x,a/y); }
  
  double abs() { return sqrt(norm()); }
  double norm() { return x*x+y*y; }
  
  bool operator < (const Point &p) const {
    return y != p.y ? y < p.y : x < p.x;
  }

  bool operator == (const Point &p) const {
    return fabs(y-p.y) < EPS && fabs(x-p.x) < EPS;
  }

};

typedef Point Vector;

double dot(Vector a,Vector b){
  return a.x * b.x + a.y * b.y;
}

double cross(Vector a,Vector b){
  return a.x * b.y - a.y * b.x;
}

bool ccw(Point p0,Point p1,Point p2){
  Vector a = p1-p0;
  Vector b = p2-p0;
  if( cross(a,b) > EPS) return true;
  return false;

}

typedef vector<Point> Polygon;

Polygon totsu(Polygon s){
  
  Polygon u,l;
  if(s.size() < 3) return s;
  sort(s.begin(),s.end());

  u.push_back(s[0]);
  u.push_back(s[1]);
  for(int i=2;i<s.size();i++){
    for(int j=u.size();j>=2 && ccw(u[j-2],u[j-1],s[i]);j--){
      u.pop_back();
    }
    u.push_back(s[i]);
  }
  
  l.push_back(s[s.size()-1]);
  l.push_back(s[s.size()-2]);
  for(int i=s.size()-3;i>=0;i--){
    for(int j=l.size();j>=2 && ccw(l[j-2],l[j-1],s[i]);j--){
      l.pop_back();
    }
    l.push_back(s[i]);
  }
  
  reverse(l.begin(),l.end());
  for(int i=u.size()-2;i>=1;i--) l.push_back(u[i]);
  
  return l;
}

int main(){
  
  int n;
  double x,y;
  Polygon s,v;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%lf %lf",&x,&y);
    s.push_back(Point(x,y));
  }

  v = totsu(s);
  printf("%d\n",v.size());
  for(int i=0;i<v.size();i++) printf("%.0lf %.0lf\n",v[i].x,v[i].y);

  return(0);
}



Measured memory_bytes: 10096
n = int(input())
x = list(map(int,input().split()))
mod = 10 ** 9 + 7
ans = 0
m = 1
for _ in range(60):
    bit = sum(a & m for a in x) #フラグが立ってる桁を合計
    bit //= m #1の個数を数えるためにmで割る
    non_bit = n - bit #0の個数を出す
    ans = (ans + bit * non_bit * m) % mod #桁の合計出す
    m <<= 1 #桁を1増やす
print(ans)




Measured memory_bytes: 42156
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
void dfs(int k, ll distance, vector<vector<pair<int,ll>>> &root, vector<ll> &allDistance){
  allDistance[k] = distance;
  for(auto a : root[k]){
    if(allDistance[a.first] == -1){
      allDistance[a.first] = distance + a.second;
      dfs(a.first, distance + a.second, root, allDistance);
    }
  }
}
int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, ll>>> root(n);
  rep(i, n - 1){
    int a,b,c; // 0 ~
    cin >> a >> b >> c;
    a--; b--;
    root[a].push_back(make_pair(b, c));
    root[b].push_back(make_pair(a, c));
  }
  int q,k;
  cin >> q >> k;
  k--;
  vector<ll> allDistance(n, -1);
  allDistance[k] = 0;
  dfs(k, 0, root, allDistance);
  rep(i, q){
    int x,y;
    cin >> x >> y;
    x--; y--;
    ll ans = 0;
    ans += allDistance[x];
    ans += allDistance[y];
    cout << ans << endl;
  }
}

Measured memory_bytes: 14336
#include <stdio.h>
#define N 100

int main(){
  int i,j,mini,A[N],t,n,cnt=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  for(i=0;i<n;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(A[j]<A[mini]){
	mini=j;
      }
    }
    t=A[i];A[i]=A[mini];A[mini]=t;
    if(i!=mini) cnt++;
  }

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2144
S = input()
T = input()
if len(S)<len(T):
    print("UNRESTORABLE")
else:
    lenS =len(S)
    lenT = len(T)
    for i in range(lenS-lenT+1):
        if S[lenS-1-i] == "?" or S[lenS-1-i] == T[lenT-1]:
            for j in range(lenT):
                if S[lenS-1-i-j] != T[lenT-1-j] and S[lenS-1-i-j] != "?":
                    flag = 0
                    break
                flag = 1
            if flag == 1:
                for j in range(lenT):
                    S = S[:(lenS-1-i-j)]+T[lenT-1-j]+S[(lenS-i-j):]
                    #S[lenS-1-i-j] = T[lenT-1-j]
                for k in range(lenS):
                    if S[k] == "?":
                        print("a",end="")
                    else:
                        print(S[k],end="")
                print("")
                break
    else:
        print("UNRESTORABLE")

Measured memory_bytes: 9076
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && a!=c)
    {
       cout<<"Yes"<<endl; 
    }
    else if( a==c && a!=b)
    {
        cout<<"Yes"<<endl;
    }
    else if(b==c && b!=a)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << "\n"
#define pr2(a,b)cout << a <<  " " <<b<< "\n"
#define pr3(a,b,c) cout << a <<" " << b << " " << c << "\n"

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
const int maxn = 2*1e5 + 10;


void solve(){

    int a,b,n;
    cin >> a >> b >> n;

    int mn = min(n, b-1);
    cout << (int)((mn*a)/b) - a*(int)(mn/b) <<endl;

} 

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1e18;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    long long ans = -INF, mn = A[0];
    for (int i = 1; i < N; i++) {
        long long pro = A[i] - mn;
        chmax(ans, pro);
        chmin(mn, A[i]);
    }
    cout << ans << endl;
    return 0;
}


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


int main() {

    int n;
    cin >> n;
    int mx = 0;
    for (int i = 1; i <= n; ++i) {
        int num = i;
        int cnt = 0;
        while (num % 2 == 0) {
            ++cnt;
            num /= 2;
        }
        mx = max(cnt, mx);
    }
    int ans = 1;
    rep(i,mx) {
        ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n; cin>>n;
    vector<int> h(n),dp(100005,1e9);
    rep(i,n) cin>>h[i];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2;i<n;i++){
        chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    
    ll cnt1=0,cnt2=0,cnt3=0;
    
    cnt1 = min(a,k);
    k-=cnt1;
    
    if(k>0)
        cnt2 = min(b,k);
    k-=cnt2;
    
    if(k>0)
        cnt3 = min(k,c);

    cout<<cnt1-cnt3<<"\n";
  
}
    // Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main(){
    int a,b;
    cin >> a;
    if(a>=30){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 3624
import numpy as np

n = int(input())
P = np.array(list(map(int, input().split())))
T = np.zeros(n)
T[0] = P[0]
for i in np.arange(1,n,1):
    T[i] = min(T[i-1], P[i])
print(np.sum(P==T))

Measured memory_bytes: 34156
# N = int(input())

import numpy as np

N,M = list(map(int, input().split()))
paths = []
connection_dic = {}

for i in range(N):
    connection_dic[i+1] = set()

for i in range(M):
    A,B = list(map(int, input().split()))
    connection_dic[A].add(B)
    connection_dic[B].add(A)

# print(connection_dic)

ans_list = np.zeros(N-1, dtype = np.int)

current_distance = 0

parents = set([1])
next_parents = set()

while len(parents) > 0:
    # print()
    # print(parents)
    
    current_distance += 1
    while len(parents) > 0:
        parent = parents.pop()
        for node in connection_dic[parent]:
            if node >= 2 and ans_list[node-2] == 0:
                ans_list[node-2] = parent
                next_parents.add(node)
    parents = next_parents
    next_parents = set()
    # print(ans_list)

for ans in ans_list:
    if ans == 0:
        print("No")
        exit()

print("Yes")
for ans in ans_list:
    print(int(ans))
    

    


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

int main(){
    int A, B, C, D, sum1 = 0, sum2 = 0;
    cin >> A >> B >> C >> D;

    sum1 = A * B;
    sum2 = C * D;

    if(sum1 < sum2){
        cout << sum2 << endl;
    }
    else {
        cout << sum1 << endl;
    }

}

Measured memory_bytes: 256
#!usr/bin/python3

x = int(input()) 

A = [2, 4, 5, 7, 9]
B = [0, 1, 6, 8]
C = [3]

c = int(x%10)

if c in A:
    print('hon')
if c in B:
    print("pon")
if c in C:
    print("bon")
    


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin>>n;
  cout<<(n-2)*180<<endl;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int x; 
int main(){
	cin>>x;
	if(x<600)
	{
		cout<<8;
		return 0;
	}
	if(x<800)
	{
		cout<<7;
		return 0;
	}
	if(x<1000)
	{
		cout<<6;
		return 0;
	}
	if(x<1200)
	{ 
		cout<<5;
		return 0;
	}
	if(x<1400)
	{
		cout<<4;
		return 0;
	}
	if(x<1600)
	{
		cout<<3;
		return 0;
	}
	if(x<1800)
	{
		cout<<2;
		return 0;
	}
	if(x<2000)
	{
		cout<<1;
		return 0;
	}
	return 0;
}

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

int main()
{
    int n,a,b,t1,t2;
    cin>>n>>a>>b;
    t1=n*a;
    t2=b;
    if(t1<=t2)
        cout<<t1<<endl;
    else if(t1>=t2)
        cout<<t2<<endl;








    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

const int limit = 50;
int a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];
int n,m;

void dfs(int v){
  visited[v] = true;
  rep(v2,n){
    if(graph[v][v2] == false) continue;
    if(visited[v2] == true) continue;
    dfs(v2); 
  }
}

int main(){
  cin >> n >> m;
  int ans = 0;
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; 
  }

  rep(i,m){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    rep(j,n) visited[j] = false;
    dfs(0);
    bool judge = false;
    rep(j,n){
      if(visited[j] == false) judge = true;
    }
    if(judge) ans++;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define REP(i,a,b) for(int i=a; i<b; i++)

const int MX=1e5+3;

int n, k, arr[MX], ans=1e9+8;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	REP(i,0,n) cin>>arr[i];
	sort(arr, arr+n);
	for(int i=0; i<n-k+1; i++) ans=min(ans, arr[i+k-1]-arr[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n, d;
    cin >> n >>d;

    ll ans = 0;

    vector<ll>x(n, 0);
    vector<ll>y(n, 0);
    REP(i, n) {
        cin >> x[i] >> y[i];
        if (sqrt((x[i]*x[i])+(y[i]*y[i])) <= d) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 6488
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;

int main(){
    ll x;cin>>x;
    ll m=100;
    int count=0;
    while(true){
        m+=m/100;
        count++;
        if(m>=x) break;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int[] num = new int[2];
			num[0]=sc.nextInt();
			num[1]=sc.nextInt();
			
			int cd0;
			int cd = 1;
			
			do{
				cd0 = 1;
				for(int j = 2; j<= getMin(num[0], num[1]); j++){
					if(num[0]%j == 0 && num[1]%j == 0){
						cd0 = j;
						cd = cd * j;
						num[0]=num[0]/j;
						num[1]=num[1]/j;
						break;
					}
				}
			}while(cd0 != 1);
			
			System.out.print(cd + " ");
			System.out.println(cd * num[0] * num[1]);
		}
	}
	
	private static int getMin(int a, int b){
		if (a>b){
			return a;
		}else{
			return b;
		}
	}
}

Measured memory_bytes: 12000
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val x = readLong()
    var ans = 0L
    var cur = 100L
    while (cur < x) {
        cur += cur / 100
        ans++
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 34628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

class UF{
private:
	vector<int> par,rank,elm;
	vector<vector<int>> elmList;	//don't be validated
public:
	int groups;
	
	UF(int __size):par(__size) , rank(__size,0) , elm(__size,1) , groups(__size), elmList(__size){
		rep(i,__size)elmList[i] = vector<int>(1,i);
		for(int i=0;i<__size;i++)par[i]=i;
	}
	
	int getElements(int n){ return elm[find(n)]; }
	vector<int> getElementsList(int n){ return elmList[find(n)]; }
	
	int find(int x){
		if(par[x]==x) {
			return x;
		}else{
			return par[x]=find(par[x]);
		}
	}
	
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		
		groups--;
		if(rank[x]<rank[y]){
			par[x]=y;
			elm[y]+=elm[x];
			for(auto &e:elmList[x])elmList[y].pb(e);
			
		}else{
			par[y]=x;
			elm[x]+=elm[y];
			for(auto &e:elmList[y])elmList[x].pb(e);
			if(rank[x]==rank[y])rank[x]++;
		}
	}
	
	bool isSame(int x,int y){
		return find(x)==find(y);
	}
};


int main(){
	int n,k,l;
	cin>>n>>k>>l;
	
	UF a(n),b(n);
	
	rep(i,k){
		int p,q;
		cin>>p>>q;
		p--,q--;
		a.unite(p,q);
	}

	rep(i,l){
		int p,q;
		cin>>p>>q;
		p--,q--;
		b.unite(p,q);
	}
	
	map<pii,int> mp;
	
	rep(i,n)mp[pii(a.find(i),b.find(i))]++;
	
	rep(i,n){
		if(i)cout<<" ";
		pii p = pii(a.find(i),b.find(i));
		cout<<mp[p];
	}
	cout<<endl;
}

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

long long N;
long long A[105];
int main(){
	cin >> N;
	double tmp = 0;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
		tmp += 1/(double)A[i];
	}
	printf("%.10f\n", 1/tmp);
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		if (i * 108 / 100 == N) {
			printf("%d", i);
			return 0;
		}
	}
	printf(":(");
	return 0;
}

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

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<long> as(n);
	for (long& a : as) cin >> a;
	vector<long> dp(2);
	dp[0] = as[0] + as[1];
	dp[1] = -dp[0];
	for (int i = 0; i < n-2; i++)
	{
		vector<long> nx(2);
		nx[0] = max(dp[0]+as[i+2], dp[1]+as[i+2]);
		nx[1] = max(dp[1]+2*as[i+1]-as[i+2], dp[0]-2*as[i+1]-as[i+2]);
		swap(dp, nx);
	}
	cout << max(dp[0], dp[1]) << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1024
N,M = map(int,input().split())
likes = [0 for _ in range(M)]
for _ in range(N):
  for food in list(map(int,input().split()))[1:]:
    likes[food-1] += 1
ans = 0
for like in likes:
  if like == N:
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXS = 20 * 1000 + 10;
const int MAXN = 1000 + 10;
int meilleur[MAXN][MAXS];
struct objet
{
	int poids , valeur , s;
	bool operator < (const objet & autre) const
	{
		return s + poids < autre.s + autre.poids;
	}
};
int32_t main()
{
	for (int i = 0 ; i < MAXN ; i++){
		for (int j = 0 ; j < MAXS ; j++)
		{
			meilleur[i][j] = -1e18;
		}
	}
	meilleur[0][0] = 0;
	int N;
	cin >> N;
	objet objets[N];
	for (int i = 0 ; i < N ; i++)
	{
		cin >> objets[i].poids >> objets[i].s >> objets[i].valeur;
	}
	sort(objets , objets + N);
	for (int i = 0 ; i < N ; i++)
	{
		for (int j = 0 ; j < MAXS ; j++)
		{
			meilleur[i + 1][j] = meilleur[i][j];
			if (j >= objets[i].poids && j - objets[i].poids <= objets[i].s)
			{
				meilleur[i + 1][j] = max(meilleur[i + 1][j] , meilleur[i][j - objets[i].poids] + objets[i].valeur);
			}
		}
	}
	int maxi = 0;
	for (int i = 0 ; i < MAXS ; i++)
	{
		maxi = max(maxi , meilleur[N][i]);
	}
	cout<<maxi<<endl;
}

Measured memory_bytes: 158208
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
	cin>>a>>b;
	if(a>0 && b>0 || (abs(a)-abs(b))%2==1)
		cout<<"Positive"<<endl;
	if(a<0 && b>0)
		cout<<"Zero"<<endl;
	if(a<0 && b<0 && (abs(a)-abs(b))%2==0)
		cout<<"Negative"<<endl;
  	return 0;
}

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

using namespace std;

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

    vector<pair<int, int>> a(n, make_pair(0, 0));
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }

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

    for (int i = 0; i < n; i++) {
        cout << (i == 0 ? "" : " ") << a[i].second;
    }
    cout << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#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 rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;

int x[10][10];

int main(){
  int l, r;
  cin>>l>>r;
  if(r-l>=2018)cout<<0<<endl;
  else{
    int la=l%2019;
    int ra=r%2019;
    if(la>=ra) cout<<0<<endl;
    else{
      int ans=2019;
      for(int i=la; i<=ra; i++)for(int j=la; j<=ra; j++)if(i<j){
        ans=min(ans, (i*j)%2019);
      }
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;
typedef gp_hash_table<int,null_type> hash_map;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 105

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

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

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,K,res;
bool bad[MAXN][MAXN];

int main(){
    scanf("%d %d",&len,&K);
    if(K > (len-1)*(len-2)/2) return 0*printf("-1\n");
    int rem = (len-1)*(len-2)/2;
    res = len-1;
    for(int i=2; i<len; i++){
        for(int k=i+1; k<=len; k++){
            if(rem == K) break;
            bad[i][k] = bad[k][i] = true;
            res++;
            rem--;
        }
    }
    printf("%d\n",res);
    for(int i=2; i<=len; i++)
        printf("1 %d\n",i);
    for(int i=2; i<len; i++)
        for(int k=i+1; k<=len; k++)
            if(bad[i][k])
                printf("%d %d\n",i,k);
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main {
  public static void main (String[] args) throws java.lang.Exception {
	Scanner sc = new Scanner(System.in);
	String s = sc.nextLine();
	String[] weather = {"Sunny", "Cloudy", "Rainy"};
	if (s.equals("Sunny")) System.out.println("Cloudy");
	else if (s.equals("Cloudy")) System.out.println("Rainy");
	else System.out.println("Sunny");
  }
}

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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll ans = 0;
    while(n){
        ans++;
        n/=2;
    }
    cout << ans <<endl;
    
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//----------------ここからだよ-------------------

int main(){
    int N; cin>>N;
    vector<ll> dp(N+1,INF);

    dp[0]=0;

    for(int i=0;i<N;i++){
        ll y=6;
        ll z=9;
        chmin(dp[i+1],dp[i]+1);
        while(i+y<=N){
            chmin(dp[i+y],dp[i]+1);
            y*=6;
        }
        while(i+z<=N){
            chmin(dp[i+z],dp[i]+1);
            z*=9;
        }
    }

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

Measured memory_bytes: 1024
from bisect import bisect_right
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
time=0
A_ruiseki=[0]
B_ruiseki=[0]
for i in range(N):
    A_ruiseki.append(A_ruiseki[-1]+A[i])
for j in B:
    B_ruiseki.append(B_ruiseki[-1]+j)
B_ruiseki.pop(0)
for i in range(N+1):
    time=A_ruiseki[i]
    if A_ruiseki[i]<=K:
        count=max(count,bisect_right(B_ruiseki,K-A_ruiseki[i])+i)
        #print(bisect_right(B_ruiseki,K-A_ruiseki[i]),i)
print(count)
#print(A_ruiseki,B_ruiseki)

Measured memory_bytes: 47512
n = int(input())
s = input()

need_left = 0
pointer = 0

for i in range(n):
    if s[i] == "(":
        pointer += 1
    else:
        if pointer == 0:
            need_left += 1
        else:
            pointer -= 1

res = ""
for i in range(need_left):
    res += "("
res += s

for i in range(pointer):
    res += ")"

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

//部分文字列の個数を検索
int find(string s,string keyword){
  int count = 0;
  string::size_type pos = s.find(keyword);
  while(pos != string::npos){
    count++;
    pos = s.find(keyword,pos+keyword.length());
  }
  return count;
}

int main() { 
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  
  int ans = 0,ab=0,a=0,b=0;
  rep(i,n){
    if(s[i].back() == 'A' && s[i].front() == 'B') ab++;
    else if(s[i].back() == 'A') a++;
    else if(s[i].front() == 'B') b++;
    ans+=find(s[i],"AB");
  }
  int m = min(a,b);
  if(a || b){
    m = m + ab;
  }
  else m=max(0,ab-1);
  ans = ans+m;
  cout<<ans<<endl;
  

  return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int seisuA = scan.nextInt();
		int  seisuB = scan.nextInt();
		boolean flg = false;
		int re = 0;

		for(int k=0;k<Math.max(seisuA, seisuB);k++) {

			if(Math.abs(seisuA-k) == Math.abs(seisuB-k)){
				re = k;
				flg = true;
				break;
			}
		}
		System.out.println(flg?re:"IMPOSSIBLE");
		scan.close();

	}

}


Measured memory_bytes: 27452
#include<bits/stdc++.h>
    #define ll long long int
    using namespace std;
    ll dp [3001][3001];
    int main()
    {
        string p,q;
        cin>>p>>q;

        for(int i=0;i<=p.length();i++){
            for(int j=0;j<=q.length();j++)
            {
                if(i==0 || j==0 )
                {
                    dp[i][j]=0;
                }
                else if(p[i-1]==q[j-1]){

                    dp[i][j]=dp[i-1][j-1]+1;
                }
                else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }


            }
        }
       // cout<<dp[p.length()][q.length()];
         char ans[dp[p.length()][q.length()]+1];
    ans[dp[p.length()][q.length()]]='\0';
    int i=p.length();int j=q.length();int k=dp[p.length()][q.length()]-1;
    while(i>0 && j > 0){
        if(p[i-1]==q[j-1])
        {
            ans[k]=p[i-1];
            k--;i--;j--;
        }
        else if (dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }

    }
    cout<<ans;
    }




Measured memory_bytes: 70656
import sys
from collections import deque
from itertools import product
sys.setrecursionlimit(10**9)

H,W=map(int,input().split())
G=[[""]*W for _ in range(H)]
road=0

# print("W,H",W,H)
for y in range(H):
    s=input()
    for x in range(W):
        G[y][x]=s[x]
        if s[x]==".":
            road+=1

# print("road",road)
def bfs(pos):
    todo=[pos]
    index=1
    dx,dy=[-1,1,0,0],[0,0,-1,1]
    depth=[[0]*W for _ in range(H)]
    while True:
        x,y=pos

        # print(pos)
        if pos==(W-1,H-1):
            # print(todo)
            return depth[y][x]

        for i in range(4):
            npos=(x+dx[i],y+dy[i])
            if 0<=npos[0]<W and 0<=npos[1]<H:
                if G[npos[1]][npos[0]]=="." and not npos in todo:
                    depth[npos[1]][npos[0]]=depth[y][x]+1
                    todo.append(npos)

        if index<len(todo):
            pos=todo[index]
            index+=1
        else:
            print(-1)
            exit()
            return


d=bfs((0,0))+1

print(road-d)


Measured memory_bytes: 40816
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> x(N);
    vector<ll> y(N);
    vector<ll> z(N);
    rep(i, N) {
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ma = 0;
    rep(i, 8) {
        vector<ll> tmp(N,0);
        ll a = 1;
        ll b = 1;
        ll c = 1;
        if (i & 1) a = -1;
        if ((i >> 1) & 1) b = -1;
        if ((i >> 2) & 1) c = -1;
        rep(j, N) {
            tmp[j] = a * x[j] + b * y[j] + c * z[j];
        }
        sort(all(tmp), greater<ll>());
        ll sum = 0;
        rep(j, M) {
            sum += tmp[j];
        }
        ma = max(ma, sum);
    }
    print(ma);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,w,sum=0;
	scanf("%d", &n);
	w = n;
	while (w != 0)
	{
		sum = sum + w % 10;
		w = w / 10;
	}
	if (n%sum == 0)
		printf("Yes");
	else
		printf("No");

	return 0;
}

Measured memory_bytes: 128