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

#define abs(N) ((N>0)?N:-1*N)
#define min(A,B) ((A>B)?B:A)
#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

int main() {
	int a,b,res;
	char op;
	while(true){
		cin >> a >> op >> b;

		if(op=='?') break;

		switch(op){
		case '+':
			res = a+b;break;
		case '-':
			res = a-b;break;
		case '*':
			res = a*b;break;
		case '/':
			res = a/b;break;
		}
		println(res);
	}


	return 0;
}



Measured memory_bytes: 3056
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
const ll inv2=5e8+4;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
vector<int> g[5000];
int n;
int ct[5000];
bool used[5000];
ll dp[2][5000][5000];
ll f[5001], invf[5001], p2v[5001];
ll calc(int x){
  return f[x]*invf[x/2]%MOD*p2v[x/2]%MOD;
}
void dfs(int x){
  used[x]=1;
  ct[x]=1;
  int par=-1;
  for(auto y:g[x]){
    if(used[y]){
      par=y;
      continue;
    }
    dfs(y);
    ct[x]+=ct[y];
  }
  vector<ll> dp1[2][2];
  for(int i=0; i<=ct[x]; i++){
    dp1[0][0].push_back(0);
    dp1[1][0].push_back(0);
    dp1[0][1].push_back(0);
    dp1[1][1].push_back(0);
  }
  dp1[0][0][0]=1;
  int t=0, sum=0;
  for(auto y:g[x]){
    if(y==par) continue;
    t=1-t;
    for(int i=0; i<=ct[x]; i++){
      dp1[1][t][i]=0;
      dp1[0][t][i]=0;
    }
    for(int i=0; i<=sum; i+=2){
      for(int j=0; j<=ct[y]; j+=2){
        if(i+j>ct[x]) continue;
        dp1[1][t][i+j]+=(dp1[1][1-t][i]*dp[0][j][y]%MOD);
        dp1[1][t][i+j]+=(dp1[0][1-t][i]*dp[1][j][y]%MOD);
        dp1[0][t][i+j]+=(dp1[1][1-t][i]*dp[1][j][y]%MOD);
        dp1[0][t][i+j]+=(dp1[0][1-t][i]*dp[0][j][y]%MOD);
        dp1[1][t][i+j]%=MOD;
        dp1[0][t][i+j]%=MOD;
      }
    }
    if(ct[y]&1){
      sum+=ct[y];
      continue;
    }
    for(int i=0; i<=sum; i+=2){
      for(int j=0; j<=ct[y]; j+=2){
        dp1[1][t][i+ct[y]]+=(dp1[0][1-t][i]*dp[0][j][y]%MOD*calc(ct[y]-j)%MOD);
        dp1[1][t][i+ct[y]]+=(dp1[1][1-t][i]*dp[1][j][y]%MOD*calc(ct[y]-j)%MOD);
        dp1[0][t][i+ct[y]]+=(dp1[0][1-t][i]*dp[1][j][y]%MOD*calc(ct[y]-j)%MOD);
        dp1[0][t][i+ct[y]]+=(dp1[1][1-t][i]*dp[0][j][y]%MOD*calc(ct[y]-j)%MOD);
        dp1[1][t][i+ct[y]]%=MOD;
        dp1[0][t][i+ct[y]]%=MOD;
      }
    }
    sum+=ct[y];
  }
  for(int i=0; i<=ct[x]; i+=2){
    dp[0][i][x]=dp1[0][t][i];
    dp[1][i][x]=dp1[1][t][i];
  }
}
int main()
{
	cin>>n;
  for(int i=0; i<n-1; i++){
    int x, y; cin>>x>>y;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  f[0]=1; p2v[0]=1;
  for(ll i=1; i<=n; i++){
    f[i]=f[i-1]*i%MOD;
    p2v[i]=p2v[i-1]*inv2%MOD;
  }
  invf[n]=inv(f[n]);
  for(ll i=n-1; i>=0; i--){
    invf[i]=invf[i+1]*(i+1)%MOD;
  }
  dfs(0);
  ll ans=0;
  for(int i=0; i<=n; i+=2){
    ans+=(dp[0][i][0]*calc(n-i)%MOD);
    ans+=(MOD-dp[1][i][0]*calc(n-i)%MOD);
    ans%=MOD;
  }
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 341352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef long double ldbl;

ll l[101];

int main() {
  l[0] = 2;
  l[1] = 1;

  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    l[i] = l[i - 1] + l[i - 2];
  }
  printf("%lld", l[n]);

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace DPL_1B_1{
    public class Program{
        public static void Main(string[] args){
            var input = Console.ReadLine().Split(' ');
            var n = int.Parse(input[0]);
            var max = int.Parse(input[1]);

            var goodslist = new HashSet<Goods>();
            for(var i = 0; i < n; i++){
                var tmp = Console.ReadLine().Split(' ');
                goodslist.Add(new Goods(int.Parse(tmp[0]), int.Parse(tmp[1])));
            }

            var dp = new int[max + 1];
            for(var i = 1; i <= max; i++){
                foreach(var goods in goodslist){
                    if(i >= goods.Weight){
                        dp[i] = Math.Max(dp[i], dp[i - goods.Weight] + goods.Value);
                    }
                }
            }

            Console.WriteLine(dp[max]);
        }
    }

    public class Goods{
        public Goods(int value, int weight){
            Value = value;
            Weight = weight;
        }

        public int Value;
        public int Weight;
    }
}

Measured memory_bytes: 9784
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}


fun main() {
    val N = nextInt()
    val a = N % 1000
    println(if (a == 0) 0 else (1000 - a))
}

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

int main() { 
  int h,w,d;
  cin >> h >> w >> d;
  vector<P> mp(h*w);
  vi cost(h*w,-1);
  rep(i,h){
    rep(j,w){
      int id;
      cin >> id;
      id--;
      mp[id] = P(i,j);
    }
  }
  rep(i,d)cost[i] = 0;
  rep(i,d){
    for(int j = i;j<h*w;j+=d){
      if(j+d>=h*w) continue;
      int diff = abs(mp[j].fi - mp[j+d].fi)+abs(mp[j].se-mp[j+d].se);
      cost[j+d] = cost[j]+diff;
    }
  }
  //rep(i,h*w)show(cost[i]);
  int q;
  cin >> q;
  vi ans;
  rep(i,q){
    int l,r;
    cin >> l >> r;
    l--;r--;
    ans.push_back(cost[r]-cost[l]);
  }
  for(auto e : ans)cout<<e<<endl;
  return 0;
}

Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();

        for (long i = 0; i < k; i++) {
            a /= 2;
            b += a;
            long wk = a;
            a = b; b = wk;
        }
        if (k % 2 != 0) {
            long wk = a;
            a = b;
            b = wk;
        }

        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 22612
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

puts get_i.sort[..1].inject(:+)

Measured memory_bytes: 14316
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

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

	string s;
	string ans;

	cin >> s;

	for (int i = 0; i < s.length(); i+=2) {
		ans += s[i];
	}

    cout << ans << endl;

	return 0;
}


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

int main(){
  int n;
  cin >>n;
  ll sum = 0;
  for(int i = 1; i<=n; i++){
    if(i%3!=0 && i%5!=0) sum += i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3568
n, m = map(int, input().split())
a = list(map(int, input().split()))
import numpy as np
asun = np.array(a)
suma = asun.sum()
a.sort(reverse=True)
cnt = 0
ans = 'Yes'
for aa in a:
  cnt += 1
  if aa < suma/(4*m):
    ans = 'No'
    break
  if cnt == m:
    break
print(ans)

Measured memory_bytes: 21644
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
 
int R, G;
 
int main()
{
	in >> R >> G;
	out << G * 2 - R << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    sc.nextLine()
    //    check the difference between array and list
    val heights: Array[Int] = sc.nextLine().split(" ").map { s => s.toInt }

    @annotation.tailrec
    def go(n: Int, maxHeight: Int, niceViewsNumber: Int): Int = {
      if (n == heights.length)
        niceViewsNumber
      else {
        if (heights(n) >= maxHeight) {
          go(n + 1, heights(n), niceViewsNumber + 1)
        } else {
          go(n + 1, maxHeight, niceViewsNumber)
        }
      }
    }

    println(go(0, 0, 0))
  }
}

Measured memory_bytes: 27312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  map<ll,ll> mp;
  for(ll i=0;i<N;i++){
    ll x;
    cin>>x;
    mp[x]+=1;
  }
  
  ll ans;
  cin>>ans;
  for(ll i=0;i<ans;i++){
    ll x;
    cin>>x;
    mp[x]-= 1;
  }
  
  for(auto m:mp){
    if(mp[m.first] < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<long long,long long> ii;
vector<pair<long long,ii>> edge;
long long n,up[100005],sz[100005];
pair<ii,long long> x[100005];

bool cmp(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.fi<b.fi.fi;
}
bool cmp1(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.se<b.fi.se;
}
int findSet(int x){
    if(x==up[x]) return x;
    else return findSet(up[x]);
}
void unionSet(int x,int y){
    long long x1=findSet(x),y1=findSet(y);
    if(sz[x1]<sz[y1]) swap(x1,y1);
    up[y1]=x1;
    sz[x1]+=sz[y1];
}
bool checkSet(int x,int y){
    long long x1=findSet(x),x2=findSet(y);
    if(x1==x2)
        return 1;
    else
        return 0;
}
int main(){
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i].fi.fi>>x[i].fi.se;
        x[i].se=i;
    }
    sort(x+1,x+1+n,cmp);
    for(int i=1;i<=n;i++){
        up[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(val,mp(x1,x2)));
    }
    sort(x+1,x+1+n,cmp1);
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(val1,mp(x1,x2)));
    }
    long long sum=0;
    sort(edge.begin(),edge.end());
    for(int i=0;i<edge.size();i++){
        long long x1=edge[i].se.fi,x2=edge[i].se.se;
        if(checkSet(x1,x2)==0){
            unionSet(x1,x2);
            sum+=edge[i].fi;
        }
    }
    cout<<sum;
}


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

#define MOD 1000000007

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
    // Your code here!
    long long n, m;
    long long edges[100001][2] = {{}};
    long long inconvenience[100001] = {};
    
    cin >> n >> m;
    for(long long i = 0; i < m; i++)
        cin >> edges[i][0] >> edges[i][1];
        
    UnionFind u(n);
    long long num_nodes[100001];
    
    for(long long i = 0; i < n; i++)
        num_nodes[i] = 1;
        
    inconvenience[m] = (n * n - n) / 2;
    for(long long i = m - 1; 0 <= i; i--){
        long long r1 = u.root(edges[i][0]-1);
        long long r2 = u.root(edges[i][1]-1);
        
        if(r1 != r2){
            inconvenience[i] = inconvenience[i+1] - num_nodes[r1] * num_nodes[r2];
            num_nodes[r1] = num_nodes[r2] = num_nodes[r1] + num_nodes[r2];
            u.unite(r1, r2);
        }
        else
            inconvenience[i] = inconvenience[i+1];
    }
    
    for(long long i = 1; i < m + 1; i++){
        cout << inconvenience[i] << endl;
    }
}


Measured memory_bytes: 4864
//In the name of god
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second

using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
const int maxn = 400;

int mat[maxn][maxn];
vector<pii> g[maxn];
int dist[maxn];
int n;
int getm(int st,int en){
	for (int i= 1;i<= n;i++){
		dist[i] = 2e10;
	}
	dist[st] = 0;
	priority_queue<pii> q;
	q.push({0,st});
	int u,d;
	
	while(!q.empty()){
		u = q.top().S;q.pop();
		if (u == en) return dist[en];
		for (pii e : g[u]){
			if (dist[e.F] > dist[u] + e.S){
				dist[e.F] = dist[u] + e.S;
				q.push({-dist[e.F],e.F});
			}
		}
	}


	return dist[en];
}
int32_t main(){
	ios_base::sync_with_stdio(0) , cin.tie(0);
	cin >> n;
	int dist;
	vector<pair<int,pii> > v1;
	for (int i = 0;i < n;i++){
		for (int j  = 0;j < n;j++){
			cin >> dist;
			if (i < j)
			v1.pb({dist,{i+  1,j + 1}});
		
		}
	}
	sort(v1.begin(),v1.end());
	int u,v,d;
	int cc = 0;
	for (int i = 0;i < v1.size();i++){
		d = v1[i].F;
		u = v1[i].S.F;
		v = v1[i].S.S;
		int d1 = getm(u,v);
	//	cout << u << ' ' << v << endl;
		if (d1 < d){
			cout << -1 << endl;
			return 0;
		}else if (d1 == d) continue;
		else{
			cc += d;
			g[u].pb({v,d});
			g[v].pb({u,d});
		}
	}
	cout << cc << endl;
	return 0;
}

Measured memory_bytes: 1912
n = int(input())
a = [10 ** 1,10 ** 2,10 ** 3,10 ** 4,10 ** 5]
if n in a:
    print(10)
    exit(0)

l = 10 ** 5
for i in range(1,n):
    m = n
    p = i
    q = m - 1
    z = 0
    while p > 0:
        z += p % 10
        p = p // 10
    while q > 0:
        z += q % 10
        q = q // 10
    l = min(l,z)

print(l)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main(){
  string s;
  cin >> s;
  if(s.back() == 's') {
    s.push_back('e');
    s.push_back('s');
  } else {
    s.push_back('s');
  }
  cout << s << endl;
  return 0;
}


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

int main(){
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int sum = 0;
  rep(i,n) sum += a[i];
  if (sum >= h) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

string board[60];
int main(void){
    int h, w;
    cin >> h >> w;

    const int dh[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    const int dw[8] = {0, 1, 1, 1, 0, -1, -1, -1};


    for (int i = 0; i < h;i++){
        cin >> board[i];
    }

    for (int i = 0; i < h;i++){
        for (int j = 0; j < w;j++){
            if(board[i][j]=='.'){
                int cnt = 0;
                for (int k = 0; k < 8;k++){
                    int y = i + dh[k];
                    int x = j + dw[k];
                    //カウントされる場合を書き出し
                    if(y>=0&&y<h&&x>=0&&x<w&&board[y][x]=='#')
                        cnt++;
                }
                board[i][j] = '0' + cnt;
            }
        }
    }
    for (int i = 0; i < h;i++){
        cout << board[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#define INF (1<<21)
using namespace std;

int main(){
  int i,j,n,a[27],s,t,G[27][27],d[27];
  string str;
  bool f,v[27],fa[27];
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<27;i++){
      a[i] = 0;
      d[i] = INF;
      fa[i] = false;
      v[i] = false;
      for(j=0;j<27;j++) G[i][j] = INF;
    }

    for(i=0;i<n;i++){
      cin >> str;
      s = str[0]-'a';
      t = str[str.size()-1]-'a';
      a[s]++;
      a[t]--;
      v[s] = true;
      v[t] = true;
      G[s][t] = G[t][s] = 1;
    }

    d[s] = 0;
    while(1){
    int min = INF;
     int p;
      for(i=0;i<27;i++){
	if(!fa[i] && d[i] < min){
	  min = d[i];
	  p = i;
	}
      }
      if(min == INF) break;
      fa[p] = true;
      for(i=0;i<27;i++){
	if(fa[i] || !v[i]) continue;
   	if(G[p][i] < d[i]) d[i] = G[p][i];
      }
    }

    f = true;

    for(i=0;i<27;i++){
      if(a[i] || (v[i] && !fa[i])){
	f = false;
	break;
      }
    }
    if(f) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=5005,inf=1e18;
int c[N],p[N];
vector<vector<int>>vecs;
vector<int>vec;
bool vis[N];
int n,k;
ll res=-inf;
void dfs(int u){
	if(vis[u])return;
	vis[u]=true;
	vec.push_back(c[u]);
	dfs(p[u]-1);
}
void solve(vector<int>&vec){
	ll sm=0;
	int n=vec.size();
	for(int i=0;i<n;++i)sm+=vec[i];
	if(k>n)res=max(res,sm*(k/n));
	for(int i=0;i<n;++i){
		ll csm=0;
		for(int j=0;j<n;++j){
			csm+=vec[(j+i)%n];
			int ck=k-(j+1);
			if(ck<0)break;
			res=max({res,csm,csm+sm*(ck/n)});
		}
	}
}

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>k;
	for(int i=0;i<n;++i)cin>>p[i];
	for(int i=0;i<n;++i)cin>>c[i];
	for(int i=0;i<n;++i)
		if(!vis[i]){
			dfs(i);
			vecs.push_back(vec);
			vec.clear();
		}
	for(auto v:vecs)solve(v);
	cout<<res<<endl;
}


Measured memory_bytes: 3832
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int M = (n*(n-1))/2 - n/2;
		System.out.println(M);
		if(n%2==0) {
			for(int i=1;i<=n;i++){
				for(int j=i+1;j<=n;j++) {
					if (i+j==n+1) continue;
					System.out.println(i + " " + j);
				}
			}
		}
		else {
			for(int i=1;i<=n-1;i++){
				for(int j=i+1;j<=n-1;j++) {
					if (i+j==n) continue;
					System.out.println(i + " " + j);
				}
				System.out.println(i + " " + n);
			}
		}
	}
}

Measured memory_bytes: 26452
#include<iostream>
#define MOD 1000000007
using namespace std;
long long a=2,b=1,i;
int main(){
  string s;
  cin>>s;
  for(i=1;i<s.size();a%=MOD,b%=MOD,i++)b*=3,b%=MOD,s[i]=='0'?:(b+=a,a*=2); 
  cout<<(a+b)%MOD<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int a;
  cin >>a;
  cout << pow(a,1) + pow(a,2) + pow(a,3)<< endl;
}


Measured memory_bytes: 4152
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	ll K;
	cin >> K;
	ll X, Y;
	cin >> X >> Y;
	ll D = abs(X) + abs(Y);
	if (D % 2 == 1 && K % 2 == 0) {
		cout << -1 << endl;
		return 0;
	}
	if (D == K) {
		cout << 1 << endl;
		cout << X << " " << Y << endl;
		return 0;
	}
	bool negX = 0, negY = 0, swapXY = 0;
	if (X < 0) {
		X = -X;
		negX = 1;
	}
	if (Y < 0) {
		Y = -Y;
		negY = 1;
	}
	if (X < Y) {
		swap(X, Y);
		swapXY = 1;
	}
	ll n = (D + K - 1) / K;
	ll m = n;
	if (m == 1) m++;
	if ((K*m - D) % 2) m++;
	vector<P> ans;
	if (n == 1 && m == 3) {
		ll c = (K * 3 - D) / 2;
		ll a = c / 2;
		ll b = (c + 1) / 2;
		ans.emplace_back(K - a, -a);
		ans.emplace_back(X + b, Y - (K - b));
		ans.emplace_back(X, Y);
	}
	else {
		ll a = (K*m - D) / 2;
		ans.emplace_back(K - a, -a);
		ll pos = K - a;
		while (pos + K <= X) {
			ans.emplace_back(pos + K, -a);
			pos += K;
		}
		ans.emplace_back(X, K - (X - pos) - a);
		pos = K - (X - pos) - a;
		while (pos + K <= Y) {
			ans.emplace_back(X, pos + K);
			pos += K;
		}
	}
	cout << m << endl;
	for (int i = 0; i < m; i++) {
		if (swapXY) swap(ans[i].first, ans[i].second);
		if (negX) ans[i].first = -ans[i].first;
		if (negY) ans[i].second = -ans[i].second;
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}


Measured memory_bytes: 5616
import numpy as np

N, K = map(int, input().split())
H = np.array(list(map(int, input().split())))

dp = np.zeros(N, dtype=int)

for i in range(1, N):
  left = max(0, i-K)
  dp[i] = np.min(dp[left:i] + abs(H[left:i]-H[i]))

print(dp[N-1])

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

int N, K;
int A[200200];
int F[200200];

signed main() {
    cin >> N >> K;
    int asum = 0;
    rep(i, N) {
        cin >> A[i];
        asum += A[i];
    }
    sort(A, A + N);
    if (K >= asum) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, N) {
        cin >> F[i];
    }
    sort(F, F + N, greater<int>());
    int can = 1000000000000;
    int cant = 0;
    while (can - cant > 1) {
        int m = (can + cant) / 2;
        int tsum = 0;
        rep(i, N) {
            //(A[i]-t)*F[i]<=mに
            if (A[i] * F[i] <= m)continue;
            tsum += (A[i] * F[i] - m + F[i] - 1) / F[i];
        }
        if (tsum <= K)can = m;
        else cant = m;
    }
    cout << can << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int a, b;
  cin >> a >> b;

  cout << max({a+b, a-b, a*b})<< endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String line;

		int vs = 0,vm=0,c=0;
		while ((line = bf.readLine()) != null) {
			String[] s = line.split(",");
			if(s.length!=2)break;
			int u = Integer.parseInt(s[0]);
			int m = Integer.parseInt(s[1]);
			c++;
			vs+=u*m;
			vm+=m;
		}
		System.out.println(vs);
		System.out.println(Math.round((double)vm/c));
	}
}

Measured memory_bytes: 9552
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
ll choose2(ll n) {
  return n*(n-1)/2;
}

int main(){
  int N;
  long long count=0;
  cin >> N;
  vector<int> A(N);
  map<int, int> m;
  for(int i=0;i<N;i++) cin >> A.at(i);
  for(int i=0;i<N;i++) m[i] = 0;
  for(int i=0;i<N;i++){
      m[A.at(i)]++;
      ///cout << "m[" <<A.at(i) << "] = " << m[A.at(i)] << endl;
    }//O(n log n)?
  for(auto p : m){
    count += choose2(p.second);
    //cout << "count = " << count << endl;
  }
  for(int i=0;i<N;i++){
    //printf("m[A.at(%d)] = %d\n",i,m[A.at(i)]);
    //cout << m[A.at(i)] << endl;
    long long ans = count - m[A.at(i)] + 1;
    cout << ans << endl;
  }
}


Measured memory_bytes: 12800
while True:
    ls = [0 for i in range(0,10)]
    n = int(input())
    if n == 0:
        break
    for i in range(n):
        ls[int(input())] +=1

    for i in ls:
        if i != 0:
            print("*"*i)
        else:
            print("-")

Measured memory_bytes: 7644
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B;
	cin >> A >> B;
	ll size = B-A + 1;
	ll ans = 0;
	if(A%2==0){
		ll one = size/2;
		if(size%2==0)ans = one%2;
		else ans = (one%2)^B;
	}else{
		ll one = (size-1)/2;
		if(B%2==0)ans = A^(one%2)^B;
		else ans = A^(one%2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
dp=[0]*a
l =[]
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a>t : print('Yes')
    else : print('No')
for i in range(c):
    d = int(input())
    dp[d-1]+=1
for i in dp:
    l.append(i+b-c)
    y(i+b-c)
# print(l)



Measured memory_bytes: 8644
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    int max = 0;
    int k = 0;
    ArrayList<Integer> array = new ArrayList<Integer>();
    for(int i = 0;i < num;i++){
      int n = sc.nextInt();
      array.add(n);
      if(max < n){
        max = n;
        k = i;
      }
    }
    array.remove(k);
    int sum = 0;
    for(Integer i : array){
      sum += i;
    }
    if(max < sum){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}
    

Measured memory_bytes: 35688
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct union_find{
    VI par, sz;

    void init(int n){
        par.resize(n);
        REP(i,n) par[i] = i;
        sz.assign(n, 1);
    }

    int find(int x){
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void merge(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        par[x] = y;
        sz[y] += sz[x];
    }

    int size(int x){
        return sz[find(x)];
    }
};

int main(void){
    int n, m;
    cin >> n >> m;
    union_find uf;
    uf.init(n);
    REP(i,m){
        int u = in() - 1, v = in() - 1;
        uf.merge(u, v);
    }
    int ans = 0;
    REP(i,n){
        int sz = uf.size(i);
        chmax(ans, sz);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11172
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(b%a == 0){
        cout << a+b << endl;
    }else{
        cout <<b-a<< endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll A,B;
    cin>>A>>B;
    vector<ll> prime_list;
    vector<ll> table(1000010,0);
    for(ll i=2; i<1e6+5; i++){
        if(table[i]==0){
            prime_list.push_back(i);
            for(ll j=i; j<1e6+5; j+=i){
                table[j]++;
            }
        }
    }
    ll gcd=GCD(A,B);
    ll ans=0;
    for(auto i=prime_list.begin(); i!=prime_list.end(); i++){
        if(gcd%(*i)==0){
            while(gcd%(*i)==0){
                gcd/=(*i);
            }
            ans++;
        }
    }
    if(gcd>1) ans++;
    cout<<ans+1<<endl;
}


Measured memory_bytes: 9208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE
#ifdef TRACE
#define tr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define tr(...)
#endif

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (ll)(a.size())
#define all(a) a.begin(), a.end() 
#define fr(i,n) for(i=1;i<=n;i++)
#define rp(i,n) for(i=0;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef pair<ll, ll> ii;
typedef vector<ll> vl;
const ll N = 200010;
ll mod=1e9+7;

ll ffmod(ll x, ll y, ll mod)
{
    ll rt=1;
    while(y)
    {
        if(y&1ll) rt=(rt*x)%mod;
        x=(x*x)%mod, y/=2ll;
    }
    return rt;
}

ll dp[3010][3010][3], a[3010];

int main()
{
    FIO;
    ll n,i,j,tp;
    cin>>n;
    fr(i,n) cin>>a[i];
    fr(i,n) dp[i][i][1]=a[i], dp[i][i][2]=-a[i];
    for(i=2;i<=n;i++)
        for(j=1;j+i-1<=n;j++)
        {
            tp=j+i-1;
            dp[j][tp][1]=max(a[j]+dp[j+1][tp][2], a[tp]+dp[j][tp-1][2]);
            dp[j][tp][2]=min(-a[j]+dp[j+1][tp][1], -a[tp]+dp[j][tp-1][1]);
        }
    cout<<dp[1][n][1]<<endl;
    return 0;
}


Measured memory_bytes: 211200
from bisect import bisect_right as br
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def MergeSort(aa, left=0, right=-1):
    def merge(aa, left2, mid2, right2):
        res=0
        inf = float("inf")
        L = aa[left2:mid2] + [inf]
        R = aa[mid2:right2] + [inf]
        Li = Ri = 0
        for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
        return res

    res=0
    if right == -1: right = len(aa)
    if left + 1 < right:
        mid = (left + right) // 2
        res+=MergeSort(aa, left, mid)
        res+=MergeSort(aa, mid, right)
        res+=merge(aa, left, mid, right)
    return res

def main():
    n=int(input())
    aa=list(map(int, input().split()))
    cnt=MergeSort(aa)
    print(*aa)
    print(cnt)
main()



Measured memory_bytes: 61700
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

a = int(input())
s = input()

if a >= 3200:
    print(s)
else:
    print('red')

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

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S1 = Console.ReadLine();
            string[] line1 = S1.Split(' ');
            String S2 = Console.ReadLine();
            string[] line2 = S2.Split(' ');
            int[] V = new int[N];
            int[] C = new int[N];
            int sum = 0;
            for(int i=0; i<N; i++)
            {
                V[i] = int.Parse(line1[i]);
                C[i] = int.Parse(line2[i]);
                if(V[i] > C[i])
                {
                    sum = sum + (V[i] - C[i]);
                }
            }


            Console.WriteLine(sum);


        }
    }
}

Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main(){
  int n, m, x;
  int cost_0 = 0;
  int cost_n = 0;
  cin >> n >> m >> x;
  for (int i=0;i<m;i++) {
    int a;
    cin >> a;
    if (a<x) {
      cost_0++;
    } else {
      cost_n++;
    }
  }
  if (cost_0 < cost_n) {
    cout << cost_0 << endl;
  } else {
    cout << cost_n << endl;
  }
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi=3.14159265358979;

ll fac[MAX], finv[MAX], inv[MAX];
ll POW[MAX];

void POWinit(){
    POW[0]=0;
    POW[1]=1;
    for(ll i=2;i<MAX;i++){
        POW[i]=POW[i-1]*i;
        POW[i]%=MOD;
    }
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    COMinit();
    POWinit();
    if(n<k){
        cout<<0<<endl;
        return 0;
    }
    cout<<COM(n-1,k-1)<<endl;
    return 0;
}


Measured memory_bytes: 19136
#include <stdio.h>

int main(){
	int n,m,x,spot=0;
	int load[100];
	int i;
	scanf("%d%d%d",&n,&m,&x);
	for (i=0;i<m;i++){
		scanf("%d",load+i);
		if (x>load[spot])
			spot=i;
	}
	printf("%d\n",(spot<m-spot)?spot:m-spot);
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		double M=1000001;
		for(;;)
		{
			int n=in.nextInt();//ビルの数
			if(n==0)
				return;
			double x[]=new double[n+1];
			double y[]=new double[n+1];
			double cost[][]=new double[n+1][n+1];
			for(int i=0;i<n;i++)
				Arrays.fill(cost[i], M);
			for(int i=0;i<n;i++)
				cost[i][i]=0;
			for(int i=0;i<n;i++)
			{
				int bn=in.nextInt();
				x[bn]=in.nextDouble();
				y[bn]=in.nextDouble();
			}
			for(int i=1;i<=n;i++)
				for(int j=i+1;j<=n;j++)
				{
					if(i==j)
						continue;
					double dif=Math.sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
					if(dif<=50)
						cost[i][j]=cost[j][i]=dif;
					else
						cost[i][j]=cost[j][i]=M;

				}
			int m=in.nextInt();
			for(int I=0;I<m;I++)
			{
				int s=in.nextInt(),g=in.nextInt();

				int p=0;
				int v[] = new int[n+1];// decision flag
				double leng[]=new double[n+1];// minimum distance
				int index[]=new int[n+1];//minimum road
				index[s]=0;
				for(int l=0;l<=n;l++)
				{
					leng[l]=M;
					v[l]=0;
				}
				leng[s]=0;
				for(int j=1;j<=n;j++)
				{
					double min=M;//最小の節点を探す
					for(int l=1;l<=n;l++)
					{
						if(v[l]==0&&leng[l]<min)
						{
							p=l;
							min=leng[l];
						}
					}
					v[p]=1;//確定フラグ
					for(int l=1;l<=n;l++) //pを経由してlに至長さがそれまでの最短経路より小さければ更新
					{
						if((leng[p]+cost[p][l])<leng[l])
						{
							leng[l]=leng[p]+cost[p][l];
							index[l]=p;
						}
					}
				}
				int po=g;
				ArrayList<Integer> L=new ArrayList<Integer>();
				L.add(g);
				if(leng[g]<M)
				{
					while(index[po]!=0)
					{
						L.add(index[po]);
						po=index[po];
					}
					for(int i=L.size()-1;i>0;i--)
						System.out.print(L.get(i)+" ");
					System.out.println(L.get(0));
				}
				else
					System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 12000
k, x = map(int, input().split())
right_idx_max = 0
left_idx = max(x - (k - 1), -1000000)

if left_idx == -1000000:
    right_idx = -1000000 + (k - 1)
else:
    right_idx = left_idx + (k - 1)


right_idx_max = right_idx + (k - 1)
print(" ".join(map(str, range(left_idx, right_idx_max + 1))))




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

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

    int a[100002] = {0};
    int temp;
    for(int i=0; i<n; i++){
        cin >> temp;
        a[temp-1]--;
        cin >> temp;
        a[temp]++;
    }

    int ans = 0;
    for(int i=100001; i>=2; i--){
        ans = ans + a[i];
        if(ans+1 >= i){
            cout << i-1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
  
    return 0;
}

Measured memory_bytes: 3500
import numpy as np
n,m = map(int,input().split())
A = np.array([list(input()) for _ in range(n)])
B = np.array([list(input()) for _ in range(m)])
bl = False

for i in range(n-m+1):
    for j in range(n-m+1):
        if (A[i:i+m,j:j+m] ==B).all():
            bl =True

print('Yes' if bl else 'No')

Measured memory_bytes: 12432
#include<bits/stdc++.h>
using namespace std;
int n,a[200000];
int mx,mx2;
bool b;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for (int i=0;i<n;i++)
	{
		if (a[i]>mx) mx2=mx,mx=a[i],b=0;
		else if (a[i]==mx) b=1;
		else if (a[i]>mx2) mx2=a[i];
	}
	for (int i=0;i<n;i++)
	{
		if (a[i]==mx) cout<<((b)?mx:mx2)<<endl;
		else cout<<mx<<endl;
	}
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    int mx = 0;
    rep(i, N) {
        int H;
        cin >> H;
        mx = max(mx, H);
        if (H >= mx) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

int max_n = 1e6 + 1;

void solve() {
    int N;
    cin >> N;
    vi v;
    rep(i, N) {
        int x;
        cin >> x;
        v.push_back(x);
    }

    vector<int> D(max_n, 0);
    vector<int> factors(max_n, 0);

    for (int i = 1; i < max_n; i++) {
        D[i] = i;
    }

    for (int i = 2; i <= 1000000; i++) {
        if (D[i] == i) {
            for (int j = 2; j * i <= 1000000; j++) {
                if (D[j*i] == j*i) {
                    D[j*i] = i;
                }
            }
        }
    }

    bool pairWise = true;
    for (int i = 0; i < v.size() && pairWise; i++) {
        int x = v[i];
        while (D[x] != 1) {
            int f = D[x];
            if (factors[f]) {
                pairWise = false;
            }
            factors[f] = 1;
            while (x % f == 0) {
                x /= f;
            }
        }
    }
    if (pairWise) {
        cout << "pairwise coprime";
        return;
    }

    int d = v[0];
    for (int i = 1; i < v.size(); i++) {
        d = __gcd(d, v[i]);
    }
    if (d == 1) {
        cout << "setwise coprime";
    } else {
        cout << "not coprime";
    }
}

//#define LOCAL 1

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();

    return 0;
}


Measured memory_bytes: 15004
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	string st1,st2;
	getline(cin,st1);
	getline(cin,st2);
	for(int i=0;i<=st1.size()-2;i++)cout<<st1[i]<<st2[i];
    cout<<st1[st1.size()-1];
    if(st1.size()-st2.size()==0)cout<<st2[st2.size()-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    Int n;
    std::cin >> n;
    std::cout << n * (n - 1) / 2 << std::endl;
    return 0;
}


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

int main(){
    int a,b,ab;
    
    while(1){
        cin>>a>>b;
        if(a==0&&b==0)break;
        
        if(a>b){
            cout<<b<<" "<<a<<endl;
        }
        else{
            cout<<a<<" "<<b<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2996
#include <iostream>
using namespace std;
int main()
{
        int n,m,x;
        cin >> n >> m >> x;

        int a,cstz=0,cstn=0;
        while(cin >> a){
                if(a<x) cstz++;
                else cstn++;
        }

        if(cstz>cstn) cstz=cstn;
        cout << cstz << endl;
        return 0;
}


Measured memory_bytes: 256