akhauriyash/Code-Regression huggingface dataset:
// Crt. 2019-12-11  21:17:53
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 200005
using namespace std;
typedef long long ll;
const ll INF = 1e15;

struct Segt {
#define ls (p << 1)
#define rs (p << 1 | 1)
    ll sum[N << 2], tag[N << 2];
    Segt() {
        memset(sum, 0, sizeof sum);
        memset(tag, 0, sizeof tag);
    }
    inline void add(int p, ll w) { 
        sum[p] += w, tag[p] += w;
    }
    inline void pushdown(int p) {
        if (!tag[p]) return ;
        add(ls, tag[p]);
        add(rs, tag[p]);
        tag[p] = 0;
    }
    void Modify(int l, int r, int L, int R, ll w, int p) {
        if (L <= l && r <= R) return add(p, w);
        int mid = (l + r) >> 1;
        pushdown(p);
        if (L <= mid) Modify(l, mid, L, R, w, ls);
        if (mid < R) Modify(mid + 1, r, L, R, w, rs);
        sum[p] = min(sum[ls], sum[rs]);
    }
    ll Query(int l, int r, int L, int R, int p) {
        if (L <= l && r <= R) return sum[p];
        int mid = (l + r) >> 1; ll res = 0x3f3f3f3f3f3f3f3fll;
        pushdown(p);
        if (L <= mid) res = Query(l, mid, L, R, ls);
        if (mid < R) res = min(res, Query(mid + 1, r, L, R, rs));
        return res;
    }
#undef ls
#undef rs
} x, y, z; // y + z -

inline int Abs(int t) {
    return t < 0 ? -t : t;
}

int n, q, a, b, pos[N];

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> q >> a >> b;

    for (int i = 1; i <= q; ++i)
        scanf("%d", pos + i);

    x.Modify(1, n, 1, n, INF, 1);
    y.Modify(1, n, 1, n, INF, 1);
    z.Modify(1, n, 1, n, INF, 1);
    
    x.Modify(1, n, a, a, -INF, 1);
    y.Modify(1, n, a, a, -INF + a, 1);
    z.Modify(1, n, a, a, -INF - a, 1);

    pos[0] = b;
    for (int i = 1; i <= q; ++i) {
        ll tmp = min(y.Query(1, n, pos[i], n, 1) - pos[i], z.Query(1, n, 1, pos[i], 1) + pos[i]);
        x.Modify(1, n, 1, n, Abs(pos[i] - pos[i - 1]), 1);
        y.Modify(1, n, 1, n, Abs(pos[i] - pos[i - 1]), 1);
        z.Modify(1, n, 1, n, Abs(pos[i] - pos[i - 1]), 1);
        ll tmp2 = x.Query(1, n, pos[i - 1], pos[i - 1], 1);
        //cout << tmp << " " << tmp2 << " #\n";
        if (tmp < tmp2) x.Modify(1, n, pos[i - 1], pos[i - 1], tmp - tmp2, 1), tmp2 = tmp;
        //cout << x.Query(1, n, pos[i - 1], pos[i - 1], 1) << endl;
        y.Modify(1, n, pos[i - 1], pos[i - 1], tmp2 + pos[i - 1] - y.Query(1, n, pos[i - 1], pos[i - 1], 1), 1);
        z.Modify(1, n, pos[i - 1], pos[i - 1], tmp2 - pos[i - 1] - z.Query(1, n, pos[i - 1], pos[i - 1], 1), 1);
    }
    
    cout << x.Query(1, n, 1, n, 1) << endl;

    return 0;
}


Measured memory_bytes: 38528
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    n = ri()
    A = rl()
    counts = dd(int)
    total  = 0
    for a in A:
        total += a
        counts[a] += 1

    for _ in range(ri()):
        x, y = rl()
        rem = counts[x]
        total += (y - x) * rem
        counts[x] = 0
        counts[y] += rem
        print (total)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 95344
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x)&(-x)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define maxd 1000000007
typedef long long ll;
const int N=200000;
const double pi=acos(-1.0);
int B,W;
ll fac[200200],invfac[200200],f[200200],g[200200],bin[200200];

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

ll qpow(int x,int y)
{
	ll ans=1,sum=x;
	while (y)
	{
		if (y&1) ans=(ans*sum)%maxd;
		sum=(sum*sum)%maxd;
		y>>=1;
	}
	return ans;
}

ll inv(int x) {return qpow(x,maxd-2);}

ll C(int n,int m)
{
	if (m>n) return 0;
	return ((fac[n]*invfac[m])%maxd*invfac[n-m])%maxd;
}

int main()
{
	int B=read(),W=read();
	fac[0]=1;invfac[0]=1;bin[0]=1;
	ll inv2=inv(2);
	rep(i,1,N) fac[i]=(fac[i-1]*i)%maxd;
	invfac[N]=inv(fac[N]);
	per(i,N-1,1) invfac[i]=(invfac[i+1]*(i+1))%maxd;
	rep(i,1,N) bin[i]=(bin[i-1]<<1)%maxd;
	rep(i,1,B+W)
	{
		f[i]=(f[i-1]+(C(i-1,W-1)*inv(bin[i]))%maxd)%maxd;
		g[i]=(g[i-1]+(C(i-1,B-1)*inv(bin[i]))%maxd)%maxd;
	}
	rep(i,1,B+W)
	{
		ll tmp=(1+maxd-f[i-1]+maxd-g[i-1])%maxd,
		   ans=((tmp*inv2)%maxd+f[i-1])%maxd;
		printf("%lld\n",ans);
	}
	return 0;
}
	
	


Measured memory_bytes: 9984
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;

#define rep(i,n) for(int i=0;i<(n);++i)
#define MAXN 1010
#define linf 8223372036854775808LL

//d,edge,g
lint d[MAXN];
struct edge{ int to;lint cost; };
vector<edge> g[MAXN];

bool bellmanford(int n,int s){
	d[s]=0;
	rep(i,n){
		rep(v,n){
			for(edge &e:g[v])if(d[v]!=linf&&d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				if(i==n-1&&e.to==n-1)return 1;
			}
		}
	}return 0;
}

int main(){
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(0);
	int n,m;cin>>n>>m;
	int a,b;lint c;
	fill(d,d+n,linf);
	rep(i,m){
		cin>>a>>b>>c;--a;--b;
		g[a].push_back({b,-c});
	}
	if(bellmanford(n,0))cout<<"inf\n";
	else cout<<-d[n-1];
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 384
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]

cntH = 0
for i in range(H-1, -1, -1):
    flag = True
    for j in range(W):
        if a[i][j] == '#':
            flag = False
            break
    if flag:
        a.pop(i)
        cntH+=1

for j in range(W-1, -1, -1):
    flag = True
    for i in range(H-cntH):
        if a[i][j] == '#':
            flag = False
    if(flag):
        for i in range(H-cntH):
            a[i].pop(j)

for i in range(H-cntH):
    for j in range(len(a[i])):
        print(a[i][j], end='')
    print('')

Measured memory_bytes: 4596
using System;
public class D
{

    public static void Main()
    {
        var len = int.Parse(Console.ReadLine());
        var l = new char[len];
        for (var i = 0; i < len; ++i)
        {
            l[i] = 'a';
        }
        while (l[0] == 'a')
        {
            Output(l);
            ++l[len - 1];
            Check(l);
        }
    }
    private static void Check(char[] l)
    {
        var max = 'a';
        for (var i = 1 ; i < l.Length; ++i)
        {
            if (l[i] - max == 1)
            {
                max = l[i];
            }
            else if (l[i] - max > 1)
            {
                ++l[i - 1];
                l[i] = 'a';
                Check(l);
                break;
            }
        }
    }
    private static void Output(char[] l)
    {
        Console.WriteLine(l);
    }
}

Measured memory_bytes: 12372
#include<iostream>
#include<string>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(W<x+r||0>x-r||H<y+r||0>y-r){
	cout<<"No";
	}else{
	cout<<"Yes";
	}
	cout<<endl;
}


Measured memory_bytes: 3108
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    string str;
    cin >> str;
    string pre = "", cur = "";

    pre = str[0];
    LL cnt = 1;
    for (int i = 1; i < (int)str.size(); i++) {
        cur += str[i];

        if (pre != cur) {
            pre = cur;
            cur = "";
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 832
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long ans=999999999999;
    
    for(long long i=1;i<=pow(n,0.5);i++){
        if(n%i==0) ans=min((i+n/i)-2,ans);
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e16;
typedef long long ll;

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

  ll ans = 0, now = 0;

  for (int i = N - 1; i >= 0; i--){
    if (now > A[i]){
      ans = -1;
      break;
    }else if(now == A[i]){
      now--;
    }else{
      ans += A[i];
      now = A[i] - 1;
    }
  }
  if (A[0] != 0){
    ans = -1;
  }
  
  
  cout << ans << endl;

  return 0;
}


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

  int x,y,temp=0;

  while(1){
    
    scanf("%d %d",&x,&y);
    
    if(x == 0 && y == 0) break;
    if(x > y){
      temp = x;
      x = y;
      y = temp;
    }
    printf("%d %d\n",x,y);

  }
  
  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#define ll long long
const int maxn = 1e5;
int n;
int a[maxn];
int x[maxn];
ll total=0;

void solve()
{
    ll temp = total;
    for(int j=2;j<=n;j+=2) temp -= (ll)a[j]*2;
    printf("%lld ",temp);
    x[1] = (int)temp;
    for(int i=2;i<n;i++)
    {
        x[i] = 2*a[i-1]-x[i-1];
        printf("%d ",x[i]);
    }
    printf("%d",2*a[n]-x[1]);
    return ;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {scanf("%d",&a[i]);total+=a[i];}
    solve();
    return 0;
}


Measured memory_bytes: 2048
n = int(input())
wl = []
wl.append(input())
ans = 'Yes'
for _ in range(1,n):
    w = input()
    if w in wl or wl[-1][-1] != w[0] or ans == 'No':
        ans = 'No'
    else:
        wl.append(w)
print(ans)

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

constexpr long long INF = 1e18+9;

class Edge{
public:
	long long cost;
	int from, to;
	Edge(long long c, int f, int t){
		cost = c;
		from = f;
		to = t;
	}
};

bool operator < (const Edge &e, const Edge &f){
	return e.cost != f.cost ? e.cost > f.cost : e.from != f.from ? e.from < f.from : e.to < f.to;
}

typedef vector<vector<Edge> > Graph;

void readGraph(Graph &g, int E, bool D, bool C){ // E:NumofEdges, D:Directed, C:Costed
	for(int i=0; i<E; ++i){
		Edge e(0, 0, 0);
		if(!C) cin >> e.from >> e.to;
		else cin >> e.from >> e.to >> e.cost;
//		--e.from;
//		--e.to;
		g[e.from].push_back(e);
		if(!D){
			swap(e.from, e.to);
			g[e.from].push_back(e);
		}
	}
}

void dijkstra(int s, const Graph &g, vector<long long> &dist){
	int V = g.size();
	dist = vector<long long>(V, INF);
	dist[s] = 0;
	priority_queue<Edge> q;
	q.push(Edge(0, s, s));
	while(!q.empty()){
		Edge e = q.top();
		q.pop();
		if(dist[e.to] < e.cost) continue;
		for(int i=0; i<(int)g[e.to].size(); ++i){
			Edge f = g[e.to][i];
			if(dist[f.to] > dist[e.to] + f.cost){
				dist[f.to] = dist[e.to] + f.cost;
				q.push(Edge(dist[f.to], s, f.to));
			}
		}
	}
}

int main(){
	int v, e, r;
	cin >> v >> e >> r;
	Graph g(v);
	readGraph(g, e, true, true);
	vector<long long> d(v);
	dijkstra(r, g, d);
	for(auto i : d){
		if(i == INF) cout << "INF" << endl;
		else cout << i << endl;
	}
}


Measured memory_bytes: 20412
// 2013/04/19 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;

	if((b1==1&&b2==1)||b3==1){
		cout << "Open" << endl;
	}
	else{
		cout << "Close" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int X = in.nextInt();
        int N = in.nextInt();
        Set<Integer> p = new HashSet<>();
        for (int n = 0; n < N; n++)
            p.add(in.nextInt());

        if (N == 0) {
            out.println(X);
        } else {
            for (int i = 0; i < 100; i++) {
                if (!p.contains(X - i)) {
                    out.println(X - i);
                    break;
                } else if (!p.contains(X + i)) {
                    out.println(X + i);
                    break;
                }
            }
        }

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 32808
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define vsort(xx) sort(xx.begin(),xx.end())
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
 int a,b,c,d;cin>>a>>b>>c>>d;
 while(1){
     
     c-=b;
     if(c<=0){cout<<"Yes";break;}
     a-=d;
     if(a<=0){cout<<"No";break;}
     
 }
    return 0;
}




Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	long N,A,B;cin>>N>>A>>B;
	long t=N%(A+B);
	long cnt=N/(A+B)*A;
	if(t>=A) cout<<cnt+A<<endl;
	else cout<<cnt+t<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
using namespace std;

int main() {
    string str;
    getline(cin, str);
    for (int i = 0; i < str.size();++i) {
        if (str[i] >= 'a' && str[i] <= 'z') str[i] += 'A' - 'a';
        else if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A';
    }
    cout << str << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(ll i=0;i<n;i++)
#define revf(i,n) for(ll i=n-1;i>=0;i-=2)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "
#define outp1(a,n) for(ll i=1;i<n;i++)cout<<a[i]<<" "
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define pb push_back
#define mp make_pair
#define mem(x,n) memset(x,n,sizeof(x))
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define cn cout<<"\n";
int main()
{
     ll x,k,d;
     cin>>x>>k>>d;
     if(abs(x)==d)
     {
          if(k%2!=0)
          cout<<0;
          else
          cout<<abs(x);
     }
     else if(abs(x)<d)
     {
          if(k%2!=0)
          cout<<abs(abs(x)-d);
          else
          cout<<abs(x);
     }
     else
     {
          ll k1=abs(x)/d;
          if(k1>=k)
          cout<<abs(abs(x)-k*d);
          else
          {
               ll k2=k-k1;
               ll d1=abs(abs(x)-k1*d);
               if(k2%2!=0)
               cout<<abs(d-d1);
               else
               cout<<abs(d1);
          }
     }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int N, M, dp[3005][3005];
char S[3005], T[3005];
int main(){
    scanf("%s %s", S + 1, T + 1);
    N = strlen(S + 1);
    M = strlen(T + 1);
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++){
            if(S[i] == T[j]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    int R = N, C = M;
    string ans;
    while(R >= 1 && C >= 1){
        if(dp[R - 1][C] == dp[R][C])
            R -= 1;
        else if(dp[R][C - 1] == dp[R][C])
            C -= 1;
        else{
            ans.push_back(S[R]);
            R -= 1, C -= 1;
        }
    }
    for(int i = ans.size() - 1; i >= 0; i--)
        printf("%c", ans[i]);
    return 0;
}


Measured memory_bytes: 35456
w, h, n = map(int, input().split())
ans = [[0 for _ in range(w)] for _ in range(h)]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(h):
            ans[j][:x] = [1 for _ in range(x)]
    if a == 2:
        for j in range(h):
            ans[j][x:] = [1 for _ in range(w-x)]
    if a == 3:
        for j in range(h-y,h):
            ans[j] = [1 for _ in range(w)]
    if a == 4:
        for j in range(h-y):
            ans[j] = [1 for _ in range(w)]
cnt = 0
for k in ans:
    cnt += k.count(0)
print(cnt)


Measured memory_bytes: 9144
while 1:
    try:
        dwh=list(map(int,input().split()))
        if dwh[0]==dwh[1]==dwh[2]==0:break
        dwh.sort()
        std=(dwh[0]**2+dwh[1]**2)**0.5/2
        n=int(input())
        for i in range(n):
            r=int(input())
            if std<r:print("OK")
            else:print("NA")
    except:break


Measured memory_bytes: 5632
def dfs(t):
    if 0 not in already:#全ての辺を訪問していた場合
        return 1
    allReach=0#全ての辺を訪問する回数を格納する変数
    for i in range(n):
        if connect[t][i]==1 and already[i]==0:#辺があり、訪問しいない場合
            already[i]=1
            allReach+=dfs(i)
            already[i]=0
    return allReach

n,m=map(int,input().split())
connect=[[0 for i in range(n)]for j in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    #辺の情報を記録する
    connect[a-1][b-1]=1
    connect[b-1][a-1]=1
already=[0 for i in range(n)]#訪問した点を記録する
already[0]=1#必ず1から始まるので訪問履歴をつけておく
print(dfs(0))#記録した情報をもとに0からdfs


Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, l; cin >> n >> l;

    vector<ll> umasa;
    vector<ll> umasaabs;
    RANGE(i, 1, n) {
        umasa.emplace_back(l+i-1);
        umasaabs.emplace_back(abs(l+i-1));
    }

    cout << accumulate(ALL_OF(umasa), 0LL) - umasa[(min_element(ALL_OF(umasaabs)) - umasaabs.begin())] << endl;
    
}

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a<1 || a>9 || b<1 || b>9){
		cout << -1 << endl;
	}else{
		cout << a*b << endl;
	}
    return 0;
}


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

int main (void) {
    int i;
    int n;
    scanf("%d", &n);
    int b[n-1];
    for ( i=0; i<n-1; i++ )
        scanf("%d", &b[i]);

    long long ans=0;
    ans += b[0];
    for ( i=1; i<n-1; i++ ) {
        ans += (b[i-1] > b[i]) ? b[i] : b[i-1];
    }
    ans += b[n-2];

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    //swap( a, b, c);
    int A = c;
    int B = a;
    int C = b;
   /* int temp=0;
    temp = a;
    a = b;
    b = c;*/
    cout<<A<<" "<<B<<" "<<C<<endl;
}


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

int main(void){
    
    long double A,B,H,M;
    
    cin >> A >> B >> H >> M;
    
    long double dA = H/12*2*M_PI + M/60*2/12*M_PI;
    long double dB = M/60*2*M_PI;
    long double dg = min(abs(dA-dB),abs(dB-dA));
    long double ans = sqrt( A*A + B*B - 2*A*B*cos(dg));
    cout <<setprecision(20)<< ans <<endl;
}

Measured memory_bytes: 4168
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int c0 = 0;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    for (int i = 0; i < n; i++){
      String S = scan.next();
      if (S.equals("AC")){
        c0 += 1;
      }else if (S.equals("WA")){
        c1 += 1;
      }else if (S.equals("TLE")){
        c2 += 1;
      }else if (S.equals("RE")){
        c3 += 1;
      }
    }
    System.out.println("AC"+" "+"x"+" "+c0);
    System.out.println("WA"+" "+"x"+" "+c1);
    System.out.println("TLE"+" "+"x"+" "+c2);
    System.out.println("RE"+" "+"x"+" "+c3);
  }
}

Measured memory_bytes: 58276
#!/usr/bin/env python3
import sys
import heapq

def solve(N: int, M: int, A: "List[int]"):
    # A.sort()
    # for i in range(M):
    #     A[-1] = A[-1] // 2
    #     A.sort()

    mA = [-1*i for i in A]
    heapq.heapify(mA)
    # print(mA)

    for i in range(M):
        x = heapq.heappop(mA)*(-1)
        x = x // 2
        heapq.heappush(mA, -1*x)

    print(-1*sum(mA))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19352
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)
	if s == t[0:len(s)] && len(s)+1 == len(t) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<P> cnt(n+2,P(0,0));
  bool flag=true;
  ll ans=0;
  FOR(i,1,n+1){
    ll a;
    cin>>a;
    cnt[i].fi=a;
    if(cnt[i-1].fi<a) cnt[i].se=1;
  }/*
  FOR(i,0,n+1){
    cout<<cnt[i].fi<<' '<<cnt[i].se<<endl;
  }*/
  vector<ll> b(n+1);
  rep(i,n) cin>>b[i+1];
  for(int i=n;i>=1;i--){
    ll a=b[i];
    if(cnt[i].se && cnt[i].fi>a) flag=false;
    cnt[i].fi=min(cnt[i].fi,a);
    if(cnt[i+1].fi<cnt[i].fi) cnt[i].se=1;
  }/*
  FOR(i,1,n+1){
    cout<<cnt[i].fi<<' '<<cnt[i].se<<endl;
  }*/
  if(!flag){
    cout<<ans<<endl;
    return 0;
  }
  ans=1;
  FOR(i,1,n+1){
    if(cnt[i].se) continue;
    (ans*=(cnt[i].fi)%mod)%=mod;
  }
  cout<<ans<<endl;
}

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

int main()
{
  //int n;
  int a[10000];
  int b[10000];
  for(int i = 0; i < 10000 ; i++ )
  {
    cin >> a[i] >> b[i];
    if (a[i] == 0 && b[i] == 0)
    {
        break;   
    }
    else if(a[i] > b[i])cout << b[i] << " " << a[i] << endl;
    else cout << a[i] << " " << b[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3108
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;
 
public class Main {
 
	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;
 
	static void solve() {
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		if(a<b&&b<c)out.println("Yes");
		else out.println("No");
	}
 
	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();
 
		solve();
		out.flush();
 
		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}
 
	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;

int main()
{_
    str s; cin >> s;
    ll res = 700;
    for(ll i = 0 ; i < s.size() ; i++)
        if(s[i] == 'o')
            res += 100;
    return cout << res , 0;
}
///SAliB


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<queue>
#include<utility>
#include<algorithm>

using namespace std;

const int di[]={1,0,-1,0},dj[]={0,1,0,-1};
const int inf=2000;

typedef pair<int,int> P;
typedef pair<int,P> PP;

bool exi[33][33][4];
int dis[33][33][4][33][33];
int ans[33][33];
int W,H;

inline bool isin(P p){
	int i=p.first,j=p.second;
	return i>=0&&j>=0&&i<H&&j<W;
}
inline P mv(P p,int dir){
	return P(p.first+di[dir],p.second+dj[dir]);
}

queue<P> que;
void bfs(P st,int dir){
	int si=st.first,sj=st.second;
	while(!que.empty()) que.pop();
	for(int i=0;i<H;i++) for(int j=0;j<W;j++) dis[si][sj][dir][i][j]=inf;
	dis[si][sj][dir][si][sj]=0;
	if(isin(mv(st,dir))==false) return;
	if(exi[si][sj][dir]==false) return;
	exi[si][sj][dir]=false;
	P tmp=mv(st,dir);
	exi[tmp.first][tmp.second][(dir+2)%4]=false;
	que.push(st);
	while(!que.empty()){
		P cur=que.front();
		que.pop();
		int cd=dis[si][sj][dir][cur.first][cur.second];
		for(int d=0;d<4;d++){
			if(exi[cur.first][cur.second][d]==false) continue;
			P nxt=mv(cur,d);
			if(isin(nxt)==false) continue;
			if(dis[si][sj][dir][nxt.first][nxt.second]<=cd+1) continue;
			dis[si][sj][dir][nxt.first][nxt.second]=cd+1;
			que.push(nxt);
		}
	}
	exi[si][sj][dir]=true;
	exi[tmp.first][tmp.second][(dir+2)%4]=true;
}

void input(){
	scanf("%d%d",&H,&W);
	if(H==0&&W==0) exit(0);
	for(int i=0;i<H;i++){
		for(int j=0;j<W-1;j++){
			int in;
			scanf("%d",&in);
			bool flg=(in==0);
			exi[i][j][1]=flg;
			exi[i][j+1][3]=flg;
		}
		if(i==H-1) break;
		for(int j=0;j<W;j++){
			int in;
			scanf("%d",&in);
			bool flg=(in==0);
			exi[i][j][0]=flg;
			exi[i+1][j][2]=flg;
		}
	}
}

void solve(){
	for(int i=0;i<H;i++) for(int j=0;j<W;j++){
		for(int k=0;k<4;k++){
			bfs(P(i,j),k);
			if(isin(mv(P(i,j),k))==false) continue;
			//if(exi[i][j][k]==true&&dis[i][j][k][H-1][W-1]==inf){
			//	printf("-1\n");
				/*printf("%d %d %d\n",i,j,k);
				for(int ii=0;ii<H;ii++){
					for(int jj=0;jj<W;jj++){
						printf("%d ",dis[i][j][k][ii][jj]);
					}
					printf("\n");
				}*/
		//		exit(0);
			//	return;
			//}
		}
	}
	for(int i=0;i<H;i++) for(int j=0;j<W;j++){
		ans[i][j]=inf;
	}
	ans[H-1][W-1]=0;
	priority_queue<PP,vector<PP>,greater<PP> > que;
	que.push(PP(0,P(H-1,W-1)));
	while(!que.empty()){
		PP pp=que.top();
		que.pop();
		int cd=pp.first;
		P p=pp.second;
		if(ans[p.first][p.second]<cd) continue;
		for(int d=0;d<4;d++){
			P nxt=mv(p,d);
			if(isin(nxt)==false) continue;
			if(exi[p.first][p.second][d]==false) continue;
			int d1=dis[nxt.first][nxt.second][(d+2)%4][H-1][W-1];
			int d2=cd+1;
			int nd=max(d1,d2);
			if(ans[nxt.first][nxt.second]<=nd) continue;
			ans[nxt.first][nxt.second]=nd;
			que.push(PP(nd,nxt));
		}
	}
	int res=ans[0][0];
	if(res==inf) res=-1;
	printf("%d\n",res);
}

int main(){
	while(true){
		input();
		solve();
	}
	return 0;
}

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

int main() {
	long long a,b,n;cin>>a>>b>>n;
	long long ans;
	if(n>=b-1){
		ans=(a*(b-1))/b;
	}else{
		ans=(a*n)/b;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

ll n, a, b;

int main()
{
  	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  	
  	cin >> n >> a >> b;
  	
  	if(a > b || (n == 1 && a != b)) cout << 0 << endl;
  	else cout << (n - 2) * (b - a) + 1 << endl;
  	
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <string>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int cnt = 0;

    while(a >= b){
        b = b * 2;
        cnt++;
        if(cnt > k){
            p("No");
            return 0;
        }
    }

    while(b >= c){
        c = c * 2;
        cnt++;
        if(cnt > k){
            p("No");
            return 0;
        }
    }

    p("Yes");

}

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

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

  if(S.at(0) == S.at(1) && S.at(1) == S.at(2)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
n,k = map(int, input().split())
mod = 10**9+7
cnt = [0]*(k+1)
for i in reversed(range(2, k+1)):
    a = k//i
    tmp = pow(a, n, mod)
    for j in range(2*i, k+1, i):
        tmp -= cnt[j]
    cnt[i] = tmp

s = sum(cnt)
ans = pow(k,n,mod) - s
for i in range(k+1):
    ans += i*cnt[i]
    ans %= mod
print(ans)


Measured memory_bytes: 68808
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20
#define DIVISOR 1000000007

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}
#define NUM_MAX 1000
#define K_MAX 1000

static uint64_t factorial[NUM_MAX+K_MAX+1];
static uint64_t inv_factorial[NUM_MAX+K_MAX+1];

struct pair {
    int x;
    int y;
};

struct pair gcdext(int a, int b) {
    if(a == 0) { return (struct pair){0, 1}; }
    struct pair p = gcdext(b%a, a);
    return (struct pair){p.y - (b/a)*p.x, p.x};
}

void prep_combi(int n) {
    // prep
    int i;
    factorial[0] = factorial[1] = 1;
    for(i = 2; i <= n; i++) {
        factorial[i] = (factorial[i-1] * i)%DIVISOR;
    }

    inv_factorial[0] = inv_factorial[1] = 1;
    for(i = 2; i <= n; i++) {
        struct pair p = gcdext(i, DIVISOR);
        int inv = (p.x + DIVISOR)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1]*inv)%DIVISOR;
    }
}

uint64_t calc_combi(int n, int k) {
    uint64_t ans = 1;
    ans = (ans * factorial[n])%DIVISOR;
    ans = (ans * inv_factorial[k])%DIVISOR;
    ans = (ans * inv_factorial[n-k])%DIVISOR;
    return ans;
}

void init() {
    prep_combi(NUM_MAX+K_MAX);
}

int main(void) {
    int n, k;
    init();
    get_int2(&n, &k);
    uint64_t ans = 0;
    
    if(n <= k) ans = calc_combi(k, n);
    printf("%d\n", (int)ans);
    return 0;
}


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

const long long MOD = 1000000007;

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;
}

void solve(long long N, std::vector<long long> A){
    vector<vector<int>> v(61);
    for(int i = 0;i < 61;i++){
        v[i].push_back(0);
        for(int j = 0;j < N;j++){
            if(bitset<61>(A[j])[i]){
                v[i].push_back(v[i].back() + 1);
            }else{
                v[i].push_back(v[i].back());
            }
        }
    }
    ll ans = 0;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 61;j++){
            if(!bitset<61>(A[i])[j]){
                ans += (v[j].back() - v[j][i + 1]) * modpow(2, j, MOD);
                ans %= MOD;
            }else{
                ans +=  ((N - i - 1) - v[j].back() + v[j][i + 1]) * modpow(2, j, MOD);
                ans %= MOD;
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 81556
#![allow(non_snake_case, unused_imports)]

// Input macros
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,VecDeque,BinaryHeap};

// Functions

// Main
fn main(){
    input!{
        N: i64,
        A: i64
    }
    println!("{}", if N%500 <= A{"Yes"}else{"No"});
}


Measured memory_bytes: 4352
//in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define forn(i,n) for(int i =0; i < (int)(n); i++)
#define rfr(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
ll a[105],dp[105][100005],n;
ll mod=1000000007;
ll solve(int ind,int count)
{
    if(dp[ind][count]!=-1)
        return dp[ind][count];
    if(count<0 || ind>n)
        return 0;
    if(count==0)
        return 1;
    if(ind >=n)
        return 0;
    dp[ind][count]=solve(ind,count-1)+solve(ind+1,count)-solve(ind+1,count-1-a[ind]);
    dp[ind][count]=(dp[ind][count]+mod)%mod;
    return dp[ind][count];
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //freopen("a.in", "r", stdin);
  //freopen("a.out", "w", stdout);
    ll k;
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<solve(0,k)<<"\n";
    
  return 0;
}


Measured memory_bytes: 88576
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	i = x - 1
	lower = 0
	while i >= 0:
		if not i+1 in p:
			lower = i+1
			break
		i -= 1
	i = x - 1
	upper = 101
	while i <= 101:
		if not i+1 in p:
			upper = i+1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
	elif abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

Measured memory_bytes: 9920
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int[] A = sc.nextIntList(N);
    int count = 0;
    for (int a : A) {
      if (a % 2 == 1) {
        count ++;
      }
    }
    System.out.println(count % 2 == 0 ? "YES" : "NO");
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 10352
#include <stdio.h>
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a < b) {
    printf("a < b\n");
  }
  else if (a > b) {
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 1796
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, i, j;
    cin >> n;
    vi d(n);
    for (i=0;i<n;i++) cin >> d[i];
    
    ll sum=0;
    for (i=0;i<n-1;i++) for (j=i+1;j<n;j++){
        sum += d[i] * d[j];
    }
    cout << sum << endl;
 }


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int LG = 20;
int dp[LG][100001];

int main(){
    int N, L, Q;
    cin >> N;
    vi x(N);
    rep(i, N)scanf("%d", &x[i]);
    cin >> L >> Q;
    
    rep(i, N){
        int k = --lower_bound(all(x), x[i] + L + 1)-x.begin();
        dp[0][i] = k;
    }

    rep(i, LG - 1){
        rep(j, N){
            dp[i + 1][j] = dp[i][dp[i][j]];
        }
    }

    while(Q--){
        int a, b;
        scanf("%d%d", &a, &b);
        if(a > b)swap(a, b);
        --a; --b;

        int lo = 0, hi = b-a;
        while(hi - lo > 1){
            int mid, cur = a;
            mid = (hi + lo) >> 1;
            rep(i, LG)if(mid >> i & 1){
                cur = dp[i][cur];
            }
            if(cur >= b)hi = mid;
            else lo = mid;
        }
        printf("%d\n", hi);
    }
}

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

int main(){
int a,b,c;
int f=0,s=0;
cin>>a>>b>>c;
if(a==5)f++;
if(b==5)f++;
if(c==5)f++;
if(a==7)s++;
if(b==7)s++;
if(c==7)s++;
if(f==2&&s==1)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
//    ŦĦ€Ř€'Ş ŇØŦĦƗŇǤ ĦØŁĐƗ'Ň Μ€ βΔĆҜ ΔŁŴΔ¥Ş ΔŇĐ ₣ØŘ€V€Ř 😈🤩😇😈💪🤜👊🤛🤟😉🤩:

#include<bits/stdc++.h>

#define mod 1000003
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define B(a) a.begin()
#define E(a) a.end()
#define For(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define M_P make_pair
#define P_B push_back
#define endd "\n"

using namespace std;

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

    double d,t,s;cin>>d>>t>>s;

    if(d/s<=t)
    cout<<"Yes";

    else
        cout<<"No";








    return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

const int inf=1<<29;

vector<vector<int>> d(10, vector<int>(10, inf));

void floyd(){
    rep(k, 0, 10){
        rep(i, 0, 10){
            if(d[i][k]==inf) continue;
            rep(j, 0, 10){
                if(d[j][k]==inf) continue;
                chmin(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
}

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

    int h, w; cin >> h >> w;
    rep(i, 0, 10) rep(j, 0, 10) cin >> d[i][j];
    floyd();

    map<int, int> mp;
    rep(i, 0, h) rep(j, 0, w){
        int a; cin >> a;
        ++mp[a];
    }

    int ans=0;
    rep(i, 0, 10) ans += mp[i]*d[i][1];
    cout << ans << endl;
    
    return 0;
}

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

typedef char String[1024];

int main(void)
{
    String Str;
	scanf("%s",Str);
      if (Str[2] == Str[3] && Str[4] == Str[5]){
        printf("Yes");
      } else {
        printf("No");
      }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

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

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>b)swap(a,b);
    if(c>d)swap(c,d);
    cout<<max({a*c,b*c,a*d,b*d});

    return 0;
}


Measured memory_bytes: 3632