akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int cnt = 0;

void insertionSort(long *a, long n, long m) {
  long i, key, j;
  for (i = m; i < n; i++) {
    key = a[i];
    j = i - m;
    while (j >= 0 && a[j] > key) {
      a[j + m] = a[j];
      j -= m;
      ++cnt;
    }
    a[j + m] = key;
  }
}

int main() {
  long a[1000000];
  long n;
  long g[100] = {0};
  int glen = 0;
  long i;

  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  g[0] = 1;
  for (i = 1; i < 100; i++) {
    long v = g[i - 1] * 3 + 1;

    if (v >= n) {
      glen = i;
      break;
    }

    g[i] = v;
  }

  cout << glen << endl;

  for (i = glen - 1; i >= 1; i--) {
    cout << g[i] << ' ';
  }
  cout << g[0] << endl;

  for (i = glen - 1; i >= 0; i--) {
    insertionSort(a, n, g[i]);
  }
  cout << cnt << endl;

  for (i = 0; i < n; i++) {
    cout << a[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 8972
N, K =map(int, input().split())
lst = []
for _ in range(N):
    lst.append(int(input()))
sor = sorted(lst)

mindiff = float('inf')
for i in range(N-K+1):
    diff = sor[i+K-1] - sor[i] 
    if diff <= mindiff:
        mindiff = diff
print(mindiff) 

Measured memory_bytes: 51160
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

typedef long long ll;
const int N = 1e5 +7;

ll a[N];
int main(){
	int n, i;
    scanf("%d",&n);
    bool flag = 1;
    for(i = 0; i < n; i++){
    	scanf("%lld",&a[i]);
    	if(a[i] == 0)
    	flag = 0;
	}
	if(!flag){
		printf("0\n");
		return 0;
	}
	ll ans = 1;
	for(i = 0; i < n; i++){
		if(a[i] <= 1000000000000000000/ans)
		ans *= a[i];
		else
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n",ans);
    
}

Measured memory_bytes: 2508
A_V = input().split()
A = int(A_V[0])
V = int(A_V[1])
B_W = input().split()
B = int(B_W[0])
W = int(B_W[1])
T = int(input())
 
if V - W <= 0:
  print('NO')
elif T < abs(B-A)/(V-W):
  print('NO')
else:
  print('YES')

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long inf = 1e18;
long long dp[105][N];
long long w[105], val[105];
int main() {
	int n, W;
	cin >> n >> W;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> val[i];
	}
	for (int i = 0; i < N; i++) {
		dp[0][i] = inf;
	}
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < N; j++) {
			if (val[i - 1] <= j) {
				dp[i][j] = min(w[i - 1] + dp[i - 1][j - val[i - 1]], dp[i - 1][j]);
			}
			else{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (dp[n][i] <= W) {
			ans = i;
		}
	}
	cout << ans;
	return 0;
}


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

namespace ABC061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d, f;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            if (a <= c && b >= c)


                    Console.WriteLine("Yes");
                else
                {
                    Console.WriteLine("No");
                }
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

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

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

    ll amari = n % 500;
    cout << ((amari <= a) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=1e5;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void solve(int time){
    max_score=evaluate();
    for(int i=0;i<time;++i){
        int p=rand()%D+1;
        int temp=ans[p];
        ans[p]=rand()%ntype+1;
        int temp_score=evaluate();
        if(max_score<temp_score) max_score=temp_score;
        else ans[p]=temp;
    }
}

int main(){
    srand(seed);
    Input();
    Greedy();
    solve(t);
    Output();
}

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


int main() {
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }

    int ans = 0;
    for (int i = 1; i < n - 1; ++i) {
        if (p[i - 1] < p[i] && p[i] < p[i + 1]) {
            ans++;
        }
    }
    for (int i = 1; i < n - 1; ++i) {
        if (p[i - 1] > p[i] && p[i] > p[i + 1]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//dp状态:dp(i,j)表示离第i个结点距离为j的结点的个数 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll Abs(ll x){
	if(x<0) return -x;
	else return x;
}
int n;
ll in[100005];
priority_queue<ll> pq;
ll res;
int p;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>in[i];
		res+=Abs(in[i]);
	}
	p=0;
	for(int i=0;i<n;i++){
		if(in[i]<0){
			p=1-p;
			pq.push(in[i]);
		}
		else pq.push(-in[i]);
	}
	if(p==1) res+=2*pq.top();
	cout<<res<<endl;
	return 0;
}

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

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

  int dp[3100][3100] = {0};

  rep(i, s.size()) {
    rep(j, t.size()) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      }
      if (dp[i + 1][j + 1] < dp[i + 1][j]) {
        dp[i + 1][j + 1] = dp[i + 1][j];
      }
      if (dp[i + 1][j + 1] < dp[i][j + 1]) {
        dp[i + 1][j + 1] = dp[i][j + 1];
      }
    }
  }

  string ans = "";

  int i = s.size(), j = t.size();
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i - 1][j])
      i--;
    else if (dp[i][j] == dp[i][j - 1])
      j--;
    else {
      ans = s[i - 1] + ans;
      i--;
      j--;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 37760
//
//  main.c
//  YYMM or MMYY
//
//  Created by yuta on 2019/05/19.
//  Copyright © 2019 501Software. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

int main(int argc, const char * argv[]) {

	char string[128];
	char first[3];
	char second[3];
	
	bool bfirst = false;
	bool bsecond = false;

	
	scanf("%s",    string);

	first[2] = 0;
	second[2] = 0;
	
	memcpy(first,string,2);
	memcpy(second,&string[2],2);
	
	if(atoi(first) > 0 && atoi(first) < 13)
		bfirst = true;
	
	if(atoi(second) > 0 && atoi(second) < 13)
		bsecond = true;
	
	
	if(bfirst && bsecond) {
		printf("AMBIGUOUS\n");
		return 0;
	}
		
	if(bfirst && !bsecond) {
		printf("MMYY\n");
		return 0;
	}

	if(!bfirst && bsecond) {
		printf("YYMM\n");
		return 0;
	}

	// insert code here...
	printf("NA\n");
	return 0;
}


Measured memory_bytes: 128
main = getLine >>= putStrLn . solve . map read . words

solve :: [Int] -> String
solve [a, b]
    | ax > bx = "Alice"
    | ax < bx = "Bob"
    | otherwise = "Draw"
    where
        ax = f a
        bx = f b
        f x
            | x == 1 = 14
            | otherwise = x


Measured memory_bytes: 508
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  std::vector<int> v(3);
  for(int i=0;i<3;i++)cin>>v[i];
  int a=v[0];int m=0;
  if(v[1]>a){a=v[1];m=1;}
  if(v[2]>a){a=v[2];m=2;}
  if(m==0)cout<<"A"<<endl;
  if(m==1)cout<<"B"<<endl;
  if(m==2)cout<<"C"<<endl;
}



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

bool kaibun(string s){
    int n = s.length();
    for(int i = 0; i < n; i++){
        if(s[i] != s[n - 1 - i]){
            return false;
        }
    }
    return true;
}

int main(){
    string s;
    cin >> s;
    int n = s.length();
    if( kaibun(s) && kaibun(s.substr(0, (n-1)/2)) && kaibun(s.substr((n+1)/2))){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
   char s[6];
    scanf("%s",s);
  
  int k=0;
  
  if(s[2]==s[3])
  {  k++;
  }
   if(s[4]==s[5])
   { k++;
   }
  
  
  if(k==2)
    printf("Yes\n");
  else
    printf("No\n");
  
  return 0;}

Measured memory_bytes: 128
s = input()
ans = s[0]
OK = True
for i in range(1,len(s)):
    ans += s[i]
    if len(ans)==2 and ans[0]==ans[1]:
        print('{0} {1}'.format(i,i+1))
        OK=False
        break
    if len(ans)==3:
        if ans[0]==ans[2] or ans[1]==ans[2]:
            OK=False
            print('{0} {1}'.format(i-1,i+1))
        else:
            ans = ans[1:3]
if OK:
    print('-1 -1')


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


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

   int n;
   cin >> n;
   map <string, vector <pair <int, int>>> m;
   for (int i = 1; i <= n; i++) {
      string s;
      int x;
      cin >> s >> x;
      m[s].push_back({x, i});
   }
   for (auto &i: m) {
      sort(i.ss.begin(), i.ss.end(), greater <pair <int, int>> ());
      for (auto j: i.ss)
         cout << j.ss << endl;
   }


   return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int n;

double dp[310][310][310];
double rec(int i,int j, int k){
  if(dp[i][j][k]>=0)return dp[i][j][k];
  if(i+j+k==0)return 0.0;
  
  double res=0.0;
  if(i>0)res+=rec(i-1,j,k)*i;
  if(j>0)res+=rec(i+1,j-1,k)*j;
  if(k>0)res+=rec(i,j+1,k-1)*k;
  res+=n;
  res*=1.0/(i+j+k);
  return dp[i][j][k]=res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int one=0,two=0,three=0;
  cin >> n;
  rep(i,n){
    int a;
    cin >> a;
    if(a==1)one++;
    if(a==2)two++;
    if(a==3)three++;
  }
  memset(dp, -1, sizeof(dp));
  cout << fixed << setprecision(10) << rec(one,two,three)<< endl;
    
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> cnt(26, 0);
    for (char c : s) {
        cnt[c - 'a']++;
    }

    ll ans = 1;
    for (int i = 0; i < 26; i++) {
        (ans *= (cnt[i] + 1)) %= MOD;
    }
    ans = (ans + MOD - 1) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
  int a, b;
  int d, r;
  double f;

  scanf("%d %d", &a, &b);

  while(a<1 || a>1000000000 || b<1 || b>1000000000){
    printf("??????????????\??????????????????\n");
    scanf("%d %d", &a, &b);
  }

  d = a / b;
  r = a % b;
  f = (double)a / b;

  printf("%d %d %f\n", d, r, f);

  return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <string.h>

int main(int argc,char* argv[]){
  int array[10001];
  int stay;
  int s,i;

  memset(array,0,sizeof(array));
  array[1] = 2;
  stay = 2;

  while(scanf("%d",&s) != EOF){
    if(array[s] != 0){
      printf("%d\n",array[s]);
    }else{
      for(i = stay; i <= s;i++){
	array[i] = array[i-1] + i;
      }
      stay = s+1;
      printf("%d\n",array[s]);
    }
  }

  return 0;
  
}

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

#define INF INT_MAX

typedef long long ll;

using namespace std;

int main(void){
	int n;
	cin >> n;
	vector<int> s;
	int temp;
	int ans = 0;
	for(int i = 0;i < n;i++){
		cin >> temp;
		s.push_back(temp);
		ans += temp;
	}
	sort(s.begin(),s.end());
	for(int i = 0;i < n;i++){
		if(ans % 10 != 0){
			break;
		}
		ans -= s[i] % 10 == 0 ? 0 : s[i];
	}
	if(ans % 10 != 0)
		cout << ans << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[500][500];

int main(){
  cin >> n;
  rep(i,0,n)cin >> d[i];
  ll ans[200010];
  clr(ans,0);
  l = 100005;
  m = l + 1;
  rep(i,0,n){
    if(i % 2 == (n - 1) % 2)ans[l--] = d[i];
    else ans[m++] = d[i];
  }
  rep(i,l+1,m)cout << ans[i] << " ";
  puts("");
  return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

using Graph = vector<vector<int>>;
Graph G;

vector<int> d, f;

int dfs(int v, int t) {
    if(d[v]==0) d[v]=t;
    int res = t;
    for(const auto nv: G[v]) {
        if (d[nv]) continue;
        res = dfs(nv, res+1);
    }
    return f[v] = ++res;
}

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

    int n; cin >> n;
    G.resize(n);
    rep(i, n) {
        int x, k; cin >> x >> k;
        x--;
        rep(j, k) {
            int v; cin >> v; v--;
            G[x].push_back(v);
        }
    }

    d.assign(n, 0); f.assign(n, 0);

    int cur = 1;
    rep(i, n) {
        if (!d[i]) {
            cur = dfs(i, cur);
            cur++;
        }
    }
    rep(i, n) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}


Measured memory_bytes: 3232
mod=10**9+7
n,a,b = map(int,input().split())
def combination(n, r,mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * pow(i+1, mod-2, mod) % mod
    return res

N = pow(2,n,mod)-1
A = combination(n,a)
B = combination(n,b)
print((N-A-B)%mod)

Measured memory_bytes: 3064
#catupper
n, m = map(int, input().split())

lmax = -1#初期値は反対（最大値は小さい、最小値は大きい）
rmin = n * 100
for i in range(m):
    l, r = map(int, input().split())#都度、入力
    lmax = max(l, lmax)#ソートは不要、最大・最小が分かれば良い
    rmin = min(r, rmin)

print(max(rmin - lmax + 1, 0))#マイナス値は取らない、植木算

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    string s;
    cin>>n>>s;

    rep(i,s.size()){
        ll ind = (s[i]-'A'+n)%26;
        s[i] = ind+'A';
    }
    cout<<s<<endl;
    return  0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	int H;
	int n;
	cin >> H >> n;
	vector<int> a(n);
	input(a);
	for (auto to : a)
		H -= to;
	if (H <= 0)
		cout << "Yes";
	else
		cout << "No";

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long int a[200010],pref[200010];
int main()
{
cout << fixed << setprecision(10);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
    cin>>a[i];
}
pref[0]=0;
pref[1]=a[1];
for(int i=2;i<=n;i++)
{
    pref[i]=a[i]+pref[i-1];
}
int s=n;
vector<  double>v;
while(s-k>=0)
{
    v.push_back(pref[s]-pref[s-k]);
    s--;
}
sort(v.begin(),v.end());
double ans=(v[v.size()-1]+k);
ans /= 2.0;
cout<<ans;
return 0;
}


Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	string S;
	cin >> S;

	S[3] = '8';

	co(S);
	Would you please return 0;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=998244353
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=set()
  if n%2==0:
    for i in range(n):
      for j in range(i+1,n):
        if i==j:
          continue
        if n+1==(i+1)+(j+1):
          continue
        ans.add((i+1,j+1))
  else:
    for i in range(n):
      for j in range(i+1,n):
        if i==j:
          continue
        if n==(i+1)+(j+1):
          continue
        ans.add((i+1,j+1))
  print(len(ans))
  for x,y in ans:
    print(x,y)

main()
# print(main())


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

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i=0; i<N; i++){
        cin >> P[i];
    }
    
    int cnt = 0;
    int min_P = N+1;
    for(int i=0; i<N; i++){
        min_P = min(min_P, P[i]);
        if(min_P == P[i]){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    priority_queue<ll> que;
    REP(_, n) {
        ll a; cin >> a;
        que.push(a);
    }
    REP(_, m) {
        ll a = que.top(); que.pop();
        que.push(a/2);
    }
    ll ans = 0;
    while(!que.empty()) {ans += que.top(); que.pop();}
    cout << ans << '\n';
    return 0;
}


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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    string S;

    cin >> S;

    cout << (S[0] == '+' ? 1 : -1) + (S[1] == '+' ? 1 : -1) + (S[2] == '+' ? 1 : -1) + (S[3] == '+' ? 1 : -1) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val inp = Main.InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = Main.TaskB()
    solver.solve(inp, out)
    out.close()
}

class Main {
    internal class TaskB {
        fun solve(inp: InputReader, out: PrintWriter) {
            val x = inp.nextInt()
            for (a in 1..9)
                for (b in 1..9)
                    if (a * b == x) {
                        out.println("Yes")
                        return
                    }
            out.println("No")
        }
    }

    internal class InputReader(stream: InputStream) {
        private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)
        private var tokenizer: StringTokenizer? = null

        init {
            tokenizer = null
        }

        operator fun next(): String {
            while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
                try {
                    tokenizer = StringTokenizer(reader.readLine())
                } catch (e: IOException) {
                    throw RuntimeException(e)
                }
            }
            return tokenizer!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return next().toLong()
        }
    }
}


Measured memory_bytes: 31132
N,M=list(map(int,input().split()))
n_l=list(map(int,input().split()))
ans=float("INF")
for i in range(N-M+1):
   ans=min(ans,abs(0-n_l[i])+abs(n_l[i]-n_l[i+M-1]),abs(0-n_l[i+M-1])+abs(n_l[i]-n_l[i+M-1]))
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int h[100];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) cin >> h[i];
  int l = 0, r = 0;
  int ans = 0;
  while(l < n) {
    bool f = false;
    while(h[r] > 0 && r < n) {
      h[r]--;
      r++;
      f = true;
    }
    if(f) ans++;
    if(h[l] == 0) l++;
    r = l;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class ABC121A{
    public static void Main(){
        var HW = Console.ReadLine().Split().Select(int.Parse).ToList();
        var hw = Console.ReadLine().Split().Select(int.Parse).ToList();
        Console.WriteLine(HW[0]*HW[1]-(hw[0]*HW[1]+(HW[0]-hw[0])*hw[1]));
    }
}

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

using namespace std;

int main(){
    int sum = 0;
    while(true){
        char c;
        cin >> c;
        if(cin.eof())break;
        sum += (c - '0');
    }

    if(sum%9 == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3616
import queue
K = int(input())
q = queue.Queue()
for i in range(1, 10):
    q.put(i)

for _ in range(K):
    x = q.get()
    r = x%10
    y = 10*x+r
    if r != 0: q.put(y-1)
    q.put(y)
    if r != 9: q.put(y+1)

print(x)

Measured memory_bytes: 18992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

const int N = 105;
int h, w, f[N][N], vis[N][N];
char s[N][N];

int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) {
    scanf("%s", s[i] + 1);
  }
  memset(f, 10, sizeof f);
  if (s[1][1] == '#') f[1][1] = 1;
  else f[1][1] = 0;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (i == 1 && j == 1) continue;
      if (s[i][j] == '.') {
        if (i > 1) f[i][j] = min(f[i][j], f[i - 1][j]);
        if (j > 1) f[i][j] = min(f[i][j], f[i][j - 1]);
      } else {
        queue<pair<int, int>> qu;
        memset(vis, 0, sizeof vis);
        qu.emplace(i, j);
        vis[i][j] = 1;
        while (!qu.empty()) {
          int ii, jj;
          tie(ii, jj) = qu.front(), qu.pop();
          if (ii == 1 && jj == 1) f[i][j] = 1;
          if (ii > 1) f[i][j] = min(f[i][j], f[ii - 1][jj] + 1);
          if (jj > 1) f[i][j] = min(f[i][j], f[ii][jj - 1] + 1);
          if (ii > 1 && s[ii - 1][jj] == '#' && !vis[ii - 1][jj]) qu.emplace(ii - 1, jj), vis[ii - 1][jj] = 1;
          if (jj > 1 && s[ii][jj - 1] == '#' && !vis[ii][jj - 1]) qu.emplace(ii, jj - 1), vis[ii][jj - 1] = 1;
        }
      }
    }
  }
  cout << f[h][w] << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long int ll;
int P[10] = {0,0,0,0,0,0,1,1,1,2};
int Q[10] = {1,1,1,2,2,3,2,2,3,3};
int R[10] = {2,3,4,3,4,4,3,4,4,4};


int main()
{
	set<string> nameList[5];
	int n;
	cin>>n;
	char initialList[5] = {'M','A','R','C','H'};
	for(int i = 0; i < n;i++){
		string str;
		cin>>str;
		for(int j = 0 ; j < 5; j++){
			if( str[0] == initialList[j]){
				nameList[j].insert(str);
				break;
			}
		}
	}

	ll ans = 0;
	rep(i,10){
		ans += nameList[P[i]].size()*nameList[Q[i]].size()*nameList[R[i]].size();
		//cout<<nameList[P[i]].size()<<" "<<nameList[Q[i]].size()<<" "<<nameList[R[i]].size()<<endl;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 9600
N = int(input())
lis = list(map(int, input().split()))

num_dic = {}

for ele in lis:
    if ele not in num_dic:
        num_dic[ele] = 1
    else:
        num_dic[ele] += 1
        
if max(num_dic.values()) == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 33612
#include <stdio.h>
#include <stdlib.h>
int buf[20005];
int A[10005];
int B[10005];
int H,N;
int F(int x)
{
    int i,a,minf;
    if(x<=0) return 0;
    if(buf[x]!=-1)return buf[x];
    else
    {
        minf=1000000000;
        for(i=0; i<N; i++)
        {
            a=F(x-A[i])+B[i];
            if(minf>a)
            {
                minf=a;
            }
        }
        buf[x]=minf;
        return minf;
    }
}
int main()
{
    scanf("%d%d",&H,&N);
    int i;
    for(i=0; i<N; i++)
    {
        scanf("%d%d",&A[i],&B[i]);
    }
    for(i=0;i<20005;i++)
    {
        buf[i]=-1;
    }
    printf("%d\n",F(H));
   
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


const int MAXN = 100005;
string S;
int RK[MAXN], SA[MAXN], LCP[MAXN], h[MAXN];
int cnt[MAXN], tmp[MAXN];

void getSA() {
	// O(NlogN)っぽいSA構築のコピペ
	// SA[i]が辞書順i番目の接尾辞が何文字目からのものか
	// RK[i]はi文字目からの接尾辞が辞書順何番目か
	// LCP[i]は辞書順i番目と(i-1)番目の接尾辞をみたとき、prefixが何文字一致するか
	// h[i] = LCP[RK[i]]

	int N = S.size();
	int limit = 128;
	rep(i, N) ++cnt[RK[i] = S[i]];
	rep(i, limit - 1) cnt[i + 1] += cnt[i];
	for (int i = N - 1; i >= 0; --i) SA[--cnt[S[i]]] = i;
	for (int k = 1; k <= N; k <<= 1) {
		int j = 0;
		rep(i, k) tmp[j++] = N - k + i;
		rep(i, N) if (SA[i] >= k) tmp[j++] = SA[i] - k;
		rep(i, limit) cnt[i] = 0;
		rep(i, N) ++cnt[RK[i]];
		rep(i, limit - 1) cnt[i + 1] += cnt[i];
		for (int i = N - 1; i >= 0; --i) SA[--cnt[RK[tmp[i]]]] = tmp[i];
		tmp[SA[0]] = 0;
		rep1(i, N - 1) {
			tmp[SA[i]] = tmp[SA[i - 1]] + 1;
			if (SA[i] + k < N && SA[i - 1] + k < N && RK[SA[i]] == RK[SA[i - 1]] && RK[SA[i] + k] == RK[SA[i - 1] + k]) {
				tmp[SA[i]]--;
			}
		}
		rep(i, N) RK[i] = tmp[i];
		limit = RK[SA[N - 1]] + 1;
		if (limit >= N) break;
	}
	rep(i, N) {
		if (!RK[i]) h[i] = 0;
		else {
			if(i && h[i - 1]) h[i] = h[i - 1] - 1;
			while (S[i + h[i]] == S[SA[RK[i] - 1] + h[i]]) h[i]++;
		}
	}
	rep(i, N) LCP[i] = h[SA[i]];
}

const int K = 15;
const int KM = 1 << (K - 1);
int dat[1 << K];

void update(int A) {
	dat[A] = min(dat[A * 2], dat[A * 2 + 1]);
	if (A != 1) update(A / 2);
}

void add(int A, int B) {
	int C = A + KM;
	dat[C] = B;
	update(C / 2);
}

int check(int L, int R, int A, int l, int r) {
	if (L <= l && r <= R) return dat[A];
	if (r <= L || R <= l) return 1e9;
	return min(check(L, R, A * 2, l, (l + r) / 2), check(L, R, A * 2 + 1, (l + r) / 2, r));
}

int query(int L, int R) {
	return check(L, R, 1, 0, KM);
}

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


	int N;
	cin >> N;
	cin >> S;

	getSA();
	rep(i, 1 << K) dat[i] = 1e9;
	rep(i, N) add(i, LCP[i]);

	//明日sparse tableの勉強しよ・・・

	int kotae = 0;
	rep(i, N) for(int j = i + 1; j < N; j++) {
		int a = RK[i];
		int b = RK[j];
		if (a > b) swap(a, b);
		if (LCP[b] <= kotae) continue;
		int k = query(a + 1, b + 1);
		kotae = max(kotae, min(k, j - i));
	}
	co(kotae);

	Would you please return 0;
}

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

int main() {
  int a, b , c;
  cin >> a >> b>> c;
  if (a!=b && b!=c && c!=a || a==b&&b==c) {
    cout << "No" <<endl;
  }
  else {
    cout << "Yes"<<endl;
  }
}

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(S, T):
    N = len(S)
    S_check = [0] * N
    T_check = [0] * N
    for i in range(N):
        if S_check[i] == 0:
            S_check[i] = 1
            for j in range(i + 1, N):
                if S[i] == S[j]:
                    S_check[j] = 1
                    if T[i] != T[j]:
                        print('No')
                        return
        if T_check[i] == 0:
            T_check[i] = 1
            for j in range(i + 1, N):
                if T[i] == T[j]:
                    T_check[j] = 1
                    if S[i] != S[j]:
                        print('No')
                        return
    print('Yes')


if __name__ == '__main__':
    S = input()
    T = input()
    solve(S, T)

    # # test
    # from random import randint
    # from func import random_str
    # S = 'abcdefghijklmnopqrstuvwxyz' * (2 * 10 ** 5 // 26 + 1)
    # T = 'abcdefghijklmnopqrstuvwxyz' * (2 * 10 ** 5 // 26 + 1)
    # solve(S, T)


Measured memory_bytes: 12408
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    char[] S = scanner.next().toCharArray();
    long[] lr = new long[N], lg = new long[N], lb = new long[N];
    for (int i = 1; i < N; i++) {
      lr[i] = lr[i - 1];
      lg[i] = lg[i - 1];
      lb[i] = lb[i - 1];
      if (S[i - 1] == 'R') lr[i]++;
      if (S[i - 1] == 'G') lg[i]++;
      if (S[i - 1] == 'B') lb[i]++;
    }
    long[] rr = new long[N], rg = new long[N], rb = new long[N];
    for (int i = N - 2; i >= 0; i--) {
      rr[i] = rr[i + 1];
      rg[i] = rg[i + 1];
      rb[i] = rb[i + 1];
      if (S[i + 1] == 'R') rr[i]++;
      if (S[i + 1] == 'G') rg[i]++;
      if (S[i + 1] == 'B') rb[i]++;
    }
    long count = 0;
    for (int i = 0; i < N; i++) {
      switch (S[i]) {
        case 'R':
          count += lg[i] * rb[i] + lb[i] * rg[i];
          for (int j = 0; i - j >= 0 && i + j < N; j++) {
            if (S[i - j] == 'G' && S[i + j] == 'B') count--;
            if (S[i - j] == 'B' && S[i + j] == 'G') count--;
          }
          break;
        case 'G':
          count += lr[i] * rb[i] + lb[i] * rr[i];
          for (int j = 0; i - j >= 0 && i + j < N; j++) {
            if (S[i - j] == 'R' && S[i + j] == 'B') count--;
            if (S[i - j] == 'B' && S[i + j] == 'R') count--;
          }
          break;
        case 'B':
          count += lr[i] * rg[i] + lg[i] * rr[i];
          for (int j = 0; i - j >= 0 && i + j < N; j++) {
            if (S[i - j] == 'R' && S[i + j] == 'G') count--;
            if (S[i - j] == 'G' && S[i + j] == 'R') count--;
          }
          break;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 28564
<?php

fscanf(STDIN, "%d", $n);

if($n == 1){
    echo "Yes";
    exit;
}
for($i=2;$i<10;$i++){
    if(($n % $i) == 0){
        if($n / $i < 10) {
            echo "Yes";
            exit;
        }
    }
}
echo "No";



Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<int> vi;
#define FOR(i,S,E) for(int i=S; i<E; i++)
#define ri(x) scanf("%d", &x)
#define pb push_back
const int MAXN = 1e5+3;
int main() {
    int N;
    ri(N);
    vi a;
    FOR(i,0,N) {
        int inp;
        ri(inp);
        a.pb(inp);
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for(auto itr = a.begin(); itr != a.end(); itr = upper_bound(a.begin(), a.end(), *itr)) {
        auto itr1 = upper_bound(a.begin(), a.end(), *itr);
        int ocs = distance(itr, itr1);
        int x = *itr;
        if (ocs < x) {
            ans += ocs;
        }
        else {
            ans += ocs-x;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    vector<ll> v[10000];
    ll n,k,i,a[10000],z[10000],c,vis[10000]={0},sum,ms,zz,j,ts,ms1,ans[10000],mlen,cycle,cs1,cs2;
    cin>>n>>zz;
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n;i++) a[i]--;
    for(i=0;i<n;i++) cin>>z[i];
    c=0;
    for(i=0;i<n;i++) {
    	if(vis[i]==0) {
    		vis[i]=1;
    		v[c].push_back(i);
    		j=i;
    		while(a[j]!=i) {
    			j=a[j];
    			vis[j]=1;
    			v[c].push_back(j);
			}
			c++;
		}
	}
	for(i=0;i<c;i++) {
		
	//	for(j=0;j<v[i].size();j++) v[i].push_back(v[i][j]);
		
		sum=0;
		for(j=0;j<v[i].size();j++)
			sum+=z[v[i][j]];
		ms=-1000000000000;
		for(j=0;j<v[i].size();j++) {
			ts=0;
			ll ccc=0;
			for(k=j;ccc<v[i].size();k=(k+1)%v[i].size()) {
				ts+=z[v[i][k]];
				ms=max(ms,ts);
				ccc++;
			}
		}
		
	//	cout<<ms<<" "<<sum<<"\n";
		ll l=v[i].size();
		if(zz<=v[i].size() || sum<=0) {
			
			mlen=min(zz,l);
			ms1=-1000000000000;
			for(j=0;j<v[i].size();j++) {
				ts=0;
				ll ccc=0;
				for(k=j;ccc<mlen;k=(k+1)%v[i].size()) {
					ts+=z[v[i][k]];
					ms1=max(ms1,ts);
					ccc++;
				}
			}
			ans[i]=ms1;
			continue;
		}
		
		cycle=zz/v[i].size();
		cs1=cycle*sum;
		cs2=cs1-sum;
		mlen=zz%v[i].size();
		ms1=-1000000000000;
		for(j=0;j<v[i].size();j++) {
			ts=0;
			ll ccc=0;
			for(k=j;ccc<mlen;k=(k+1)%v[i].size()) {
				ts+=z[v[i][k]];
				ms1=max(ms1,ts);
				ccc++;
			}
		}
		ans[i]=max(ms,max(cs1+ms1,cs2+ms));
	}
	sort(ans,ans+c,greater<ll>());
	cout<<ans[0];
}

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

ll f(string t){
  ll res = 0;
  string a = "";
  rep(i, t.size()){
    if (t[i] == '+'){
      res += stoll(a);
      a = "";
    }
    else {
      a += t[i];
    }
  }
  res += stoll(a);
  return res;
}
      

int main(){
  string s;
  cin >> s;
  int n = s.size();
  ll ans = 0;
  for (int bit = 0; bit < (1 << n-1); ++bit){
    string t;
    t += s[0];
    rep(i, n-1){
      if (bit & (1 << i)){
        t += '+';
      }
      t += s[i+1];
    }
    ans += f(t);
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

type unionfind []int

func unionfindInit(n int) unionfind {
	tmp := make([]int, n)
	for i := range tmp {
		tmp[i] = -1
	}
	return tmp
}

func (u unionfind) root(i int) int {
	if u[i] < 0 {
		return i
	}
	u[i] = u.root(u[i])
	return u[i]
}

func (u unionfind) size(i int) int {
	return u[u.root(i)] * -1
}

func (u unionfind) unite(i, j int) {
	ri := u.root(i)
	rj := u.root(j)
	if ri == rj {
		return
	}
	if u[ri] > u[rj] {
		ri, rj = rj, ri
	}
	u[ri] += u[rj]
	u[rj] = ri
	return
}

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &n, &m)

	u := unionfindInit(n)

	for i := 0; i < m; i++ {
		var tmp1, tmp2 int
		fmt.Fscan(r, &tmp1, &tmp2)
		u.unite(tmp1-1, tmp2-1)
	}

	max := 0
	for i := range u {
		if max < u.size(i) {
			max = u.size(i)
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 6304
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner input = new Scanner(System.in);
	String a = input.next();
	String first_letter="";
	first_letter=a.valueOf(a.charAt(0));
	String s=input.next();
	String second_letter=" ";
	second_letter=s.valueOf(s.charAt(0));
	String b = input.next();
	String third_letter="";
	third_letter=b.valueOf(b.charAt(0));
	System.out.println(first_letter + second_letter + third_letter);
}
}


Measured memory_bytes: 26936
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String S=gs();
	    boolean n=false;
	    boolean e=false;
	    boolean w=false;
	    boolean s=false;
	    
	    for (int i=0; i<S.length();i++) {
	    	char c=S.charAt(i);
	    	if(c=='N') {
	    		n=true;
	    	} else if(c=='E') {
	    		e=true;
	    	} else if(c=='W') {
	    		w=true;
	    	} else if(c=='S') {
	    		s=true;
	    	} 
	    }

	    //System.out.println(min);
        if ((n && !s) || (!n && s) || (e && !w) || (!e && w)) {
    	    System.out.print("No");
        }else {
        	System.out.print("Yes");
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35652
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int h, w; cin >> h >> w;
    vector<vector<char> > a(h + 2, vector<char> (w + 2, '#'));
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i < h + 2; i++){
        for(int j = 0; j < w + 2; j++){
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <iostream>
//#include <sstream>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define deb(x) cout << #x" = " << x << '\n'
#define debd(x) pf("%s = %d\n", #x, x)
#define debs(x) pf("%s = %s\n", #x, s)
#define debll(x) pf("%s = %lld\n", #x, x)
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
//bitmask
int onbit(int x, int pos) {x |= (1 << pos); return pos;}
int offbit(int x, int pos) {x &= ~(1 << pos); return x;}
int test(int x, int pos) {return x & (1 << pos);}
int flip(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int onbitall(int x, int pos) {x = (1 << pos)-1; return x;}
//constants
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
//moves
const int dx1[] = {0, 1, 0, -1};
const int dy1[] = {1, 0, -1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy2[] = {-1, 0, 1, -1, 1, -1, 0, 1};


int main() {
//    freopen("input.in", "r", stdin);
	string x;
	int h, w;
	cin >> h >> w;
	vector<string> res;
	fr(i, 0, h) {
		string t;
		cin >> t;
		string he = "#";
		he += t;
		he += "#";
		res.pb(he);
	}
	int len = res[0].size();
	fr(i, 0, len) pf("#");puts("");
	tr(it, res) cout << *it << '\n';
	fr(i, 0, len) pf("#");puts("");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<double>;
using Plane=vector<Point>;
using Polygon=vector<Point>;

bool operator<(const Point &a, const Point &b) {
    return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

struct LineSeg: public pair<Point, Point> {
    LineSeg() {}
    LineSeg(const Point &a, const Point &b) {
        first = a;
        second = b;
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(const Point &p, const double r): p(p), r(r) {}
};

size_t num_ctangent(const Circle &c1, const Circle &c2) {
    double d=abs(c1.p-c2.p);
    double r=min(c1.r, c2.r), R=max(c1.r, c2.r);
    if (R+r < d) {
        return 4;
    } else if (abs(R+r-d) < EPS) {
        return 3;
    } else if (abs(R-r-d) < EPS) {
        return 1;
    } else if (R-r > d) {
        return 0;
    } else {
        return 2;
    }
}

int main() {
    double x, y, r;
    scanf("%lf %lf %lf", &x, &y, &r);
    Circle c1(Point(x, y), r);

    scanf("%lf %lf %lf", &x, &y, &r);
    Circle c2(Point(x, y), r);

    printf("%zu\n", num_ctangent(c1, c2));
    return 0;
}

Measured memory_bytes: 2804