akhauriyash/Code-Regression huggingface dataset:
import kotlin.math.max
import kotlin.math.min

fun main() {
    var nk= readLine()!!.split(" ").map { it.toInt() }
    var a= readLine()!!.split(" ").map { it.toLong() }
    var ans:Long=9223372036854775807
    for (i in 0 until Math.pow(2.toDouble(), nk[0].toDouble()).toInt()){
        var pre:Long=0
        var sum:Long=0
        var hot=0
        for (j in 0 until nk[0]){
            if(i.shr(j)%2==1){
                if (pre>=a[j]){
                    sum+=pre-a[j]+1
                }
                pre= max(pre+1, a[j])
                hot++
            }
            pre= max(pre, a[j])
        }
        if(hot>=nk[1]) ans= min(ans, sum)
    }
    println(ans)
}

Measured memory_bytes: 37792
#include<iostream>
#include<cmath>
#include<map>
using namespace std;
#define lli long long int
int main(){
lli inf=1e9+7;
lli n;
scanf("%lld",&n);
map<lli,int>a;
map<lli,int>::iterator x = a.begin();
for(int i=0;i<n;i++){
	lli s;
	scanf("%lld",&s);
	pair<map<lli,int>::iterator,bool> ret;
	ret=a.insert(make_pair(s,1));
	if(ret.second==false){
			((ret.first)->second)+=1;
			//cout<<(ret.first)->second<<" "<<(ret.first)->second<<endl;

		}
}
//for(auto x:a){
	//cout<<x.first<<x.second<<endl;}
//cout<<"------"<<endl;
lli ans=1;bool f=false;
if(n%2==0){
	map<lli,int>::iterator x=a.begin();
	lli check=1;
	while(check<n){
		if(x->first==1&&x->second!=2){f=true;
			printf("0\n");return 0;}
		 else{
			 if(x->first==check&&x->second==2){
				 check+=2;
				 ans=((ans%inf)*2)%inf;
				 }
				 else{f=true;printf("0\n");return 0;}
			 }
			 ++x;
	}
	//ans=check;
}
else{
	map<lli,int>::iterator x=a.begin();
	lli check=0;
	while(check<n){
		if(x->first==0&&x->second!=1){f=true;
			printf("0\n");return 0;}
		else{
				if(x->first==0&&x->second==1){
					check+=2;
					}
				else{
					if(x->first==check&&x->second==2){check+=2;ans=((ans%inf)*2)%inf;}
					else{f=true;printf("0\n");return 0;}
					}
			}
			x++;
		}
		//ans=check;
	}
	//cout<<ans<<"---"<<n<<endl;
if(f==false){
	printf("%lld\n",(ans%inf));
	}
/*int sum=1;
cout<<"0"<<a[0]<<endl;
cout<<"0"<<a[1]<<endl;
if(a[1]>2){printf("0--\n");return 0;}
if(a[0]>2){printf("0---\n");return 0;}
for(auto x:a){
	if(n%2==0){
		if(x.second!=2&&x.first>0){printf("this");printf("0\n");return 0;}
		}
	}
for(auto x:a){
	cout<<"ENTERED"<<x.first<<x.second<<endl;
	if(x.second==0){continue;}
	sum=(sum%inf*x.second%inf)%inf;}
printf("%d\n",sum);
//cout<<inf<<endl;
*/
	return 0;}


Measured memory_bytes: 4224
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

const long long MOD = (long long)(1e9 + 7);
const long long N = (long long)(500007 * 4);
string s;
int tree[N][30];
vector<int> ans(30);

void init() {
    for(int i=0; i<30; i++) {
        ans[i] = 0;
    }
}

long long powerf(long long a, long long b) {
    long long res = 1;
    while(b > 0) {
        if((b%2 == 1)) {
            res = (res * a) % MOD;
        }
        a = (a * a) % MOD;
        b/=2;
    }
    return res;
}

void buildf(int idx, int l, int r) {
    if(l == r) {
        for(int i=0; i<30; i++) {
            tree[idx][i] = 0;
        }
        tree[idx][s[l] - 'a'] = 1;
        return;
    }
    int mid = (l + r)/2;
    buildf((2*idx)+1, l, mid);
    buildf((2*idx)+2, mid+1, r);
    for(int i=0; i<30; i++) {
        tree[idx][i] = tree[(2*idx)+1][i] + tree[(2*idx)+2][i];
    }
    return;
}

void updatef(int idx, int l, int r, int x, char ch, int val) {
    if((l > x) || (r < x)) {
        return;
    }
    if((l == r) && (r == x)) {
        tree[idx][ch - 'a'] +=val;
        return;
    }
    int mid = (l + r)/2;
    updatef((2*idx)+1, l, mid, x, ch, val);
    updatef((2*idx)+2, mid+1, r, x, ch, val);
    for(int i=0; i<30; i++) {
        tree[idx][i] = tree[(2*idx)+1][i] + tree[(2*idx)+2][i];
    }
    return;
}

void queryf1(int idx, int l, int r, int x, int y) {
    if(l > y || r < x) {
        return;
    }

    if(x <= l && r <= y) {
        for(int i=0; i<30; i++) {
            ans[i] += tree[idx][i];
        }
        return;
    }
    int mid = (l + r)/2;
    queryf1((2*idx)+1, l, mid, x, y);
    queryf1((2*idx)+2, mid+1, r, x, y);
    return;
}

int main() {
    int n;
    cin >> n;
    cin >> s;
    buildf(0, 0, n-1);
    int q;
    cin >> q;
    while(q--) {
        int ty;
        cin >> ty;
        if(ty == 1) {
            int x;
            char ch;
            cin >> x >> ch;
            updatef(0, 0, n-1, x-1, s[x-1], -1);
            s[x-1] = ch; 
            updatef(0, 0, n-1, x-1, s[x-1], +1);
        } else {
            int l, r;
            cin >> l >> r;
            l-=1;
            r-=1;
            init();
            queryf1(0, 0, n-1, l, r);
            int cnt = 0;
            for(int i=0; i<30; i++) {
                if(ans[i] > 0) cnt = cnt + 1;
            }
            cout << cnt << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 125828
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  ll N;
  cin >> N;

  cout << N * (N - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int c,n,k,q,i,a[200001],h[100002]={0};
cin>>n>>k>>q;
c=(q-k);
for(i=0;i<q;i++)
cin>>a[i];
if(k>q)
{
	for(i=0;i<n;i++)
cout<<"Yes"<<endl;
}
else
{
	for(i=0;i<q;i++)
  h[a[i]]++;
  for(i=1;i<=n;i++)
  {
  	if(c<h[i])
  	cout<<"Yes"<<endl;
  	else
  	cout<<"No"<<endl;
  	}
  	}
return 0;
}

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

int main() {
    int N, L;
    cin >> N >> L;
    vector<string> vec(N);
    for (int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < N; i++){
        cout << vec.at(i);
    }
    cout << endl;
    return 0;
}




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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> vec(n);
  for(int i = 0; i < n; i ++){
    cin >> vec.at(i);
  }

  
  ll all_count = 0;
  ll after_count = 0;
  
  for(int i; i < n; i++){
    int num = vec.at(i);
    
    for(int j = 0; j < n; j ++){
      if(num > vec.at(j)){
        if(i < j){
          after_count += 1;
          all_count += 1;
        }else{
          all_count += 1;
        }
      }
    }

  }

  
  ll tento = 0;
  ll tento_2 = 0;
  ll mod = 1000000007;
  
  ll all_count_mod = all_count % mod;
  ll after_count_mod = after_count % mod;
  ll k_mod = k % mod;
  ll k_mod_1 = (k-1) % mod;
  
  ll k_mod_2 = (k*(k-1)/2) % mod;
  
  tento = all_count * k_mod_2 % mod;
  tento_2 = after_count_mod * k_mod % mod;
  tento = (tento + tento_2) % mod;
  
  cout << tento << endl;
  
  
  
  //tento = ((all_count % mod)  * (((k % mod)*((k-1) % mod)/2)) % mod) + ((after_count % mod) * (k % mod));
  //tento = (((all_count % mod)  * ((k % mod)*((k-1) % mod) * 2) % mod) + ((after_count % mod) * (k % mod) % mod)) % mod;

  



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll h;

ll f(ll h)
{
    if (h == 1)
        return 1;
    return 1 + 2 * f(h / 2);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h;
    cout << f(h);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	string st;
	cin >> st;
	deque<char> dq;
	for(auto &c:st) dq.push_back(c);
	int q;
	cin >> q;
	bool reversed = false;
	while(q--){
		int t;
		cin >> t;
		if(t==1){
			reversed = !reversed;
		}
		else{
			int f;
			char c;
			cin >> f >> c;
			if((f==1 and !reversed) or (f==2 and reversed))
				dq.push_front(c);
			else
				dq.push_back(c);
		}
	}
	string ans;
	while(not dq.empty())
		ans.push_back(dq.front()), dq.pop_front();
	if(reversed)
		reverse(all(ans));
	cout << ans << endl;
}


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

int main(){
  int x;
  cin >> x;
  int ans;
  if(x>=400 && x<=599) ans=8;
  else if(x>=600 && x<=799) ans=7;
  else if(x>=800 && x<=999) ans=6;
  else if(x>=1000 && x<=1199) ans=5;
  else if(x>=1200 && x<=1399) ans=4;
  else if(x>=1400 && x<=1599) ans=3;
  else if(x>=1600 && x<=1799) ans=2;
  else ans=1;

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


Measured memory_bytes: 3632
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,sse,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int mod = 1e9 + 7, maxn = 3e5;
int fact[maxn];
ll bp(ll a, ll p) {
	ll r = 1;
	while(p) {
		if(p&1) r = r*1ll*a%mod;
		a=a*1ll*a%mod, p>>=1;
	}
	return r;
}
ll nck(ll n, ll k) {
	if(k > n || k < 0) return 0;
	ll res = fact[n] * bp(fact[k], mod-2)%mod;
	res = res * bp(fact[n-k], mod-2)%mod;
	return res;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	fact[0] = 1;
	for(int i = 1; i < maxn; i++) fact[i] = fact[i-1]*1ll*i%mod;
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	(a *= bp(100, mod-2))%=mod;
	(b *= bp(100, mod-2))%=mod;
	(c *= bp(100, mod-2))%=mod;
	
	ll x = (bp(mod+1-c, mod-2))%mod;
	tie(a, b) = pair<ll, ll>{a*bp(a+b, mod-2)%mod, b*bp(a+b, mod-2)%mod};
	ll ans = 0, t;
	for(int _ = 0; _ < 2; _++, swap(a, b))
	for(int i = n; i < 2*n; i++) {
		t = nck(i - 1, n - 1)*(i*x%mod)%mod;
		t = t*bp(a, n)%mod;
		t = t*bp(b, i-n)%mod;
		ans = (ans + t)%mod;
	}
	cout << ans;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)

template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}
typedef pair<int,int> P ;

int h, w;
int dis[20][20];
char grid[30][30];

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

inline bool inside(int x, int y) {
  return 0 <= x && x < h && 0 <= y && y < w;
}

int bfs(int x, int y) {
  rep(i, h) {
    rep(j, w) {
      dis[i][j] = 100000;
    }
  }
  dis[x][y] = 0;
  queue<P> que;
  que.push(P(x,y));
  while (que.size()) {
    int s, t;
    tie(s,t) = que.front();
    que.pop();
    
    for (int i = 0; i < 4; ++i) {
      int nx = s + dx[i], ny = t + dy[i];
      if (!inside(nx,ny) || grid[nx][ny] == '#') {
        continue;
      }
      if (dis[nx][ny] > dis[s][t] + 1) {
        dis[nx][ny] = dis[s][t] + 1;
        que.push(P(nx,ny));
      }
    }
  }
  int ret = 0;
  rep(i,h) {
    rep(j,w) {
      if (grid[i][j] == '.') {
        chmax(ret, dis[i][j]);
      }
    }
  }
  return ret;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  rep(i,h) {
    rep(j,w) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  rep(i,h) rep(j,w) {
    if (grid[i][j]=='.') {
      chmax(ans, bfs(i,j));
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    int a[n];
    map<int,int> mp;
    ll ans=0;
    rep(i,n){
        cin>>a[i];
        ans+=mp[a[i]];
        ++mp[a[i]];
    }
    rep(i,n){
        ll t=mp[a[i]]-1;
        cout<<ans-t<<endl;
    }
}


Measured memory_bytes: 8320
def main():
    nk = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    tenchi_short = []
    for i in range(len(a)):
        tenchi_short.append([0, 0])
        for j in range(len(a)):
            if a[i] > a[j]:
                if i < j:
                    tenchi_short[i][0] += 1
                else:
                    tenchi_short[i][1] += 1
    sum = [(1 + nk[1]) * nk[1] // 2, (nk[1] - 1) * nk[1] // 2]
    ret = 0
    dividor = int(pow(10, 9) + 7)
    for i in range(len(a)):
        # tmp = 0
        # if nk[1] % 2 == 1:
        #     tmp += ()
        ret += (sum[0] * tenchi_short[i][0] + sum[1] * tenchi_short[i][1]) % dividor
        ret %= dividor
    print(int(ret))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
	int N, L;
	cin >> N >> L;

	vector<string> S(N);
	for(int i=0; i<N; i++)
		cin >> S[i];

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

	for(int i=0; i<N; i++)
		cout << S[i];

	cout << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;

int n;
vector<vector<int>> bitree;

void bfs(int start, vector<int> &c) {
    queue<pair<int, int>> q;
    q.push({start, 0});
    vector<bool> reached(n);
    reached[start] = true;
    while (!q.empty()) {
        auto f = q.front(); q.pop();
        int cur = f.first;
        int count = f.second;
        c[cur] = count;
        for (int v : bitree[cur]) {
            if (!reached[v]) {
                q.push({v, count + 1});
                reached[v] = true;
            }
        }
    }
}

int main() {
    cin >> n;
    bitree.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        a--; b--;
        bitree[a].push_back(b);
        bitree[b].push_back(a);
    }
    vector<int> c1(n), c2(n);
    bfs(0, c1);
    bfs(n - 1, c2);
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (c1[i] <= c2[i]) {
            c++;
        }
    }
    if (c > n / 2)
        cout << "Fennec";
    else
        cout << "Snuke";
    return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>

using namespace std;

static const int MAX = 200000;

int main() {

	int R[MAX],n;
	cin >> n;
	int minv = 0;
	int maxv= -1000000000;

	for (int i = 0; i < n; i++)
	{
		cin >> R[i];
	}
	
	minv = R[0];
		for (int j = 1; j < n; j++)
		{
			maxv = max(maxv,R[j]-minv);
			minv = min(minv, R[j]);
		}
	cout << maxv<<endl;

	return 0;
}


Measured memory_bytes: 3852
#include<stdio.h>

int main(){
  char move1,move2,correct;
  correct = 'A';
  while(scanf("%c,%c",&move1,&move2)!=EOF){
    if(move1 == correct){
      correct = move2;
      continue;
    }
    else if(move2 == correct){
      correct = move1;
      continue;
    }
  }
  printf("%c\n",correct);
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
struct Child
{
    long long A,place;
    bool operator>(Child XYZ) const
    {
        return A>XYZ.A;
    }
};
long long dp[2002][2002];
int main()
{
    long long N;
    cin>>N;
    vector<Child> in(N);
    for(long long i=0;i<N;i++)
    {
        cin>>in[i].A;
        in[i].place=i;
    }
    sort(in.begin(),in.end(),greater<Child>());
    long long ans=0;
    for(long long l=0;l<N;l++)
    {
        for(long long r=0;r<N;r++)
        {
            long long tmp=l+r;
            if(l+r==N)
            {
                ans=max(ans,dp[l][r]);
                break;
            }
            dp[l+1][r]=max(dp[l][r]+abs(in[tmp].place-l)*in[tmp].A,dp[l+1][r]);
            dp[l][r+1]=max(dp[l][r]+abs(in[tmp].place-(N-1-r))*in[tmp].A,dp[l][r+1]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 26248
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef struct{
	int x;
	int y;
}point;
point mp[200],np[1000],up[200];
int c;
int n,m;
int i,j;
int comp(const void* a,const void* b){
	point* p=(point*)a;
	point* q=(point*)b;
	return p->x-q->x;
}
bool search(point a[],int n,int b,int c){
	int r=0;
	int l=n-1;
	int mid;
	for(int k=0;k<20;k++){
		mid=(int)(r+l)/2;
		if(abs(a[mid].x-b)>abs(a[mid+1].x-b))mid=mid+1;
		if(a[mid].x==b){
			while(a[mid].x==b)mid--;
			for(int l=mid+1;a[l].x==b;l++){
				if(a[l].y==c)return true;
			}
			return false;
		}
		else if(a[mid].x>b)l=mid;
		else r=mid;
	}
	return false;
}


int main(){
	while(1){
		scanf("%d",&m);
		if(m==0)return 0;
		for(i=0;i<m;i++){
			scanf("%d %d",&mp[i].x,&mp[i].y);
			if(i!=0){
				mp[i].x-=mp[0].x;
				mp[i].y-=mp[0].y;
			}
		}
		scanf("%d",&n);
		for(i=0;i<n;i++)scanf("%d %d",&np[i].x,&np[i].y);
		qsort(np,n,sizeof(point),comp);
		for(i=0;i<n;i++){
			c=0;
			for(j=1;j<m;j++)if(search(np,n,np[i].x+mp[j].x,np[i].y+mp[j].y)){
				c++;
			}
			if(c==m-1)break;
		}
		printf("%d %d\n",np[i].x-mp[0].x,np[i].y-mp[0].y);
	}
}
	

Measured memory_bytes: 1084
from collections import defaultdict


N = int(input())
dict = defaultdict(int)


def prime_factorize(n):  # nを素因数分解してdictに保存
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    for ai in a:
        dict[ai] += 1


for i in range(1, N + 1):  # N!の素因数分解に相当する
    prime_factorize(i)

ans = 0

# p**4 * q**4 * r**2
for k1, v1 in dict.items():
    for k2, v2 in dict.items():
        for k3, v3 in dict.items():
            if k1 < k2 < k3:
                if v1 >= 2 and v2 >= 4 and v3 >= 4:
                    ans += 1
                if v1 >= 4 and v2 >= 2 and v3 >= 4:
                    ans += 1
                if v1 >= 4 and v2 >= 4 and v3 >= 2:
                    ans += 1

for k1, v1 in dict.items():
    for k2, v2 in dict.items():
        if k1 < k2:
            # p**14 * q**4
            if v1 >= 14 and v2 >= 4:
                ans += 1
            if v1 >= 4 and v2 >= 14:
                ans += 1
            # p**24 * q*2
            if v1 >= 24 and v2 >= 2:
                ans += 1
            if v1 >= 2 and v2 >= 24:
                ans += 1

# p**74
for k1, v1 in dict.items():
    if v1 >= 74:
        ans += 1

print(ans)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define sz(a) int((a).size())
#define endl '\n' // remove for interactive

const int N = 1e5 + 5;
int dp[N];

int main()
{
    ios_base::sync_with_stdio(0); //cant use scanf, printf
    cin.tie(0);cout.tie(0); // no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); // no scientific output
    int n, k; cin>>n>>k;
    vi v;
    rep(i, n)
    {
        int x; cin>>x;
        v.pb(x);
    }
    dp[0] = 0;
    REP(i, 1, n-1)
    {
        int mn = INF;
        REP(j, max(0, i-k), i-1)
        {
            mn = min(mn, dp[j]+abs(v[i]-v[j]));
        }
        dp[i] = mn;
    }
    cout<<dp[n-1];
}



/*before sub
loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
*/

Measured memory_bytes: 1144
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int A; cin >> A;
    string s; cin >> s;

    if(A >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}


Measured memory_bytes: 764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
        StringBuilder str = new StringBuilder();
        int i = 1;
        while (true) {
            int data = Integer.parseInt(br.readLine());
            if (data == 0)
                break;
            str.append("Case ").append(Integer.toString(i)).append(": ")
                .append(Integer.toString(data)).append("\n");
            i++;
        }
        System.out.print(str);
    }
}

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


int main() {
   int n;
   cin>>n;
   
   int a[n],b[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i]>>b[i];
   }
   for(int i=0;i<n-2;i++)
   {
       
               if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2])
               {
                   cout<<"Yes"<<endl;
                   return 0;
               }
   }
   cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<limits>
using namespace std;

int main() {
	
	string str;

	getline(cin, str);

	int size = 0;

	for (int i = 0; str[i] != '\0'; i++) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			printf("%c", str[i] + ('A' - 'a'));
		}
		else if (str[i] >= 'A' && str[i] <= 'Z') {
			printf("%c", str[i] - ('A' - 'a'));
		}else {
			printf("%c", str[i]);
		}
	}
	printf("\n");



	//system("pause");
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for(int i = 0; i<N; i++){
    int A;
    cin >> A;
    vec[i] = A;
  }
  
  bool ans = false;
  int c = 0;
  
  while(true){
   
    for(int i = 0;i < N; i++){
      if(vec[i]%2 > 0){
        ans = true;
        break;
      }
      vec[i] = vec[i] / 2;
      
    }
    if(ans){
      break;
    }
    c++;
  }
  cout << c << endl;
}


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

using namespace std;

const int INF = 1e9;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a)
    cin >> x;
  vector<int> dp(n, INF);
  dp[0] = 0;
  dp[1] = abs(a[1] - a[0]);
  for (int i = 2; i < n; ++i)
    for (auto j : {i - 1, i - 2})
      dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
  cout << dp[n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x, y;
  cin >> x >> y;
  int s[4];
  s[0] = max(x, y) * 2 * c;
  s[1] = 2 * x * c + max(0, y - x) * b;
  s[2] = 2 * y * c + max(0, x - y) * a;
  s[3] = x * a + y * b;
  int ans = s[0];
  rep(i, 4) ans = min(ans, s[i]);
  cout << ans << endl;
  return 0;
}

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

int n, a, imax, m1, m2;

int main(){
	cin >> n;
	cin >> a;
	imax = 0;
	m1 = a;
	m2 = 0;
	for (int i = 1; i < n; ++i){
		cin >> a;
		if (a > m1){
			m2 = m1;
			m1 = a;
			imax = i;
		}
		else if (a > m2){
			m2 = a;
		}
	}
	for (int i = 0; i < n; ++i){
		printf("%d\n", (i != imax) ? m1 : m2);
	}
}


Measured memory_bytes: 1664
fun main(args: Array<String>) {
    val inputLine1 = readLine()!!.split(" ")
    val numberOfCoins = inputLine1[0].toInt()
    val price = inputLine1[1].toInt()

    if (numberOfCoins * 500 >= price) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 37808
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	ll N;
	cin >> N;
	int ans = 1e9;
	ll A, B;
	for (A = 1; A <= 100000; A++)
	{
		B = N / A;
		if (A*B == N)
		{
			string a = to_string(A);
			string b = to_string(B);
			ans = min(ans, max((int)a.size(), (int)b.size()));
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);
	int n, t, s, cnt;
	int[] a;

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    cnt = 0;
	    for(int i = 0; i < n; ++i){
		t = i;
		for(int j = i; j < n; ++j)
		    if(a[j] < a[t]) t = j;

		if(a[t] != a[i]){
		    s = a[i];
		    a[i] = a[t];
		    a[t] = s;
		    ++cnt;
		}
	    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.println(cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 12000
n=int(input())
l=[]
for i in range(n):
  ll=[]
  for j in range(int(input())):
    ll.append(list(map(int,input().split())))
  l.append(ll)


def cobi(x):
  ret=0
  while True:
    if x==0:
      break
    ret+=x%2
    x=x//2
  return ret

def chbi(x,y,z):
  t=int((x&(2**y)))
  if z*(2**y)==t:
    return True
  else:
    return False

max_t=0

for i in range(2**n):
  f=0
  for j in range(n):
    if (2**j)&i:
      for k in l[j]:
        if not chbi(i,k[0]-1,k[1]):
          f=1
          break
      if f:
        break
  if f:
    continue
  max_t=max(max_t,cobi(i))
print(max_t)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if( (abs(b-a)<=d&&abs(c-b)<=d)||abs(c-a)<=d)
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  if(N == 2){
    int A,B;
    cin >> A >> B;
    cout << A+B << endl;
  }else{
    cout << "Hello World" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define lli long long int
#define fw(i, s, e) for (ll i = s; i < e; ++i)
#define fe(i, s, e) for (ll i = s; i <= e; ++i)
#define fb(i, e, s) for (ll i = e; i >= s; --i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define mem(a, i) memset(a, i, sizeof(a))
#define ld long double
#define endl "\n"
#define in(P) \
    ll P;     \
    cin >> P;
int main()
{
    FASTIO
    // L(T)
    {
        in(a);
        in(b);
        fe(x, 1, 1500)
        {
            if (floor(x * 0.08) == a && b == floor(x * 0.1))
            {
                cout << x;
                cout << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3676
#include<iostream>
using namespace std;
int main(){
    int a;
    cin >> a;
    int b[a];
    bool c = true;
    int d =0;
    for(int i = 0;i<a;i++){
        cin >> b[i];
        if(b[i]%2==1){
            c = false;
        }
        b[i] = b[i]/2;
    }
    while(c){
        d++;
        for(int i = 0;i<a;i++){
            if(b[i]%2==1){
                c = false;
                break;
            }
            b[i] = b[i]/2;
        }
    }
    cout <<d;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn ex_gcd(x: i64, y: i64) -> (i64, i64) {
    let mut r0 = x;
    let mut a0 = 1;
    let mut b0 = 0;

    let mut r = y;
    let mut a = 0;
    let mut b = 1;

    while r > 0 {
        let r2 = r0 % r;
        let a2 = a0 - r0 / r * a;
        let b2 = b0 - r0 / r * b;
        r0 = r; r = r2;
        a0 = a; a = a2;
        b0 = b; b = b2;
    }
    (a0, b0)
}

fn mod_inv(x: i64, m: i64) -> i64 {
    let mut a = ex_gcd(x, m).0;
    while a < 0 { a += m; }
    a
}

fn comb(n: i64, k: i64, m: i64) -> i64 {
    if n < k { return 0 }
    if k == 0 { return 1; }
    if k == 1 { return n % m; }
    if n - k < k { return comb(n, n - k, m); }
    (((comb(n - 1, k - 1, m) * n) % m) * mod_inv(k, m)) % m
}

fn main() {
    let mut sc = Scanner::new();
    let n: i64 = sc.cin();
    let k: i64 = sc.cin();
    for i in 1..k+1 {
        put!((comb(n-k+1, i, M) * comb(k-1, i - 1, M)) % M);
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(){
    int num,m, c, i = 0;
    int a[32], n;
    scanf("%d %d", &num, &n);
    m = num;
    while (num>0)
    {
        c = (num % n);
        a[i] = c;
        num = num / n;
        i++;
    }
    printf("%d", i);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
const int N = 1e5+1;
typedef long long ll;
ll a[N];
double b[N];
int main()
{
     int n;
     cin>>n;
     for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    double mid=1.0*a[n]/2,min=1e9;
    ll ans;
    for(int i=1;i<n;i++){
        if(fabs(mid-(1.0*a[n]-1.0*a[i]))<min)
        {
            ans=a[i];
            min=fabs(mid-(1.0*a[n]-1.0*a[i]));
        }
    }
    printf("%lld %lld\n",a[n],ans);
}

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

int main(void){
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++)
        cin>>a[i];
    sort(a,a+N);
    cout<<a[N-1]-a[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
// const int INF = +100100100;
// typedef pair<int,int> P;



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


Measured memory_bytes: 3092
s = input()
baket = {}
answer = 'None'
for i in range(97, 97+26):
  baket[chr(i)] = 0
for j in s:
  baket[j] += 1
for i in range(97, 97+26):
  if baket[chr(i)] == 0:
    answer = chr(i)
    break
print(answer)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	static int[] dx = {1, -1, 0, 0};
	static int[] dy = {0, 0, 1, -1};

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] s = new char[h][w];
		for(int i = 0; i < h ; i++) s[i] = sc.next().toCharArray();
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				if(s[i][j] == '#') {
					int cnt = 0;
					for(int k = 0 ; k < 4 ; k++) {
						int nx = i + dx[k];
						int ny = j + dy[k];
						if(0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '#') {
							cnt++;
						}
					}
					if(cnt == 0) {
						System.out.println("No");
						return;
					}
				}
			}
		}
		System.out.println("Yes");
	}
}


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

int main(){
	int n,m;
	int o[1000],d[1000];
	while(scanf("%d%d",&n,&m),n){
		for(int i=0;i<n;i++) scanf("%d",&o[i]);
		for(int i=0;i<m;i++) scanf("%d",&d[i]);
		int p=0;
		for(int i=1;i<=m;i++){
			p+=d[i-1];
			p+=o[p];
			if(p>=n-1){
				printf("%d\n",i);
				break;
			}
		}
	}
		
}

Measured memory_bytes: 1192
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n=int(input())
	A=list(map(int,input().split()))
	A.sort()
	
	for i in range(n-1):
		if A[i]==A[i+1]:
			print("NO")
			exit(0)
	
	print("YES")
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 75376
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), W = sc.nextInt(), w[] = new int[N], v[] = new int[N];
		long dp[][] = new long[N][W + 1];
		for (int i = 0; i < N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < W + 1; j++) {
				long temp = (i > 0 && j >= w[i]) ? dp[i - 1][j - w[i]] : 0;
				long temp2 = (i > 0) ? dp[i - 1][j] : 0;
				if (j >= w[i])
					dp[i][j] = Long.max(temp + v[i], temp2);
				else
					dp[i][j] = temp2;
			}
		}
		sc.close();
		System.out.println(dp[N - 1][W]);
	}
}


Measured memory_bytes: 126164
import sys
fin = sys.stdin.readline


def initialize_int(adj, s):
    """
    assume that all vertex in {0, 1, 2, ..., N - 1}
    """
    N = len(adj)
    MAX_NUM = float('inf')
    d = [MAX_NUM] * N
    d[s] = 0
    parent = [None] * N
    return d, parent


def relax(d, w, source_v, target_v, parent):
    new_cost = d[source_v] + w[source_v][target_v]
    if new_cost < d[target_v]:
        d[target_v] = new_cost
        parent[target_v] = source_v


# Even if a negative weight exists, bellman-ford can find shortest paths.
# it also detects negative cycles,
# but not every edges that consist the negative cycles is stored.
# time complexity: O(VE + (V^2))
def bellman_ford(adj, w, s):
    d, parent = initialize_int(adj, s)
    # calculate shortest paths
    for _ in range(len(adj)):
        for vertex in range(len(adj)):
            for neighbor in adj[vertex]:
                relax(d, w, vertex, neighbor, parent)

    # detects negative cycles if exist
    negative_cycle_edges = set()
    for vertex in range(len(adj)):
        for neighbor in adj[vertex]:
            if d[neighbor] > d[vertex] + w[vertex][neighbor]:
                negative_cycle_edges.add((vertex, neighbor))
    return d, parent, negative_cycle_edges


N, M = [int(elem) for elem in fin().split()]
adj = [[] for _ in range(N)]
w = [[None] * N for _ in range(N)]

for _ in range(M):
    a, b, c = [int(elem) for elem in fin().split()]
    a -= 1
    b -= 1
    c *= -1
    adj[a].append(b)
    w[a][b] = c

d, parent, negative_cycle_edges = bellman_ford(adj, w, 0)
if len(negative_cycle_edges) > 0:
    # see if there's a path from 0 to this edge via DFS
    stack = [0]
    visited = set()
    visited.add(0)
    reachable_edges = set()
    while stack:
        source = stack.pop()
        for neighbor in adj[source]:
            if (source, neighbor) in negative_cycle_edges:
                reachable_edges.add((source, neighbor))
            if neighbor not in visited:
                visited.add(neighbor)
                stack.append(neighbor)
    # see if there is a path to N - 1
    for _, target in reachable_edges:
        stack = [target]
        visited = set()
        visited.add(target)
        while stack:
            source = stack.pop()
            for neighbor in adj[source]:
                if neighbor == N - 1:
                    print("inf")
                    exit(0)
                if neighbor not in visited:
                    visited.add(neighbor)
                    stack.append(neighbor)
    else:
        print(-d[N - 1])
else:
    print(-d[N - 1])


Measured memory_bytes: 11380
from numpy import zeros

inf = float('inf')

n = int(input())
a = tuple(map(int, input().split()))

dp = zeros((n + 1, 2))
dp[0][1] = -inf
# dp[idx][マイナスを使う必要がある個数]

for i, aa in enumerate(a):
    if aa >= 0:
        dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
        dp[i + 1][1] = max(dp[i][1] + aa, dp[i][0] - aa)
    else:
        dp[i + 1][0] = max(dp[i][1] - aa, dp[i][0] + aa)
        dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)

# print(dp)
print(int(dp[n][0]))


Measured memory_bytes: 23416
#include <iostream>
#include <vector>
#include <climits>

// -------------8<------- start of library -------8<------------------------
struct LowestCommonAncestor {
    const int root, INF, n;
    int size, no;
    std::vector<std::vector<int>> adj;
    std::vector<int> idx;
    std::vector<std::pair<int, int>> dep;

    LowestCommonAncestor(int _n, int _r = 0) :
        root(_r), INF(INT_MAX), n(_n), adj(n), idx(n) {}

    void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); }

    void Dfs(int cur, int p, int d) {
        idx[cur] = no;
        dep[size - 1 + no++] = std::make_pair(d, cur);
        for (int nxt : adj[cur]) {
            if (nxt == p) continue;
            Dfs(nxt, cur, d + 1);
            dep[size - 1 + no++] = std::make_pair(d, cur);
        }
    }

    void Preprocessing() {
        for (size = 1; size < 2 * n - 1; ) size <<= 1;
        dep.assign(2 * size - 1, std::make_pair(INF, INF));

        no = 0;
        Dfs(root, -1, 0);

        for (int i = size - 2; 0 <= i; --i) {
            if (dep[2 * i + 1] < dep[2 * i + 2]) dep[i] = dep[2 * i + 1];
            else dep[i] = dep[2 * i + 2];
        }
    }

    int rmq(int l, int r) {
        std::pair<int, int> res(INF, INF);
        l += size - 1;
        r += size - 1;
        while (l < r) {
            if ((l & 1) == 0) res = std::min(res, dep[l]);
            if ((r & 1) == 0) res = std::min(res, dep[r - 1]);
            l >>= 1;
            r = (r - 1) >> 1;
        }
        return res.second;
    }

    int query(int u, int v) {
        if (idx[v] < idx[u]) std::swap(u, v);
        return rmq(idx[u], idx[v] + 1);
    }
};
// -------------8<------- end of library ---------8-------------------------

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

    // AOJ GRL_5_C: Tree - Lowest Common Ancestor
    int n;
    std::cin >> n;

    LowestCommonAncestor lca(n, 0);
    for (int v = 0, deg, c; v < n; ++v) {
        std::cin >> deg;
        while (deg--) {
            std::cin >> c;
            lca.add_edge(v, c);
        }
    }
    lca.Preprocessing();

    int q, u, v;
    std::cin >> q;
    while (q--) {
        std::cin >> u >> v;
        std::cout << lca.query(u, v) << '\n';
    }

    return 0;
}



Measured memory_bytes: 15584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct data { int t, s, d; } data;
data v[20010];
char c[20010];

int comp(const void* a, const void* b) { return ((data*)a)->t>((data*)b)->t; }

int main(void)
{
    int n, m;
    while (scanf("%d%d", &n, &m), n) {
        int i, res;
        for(i=0;i<m;++i) scanf("%d%d%d", &v[i].t, &v[i].s, &v[i].d);
        qsort(v, m, sizeof(data), comp);

        memset(c, 0, sizeof(c));
        c[1]=1;
        for(i=0;i<m;++i) if (c[v[i].s]) c[v[i].d]=1;

        res=0;
        for(i=1;i<=n;++i) res+=c[i];
        printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 1136
#include<iostream>

int main(){
	while(1){
		int i=0,n,a=0,b=0;
		std::cin>>n;
		if(n==0)break;
		while(i<n){
			int ca,cb;
			std::cin>>ca>>cb;
			if(ca>cb)a+=ca+cb;
			else if(cb>ca)b+=ca+cb;
			else if(ca==cb)a+=ca,b+=cb;
			i++;
		}
		std::cout<<a<<" "<<b<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
'use strict'

function main(inp) {
  inp = inp.trim().split('\n')
  inp[0] = inp[0].split(' ').map(n => Number(n));
  const H = inp[1].split(' ').map(n => Number(n)).sort((a, b) => a - b)
  const N = inp[0][0]
  const K = inp[0][1]

  let ans = 0
  for (let i = 0; i < N - K; i++) {
    ans += H[i]
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 48412
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b,m;
    cin>>k;
    cin>>a>>b;
    m=(b/k)*k;
    if(m>=a)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
#define ll long long
#define pii pair<int,int>
ll A, B, K;
ll ans;
int main(){
    cin >> K >> A >> B;
    if(K < A - 1){
        cout << K + 1 << endl;
        return 0;
    }
    K -= A - 1;
    if(A  + 1 < B){
        ans = A + (B - A) * (K / 2);
        if(K % 2) ans++;
    }else{
        ans += K + A;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s, t; std::cin >> s >> t;
  std::cout << t;
  std::cout << s << std::endl;
  return 0;
}

Measured memory_bytes: 256
import re
s=input()
ans=re.findall(r"((A|T|G|C)+)",s)#先に(が手てくる方から行列が形成される。

if ans==[]:#リストではなくてタプルなので注意・
    print(0)
else:
    #max関数はnumpyでないと一次元に特化していてなかなか思い通りに動かないので
    max=0
    for i in range(len(ans)):
        temp=ans[i][0]
        if len(temp) >= max:
            max=len(temp)
    print(max)

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#define MAX 505
int h,w;
char g[MAX][MAX],A[MAX][MAX],B[MAX][MAX];
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;++i)scanf("%s",g[i]+1);
	memset(A,'.',sizeof(A));
	memset(B,'.',sizeof(B));
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)
			if(g[i][j]=='#')A[i][j]=B[i][j]='#';
	for(int i=1;i<=h;++i)
		for(int j=2;j<w;++j)
			(i&1)?A[i][j]='#':B[i][j]='#';
	for(int i=1;i<=h;++i)A[i][1]=B[i][w]='#';
	for(int i=1;i<=h;++i,puts(""))
		for(int j=1;j<=w;++j)
			putchar(A[i][j]);
	puts("");
	for(int i=1;i<=h;++i,puts(""))
		for(int j=1;j<=w;++j)
			putchar(B[i][j]);
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> kazu(n);
  for (int i = 0; i < n; i++) {
    cin >> kazu.at(i);
  }
  
  int m1 = 0, m2 = 0, ans;
  for (int i = 0; i < n; i++) {
    if (m1 <= kazu.at(i)) {
      m2 = m1;
      m1 = kazu.at(i);
      ans = i;
    }
    else {
      if (m2 <= kazu.at(i)) {
        m2 = kazu.at(i);
      }
    }
  }
  if (m1 == m2) {
    for (int i = 0; i < n; i++) {
      cout << m1 << endl;
    }
  }
  else {
    for (int i = 0; i < n; i++) {
      if (i == ans) {
        cout << m2 << endl;
      }
      else {
        cout << m1 << endl;
      }
    }
  }
}


Measured memory_bytes: 2432
#pragma GCC optimize ("Ofast")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
priority_queue<int> PQ;
int a[2005], rd[2005];
struct graph {
	set<int> S[2005];
	int vs[2005];
	void push(int x, int y) {
		S[x].insert(y);
	}
	void dfs(int nw) {
//		cout << nw << endl;
		vs[nw] = 1;
		auto IT = S[nw].begin();
		while(IT != S[nw].end()) {
//			cout << a[nw] << "0 " << a[(*IT)] << endl; 
			++rd[*IT];
			S[*IT].erase(nw); 
			++IT;
		}
		IT = S[nw].begin();
		while(IT != S[nw].end()) {
			if(vs[*IT]) {++IT; continue;}
			dfs(*IT);
			++IT;
		}
	}
	void tuopu() {
		PQ.push(0);
		while(PQ.size()) {
			int nw = PQ.top();
			if(nw) printf("%d ", a[nw]);
			PQ.pop();
			auto IT = S[nw].begin();
			while(IT != S[nw].end()) {
				--rd[*IT];
				if(rd[*IT] == 0) PQ.push(*IT);
				++IT;
			}
		}
	}
}G;
int n;
int main() {
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
	rep(i, 1, n) rep(j, 1, n) if(i != j && __gcd(a[i], a[j]) != 1) G.push(i, j); 
	rep(i, 1, n) G.push(0, i), G.push(i, 0);
	G.dfs(0);
	G.tuopu();
	return 0;
}

Measured memory_bytes: 119424
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var k = int.Parse(Console.ReadLine());
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var isOk = false;
            for (var i = ab[0]; i <= ab[1]; i++)
            {
                if (i % k == 0)
                {
                    isOk = true;
                    break;
                }
            }
            Console.WriteLine(isOk ? "OK" : "NG");
        }
    }
}


Measured memory_bytes: 28268