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

// one-based numbering
struct UnionFind {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    UnionFind(int n) {
        data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
        return -data[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<pair<int, int>> X(N+1), Y(N+1);
    UnionFind UF(N);
    for (int i = 1; i <= N; i++) {
        int x, y; cin >> x >> y;
        X[x] = {y, i};
        Y[y] = {x, i};
    }
    set<pair<int, int>> S;
    for (int i = 1; i <= N; i++) {
        bool ins = true;
        if (!S.empty()) {
            for (auto [y, z] : S) {
                if (y < X[i].first) {
                    UF.unite(X[i].second, z);
                    if (y > X[i].first) {
                        S.erase(S.begin());
                    } else ins = false;
                } else break;
            }
        }
        if (ins) S.emplace(X[i].first, X[i].second);
    }

    for (int i = 1; i <= N; i++) {
        cout << UF.size(i) << "\n";
    }

    return 0;
}

Measured memory_bytes: 11608
<?php
$N=(int)fgets(STDIN);
$Ab=$As=explode(' ',trim(fgets(STDIN)));
 
for($i=0;$i<$N;$i++)
  for($j=$N-1;$i<$j;$j--)
    if($Ab[$j][1]<$Ab[$j-1][1]) list($Ab[$j],$Ab[$j-1])=[$Ab[$j-1],$Ab[$j]];
 
for($i=0;$i<$N;$i++){
  for($mini=$j=$i;$j<$N;$j++)
    if($As[$j][1]<$As[$mini][1]) $mini=$j;
  if($i!=$mini) list($As[$i],$As[$mini])=[$As[$mini],$As[$i]];
}
 
$diff=0;
for($i=0;$i<$N;$i++)
  if($Ab[$i]!=$As[$i]){$diff=1;break;}
 
$sAb=implode(' ',$Ab);
echo $sAb,PHP_EOL,'Stable',PHP_EOL;
if($diff) echo implode(' ',$As),PHP_EOL,'Not stable',PHP_EOL;
else echo $sAb,PHP_EOL,'Stable',PHP_EOL;

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

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

  vector<int> vec(N);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
}

    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
   
    int x , y ;
    for (int i = 0; i < vec.size(); i++) {
      if(i%2==0){
        x+=vec.at(i);
      }
      else{
        y+=vec.at(i);
      }
    }
        
        cout << x-y << endl;
    
}



Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = br.readLine()!!
    val remains = LongArray(2019)
    remains[0] = 1
    var remain = 0
    var ten = 1
    for (c in s.reversed()) {
        remain = (remain + (c - '0') * ten) % 2019
        remains[remain]++
        ten = (ten * 10) % 2019
    }
    var ans = remains.fold(0L) { acc, r -> acc + r * (r - 1) / 2 }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 39560
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,c; cin >> a >> b >> c;
    if(b >= c or a + b >= c) cout << b + c << endl;
    else cout << a + b + 1 + b  << endl;
}




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

int main(void)
{
	int k; cin >> k;
	queue<ll> q;
	for(int i=1;i<=9;i++) q.push(i);
	ll front;
	while(k--) {
		front = q.front(); q.pop();
		if(front % 10 == 0) {
			q.push(front * 10);
			q.push(front * 10 + 1);
		}
		else if(front % 10 == 9) {
			q.push(front * 10 + 8);
			q.push(front * 10 + 9);
		}
		else {
			q.push(front * 10 + front % 10 - 1);
			q.push(front * 10 + front % 10);
			q.push(front * 10 + front % 10 + 1);
		}
	}
	cout << front << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")

#define fi first
#define se second

const int N = 100100;

using namespace std;

namespace Dinic {

	using F = int;
	const F INF = 1e9+1e8;

	const int N = 220000;
	const int M = 1100000;

	int fst[N], nxt[M], to[M];
	F cap[M];
	int dis[N], q[N], ptr[N];
	int E;

	void init() {
		memset(fst, -1, sizeof fst);
		E = 0;
	}
	inline void add_edge(int u, int v, F c) {
		to[E] = v, cap[E] = c, nxt[E] = fst[u], fst[u] = E++;
		to[E] = u, cap[E] = 0, nxt[E] = fst[v], fst[v] = E++;
	}
	inline bool bfs(int S, int T, int n) {
		memset(dis, -1, sizeof(int) * n);
		int h = 0, t = 0;
		dis[S] = 0, q[t++] = S;
		while (h < t) {
			int u = q[h++];
			for (int e = fst[u]; ~e; e = nxt[e]) if (cap[e] > 0 && dis[to[e]] == -1) {
				dis[to[e]] = dis[u] + 1, q[t++] = to[e];
				if (to[e] == T) return 1;
			}
		}
		return (dis[T] != -1);
	}
	F dfs(int u, int T, F f) {
		if (u == T) return f;
		for (int &e = ptr[u]; ~e; e = nxt[e]) if (cap[e] > 0 && dis[to[e]] > dis[u]) {
			F ret = dfs(to[e], T, min(f, cap[e]));
			if (ret > 0) {
				cap[e] -= ret, cap[e ^ 1] += ret;
				return ret;
			}
		}
		return 0;
	}
	F max_flow(int S, int T, int n) {
		F ret = 0;
		while (bfs(S, T, n)) {
			memcpy(ptr, fst, sizeof(int) * n);
			for (F cur; (cur = dfs(S, T, INF)) > 0; ret += cur);
		}
		return ret;
	}
};

int n;
int p[N];
int q[N];
int A[N];
int B[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 0; i < n; i++){
                cin >> p[i];
        }
        for(int i = 0; i < n; i++){
                cin >> q[i];
        }
        int G = 0;
        for(int i = 0; i < n; i++){
                if(A[i] == 0){
                        G += 1;
                        A[i] = G;
                        int j = p[i];
                        while(j != i){
                                A[j] = G;
                                j = p[j];
                        }
                }
        }
        for(int i = 0; i < n; i++){
                if(B[i] == 0){
                        G += 1;
                        B[i] = G;
                        int j = q[i];
                        while(j != i){
                                B[j] = G;
                                j = q[j];
                        }
                }
        }
        G += 1;
        Dinic::init();

        int res = n;
        for(int i = 0; i < n; i++){
                if(p[i] == i && q[i] == i){
                        res -= 1;
                } else if(p[i] == i){
                        Dinic::add_edge(B[i], G, 1);
                } else if(q[i] == i){
                        Dinic::add_edge(0, A[i], 1);
                } else{
                        Dinic::add_edge(B[i], A[i], 1);
                        if(p[i] == q[i]){
                                Dinic::add_edge(A[i], B[i], 1);
                        }
                }
        }
        res -= Dinic::max_flow(0, G, G + 1);

        cout << res << '\n';
}


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

int dis(int a, int b) {
  if(a-b > 0)  return a-b;
  else         return b-a;
}

int main() {
 
  int n;
  cin >> n;
  vector<int> a(n+2);
  a.at(0) = 0;
  a.at(n+1) = 0;
  vector<int> d(n+1);
  int total = 0;
  for(int i = 1; i < n+1; i++) {
    cin >> a.at(i);
  }
  for(int i = 0; i < n+1; i++) {
    d.at(i) = dis(a.at(i), a.at(i+1));
    total += d.at(i);
  }
  
  for(int i = 0; i < n; i++) {
    int sum = total - d.at(i) - d.at(i+1);
    if((a.at(i+1)-a.at(i)) * (a.at(i+2)-a.at(i+1)) > 0) {
      sum += d.at(i) + d.at(i+1);
    } else {
      sum += dis(d.at(i), d.at(i+1));
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 2048
import sys

N = int(sys.stdin.readline())
grid = []
for _ in range(N):
    grid.append(list(sys.stdin.readline().strip()*2))
for i in range(N):
    grid.append(grid[i])

ans = 0
for a in range(N):
    flag = False
    for i in range(N):
        for j in range(N):
            # print(i+a, j)
            if grid[i+a][j] != grid[j+a][i]:
                flag = True 
                break
        if flag:
            break
    else:
        ans += 1

print(ans * N)

Measured memory_bytes: 80292
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int number = scanner.nextInt();

		ArrayList<Integer> list = new ArrayList<Integer>();

		long total = 0;

		for (int i = 0; i < number; i++) {
			list.add(scanner.nextInt());
		}

		// ????????§???????????????
		Collections.sort(list);
		System.out.print(list.get(0) + " ");

		System.out.print(list.get(list.size() - 1) + " ");

		for (int i = 0; i < list.size(); i++) {
			total += list.get(i);
		}

		System.out.println(total);
	}
}

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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999

using namespace std;

int32_t main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    int t;
    REP(i, n){
        cin >> v[i];
    }

    int cnt=0;
    n-=k;
    k--;
    cnt++;

    while(n>0){
        cnt++;
        n-=k;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
n = int(input())
s = input()
maxcount = 0
for i in range(1, n):
	count = 0
	marked = []
	for j in range(i):
		if s[j] in marked:
			continue
		if s[i:].count(s[j]) > 0:
			count += 1
			marked.append(s[j])
	maxcount = max(count, maxcount)
print(maxcount)

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

int main(){
  string s; cin >> s;
  int mode = 1, rcount = 1, lcount = 0;
  vector<long long> out;
  vector<pair<int, long long>> ind;
  for(int i = 0; i < s.size(); i++){
    if(i == s.size() - 1){
      out.at(out.size() - 2) += lcount / 2;
      out.at(out.size() - 1) += lcount / 2 + (lcount % 2 == 1) * 1;
      for(int j = 0; j < lcount - 1; j++) out.push_back(0);
      continue;
    }
    if(mode == 1){
      if(s.at(i + 1) == 'R'){
        rcount++; continue;
      }else{
        for(int j = 0; j < rcount - 1; j++) out.push_back(0);
        long long tmp = rcount / 2 + (rcount % 2 == 1) * 1;
        out.push_back(tmp);
        out.push_back(rcount / 2);
        rcount = 1; mode = 0;
      }
    }
    if(mode == 0){
      if(s.at(i + 1) == 'R'){
        out.at(out.size() - 2) += lcount / 2;
        out.at(out.size() - 1) += lcount / 2 + (lcount % 2 == 1) * 1;
        for(int j = 0; j < lcount - 1; j++) out.push_back(0);
        lcount = 0; mode = 1;
      }else{
        lcount++; continue;
      }
    }
  }
  for(int i = 0; i < out.size(); i++){
    cout << out.at(i) << " ";
  }
}


Measured memory_bytes: 1528
// #include<iostream>
// #define MOD 1000000007
// typedef unsigned long long int ll;
// #define fastio ios_base::sync_with_stdio(false);
// using namespace std;

// ll solve(ll l , ll r){
// 	ll temp = l;
// 	ll res=0;
// 	ll k=0;
// 	// while(1){
// 	// 	if(!(r & (1 << k)) && !(temp & (1 << k))){
// 	// 		temp = temp | (1 << k);
// 	// 		if(temp >= r){
// 	// 			break;
// 	// 		}
// 	// 		else{
// 	// 			res  = temp;
// 	// 		}
// 	// 	} 
// 	// 	k++;
// 	// }
// 	for(int i=0;i<62;i++){
// 		if(!(r & (1 << i)) && !(temp & (1 << i))){
// 			temp = temp | (1 << i);
// 			if(temp >= r){
// 				break;
// 			}
// 			else{
// 				res  = temp;
// 			}
// 		} 
// 	}
// 	return res;
// }


// int main(){
// 	fastio
// 	int test;
// 	cin >> test;
// 	while(test--){
// 		ll  l ,r;
// 		cin >> l >> r;
// 		ll res = solve(l ,r);
// 		cout << (res | r) << endl;
// 	}
// 	return 0;
// }


#include<bits/stdc++.h>
using namespace std;


int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	char curr = s[0];
	int count =1  ;
	for(int i=1;i<s.size();i++){
		if(s[i] != curr){
			count ++;
			curr = s[i];
		}

	}	
	cout << count << endl; 
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int n, t, a;
	cin >> n >> t >> a;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	t *= 1000;
	a *= 1000;
	int id = 0;
	for (int i = 0; i < n; i++) {
		if (abs(t - 6 * h[i] - a) < abs(t - 6 * h[id] - a)) {
			id = i;
		}
	}

	cout << id + 1 << endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2==0 && a%3!=0 && a%5!=0){
			cout<<"DENIED"<<endl;
			return(0);
		}
	}
	cout<<"APPROVED"<<endl;
  return(0);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		var P = GetInts(N);

		int ans = 0;
		int min = int.MaxValue;
		for(int i = 0; i < N; i++)
		{
			if(min > P[i])
			{
				min = P[i];
				ans++;
			}
		}
		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 33500
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long

int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("test.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif*/
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
 
    int n;cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        if(i == 0)continue;
        if(v[i] > v[i - 1])v[i]--;
        if(v[i] < v[i - 1]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[100010];

int main(void){
	          int i;

	          int N;
	          cin >> N;
	          for(i=1;i<=N;i++){
	        	  int x;
				  cin >> x;
	        	  a[x]++;
	          }

	          for(i=1;i<=100000;i++){
	        	  if(a[i]!=0){
	        		  if(a[i]%2==0) a[i]=2;
	        		  else a[i]=1;
	        	  }
	          }

	          int s=0,p=0;
	          for(i=1;i<=100000;i++){
	        	  if(a[i]==2) p++;
	        	  else if(a[i]==1) s++;
	          }

	          cout << 2*(p/2)+s << endl;

	          return 0;
}


Measured memory_bytes: 640
L, R = map(int, input().split())

if (R - L) >= 2019:
  print(0)
  
else:
  res = 2*10**9
  for i in range(L, R):
    for j in range(i + 1, R + 1):
      res = min(res, (i*j) % 2019)
  print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define lb(x,a) lower_bound(all(x),a)
#define ub(x,a) upper_bound(all(x),a)
#define maxe(x,a) max_element(all(x))
#define mine(x,a) min_element(all(x))
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
 ll a;
  cin >>a;
  
  while(a--) cout << "ACL";
  cout << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3644
arr=[3,5,7]

global res
res = 0
ma = int(input())

def gen(num = 0):
    global res
    # print(num)
    if ma < num:
        return
    else:
        st = str(num)
        if st.count('3') and st.count('5') and st.count('7'):
            res += 1

    for i in arr:
        if num == 0:
            gen(num+i)
        else:
            gen(10*num + i)

gen()
print(res)


Measured memory_bytes: 48220
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000003LL)
typedef long long Int;

int n, mi, cs[60000][2];
vector<int> g[60000];
bool has[60000];
int dp[60000][2][2];

inline int f(int k, int x, int y) { return k == -1 ? x==y : dp[k][x][y]; }

void add(int p, int q) {
    if (p > q) swap(p, q);
    g[p].push_back(q);
}

int pre(int p, int q) {
    if (p+1 == q) return -1;
    const int k = mi++;
    has[k] = false;
    if (g[p].back() == q) {
        has[k] = true;
        g[p].pop_back();
    }
    const int r = g[p].back();
    cs[k][0] = pre(p, r);
    cs[k][1] = pre(r, q);
    return k;
}

int main() {
    for (;;) {
        int m, a, b;
        scanf("%d%d", &n, &m);
        if (n == 0) return 0;
        rep (_, m) {
            scanf("%d%d", &a, &b);
            if (n%2 == 0) add(a-1, b-1);
        }
        if (n%2) {
            printf("%d\n", 0);
            continue;
        }
        rep (i, n) add(i, (i+1)%n);
        rep (i, n) sort(g[i].begin(), g[i].end());
        mi = 0;
        pre(0, n-1);
        for (int k = mi-1; k >= 0; k--) rep (x, 2) rep (y, 2) {
            const int p = cs[k][0], q = cs[k][1];
            Int ans = 0;
            ans += (Int)f(p, x, 0) * f(q, 1, y);
            ans += (Int)f(p, x, 1) * f(q, 0, y);
            if (x && y && has[k]) {
                ans += (Int)f(p, 0, 0) * f(q, 1, 0);
                ans += (Int)f(p, 0, 1) * f(q, 0, 0);
            }
            dp[k][x][y] = ans % MOD;
        }
        printf("%d\n", dp[0][1][1]);
    }
}

Measured memory_bytes: 10248
#include<cstdio>
#include<cstring>
#define maxl 5000005
using namespace std;
int len,x;
char ch[maxl];
int main(){
	scanf("%s",ch+1);
	scanf("%d",&x);
	len=strlen(ch+1);
	for (int i=1;i<=len;i+=x) printf("%c",ch[i]);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    // data loader
    int n, m;
    cin >> n >> m;
    int a[n], b[n];
    for (int i=0;i<n;i++){
        cin >> a[i]>> b[i];
    }
    
    //main
    vector<vector<int>> v(m);
    priority_queue<int> q;
    
    int i,j;
    long long rem=0;
    for (i=0;i<n;i++){
        if (a[i]-1<m){
            v[a[i]-1].push_back(b[i]);
        }
    }
    for (i=0;i<m;i++){
        for (j=0;j<v[i].size();j++){
            q.push(v[i][j]);
        }
        if (q.size()>0){
            rem+=q.top();
            q.pop();
        }
    }
    cout<<rem<<endl;
}


Measured memory_bytes: 6400
using System;

namespace ITP1_7_A
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int j=0; ;j++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int m = int.Parse(input[0]);
                int f = int.Parse(input[1]);
                int r = int.Parse(input[2]);
                int sum = m + f;
                string output = null;

                if (m == -1 && f == -1 && r == -1) break;

                if (m == -1 || f == -1)
                    output = "F";
                else if (sum >= 80)
                    output = "A";
                else if (65 <= sum && sum < 80)
                    output = "B";
                else if (50 <= sum && sum < 65)
                    output = "C";
                else if (30 <= sum && sum < 50)
                    if (r >= 50) output = "C";
                    else output = "D";
                else if (sum < 30)
                    output = "F";

                Console.WriteLine(output);
            }

        }
    }
}

Measured memory_bytes: 8816
use proconio::{fastout, input};
// use proconio::marker::*;

const MOD: usize = 998244353;

#[fastout]
fn main() {
   input! {
      n: usize,
      s: usize,
      a: [usize; n]
   }
   let mut dp = vec![0; s + 1];
   dp[0] = 1;
   for &a in a.iter() {
      for i in (0..=s).rev() {
         dp[i] *= 2;
         if i >= a {
            dp[i] += dp[i - a];
         }
         dp[i] %= MOD;
      }
   }
   println!("{}", dp[s]);
}


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

typedef long long LL;

const int N=2000;

int n,a[N+9],sum;

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
	scanf("%d",&a[i]);
	sum+=a[i];
  }
}

bitset<N*N+9>dp;
int ans;

void Get_dp(){
  dp[0]=1;
  for (int i=1;i<=n;++i) dp|=dp<<a[i];
  for (ans=sum>>1;!dp[ans];--ans);
  ans=sum-ans;
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    cout << n*800 - (n/15)*200 << endl;
    return 0;
}

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

int main() {
    int A, B, C, WA, WB, WC, min;
    cin >> A >> B >> C;

    WA= A + B;
    WB= B + C;
    WC= C + A;

    min = WA;
    if(WB < WA){
        min = WB;
    }
    if(WC < min){
        min = WC;
    }

    cout << min << endl;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;

	if(abs(a-b) <= k && abs(a-c) <= k && abs(a-d) <= k && abs(a-e) <= k && 
	   abs(b-c) <= k && abs(b-d) <= k && abs(b-e) <= k && abs(c-d) <= k && 
	   abs(c-e) <= k && abs(d-e) <= k){
		cout << "Yay!";
	} else {
		cout << ":(";		
	}

    return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  if(abs(a-b)%2==0) cout << abs(a-b)/2 << endl;
  else {
    ll ans = min(a, n-b+1) + (abs(a-b)-1) / 2;
    cout << ans << endl;
  }
}


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

using namespace std;

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

    int as[3];
    for (int i = 0; i < 3; i++) cin >> as[i];
    
    int cnt = 0;
    for (int i = 0; i < 3; i++) {
        if (as[i] & 1) cnt++;
    }
    
    cout << (cnt >= 2 ? "Hom" : "Tem") << endl;
}


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

int main(int argc, char *argv[]){
    int n;
    cin >> n;
    int a,b;
    int c=0;
    int flag=0;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        if(a==b){
            c++;
        }
        else c=0;
        if(c==3){
            flag=1;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>

typedef struct {
  double x;
  double y;
}Point;

void koch(int n,Point a,Point b){
  if(n==0)return;
  Point s,t,u;
  double th=M_PI*60.0/180.0;

  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);

}

int main(){
  Point a,b;
  int n;
  scanf("%d",&n);
  a.x=0;
  a.y=0;
  b.y=0;
  b.x=100;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
  

}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
int main(){
    int H,W,D,x,Q,L,R;
    int px[90001],py[90001],d[90001]={};
    cin >> H >> W >> D;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> x;
            px[x] = i;
            py[x] = j;
        }
    }

    for(int i=D+1;i<=H*W;i++){
        d[i] = d[i-D] + abs(px[i]-px[i-D]) + abs(py[i]-py[i-D]);
    }
    
    cin >> Q;
    while(Q--){
        cin >> L >> R;
        cout << d[R]-d[L] << endl;
    }
}

Measured memory_bytes: 2176
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
  
// ここから
function main(){
  for(var line = 1, maxLines = input[0] - 0; line <= maxLines; line++){
    var inputArray = input[line].split(" ").sort(function(a,b){return a-b});
    var longest = inputArray[2];
    var middle = inputArray[1];
    var shortest = inputArray[0];
 
      console.log((longest*longest == middle*middle + shortest*shortest) ? 'YES' : 'NO');
  }
}

Measured memory_bytes: 10376
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

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

long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int s[101];
int ss[101];

int main(){
	int n;
	int sum = 0;
	int j = 0;
	
	cin >> n;
	
	REP(i,n){
		scanf("%d", &s[i]);
		if (s[i]%10 != 0){
			ss[j] = s[i];
			j++;
		}
		sum += s[i];
	}
	
	sort(ss,ss+j);
	
	if (sum%10 == 0){
		if (j == 0) sum = 0;
		else sum -= ss[0];
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, l = map(int, input().split())

li = list(i for i in range(1, n+1, 1))
ab = 10000
ans = 0

for i in li:
  if abs(l + i - 1) < ab:
    ab = abs(l + i - 1)
    ans = l + i - 1

su = sum(li) + n * l - n

print(su - ans)


Measured memory_bytes: 2940
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  v = input().strip()
  i = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'].index(v)

  print(7 - i)


if __name__ == '__main__':
  main()


Measured memory_bytes: 38384
import java.util.*;

public class Main {

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

    if (105 * (x / 100) < x || x < 100) {
      System.out.println(0);
    } else {
      System.out.println(1);
    }


  }

}

Measured memory_bytes: 22732
n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = list(map(int, input().split()))

a = set()
def bf(sum_, n):
    global a, A
    
    a.add(sum_)
    if n < 0: return
    
    bf(sum_+A[n], n-1)
    bf(sum_, n-1)

bf(0, n-1)
for b in B:
    if b in a:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5656
class Dice(object):
    """docstring for Dice"""
    def __init__(self, numeric_column):
        self.numeric_column=numeric_column
    def roll_to_S_direction(self):
        self.numeric_column=[self.numeric_column[4],self.numeric_column[0],self.numeric_column[2],self.numeric_column[3],self.numeric_column[5],self.numeric_column[1]]
    def roll_to_N_direction(self):
        self.numeric_column=[self.numeric_column[1],self.numeric_column[5],self.numeric_column[2],self.numeric_column[3],self.numeric_column[0],self.numeric_column[4]]
    def roll_to_E_direction(self):
        self.numeric_column=[self.numeric_column[3],self.numeric_column[1],self.numeric_column[0],self.numeric_column[5],self.numeric_column[4],self.numeric_column[2]]
    def roll_to_W_direction(self):
        self.numeric_column=[self.numeric_column[2],self.numeric_column[1],self.numeric_column[5],self.numeric_column[0],self.numeric_column[4],self.numeric_column[3]]

dice=Dice(map(int,raw_input().split()))
direction=raw_input()
for i in direction:
    if i=='S': dice.roll_to_S_direction()
    elif i=='N': dice.roll_to_N_direction()
    elif i=='E': dice.roll_to_E_direction()
    else: dice.roll_to_W_direction()
print dice.numeric_column[0]

Measured memory_bytes: 6428
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll x[110];
int main() {
  ll n,k,ans=0;
  cin>>n>>k;

  rep(i,k,n+2){
    ll m1=(2*n+1-i)*i/2;
   ll m2=((i-1)*i)/2;
   ans=(ans+m1-m2+1)%mod;
  }
  cout<<ans;
}



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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vi a(3*n);
  rep(i,0,3*n) cin >> a[i];

  const int N = 2123;
  const int inf = 1e9;

  vi bst(N, -inf);
  vvi dp(N, vi(N, -inf));
  queue<tuple<int,int,int>> q;
  int mx = 0, extra = 0;

  dp[a[0]][a[1]] = dp[a[1]][a[0]] = 0;
  bst[a[0]] = bst[a[1]] = 0;

  auto upd = [&](int i, int j, int v) {
    q.emplace(i, j, v);
  };

  for (int i = 2; i+2 < 3*n; i += 3) {
    sort(a.begin()+i, a.begin()+i+3);

    if (a[i] == a[i+2]) { // just pick these three
      ++extra;
      continue;
    }

    if (a[i] == a[i+1])
      rep(j,1,N)
        upd(j, a[i+2], dp[a[i]][j]+1);


    if (a[i+1] == a[i+2])
      rep(j,1,N)
        upd(j, a[i], dp[a[i+1]][j]+1);

    // try to match with prev pair
    upd(a[i], a[i+1], max(dp[a[i+2]][a[i+2]]+1, mx));
    upd(a[i], a[i+2], max(dp[a[i+1]][a[i+1]]+1, mx));
    upd(a[i+2], a[i+1], max(dp[a[i]][a[i]]+1, mx));

    rep(j,0,N) rep(k,0,3) upd(a[i+k], j, bst[j]);

    while (not q.empty()) {
      auto [i, j, v] = q.front(); q.pop();
      ckmax(dp[i][j], v);
      ckmax(dp[j][i], v);
      ckmax(bst[i], v);
      ckmax(bst[j], v);
      ckmax(mx, v);
    }

  }

  ++dp[a[3*n-1]][a[3*n-1]];

  int ans = 0;
  rep(i,0,N) ckmax(ans, *max_element(all(dp[i])));
  cout << ans+extra << '\n';

}

Measured memory_bytes: 21440
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

N = int (raw_input ())
K = int (raw_input ())
l = [int (i) for i in raw_input ().split ()]
print sum (2 * min (i, abs (K - i)) for i in l)


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

using namespace std;

class UnionFind {
 private:
  std::vector<int> parent;

 public:
  UnionFind(int n) : parent(n, -1) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    return parent[x] = root(parent[x]);
  }

  bool is_same(int x, int y) { return root(x) == root(y); }

  int size(int x) { return -parent[root(x)]; }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) std::swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf.unite(a, b);
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    res = max(res, uf.size(i));
  }
  cout << res << '\n';
  return 0;
}


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

int arr[100001], N;
int res, order = 0;
int main() {
	cin >> N;

	for (int i = 0; i < N; ++i) {
		scanf("%d", &arr[i]);
	}

	for (int i = 1; i < N; ++i) {
		if (order == 0 || order == 3) {
			if (order == 0) res++;
			if (arr[i - 1] == arr[i]) {
				order = 3;
			}
			else if (arr[i - 1] < arr[i]) {
				order = 1;//not decreasing
			}
			else if (arr[i - 1] > arr[i]) {
				order = 2;//not increasing
			}
		}
		if (order == 1 && arr[i - 1] > arr[i]) {
			order = 0;
		}
		else if (order == 2 && arr[i - 1] < arr[i]) {
			order = 0;
		}
	}

	if (order == 0) res++;
	cout << res;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int N, M, A, B;
	cin >> N >> M;
	vector<vector<int>> adj(N + 1);
	for (int i = 1; i <= M; ++i) {
		cin >> A >> B;
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	// for (int i = 1; i <= N; ++i) {
	// 	cout << i << ": ";
	// 	for (int j = 0; j < adj[i].size(); ++j) cout << adj[i][j] << ' ';
	// 	cout << '\n';
	// }
	queue<int> q;
	bool visited[N + 1];
	int distance[N + 1];
	for (int i = 1; i <= N; ++i) {
		visited[i] = distance[i] = 0;
	}
	visited[1] = true;
	distance[1] = 0;
	q.push(1);
	int cnt = 0;
	vector<vector<int>> signposts(N + 1);
	while (!q.empty()) {
		int s = q.front();
		q.pop();
		for (int u : adj[s]) {
			// cout << u << ' ' << visited[u] << '\n';
			signposts[u].push_back(s);
			if (visited[u]) continue;
			visited[u] = true;
			distance[u] = distance[s] + 1;
			// cout << u << ' ' << distance[u] << '\n';
			q.push(u);
		}
	}
	// for (int i = 2; i <= N; ++i) cout << distance[i] << '\n';
	for (int i = 2; i <= N; ++i) {
		if (distance[i] == 0) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	for (int i = 2; i <= N; ++i) {
		cout << signposts[i][0] << '\n';
	}
	return 0;
}

Measured memory_bytes: 16532
#include <stdio.h>
#include <stdlib.h>
typedef struct edge {
    int w, f, t;
} edge;
edge E[(100*100)/2];
int A[100][100];
int group[100];
int comp(const void *x, const void *y)
{
    return ((edge*)x)->w - ((edge*)y)->w;
}
  
int kru(int n)
{
    int i, j, en, s, from, to;
    for(i=0; i<n; i++) group[i]=i;
    en=0;
    for(i=0; i<n; i++) {
        for(j=0; j<i; j++) {
            if(A[i][j]!=-1) {
                E[en].w=A[i][j];
                E[en].f=i;
                E[en].t=j;
                en++;
            }
        }
    }
    qsort(E, en, sizeof(edge), comp);
      
    s=0;
    for(i=0; i<en; i++) {
        from=group[E[i].f];
        to=group[E[i].t];
        if(from != to) {
            s+=E[i].w;
            for(j=0; j<n; j++) {
                if(group[j]==from) group[j]=to;
            }
            for(j=1; j<n && group[j-1]==group[j]; j++);
            if(j==n) break;
        }
    }
      return s;
}
int main(int argc,char * argv[])
{
    int i=0, j, n, s;
    scanf("%d", &n);
  for(i=0;i<n;i++){
        for(j=0; j<n; j++) {
            scanf("%d", &A[i][j]);
        }
    }
      
    s=kru(n);
    printf("%d\n", s);
    return 0;
}
 

Measured memory_bytes: 776
# -*- coding:utf-8 -*-
import sys
import heapq


def solve():
    N, K = list(map(int, sys.stdin.readline().split()))
    Vs = list(map(int, sys.stdin.readline().split()))

    ans = 0
    for i in range(0, K+1):
        for j in range(0, K+1):
            if i+j > K: break
            if i+j > N: break
            #
            if i==0 and i==j:
                continue

            _Vs = Vs[::-1]
            have = Vs[0:i]+_Vs[0:j]
            have.sort(reverse=True)

            M = i+j
            while M < K:
                if len(have) == 0: break
                if have[-1] < 0:
                    have.remove(have[-1])
                    M += 1
                    continue
                break

            ans = max(ans, sum(have))

    print(ans)



if __name__ == "__main__":
    solve()


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

int main(void)
{
    int N;
    cin >> N;
    int B[N];
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        B[A-1] = i + 1;
    }
    for (int i = 0; i < N - 1; i++) {
        cout << B[i] << " ";
    }
    cout << B[N-1] << endl;
}


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

int main(){
  int N,x;
  cin >> N;
  x=800*N;
  if(N<15)
    cout << x << endl;
  else if(N<30)
    cout << x-200 << endl;
  else if(N<45)
    cout << x-400 << endl;
  else if(N<60)
    cout << x-600 << endl;
  else if(N<75)
    cout << x-800 << endl;
  else if (N<90)
    cout << x-1000 << endl;
  else
    cout << x-1200 << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,q=map(int,input().split())
    s=input()
    lis=[0]*(n+1) 
    for i in range(n-1):
        if s[i:i+2]=="AC":
            lis[i+1]+=1
        lis[i+2]=lis[i+1]
    for i in range(q):
        l,r=map(int,input().split())
        print(lis[r-1]-lis[l-1])


if __name__=='__main__':
    main()

Measured memory_bytes: 6300
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
int n;
signed main()
{
	Very_fast;
	string s;
	cin>>s;
	if(s=="ABC")cout<<"ARC";
	else cout<<"ABC";
	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl d(n);
  REP(i,n) cin >> d[i];
  ll ans = 0;
  REP(i,n){
    REP(j,n){
      if(i<j) ans += d[i]*d[j];
    }
  }
  cout << ans<< endl;
  return 0;
}


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

int n;
vector < vector < int > > linkList;
bool used[100005];
int countV[100005];

int dfs(int v)
{
	used[v] = 1;
	int maxH = 0;
	multiset<int> val;
	multiset<int>::reverse_iterator it;
	if (!linkList[v].empty())
	{
		for (int i = 0; i < linkList[v].size(); i++)
			if (!used[linkList[v][i]])
			{
				int a = dfs(linkList[v][i]) + 1;
				val.insert(a);
			}

		int slotH = 0;
		it = val.rbegin();
		maxH = 0;
		while (it != val.rend())
		{
			maxH = (maxH > *it + slotH) ? maxH : *it + slotH;
			it++;
			slotH++;
		}
	}
	return maxH;
}

int main()
{

	for (int i = 0; i < 100005; i++)
		used[i] = 0;

	int a;
	cin >> n;
	linkList.resize(n);
	for (int i = 1; i < n; i++)
	{
		cin >> a;
		a--;
		linkList[i].push_back(a);
		linkList[a].push_back(i);
	}

	cout << dfs(0) << endl;
	/*
	11
	4
	4
	5
	1
	3
	2
	4
	6
	4
	4

	8
	4
	4
	5
	1
	3
	2
	4

	int maxi = linkList[0].size();
	for(int i = 1; i < n; i++)
	maxi = (maxi > linkList[i].size() + countV[i] - 1)? maxi : linkList[i].size()  + countV[i] - 1;

	cout<<maxi<<endl;
	*/
	//system("PAUSE");
	return 0;
}


Measured memory_bytes: 16768
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 19, mod = 1e9 + 7;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	ll dist = abs(a-b);
	ll change = (w-v)*t;
	cout << (dist == 0 || dist + change <= 0 ? "YES\n": "NO\n");
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  N %= 10;

  if(N == 3){
    cout << "bon" << endl;
  } else if((N == 0) || (N == 1) || (N == 6) || (N == 8)){
    cout << "pon" << endl;
  } else{
    cout << "hon" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3632