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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


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

    int ans = 1000 - N%1000;
    if (ans == 1000)ans = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int m;
  cin >> m;
  cout << (24-m) + 24 << endl;

  return 0;
}

Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# A, B, C = list(map(int, sys.stdin.readline().split()))
# ans = max(0, C - (A - B))
#
# print(ans)

# N = int(sys.stdin.readline())
# ans = 0
# for i in range(1, N + 1):
#     ans += len(str(i)) & 1
# print(ans)

N = int(sys.stdin.readline())
H = list(map(int, sys.stdin.readline().split()))

for i in range(1, len(H)):
    if H[i - 1] < H[i]:
        H[i] -= 1
ans = (H == sorted(H))
if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14684
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define MAXN 100005
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define SQ(a) (a)*(a)
#define nl "\n"
#define INF std::numeric_limits<int>::max()
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
ll mod=1000000009;
int t[4*MAXN],n;
void build(int a[],int v,int tl,int tr){
	if( tl == tr) t[v] = a[tl];
	else{
		int tm = (tl + tr)/2;
		build(a,2*v,tl,tm);
		build(a,2*v+1,tm+1,tr);
		t[v] = min(t[2*v],t[2*v+1]);
	}
}

int min(int v,int tl,int tr,int l,int r){
	if(l > r){
		return INF - 1;
	}	
	if(l == tl && r == tr)
		return t[v];
	else{
		int tm = (tl + tr)/2;
		return min(min(2*v,tl,tm,l,min(tm,r)),min(2*v+1,tm+1,tr,max(tm+1,l),r));
	}
}

void update(int v,int tl,int tr,int pos,int new_val){
	if(tl == tr){
		t[v] = new_val;
	}
	else{
		int tm = (tl + tr)/2;
		if(pos<=tm)
			update(2*v,tl,tm,pos,new_val);
		else update(2*v+1,tl,tm,pos,new_val);
		t[v] = min(t[2*v],t[2*v+1]);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b && a!=c)||(b==c&&b!=a)||(a==c&&a!=b)){
		cout<<"Yes"<<nl;
	}
	else cout<<"No"<<nl;
	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string S;
  cin >> S;
  int ans = 0;
  int t = 0;
  rep(i, S.size()) {
    if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
      ++t;
    }
    else {
      ans = max(ans, t);
      t = 0;
    }
  }
  ans = max(t, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n,s,k;
	cin>>n>>k>>s;
	for(int i=0;i<k;i++){
		cout<<s<<" ";
	}
	if(s==1e9) s=1e9-2;
	for(int i=k;i<n;i++)
		cout<<s+1<<" ";
} 

Measured memory_bytes: 1280
#include<cstdio>
#pragma warning(disable:4996);

int main(void)
{
	long long a, b, c, k;
	long long ans = 0;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
	if (k >= a)
	{
		k -= a;
		ans += a;
	}
	else
	{
		ans = k;
		k = 0;
	}
	if (k)
	{
		k -= b;
		if (k > 0)
		{
			ans -= k;
		}
	}
	printf("%lld", ans);
	return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	ll N , T ;
	cin >>  N >> T;
	vector<ll> time(N);
	rep(i,N) cin >> time[i];

	ll ans = 0;
	ll clock = 0 ;
	rep(i,N){
		ans += time[i] + T - max(clock,time[i]);
		clock = time[i]+T;
	}
	cout << ans << endl;


}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/12/16  Problem: ARC 087 B / Link: http://arc087.contest.atcoder.jp/tasks/arc087_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	string s; cin >> s;
	int x, y;
	cin >> x >> y;
	VI xs(SZ(s)), ys(SZ(s));
	int xp = 0, yp = 0;
	int mode = 0;
	FOR(i, 0, SZ(s)) {

		if (mode == 0) {// x
			if (s[i] == 'T') { mode = 1; xp++; continue; }
			else {
				xs[xp]++;
			}
		}
		else {//y
			if (s[i] == 'T') { mode = 0; yp++; continue; }
			else {
				ys[yp]++;
			}

		}
	}
	if (mode == 0) {// x
		{ mode = 1; xp++; }
	}
	else {//y
		{ mode = 0; yp++; }
	}

	//FOR(i, 0, xp) {
	//	cout << xs[i] << " ";
	//}cout << endl;
	//FOR(i, 0, yp) {
	//	cout << ys[i] << " ";
	//}cout << endl;

	// dp
	vector<vector<bool>> dpx(8000, vector<bool>(20000));
	vector<vector<bool>> dpy(8000,vector<bool>(20000));
	dpx[0][xs[0]+10000] = 1;
	dpy[0][ys[0] + 10000] = 1;
	dpy[0][-ys[0]+10000] = 1;

	FOR(i, 0, xp) {
		FOR(j, 0, 20000) {//10000 base
			if (dpx[i][j]) {
				dpx[i + 1][j - xs[i + 1]] = 1;
				dpx[i + 1][j + xs[i + 1]] = 1;
			}
		}
	}
	FOR(i, 0, yp) {
		FOR(j, 0, 20000) {//10000 base
			if (dpy[i][j]) {
				dpy[i + 1][j - ys[i + 1]] = 1;
				dpy[i + 1][j + ys[i + 1]] = 1;
			}
		}
	}
	if (dpx[xp][10000+x] && dpy[yp][10000+y]) {
		cout << "Yes" << endl;
	}else cout << "No" << "\n";

	return 0;
}


Measured memory_bytes: 40192
N = int(input())
if N%4 == 0 or N%7 == 0:
    print("Yes")
elif True:
    M = N%11
    if M%4 == 0 or M%7 == 0:
        print("Yes")
    else:
        for i in range(int((N-M)/11)):
            M = M+11
            if M%4 == 0 or M%7 == 0:
                print("Yes")
                break
        if N == M:
            print("No")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T to_rad(T d) {
  return d * M_PI / 180.0;
}

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

  cout << setprecision(15) << fixed;
  int A,B,H,M;
  cin >> A >> B >> H >> M;

  long double d = abs(6.0 * M - (30 * H + 0.5 * M));
  long double rad = to_rad(d);
  long double ans = sqrt(A * A + B * B - 2 * A * B * cos(rad));
  cout << ans << endl;
}

Measured memory_bytes: 4128
#include<iostream>

int main(void){
    int n, k;
    std::cin >> n >> k;
    double cp = 1.0;
    int i = n;
    double ans = 0;
    int cur = 1;
    int cnt = 0;
    while(i > 0){
        if(cur * i < k){
            ans += cp * cnt / n;
            cp /= 2.0;
            cur *= 2;
            cnt = 0;
        }else if(i == 1){
            cnt++;
            ans += cp * cnt / n;
            i--;
        }else{
            cnt++;
            i--;
        }
    }
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 3772
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;
using std::min;
using std::max;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd(){static uint seed=416;return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	f&&(x=-x);
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;
int fa[N],E[N][2],dg[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int main()
{
	int n,m;read(n,m);
	int x,y;
	for(int i=1;i<=m;++i)
	{
		read(x,y);
		++dg[x],++dg[y];
		E[i][0]=x,E[i][1]=y;
	}
	for(int i=1;i<=n;++i) if(dg[i]&1) return puts("No"),0;
	int maxx=0;
	for(int i=1;i<=n;++i) chmax(maxx,dg[i]);
	if(maxx==2) return puts("No"),0;
	if(maxx!=4) return puts("Yes"),0;
	int cnt=0,ban=0;for(int i=1;i<=n;++i) if(dg[i]==4) ++cnt,ban=i;
	if(cnt==1) return puts("No"),0;
	if(cnt>=3) return puts("Yes"),0;
	for(int i=1;i<=n;++i) fa[i]=i;
	for(int i=1;i<=m;++i)
	{
		int x=E[i][0],y=E[i][1];
		if(x==ban||y==ban) continue;
		x=find(x),y=find(y);
		if(x==y) return puts("Yes"),0;
		fa[x]=y;
	}
	return puts("No"),0;
}


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

string s;
deque<char> dq;
bool rev=0;

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

    cin >> s;
    for (int i=0; i<s.size(); ++i) {
        dq.push_back(s[i]);
    }

    int q;
    cin >> q;
    while (q--) {
        int type;
        cin >> type;

        if (type==2) {
            int pos;
            char c;
            cin >> pos >> c;

            if (rev) {
                pos=3-pos;
            }

            if (pos==1)     dq.push_front(c);
            else            dq.push_back(c);
        }
        else {
            rev=!rev;
        }
    }

    if (rev) {
        reverse(dq.begin(), dq.end());
    }

    for (int i=0; i<dq.size(); ++i) {
        cout << dq[i];
    }

    return 0;
}


Measured memory_bytes: 976
#include <cstdio>
#include <iostream>

using namespace std;

char panjang[100005];
int main(){
   long long n,k,r,p,s,i,nilai;
   scanf("%lld %lld", &n, &k);
   nilai=0;
   getchar();
   scanf("%lld %lld %lld", &r, &s, &p);
   getchar();
   scanf("%s", panjang);
   getchar();
   for(i=0;i<n;i++){
      if(panjang[i]=='r'){
         if(i<k){
           // cout<<"p"<<endl;
            nilai+=p;
            panjang[i]='1';
         }
         else{
            if(panjang[i-k]=='1'){
               
            }
            else{
               panjang[i]='1';
              // cout<<"p"<<endl;
               nilai+=p;
            }
         }
      }
      else if(panjang[i]=='s'){
         if(i<k){
            //cout<<"r"<<endl;
            nilai+=r;
            panjang[i]='2';
         }
         else{
            if(panjang[i-k]=='2'){
              
            }
            else{
               panjang[i]='2';
               //cout<<"r"<<endl;
               nilai+=r;
            }
         }
      }
      if(panjang[i]=='p'){
         if(i<k){
            //cout<<"s"<<endl;
            nilai+=s;
            panjang[i]='3';
         }
         else{
            if(panjang[i-k]=='3'){
             
            }
            else{
               panjang[i]='3';
               //cout<<"s"<<endl;
               nilai+=s;
            }
         }
      }
}
  cout<<nilai<<endl;
}

Measured memory_bytes: 384
def read():
    N, A, B = list(map(int, input().strip().split()))
    return N, A, B

def solve(N, A, B):
    if (A + B) % 2 == 0:
        return (B - A) // 2
    left = (A - 1) + 1 + (B - A) // 2
    right = (N - B) + 1 + (B - A) // 2
    return min(left, right)

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        if(input.charAt(2) == input.charAt(3) && input.charAt(4)== input.charAt(5)){
            System.out.println("Yes");
          } else {
            System.out.println("No");
          }
    }
}


Measured memory_bytes: 21844
function Main(input) {
  input = input.split("\n");
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  const h = parseInt(input[2], 10);

  var S = ((a + b) * h) / 2.0;
  console.log(S);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import bisect
n,m = map(int,input().split())

l1 = [[] for i in range(n)]
l2 = []

for i in range(m):
    p,y = map(int,input().split())
    l1[p-1].append(y)
    l2.append((p,y))

for p in range(n):
    l1[p].sort()

for i in range(m):
    p = l2[i][0]
    k = bisect.bisect_right(l1[p-1],l2[i][1])
    p = str(p)
    k = str(k)
    ans = "0"*(6-len(p))+p+"0"*(6-len(k))+k
    print(ans)

Measured memory_bytes: 29604
#include <cstdio>

using namespace std;

int main() {
    char s[16], t[16]={};
    scanf("%s", s);

    int j=0;
    for (int i=0; s[i]; ++i) {
        switch (s[i]) {
            case 'B':
                if (j)
                    t[--j] = '\0';

                break;
            default:
                t[j++] = s[i];
        }
    }

    printf("%s\n", t);
    return 0;
}


Measured memory_bytes: 128
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

grid = [[0] * W for _ in range(H)]

alternate = True
index = 0
for i in range(H):
    if alternate:
        for j in range(W):
            if A[index] != 0:
                grid[i][j] = index
                A[index] -= 1
            else:
                index += 1
                grid[i][j] = index
                A[index] -= 1
    else:
        for j in reversed(range(W)):
            if A[index] != 0:
                grid[i][j] = index
                A[index] -= 1
            else:
                index += 1
                grid[i][j] = index
                A[index] -= 1
    alternate = not alternate

for gr in grid:
    for g in gr:
        print('{} '.format(g+1),end='')
    print()

Measured memory_bytes: 3956
s = input()
n = len(s)
k = int(input())
dp = [[[0 for _ in range(2)] for _ in range(k + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1
for a in range(n):
    for b in range(k + 1):
        for c in range(2):
            nd = int(s[a])
            for d in range(10):
                na, nb, nc = a + 1, b, c
                if 0 != d:
                    nb += 1
                if nb > k:
                    continue
                if nc == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nc = 1
                dp[na][nb][nc] += dp[a][b][c]
print(sum(dp[-1][-1]))


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
	int a,b,c,d,p,x,y,r;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&p);
	if(c>p){
		y=b;
	}else{
		y=b+(p-c)*d;
	}
	x=a*p;
	if(y<x){
		r=y;
	}else{
		r=x;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 2692
#0518
while True:
    n = int(input())
    if n == 0:
        break
    c = 0
    while True:
        if n == 1:
            break
        if n%2 == 0:
            n = n//2
        else:
            n= n*3 + 1
        c += 1
    print(c)



Measured memory_bytes: 5592
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = pow(10, 9) + 7;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};


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

int main(void) {
	vector<int> num = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	int K;
	cin >> K;

	cout << num[K-1] << endl;
	return 0;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int n; cin >> n;
    vector<ll> ar(n);
    rep(i,n) cin >> ar[i];
    int ans = 0;
    rep(i,n-2){
        repp(j,n-1,i+1){
            repp(k,n,j+1){
                vector<ll> ma = {ar[i],ar[k],ar[j]};
                sort(ma.rbegin(),ma.rend());
                if (ma[0] < ma[1] + ma[2] && ma[0] != ma[1] && ma[1] != ma[2] && ma[2] != ma[0]){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val (A, B) = readLine()!!.split(" ").map(String::toLong)
    println(lcm(A, B))
}

// 最小公倍数
fun lcm(a: Long, b: Long): Long {
    return a / gcd(a, b) * b
}

// 最大公約数
tailrec fun gcd(a: Long, b: Long): Long {
    if (a < b) return gcd(b, a)
    if (b == 0L) return a
    if (a <= 0L) throw IllegalArgumentException()
    return gcd(b, a % b)
}

Measured memory_bytes: 37736
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<int mod> class modint
{   
private:
    int val;
public:
    int value(){ return val; }
    modint(int x=0){ val=x%mod; }
    modint pow(int n){
        modint res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    modint inv(){ return pow(mod-2); }
    modint& operator+=(modint rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    modint& operator-=(modint rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    modint& operator*=(modint rhs){ val=val*rhs.val%mod; return *this; }
    modint& operator/=(modint rhs){ *this*=rhs.inv(); return *this; }
    modint operator+(modint rhs){ return modint(val)+=rhs; }
    modint operator-(modint rhs){ return modint(val)-=rhs; }
    modint operator*(modint rhs){ return modint(val)*=rhs; }
    modint operator/(modint rhs){ return modint(val)/=rhs; }
};

using mint=modint<1000000007>;
mint dp[100010][2][100];

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

    string s; cin>>s;
    int D; cin>>D;
    int N=s.size();

    dp[0][0][0]=1;
    for(int i=0;i<N;i++) for(int j=0;j<D;j++){
        for(int d=0;d<=s[i]-'0';d++){
            dp[i+1][d<s[i]-'0'][(j+d)%D]+=dp[i][0][j];
        }
        for(int d=0;d<=9;d++){
            dp[i+1][1][(j+d)%D]+=dp[i][1][j];
        }
    }
    mint ans=dp[N][0][0]+dp[N][1][0]-1;
    cout<<ans.value()<<endl;
    return 0;
}

Measured memory_bytes: 156672
N = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(N):
  d = input()
  if d == "AC":
    ac += 1
  elif d == "WA":
    wa += 1
  elif d == "TLE":
    tle += 1
  elif d == "RE":
    re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 74692
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    print(ii()*2*3.1415926535)



main()



Measured memory_bytes: 9984
#include <stdio.h>
       
int main()
{
    int W, H, x, y, r;
        
    scanf("%d %d %d %d %d\n", &W, &H, &x, &y, &r);
    
    if(W >= x + r && x - r >= 0 && H >= y + r && y - r >= 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 588
sec = $stdin.gets.to_i

HOUR_SEC = 3600

hour = 0
while sec >= HOUR_SEC do
  hour += 1
  sec -= HOUR_SEC
end

MIN_SEC = 60

min = 0
while sec >= MIN_SEC do
  min += 1
  sec -= MIN_SEC
end

puts "#{hour}:#{min}:#{sec}"

Measured memory_bytes: 8608
#include <iostream>
#include <vector>
#include <utility>
#include <stdio.h>

using namespace std;

int main(void){
	int N, temp;

	cin >> N;

	vector< vector<int> > cond(N+2, vector<int>(3, 0) ) ;

	for (int i = 1; i < N+1; i++){
		cin >> temp;
		cond[i][1] = temp + cond[i-1][1];
		cond[i][0] = cond[i-1][1];
	}
	cond[N+1][0] = cond[N+1][1] = cond[N][1];

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

	double distance = 0;
	double curv, prev = 0;


	for (double i = 0.5; i <= cond[N+1][1]; i += 0.5){
		double minv = 100000;
		for (int j = 0; j < N + 2; j++){
			if (i < cond[j][0]){
				if (minv > cond[j][2] + cond[j][0] - i)
					minv = cond[j][2] + cond[j][0] - i;
			}
			else if (i < cond[j][1]){
				if (minv > cond[j][2])
					minv = cond[j][2];
			}
			else {
				if (minv > cond[j][2] + i - cond[j][1])
					minv = cond[j][2] + i - cond[j][1];
			}
		}


		distance += 0.25*(prev + minv);
		prev = minv;
	}

	printf("%.5lf\n", distance);

	return 0;

}

Measured memory_bytes: 256
//A問題の時点ですでにきつい
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC147a
{
    class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = input[0];
            int b = input[1];
            int c = input[2];
            if (a + b + c >= 22)
            {
                Console.WriteLine("bust");
            }
            else
            {
                Console.WriteLine("win");
            }
        }
    }
}


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

int main() {
  int A,B,C,D;
    cin>>A>>B>>C>>D;
  if (A+B>C+D) {
    cout<<"Left"<<endl;
  }
  else if (A+B==C+D) {
    cout <<"Balanced"<<endl;
  }
   else {
     cout<<"Right"<<endl;
   }
}
  

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t X, A;

    scanf("%zu %zu", &X, &A);

    printf("%zu", X < A ? 0 : 10);

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt(), Y = s.nextInt();
        
        if(X % Y == 0){
            System.out.println(-1);
            return;
        }
        int n = 1000000000 / X + 1;
        for(int i = 1; i<n; i++){
            if((X * i) % Y != 0){
                System.out.println(X * i);
                break;
            }
        }
        
    }
    
}

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


Measured memory_bytes: 4432
/**
*    author:  y_takano
*    created: 18.06.2020 17:02:25
**/

#include <bits/stdc++.h>

using namespace std;

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

  int i, j;
  cin >> i >> j;

  cout << i / j  << " " << i % j << " " << fixed << setprecision(6) << double(i) / double(j) << endl;

  return 0;
}


Measured memory_bytes: 3268
#include <iostream>

using namespace std;

int main()
{
	int A,B,C;

	cin >> A;
	cin >> B;
	cin >> C;

	if (A+B-C >= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,s,e) for(register int i=s;i<=e;i++)
#define maxn 2020
int n,nums[maxn];
long long ans;
int main(){
      cin>>n;
      for(int i=0;i<=n-1;i++)cin>>nums[i];
        if(n<3)
        {
            return 0;
        }
        sort(nums,nums+n);
        int count=0;
        for(int i=n-1;i>=2;i--)
        {
            int left=0;
            int right=i-1;
            while(left<right)
            {
                if(nums[left]+nums[right]>nums[i])
                {
                    count+=right-left;
                    right--;
                }
                else
                {
                    left++;
                }
            }
        }
        cout<<count;
	return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self,N):
        self.root = list(range(N))
        self.size = [1] * (N)
        
    def find_root(self,x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x
    
    def merge(self,x,y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        sx,sy = self.size[x],self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
        else:
            self.root[y] = x
            self.size[x] += sy


n, m = map(int, input().split())
xyz = []
for i in range(m):
    xyz.append(list(map(int,input().split())))
    

uf = UnionFind(n)

answer = []
find_root = uf.find_root
merge = uf.merge
for i in range(m):
    x, y, z = xyz[i][0]-1, xyz[i][1]-1, xyz[i][2]
    merge(x,y)
s = set([])
for i in range(n):
    s.add(uf.find_root(i))
print(len(s))

Measured memory_bytes: 40192
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  int64_t result = 0;
  for (int64_t i = 1; i <= N; ++i) {
    int64_t a;
    cin >> a;
    if ((i % 2 == 1) && (a % 2 == 1)) {
      ++result;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3604
a,b,c=map(lambda x: int(x), input().split())
flag=[False]*b
tmp=0
for i in range(b):
    tmp=(tmp+a)%b
    if flag[tmp]==True:
        break
    else:
        flag[tmp]=True
if flag[c]==True:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool dfs(int a0, int a1, int l, int m, const set<int> &st) {
    if (st.empty()) { return m == (l ^ a0) && a0 == (m ^ a1); }
    set<int> copy = st;
    for (auto &r : st) {
        if (m == (l ^ r)) {
            copy.erase(r);
            if (dfs(a0, a1, m, r, copy)) return true;
            copy.insert(r);
        }
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    map<int, int> mp;
    REP(i, N) {
        cin >> a[i];
        mp[a[i]]++;
    }
    bool yes = false;
    if (SZ(mp) == 1 && a[0] == 0) {
        yes = true;
    } else if (SZ(mp) == 2 && N % 3 == 0 && mp[0] == N / 3) {
        yes = true;
    } else if (SZ(mp) == 3 && N % 3 == 0) {
        bool tmp = true;
        int sum = 0;
        for (auto &p : mp) {
            tmp = tmp && (p.second == N / 3);
            sum ^= p.first;
        }
        yes = tmp && (sum == 0);
    }
    if (yes)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 4224
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;


int main()
{
    
    int n, k;
    cin >> n >> k;
    vector<int>x(n);
    for (int i = 0; i < n; i++)cin >> x[i];

    sort(x.begin(), x.end());
    int t = 0;
    for (int i = 0; i < k; i++)t += x[i];

    cout << t << endl;

    return 0;

}

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

struct BIT {
  long long n;
  vector<long long> dat;

  void init(long long n_input) {
    n = n_input+1;
    dat.resize(n+1);
    for(int i=0;i<=n;i++)dat[i]=0;
  }

  long long sum(long long i){
    long long s=0;
    while(i>=0){
      s+=dat[i];
      i=(i&(i+1)) - 1;
    }
    return s;
  }

  void add(long long i, long long x){
    while(i<=n){
      dat[i]+=x;
      i |= i+1;
    }
  }
};

int main() {
  int i;
  long long N;
  cin>>N;
  vector<int> A(N), sortedA(N);
  for(i=0;i<N;i++){
    cin>>A[i];
    sortedA[i]=A[i];
  }
  sort(sortedA.begin(), sortedA.end());
  int ub=N;
  int lb=0;
  BIT bit;

  long long border = ((N*(N+1)/2)+1)/2;
  while(ub-lb>1) {
    int mid=(ub+lb)/2;
    int midn=sortedA[mid];
    bit.init(2*N+1);
    int sum=0;
    bit.add(sum+N, 1);
    long long result=0;
    for(i=0;i<N;i++){
      sum+=A[i]>=midn ? 1:-1;
      result+=bit.sum(sum+N);
      bit.add(sum+N, 1);
    }
    if(result>=border){
      lb=mid;
    }else{
      ub=mid;
    }
  }
  cout<<sortedA[lb]<<endl;
  return 0;
}


Measured memory_bytes: 2560
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P) + 1):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    elif nearest_l is not None:
        nearest = nearest_l
    elif nearest_r is not None:
        nearest = nearest_r
    return nearest

X, N = map(int, input().split())
P = list(map(int, input().split()))

print(solution(X, N, P))

Measured memory_bytes: 9240
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

def dfs(s, t, conn, visited):
    #print(s, t, visited)
    #print(s, t, conn)
    if s == t:
        return True
    visited[s] = True
    for n in conn[s]:
        if not visited[n] and dfs(n, t, conn, visited):
            return True
    return False


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    #conn = [[False] * N for _ in range(N)]
    ret = 0
    for i in range(M):
        conn = [[] for _ in range(N)]
        for j in range(M):
            if i == j:
                continue
            conn[a[j] - 1].append(b[j] - 1)
            conn[b[j] - 1].append(a[j] - 1)
        visited = [False] * N
        if not dfs(a[i] - 1, b[i] - 1, conn, visited):
            #print(a[i] - 1, b[i] - 1)
            #print()
            ret += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n,m,co=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
c=2**n
ans=10**10
for i in range(c):
  li=[]
  a=0
  for j in range(n):  
      if ((i >> j) & 1):  
        li.append(l[j])
        a+=l[j][0]
  z=[0]*m
  for k in range(len(li)):
    for kk in range(m):
      z[kk]+=li[k][kk+1]
  if min(z)>co-1:
    ans=min(ans,a)
if ans==10**10:
  print(-1)
else:
  print(ans)
            

Measured memory_bytes: 9252
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    int A,B,C;
    cin >> A >> B >> C;
    int ans = min(A+B+1, C) + B;
    cout << ans << endl;
    
    return 0;
}

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

Measured memory_bytes: 888
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, D = map(int, readline().split())
    A = [list(map(int, readline().split())) for _ in range(H)]
    Q, *LR = map(int, read().split())

    vec = [0] * (H * W + 1)
    for i in range(H):
        for j in range(W):
            vec[A[i][j]] = (i + 1, j + 1)
    vec[0] = vec[D]

    csum = [0] * D
    for i in range(D):
        N = (H * W - i) // D + 1
        csum[i] = [0] * N
        for j in range(N - 1):
            csum[i][j + 1] = (
                csum[i][j]
                + abs(vec[i + (j + 1) * D][0] - vec[i + j * D][0])
                + abs(vec[i + (j + 1) * D][1] - vec[i + j * D][1])
            )

    ans = [0] * Q
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        n, m = divmod(l, D)
        ans[i] = csum[m][(r - l) // D + n] - csum[m][n]

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 110300
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;
#define A first
#define B second
#define pb push_back
void chmax(int &a, int b) { a = (a > b ? a : b); }
void chmin(int &a, int b) { a = (a < b ? a : b); }

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> f(M, 0);
    for(int i = 0;i < N;i++) {
        int K; cin >> K;
        for(int j = 0;j < K;j++) {
            int a; cin >> a;
            f[a - 1]++;
        }
    }
    int ans = 0;
    for(int i = 0;i < M;i++)
        if(f[i] == N)
            ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(b == 1){
    cout << 0 << endl;
    return 0;
  }
  int ans=0, res=0;
  ans++;
  res += a;
  while(1){
    if(res>=b) break;
    res += a-1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

void print_v(vector<int> v){
    for(int i=0; i<v.size(); i++){
        cout << char(v[i]+97);
    }
    cout << endl;
}

void count_di(map<int,int> &mp, int n){
    int d=2;
    while(d<=n){
        if(n%d==0){
            n/=d;
            mp[d]++;
        }else d++;
    }
}

int main()
{
    int N;
    cin >> N;
    map<int,int> mp;
    for(int i=2; i<=N; i++){
        count_di(mp, i);
    }
    vector<int> c(5,0);
    for(auto m:mp){
        int n=m.second;
        if(n>=74) c[0]++;
        if(n>=24) c[1]++;
        if(n>=14) c[2]++;
        if(n>=4) c[3]++;
        if(n>=2) c[4]++;
    }
    cout << c[0]+max(0,(c[4]-1))*c[1]+max(0,(c[3]-1))*c[2]+max(0,(c[4]-2))*max(0,(c[3]-1))*c[3]/2 << endl;

    return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())
if y*x < 0:
    ans = abs(x + y) + 1
elif y*x == 0:
    if x < y:
        ans = y - x
    else:
        ans = x - y + 1
else:
    if x < y:
        ans = y - x
    else:
        ans = x - y + 2

print(ans)

Measured memory_bytes: 79908
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A_list = list(map(int, input().split()))

min_vote_line = sum(A_list) / (4 * M)
ans_list = [i for i in A_list if i >= min_vote_line]

print("Yes" if len(ans_list) >= M else "No")

Measured memory_bytes: 3060