akhauriyash/Code-Regression huggingface dataset:
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#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::cerr <<"debug "<< i << std::endl;

//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か確認!

  ll n;
  std::cin>>n;

  std::vector<ll> a(n),v(n,LLONG_MAX),sort;
  rep(i,0,n)std::cin>>a[i];

  std::vector<std::vector<ll>> graph(n);
  rep(i,0,n-1){
    ll x,y;
    std::cin>>x>>y;
    x--;y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  if(n==2){
    std::cout<<((a[0]==a[1])?"YES":"NO");
    return 0;
  }

  ll root=-1;
  rep(i,0,n){
    if(graph[i].size()>=2)root=i;
  }

  std::vector<bool> used(n,false);
  std::queue<ll> que;

  que.push(root);

  while(!que.empty()){
    ll now=que.front();que.pop();
    sort.push_back(now);used[now]=true;
    for(ll next:graph[now]){
      if(!used[next])que.push(next);
    }    
  }

  for(ll i=n-1;i>=0;i--){
    ll now=sort[i];
    ll sum=0,max=-1;
    for(ll next:graph[now]){
      if(v[next]!=LLONG_MAX){
        sum+=v[next];
        max=std::max(max,v[next]);
      }
    }

    if(sum==0){
      v[now]=a[now];
    }else{
      v[now]=2*a[now]-sum;
      if(v[now]<0){
        std::cout<<"NO";
        return 0;
      }
      ll pair=(sum-v[now])/2;
      if(pair<0){
        std::cout<<"NO";
        return 0;
      }
      if(max>sum/2){
        if(sum-max<pair){
          std::cout<<"NO";
          return 0;
        }
      }else{
        if(sum/2<pair){
          std::cout<<"NO";
          return 0;
        }
      }
    }
  }

  if(v[root]!=0){
    std::cout<<"NO";
    return 0;
  }

  std::cout<<"YES";

  return 0;
}


Measured memory_bytes: 9172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		/*String a = s.next();
		String b = s.next();
		*/
		int N = s.nextInt();
		int[][] arr = new int[2][N];
		int count = 0;
		int upSum = 0;
		int downSum = 0;
		int[] upArr = new int[N];
		int[] downArr = new int[N];
		int tmpcount = 0;

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < N; j++) {
				arr[i][j] = s.nextInt();
			}
		}
		for (int i = 0; i < N; i++) {
			upSum += arr[0][i];
			downSum += arr[1][i];
		}
		count = Math.max(downSum, upSum);

		for (int i = 0; i < N; i++) {
			if (i == 0) {
				upArr[0] = arr[0][0];
			} else {
				upArr[i] = arr[0][i] + upArr[i - 1];
			}
		}
		for (int j = 0; j < N; j++) {
			if (j == 0) {
				downArr[0] = downSum;
			} else {
				downArr[j] = downArr[j - 1] - arr[1][j - 1];
			}
		}
		for (int k = 0; k < N; k++) {
			tmpcount = upArr[k] + downArr[k];
			count = Math.max(count, tmpcount);
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23636
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

int main()

{

    string a,b,c;

    cin>>a>>b>>c;

    if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])

    {
        cout<<"YES"<<endl;
    }

    else

        {
        cout<<"NO"<<endl;
    }
    return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template <class Abel> 
struct BinaryIndexTree {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0; // to be set
    
    /* [1, n] */
    BinaryIndexTree(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    string A;
    cin >> n >> A;

    vector<int> X(n);
    rep(i, n) X[i] = A[i] - '0';
    int odd_cnt = 0;
    rep(i, n) {
        if (X[i] % 2 == 0) continue;
        if (((n - 1) & i) == i) ++odd_cnt;
    }
    if (odd_cnt % 2) {
        cout << 1 << endl;
        return 0;
    }

    vector<int> cnt(3, 0);
    rep(i, n) {
        ++cnt[X[i] - 1];
    }
    if(cnt[1]) {
        cout << 0 << endl;
        return 0;
    }

    rep(i, n) X[i] = (X[i] - 1) / 2;
    odd_cnt = 0;
    rep(i, n) {
        if (X[i] % 2 == 0) continue;
        if (((n - 1) & i) == i) ++odd_cnt;
    }
    if (odd_cnt % 2) cout << 2 << endl;
    else cout << 0 << endl;
    
    return 0;
}

Measured memory_bytes: 5276
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#print(s)
c=0
for i in t:
    if i in s:
        c+=1
print(c)
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#binary search
a=0
for i in range(q):
    L=0
    R=n-1#探索する方の配列(s)はソート済みでないといけない
    while L<=R:
        M=(L+R)//2
        if s[M]<t[i]:
            L=M+1
        elif s[M]>t[i]:
            R=M-1
        else:
            a+=1
            break
print(a)


Measured memory_bytes: 16896
N,M=gets.split.map(&:to_i)
H=gets.split.map(&:to_i)
J=N.times.map{[]}
M.times{
  a,b=gets.split.map(&:to_i)
  J[a-1]<<H[b-1]
  J[b-1]<<H[a-1]
}
c=0
H.each_with_index{|h,i|
  c+=1 if J[i].select{|x|x>=h}.empty?
}
p c

Measured memory_bytes: 26932
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9+10;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

const int MAX_N = 1e5+10;
int n, a[MAX_N];
int dp[MAX_N];
 
 
int solve() {
    fill(dp, dp + n, INF);
    for(int i = 0; i < n; i++){
        *lower_bound(dp, dp + n, a[i]) = a[i];
    }
    return lower_bound(dp, dp + n, INF) - dp;
}

int main(){
    cin >> n;
    rep(i, n) cin >> a[i];
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int INF=1001001001;

int main() {
  int64_t X,Y;
  cin>>X>>Y;
  int64_t now=X;
  int64_t count=1;
  while(now<=Y/2){
    now*=2;
    count++;
  }
  cout<<count<<endl;
  return 0;}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  string a, b;
  cin >> a >> b;

  int n = stoi(a + b);
  for (int i = 1; i <= 400; ++i) {
    if (i * i == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
use std::collections::BTreeMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut map = BTreeMap::new();
    for _ in 0..n {
        let x:String = read();
        *map.entry(x).or_insert(0) += 1;
    }
    let mut v = Vec::new();
    for (key, value) in map {
        v.push((value as usize, key));
    }
    v.sort();
    let c:usize = v.last().unwrap().0;
    let v:Vec<(usize, String)> = v.into_iter().filter(|x| x.0 == c).collect();
    for (num, s) in v {
        println!("{}", s);
    }
}

Measured memory_bytes: 34284
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    ans = 0
    for i in range(1, N+1):
        if i%3 and i%5:
            ans += i
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73204
N,M=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*N
d=[]
for i in range(N):
  d.append([])
ans=0
r=[]
for i in range(M):
  r.append(list(map(int,input().split())))
for i in range(M):
  d[r[i][0]-1].append(r[i][1]-1)
  d[r[i][1]-1].append(r[i][0]-1)
for i in range(N):
  if c[i]==0:
    flag=0
    for j in range(len(d[i])):
      if h[i]<=h[d[i][j]]:
        flag=1
      else:
        c[d[i][j]]=1
    if flag==0:
      ans+=1
print(ans)


Measured memory_bytes: 48472
n = int(input())
ans = [[0 for i in range(n)] for j in range(n)]
def p2(a):
  ret = 0
  while a%2 == 0:
    ret += 1
    a //= 2
  return ret
for i in range(n):
  for j in range(n-i-1):
    ans[i][j] = p2(j+1)+1
for i in range(n):
  arr = ans[i][:n-i-1]
  print(*arr)

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

int main()
{
	int a,b;
	cin >>a >>b;
	int ans = 0;
//	while(b > 1){
//		b-=(a-1);
//		ans++;
//	}
	if(b == 1){
		printf("0\n");
		return 0;
	}
	for(int i = 1;i < 100;i++){
		if(a+(a-1) * (i - 1) >= b){
			cout << i << endl;
			break;
		}
	}
//	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int s = scan.nextInt();
		int w = scan.nextInt();

		if(s <= w) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 27104
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 












int main()
{
     int n;
     cin>>n;
     int mx=-1;
     int a[n];
     for(int i=0;i<n;i++){cin>>a[i];}
     sort(a,a+n);
     int ct[1000005]={0};
     memset(ct,0,sizeof(ct));
     int res=0;
     for(int i=0;i<n;i++)
     {
          int t=a[i];
          int f=0;
          if(i+1<n&&a[i]!=a[i+1])
          {
               
          for(int j=1;j<=sqrt(t);j++)
          {
               if(t%j==0)
               {
                    int z=t/j;
                   if(ct[z]==1||ct[j]==1){
                       // cout<<j<<" "<<z<<"\n";
                        f=1;break;
                   }
               }
          }
          if(!f)res++;
          ct[a[i]]=1;
          }
          else if(i+1<n&&a[i]==a[i+1])ct[a[i]]=1;
          else{
               for(int j=1;j<=sqrt(t);j++)
          {
               if(t%j==0)
               {
                    int z=t/j;
                   if(ct[z]==1||ct[j]==1){
                       // cout<<j<<" "<<z<<"\n";
                        f=1;break;
                   }
               }
          }
          if(!f)res++;
          ct[a[i]]=1;
          }
          
     }
     cout<<res;

     
}







 
 

















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

int main()
{
  int n, m, k;
  bool f = true;
  cin >> n >> m;
  k = m;

  for (int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    m += (a - b);
    k = max(k, m);
    if (m < 0) f = false;
  }

  if (!f) cout << 0;
  else cout << k;
  cout << '\n';
}

Measured memory_bytes: 2996
#include <stdio.h>

int main(void){

        int h,w;
        int n;
        int ans;

        scanf("%d%d%d",&h,&w,&n);

        int longer = h;

        if(longer<w){
                longer = w;
        }   

        ans = n/longer;

        if(n%longer != 0){ 
                ans++;
        }   

        printf("%d\n",ans);

return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>

using namespace std;

int xx[100],yy[100];
int a[100],b[100];

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;i++){
        scanf("%d%d",&xx[i],yy + i);
    }
    for(int i = 1;i <= m;i++){
        scanf("%d%d",&a[i],&b[i]);
    }
    for(int i = 1;i <= n;i++){
        int ans = 1;
        int sum = abs(xx[i] - a[1]) + abs(yy[i] - b[1]);
        for(int j = 2;j <= m;j++){
            if(abs(xx[i] - a[j]) + abs(yy[i] - b[j]) < sum){
                sum = abs(xx[i] - a[j]) + abs(yy[i] - b[j]);
                ans = j;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
s=input()
N=len(s)

for i in range(N):
    l,r=0,i+1 # 半開区間
    # print(s[l:r]) #DB
    t=set(s[l:r])
    # print(t)
    while r<N:
        l,r=l+1,r+1
        # print(s[l:r]) #DB       
        t&=set(s[l:r])
        # print(t)
        if not t:            
            break
    if t:        
        break

print(i)

Measured memory_bytes: 38768
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

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

  long long A, B, C, D;
  cin >> A >> B >> C >> D;

  cout << ((B - ((B / C) + (B / D))) + (B / ((C * D) / gcd(C, D)))) - (((A - 1) - ((A - 1) / C) - ((A - 1) / D)) + ((A - 1) / ((C * D) / gcd(C, D)))) << endl;

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <queue>
#define f first
#define s second
#define INF (1e9)
#define N 7
using namespace std;
typedef pair<int,int> P;
int bfs(int,int,int,int,int,int);
bool check(int,int,int,int,int,int);
int w,h,data[N][N],d[N][N],cnt[N][N];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
typedef struct data{
  int cy,cx,wy,wx;
} dat;

int main(){
  int sy,sx,gy,gx,wy,wx,ans;
  while(1){
    cin>>w>>h;
    if(!w&&!h) break;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin >> data[i][j];
	if(data[i][j]==2) sy=i,sx=j;
	else if(data[i][j]==3) gy=i,gx=j;
	else if(data[i][j]==4) wy=i,wx=j;
	d[i][j]=INF;
      }
    ans=bfs(sy,sx,wy,wx,gy,gx);
    cout << ans << endl;
  }
  return 0;
}

int bfs(int sy,int sx,int wy,int wx,int gy,int gx){
  queue<dat > q;
  int flag;
  dat k={sy,sx,wy,wx};
  q.push(k);
  d[sy][sx]=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++) cnt[i][j]=0;
  while(!q.empty()){
    dat u=q.front();
    q.pop();
    flag=0;
    for(int i=0;i<4;i++){
      int ny=u.cy+dy[i],nx=u.cx+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx||data[ny][nx]==1) continue;
      if(check(u.wy,u.wx,u.cy-dy[i],u.cx-dx[i],u.cy,u.cx)){
	d[ny][nx]=d[u.cy][u.cx]+1;
	cnt[nx][ny]++;
	if(cnt[nx][ny]==500){
	  flag=1;
	  break;
	}
	if(d[gy][gx]!=INF){
	  flag=2;
	  break;
	}
	dat t={ny,nx,u.cy-dy[i],u.cx-dx[i]};
	q.push(t);
      }
    }
    if(flag) break;
  }
  if(flag==2) return d[gy][gx];
  if(flag) return -1;
  if(d[gy][gx]!=INF) return d[gy][gx];
  return -1;
}

bool check(int sy,int sx,int gy,int gx,int xy,int xx){
  if(gy<0||gx<0||h<=gy||w<=gx) return false;
  if(data[gy][gx]==1) return false;
  bool c[N][N];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) c[i][j]=false;
  queue<P > q;
  q.push(make_pair(sy,sx));
  c[sy][sx]=true;
  while(!q.empty()){
    P u=q.front();
    q.pop();
    for(int i=0;i<4;i++){
      int ny=u.f+dy[i],nx=u.s+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx||data[ny][nx]==1||(ny==xy&&nx==xx)) continue;
      if(c[ny][nx]==true) continue;
      c[ny][nx]=true;
      q.push(make_pair(ny,nx));
    }
  }
  if(c[gy][gx]==true) return true;
  return false;
}

Measured memory_bytes: 1280
#include <iostream>
#include<algorithm>
using namespace std;
void BubbleSort(string C[], int N)
{
  for(int i = 0; i < N; i++)
    for(int j = N - 1; j > i; j--)
      if(C[j][1] < C[j - 1][1])
    swap(C[j], C[j - 1]);
}

void SelectionSort(string C[], int N)
{
  for(int i = 0, minj; i < N; i++){
    minj = i;
    for(int j = i; j < N; j++)
      if(C[j][1] < C[minj][1])
    minj = j;
    swap(C[i], C[minj]);
  }
}

int main()
{
  int N;
  cin >> N;
  string a[N];
  string b[N];
  for(int i = 0; i < N; i++)cin >> a[i];
  copy(a, a + N, b);

  BubbleSort(a, N);
  for(int i = 0; i < N; i++)
    if(i)
      cout << " " << a[i];
    else
      cout << a[i];
  cout << endl << "Stable" << endl;

  SelectionSort(b, N);
  for(int i = 0; i < N; i++)
    if(i)
      cout << " " << b[i];
    else
      cout << b[i];
  for(int i=0;i<N;i++){
    if(a[i]==b[i]){
      if(i==N-1){cout <<endl<< "Stable" << endl;
      break;}
    }
    else{cout <<endl<< "Not stable" << endl;
    break;}
  }
    return 0;
}

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

int main(){
  int a[6];
  int ans=0;
  int b[]={1,5,10,50,100,500};
  for(int i=0;i<6;i++){
    cin >> a[i];
    ans += a[i] * b[i];
  }
  if(ans >= 1000){
    cout << "1" << endl;
  }
  else {
    cout << "0" << endl;
  }
}

Measured memory_bytes: 1160
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())

ans = sum(a)
for i in range(n):
    if a[i] < b[i]:
        b[i] -= a[i]
        a[i] = 0
    else:
        a[i] -= b[i]
        b[i] = 0
    
    if a[i+1] < b[i]:
        b[i] -= a[i+1]
        a[i+1] = 0
    else:
        a[i+1] -= b[i]
        b[i] = 0
ans = ans - sum(a)
print(ans)

Measured memory_bytes: 18752
k = int(input())

def gcd(p, q):
    if p%q==0:
        return q
    else:
        return gcd(q, p%q)

h=1
ans=0
while h<=k:
    i=1
    while i<=k:
        j=1
        while j<=k:
            ans += gcd(gcd(h,i),j)
            j+=1
        i+=1
    h+=1

print(ans)


Measured memory_bytes: 74128
import heapq
n, m = map(int, input().split()) 

d = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a < m+1:
        d[a].append(b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(1, m+1): 
    if len(d[i]) > 0:
        for j in d[i]:
            heapq.heappush(hq, j*(-1))
    if len(hq) > 0:
        ans += heapq.heappop(hq)*(-1)
print(ans)


Measured memory_bytes: 24216
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

ans = 0
for i in range(2**(H+W)):
  height = [x for x in range(H)]
  width = [y for y in range(W)]
  for j in range(H):
    if i >> j & 1:
      height.remove(j)
  for k in range(H, H+W):
    if i >> k & 1:
      width.remove(k-H)
  num = 0
  for p in height:
    for q in width:
      if c[p][q] == "#":
        num += 1
  if num == K:
    ans += 1
print(ans)


Measured memory_bytes: 74556
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 5e5+5, P = 998244353;
int n, k, ans; i64 fac[N], ifac[N];
i64 inv(int i) { return i == 1?1:P-(P/i)*inv(P%i)%P; }
void prepare(int n)
{
    fac[0] = 1; for(int i = 1; i <= n; ++i) fac[i] = fac[i-1]*i%P;
    ifac[n] = inv(fac[n]); for(int i = n; i; --i) ifac[i-1] = ifac[i]*i%P;
}
i64 C(int n, int m) { return m<0||n<m?0:fac[n]*ifac[m]%P*ifac[n-m]%P; }
int main()
{
    n = read(), k = read(); if(n > k) return puts("0"), 0; prepare(k);
    for(int i = 0; i <= k; ++i)
    {
        int j = k-i; if(i < j) continue; j -= i == j;
        ans = (ans+(C(i+j, i)-C(i+j, 2*i-n+1)+P)%P)%P;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 7936
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> P;
    vector<int> M;

    int p;cin>>p;
    P.push_back(p);
    M.push_back(p);
    for(int i=1;i<N;i++){
        cin>>p;
        P.push_back(p);
        M.push_back(min(p,M[i-1]));
    }

    int ans=1;
    for(int i=1;i<N;i++){
        if(P[i]<=M[i-1]) ans++; 
    }
    cout << ans << endl;

    return 0;
}

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

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

  int ans = n;
  for (int i = 0; i <= n; i ++) {
    int cc = 0, t = i;
    while (t > 0) {
      cc += t % 6;
      t /= 6;
    }
    t = n - i;
    while (t > 0) {
      cc += t % 9;
      t /= 9;
    }
    if (ans > cc) ans = cc;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, x;
int v[100];
int w[100];
int dp[101][10001];

int main(){
	scanf("%d%d", &n, &x);
	rep(i, n){
		scanf("%d%d", &v[i], &w[i]);
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j <= x; ++j){
			dp[i][j] = dp[i - 1][j];
			if(j >= w[i - 1]){
				dp[i][j] = max(dp[i][j - w[i - 1]] + v[i - 1], dp[i][j]);
			}
		}
	}
	printf("%d\n", dp[n][x]);
	return 0;
}

Measured memory_bytes: 4936
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <functional>

using namespace std;

#define ll long long

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

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad" << endl;
	}
	else {
	
		cout << "Good" << endl;

	}
		


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
typedef long long ll;
using namespace std;
int main(){
    ll x,y,z,k,i,j,l,ans;
    cin >> x;
    cin >> y;
    cin >> z;
    cin >> k;

    ll a[x],b[y],c[z];
    for (i = 0; i < x; i++){
        cin >> l;
        a[i] = l;
    }
    for (i = 0; i < y; i++){
        cin >> l;
        b[i] = l;
    }
    for (i = 0; i < z; i++){
        cin >> l;
        c[i] = l;
    }

    vector <ll> v;
    for (i = 0; i < x; i++){
        for (j = 0; j < y; j++){
            v.push_back(a[i] + b[j]);
        }
    }
    
    sort(v.begin(),v.end(),greater<ll>());
    sort(c,c+z,greater<ll>());
    ll n = min(k,x*y);
    vector <ll> v2;
    for (i = 0; i < n; i++)
        v2.push_back(v[i]);
    
    vector <ll> v3;
    for (i = 0; i < n; i++){
        for (j = 0; j < z; j++){
            v3.push_back(v2[i]+c[j]);
        }
    }    
    sort(v3.begin(),v3.end(),greater<ll>());

    for (i = 0;i < k; i++)
        cout << v3[i] << endl;
    
    
    
    
}



Measured memory_bytes: 43396
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n;
	cin >> n;
	vector<int>vec[100005];
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}

	int visit[100005];
	rep(i, n) visit[i] = 0;
	queue<P>f, s;
	visit[0] = -1, visit[n - 1] = 1;
	f.push({ 0,0 }), s.push({ n - 1,0 });
	int now = 0;
	while (!f.empty() || !s.empty()) {
		while (!f.empty()) {
			if (f.front().second != now) break;
			P ne = f.front(); f.pop();
			rep(i, vec[ne.first].size()) {
				if (!visit[vec[ne.first][i]]) {
					visit[vec[ne.first][i]] = -1;
					f.push({ vec[ne.first][i], now + 1 });
				}
			}
		}
		while (!s.empty()) {
			if (s.front().second != now) break;
			P ne = s.front(); s.pop();
			rep(i, vec[ne.first].size()) {
				if (!visit[vec[ne.first][i]]) {
					visit[vec[ne.first][i]] = 1;
					s.push({ vec[ne.first][i], now + 1 });
				}
			}
		}
		now++;
	}
	int cf = 0, cs = 0;
	rep(i, n) {
		if (visit[i] == -1) cf++;
		else cs++;
	}
	if (cf > cs) {
		cout << "Fennec" << endl;
	}
	else cout << "Snuke" << endl;

	return 0;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,ar[N],dp[N];
ll maxval(ll i){
	if(i>=n) return 0;
	
	if(dp[i]!=-1){
		return dp[i];
	}
	ll an=1e18;
	if(i+1<=n) an=min(an,maxval(i+1)+abs(ar[i+1]-ar[i]));
	if(i+2<=n) an=min(an,maxval(i+2)+abs(ar[i+2]-ar[i]));
	return dp[i]=an;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	memset(dp,-1,sizeof(dp));
	ll an=maxval(1);
	cout<<an;
	return 0;
}

Measured memory_bytes: 9880
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        String S = sc.next();
        int l = S.length();
        int ans = 0;

        for(int i=l-2; i>=0; i--){
            if(S.charAt(i)!=S.charAt(i+1)){
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}

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

//  a^b % m
long long powmod(long long a, long long b, long long m)
{
    long long r = 1;
    for (; b>0; b>>=1, a=a*a%m)
        if (b&1)
            r = r*a%m;
    return r;
}

int main()
{
    int N;
    cin>>N;
    vector<long long> C(N);
    for (long long &c: C)
        cin>>c;

    sort(C.begin(), C.end());
    long long M = 1000000007;
    long long ans = 0;
    for (int i=N-1; i>=0; i--)
    {
        ans += C[i]*powmod(2, N-2+(M-1), M)%M*(2+N-i-1)%M;
        ans %= M;
    }
    ans *= powmod(2, N, M);
    ans %= M;
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(I, LIM) for (int I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;

constexpr int MOD = 10000007;

vector<long> divisor(long n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

void execute();

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

  execute();

  return (0);
}

void execute() {
  int ls[5];
  int lastnum = 0;
  REP(i, 5) {
    cin >> ls[i];
    if (0 < ls[i] % 10) {
      if (ls[i] % 10 < ls[lastnum] % 10) {
        lastnum = i;
      }
    }
  }

  int sum = 0;
  REP(i, 5) {
    if(i == lastnum){
      sum += ls[lastnum];
      continue;
    }
    sum += ((ls[i] + 9) / 10) * 10;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long douroote
#define pb push_back
#define sz size
#define ll long long
#define ull unsigned long long
#define INF 0x7f7f7f7f
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(a,s,e) for(ll a=s;a<=e;a++)
#define read_arr(a,s,n) for(int i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(int i=s;i<n+s;i++){scll(a[i]);}
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(int i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
#define prtll(x) printf("%lld",x);
#define prt(x) printf("%d",x);
using namespace std;
const int N=(2e5)+10;
ll tree[4*N],a[N],b[N],n,mem[N];
void update(int p, int l,int r,int i,ll x){
    if(l == r){tree[p]=1ll*x;return;}
    int mid = (l + r) / 2;
    if( i <= mid)update(p * 2,l , mid, i, x);
    else update(p * 2 + 1, mid + 1, r, i ,x);
    tree[p] =max(tree[p * 2],tree[p * 2 + 1]);
}
ll rsq(int p,int l,int r,int i,int j){
    if(l >= i && r <= j){return 1ll*tree[p];}
    if(r < i || l > j){return 0ll;}
    int mid = (l + r) / 2;
    ll x = rsq(p * 2, l, mid, i, j);
    ll y = rsq(p * 2 + 1, mid + 1, r, i, j);
    return 1ll*max(x,y);
}
int main(){
scll(n);
loop(i,1,n){scll(a[i]);a[i]++;}
loop(i,1,n){scll(b[i]);}
loop(i,1,n){
   ll best=rsq(1,1,n,1,a[i]-1);
   mem[i]=1ll*best+b[i];
   update(1,1,n,a[i],mem[i]);
}
ll ans=tree[1];
if(ans<0){ans/0;}
printf("%lld\n",ans);
}

/**
**/


Measured memory_bytes: 10496
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

const long long LLINF = 1LL << 60;

#define PI 3.14159265359

int main(void) {
	double a, b, C;
	cin >> a >> b >> C;

	double s = 0.5 * a * b * sin(C / 180 * PI);
	double L = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(C / 180 * PI)) + a + b;
	double h = b * sin((180 - C) / 180 * PI);
	printf("%.8f\n%.8f\n%.8f\n", s, L, h);
}


Measured memory_bytes: 3436
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"29
" => r"Yes",

r"72
" => r"No",

r"91
" => r"Yes"
}

use std::cmp;
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: String,
    }

    for i in n.as_str().chars() {
        if i == '9' {
            return "Yes".to_string();
        }
    }

    "No".to_string()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

vector<long long> enum_div(long long n) {
    vector<long long> res;
    for (long long i = 1; i*i <= n; i++) {
        if (n%i) continue;
        res.push_back(i);
        if (i*i != n) res.push_back(n/i);
    }
    sort(res.begin(), res.end());
    return res;
}

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0);
    auto d = enum_div(sum);

    auto ok = [&](int x) {
                  vector<int> rs;
                  rep(i, n) {
                      int r = a[i] % x;
                      if (r != 0) rs.push_back(r);
                  }
                  if (rs.size() == 0) return true;
                  sort(rs.begin(), rs.end());
                  int m = sz(rs);
                  vector<ll> sum(m + 1);
                  rep(i, m) sum[i+1] = sum[i] + rs[i];
                  ll res = 5e18;
                  rep(i, m+1) {
                      ll l = sum[i];
                      ll r = 1LL * x * (m - i) - (sum[m] - sum[i]);
                      chmin(res, max(l, r));
                  }
                  return res <= k;
             };
    
    rrep(i, sz(d)) {
        int x = d[i];
        if (ok(x)) {
            cout << x << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <list>
#define llint long long

using namespace std;

llint n, m;
llint lb[10005], ub[10005];
llint lmax[10005], rmax[10005];

int main(void)
{
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		
		for(int i = 1; i <= n; i++) lb[i] = ub[i] = 0;
		llint s, k, x;
		for(int i = 1; i <= m; i++){
			cin >> s >> k;
			for(int j = 0; j < k; j++){
				cin >> x;
				ub[x] += s;
				if(k == 1) lb[x] += s;
			}
		}
		for(int i = 1; i <= n; i++) lmax[i] = max(lmax[i-1], ub[i]);
		rmax[n+1] = 0;
		for(int i = n; i >= 1; i--) rmax[i] = max(rmax[i+1], ub[i]);
		
		llint ans = 0;
		for(int i = 1; i <= n; i++) ans = max(ans, max(lmax[i-1], rmax[i+1]) - lb[i]);
		cout << ans+1 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3396
n = int(input())
p = [int(i) for i in input().split()]

count = 0
for i in range(1, n-1):
    if (p[i] < p[i-1]) and (p[i] > p[i+1]):
        count += 1
    elif (p[i] < p[i+1]) and (p[i] > p[i-1]):
        count += 1

print(count)


Measured memory_bytes: 3316
import java.util.Scanner;
class Main{
  			public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int n = sc.nextInt();
        
			switch (n % 10){
	          case 2:
	          case 4:
              case 5:
	          case 7:
	          case 9:
                System.out.println("hon");
	            break;
	          case 0:
	          case 1:
	          case 6:
	          case 8:
                System.out.println("pon");
	            break;
	          case 3:System.out.println("bon");
                break;
              default:break;
	        }
        }
	}

Measured memory_bytes: 35708
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (100010)
int k,x;

int main(){
	scanf("%d%d",&k,&x);
	for (int i=x-k+1;i<=x+k-1;i++) printf("%d ",i);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cstring>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define ISP pair<int, string>
#define SSP pair<string, string>
const int INF = INT_MAX;

string bef, aft;
vector<SSP> v;

string make_str(string now_s, int now, string str, string b, string a){
  if(now >= str.length()) return now_s;

  if(str.substr(now, b.length()) == b) return make_str(now_s + a, now + b.length(), str, b, a);
  else return make_str(now_s + str[now], now + 1, str, b, a);
}

int main(){
  int n;
  while(cin >>n && n){
    v = vector<SSP>(n);
    REP(i, n) cin >>v[i].first >>v[i].second;
    cin >>bef >>aft;

    queue<ISP> open;
    open.push( ISP(0, bef) );
    set<string> closed;

    int ans = -1;
    while(!open.empty()){
      int cnt = open.front().first;
      string str = open.front().second;
      open.pop();
      if(str == aft){
        ans = cnt;
        break;
      }

      closed.insert(str);

      REP(i, v.size()){
        string next = make_str("", 0, str, v[i].first, v[i].second);
        if(str == next || next.length() > aft.length() || closed.find(next) != closed.end()) continue;
        open.push( ISP(cnt + 1, next) );
      }
    }
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1572
def main():
    k,n = map(int,input().split())
    arr = list(map(int,input().split()))
    ans = float('inf')
    prev = 0
    for i in range(n):
        if i == n-1:
            if prev == 0:
                total = arr[-1]-arr[i]
            else:
                total = k-arr[i]+prev
        else:
            if i == 0:
                total = arr[-1]-arr[i]
            else:
                total = min(k-arr[i]+prev,arr[i]+k-arr[i+1])

        prev += arr[i]
            
        ans = min(ans,total)

    print(ans)
                            
main()


Measured memory_bytes: 26444
import numpy as np
# 参加人数を入力する
N = int(input())
# レートを入力する
a = list(map(int, input().split()))
# ndarray型に変換
arr_a = np.array(a)
# 3200未満のレートを持つ人について、色の種類数を設定する
under3200 = 0
# 色ごとのレートの下限と上限を設定
lower = 1
upper = 399
# 上限が3200未満である限り繰り返す
while upper < 3200:
    # 範囲内のレートを持つ人がいる場合、色の種類数を増やす
    if len(arr_a[(arr_a  >= lower) & (arr_a <= upper)]) != 0:
        under3200 += 1
    # 下限と上限を更新する
    lower = upper + 1
    upper += 400
# 3200を超えるレートを持つ人の数を数える
over3200 = len(arr_a[arr_a >= 3200])

# 色の種類数の最小値について
if under3200 != 0:
    min_color = under3200
else:
    min_color = 1
# 色の種類数の最大値について
max_color = under3200 + over3200
# 結果を出力する
print("{} {}".format(min_color, max_color))

Measured memory_bytes: 18972
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  ll a[N+1];
  a[0]=2;
  a[1]=1;
  FOR(i,2,N+1){
    a[i]=a[i-1]+a[i-2];
  }
  cout<<a[N]<<endl;
    
 
}
  







Measured memory_bytes: 256
'use strict'
function Main(input){
  input=input.trim().split(/\n/);
  var firstline=input.shift();
  firstline=firstline.split(/\s+/).map(x=>x-0);
  var H=firstline[0];
  var W=firstline[1];
  var matrix=input.map(str=>str.split('').map(x=>x==='#'?0:1));
  var Black=[[]];
  matrix.forEach(function(row,i){
    row.forEach(function(x,j){
      if(x===0)Black[0].push([i,j]);
    });
  });
  if(!(Black[0].length<H*W)){
    console.log(0);
    return;
  }
  var generation=1;
  while(true){
    Black[generation]=[];
    let B=Black[generation-1];
    let C=Black[generation];
    B.forEach(function(ij){
      let i=ij[0];
      let j=ij[1];
      if(matrix[i-1]&&matrix[i-1][j]){
        matrix[i-1][j]=0;
        C.push([i-1,j]);
      }
      if(matrix[i+1]&&matrix[i+1][j]){
        matrix[i+1][j]=0;
        C.push([i+1,j]);
      }
      if(matrix[i][j-1]){
        matrix[i][j-1]=0;
        C.push([i,j-1]);
      }
      if(matrix[i][j+1]){
        matrix[i][j+1]=0;
        C.push([i,j+1]);
      }
    });
    if(C.length===0)break;
    generation++;
  }
  console.log(generation-1);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 136708
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード

    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M = map(int, input().split())

uf = UnionFind(M+1)
talker = [False]*(M+1)

for i in range(N):
    K, *L = map(int, input().split())
    f = -1
    for l in L:
        talker[l] = True
        if f == -1:
            f = l
        else:
            uf.Unite(f, l)

for m in range(M+1):
    if talker[m] is True:
        if not uf.isSameGroup(f, m):
            print('NO')
            exit()
print('YES')


Measured memory_bytes: 9916
from collections import deque
k = int(input())

digsum = lambda x: sum(list(map(int, list(str(x)))))
dignorm = lambda x: x/digsum(x)

n = 1
order = 1
while k > 0:
    print(n)
    k -= 1
    if dignorm(n+10**(order-1)) > dignorm(n+10**order):
        order += 1
    n += 10**(order-1)

Measured memory_bytes: 3444
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

const int N=105;
map<int,int> dp[N];
int n,m,ans;
int v[N],w[N];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",w+i,v+i);
	dp[0][0]=0;
	for(int i=0;i<n;i++) for(map<int,int>::iterator it=dp[i].begin();it!=dp[i].end();it++){
		int V=(*it).second;
		int W=(*it).first;
		dp[i+1][W]=max(dp[i+1][W],V);
		if(W+w[i+1]<=m) dp[i+1][W+w[i+1]]=max(dp[i+1][W+w[i]],V+v[i+1]);
	}
	for(map<int,int>::iterator it=dp[n].begin();it!=dp[n].end();it++){
		int W=(*it).first;
		int V=(*it).second;
		if(W<=m) ans=max(ans,V);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4992
n = int(input())
a = sorted(map(int, input().split()), reverse = True)

ans = a[0]
i = 0
for i in range(1, (n-2) // 2 + 1):
    ans += a[i] * 2
    
if (n-2) % 2 == 1 and not n-2 == 1:
    ans += a[i+1]
    
print(ans)

Measured memory_bytes: 94100