akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
	int N;
	vector <int> D;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int d;
		cin >> d;
		D.push_back(d);
	}
	
	std::sort(D.begin(), D.end());

	vector <int> hours;
	hours.push_back(0);
	int pm = 1;
	for (int i = 0; i < N; i++) {
		hours.push_back(D[i]*pm);
		pm *= -1;
	}
	std::sort(hours.begin(), hours.end());
	hours.push_back(hours.at(0)+24);

	int ans = 12;
	for (int i = 0; i < hours.size()-1; i++)
		ans = min(ans, hours.at(i+1)-hours.at(i));

	cout << ans << endl;

  return 0;
}


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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n, m;
  while(cin >> n >> m, n+m) {
    pii dp[110][110];
    rep(i, m+1) rep(j, m+1) dp[i][j].first = dp[i][j].second = 1<<25;
    while(n--) {
      int a, b, cost, time; cin >> a >> b >> cost >> time;
      dp[a][b].first = dp[b][a].first = cost;
      dp[a][b].second = dp[b][a].second = time;
    }

    rep(i, m+1) dp[i][i].first = dp[i][i].second = 0;

    rep(k, m+1) rep(i, m+1) rep(j, m+1) {
      dp[i][j].first = min(dp[i][j].first, dp[i][k].first + dp[k][j].first);
      dp[i][j].second = min(dp[i][j].second, dp[i][k].second + dp[k][j].second);
    }
      
    int k; cin >> k;
    rep(i, k) {
      int p, q, r; cin >> p >> q >> r;
      if(r == 0) cout << dp[p][q].first << endl;
      else cout << dp[p][q].second << endl;
    }
  }
}

Measured memory_bytes: 1248
#include <stdio.h>
int main(void){



 int H, W;
 int h, w; 
 while (1) {
     scanf("%d%d", &H, &W); 
     if (H == 0 && W == 0) break; for (h = 0; h < H; h++) {for (w = 0; w < W; w++) {
             putchar(((h & 1) ^ (w & 1)) == 0 ? '#' : '.'); } 
             putchar('\n'); } putchar('\n'); } 




return 0;    
}



Measured memory_bytes: 2140
import numpy as np
MAX = 10**5
isPrime = np.full(MAX+1,True)
isPrime[:2] = False
for p in range(2,MAX+1):
    if p*p > MAX: break
    if isPrime[p]: isPrime[p*p::p] = False

mat = np.zeros(MAX+1,np.int32)
for p in range(1,MAX+1):
    if 2*p > MAX: break
    if isPrime[p] and isPrime[2*p-1]: mat[2*p-1] = 1

cum = mat.cumsum()

Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    print(cum[r]-cum[l-1])

Measured memory_bytes: 16572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    double r;
    cin >> r;
    printf("%.10f\n", r * 6.283185307179586232);
    return 0;
}

Measured memory_bytes: 3760
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class D
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int K = Int32.Parse(args[1]);
		string S = Console.ReadLine();
		
		// 1-0-1-...-0-1
		List<int> nums = new List<int>(N);
		int  now = 1;
		int counter = 0;
		for(int i = 0; i < N; i++)
		{
			if(S[i] == (char)('0' + now))
			{
				counter++;
			}
			else
			{
				nums.Add(counter);
				now = 1 - now;
				counter = 1;
			}			
		}
		if(counter != 0)
			nums.Add(counter);
		
		if(nums.Count % 2 == 0)
			nums.Add(0);
		
		int[] csum = new int[nums.Count + 1];
		for(int i = 0; i < nums.Count; i++)
			csum[i+1] = csum[i] + nums[i];
		
		int result = 0;
		for(int i = 0; i < nums.Count; i+=2)
		{
			int left = i;
			int right = Math.Min(i + 2 * K + 1, nums.Count);
			int tmp = csum[right] - csum[left];

			result = Math.Max(result, tmp);
		}
		
		Console.WriteLine(result);		
	}	
}





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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 100005;

int main(){
  int N; cin >> N;
  int pt,px,py,t,x,y;
  pt = px = py = 0;
  rep(i,N){
    scanf("%d%d%d",&t,&x,&y);
    int d = (t-pt)-(abs(x-px) + abs(y-py));
    if(!(d>=0 && d%2==0)){
      cout << "No" << endl;
      return 0;
    }
    pt = t; px = x; py = y;
  }
  cout << "Yes" << endl;
  return 0;
}

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

typedef struct{
    int s;
    int c;
}pair_t;

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){

    int N,M,i,ans[11] = {0},flag = 1;
    pair_t pair[11] = {0};

    scanf("%d %d",&N,&M);
    for(i = 0;i < M;i++){
        scanf("%d %d",&pair[i].s,&pair[i].c);
    }

    qsort(pair,M,sizeof(pair_t),compare_int);

    if(N > 1) ans[1] = 1;
    for(i = 0;i < M;i++){
        if(pair[i].s == pair[i+1].s && pair[i].c != pair[i+1].c){
            flag = 0;
        }
        ans[pair[i].s] = pair[i].c;
    }

    if(flag == 0 || ans[1] == 0){
        if(flag == 0 || N > 1) printf("-1\n");
        else printf("0\n");
    }else{
        for(i = 1;i <= N;i++){
            printf("%d",ans[i]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
(let* ((s (read-line))
       (y (parse-integer (subseq s 0 4)))
       (m (parse-integer (subseq s 5 7)))
       (d (parse-integer (subseq s 8))))
      (if (and
           (<= y 2019)
           (<= m 4)
           (<= d 30))
          (princ "Heisei")
          (princ "TBD")))

Measured memory_bytes: 4836
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  k=I()

  l=[]

  for i in range(len(s)):
    l.append(s[i])
    l.append(s[i:i+2])
    l.append(s[i:i+3])
    l.append(s[i:i+4])
    l.append(s[i:i+5])

  l=list(set(l))
  l.sort()

  return l[k-1]

print(main())


Measured memory_bytes: 8088
#include<stdio.h>
int main()
{
    int a,b,i,j;
    int d=0,f,g,h;
    scanf("%d",&a);
    int x[a];
    char c[12];
    for(i=0;i<a;i++){
        scanf("%s %d",c,&b);
        if(c[0]=='i'){
            x[i]=b;
        }
        else if(c[6]=='F'){
            i-=2;
	    a-=2;
        }
        else if(c[6]=='L'){
            i--;
	    a--;
	    d++;
        }
        else{
            i--;
	    a--;
            f=0;
            for(j=i;j>=0;j--){
                if(f>0)break;
                if(b==x[j]){
                    g=i-j;
                    h=0;
                    f++;
                    while(g!=h++){
		      x[j+h-1]=x[j+h];		  
		    }
		    i--;
		    a--;
                }
            }
        }
    }
    for(i=0;i<a-d;i++){
      if(i==a-d-1){
	printf("%d\n",x[a-1-i]);
      }
      else{
	printf("%d ",x[a-1-i]);
      }
    }
    return 0;
}

Measured memory_bytes: 6304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;

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

    vector<int> tup(3);
    int fives = 0, sevens = 0;
    for (int i = 0; i < 3; ++i) {
        cin >> tup[i];
        if (tup[i] == 5) {
            ++fives;
        }
        if (tup[i] == 7) {
            ++sevens;
        }
    }
    //cout << fives << ' ' << sevens << '\n';
    if (sevens == 1 && fives == 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
     int i,j,k,n,m;
     scanf("%d%d",&n,&m);
     k=1;
     for(i=0;i<n;i++)
     {
          if(k<=m)
               k=k*2;
          else
               k=k+m;
     }
     printf("%d\n",k);
     return 0;
}


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

int main() {
    int n, l, r;
    while(cin >> n >> l >> r, n) {
        vector<int> a(n);
        for(int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        int ans = 0;
        for(int i = l; i <= r; ++i) {
            int idx = -1;
            for(int j = 0; j < n; ++j) {
                if(i % a[j] == 0) {
                    idx = j;
                    break;
                }
            }
            if(idx == -1) {
                ans += n % 2 == 0;
            } else {
                ans += idx % 2 == 0;
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  string s;
  cin>>n>>s;
  for(int p=0;p<4;++p){
    string t(n,'?');
    t[0]=a=(p%2?'S':'W');
    t[1]=b=(p/2%2?'S':'W');
    for(int i=1;i<=n;++i){
      int prev=(i%n==0?n-1:i-1);
      int next=(i==n-1?0:i%n+1);
      if((s[i%n]=='o'&&t[i%n]=='S')||(s[i%n]=='x'&&t[i%n]=='W')){
        t[next]=t[prev];
      }
      else t[next]=(t[prev]=='S'?'W':'S');
    }
    if(t[0]==a&&t[1]==b){
      cout<<t<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,arr[100009],Dp[100009];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    Dp[1]=0;
    for(int i=2;i<=n;i++)Dp[i]=1000009;
    Dp[2]=abs(arr[1]-arr[2]);
    int sum=0;
    for(int i=3;i<=n;i++)
    {
        Dp[i]=min(Dp[i-1]+abs(arr[i-1]-arr[i]),Dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    cout<<Dp[n];
}

Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int height = scan.nextInt();
        int count = 0;
        int i = 0;
        for (i = 0; i < num; i++){
            int heightI = scan.nextInt();
            if(heightI >= height){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 49564
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


int main() {
	int l, r, d,i=0,s=0;
	cin >> l >> r >> d;
	rep2(i, l, r+1) {
		if (i % d == 0) {
			s++;
		}
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int one[64];
int main() {
	int N; cin >> N;
	vector<ll> a(N); rep(i, N) cin >> a[i];
	ll ans = 0;
	rep(i, 60) {
		ll x = 0;
		rep(j, N) if (a[j]>>i & 1) x++;
		ll temp = x * (N-x) % MOD;
		rep(j, i) temp = temp * 2 % MOD;
		ans += temp;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007LL
#define all(x) x.begin() , x.end()
#define ld long double
void solve();
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}
void solve()
{
	ll n; cin >> n;
	ll arr[n]; for (auto &x : arr) cin >> x;
	ll psum[n + 1];
	psum[0] = 0;
	for (int i = 0; i < n; i++) psum[i + 1] = (psum[i] + arr[i]) % mod;
	ll res = 0;
	for (int i = 0; i < n; i++)
	{
		ll tp = (psum[i] * arr[i]) % mod;
		(res += tp) %= mod;
	}
	cout << res;
	cout << "\n";
	return ;
}

Measured memory_bytes: 6764
main :: IO ()
main = do
    str <- getLine
    let inputs = [read word :: Int | word <- words str]
    let a = head inputs
    let b = head $ tail inputs
    let c = head . tail $ tail inputs

    print . length $ divisor a b c

divisor :: Int -> Int -> Int -> [Int]
divisor a b c = [ n | n <- [a .. b],  c `mod` n == 0]

Measured memory_bytes: 4080
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll a, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 10000;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

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

void solve() {
	int n; cin >> n;
	vector<string> s(n);
	rep(i, n)cin >> s[i];
	sort(all(s));
	s.erase(unique(all(s)), s.end());
	cout << s.size() << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init_f();
	//init();
	//experi();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}

Measured memory_bytes: 9548
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,ans;
long long a[100001];
int gcd(int x, int y)
{
	if(y == 0)
	return x;
	if(x < y)      
	return gcd(y,x);
	else      
	return gcd(y,x%y);
}
int  main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
		{
			cin>>a[i];
			a[i]=abs(a[i]-m);
		}
	sort(a+1, a+n+1);
	ans=a[n];
	for(int i=n-1; i>=1; i--)
		ans=gcd(ans,a[i]);
		cout<<ans;
		return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double ans = sqrt(A*A + B*B - 2*A*B*cos(M_PI/6 * H + M_PI/360 * M - M_PI/30 * M));
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 4100
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,int>P;
int main(void){
	int n;
	int t;
	int i;
	int x,y;
	int flg;
	P box[200001];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x>>y;
		box[i].F=y;
		box[i].S=x;
	}
	sort(box,box+n);
	//for(i=0;i<n;i++)	cout<<box[i].F<<" "<<box[i].S<<endl;
	t=0;
	flg=0;
	for(i=0;i<n;i++){	
		x=box[i].S;
		y=box[i].F;
		t+=x;
		if(t>y){
			flg=1;
			break;
		}
	}
	cout<<((flg)?"No":"Yes")<<endl;
	return 0;
}

	

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

vector<int> edge[200005];
vector<int> ans(200005);
vector<int> x(200005);

void dfs(int s, int prev, int add){
    add += x[s];
    ans[s] = add;
    for (auto v : edge[s]) {
        if(v == prev) continue;
        dfs(v, s, add);
    }
    add -= x[s];
}


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

    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].emplace_back(b);
        edge[b].emplace_back(a);
    }

    rep(i, q) {
        int p, x_;
        cin >> p >> x_;
        x[--p] += x_;
    }

    dfs(0, -1, 0);

    rep(i, n){
        cout << ans[i];
        if(i!=n-1){
           cout << " ";
        }else{
            cout << endl;
        }
    }
    // printf("%d\n", N);
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int arr[] = new int[n + 1], srt[] = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			arr[i] = sc.nextInt();
			srt[i] = arr[i];
		}
		Arrays.sort(srt);
		for (int i = 1; i <= n; i++) {
			System.out.println(srt[n / 2 + (arr[i] >= srt[n / 2 + 1] ? 0 : 1)]);
		}
	}

}

Measured memory_bytes: 61936
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
        int W=scanner.nextInt();
        int H=scanner.nextInt();
        int x=scanner.nextInt();
        int y=scanner.nextInt();
        int r=scanner.nextInt();
		if(x>=r && y>=r && x<=W-r && y<=H-r ){
			System.out.printf("Yes\n");
		}
		else System.out.printf("No\n");
	}
}


Measured memory_bytes: 26444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

/*int darma_max(vector<vector<int> > dp, int ){
    

}*/

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    vector<int> ans;
    while(true){
        int N; cin >> N;
        //ans.resize(N);
        if(N == 0){
            REP(i,ans.size()){
                cout << ans[i] << endl;
            }
            return 0;
        }
        else{
            vector<vector<int> >dp(N+1,vector<int>(N+1,0));
            vector<int> darma(N);
            vector<bool> flag(N,false);
            //flag.resize(N,false);
            /*REP(i,N+1){
                dp[i][i] = true; //半開区間？
            }*/
            REP(i,N){cin >> darma[i];}

            for(int w = 2; w <= N; w++){
                for(int left = 0; left + w <= N; left++){
                    int right = left + w;
                    if((dp[left+1][right-1] == w-2) && (abs(darma[left] - darma[right-1]) <= 1)){
                        dp[left][right] = w;
                        //flag[left] = true; flag[right-1] = true;
                    }
                    else{
                        for(int mid = left + 1; mid < right; mid++){
                            /*if(dp[left][mid] && dp[mid][right]){
                                dp[left][right] = true;
                                break;
                            }*/
                            dp[left][right] = max(dp[left][right], dp[left][mid] + dp[mid][right]);
                        }
                    }
    
                }
            }
            //cout << dp[3][7] << endl;
            /*REP(i,N){
                cout << flag[i] << endl;
            }*/
            /*int maxi = 0;
            REP(i,N-1){
                FOR(k,i,N){
                    if(dp[i][k]){
                        maxi = max(maxi,k-i);
                    }
                }
            }*/
            /*int ans_now = 0;
            int now = 0;
            while(now < N-1){
                while(!flag[now]){
                    now++;
                }
                for(int next = N; now < next; next--){ //バグりポイント flag[i] = trueだけの情報では、それが前に繋がっているのか後ろに繋がっているかわからないから、nextの範囲は指定しないといけない。
                    if(dp[now][next]){
                        ans_now += (next-now);
                        now = next;
                    }
                }
            }*/
            ans.push_back(dp[0][N]); 
            
        }
    }
}


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

int main()
{
	string s;
	cin >> s;

	int sum=0;
	for(int j=0;j<s.length();j++){
		sum = sum + int(s[j] - '0');
	}

	if(sum % 9 == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3752
object Main{
  def comparision(a:Int,b:Int):Unit={
    if(a > b)println("a > b")
    if(b > a)println("a < b")
    if(a == b)println("a == b")
  }
  def main(args:Array[String]){
    var sc = new java.util.Scanner(System.in) 
    var a = sc.nextInt
    var b = sc.nextInt
    comparision(a,b)
  }
}

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

int main(){
	int n,k;
	cin>>n>>k;
	int a[n+1]={0};
	for(int i=1;i<=k;i++){
		int d,b;
		cin>>d;
		for(int j=0;j<d;j++){
			cin>>b;
			a[b]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==0)ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  ll a,b,c=0,d=0,e,f,g,h,n,m,ans=0;
  cin>>a>>b;
  if(a==1 || b==1) co(1);
  else co((a*b+1)/2);
  
  return 0;
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const int MAX   = 100;
const int INF   = (1 << 21);
const int white = 0;
const int gray  = 1;
const int black = 2;

int n, m[MAX][MAX];

int dijkstra() {
    int minV;
    int d[MAX], color[MAX];
    rep(i, n) {
        d[i]     = INF;
        color[i] = white;
    }

    d[0]     = 0;
    color[0] = gray;
    while (1) {
        minV  = INF;
        int u = -1;
        rep(i, n) {
            if (minV > d[i] && color[i] != black) {
                u    = i;
                minV = d[i];
            }
        }
        if (u == -1) break;
        color[u] = black;
        rep(v, n) {
            if (color[v] != black && m[u][v] != INF) {
                if (d[v] > d[u] + m[u][v]) {
                    d[v]     = d[u] + m[u][v];
                    color[v] = gray;
                }
            }
        }
    }
    rep(i, n) { cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl; }
}

// 単一始点最短経路
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    cin >> n;
    rep(i, n) {
        rep(j, n) { m[i][j] = INF; }
    }

    int k, c, u, v;
    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v >> c;
            m[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string str, a, b, ans="Yes";

    cin >> str;
    a = str.substr(0, (str.size()-1)/2);
    b = str.substr((str.size()+3)/2-1, str.size());
    for(int i=0; i<a.size(); i++)
      if(str[str.size()-(i+1)] != a[i]) ans = "No";

    for(int i=0; i<b.size(); i++)
      if(str[str.size()-(i+1)] != b[i]) ans = "No";


    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
int gcd(int a, int b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}
vector<int> to[maxn];
int a[maxn], vis[maxn];
vector<int> merge(const vector<int> &a, const vector<int> &b){
	int pa = 0, pb = 0, la = a.size(), lb = b.size();
	vector<int> ans;
	while(pa < la && pb < lb){
		if(a[pa] > b[pb]) ans.push_back(a[pa++]);
		else ans.push_back(b[pb++]);
	}
	while(pa < la) ans.push_back(a[pa++]);
	while(pb < lb) ans.push_back(b[pb++]);
	return ans;
}
vector<int> dfs(int u){
	vector<int> ans;
	vis[u] = 1;
	for(int v : to[u]){
		if(!vis[v]){
			ans = merge(ans, dfs(v));
		}
	}
	ans.insert(ans.begin(), a[u]);
	return ans;
}
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(gcd(a[i], a[j]) != 1){
			to[i].push_back(j);
		}
	}
	vector<int> ans;
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			ans = merge(ans, dfs(i));
		}
	}
	for(int v : ans) cout << v << " ";
	return 0;
}



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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000000007;

ll N, A, B, ans=0, tmp=0, ave=0;
double ave1;
vector<ll> V;
map<ll,ll> M; 
ll fac[MAX], finv[MAX], inv[MAX];

ll COM(ll n, ll k){
    ll num=1;
    for(int i=0;i<k;i++) {
        num *= n-i;
        num /= (1+i);
    }
    return num;
}

signed main(){
    cin >> N >> A >> B;
    for(int i=0;i<N;i++) {
        ll v;
        cin >> v;
        M[v]++;
        V.push_back(v);
    }
    sort(V.begin(), V.end());
    for(int i=N-1;i>=N-A;i--) {
        ave += V[i];
    }
    ave1 = (double)ave/(double)A;
    ll id1 = lower_bound(V.begin(), V.end(), V[N-A])-V.begin();
    if(id1!=N-A) {
        ll id2 = lower_bound(V.begin(), V.end(), V[N-A]+1)-V.begin();
        ans += COM(id2-id1, id2-(N-A));
        //cout << id2-id1 << " " << id2-(N-A) << " " << COM(id2-id1, id2-(N-A)) << endl;
        if(V[N-A]==V[N-1]) {
            for(int i=N-A-1;i>=max(N-B, id1);i--) {
                tmp = COM(id2-id1, id2-i);
                //if(tmp<0) tmp += MOD;
                ans += tmp;
                //cout << id2-id1 << " " << id2-i << " " << tmp << endl;
            }
        }
    }
    cout << fixed << setprecision(6) << ave1 << endl;
    cout << setprecision(18) << max(1LL, ans) << endl;
    //cout << setprecision(18) << (ll)pow(2,50)-1LL << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <stdio.h>

int main()
{
	int a, b, c, d;
	int ab_sq, cd_sq, ans_sq;
	
	scanf( "%d %d %d %d", &a, &b, &c, &d );
	
	ab_sq = a * b;
	cd_sq = c * d;
	
	if ( ab_sq < cd_sq )
	{
		ans_sq = cd_sq;
	}
	else
	{
		ans_sq = ab_sq;
	}
	printf( "%d\n", ans_sq );
	
	return 0;
}


Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<cstdio>
#define MN 500000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,p[MN+5],Q,a[MN+5];long long s[MN+5];
inline int abs(int x){return x<0?-x:x;}
int main()
{
    n=read();s[n+1]=1;p[0]=read();
    for(int i=1;i<=n;++i) a[i]=read(),p[i]=min(p[i-1],abs(p[i-1]-a[i]));
    for(int i=n;i;--i) s[i]=(a[i]>s[i+1]&&a[i]>=2*s[i+1])?s[i+1]:s[i+1]+a[i];
    Q=read();
    for(int i=1;i<=Q;++i)
    {
        int x=read();
        puts(p[x-1]>=s[x+1]?"YES":"NO");
    }
    return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
/*using P = pair<int, int>;*/
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

int main(){
    int n, m; cin >> n >> m;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    priority_queue<int> impossible;
    rep(i, m){
        int mount1, mount2; cin >> mount1 >> mount2;
        if(h[mount1-1] > h[mount2-1]) impossible.push(mount2);
        else if(h[mount1-1] < h[mount2-1]) impossible.push(mount1);
        else{
            impossible.push(mount1);
            impossible.push(mount2);
        }
    }
    int ans = 0;
    int cur_mount;
    if(!impossible.empty()){
        cur_mount = impossible.top();
        impossible.pop();
        ans++;
    }
    while(!impossible.empty()){
        int new_mount = impossible.top();
        if(cur_mount != new_mount) ans++;
        cur_mount = new_mount;
        impossible.pop();
    }
    cout << n - ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    int ac = 0, wa = 0, tle = 0, re = 0;
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "AC") ac++;
        if (s == "WA") wa++;
        if (s == "TLE") tle++;
        if (s == "RE") re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}

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

int fib(int n){
  if (n == 0) return 1;
  if (n == 1) return 1;
  else return fib(n-1) + fib(n-2);
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i=0;i<M;i++) cin >> A[i];
  
  vector<bool> row(N+1,1);
  for (int i=0;i<M;i++) row[A[i]] = 0;
  
  vector<long long> ans(N+1,1);
  for (long long i=N-2;i>=0;i--){
    ans[i] = row[i+1]*ans[i+1] + row[i+2]*ans[i+2];
    ans[i] %= 1000000007;
  }
  cout << ans[0] << endl; 
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");
        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        int mysum = 0;
        for (int i = 0; i < m; i++) {
            mysum += Integer.valueOf(arr02[i]);

        }

        if (mysum > n) {
            System.out.println(-1);
        } else {
            System.out.println(n - mysum);
        }
    }

}


Measured memory_bytes: 34712
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      #ifndef ONLINE_JUDGE
      freopen("inputf.in",  "r",   stdin);
      freopen("outputf.in", "w",  stdout);
      #endif
      FastIO
      lld a, b, c, k;
      cin >> a >> b >> c >> k;
      if (k > a){
      	lld sum = 0;
      	sum += a;
      	k-=a;
      	if (k > b){
      		k-=b;
      		if (k > c){
      			// do nothing
      		}
      		else{
      			sum -= k;
      			cout << sum << "\n";
      		}
      	}
      	else{
      		cout << sum << "\n";
      	}
      }
      else{
      	cout << k << "\n";
      }
      return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    int n,m;
    cin>>n>>m;
    pair<int,int> p[m];
    for (int i = 0; i < m; ++i) {
        cin>>p[i].second>>p[i].first;
    }

    sort(p,p+m);

    int mx=0;
    int cnt=0;
    for (int i = 0; i < m; ++i) {
        if(p[i].second>=mx)
        {
            mx=max(mx,p[i].first);
            cnt++;
        }
    }

    cout<<cnt;
}

Measured memory_bytes: 1792
N = int(input())

t,x,y = 0,0,0
for _ in range(1, N+1):
    tn,xn,yn = map(int, input().split())
    step = tn-t
    step_needed = abs(x-xn) + abs(y-yn)
    
    if step < step_needed or step%2 != step_needed%2:
        print("No")
        break
    t,x,y = tn,xn,yn
    
else:  
    print("Yes")

Measured memory_bytes: 9080
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine().ToCharArray();
        var k = int.Parse(input.ReadLine());

        Func<char, char> f = (cc) => {
            if(cc == 'z') return 'a';
            else return (char)(cc + 1);
        };

        for(int i=0; i<s.Length; i++) {
            var c = s[i];
            if(c != 'a' && 'z' - c + 1 <= k) {
                s[i] = 'a';
                k-=('z' - c + 1);
            }
        }

        if(k > 0) {
            long c = s[s.Length - 1] - 'a';
            c += k;
            c %= 'z' - 'a' + 1;
            s[s.Length -1] = (char)(c + 'a');
        }

        return new StringBuilder().Append(s);
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13276
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    int A,B;
    cin  >> A >> B  ;
    if((A+B)%2==0) cout << (A+B)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> vec;
    string tmp;
    for(int i=0;i<N;i++){
        cin >> tmp;
        vec.push_back(tmp);
    }

    // 昇順ソート
    sort(vec.begin(), vec.end());
    string ans;
    for(int i=0;i<N;i++){
        ans += vec[i];
    }
        
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <utility>
#include <functional>
#include <stack>
#include <deque>
#include <sstream>
using namespace std;

#define mod 1000000007
#define infinity (ll)1e8+1
#define PI 3.14159265358979

#define ll long long
#define pdd pair<double,double>
#define pll pair<ll, ll>
#define pii pair<int,int>

#define MP make_pair
#define SZ size()
#define PB push_back

#define vi vector<int>//ll
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define vch vector<char>
#define vb vector<bool>

#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()
#define X first
#define Y second

int n;
int m;
vpii ab;

int main()
{
	ios_base::sync_with_stdio(false);
	//ifstream in("In.txt");
	cin >> n >> m;
	int a, b;
	map<int, int> times;
	FOR(i, 0, m)
	{
		cin >> a >> b;
		ab.push_back(MP(a, b));
		times[a]++;
		times[b]++;
	}

	bool allEven = true;
	FOR(i, 1, n + 1)
		if (times[i] % 2 == 1)
		{
			allEven = false;
			break;
		}

	if (allEven)
		cout << "YES";
	else
	{
		cout << "NO";
	}

	return 0;
}

Measured memory_bytes: 5748
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
const int maxn=20;
const int maxpos=65540;
int my_popcount[maxpos];
ll a[maxn][maxn],val[maxpos],maxx[maxpos];
vector<int> tmp,useful[maxn];
void fl()
{
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}
int main()
{
//    fl();
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            scanf("%lld",&a[i][j]);
    for(int i=0;i<(1<<n);i++)
    {
        tmp.clear();
        for(int j=0;j<n;j++)
            if(i&(1<<j))
                tmp.push_back(j+1);
        for(int x=0;x<(int)tmp.size();x++)
            for(int y=x+1;y<(int)tmp.size();y++)
                val[i]+=a[tmp[x]][tmp[y]];
    }
    for(int i=0;i<(1<<n);i++)
    {
        my_popcount[i]=my_popcount[i>>1]+(i&1);
        useful[my_popcount[i]].push_back(i);
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<(int)useful[i].size();j++)
        {
            int mask=useful[i][j];
            maxx[mask]=val[mask];
            for(int sub=mask;sub;sub=(sub-1)&mask)
                maxx[mask]=max(maxx[mask],maxx[sub]+val[mask^sub]);
        }
    ll ans=maxx[(1<<n)-1];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 5224
#include<bits/stdc++.h>
using namespace std;
int b[2000];
int n;
char p[2000];
int query(int* a) {
    printf("? ");
    for(int i=1;i<=n;i++) {
        if(i<n) printf("%d ",a[i]);
        else printf("%d\n",a[i]);
    }
    fflush(stdout);
    int o;
    scanf("%s",p);
    if(p[0]=='R') return 1;
    else return 2;
}
int main() {
    scanf("%d",&n);
    int c[2000];
    for(int i=1;i<=n;i++) c[i]=i;
    int t=query(c);
    int l=2,r=n+1;
    while(l<r) {
        int m=(l+r)>>1;
        for(int i=1;i<=n;i++) c[i]=m+i-1;
        if(t!=query(c)) r=m;
        else l=m+1;
    }
    b[l-1]=t;
    b[l+n-1]=3-t;
    for(int i=1;i<=n-1;i++) c[i]=l+i-1;
    for(int i=1;i<l-1;i++) {
        c[n]=i;
        b[i]=query(c);
    }
    for(int i=l+n;i<=2*n;i++) {
        c[n]=i;
        b[i]=query(c);
    }
    int k=n/2;
    for(int i=1;i<=2*n && k>0;i++) {
        if(b[i]==t) {
            c[k]=i;
            k--;
        }
    }
    k=n/2;
    for(int i=1;i<=2*n && k>0;i++) {
        if(b[i]==3-t) {
            c[(n/2)+k]=i;
            k--;
        }
    }
    for(int i=l;i<l+n-1;i++) {
        c[n]=i;
        b[i]=query(c);
    }
    printf("! ");
    for(int i=1;i<=2*n;i++) {
        if(b[i]==1) printf("R");
        if(b[i]==2) printf("B");
    }
    printf("\n");
    fflush(stdout);
    return 0;
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  if (N%2==1) {
    cout << "No" << endl;
  }
  else {
    int M, A;
    M=N/2;
    A=0;
    for (int i=0; i<M; i++) {
      if (S.at(i)==S.at(M+i)) {
        A=A+1;
      }
    }
    if (A==M) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3620
n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
m=A[0]
for i in range(61):
    cnt0 = cnt1 = 0
    if m < 2 ** i:
        break
    for j, a in enumerate(A):
        if a < 2 ** i:
            cnt0 += n - j
            break
        if (a >> i) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
    ans %= mod

print(ans)


Measured memory_bytes: 124524
while 1:
    m,f,r=map(int, raw_input().split())
    if m==f==r==-1: break
    s=m+f
    if m==-1 or f==-1 or s<30: R="F"
    elif s>=80: R="A"
    elif s>=65: R="B"
    elif s>=50: R="C"
    elif r>=50: R="C"
    else: R="D"
    print R

Measured memory_bytes: 6444
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
a.unshift(0)
a.push(0)
c = Array.new(n + 2, 0)
1.step(n + 1) do |i|
  c[i] = a[i] - a[i - 1]
end
cs = c.inject(0) {|acc, x| acc += x.abs }
1.step(n) do |i|
  res = cs - c[i].abs - c[i + 1].abs
  res += (c[i] + c[i + 1]).abs
  puts res
end

Measured memory_bytes: 13316
n,m,k=map(int,input().split())

par = [-1]*n
num = [0]*n

def find(x):
    if par[x]<0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x, y):
    p,q=find(x), find(y)
    if p==q:
        return
    if p>q:
        p,q = q,p
    par[p] += par[q]
    par[q] = p

def size(x):
    return -par[find(x)]

def same(x,y):
    return find(x)==find(y)

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    union(a,b)
    num[a]+=1
    num[b]+=1

for i in range(k):
    c,d=map(int,input().split())
    c-=1
    d-=1
    if same(c,d):
        num[c]+=1
        num[d]+=1

for i in range(n):
    print(size(i)-1-num[i], end=" ")

Measured memory_bytes: 11500
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, dp[1000000], dp2[1000000];

void solve() {
  cout<<dp[n]<<" "<<dp2[n]<<endl;
}

int main (int argc, char const* argv[]) {
  memset(dp, -1, sizeof dp);
  memset(dp2, -1, sizeof dp2);
  
  dp[0] = dp2[0] = 0;
  for (int i = 1; i < 1000000; i += 1) {
    dp[i] = dp2[i] = i;
    for (int j = 1;; j += 1) {
      int s = j * (j + 1) * (j + 2) / 6;
      if (s > i) break;
      dp[i] = min(dp[i], dp[i - s] + 1);
      if (s % 2) {
        dp2[i] = min(dp2[i], dp2[i - s] + 1);
      }
    }
  }
  
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 8568
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll C[100007];
vector<vector<ll>> V(100007);
 
int main(){
  ll N,K,a,b,ans[100007];
  cin >> N >> K;
  rep(i,N-1){
    cin >> a >> b;
    V[a].pb(b);
    V[b].pb(a);
  }
  queue<pair<ll,ll>> Q;
  Q.push(mp(1,0));
  C[1]=1;
  while(!Q.empty()){
    auto X = Q.front();
    Q.pop();
    ll T=1;
    if(X.sc==0){
      ans[X.fr]=0;
      T--;
    }
    else{
      ans[X.fr]=X.sc;
    }
    rep(i,V[X.fr].size()){
      if(C[V[X.fr][i]]==0){
        T++;
        Q.push(mp(V[X.fr][i],T));
        C[V[X.fr][i]]=1;
      }
    }
  }
  ll X=1;
  Rep(i,1,N+1){
    X*=K-ans[i];
    X%=MOD;
  }
  cout << X << endl;
}

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

int main(){
	vector<int> vec_height(10);
	
	for (auto& h : vec_height)
		cin >> h;

	sort(vec_height.begin(), vec_height.end(), greater<int>());
	
	cout
		<< vec_height[0] << endl
		<< vec_height[1] << endl
		<< vec_height[2] << endl;
	
    return 0;
}

Measured memory_bytes: 1204
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    N=len(S)
    alps=[chr(i) for i in range(97,97+26)]
    flags=[False]*26
    if N<26:
        for i in range(N):
            flags[ord(S[i])-97]=True
        for i in range(26):
            if flags[i]==False:
                s=alps[i]
                break
        print(S+s)

    else:
        if S=="zyxwvutsrqponmlkjihgfedcba":
            print(-1)
        else:
            k=0
            for i in range(26):
                if i==0:
                    j=ord(S[i])-97
                else:
                    if ord(S[i-1])-97<ord(S[i])-97:
                        k=i
                        j=ord(S[i])-97

            target1=S[k-1]
            for i in range(k,26):
                if i==k:
                    target2=S[k]
                else:
                    if ord(target1)-97<ord(S[i])-97<ord(target2)-97:
                        target2=S[i]

            print(S[:k-1]+target2)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064