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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
  	int n;
  	cin >> n;
  	vi a(n); for (auto &x : a) cin >> x;
  	vi dp(n, numeric_limits<int>::max()); dp[0] = 0;
  	for (int i = 0; i < n; i++) {
		if (i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
        if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
    }
    cout << dp[n - 1] << endl;
}

/*
USE LONG LONG!!!!

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

Measured memory_bytes: 1024
n = int(input())

primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

d = dict()
for i in range(len(primes)):
    d[primes[i]] = i

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

l = [0] * len(primes)
for i in range(1, n+1):
    divisors = prime_factorize(i)
    for dv in divisors:
        idx = d[dv]
        l[idx] += 1
    # print(l)
    tmp = 1
    for j in range(len(primes)):
        tmp *= (l[j] + 1)

print(tmp % (10 ** 9 + 7))


Measured memory_bytes: 3188
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	int q; cin >> q;
	long double theta1, theta2;
	theta1 = atan2(y2 - y1, x2 - x1);
	while (q--) {
		int x, y; cin >> x >> y;
		theta2 = atan2(y - y1, x - x1);
		long double dist_x = hypot(x - x1,y - y1) * cos(theta2 - theta1);
		cout << fixed << setprecision(11) << x1 +  dist_x * cos(theta1) << " " << y1 + dist_x * sin(theta1) << endl;
	}
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;

struct UnionFind{
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];//高さを更新
      data[y] = x;//親を更新
    }
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector< pair<int,int> > A;
  int a;
  for(int i = 0; i < N; ++i){
    cin >> a;
    A.emplace_back(a,i);
  }
  UnionFind uf(N);
  int x, y;
  for(int i = 0; i < M; ++i){
    cin >> x >> y;
    uf.unite(x,y);
  }
  set<int> s;
  for(int i = 0; i < N; ++i) s.insert(uf.find(i));
  int k = s.size(), e = 2*(k-1);
  vector<int> C(N,0);
  sort(A.begin(),A.end());
  long long int ans = 0;
  
  for(int i = 0; i < N; ++i){
    if(e == 0) break;
    a = A[i].first;
    int v = A[i].second;
    if(C[uf.find(v)] == 0){
      ans += a;
      A[i].first = 1e9+1;
      ++C[uf.find(v)];
      --e;
    }
  }
  sort(A.begin(),A.end());
  for(int i = 0; i < N; ++i){
    if(e == 0) break;
    a = A[i].first;
    if(a > 1e9) break;
    int v = A[i].second;
    if(C[uf.find(v)] < k-1){
      --e;
      ans += a;
      ++C[uf.find(v)];
    }
  }
  if(e > 0) cout << "Impossible" << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6516
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true){
			
			int n = sc.nextInt();
			if(n==0) {
				sc.close();
				break;
			}
			
			int[] a = new int[n];
			int[] b = new int[n];
			Arrays.fill(a, 0);
			Arrays.fill(b, 0);
			
			int a_score=0;
			int b_score=0;
			
		
			for(int i=0; i<n; i++){
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
			}
		
			for(int i=0; i<n; i++){
				if(a[i] > b[i]){
					a_score += a[i]+b[i];
				}else if(a[i] == b[i]){
					a_score += a[i];
					b_score += b[i];
				}else{
					b_score += a[i]+b[i];
				}
			}
			
			System.out.println(a_score + " " + b_score);

		}
		
	}

}

Measured memory_bytes: 51684
import sys
input=sys.stdin.readline
import heapq
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
hq=[]
tmp=0
ans=0
for i in range(1,m+1):
    while tmp<n and AB[tmp][0]<=i:
        heapq.heappush(hq,-AB[tmp][1])
        tmp+=1
    if hq:
        ans-=heapq.heappop(hq)
print(ans)

Measured memory_bytes: 68060
fun main(args:Array<String>?): Unit {
    repeat(readLine()!!.trim().toInt()){
        val (x, y, b, p) = readLine()!!.trim().split(' ').map(String::toInt)
        if (((x * Math.max(b, 5) + y * Math.max(p, 2)) * 4 / 5) < (x * b + y * p)) println((x * Math.max(b, 5) + y * Math.max(p, 2)) * 4 / 5)
        else println(x * b + y * p)
    }
}


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

namespace VirtualAtCorder
{
    class Program
    {



        static void Main(string[] args)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            string[] lst = new string[int.Parse(inputs[0])];

            for (int i = 0; i < int.Parse(inputs[0]); ++i)
            {
                lst[i] = Console.ReadLine();
            }

            Array.Sort(lst);

            foreach (var str in lst)
            {
                Console.Write(str);
            }

            Console.ReadKey();
        }





    }
}

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

int main(){
	int n, are, h1, h2, d, u;
	d = u = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		d = u = 0;
		cin >> are >> h1;
		for(int j = 1; j < are; j++){
			cin >> h2;
			if(h1 < h2){
				if(u < h2 - h1) u = h2-h1;
			}
			else if(h1 > h2){
				if(d < h1 - h2) d = h1-h2;
			}
			h1 = h2;
		}
		cout << u << " " << d << endl;
	}
	return 0;
}


Measured memory_bytes: 2984
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  rep(i, k) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3660
fun main(args:Array<String>) {
    val (person, food) = readLine()!!.split(" ").map { it.toInt() }
    var flag = (1..food).toMutableSet()
    (1..person).forEach {
        val like = readLine()!!.split(" ").map { it.toInt() }.drop(1).toSet()
        flag = flag.filter { a-> like.contains(a) }.toMutableSet()
    }
    println(flag.size)
}


Measured memory_bytes: 37940
#include <iostream>
#include <string>
#include <vector>

void update(int* source, int* dest, int size) {
  for (int i = 0; i < size; i++) {
    dest[i] = source[i];
  }
}

void rollToNorth(int* dice) {
  int buf[6];
  buf[2] = dice[0];
  buf[4] = dice[1];
  buf[1] = dice[2];
  buf[3] = dice[3];
  buf[0] = dice[4];
  buf[5] = dice[5];
  update(buf, dice, 6);
}
void rollToEast(int* dice) {
  int buf[6];
  buf[3] = dice[0];
  buf[5] = dice[1];
  buf[2] = dice[2];
  buf[1] = dice[3];
  buf[4] = dice[4];
  buf[0] = dice[5];
  update(buf, dice, 6);
}
void rollToSouth(int* dice) {
  int buf[6];
  buf[4] = dice[0];
  buf[2] = dice[1];
  buf[0] = dice[2];
  buf[3] = dice[3];
  buf[1] = dice[4];
  buf[5] = dice[5];
  update(buf, dice, 6);
}
void rollToWest(int* dice) {
  int buf[6];
  buf[5] = dice[0];
  buf[3] = dice[1];
  buf[2] = dice[2];
  buf[0] = dice[3];
  buf[4] = dice[4];
  buf[1] = dice[5];
  update(buf, dice, 6);
}

int main() {
  // top, bottom, north, east, south, west.
  int dice[6] = {1, 6, 5, 3, 2, 4};
  std::vector<int> numbers;
  for (int i = 0; i < 6; i++) {
    int buf;
    std::cin >> buf;
    numbers.push_back(buf);
  }
  std::string commands;
  std::cin >> commands;
  for (auto& c : commands) {
    if (c == 'N') {
      rollToNorth(dice);
    } else if (c == 'E') {
      rollToEast(dice);
    } else if (c == 'S') {
      rollToSouth(dice);
    } else if (c == 'W') {
      rollToWest(dice);
    }
  }
  std::cout << numbers[dice[0] - 1] << std::endl;
  return 0;
}



Measured memory_bytes: 3204
n, m = map(int, input().split())
edges = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a,b = map(int, input().split())
    edges[a-1][b-1] = 1
    edges[b-1][a-1] = 1

def dfs(start):
    if visited[start]:
        return
    visited[start] = 1
    for i in range(n):
        if edges[start][i]:
            dfs(i)

ans = m
# edgeを一つづつ見ていく
for i in range(n-1):
    for j in range(i+1, n):
        if not edges[i][j]:
            continue
        # エッジを削除した場合に、連結しているかをdfsで確認
        #   visited: 訪れたかどうかを表す変数
        visited = [0] * n
        edges[i][j] = 0
        edges[j][i] = 0
        dfs(0)
        # お片付け、削除したedgeを元に戻しておく
        edges[i][j] = 1
        edges[j][i] = 1
        # 全て訪れられていたら、そのエッジはなくても非連結にならないので、bridgeではない
        if sum(visited) == n:
            ans -=1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long int
#define ff first
#define ss second
#define u128 __int128
#define pb push_back
 
#define N 200010
#define MOD 1000000007


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

	int n;
	cin >> n;
	cout << (n * (n - 1)) / 2;
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
struct edge{ll to;};
struct graph{
    ll N; //ノードの個数
    vector<vector<edge> > G;
    vector<ll> depth;
    vector<bool> used;

    ll goal=-1; // ここについたら終了
    bool found=false; // 終了の合図
    deque<ll> root; // 経路

    graph(ll n): N(n), G(N), depth(N,INF2), used(N,false) {}

    void add_edge(ll s, ll t){
        G[s].emplace_back((edge){t});
        G[t].emplace_back((edge){s}); //無効ならON
    }

    void dfs(ll v=0, ll p=-1){
        used[v]=true;
        if(!found) root.emplace_back(v);
        if(v==goal) found=true;
        for(auto E : G[v]){
            if(used[E.to] == false) dfs(E.to , v);
            if(found) break;
        }
        if(!found) root.pop_back();
        //used[v]=false; //同じところに違う経路で行くなら追加 計算量爆発に注意
    }
};

struct graph2{
    ll N;
    vector<vector<edge> > G;
    vector<bool> used;
    ll muri;
    ll madep=0;


    graph2(ll n): N(n), G(N), used(N,false) {}

    void add_edge(ll s, ll t){
        G[s].emplace_back((edge){t});
        G[t].emplace_back((edge){s}); //無向ならON
    }

    void dfs(ll v=0, ll dep=0){
        used[v]=true;
        maxi(madep,dep);
        for(auto E : G[v]){
            if(!used[E.to] and E.to!=muri){
                dfs(E.to, dep+1);
            }
        }
    }
};

//--MAIN-----------------------------------
void Main() {
    ll N,u,v; cin>>N>>u>>v; --u,--v;
    graph g(N);
    graph2 g2(N);
    rep(i,N-1){
        ll x,y; cin>>x>>y;
        g.add_edge(--x,--y);
        g2.add_edge(x,y);
    }
    g.goal=v;
    g.dfs(u);
    g2.muri=g.root[(g.root.size()/2)];
    //cout<< (ll)g.root.size()/2-1 <<endl;
    g2.dfs(g.root[(g.root.size()/2)-1]);
    ll ans=0;
    if((g.root.size()%2)==0){
        ans=g2.madep+g.root.size()/2-1;
    }
    else ans=g2.madep+g.root.size()/2;
    cout<< ans <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef long long int lli;
typedef long double float64;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
        << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
    << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

/*bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } // __gcd(0,0) gives exception

const int MAX_N = 1234;

//int arr[MAX_N][MAX_N];

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.length()-8;i++){
        printf("%c",s[i]);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first 
#define S second
const ll N = 3033 ;
ll n, dp[2][10111], w[N], v[N], s[N], ans;
pair<ll,ll> P[N] ;
int main ()
{
	scanf("%lld", &n) ;
	for(int i = 1 ; i <= n ; i ++){
		scanf("%lld%lld%lld", &w[i], &s[i], &v[i]) ;
		P[i].F = s[i]+w[i] ;
		P[i].S = i ; 
	}
	sort(P+1, P+n+1) ;
	for(int i = w[P[1].S] ; i < 10111 ; i ++)
		dp[0][i] = v[P[1].S] ;
 	ans = v[P[1].S] ;
 	for(int i = 2 ; i <= n ; i ++){
		for(int j = 0 ; j < 10111 ; j ++)
			dp[1][j] = dp[0][j] ; 
		ans= max(ans, dp[0][s[P[i].S]]+v[P[i].S]) ;
		for(int j = w[P[i].S] ; j <= P[i].F ; j ++){
			dp[0][j] = max(dp[0][j], dp[1][j-w[P[i].S]] + v[P[i].S]) ;
		}
		for(int j = 1 ; j < 10111 ; j ++)
			dp[0][j] = max(dp[0][j], dp[0][j-1]) ;
	}
	cout << ans ;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <map>
using namespace std;
#define REP(n) for(int i=0;i<n;i++)
#define INF_32 0x7fffffff;



int main() {
	long long N,M;
	cin >> N >> M;
	vector<long long> X(M);
	vector<long long> X_diff(M);
	REP(M) {
		cin >> X[i];
		X[i] += +100000;
	}

	sort(X.begin(), X.end());
	
	for (int i = 1; i < M; i++) {
		X_diff[i] = X[i] - X[i - 1];
	}
	sort(X_diff.rbegin(), X_diff.rend());
	
	long long ans = 0;
	
	for (int i = N - 1; i < X_diff.size() ; i++) {
		ans += X_diff[i];
	}

	cout << ans;


	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
	
	int W,H,x,y,r;
	
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	

	
	if((x-r)>=0 && x+r<=W && (y-r)>=0 && (y+r)<=H)
	{
		printf("Yes\n");
	}
	
	else 
	{
		printf("No\n");
	}
	
	
	// your code goes here
	return 0;
	
	
	
}



Measured memory_bytes: 2140
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[] countArr = new int[n];
        int count = 0;

        countArr[0] = 0;
        for (int i = 1; i < arr.length; i++) {
            if ("AC".equals("" + arr[i - 1] + arr[i])) {
                count++;
            }
            countArr[i] = count;
        }

//        for (int i = 0; i < countArr.length; i++) {
//            System.out.print(countArr[i]);
//        }
//        System.out.println("+++++++++");
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(countArr[r - 1] - countArr[l - 1]);
        }
    }
}


Measured memory_bytes: 70268
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>

typedef long long ll;

using namespace std;

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

    vector<int> num(n, 0);

    for (int i = 0; i < q; ++i) {
        int a;
        cin >> a;
        --a;
        num[a]++;
    }

    for (int i = 0; i < n; i++) {
        if(k-(q-num[i]) <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

vi pos[105];
vi pos1[105];

bool cmp(pair<pi, int> a, pair<pi, int> b){
	return (int)(pos[a.se].size()) < (int)(pos[b.se].size());
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<pair<pi, int>> a(n), b(n);
	rep(i, n) cin >> a[i].fi.fi >> a[i].fi.se, a[i].se = i;
	rep(i, n) cin >> b[i].fi.fi >> b[i].fi.se, b[i].se = i;
	int ans = 0;
	rep(i, n) rep(j, n) if(a[i].fi.fi < b[j].fi.fi && a[i].fi.se < b[j].fi.se){
		pos[i].pb(j);
		pos1[j].pb(i);
	}
	sort(all(a), cmp);
	vi vis(n, 0);
	rep(i, n){
		int cur = -1;
		int mn = 1e9;
		rep(j, pos[a[i].se].size()) if(!vis[pos[a[i].se][j]]){
			int nw = pos1[pos[a[i].se][j]].size();
			if(nw < mn) cur = pos[a[i].se][j], mn = nw;
		}
		if(cur != -1){
			rep(j, pos[a[i].se].size()){
				rep(k, pos1[pos[a[i].se][j]].size()){
					if(pos1[pos[a[i].se][j]][k] == a[i].se){
						pos1[pos[a[i].se][j]].erase(pos1[pos[a[i].se][j]].begin() + k);
						break;
					}
				}
			}
			vis[cur] = 1;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/



Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n,m,q=get_i
info=array(n,n,0)
m.times do
  l,r=get_i
  l-=1
  r-=1
  info[l][r]+=1
end
table=array(n+1,n+1,0)
n.times do|i|
  n.times do|j|
    table[i+1][j+1]=table[i][j+1]+table[i+1][j]-table[i][j]+info[i][j]
  end
end
q.times do
  l,r=get_i
  l-=1
  r-=1
  puts table[r+1][r+1]+table[l][l]-table[l][r+1]-table[r+1][l]
end

Measured memory_bytes: 6652
def abc151c_welcome_to_at_coder():
    n, m = map(int, input().split())
    penalty = [0] * n
    sum_penalty = 0
    ac = [0] * n
    for i in range(m):
        p, s = input().split()
        if ac[int(p) - 1] == 0:
            if s == 'WA':
                penalty[int(p) - 1] += 1
            else:
                ac[int(p) - 1] = 1
                sum_penalty += penalty[int(p) - 1]
    print(sum(ac), sum_penalty)


abc151c_welcome_to_at_coder()

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

int main()
{
 
 char N[4] ;
 scanf("%s",N);

  int d = N[strlen(N)-1] - '0';

  if (d == 2 || d == 4 || d == 5 || d == 7 || d == 9)printf("hon");
  else if (d == 0 || d == 1 || d == 6 || d == 8)printf("pon");
  else if (d== 3) printf("bon");



  return 0;
}


Measured memory_bytes: 1728
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int counter = 0;

    for(int i = 0; i < 21; i++){
      for(int j = 0; j < A + 1; j++){
        int amount = 500 * i + j;
        if(amount == N){
          counter = 1;
        }
      }
    }

    if(counter == 1){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
bool use1[101010];
bool use2[101010];

signed main()
{
	int N;
	cin >> N;
	priority_queue<P> L, L1;
	priority_queue<P, vector<P>, greater<P> > R, R1;
	for (int i = 0; i < N; i++)
	{
		int l, r;
		cin >> l >> r;
		L.push(P(l, i));
		L1.push(P(l, i));
		R.push(P(r, i));
		R1.push(P(r, i));
	}
	int now = 0;
	int ans = 0;
	int cnt = 0;
	while (1)
	{
		P p = L.top();
		L.pop();
		while (use1[p.second])
		{
			if (L.empty()) break;
			p = L.top();
			L.pop();
		}
		if (use1[p.second]) break;
		use1[p.second] = true;
		int to = p.first;
		if (to <= now) break;
		ans += to - now;
		now = to;
		cnt++;
		if (cnt == N) break;
		p = R.top();
		R.pop();
		while (use1[p.second])
		{
			if (R.empty()) break;
			p = R.top();
			R.pop();
		}
		if (use1[p.second]) break;
		use1[p.second] = true;
		to = p.first;
		if (now <= to) break;
		ans += now - to;
		now = to;
		cnt++;
		if (cnt == N) break;
	}


	ans = ans + abs(now);
	int ans1 = 0;
	cnt = 0;
	now = 0;

	while (1)
	{
		P p = R1.top();
		R1.pop();
		while (use2[p.second])
		{
			if (R1.empty()) break;
			p = R1.top();
			R1.pop();
		}
		if (use2[p.second]) break;
		use2[p.second] = true;
		int to = p.first;
		if (now <= to) break;
		ans1 += now - to;
		now = to;
		cnt++;
		if (cnt == N) break;
		p = L1.top();
		L1.pop();
		while (use2[p.second])
		{
			if (L1.empty()) break;
			p = L1.top();
			L1.pop();
		}
		if (use2[p.second]) break;
		use2[p.second] = true;
		to = p.first;
		if (to <= now) break;
		ans1 += to - now;
		now = to;
		cnt++;
		if (cnt == N) break;
	}
	cout << max (ans, ans1 + abs(now)) << endl;
}

Measured memory_bytes: 6852
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  int n;
  cin>>n;
  V<int> d(n);
  for(int i=0;i<n;i++)cin>>d[i];
  sort(all(d));
  ll ans=0;
  for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
             ans+=lower_bound(all(d),d[i]+d[j])-d.begin()-j-1;     
      }
  }
  cout<<ans<<endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n" 
#define MOD 1000000009

const int MAXN = 2e5 +15;
 
using namespace std;

vector<int> adj[MAXN];
int vis[MAXN];
int cnt=0,mcnt = -1;

void dfs(int x){
	cnt++;
	vis[x] = 1;
	for(auto v: adj[x]){
		if(vis[v] == 0) dfs(v);
	}
}

void solve(){	
	int n,m; cin>>n>>m;
	map<pair<int,int>,bool > mp;
	for(int i=0; i<m; i++){
		int a,b; cin>>a>>b;
		if(mp[{a,b}] == 0){
			adj[a].pb(b);
			adj[b].pb(a);
			mp[{a,b}] = 1;
		}
	}
	for(int i=1; i<=n; i++){
		if(vis[i] == 0){
			cnt = 0;
			dfs(i);
			mcnt = max(cnt,mcnt);
		}
	}
	cout<<mcnt;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);	
	cout<<fixed<<setprecision(12);

	int t =1; //cin>>t;
	for(int i=1; i<= t; i++){
		solve();
		cout<<"\n";
	}
	
	return 0;
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  long long x = N / K;
  if (K % 2 == 1) cout << x * x * x << endl;
  else {
    long long y = (N + K / 2) / K;
    cout << x * x * x + y * y * y << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]){
    int n=1;
    int sumA, sumB;
    int a, b;
    int i;
    scanf("%d", &n);
    while(n!=0){
        sumA=0; sumB=0;
        for(i=0;i<n;i++){
            scanf("%d %d", &a, &b);
            if(a>b){
                sumA = sumA + a + b;
            }else if(a<b){
                sumB = sumB + a + b;
            }else{
                sumA = sumA + a;
                sumB = sumB + b;
            }
        }
        printf("%d %d\n", sumA, sumB);
        scanf("%d", &n);
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end() 
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll; 
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279


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

 	int t{},T{};
 	//cin>>t;T=t;
    t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        ll n{},m{},ans{},x,tt,k{},a{},b{},c{},f{1};
        string str;
        cin>>str;
        n=str.length();
        F(i,0,n){
            a+=str[i]-'0';
        }
        if(a%9==0){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
        
    }
    
    
	return 0;
}

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] T = new long[N];
		for(int i = 0 ; i < T.length ; i++) {
			T[i] = sc.nextLong();
		}
		long ans = T[N - 1];
		int i;
		for (i = N - 2 ; i >= 0 ; i--)
			if (ans % T[i] != 0) {
				ans = lcm(ans, T[i]);
			}
		System.out.println(ans);
	}

	public static long gcd(long a, long b) {
		long v0 = a, v1 = b, v2 = a % b;
		while (v2 != 0) {
			v0 = v1;
			v1 = v2;
			v2 = v0 % v1;
		}
		return v1;
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()

const int ALPHABET_NUM = 26;

int main()
{
  int n; cin >> n;
  vector<map<int, int>> mps(n);
  for (int i = 0; i < n; ++i) {
    string s; cin >> s;

    for (int j = 0; j < s.size(); ++j) {
      mps[i][s[j]-'a']++;
    }
  }

  vector<int> ans(ALPHABET_NUM, 1e9);
  for (int j = 0; j < ALPHABET_NUM; ++j) {
    for (int i = 0; i < n; ++i) {
      ans[j] = min(ans[j], mps[i][j]);
    }
  }

  for (int i = 0; i < ALPHABET_NUM; ++i) {
    cout << string(ans[i], 'a' + i);
  }
}

Measured memory_bytes: 256
def bubble_sort(vec, num)
  num.times do |i|
    (num - 1).downto(i + 1) do |j|
      vec[j], vec[j - 1] = vec[j - 1], vec[j] if vec[j][1] < vec[j - 1][1]
    end
  end
end

def selection_sort(vec, num)
  num.times do |i|
    minj = i
    (i...num).each do |j|
      minj = j if vec[j][1] < vec[minj][1]
    end

    vec[i], vec[minj] = vec[minj], vec[i]
  end
end

n = gets.to_i
cards1 = gets.split.map { |x| x.split('') }
cards2 = cards1.dup

bubble_sort(cards1, n)
selection_sort(cards2, n)

n.times do |i|
  print ' ' unless i.zero?
  print cards1[i].join
end

puts
puts 'Stable'

n.times do |i|
  print ' ' unless i.zero?
  print cards2[i].join
end

puts

if cards1 == cards2
  puts 'Stable'
else
  puts 'Not stable'
end



Measured memory_bytes: 6904
package main

import (
	"fmt"
)

func chmax(a *int, b int) bool {
	if *a < b {
		(*a) = b
		return true
	}
	return false
}

func main() {
	var N, W int
	fmt.Scan(&N, &W)

	var weight = make([]int, N)
	var value = make([]int, N)

	for i := range weight {
		fmt.Scan(&weight[i], &value[i])
	}

	var dp = make([][]int, N+1)
	for i := range dp {
		dp[i] = make([]int, W+1)
	}

	for i := range weight {
		for sum := 0; sum <= W; sum++ {
			if sum-weight[i] >= 0 {
				chmax(&dp[i+1][sum], dp[i][sum-weight[i]]+value[i])
			}
			chmax(&dp[i+1][sum], dp[i][sum])
		}
	}

	fmt.Println(dp[N][W])
}

Measured memory_bytes: 81792
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;
const ll INF = 1LL << 60;

int n,m;
int dp[100005];
vector<vector<int>> G;

int rec(int v){
  if(dp[v] != -1) return dp[v];
  int res = 0;
  
  for(auto nv:G[v]){
    chmax(res,rec(nv)+1);
  }
  
  return dp[v] = res;
  
}

int main(){
  cin >> n >> m;
  G.assign(n,vector<int>());
  rep(i,m){
    int x,y; cin >> x >> y;
    x--,y--;
    G[x].push_back(y);
  }
  
  rep(i,n) dp[i] = -1;
  
  int ans = 0;
  rep(i,n) chmax(ans,rec(i));
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    cout << string(sz(s), 'x') << '\n';
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  string s;
  cin >> s;
  int a=0;
  rep(i,6){
      if (s[i]=='1') a++;
  }
  cout << a << endl;
}


Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

int n, a[mxn];
ll ans;
ll memo[4][mxn];
bitset<mxn> vstd[4];
ll dp(int prv, int at) {
    if (at==n+1) return prv/2;
    auto &ret = memo[prv][at];
    if (vstd[prv][at]) return ret;
    vstd[prv][at] = 1;
    ret = 0;
    int mp = min(a[at], prv);
    for (int i = 0; i <= mp; i++) {
        ret = max(ret, i+(prv-i)/2+dp(a[at]-i, at+1));
    }
    return ret;
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        int tmp = ((a[i]&1) ? a[i]-1 : max(a[i]-2, 0));
        a[i] -= tmp, ans += tmp/2;
    }
    cout << ans+dp(0, 1) << '\n';
}// 9 1 1 1 1 1 2 2 2 1

Measured memory_bytes: 9344
#include<stdio.h>

typedef unsigned long long ull;

int main(void){
  int num,sum;
  int i,j;
  while(scanf("%d",&num)&&num){
    sum=0;
    for(i=2;i*i<=num;i++){
      if(num%i==0){
	sum+=i+num/i;
	if(i==num/i) sum-=i;
      }
    }
    if(num!=1) sum++;
    if(sum<num) puts("deficient number");
    else if(sum==num) puts("perfect number");
    else puts("abundant number");
  }
  return 0;
}

    

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
#include<set>
#include<iterator>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
typedef long long ll;
int main(){
    int n;
    set<int>a,b;
    cin>>n;
    while(n--){
        int x;
        cin>>x;
        a.insert(x);
    }
    cin>>n;
    while(n--){
        int x;
        cin>>x;
        b.insert(x);
    }
    vector<int>c;
    set_union(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
    for(int i=0;i<c.size();i++)cout<<c[i]<<endl;
    return 0;
}


Measured memory_bytes: 23672
#include <iostream>
#include <vector>
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<vector<ll>> a(n, vector<ll>(n));
  rep(i, n)rep(j, n) cin >> a[i][j];
  vector<vector<bool>> x(n, vector<bool>(n, false));
  bool flag = false;
  rep(k, n)rep(i, n)rep(j, n){
    if (a[i][j] > a[i][k] + a[k][j]) flag = true;
  }
  rep(i, n)rep(j, n)rep(k, n){
    if(i == k || j == k) continue;
    if (a[i][j] == a[i][k] + a[k][j]) x[i][j] = true;
  }
  if (flag)
    cout << -1 << endl;
  else {
    ll ans = 0;
    rep(i, n)rep(j, n){
      if (x[i][j]) continue;
      ans += a[i][j];
    }
    cout << ans/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
S = input()
N = len(S)

def is_kaibun(str_):
    return str_ == str_[::-1]

if is_kaibun(S) and is_kaibun(S[:(N-1)//2]) and is_kaibun(S[(N+3)//2-1:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pp pair<int,int> 
#define v(T) vector<T>
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
 
int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n){
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,m){
    int b=q.top(); q.pop();
    q.push(b/2); 
  }
  ll ans=0;
  rep(i,n){
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,l;cin>>n>>l;
	ll t = n*l+(n*(n-1))/2;
	ll diff = 1e18;
	ll ans = -1;
	For(i,0,n){
		ll t2 = t-(l+(i));
		if(abs(t-t2)<diff){
			diff = abs(t-t2);
			ans = t2;
		}
	}

	cout<<ans<<endl;











	
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<stdio.h>



using namespace std;


int main(void)
{
	int n;
	int num;
	int sum = 0;
	cin >> n;
	vector<int> v(n);
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	int t;
	for (i = 0 ; i < n-1; i++)
	{
		for (t = i+1; t < n; t++)
		{
			num = v[i] * v[t];
			sum = sum + num;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x,a;
    cin>>x>>a;
    if(x<a) cout<<0<<endl;
    else cout<<10<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int a[MAX_N];
int b[MAX_N];


int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int X, Y, Z;
  cin >> X >> Y >> Z;

  cout << Z << " " << X << " " << Y << endl;
  
  return 0;
  
}


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

int main(){
   char a[1002];
   int x;
   scanf("%s",&a);

   x = strlen(a);
   if(a[x-1]!='s'){
       a[x] = 's';
       a[x+1] = '\0';
    } else {
        a[x] =  'e';
       a[x+1] = 's';
       a[x+2] = '\0';
    }
    printf("%s",a);
}



Measured memory_bytes: 1736
def test(length, cost):
    tmp = length.replace('()', '')
    if len(length) < 2 or len(tmp) == len(length):
        return length
    return test(tmp, len(length))

n = int(input())
s = input()
last = test(s, len(s))
print(last.count(')') * '(' + s + last.count('(') * ')')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      int n, m, x;
      cin >> n >> m >> x;
      int c[n], a[n][m];
      for(int i = 0; i < n; i++)
      {
        cin >> c[i];
        for(int j = 0; j < m; j++)
          cin >> a[i][j];
      }
      int sol = INT_MAX;
      for(int i = 1; i < (1 << n); i++)
      {
        vector<int> val(m);
        int cost = 0;
        for(int row = 0; row < n; row++)
        {
          if((i & (1 << row)) == 0)
            continue;
          cost += c[row];
          for(int j = 0; j < m; j++)
         	val[j] += a[row][j];
        }
        bool can = true;
        for(int j = 0; j < m; j++)
          if(val[j] < x)
            can = false;
        if(can)
          sol = min(sol, cost);
      }
      if(sol == INT_MAX)
        sol = -1;
      cout << sol;
     
      return 0;
    }

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll mul(ll x, ll y)
{
    return (x * 1ll * y) % MOD2;
}

ll fastpow(ll x, ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}
ll dp[1001][1001] ;
char a[1001][1001] ;

int main(int argc, char** argv)
{   sws ;
   // tcase
    {
    ll h,w ;
    cin>>h>>w ;
   // char a[h][w] ;
    forn(i,h)
    {
    	forn(j,w)
    	{  dp[i][j]=0;
    	   
    		cin>>a[i][j] ;
    
		}
	}
	if(a[0][0]=='.')
	dp[0][0]=1 ;
	for(int i=1;i<h;i++)
	{
		if(a[i][0]=='.')
	dp[i][0]=dp[i-1][0] ;
	}
	for(int j=1;j<w;j++)
	{
		if(a[0][j]=='.')
	dp[0][j]=dp[0][j-1] ;
	}
	for(int i=1;i<h;i++)
	{
		for(int j=1;j<w;j++)
		{
			if(a[i][j]=='.')
			{
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
			}
		}
	}
	cout<<dp[h-1][w-1]<<"\n" ;
	
    }
return 0 ;
}

Measured memory_bytes: 12416
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;





int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(b[i]>=a[n/2]){cout<<a[n/2-1]<<endl;}
        else{cout<<a[n/2]<<endl;}
    }
    
    
    
    return 0;
}


Measured memory_bytes: 5376
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, w[200], s[200], ans = 100009;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> w[0];
    s[0] = w[0];
    for (int i = 1; i < n; i++) {
        cin >> w[i];
        s[i] = s[i - 1];
        s[i] += w[i];
    }
    for (int i = 0; i < n - 1; i++) {
        ans = min(ans, abs(s[n - 1] - s[i] - s[i]));
    }
    cout << ans << "\n";
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
import itertools
n=int(input())
p=tuple([int(i) for i in input().split()])
q=tuple([int(i) for i in input().split()])
x=list(itertools.permutations(range(1,n+1)))
nc=len(x)

for i in range(nc):
  if x[i]==p:
    pn=i
    
for j in range(nc):
  if x[j]==q:
    qn=j


print(abs(pn-qn))

Measured memory_bytes: 8052