akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,l,tmp=1,hen,need,tyo,from,to,add[100],addcnt=0,cntt=0;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>l;
      while(1){
        sum+=tmp;
        cnt++;
        if(sum>=l)break;
        tmp*=2;
      }
      sum-=tmp;
      tyo=cnt;
      hen=(cnt-1)*2;
      need=l-1-sum;
      pos=need;
      cnt=1;
      while(1){
        if(pos==0)break;
        if(cnt>pos){
          if(cnt%2==0){
          cnt/=2;
          }
          add[addcnt++]=cnt;
          pos-=cnt;
          hen++;
          cnt=1;
        }
        cnt*=2;
      }
      cout<<tyo<<" "<<hen<<"\n";
      cnt=1;
      from=1;to=2;
      while(1){
        cout<<from<<" "<<to<<" "<<0<<"\n";
        cout<<from<<" "<<to<<" "<<cnt<<"\n";
        cnt*=2;
        from++;
        to++;
        if(to==tyo+1)break;
      }
      reverse(add,add+addcnt);
      rep(i,addcnt){
        cnt=1;
        cntt=1;
        rep(j,30){
          if(cnt==add[i]){
            ll cost=l-cnt;
            l-=cnt;
            if(l==sum+1)fl=true;
            cout<<cntt<<" "<<tyo<<" "<<cost<<"\n";
            break;
          }
          cnt*=2;
          cntt++;
        }
        if(fl)break;
      }
      

     

       
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  string s;
  for (long long i = 0; i < 33; i++) {
    if (i % 2 == 0) {
      s.push_back('0');
    } else {
      s.push_back('1');
      n -= (1 << (i - 1)) * (-2);
    }
  }
  string t;
  while (n > 0) {
    t.push_back('0' + (n % 2 == 1));
    n /= 2;
  }
  while (t.size() < s.size())
    t.push_back('0');
  string ans;
  for (long long i = 0; i < t.size(); i++) {
    ans.push_back('0' + (s[i] != t[i]));
  }
  bool b = false;
  for (int i = ans.size() - 1; i >= 0; i--) {
    b = ans[i] == '1' || b;
    if (b)
      cout << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    string S; cin >> S;
    bool a = false, b = false;
    REP(i, 3){
        if(S[i] == 'A') a = true;
        else b = true;
    }
    cout << ((a&&b) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
// ??????????????????

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF INT_MAX

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

// ????????¨???????????????????¨???????????§???????
struct Edge {
    int to, cost;
    Edge(int s, int d) : to(s), cost(d) {}
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;

vector<int> dijkstra(Graph &G, int s) {
    int V = G.size();
    vector<int> d(V); fill(d.begin(), d.end(), INF);
    priority_queue<pii, vector<pii>, greater<pii> > que;
    d[s] = 0;
    que.push(pii(0,s));

    while(!que.empty()) {
        pii p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i<G[v].size(); i++) {
            Edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pii(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main() {
    int V, E, r; cin >> V >> E >> r;
    Graph G(V);
    int s, t, d;
    rep(i,0,E) {
        cin >> s >> t >> d;
        G[s].pb(Edge(t, d));
    }

    vector<int> ans = dijkstra(G, r);
    rep(i,0,ans.size()) (ans[i] == INF) ? cout << "INF" << endl : cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 11212
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define per(i,j,k) for(int i = (int)j;i >= (int)k;i --)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0)
#define Decimal fixed<<setprecision(20)
#define int long long
//INSERT ABOVE HERE
typedef double db;
typedef long long ll;
signed main(){
    FAST_IO;
    ll n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}

#define SHOW(x) std::cout << #x << " = " << x << std::endl;


int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);


    int n;
    cin >> n;
    for(int i = 10; i >= 0; --i)
        if ((1 << i) <= n)
            FINAL_OUT(1 << i);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

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

int main()
{
    ll n;
    cin >> n;
    ll h;
    cin >> h;
    ll pre = h;
    ll cnt = 0;
    ll ans = 0;
    for (int i = 1; i < n; i++)
    {
        cin >> h;
        if (h <= pre)
        {
            cnt++;
            chmax(ans, cnt);
        }
        else
        {
            cnt = 0;
        }
        pre = h;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = sum(A)

if S//N*N==S:
    C1 = S//N
    C2 = S//N
else:
    C1 = S//N
    C2 = S//N+1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += (A[i]-C1)**2
    ans2 += (A[i]-C2)**2
#print(ans1,ans2)
print(min(ans1,ans2))

Measured memory_bytes: 38384
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n,k=map(int,input().split())
    A=list(map(int,input().split()))

    for i in range(k):
        B=[0]*(n+1)

        for j in range(n):
            val=A[j]
            B[max(0,j-val)]+=1
            B[min(n,j+val+1)]-=1
        
        B = list(accumulate(B))
        
        A=B[:-1]

        if A==[n]*(n):
            break
    
    

    print(*A)    
    
resolve()

Measured memory_bytes: 210700
n=int(input())
a=[int(i) for i in input().split()]
rate=[0,0,0,0,0,0,0,0,0]
for i in a:
    if i<400:
        rate[0]=1
    elif 400<=i<800:
        rate[1]=1
    elif 800<=i<1200:
        rate[2]=1
    elif 1200<=i<1600:
        rate[3]=1
    elif 1600<=i<2000:
        rate[4]=1
    elif 2000<=i<2400:
        rate[5]=1
    elif 2400<=i<2800:
        rate[6]=1
    elif 2800<=i<3200:
        rate[7]=1
    else:
        rate[8]+=1
color=rate[:8]
x=color.count(1)
color_max=x+rate[8]
if x==0 and rate[8]>0:
    color_min=1
else:
    color_min=x
print('{} {}'.format(color_min,color_max))

Measured memory_bytes: 3064
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
 
	ll A,B,C, K,an=1;
	cin >> A>>B>>C>>K ;
	
	rep(i, K) {
		an *= 2;
	}
	
	cout << A+B+C+(an-1)*Max(A,B,C) << endl;
}

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

using namespace std;

#define ar array
#define ll long long

const ll INF=1e18;

int main (){
	ll n, W;
	cin >> n >> W;
	vector<ll> dp(W+1,0);
	vector<ll> w(n);
	vector<ll> v(n);
	for(int i=0; i<n; ++i) cin >> w[i] >> v[i];
	for(int i=0; i<n; ++i){
		for(int j=W; j>=w[i]; --j) dp[j]=max(dp[j], dp[j-w[i]]+v[i]);
	}
	ll ans=0;
	for(ll i : dp) ans=max(ans,i);
	cout << ans;

	return 0;
}



Measured memory_bytes: 3952
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int sum[3][4040];

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i = 0; i < n; ++i){
  	sum[0][i + 1] = sum[0][i];
  	sum[1][i + 1] = sum[1][i];
  	sum[2][i + 1] = sum[2][i];
  	if(s[i] == 'R')++sum[0][i + 1];
  	else if(s[i] == 'G')++sum[1][i + 1];
  	else ++sum[2][i + 1];
  }

  ll ans = 0;
  for(int i = 0; i < n; ++i){
  	for(int j = i + 1; j < n; ++j){
  		if(s[i] == 'R'){
  			if(s[j] == 'G'){
  				ans += sum[2][n] - sum[2][j + 1];
  				// j - i != k - j
  				if(2 * j - i < n && s[2 * j - i] == 'B')--ans;
  			}
  			else if(s[j] == 'B'){
  				ans += sum[1][n] - sum[1][j + 1];
  				if(2 * j - i < n && s[2 * j - i] == 'G')--ans;
  			}
  		}
  		else if(s[i] == 'G'){
  			if(s[j] == 'B'){
  				ans += sum[0][n] - sum[0][j + 1];
  				if(2 * j - i < n && s[2 * j - i] == 'R')--ans;
  			}
  			else if(s[j] == 'R'){
  				ans += sum[2][n] - sum[2][j + 1];
  				if(2 * j - i < n && s[2 * j - i] == 'B')--ans;
  			}
  		}
  		else if(s[i] == 'B'){
  			if(s[j] == 'R'){
  				ans += sum[1][n] - sum[1][j + 1];
  				if(2 * j - i < n && s[2 * j - i] == 'G')--ans;
  			}
  			else if(s[j] == 'G'){
  				ans += sum[0][n] - sum[0][j + 1];
  				if(2 * j - i < n && s[2 * j - i] == 'R')--ans;
  			}
  		}
  	}
  }

  cout << ans << endl;
  return 0;
}


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

int n, m, point1[1001], sum, ans;
vector<int> point2;

int solve(int start, int end, int border){
    int mid;
    while(1){
        if((end + start) % 2){
            mid = (end + start) / 2 + 1;
        } else{
            mid = (end + start) / 2;
        }

        if(point2[mid] > border){
            end = mid;
        } else{
            start = mid;
        }

        if(end - start == 1){
            if(point2[end] < border){
                return point2[end];
            } else{
                return point2[start];
            }
        }
    }
}

int main(){
    while(cin >> n >> m && n && m){
        for(int i = 0; i < n; i++){
            cin >> point1[i];
        }
        for(int i = 0; i < n + 1; i++){
            for(int j = 0; j < n + 1; j++){
                point2.push_back(point1[i] + point1[j]);
            }
        }

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

        for(int i = 0; i < point2.size(); i++){
            if(point2[i] > m){
                continue;
            }
            ans = max(ans, point2[i] + solve(0, point2.size() - 1, m - point2[i]));
        }

        cout << ans << endl;

        memset(point1, 0, sizeof(point1));
        point2.clear();
        ans = 0;
    }

    return 0;
}

Measured memory_bytes: 5732
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      String T = sc.next();
      
      // 判定
      int lenS = S.length();
      String partT = T.substring(0,lenS);
      String result = "No";
      if(S.equals(partT)){
        result = "Yes";
      }
      
      // 出力
      System.out.println(result);
    }

}

Measured memory_bytes: 35724
#include<stdio.h>
int main(void)
{
	int p[3];
	int j[2];
	int min;
	int s;
	int i;
	
	s=0;
	min=10000;
	for(i=0;i<3;i++){
		scanf("%d",&p[i]);
		if(min>p[i]){
			min=p[i];
		}
	}
	for(i=0;i<2;i++){
		scanf("%d",&j[i]);
	}
	if(j[0]<j[1]){
		s=min+j[0];
	}
	else {
		s=min+j[1];
	}
	printf("%d\n",s-50);
	return 0;
}
	

Measured memory_bytes: 1020
import java.util.Scanner;

import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int [] V = new int[N];
		int [] C = new int [N];
		
		for (int i=0; i<N; i++) {
			V[i] = sc.nextInt();
		}
		int total = 0;
		for (int i=0; i<N; i++) {
			C[i] = sc.nextInt();
			if(V[i]>C[i]) {
				total += V[i] - C[i];
			}
		}
		

		System.out.println(total);
		
		
		
	}
}	


Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		double i=(double)a/(double)b;
 		System.out.printf((a-a%b)/b+" "+a%b+" "+"%.10f",i);
	}
}

Measured memory_bytes: 26496
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int a,b,n;

    while(true){
        cin >> a >> b >> n;
        if(a==0&&b==0&&n==0){
            break;
        }
        ll cnt = 0;
        ll num;
        ll i=0;
        bool flag;
        while(cnt < n){
            num = a+i*b;
            flag = true;
            for(ll j=2;j<=sqrt(a+i*b);j++){
                if((a+i*b)%j==0){
                    flag = false;
                    break;
                }
            }
            if(flag && a+i*b > 1)cnt++;
            i++;
        }
        cout << a+(i-1)*b << endl;
    }
    return 0;
}


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


#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll n, k;
 

int main() {
    cin >> n >> k;
    vector<ll> history;
    vector<ll> ord(n+1, -1);
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    ll c = 1, l = 0;
    {
        int v = 1;
        while (ord[v]==-1) {
            ord[v] = history.size();
            history.push_back(v);
            v = a[v - 1];
        }
        //2回目にきたとき-1回目のとき
        c = history.size() - ord[v];
        l = ord[v];
    }

    if (k < l) cout << history[k] << endl;
    else {
        k -= l;
        k %= c;
        cout << history[l + k] << endl;
    }

    return 0;
}

Measured memory_bytes: 8496
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	int n,d,ice[11];
	
	while(1){
		memset(ice,0,sizeof(ice));
		cin >> n;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> d;
			ice[d]++;
		}
		for(int i=0;i<10;i++){
			if(ice[i] == 0)
				cout << "-";
			for(int j=0;j<ice[i];j++)
				cout << "*";
			cout << endl;
		}
	}
	return 0;
}

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

//奇数の文字を取り出して判定
//偶数の文字を取り出して判定

int main(){
  string step;
  cin >> step;
  bool a =false;
  for(int i=0;i<step.size();i++){
    if(i%2 == 0){
      if(step.at(i)=='R'|| step.at(i)=='U'|| step.at(i)=='D'){
        a =true;
      }else {a=false; break;}}
    else if(i%2 == 1){
      if(step.at(i)=='L'|| step.at(i)=='U'|| step.at(i)=='D'){
        a =true;
        }else {a = false; break;}}}
    if(a){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
 }
   

Measured memory_bytes: 256
A11, A12, A13 = list(map(int, input().split()))
A21, A22, A23 = list(map(int, input().split()))
A31, A32, A33 = list(map(int, input().split()))
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
if A11 in b and A12 in b and A13 in b:
    print("Yes")
elif A21 in b and A22 in b and A23 in b:
    print("Yes")
elif A31 in b and A32 in b and A33 in b:
    print("Yes")
elif A11 in b and A21 in b and A31 in b:
    print("Yes")
elif A12 in b and A22 in b and A32 in b:
    print("Yes")
elif A13 in b and A23 in b and A33 in b:
    print("Yes")
elif A11 in b and A22 in b and A33 in b:
    print("Yes")
elif A13 in b and A22 in b and A31 in b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
//点iの領域は, 線分i-jの垂直2等分線(j≠i, 1≦j≦n)によって作られるが、全体を1としたときの面積は垂直2等分線同士の角度で求められる。
//変形すると、単に方向ベクトルi->j同士(i:固定, j:i以外)の角度で求められる。
//ある方向ベクトルi->j1を基準(Re=1, Im=0)に取り、反時計回りに進む方向を角度(0～2 * PI)正としたときの、方向ベクトルの最大角度
//をA(i, j1)とおくと、X = min(A(i, 1), …, A(i, n)) (2項目はi以外)がPI以上なら「i行目の答え = 0」、
//PI未満なら「i行目の答え = (PI - X) / (2 * PI)」になる。「基準i->j1以外の方向ベクトルの角度値を0超えにしたいこと・第3,4象限」を考慮すると、
//円環数列のテクの応用によって、O(N^2)に落とせる。
//注意点としては、円環数列を作る前に角度をソートする必要があること！！！

#include <iostream>
#include <complex>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef complex<double> P;

double PI = 3.14159265358979;
int n;
P p[100];

int main() {
	int i, j, k;
	cin >> n;
	for (i = 0; i < n; i++) {
		double x, y; cin >> x >> y;
		p[i] = P(x, y);
	}
	
	for (i = 0; i < n; i++) {
		double ang[198];
		int cnt = 0;
		for (j = 0; j < n; j++) {
			if (j == i) continue;
			ang[cnt++] = arg(p[j] - p[i]);
		}
		sort(ang, ang + cnt);
		for (j = 0; j < cnt; j++) {
			ang[cnt + j] = ang[j] + 2 * PI;
		}
		
		double minArg = PI;
		for (j = 0; j < cnt; j++) {
			minArg = min(minArg, ang[j + cnt - 1] - ang[j]);
		}
		double ans = (PI - minArg) / (2 * PI);
		printf("%.14f\n", ans);
	}
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<functional>
using namespace std;

const int mod = 1E+09 + 7;
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int n;
const int N_MAX = 200005;
vector<int> C;
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int c;
        cin >> c;
        C.push_back(c);
    }

    sort(C.begin(), C.end(), greater<int>());
    modint ans(0);
    for(int i = 0; i < n; i++){
        modint nowC(C[i]);
        ans += nowC * modint(2).pow(n) * modint(2).pow(n-1-i) * (modint(2).pow(i) + modint(i) * modint(2).pow(i-1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader stdin = getStdin();
		String[] arr = stdin.readLine().split("");
		for (int i = 0; i < arr.length; i++) {
			if (i % 2 == 0) {
				if (arr[i].equals("L")) {
					System.out.println("No");
					return;
				}
			} else {
				if (arr[i].equals("R")) {
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");

	}

	public static BufferedReader getStdin() {
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		return stdin;
	}

}

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

int main() {

    int a, b, c, d ,i, j, k = 0, l;
    int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

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

    c = 0, d = 1;

    while(1) {
        if(c+1 == d)
            k++;
        if(c+1 == a && d == b)
            break;
        d++;
        if(d > m[c]) {
            d = 1;
            c++;
        }
    }

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

    return 0;
}


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

#define int 		long long
#define vi 			vector <int>
#define si 			set <int>
#define pii 		pair<int,int>
#define fr(n) 		for(__typeof(n) i=0;i<n;i++)
#define rep(i,a,b) 	for(__typeof(b) i=a;i<b;i++)
#define repi(i,b,a) for(__typeof(a) i=b;i>=a;i--)
#define tr(a) 		for(auto it=a.begin();it!=a.end();it++)
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define FAST 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

void solve()
{
	int n;
	cin>>n;
	int ans=1000 - n%1000;
	if(ans==1000)
		ans=0;
	cout<<ans;
}

signed main()
{
	FAST
	int test=1;
	//cin>>test;
	while(test--)
	{
		solve();
	}
	cerr<<endl<<"Time elapsed : "<<time_passed<<endl;
	return 0;
}

Measured memory_bytes: 3792
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    sc.useDelimiter(",|\n");

    int w=sc.nextInt();
    int string[] = new int[w];

    for(int i=0; i<w; i++) string[i] = i+1;

    int n=sc.nextInt();
    int a[] = new int [n];
    int b[] = new int [n];
    int times=0;
    int chg=0;

    while(times<n){
      a[times]=sc.nextInt();
      b[times]=sc.nextInt();

      chg=string[(a[times]-1)];
      string[(a[times]-1)]=string[(b[times]-1)];
      string[(b[times]-1)]=chg;

      times++;
    }

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



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

ll n,k,a[N_MAX];	
ll l;
vector<ll> ks,best; // ks : Kを2進数表記, best : 最適解

ll len(ll K) {
	// Kを２進数表記したときの桁数
	int cnt = 1;
	while(K>=2) {
		K /= 2;
		cnt++;
	}
	return cnt;
}

ll f(ll x) {
	// f(x)を計算する O(n)
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ans += x ^ a[i];
	}
	return ans;
}

ll make(ll i) {
	// l-1 ~ i+1 bitはks
	// iは0 (書く必要はない)
	// i-1 ~ 0 bitはbest
	ll ans = 0;
	for (ll j = 0; j < i; j++) {
		if (best[j]) {
			ans |= (1ll << j);
		}
	}
	for (ll j = i+1; j < l; j++) {
		if (ks[j]) {
			ans |= (1ll << j);
		} 
	}
	return ans;
}

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

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

	for (ll i=0; i<l;i++) {	// iは桁数を表す
		int cnt0 = 0, cnt1 = 0;
		for (ll j=0; j<n;j++) { // jはa配列のどれを巡っているかを表す
			if (a[j] & (1ll << i)) {
				cnt1++;
			} else {
				cnt0++;
			}
		}
		if (cnt1 >= cnt0) {
			best.push_back(0);
		} else {
			best.push_back(1);
		}
	}

	for (ll i=0; i<l;i++) {
		ks.push_back(k&(1ll<<i));
	}

	// rep(i, (int)ks.size()) {
	// 	cout << ks[i];
	// }
	// cout << endl;

	// K以下で最適解探す
	ll ma = f(k);
	for (ll i=0; i<l; i++) {
		if (ks[i]) {
			ma = max(ma, f(make(i)));
		}
	}

	cout << ma << endl;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        if (1 < Math.abs(N-M)) {
            System.out.println(0);
            return;
        }
        long x = f(N);
        long y = f(M);
        long answer = (x * y) % 1000000007;
        if (Math.abs(N-M) == 0) {
            answer = answer * 2 % 1000000007;
        }
        System.out.println(answer);
    }
    private static long f(long x) {
        long answer = 1;
        for(; 1 <= x; x--) {
            answer = answer * x % 1000000007;
        }
        return answer;
    }
}


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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 1e5+34;
const ll inf = 1e18+7;
vi adj[MAX];
ll dp[MAX][3];

void dfs(ll u, ll parent){
  dp[u][0] = dp[u][1] = 1;
  for(auto v: adj[u]){
    if(v == parent) continue;
    dfs(v,u);
    dp[u][0] = (dp[u][0]*dp[v][1])%mod;
    dp[u][1] = (dp[u][1]*(dp[v][0]+dp[v][1])%mod)%mod;
  }
}

int main(){
  fastio;
  ll n,x,y;
  cin>>n;
  f(i,0,n-1){
    cin>>x>>y;
    x--;y--;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  dfs(0,0);
  cout<<(dp[0][0]+dp[0][1])%mod<<"\n";
  return 0; 
}

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

int main() {
    long long n, k, ret = 0, tmp;
    std::cin >> n >> k;
    std::vector<long long> a(n), s(n), t(n);

    for (long long i = 0; i < n; i++) {
        std::cin >> a[i];
        s[i] = (i>0?s[i-1]:0) + a[i];
        t[i] = (i>0?t[i-1]:0) + std::max(0ll, a[i]);
    }
    
    for (long long i = 0; i < n - k + 1; i++) {
        ret = std::max(ret, std::max(s[i + k - 1] - s[i] + a[i], 0ll) + t[i] - std::max(0ll, a[i]) + t[n-1] - t[i+k-1]);
    }

    std::cout << ret << std::endl;

    return 0;
}

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

using namespace std;

int main() {
  
  int n;
  cin >> n;
  
  int vals[n];
  int result[n];
  
  for (int i = 0; i < n; i++) {
    cin >> vals[i];
  }
  
  result[0] = 0;
  result[1] = abs(vals[0] - vals[1]);
  
  for (int i = 2; i < n; i++) {
  	int fromOneStep = result[i-1] + abs(vals[i] - vals[i-1]);
    int fromTwoStep = result[i-2] + abs(vals[i] - vals[i-2]);
    result[i] = min(fromOneStep, fromTwoStep);
  }
  
  cout << result[n-1] << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::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==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};



int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s.pb('#');
    int ans = 0;
    rep(i,s.size()-1) if(s[i] != s[i+1]) ans++;
    print(ans);
}

Measured memory_bytes: 512
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int i = 0;
    while (N >= (1 << (i + 1)))
    {
        i++;
    }
    cout << (1 << i) << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	//vector<pair<pair<ll, ll>, ll>> seg(N);
	ll Seg[360] = { 0 };
	for (int i = 0; i < N;i++) {
		ll M, D, S, V; cin >> M >> D >> V >> S; D--;
		for (int j = 0; j < V;j++) {
			Seg[((M - 1) * 30 + D + j) % 360] = max(Seg[((M - 1) * 30 + D + j) % 360], S);
		}
		for (int j = 1; j <= S; j++) {
			Seg[((M - 1) * 30 + D - j + 360 * 2) % 360] = max(Seg[((M - 1) * 30 + D - j + 360 * 2) % 360], S - j);
			Seg[((M - 1) * 30 + D + V + j - 1) % 360] = max(Seg[((M - 1) * 30 + D + V + j - 1) % 360], S - j);
		}
	}
	ll ans = INF;
	for (int i = 0;i < 360; i++) {
		ans = min(ans, Seg[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3188
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 1e5+9;

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    string str;
    cin>>str;

    for(i=0;i<3;i++)
    {
        if(str[i]=='R')
        {
            y++;
        }
        else
        {
            x =  max(x,y);
            y = 0;
        }
    }
    x =  max(x,y);
    cout<<x<<endl;
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vi a(n);
    rep(i,n) cin>>a[i];
    ll sum=0;
    rep(i,n) sum+=a[i];
    sort(all(a));
    int cnt=0;
    rep(i,n){
        if (4*m*a[i]>=sum) cnt++;
    }
    if (cnt>=m){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


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

int main() {
    int w, h; cin >> w >> h;
    long long ans = 0;
    vector<pair<long long, int>> v;
    for (int i = 0; i < w; i++) {
        long long p; cin >> p;
        v.emplace_back(p, 0);
    }
    for (int i = 0; i < h; i++) {
        long long q; cin >> q;
        v.emplace_back(q, 1);
    }
    sort(v.begin(), v.end());
    for (auto x: v) {
        int type = x.second;
        long long d = x.first;
        if (type) {
            if (w >= 0) ans += d * (w+1);
            h--;
        } else {
            if (h >= 0) ans += d * (h+1);
            w--;
        }
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6512
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] list = S.toCharArray();
      
       if(list.length == 2){
         System.out.println(S);
       }else{
         for(int i = list.length-1; i >= 0; i-- ){
           System.out.print(list[i]);
         }
          System.out.println();
       }
	}

}

Measured memory_bytes: 35592
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  ll n,k,s;
  cin >> n >> k >> s;

  std::vector<ll> a(n,1000000000);

  if(s==1000000000){
    for(ll i=0;i<n;i++){
      a.at(i)=1;
    }

    for(ll i=0;i<k;i++){
      a.at(i)=s;
    }
    
  }


  else{for(ll i=0;i<k;i++){
    a.at(i)=s;
  }
}

for(ll i:a){
  cout << i << endl;
}
  }

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

int main()
{
    ll x; cin >> x;
    
    ll quotient = x / 11LL;
    ll mod = x % 11LL;

    ll ans = quotient * 2;
    
    if (6LL < mod) {
        ans += 2LL;
    }
    else if (mod == 0LL) {
    }
    else {
        ans += 1LL;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
"use strict"
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_string = '';

process.stdin.on('data', function (chunk) {
    input_string += chunk;
});
const space_input = function (line) {
    var arr = line.replace(/(^\s+)|(\s+$)/g, "").split(" ");
    for (var i = 0; i < arr.length; ++i) {
        arr[i] = +arr[i];
    }
    return arr;
};
const space_input_char = function (line) {
    var arr = line.replace(/(^\s+)|(\s+$)/g, "").split(" ");
    for (var i = 0; i < arr.length; ++i) {
        arr[i] = arr[i];
    }
    return arr;
};

process.stdin.on('end', function () {
    const lines = input_string.split('\n');
    const wh = space_input(lines[0])
    const H = wh[0]
    const W = wh[1]
    const t = lines.slice(1).filter(v=>v.length>0).map(l=>l.split(""))
    let res = []
    let mawari = []
    for(let i=-1;i<=1;++i){
        for(let j=-1;j<=1;++j){
            if(i!=0||j!=0){
                mawari.push([i,j])
            }
        }
    }
   // console.log(t)
    for(let h=0;h<H;++h){
        for(let w=0;w<W;++w){
            //console.log(h,w)
            if(t[h][w]==="."){
                let cnt=0
                for(let m of mawari){
                    //console.log(h+m[0])
                    if((h+m[0])<H&&0<=h+m[0] && ((w+m[1])<W)&&0<=w+m[1]){
                        if(t[h+m[0]][w+m[1]]==="#"){
                            cnt++
                        }
                    }
                }
                t[h][w]=cnt
            }
        }
        console.log(t[h].join(""))
    }
    
});

Measured memory_bytes: 10144
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;

int main(){
	int n,k;
	cin>>n>>k;
	vi a(n+1);
	vi dp(n+1,inf);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dp[1]=0;
	for(int i=2;i<=n;i++){
		for(int cnt=1;cnt<=k && i-cnt>=1;cnt++){
			dp[i]=min(dp[i],dp[i-cnt]+abs(a[i]-a[i-cnt]));
		}
	}
	cout<<dp[n];

	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

template<class T>bool ch1000000(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }





int main() {
  ll N, M, K;
  cin >> N >> M >> K;

  vector<ll> A(N+1), B(M+1);
  A[0] = 0;
  B[0] = 0;

  for(ll i = 1; i <= N; i++){
    ll Ai;
    cin >> Ai;
    A[i] = Ai + A[i-1];
  }
  for(ll i = 1; i <= M; i++){
    ll Bi;
    cin >> Bi;
    B[i] = Bi + B[i-1];
  }
  
  ll ia = 0;
  for(ll i = 1; i <= N; i++){
    if(A[i] <= K){
      ia = i;
    }else{
      break;
    }
  }
  ll ib = 0;
  for(ll i = 1; i <= M; i++){
    if(A[ia] + B[i] <= K){
      ib = i;
    }else{
      break;
    }
  }

  ll ans = ia + ib;

  for(ll i = ia; i >= 0; i--){
    for(ll j = ib; j <= M; j++){
      if(A[i] + B[j] <= K){
        ans = max(ans, i+j);
      }else{
        ib = j;
        break;
      }
    }
  }

  cout << ans << endl;


  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 6368
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll k; cin >> k;
    vector<ll> ans(50);
    ll n = k / 50, l = k % 50;
    rep(i,50){
        ans[i] = n + (51 - l + i) % 51;
    }

    cout << 50 << endl;
    for(auto i : ans)cout << i << " ";
    cout << endl;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = ril()
res = 0
minval = float('inf')
for x in ls:
    if x < minval:
        res += 1
        minval = x
print(res)

Measured memory_bytes: 25456
n = gets.to_i
max = 0;b = 0
a = gets.split(" ").map!{|i| i.to_i}
(n-1).times do |j|
  (j+1).upto(n-1) do |k|
    b = (a[j] - a[k]).abs
    if b > max
      max = b
    end
  end
end
puts max



Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main()
{
    int a,b,x;
    cin>>a>>b;
    if (b/10==0)
        x=a*10+b;
    else{if (b/100==0)
            x=a*100+b;
         else
            x=a*1000+b;
    }
    for (int i=1;i*i<=x;i++)
    {
        if (i*i==x)
        {cout<<"Yes"<<endl;
        system("pause");
        return 0;}
    }
    cout<<"No"<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
string s,t;
int n,m;
int dp[3030][3030];
int dfs1(int x,int y){
  int &res=dp[x][y];
  if(~res) return dp[x][y];
  res=0;
  if(x<n&&y<m) chmax(res,dfs1(x+1,y+1)+(s[x]==t[y]));
  if(x<n) chmax(res,dfs1(x+1,y));
  if(y<m) chmax(res,dfs1(x,y+1));
  return res;
}

void dfs2(int x,int y){
  if(x==n||y==m) return;
  if(dfs1(x,y)==(dfs1(x+1,y+1)+1)&&(s[x]==t[y])){
    cout<<s[x];
    dfs2(x+1,y+1);
    return;
  }
  if(dfs1(x,y)==dfs1(x+1,y)){
    dfs2(x+1,y);
    return;
  }
  if(dfs1(x,y)==dfs1(x,y+1)){
    dfs2(x,y+1);
    return;
  }
  assert(0);
}

signed main(){
  cin>>s>>t;
  n=s.size();
  m=t.size();
  memset(dp,-1,sizeof(dp));
  dfs1(0,0);
  dfs2(0,0);
  cout<<endl;
  return 0;
}


Measured memory_bytes: 36608