akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.Point2D;
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new aoj1155().doIt();
    }
    class aoj1155{
    	int dp_table(int n){
    		Circle[] c=new Circle[n];
            int[] a=new int[n];
            for(int i=0; i<n; i++){
                c[i]=new Circle(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()-1);
                for(int j=0; j<i;j++){
                	if(c[i].dis+c[j].dis > c[i].p.distance(c[j].p)) a[i] |= (1<<j);
                }
            }
            int ans=n;
            boolean[] dp=new boolean[1<<n];
            dp[(1<<n)-1]=true;
            for(int i=(1<<n)-1; i>=0; i--){
            	if(dp[i]){
            		for(int j=0; j<n; j++){
            			if((i&(1<<j))>0 && (i&a[j])==0){
            				for(int k=j+1; k<n; k++){
            					if(j!=k && (i&(1<<k))>0 && (i&a[k])==0 && c[j].color==c[k].color){
            						int tmp=(1<<j)|(1<<k);
            						int next=i&(((1<<n)-1)^tmp);
            						dp[next]=true;
            						ans = Math.min(ans, Integer.bitCount(next));
            					}
            				}
            			}
                    }
                }
            }
            return -(ans - n);
    	}
    	void doIt(){
    		while(true){
    			int n = sc.nextInt();
    			if(n == 0)break;
                System.out.println(dp_table(n));
    		}
    	}
    	class Circle{
    		Point2D p;
    		double dis;
    		int color;
    		public Circle(double x,double y,double dis,int color){
    			this.p = new Point2D.Double(x,y);
    			this.dis = dis;
    			this.color = color;
    		}
    	}
     }
}

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

int main(){
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> k(n-1, 0);
  vector<int> l(3);
  
  rep(i,n){
    rep(j,n){
      if(i<j){
        l[0] = abs(j-i);
        l[1] = abs(x-1-i)+1+abs(j-(y-1));
        l[2] = abs(y-1-i)+1+abs(j-(x-1));
        int ll = *min_element(begin(l), end(l));
        k[ll-1]++;
      }
    }
  }
  rep(i,n-1){
    cout << k[i] << endl;
  }
  return 0;
}

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

int main() {
  ll q, h, s, d, n; cin >> q >> h >> s >> d >> n;
  ll c = min(q * 4, min(h * 2, s));
  if (c * 2 <= d) cout << n * c << endl;
  else cout << d * (n / 2) + c * (n % 2) << endl;
  
  return 0;
}

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

int main(){
    string s ;
    cin >> s ;
    bool odd = true ;
    bool even = true ;
    int size = s.size() ;
    for (size_t i = 0; i < size; i++)
    {
        if (i%2 == 0)
        {
            if (odd == false)
            {
                continue ;
            }
            if (s.at(i) == 'L')
            {
                odd = false ;
            }
            
        }else
        {
            if (even == false)
            {
                continue ;
            }
            if (s.at(i) == 'R')
            {
                even = false ;
            }
        }
        
        
    }
    if (odd == true && even == true)
    {
        cout << "Yes" << endl ;
    }else
    {
        cout << "No" << endl ;
    }
    
    
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	}
}

Measured memory_bytes: 39472
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 200001;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
        signed main() {
    COMinit();
    int n,k;
    cin>>n>>k;
    k=min(n,k);
    int ans=0;
    for(int i=0;i<=k;i++){
            ans=(ans+COM(n,i)*COM(n-1,i)%MOD)%MOD;
          //  cerr<<ans<<endl;
    }
    cout<<ans;

    
      }

        


Measured memory_bytes: 4992
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)


func main() {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	m := make(map[string]int, N)
	for sc.Scan() {
		m[sc.Text()]++
	}

	fmt.Printf("AC x %d\n", m["AC"])
	fmt.Printf("WA x %d\n", m["WA"])
	fmt.Printf("TLE x %d\n", m["TLE"])
	fmt.Printf("RE x %d\n", m["RE"])
}


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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 //998244353
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){	if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;}	return ans;}
template <typename T> 
T Min(T a,T b){ return a<b?a:b; }
template <typename T>
T Max(T a,T b){ return a>b?a:b; }

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	int n;cin>>n;
	repi(i,n) cout<<"ACL";cout<<endl;
	
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int N = 105;

int n, m;
int dp[N][N];
char grid[N][N];

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			cin >> grid[i][j];
			dp[i][j] = INF;
		}
	}
	dp[1][1] = (grid[1][1] == '#');
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			if (i == 1 && j == 1) continue;
			if (i > 1) {
				dp[i][j] = min(dp[i][j], dp[i-1][j] + (grid[i][j] == '#' && grid[i-1][j] == '.'));
			}
			if (j > 1) {
				dp[i][j] = min(dp[i][j], dp[i][j-1] + (grid[i][j] == '#' && grid[i][j-1] == '.'));
			}
		}
	}
	cout << dp[n][m] << '\n';
	
	return 0;
}


Measured memory_bytes: 892
A, B, C, D = map(int,list(input()))

if A+B+C+D == 7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))

elif A+B+C-D == 7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    
elif A+B-C+D == 7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    
elif A-B+C+D == 7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    
elif A+B-C-D == 7:
    print("{}+{}-{}-{}=7".format(A,B,C,D))
    
elif A-B+C-D == 7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    
elif A-B-C+D == 7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    
elif A-B-C-D == 7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

int main(){
    cin.tie(0), ios::sync_with_stdio(false);
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2==0) cout << a-b << endl;
    else cout << b-a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;


#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(),i.end()
#define debug(i) std::cout << i << "\n"



const int INF = 100000000;
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;
    if(y%2){
        return (x*pow_mod(x,y-1,mod))%mod;
    }else{
        return pow_mod(x*x,y/2,mod);
    }
}

int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!

  ll n,ans=0;
  std::cin>>n;
  rep(i,1,n+1){
    ll temp=i,cnt=0;
    while(temp>0){
      cnt++;
      temp/=10;
    }
    if(cnt%2)ans++;
  }
  std::cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define MOD 1000000007
using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<ll> fac, finv, inv;
void COMinit(int max, ll mod){
    fac.resize(max);
    finv.resize(max);
    inv.resize(max);

    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (int i = 2; i < max; i++)
    {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(int n, int k, ll mod){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(void) {
    int S;
    cin >> S;

    int maxlen = S/3;

    if(maxlen == 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;

    COMinit(S, MOD);
    for (int i = 2; i <= maxlen; i++)
    {
        int residue = S - 3*i;
        ans += COM(residue + i - 1, i-1, MOD);
        ans %= MOD;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100

int pop(void);
void push(int);

int stackPointer=0;
int stack[N];

int main(){
  int x=0,n,y=0;
  char s[N];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x=pop();
      y=pop();
      push(x+y);
    } else if ( s[0] == '-' ){
      x=pop();
      y=pop();
      push(y-x);
    } else if ( s[0] == '*' ){
      x=pop();
      y=pop();
      push(x*y);
    } else {
      n = atoi(s);
      push(n);
    }
  }
  printf("%d\n",stack[stackPointer]);
  return 0;
}

int pop(){
  stackPointer--;
  return stack[stackPointer+1];
}

void push(int s){
  stackPointer++;
  stack[stackPointer]=s;
  return;
}

Measured memory_bytes: 548
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),sum=0,a=0;
		int[] t=new int[n];
		for(int i=0;i<n;i++) {
			t[i]=sc.nextInt();
			sum+=t[i];
		}
		int m=sc.nextInt();
		for(int i=0;i<m;i++) {
			a=t[sc.nextInt()-1]-sc.nextInt();
			System.out.println(sum-a);
		}
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
	double a, b, C;
	cin >> a >> b >> C;

	double S, L, h, radC, c;
	radC = C *acos(-1) / 180;
	S = 0.5 * a * b * sin(radC);
	c = sqrt(a*a + b*b - 2 * a*b*cos(radC));
	L = a + b + c;
	h = 2 * S / a;

	printf("%lf\n%lf\n%lf\n", S, L, h);

	return 0;
}



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

int C, D, W, X, E[15+1][30+1], F[15+1][30+1], dp[30+1][50+1][5+1];

int solve(int d, int w, int x)
{
  if (d >= D)
    return 0;

  if (dp[d][w][x] != -1)
    return dp[d][w][x];

  int ret = solve(d+1, w, x);
  for (int i = 0; i < C; ++i) {
    if (E[i][d] != 0 && w+F[i][d] <= W) {
      ret = max(ret, solve(d+1, w+F[i][d], x)+E[i][d]);
      if (x+1 <= X) {
	int now_w = w+F[i][d], now_e = E[i][d];
	for (int j = i-1; j >= 0; --j) {
	  if (E[j][d] == 0 || now_w+F[j][d] > W)
	    break;
	  now_w += F[j][d];
	  now_e += E[j][d];
	  ret = max(ret, solve(d+1, now_w, x+1)+now_e);
	}

	now_w = w+F[i][d], now_e = E[i][d];
	for (int j = i+1; j < C; ++j) {
	  if (E[j][d] == 0 || now_w+F[j][d] > W)
	    break;
	  now_w += F[j][d];
	  now_e += E[j][d];
	  ret = max(ret, solve(d+1, now_w, x+1)+now_e);
	}
      }
    }
  }
  return dp[d][w][x] = ret;
}

int main()
{
  while (cin >> C >> D >> W >> X) {
    if ((C|D|W|X) == 0)
      break;

    for (int i = 0; i < C; ++i) {
      for (int j = 0; j < D; ++j)
	cin >> E[i][j];
    }

    for (int i = 0; i < C; ++i) {
      for (int j = 0; j < D; ++j)
	cin >> F[i][j];
    }

    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 908
N, M, Q = map(int, input().split())
trains = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    trains[L][R] += 1
for i in range(1, N + 1):
    for j in range(1, N + 1):
        trains[i][j] += trains[i - 1][j]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        trains[i][j] += trains[i][j - 1]
ans = [0] * Q
for k in range(Q):
    p, q = map(int, input().split())
    ans[k] = trains[q][q] - trains[p-1][q] - trains[q][p-1] + trains[p-1][p-1]
for A in ans:
    print(A)

Measured memory_bytes: 22352
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll h,w,a,b;
    ci(h>>w>>a>>b);

  FOR(i,0,h){
    st s;
    FOR(j,0,w){
      if(i<b&&j<a){
        s+='0';
      }

      else if(i>=b&&j>=a){
        s+='0';
      }

      else{
        s+='1';
      }
    }
    cout<<s<<endl;
  }
}


Measured memory_bytes: 1280
import java.util.Scanner;
import static java.lang.System.out;
import java.util.Arrays;
public class Main{
   public static void main(String []args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      boolean flag = true;
      int count = 0;
      int array[] = new int[N];  
      for(int i=0; i<N;i++){
         array[i] = sc.nextInt();

      }
      Arrays.sort(array);

      for(int i=0;i<N; i++){
         if(i ==N-1){
            ++count;
            break;
         }
         if(array[i] == array[i+1]){
            i +=1;
         }else{
            ++count;
         }
      }  out.println(count);
      }
      
   }

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

#define N	50
#define M	100
#define K	100
#define MD	1000000007

int min(int a, int b) { return a < b ? a : b; }

int vv[M + K + 1], ff[M + K + 1], gg[M + K + 1], tt[M + 1], pp[M + 1];

void init(int k) {
	int i, j;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= M + K; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
		ff[i] = (long long) ff[i - 1] * i % MD;
		gg[i] = (long long) gg[i - 1] * vv[i] % MD;
	}
	for (i = 1; i <= M; i++)
		tt[i] = i;
	for (i = 2; i <= M; i++) {
		if (tt[i] != i)
			continue;
		for (j = i; j <= M; j += i)
			tt[j] = tt[j] / i * (i - 1);
	}
	pp[0] = 1;
	for (i = 1; i <= M; i++)
		pp[i] = (long long) pp[i - 1] * k % MD;
}

int *oh[N], oo[N];

void link(int i, int h) {
	int o = oo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		oh[i] = (int *) realloc(oh[i], o * 2 * sizeof *oh[i]);
	oh[i][o] = h;
}

int ij[M], ds[M], ke[M];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j, ke[j] += ke[i];
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i, ke[i] += ke[j];
	}
}

int ta[N], tb[N];

void dfs(int f, int i) {
	static int time;
	int o;

	ta[i] = tb[i] = ++time;
	for (o = 0; o < oo[i]; o++) {
		int h = oh[i][o], j = i ^ ij[h];

		if (h != f) {
			if (!ta[j]) {
				dfs(h, j);
				tb[i] = min(tb[i], tb[j]);
				if (tb[j] < ta[i])
					join(h, f);
			} else if (ta[j] < ta[i]) {
				tb[i] = min(tb[i], ta[j]);
				join(h, f);
			}
		}
	}
}

int count(int n) {	/* https://en.wikipedia.org/wiki/Burnside%27s_lemma */
	int m, cnt;

	cnt = 0;
	for (m = 1; m <= n; m++)
		if (n % m == 0)
			cnt = (cnt + (long long) pp[m] * tt[n / m]) % MD;
	cnt = (long long) cnt * vv[n] % MD;
	return cnt;
}

int choose(int n, int k) {
	return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

int main() {
	static int kv[M];
	static char used[M];
	int n, m, k, h, i, j, ans;

	scanf("%d%d%d", &n, &m, &k), init(k);
	for (i = 0; i < n; i++)
		oh[i] = (int *) malloc(2 * sizeof *oh[i]);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		ij[h] = i ^ j;
		link(i, h), link(j, h);
	}
	for (h = 0; h < m; h++)
		ds[h] = -1, ke[h] = 1;
	for (i = 0; i < n; i++)
		if (!ta[i])
			dfs(-1, i);
	for (i = 0; i < n; i++) {
		int o;

		for (o = 0; o < oo[i]; o++) {
			h = find(oh[i][o]);
			if (!used[h])
				used[h] = 1, kv[h]++;
		}
		for (o = 0; o < oo[i]; o++)
			used[find(oh[i][o])] = 0;
	}
	ans = 1;
	for (h = 0; h < m; h++)
		if (ds[h] < 0)
			ans = (long long) ans * (ke[h] == 1 ? k : (ke[h] == kv[h] ? count(ke[h]) : choose(ke[h] + k - 1, k - 1))) % MD;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int N = 100010;
#define x first
#define y second
#define pb push_back
#define mp make_pair

string S,T;
int freq[27],p[200010],bit[200010];
deque<int> q[27];

void add(int idx){
	while(idx <= S.size()){
		bit[idx]++;
		idx += (idx&-idx);
	}
}
int get(int idx){
	int res = 0;
	while(idx){
		res += bit[idx];
		idx -= (idx & -idx);
	}
	return res;
}
int main() {
	memset(p,-1,sizeof p);
	cin >> S;
	for (int i = 0; i < S.size(); ++i){
		freq[S[i] - 'a']++;
		q[S[i] - 'a'].pb(i);
	}
	int odd = 0;
	for (int i = 0; i < 26; ++i) {
		odd += (freq[i] & 1);
	}
	if (odd > 1) {
		puts("-1");
		return 0;
	}
	int idx = 0;
	for (int i = 0; i < S.size(); ++i) {
		if (freq[S[i]-'a']<=1)continue;
		p[q[S[i]-'a'].front()]=idx;
		p[q[S[i]-'a'].back()]=S.size()-idx-1;
		q[S[i]-'a'].pop_back();
		q[S[i]-'a'].pop_front();
		freq[S[i]-'a'] -= 2;
		idx++;
	}
	for (int i = 0; i < 26; ++i){
		while(q[i].size()){
			p[q[i].front()] = S.size()/2;
			q[i].pop_front();
		}
	}
	for (int i = 0; i < S.size(); ++i){
		p[i]++;
		//cout << p[i] << " ";
	}
	//cout << endl;
	ll cnt = 0;
	for (int i = S.size()-1;i >= 0; --i){
		cnt += get(p[i]);
		add(p[i]);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 2820
#include <iostream>
using namespace std;
int dp[21][50010], c[21];

const int INF = 1e9;

int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> c[i];

  for (int i = 0; i < m; i++) {
    for (int j = 1; j <= n; j++) {
      if (!i) dp[i][j] = dp[i][j - c[i]] + 1;
      else {
        if (j - c[i] >= 0) dp[i][j] = min(dp[i-1][j], dp[i][j - c[i]] + 1);
        else dp[i][j] = dp[i-1][j];
      }
      //cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
    }
  }

  cout << dp[m-1][n] << endl;
  return 0;
}

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

int id[20],dist[20],cnt[20];
double dp[1<<15][15];
pair<int,int> prev[1<<15][15];

int W[1<<15];


int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++){
			cin >> id[i] >> dist[i] >> cnt[i];
		}
		for(int i = 0 ; i < (1<<15) ; i++)
			for(int j = 0 ; j < 15 ; j++)
				dp[i][j] = 1e12;
		for(int i = 0 ; i < n ; i++)
			dp[0][i] = 0;
		for(int i = 0 ; i < (1<<n) ; i++){
			int aaa = 0;
			for(int j = 0 ; j < n ; j++)
				if(i>>j&1) aaa += cnt[j];
			W[i] = aaa;
		}
		for(int i = 0 ; i < (1<<n) ; i++){
			for(int j = 0 ; j < n ; j++){
				for(int k = 0 ; k < n ; k++){
					double cost = abs(dist[j]-dist[k]) / ( 2000.0 / (70+20*W[i]) )+dp[i][j];
					if( dp[i|(1<<k)][k] > cost + 1e-9 ){
						prev[i|(1<<k)][k] = make_pair(i,j);
						dp[i|(1<<k)][k] = cost;
					}
				}
		
			}
		}
		double minCost = 1e12;
		for(int i = 0 ; i < n ; i++){
			minCost = min( dp[(1<<n)-1][i] , minCost) ;
		}
		for(int i = 0 ; i < n ; i++){
			if( fabs(minCost - dp[(1<<n)-1][i]) < 1e-9){
				int bit = (1<<n)-1;
				int k = i;
				vector<int> idd;
				while(bit){
					idd.push_back(k);
					pair<int,int> tmp = prev[bit][k];
					bit = tmp.first;
					k = tmp.second;
				}
				reverse(idd.begin(),idd.end());
				for(int j = 0 ; j < n ; j++)
					cout << id[idd[j]] << (char)(j==n-1?10:32);
			}
		}
	}	
}

Measured memory_bytes: 9024
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;


ll gcd(ll l, ll r)
{
	if (l < r) swap(l, r);
	while(true)
	{
		ll m = l % r;
		if (m == 0) return r;
		l = r;
		r = m;
	}
}

ll lcm(ll l, ll r)
{
    ll gcdlr = gcd(l, r);
    ll lf = l / gcdlr;
    ll rf = r / gcdlr;
    return gcdlr * lf * rf;
}

int main()
{
    int N;
    cin >> N;
    vi a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];

    int ok_i = 0, broken = 0;
    for (int i = 0; i < N; i++)
    {
        if (a[i] == ok_i + 1)
            ok_i++;
        else
            broken++;
    }
    if (ok_i == 0)
        broken = -1;
       
    cout << broken << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>

#define rep(i, n) for(int i=0;i<n;i++)
#define IOS() ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define INT_MINI -987654321
#define INT_MAXI 987654321
#define ABS(X) ((X) < 0 ? -(X) : (X))


using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

long double a, b, c;


void input() {

    cin >> a >> b >> c;
}

void process() {

    long double aa, bb, cc;
    long double eps = 1.0E-14;
    aa = sqrt(a);
    bb = sqrt(b);
    cc = sqrt(c);
    

    if(aa + bb + eps < cc) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    input();
    process();

    return 0;
}


Measured memory_bytes: 256
n=gets.chomp.to_i
answers = []

input_values = gets.chomp.split.map(&:to_i)
# i = 0
# (n-1).times do
#   (n-1).times do |i|
#     if input_values[i] > input_values[i+1]
#       tmp = input_values[i+1]
#       input_values[i+1] = input_values[i]
#       input_values[i] = tmp
#     end
#   end
# end
#
# min = input_values[0]
# max = input_values[-1]
# sum = 0
# i = 0
# n.times do
#   sum += input_values[i]
#   i += 1
# end
# answers.push(min, max, sum)
# puts answers.join(' ')

def search_min(array, length)
  min = array[0]
  for i in 1..(length-1)
    if min > array[i]
      min = array[i]
    end
  end
  return min
end

def search_max(array, length)
  max = array[0]
  for i in 1..(length-1)
    if max < array[i]
      max = array[i]
    end
  end
  return max
end

def calc_sum(array, length)
  sum = 0
  for i in 0..(length-1)
    sum += array[i]
  end
  return sum
end

answers.push(search_min(input_values, n), search_max(input_values, n), calc_sum(input_values, n))
puts answers.join(' ')

Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	

	int n;
	cin >> n;
	n %= 10;
	if (n == 3) {
		cout << "bon\n";
	} else if (n == 0 || n == 1 || n == 6 || n == 8) {
		cout << "pon\n";
	} else {
		cout << "hon\n";
	}
}

Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,a,b,c,d,val0,val1;
  bool can=false;
  cin >> n >> a >> b >> c >> d;
  for(int i=0;i<n;i++){
    val0 = c*(n-1-i) - d*i; 
    val1 = -c*i + (n-1-i)*d; 
    if(val0<=(b-a)&&(b-a)<=val1){
      can = true;
      break;
    }
  }
  if(can){
    cout <<"YES\n";
  }else{
    cout <<"NO\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(All(a));
    int now=0;
    int res=0;
    for(int i=0;i<n-1;i++){
        now+=a[i];
        if(now*2<a[i+1]){
            res=0;
        }
        else{
            res++;
        }
    }
    res++;
    cout<<res<<endl;
}

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

const static double	de_PI	= 3.14159265358979323846;
//const static int	de_MOD	= 1000000007;
//const static int	de_MAX	= 999999999;
//const static int	de_MIN = -999999999;

inline std::vector<std::string> Split_String(const std::string &str, const char key) {

	std::vector<std::string> result;
	std::stringstream SS(str);
	std::string temp;

	while (std::getline(SS, temp, key)) {
		result.push_back(temp);
	}

	return(result);

}

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());

	std::string str;
	double x = 0, y = 0, rad = 0;
	int distance = 0, degree = 0;

	while (std::cin >> str) {

		std::vector<std::string> v = Split_String(str, ',');
		distance = std::stoi(v[0]);
		rad = degree * de_PI / 180.0;

		x += distance * sin(rad);
		y += distance * cos(rad);

		degree += std::stoi(v[1]);
	}

	std::cout << static_cast<int>(x) << std::endl;
	std::cout << static_cast<int>(y) << std::endl;
}

Measured memory_bytes: 3420
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll D,N;cin>>D>>N;
    ll ans;
    if(N!=100)ans=pow(100,D)*N;
    else ans=ans=pow(100,D)*(N+1);
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
if len(a)%2 == 0:
    for i in a[::-2]:
        print(i,end=" ")
    for i in a[::2]:
        print(i,end=" ")
else:
    for i in a[::-2]:
        print(i,end=" ")
    for i in a[1::2]:
        print(i,end=" ")

Measured memory_bytes: 26180
if __name__ == '__main__':
    H, W = map(int, input().split())
    s_list = [list(input()) for i in range(H)]


    answer = "Yes"

    for x in range(H):
        for y in range(W):
            if s_list[x][y] == '.':
                continue
            is_all_white = True
            dxs = [0, 1, 0, -1]
            dys = [1, 0, -1, 0]
            for dx, dy in zip(dxs, dys):
                nx = x + dx
                ny = y + dy
                if 0 <= nx <= H-1 and 0 <= ny <= W-1:
                    if s_list[nx][ny] == "#":
                        is_all_white = False
                        break
            if is_all_white:
                answer = "No"
                break
        if s_list[x][y] == '#' and is_all_white:
            break

    print(answer)

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

int main() {
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double Mi = H*60.0+M;
    double x = Mi*0.5;
    double y = M*6.0;
    double theta = abs(x-y);
    if(theta>=180) theta = 360.0-theta;
    double PI = 3.14159265358979;
    double ans = sqrt(A*A+B*B-2*A*B*cos(theta*PI/180.0));
    printf("%.12lf",ans);
}


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

using namespace std;

typedef long long int64;
const int INF = 1 << 29;

int main()
{
  int N, A[100000];

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

  int64 ret = 0, toll = 1;
  for(int i = 0; i < N; i++) {
    auto get = (A[i] - 1) / toll;
    ret += get;
    if(toll == 1 || toll == A[i]) ++toll;
  }

  cout << ret << endl;
}

Measured memory_bytes: 640
X=int(input())
List=[1]
for i in range(2,32):
  j=2
  while True:
    if i**j<=1000:
      List.append(i**j)
      j+=1
    else:
      break
x=1
for i in range(len(List)):
  if List[i]<=X:
    x=max(x,List[i])
print(x)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


// import here

int main(){
    LL n, k;
    cin >> n >> k;
    LL ans = 0;
    while(n > 0){
        ans += 1;
        n /= k;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int X,A,B;
  scanf("%d",&X);
  scanf("%d",&A);
  scanf("%d",&B);
  
  if(A>=B)
    printf("delicious");
  else if(A+X>=B)
    printf("safe");
  else
    printf("dangerous");
  
  return 0;
}

Measured memory_bytes: 128
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    string s;cin >> s;
    if(s=="Sunny")puts("Cloudy");
    else if(s=="Cloudy")puts("Rainy");
    else puts("Sunny");
    
    return 0;
}

Measured memory_bytes: 3472
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int d;
		int r;
		double f;
		
		d=a / b;
		r=a % b;
		f=(double)a / b;
		//????????????
		System.out.printf("%d %d %.5f",d,r,f);
	}
}

Measured memory_bytes: 17192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>


int main(){
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0 ; i < n ;++i)
        cin >> arr[i];
    int ans, m = INT_MAX;
    for (int p = 1 ; p <= 100 ; ++p){
        int tmp = 0;
        for (int i = 0 ; i < n ; ++i)
            tmp += (arr[i]-p)*(arr[i]-p);
        if (tmp < m){
            m = tmp;
            ans = p;
        }
    }
    cout << m;
    return 0;
}


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

int main()
{
	double a,b,h,m,tmp;
	double aph1;
	double aph2;
	while(cin>>a>>b>>h>>m)
	{
		cout<<setiosflags(ios::fixed)<<setprecision(20);
		tmp=1.0*h*60+m;
		aph1=1.0*tmp/(12*60)*3.1415926535898*2;
		aph2=1.0*m/60*3.1415926535898*2;
		tmp=abs(aph1-aph2);
		double ans=a*a+b*b-2*a*b*cos(tmp);
		cout<<sqrt(ans)<<endl;
	}
	
return 0;
 } 

Measured memory_bytes: 4172
#include <bits/stdc++.h>
//#define DEBUG

using namespace std;
int n, a[132510];
struct node {
    int id, point;
} node[1<<18];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

Measured memory_bytes: 3148
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(1000):
  tmp = [x-i, x+i]
  if tmp[0] not in p:
    print(tmp[0])
    exit()
  elif tmp[1] not in p:
    print(tmp[1])
    exit()

Measured memory_bytes: 61996
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        public static void main(String[] args){
          ArrayDeque<Character> queue = new ArrayDeque<Character>();
          char[] ch = mySplit(getStr());
          for(int i = 0; i < ch.length; i++){
            queue.add(ch[i]);
          }
          int Q = getInt();
          boolean isReverse = false;
          for(int i = 0; i < Q; i++){
            int T = getInt();
            if(T == 1){
              isReverse = !isReverse;
            }else{
              int F = getInt();
              if(isReverse){
                if(F == 1){
                  F = 2;
                }else{
                  F = 1;
                }
              }
              char[] addChar = mySplit(getStr());
              if(F == 1){
                queue.addFirst(addChar[0]);
              }else{
                queue.addLast(addChar[0]);
              }
            }
          }
          StringBuilder sb = new StringBuilder("");
          while(!queue.isEmpty()){
              if(isReverse){
                 sb.append(queue.pollLast());
              }else{
                sb.append(queue.pollFirst());
              }
          }
          myout(sb.toString());
        }
        //Method addition frame start

        //Method addition frame end
}


Measured memory_bytes: 95540
using System;

class Program
{
    static void Main(string[] args)
    {
        var observatory = Console.ReadLine().Split(' ');
        var elevation = Console.ReadLine().Split(' ');
        bool[] goodObservatory = new bool[int.Parse(observatory[0])];

        for (int idx = 0; idx < goodObservatory.Length; idx++)
        {
            goodObservatory[idx] = true;
        }

        for (int idx = 0; idx < int.Parse(observatory[1]); idx++)
        {
            var road = Console.ReadLine().Split(' ');

            if (int.Parse(elevation[int.Parse(road[0]) - 1]) == int.Parse(elevation[int.Parse(road[1]) - 1]))
            {
                goodObservatory[int.Parse(road[0]) - 1] = false;
                goodObservatory[int.Parse(road[1]) - 1] = false;
                continue;
            }

            if (int.Parse(elevation[int.Parse(road[0]) - 1]) > int.Parse(elevation[int.Parse(road[1]) - 1]))
            {
                goodObservatory[int.Parse(road[1]) - 1] = false;
            }
            else
            {
                goodObservatory[int.Parse(road[0]) - 1] = false;
            }
        }

        int count = 0;
        for(int idx = 0; idx < goodObservatory.Length; idx++)
        {
            if (goodObservatory[idx]) count++;
        }

        Console.WriteLine(count.ToString());
    }
}

Measured memory_bytes: 48692
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	double tea[4]={0.25, 0.5, 1.0, 2.0};

	ll cost[4], costp[4], n;

	rep(i, 4){
		cin>>cost[i];
		costp[i]=cost[i]<<(3-i);
	}
	cin>>n;

	if(n==1){
		int min=1e9, mini;
		rep(i, 3){
			if(min>costp[i]){
				min=costp[i];
				mini=i;
			}
		}
		cout<<(1.0/tea[mini])*cost[mini]<<endl;
	}else{
		int lim=4;
		ll ans=0;
		while(n>0){
			int min=1e9, mini;
			rep(i, lim){
				if(min>costp[i]){
					min=costp[i];
					mini=i;
				}
			}
			if(mini==3){
				ans+=(n/2)*cost[3];
				n=n%2;
				lim--;
			}else{
				ans+=n*(ll)(1.0/tea[mini])*cost[mini];
				break;
			}
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;

typedef long long ll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)

int n;
ll k;
ll a[252521];

ll s[125252];

ll solve(int l,int r){
  if(r-l==1){
    return (ll)(a[l]>=0);
  }
  int mid = (l+r)/2;
  // divide
  ll ret = solve(l,mid) + solve(mid,r);
  // merge
  int lena = mid-l;
  int lenb = r-mid;
  // 片方を列挙
  ll yo = 0;
  REP(i,lenb){
    yo += a[mid+i];
    s[i] = yo;
  }
  // ソート
  sort(s,s+lenb);
  // もう片方を1つ1つ試して二分探索
  yo = 0;
  REP(i,lena){
    yo += a[mid-1-i];
    int x = lower_bound(s,s+lenb,-yo) - s;
    ret += lenb-x;
  }
  return ret;
}

int main(){
  scanf("%d%lld",&n,&k);
  REP(i,n)scanf("%lld",a+i);
  REP(i,n)a[i] -= k;
  ll ans = solve(0,n);
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 2560
N = int(input())
S = list(input())
r = 0
g = 0
b = 0

for i in S:
    if i == "R":
        r += 1
    if i == "G":
        g += 1
    if i == "B":
        b += 1

ans = r*g*b

for i in range(N):
    for j in range(i+1,N):
        if 2*j - i <= N - 1:
            t = [ S[i],S[j],S[2*j-i] ]
            if len(set(t)) == 3:
                ans -= 1

print(ans)

Measured memory_bytes: 68368
import sys
input = sys.stdin.readline
from bisect import *

H, W, K = map(int, input().split())
S = [input()[:-1] for _ in range(H)]
ans = [[-1]*W for _ in range(H)]
now = 1
l = []

for i in range(H):
    cnt = 0
    
    for j in range(W):
        if S[i][j]=='#':
            cnt += 1
    
    if cnt==0:
        continue
    
    l.append(i)
    c = 0
    
    for j in range(W):
        ans[i][j] = now
        
        if S[i][j]=='#':
            c += 1
            
            if c<cnt:
                now += 1
    
    now += 1
    
for i in range(H):
    if '#' not in S[i]:
        j = bisect_left(l, i)
        
        if j==len(l):
            for k in range(W):
                ans[i][k] = ans[l[-1]][k]
        else:
            for k in range(W):
                ans[i][k] = ans[l[j]][k]

for ans_i in ans:
    print(*ans_i)

Measured memory_bytes: 75572
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;


#define TRACE

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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
const int maxN = 100224;

void solve(){
  ll n,m;
  cin>>n>>m;
  ll a[m];
  vi v;
  rep(i,m) cin>>a[i];
  sort(a,a+m);
  if(n>=m){
    cout<<0<<endl;
    return ;
  }
  rep(i,m-1) v.push_back(abs(a[i] - a[i+1]));
  sort(all(v), greater<ll>());
  ll ans = a[m-1] - a[0];
  rep(i,n-1) ans-=v[i];
  cout<<ans<<endl;
} 

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);
 //pre();
  solve();
  return 0;
}


Measured memory_bytes: 2168
#ABC 105 B
divisors = [4+i*7 for i in range(4)]
bound_num = max(divisors)
n = int(input())
yes=[i*4 + j*7 for i in range(6) for j in range(6)]
if n >= bound_num or n in yes:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940